| | | 1 | | namespace Allyaria.Theming.StyleTypes; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Represents a CSS <c>overscroll-behavior</c>, <c>overscroll-behavior-x</c>, or <c>overscroll-behavior-y</c> value wit |
| | | 5 | | /// the Allyaria theming system. Provides a strongly typed wrapper for controlling browser scroll chaining and overscrol |
| | | 6 | | /// behavior. |
| | | 7 | | /// </summary> |
| | | 8 | | public sealed record StyleOverscrollBehavior : StyleValueBase |
| | | 9 | | { |
| | | 10 | | /// <summary> |
| | | 11 | | /// Initializes a new instance of the <see cref="StyleOverscrollBehavior" /> record using the specified <see cref="K |
| | | 12 | | /// value. |
| | | 13 | | /// </summary> |
| | | 14 | | /// <param name="kind">The overscroll behavior to represent.</param> |
| | | 15 | | public StyleOverscrollBehavior(Kind kind) |
| | 24 | 16 | | : base(value: kind.GetDescription()) { } |
| | | 17 | | |
| | | 18 | | /// <summary>Defines the supported CSS <c>overscroll-behavior</c> property values.</summary> |
| | | 19 | | public enum Kind |
| | | 20 | | { |
| | | 21 | | /// <summary> |
| | | 22 | | /// Allows the default scroll chaining behavior. Scrolls will propagate to parent containers or cause browser ge |
| | | 23 | | /// (such as pull-to-refresh). |
| | | 24 | | /// </summary> |
| | | 25 | | [Description(description: "auto")] |
| | | 26 | | Auto, |
| | | 27 | | |
| | | 28 | | /// <summary> |
| | | 29 | | /// Prevents scroll chaining to parent containers, but allows default browser gestures (e.g., pull-to-refresh). |
| | | 30 | | /// </summary> |
| | | 31 | | [Description(description: "contain")] |
| | | 32 | | Contain, |
| | | 33 | | |
| | | 34 | | /// <summary>Completely disables scroll chaining and default browser gestures caused by reaching scroll limits.< |
| | | 35 | | [Description(description: "none")] |
| | | 36 | | None |
| | | 37 | | } |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// Parses a string representation of a CSS <c>overscroll-behavior</c> value into a <see cref="StyleOverscrollBehavi |
| | | 41 | | /// instance. |
| | | 42 | | /// </summary> |
| | | 43 | | /// <param name="value">The string representation of the overscroll behavior value.</param> |
| | | 44 | | /// <returns>A new <see cref="StyleOverscrollBehavior" /> instance representing the parsed value.</returns> |
| | | 45 | | /// <exception cref="AryArgumentException"> |
| | | 46 | | /// Thrown when the provided <paramref name="value" /> does not correspond to a valid <see cref="Kind" />. |
| | | 47 | | /// </exception> |
| | | 48 | | public static StyleOverscrollBehavior Parse(string? value) |
| | 10 | 49 | | => value.TryParseEnum<Kind>(result: out var kind) |
| | 10 | 50 | | ? new StyleOverscrollBehavior(kind: kind) |
| | 10 | 51 | | : throw new AryArgumentException(message: $"Invalid style: {value}", argName: nameof(value)); |
| | | 52 | | |
| | | 53 | | /// <summary>Attempts to parse a string into a <see cref="StyleOverscrollBehavior" /> instance.</summary> |
| | | 54 | | /// <param name="value">The string representation of the overscroll behavior value to parse.</param> |
| | | 55 | | /// <param name="result"> |
| | | 56 | | /// When this method returns, contains the parsed <see cref="StyleOverscrollBehavior" /> instance or |
| | | 57 | | /// <see langword="null" /> if parsing failed. |
| | | 58 | | /// </param> |
| | | 59 | | /// <returns><see langword="true" /> if parsing succeeded; otherwise, <see langword="false" />.</returns> |
| | | 60 | | public static bool TryParse(string? value, out StyleOverscrollBehavior? result) |
| | | 61 | | { |
| | | 62 | | try |
| | | 63 | | { |
| | 3 | 64 | | result = Parse(value: value); |
| | | 65 | | |
| | 1 | 66 | | return true; |
| | | 67 | | } |
| | 2 | 68 | | catch |
| | | 69 | | { |
| | 2 | 70 | | result = null; |
| | | 71 | | |
| | 2 | 72 | | return false; |
| | | 73 | | } |
| | 3 | 74 | | } |
| | | 75 | | |
| | | 76 | | /// <summary>Implicitly converts a string into a <see cref="StyleOverscrollBehavior" /> instance.</summary> |
| | | 77 | | /// <param name="value">The string representation of the overscroll behavior value.</param> |
| | | 78 | | /// <returns>A <see cref="StyleOverscrollBehavior" /> instance representing the provided value.</returns> |
| | | 79 | | /// <exception cref="AryArgumentException"> |
| | | 80 | | /// Thrown when the provided string cannot be parsed into a valid |
| | | 81 | | /// <see cref="Kind" />. |
| | | 82 | | /// </exception> |
| | 2 | 83 | | public static implicit operator StyleOverscrollBehavior(string? value) => Parse(value: value); |
| | | 84 | | |
| | | 85 | | /// <summary>Implicitly converts a <see cref="StyleOverscrollBehavior" /> instance to its string representation.</su |
| | | 86 | | /// <param name="value">The <see cref="StyleOverscrollBehavior" /> instance to convert.</param> |
| | | 87 | | /// <returns> |
| | | 88 | | /// The underlying CSS <c>overscroll-behavior</c> string value, or an empty string if <paramref name="value" /> is |
| | | 89 | | /// <see langword="null" />. |
| | | 90 | | /// </returns> |
| | 2 | 91 | | public static implicit operator string(StyleOverscrollBehavior? value) => (value?.Value).OrDefaultIfEmpty(); |
| | | 92 | | } |