| | | 1 | | namespace Allyaria.Theming.StyleTypes; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Represents a CSS <c>border-style</c> or <c>outline-style</c> value used within the Allyaria theming system. Provides |
| | | 5 | | /// strongly typed wrapper around standard CSS line style keywords (e.g., solid, dashed, dotted). |
| | | 6 | | /// </summary> |
| | | 7 | | public sealed record StyleBorderOutlineStyle : StyleValueBase |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// Initializes a new instance of the <see cref="StyleBorderOutlineStyle" /> record using the specified border or ou |
| | | 11 | | /// style kind. |
| | | 12 | | /// </summary> |
| | | 13 | | /// <param name="kind">The border or outline style kind to represent.</param> |
| | | 14 | | public StyleBorderOutlineStyle(Kind kind) |
| | 98 | 15 | | : base(value: kind.GetDescription()) { } |
| | | 16 | | |
| | | 17 | | /// <summary>Defines the supported CSS <c>border-style</c> and <c>outline-style</c> values.</summary> |
| | | 18 | | public enum Kind |
| | | 19 | | { |
| | | 20 | | /// <summary>Specifies a dashed line style.</summary> |
| | | 21 | | [Description(description: "dashed")] |
| | | 22 | | Dashed, |
| | | 23 | | |
| | | 24 | | /// <summary>Specifies a dotted line style.</summary> |
| | | 25 | | [Description(description: "dotted")] |
| | | 26 | | Dotted, |
| | | 27 | | |
| | | 28 | | /// <summary>Specifies a double-line border style.</summary> |
| | | 29 | | [Description(description: "double")] |
| | | 30 | | Double, |
| | | 31 | | |
| | | 32 | | /// <summary>Specifies a 3D grooved border style that appears carved into the page.</summary> |
| | | 33 | | [Description(description: "groove")] |
| | | 34 | | Groove, |
| | | 35 | | |
| | | 36 | | /// <summary>Specifies an inset 3D border style that appears embedded.</summary> |
| | | 37 | | [Description(description: "inset")] |
| | | 38 | | Inset, |
| | | 39 | | |
| | | 40 | | /// <summary>Specifies that no border or outline is drawn.</summary> |
| | | 41 | | [Description(description: "none")] |
| | | 42 | | None, |
| | | 43 | | |
| | | 44 | | /// <summary>Specifies an outset 3D border style that appears raised.</summary> |
| | | 45 | | [Description(description: "outset")] |
| | | 46 | | Outset, |
| | | 47 | | |
| | | 48 | | /// <summary>Specifies a 3D ridged border style that appears raised from the surface.</summary> |
| | | 49 | | [Description(description: "ridge")] |
| | | 50 | | Ridge, |
| | | 51 | | |
| | | 52 | | /// <summary>Specifies a single solid line border or outline.</summary> |
| | | 53 | | [Description(description: "solid")] |
| | | 54 | | Solid |
| | | 55 | | } |
| | | 56 | | |
| | | 57 | | /// <summary> |
| | | 58 | | /// Parses a string representation of a CSS <c>border-style</c> or <c>outline-style</c> value into a |
| | | 59 | | /// <see cref="StyleBorderOutlineStyle" /> instance. |
| | | 60 | | /// </summary> |
| | | 61 | | /// <param name="value">The string representation of the style value.</param> |
| | | 62 | | /// <returns>A new <see cref="StyleBorderOutlineStyle" /> instance representing the parsed value.</returns> |
| | | 63 | | /// <exception cref="AryArgumentException"> |
| | | 64 | | /// Thrown when the provided <paramref name="value" /> does not correspond to a valid <see cref="Kind" />. |
| | | 65 | | /// </exception> |
| | | 66 | | public static StyleBorderOutlineStyle Parse(string? value) |
| | 16 | 67 | | => value.TryParseEnum<Kind>(result: out var kind) |
| | 16 | 68 | | ? new StyleBorderOutlineStyle(kind: kind) |
| | 16 | 69 | | : throw new AryArgumentException(message: $"Invalid style: {value}", argName: nameof(value)); |
| | | 70 | | |
| | | 71 | | /// <summary>Attempts to parse a string into a <see cref="StyleBorderOutlineStyle" /> instance.</summary> |
| | | 72 | | /// <param name="value">The string representation of the border or outline style to parse.</param> |
| | | 73 | | /// <param name="result"> |
| | | 74 | | /// When this method returns, contains the parsed <see cref="StyleBorderOutlineStyle" /> instance or |
| | | 75 | | /// <see langword="null" /> if parsing failed. |
| | | 76 | | /// </param> |
| | | 77 | | /// <returns><see langword="true" /> if parsing succeeded; otherwise, <see langword="false" />.</returns> |
| | | 78 | | public static bool TryParse(string? value, out StyleBorderOutlineStyle? result) |
| | | 79 | | { |
| | | 80 | | try |
| | | 81 | | { |
| | 3 | 82 | | result = Parse(value: value); |
| | | 83 | | |
| | 1 | 84 | | return true; |
| | | 85 | | } |
| | 2 | 86 | | catch |
| | | 87 | | { |
| | 2 | 88 | | result = null; |
| | | 89 | | |
| | 2 | 90 | | return false; |
| | | 91 | | } |
| | 3 | 92 | | } |
| | | 93 | | |
| | | 94 | | /// <summary>Implicitly converts a string into a <see cref="StyleBorderOutlineStyle" /> instance.</summary> |
| | | 95 | | /// <param name="value">The string representation of the border or outline style.</param> |
| | | 96 | | /// <returns>A <see cref="StyleBorderOutlineStyle" /> instance representing the provided value.</returns> |
| | | 97 | | /// <exception cref="AryArgumentException"> |
| | | 98 | | /// Thrown when the string cannot be parsed into a valid border or outline style |
| | | 99 | | /// kind. |
| | | 100 | | /// </exception> |
| | 2 | 101 | | public static implicit operator StyleBorderOutlineStyle(string? value) => Parse(value: value); |
| | | 102 | | |
| | | 103 | | /// <summary>Implicitly converts a <see cref="StyleBorderOutlineStyle" /> instance to its string value.</summary> |
| | | 104 | | /// <param name="value">The <see cref="StyleBorderOutlineStyle" /> instance to convert.</param> |
| | | 105 | | /// <returns> |
| | | 106 | | /// The underlying CSS border or outline style string, or an empty string if <paramref name="value" /> is |
| | | 107 | | /// <see langword="null" />. |
| | | 108 | | /// </returns> |
| | 2 | 109 | | public static implicit operator string(StyleBorderOutlineStyle? value) => (value?.Value).OrDefaultIfEmpty(); |
| | | 110 | | } |