| | | 1 | | namespace Allyaria.Theming.StyleTypes; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Represents a CSS <c>display</c> value within the Allyaria theming system. Provides a strongly typed wrapper for comm |
| | | 5 | | /// CSS display keywords controlling element layout behavior. |
| | | 6 | | /// </summary> |
| | | 7 | | public sealed record StyleDisplay : StyleValueBase |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// Initializes a new instance of the <see cref="StyleDisplay" /> record using the specified display <see cref="Kind |
| | | 11 | | /// </summary> |
| | | 12 | | /// <param name="kind">The display kind that determines how the element is rendered in the layout.</param> |
| | | 13 | | public StyleDisplay(Kind kind) |
| | 126 | 14 | | : base(value: kind.GetDescription()) { } |
| | | 15 | | |
| | | 16 | | /// <summary>Defines the supported CSS <c>display</c> property values.</summary> |
| | | 17 | | public enum Kind |
| | | 18 | | { |
| | | 19 | | /// <summary>The element generates a block-level box (starts on a new line, full width by default).</summary> |
| | | 20 | | [Description(description: "block")] |
| | | 21 | | Block, |
| | | 22 | | |
| | | 23 | | /// <summary>The element behaves as a flexible container using the Flexbox layout model.</summary> |
| | | 24 | | [Description(description: "flex")] |
| | | 25 | | Flex, |
| | | 26 | | |
| | | 27 | | /// <summary>Creates a block-level box that establishes a new block formatting context.</summary> |
| | | 28 | | [Description(description: "flow-root")] |
| | | 29 | | FlowRoot, |
| | | 30 | | |
| | | 31 | | /// <summary>The element behaves as a grid container using the CSS Grid layout model.</summary> |
| | | 32 | | [Description(description: "grid")] |
| | | 33 | | Grid, |
| | | 34 | | |
| | | 35 | | /// <summary>The element generates one or more inline-level boxes that do not start on a new line.</summary> |
| | | 36 | | [Description(description: "inline")] |
| | | 37 | | Inline, |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// The element behaves as an inline-level block container (flows inline but accepts block properties). |
| | | 41 | | /// </summary> |
| | | 42 | | [Description(description: "inline-block")] |
| | | 43 | | InlineBlock, |
| | | 44 | | |
| | | 45 | | /// <summary>The element behaves as an inline-level flex container.</summary> |
| | | 46 | | [Description(description: "inline-flex")] |
| | | 47 | | InlineFlex, |
| | | 48 | | |
| | | 49 | | /// <summary>The element behaves as an inline-level grid container.</summary> |
| | | 50 | | [Description(description: "inline-grid")] |
| | | 51 | | InlineGrid, |
| | | 52 | | |
| | | 53 | | /// <summary>The element behaves as an inline-level table container.</summary> |
| | | 54 | | [Description(description: "inline-table")] |
| | | 55 | | InlineTable, |
| | | 56 | | |
| | | 57 | | /// <summary>The element behaves as a list item with a marker box (e.g., a bullet).</summary> |
| | | 58 | | [Description(description: "list-item")] |
| | | 59 | | ListItem, |
| | | 60 | | |
| | | 61 | | /// <summary>The element is not displayed and takes up no layout space.</summary> |
| | | 62 | | [Description(description: "none")] |
| | | 63 | | None, |
| | | 64 | | |
| | | 65 | | /// <summary>The element behaves as a block-level table.</summary> |
| | | 66 | | [Description(description: "table")] |
| | | 67 | | Table, |
| | | 68 | | |
| | | 69 | | /// <summary>The element behaves as a table caption.</summary> |
| | | 70 | | [Description(description: "table-caption")] |
| | | 71 | | TableCaption, |
| | | 72 | | |
| | | 73 | | /// <summary>The element behaves as a table cell.</summary> |
| | | 74 | | [Description(description: "table-cell")] |
| | | 75 | | TableCell, |
| | | 76 | | |
| | | 77 | | /// <summary>The element behaves as a table column.</summary> |
| | | 78 | | [Description(description: "table-column")] |
| | | 79 | | TableColumn, |
| | | 80 | | |
| | | 81 | | /// <summary>The element behaves as a group of table columns.</summary> |
| | | 82 | | [Description(description: "table-column-group")] |
| | | 83 | | TableColumnGroup, |
| | | 84 | | |
| | | 85 | | /// <summary>The element behaves as a group of table footer rows.</summary> |
| | | 86 | | [Description(description: "table-footer-group")] |
| | | 87 | | TableFooterGroup, |
| | | 88 | | |
| | | 89 | | /// <summary>The element behaves as a group of table header rows.</summary> |
| | | 90 | | [Description(description: "table-header-group")] |
| | | 91 | | TableHeaderGroup, |
| | | 92 | | |
| | | 93 | | /// <summary>The element behaves as a single table row.</summary> |
| | | 94 | | [Description(description: "table-row")] |
| | | 95 | | TableRow, |
| | | 96 | | |
| | | 97 | | /// <summary>The element behaves as a group of table rows.</summary> |
| | | 98 | | [Description(description: "table-row-group")] |
| | | 99 | | TableRowGroup |
| | | 100 | | } |
| | | 101 | | |
| | | 102 | | /// <summary> |
| | | 103 | | /// Parses a string representation of a CSS <c>display</c> value into a <see cref="StyleDisplay" /> instance. |
| | | 104 | | /// </summary> |
| | | 105 | | /// <param name="value">The string representation of the display value.</param> |
| | | 106 | | /// <returns>A new <see cref="StyleDisplay" /> instance representing the parsed value.</returns> |
| | | 107 | | /// <exception cref="AryArgumentException"> |
| | | 108 | | /// Thrown when the provided <paramref name="value" /> does not correspond to a valid <see cref="Kind" />. |
| | | 109 | | /// </exception> |
| | | 110 | | public static StyleDisplay Parse(string? value) |
| | 27 | 111 | | => value.TryParseEnum<Kind>(result: out var kind) |
| | 27 | 112 | | ? new StyleDisplay(kind: kind) |
| | 27 | 113 | | : throw new AryArgumentException(message: $"Invalid style: {value}", argName: nameof(value)); |
| | | 114 | | |
| | | 115 | | /// <summary>Attempts to parse a string into a <see cref="StyleDisplay" /> instance.</summary> |
| | | 116 | | /// <param name="value">The string value to parse.</param> |
| | | 117 | | /// <param name="result"> |
| | | 118 | | /// When this method returns, contains the parsed <see cref="StyleDisplay" /> instance or <see langword="null" /> if |
| | | 119 | | /// parsing failed. |
| | | 120 | | /// </param> |
| | | 121 | | /// <returns><see langword="true" /> if parsing succeeded; otherwise, <see langword="false" />.</returns> |
| | | 122 | | public static bool TryParse(string? value, out StyleDisplay? result) |
| | | 123 | | { |
| | | 124 | | try |
| | | 125 | | { |
| | 3 | 126 | | result = Parse(value: value); |
| | | 127 | | |
| | 1 | 128 | | return true; |
| | | 129 | | } |
| | 2 | 130 | | catch |
| | | 131 | | { |
| | 2 | 132 | | result = null; |
| | | 133 | | |
| | 2 | 134 | | return false; |
| | | 135 | | } |
| | 3 | 136 | | } |
| | | 137 | | |
| | | 138 | | /// <summary>Implicitly converts a string into a <see cref="StyleDisplay" /> instance.</summary> |
| | | 139 | | /// <param name="value">The string representation of the display value.</param> |
| | | 140 | | /// <returns>A <see cref="StyleDisplay" /> instance representing the provided value.</returns> |
| | | 141 | | /// <exception cref="AryArgumentException"> |
| | | 142 | | /// Thrown when the provided string cannot be parsed into a valid |
| | | 143 | | /// <see cref="Kind" />. |
| | | 144 | | /// </exception> |
| | 2 | 145 | | public static implicit operator StyleDisplay(string? value) => Parse(value: value); |
| | | 146 | | |
| | | 147 | | /// <summary>Implicitly converts a <see cref="StyleDisplay" /> instance to its string representation.</summary> |
| | | 148 | | /// <param name="value">The <see cref="StyleDisplay" /> instance to convert.</param> |
| | | 149 | | /// <returns> |
| | | 150 | | /// The underlying CSS <c>display</c> string value, or an empty string if <paramref name="value" /> is |
| | | 151 | | /// <see langword="null" />. |
| | | 152 | | /// </returns> |
| | 2 | 153 | | public static implicit operator string(StyleDisplay? value) => (value?.Value).OrDefaultIfEmpty(); |
| | | 154 | | } |