< Summary

Information
Class: Allyaria.Theming.StyleTypes.StylePosition
Assembly: Allyaria.Theming
File(s): /home/runner/work/allyaria/allyaria/src/Allyaria.Theming/StyleTypes/StylePosition.cs
Line coverage
100%
Covered lines: 12
Uncovered lines: 0
Coverable lines: 12
Total lines: 104
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Parse(...)100%22100%
TryParse(...)100%11100%
op_Implicit(...)100%11100%
op_Implicit(...)100%22100%

File(s)

/home/runner/work/allyaria/allyaria/src/Allyaria.Theming/StyleTypes/StylePosition.cs

#LineLine coverage
 1namespace Allyaria.Theming.StyleTypes;
 2
 3/// <summary>
 4/// Represents a CSS <c>position</c> value within the Allyaria theming system. Provides a strongly typed wrapper for
 5/// defining how an element is positioned in the document layout.
 6/// </summary>
 7public sealed record StylePosition : StyleValueBase
 8{
 9    /// <summary>
 10    /// Initializes a new instance of the <see cref="StylePosition" /> record using the specified <see cref="Kind" /> va
 11    /// </summary>
 12    /// <param name="kind">The position behavior to represent.</param>
 13    public StylePosition(Kind kind)
 3614        : base(value: kind.GetDescription()) { }
 15
 16    /// <summary>Defines the supported CSS <c>position</c> property values.</summary>
 17    public enum Kind
 18    {
 19        /// <summary>
 20        /// Positions the element relative to its nearest positioned ancestor. The element is removed from the normal do
 21        /// flow.
 22        /// </summary>
 23        [Description(description: "absolute")]
 24        Absolute,
 25
 26        /// <summary>
 27        /// Positions the element relative to the viewport. The element remains fixed in the same position even when the
 28        /// scrolled.
 29        /// </summary>
 30        [Description(description: "fixed")]
 31        Fixed,
 32
 33        /// <summary>
 34        /// Positions the element relative to its normal position. Offsets can be applied using <c>top</c>, <c>right</c>
 35        /// <c>bottom</c>, and <c>left</c>.
 36        /// </summary>
 37        [Description(description: "relative")]
 38        Relative,
 39
 40        /// <summary>Uses the normal document flow (default). Offsets have no effect when <c>position: static</c>.</summ
 41        [Description(description: "static")]
 42        Static,
 43
 44        /// <summary>
 45        /// Positions the element based on the user's scroll position. The element toggles between relative and fixed po
 46        /// depending on scroll boundaries.
 47        /// </summary>
 48        [Description(description: "sticky")]
 49        Sticky
 50    }
 51
 52    /// <summary>
 53    /// Parses a string representation of a CSS <c>position</c> value into a <see cref="StylePosition" /> instance.
 54    /// </summary>
 55    /// <param name="value">The string representation of the position value.</param>
 56    /// <returns>A new <see cref="StylePosition" /> instance representing the parsed value.</returns>
 57    /// <exception cref="AryArgumentException">
 58    /// Thrown when the provided <paramref name="value" /> does not correspond to a valid <see cref="Kind" />.
 59    /// </exception>
 60    public static StylePosition Parse(string? value)
 1261        => value.TryParseEnum<Kind>(result: out var kind)
 1262            ? new StylePosition(kind: kind)
 1263            : throw new AryArgumentException(message: $"Invalid style: {value}", argName: nameof(value));
 64
 65    /// <summary>Attempts to parse a string into a <see cref="StylePosition" /> instance.</summary>
 66    /// <param name="value">The string representation of the position value to parse.</param>
 67    /// <param name="result">
 68    /// When this method returns, contains the parsed <see cref="StylePosition" /> instance or <see langword="null" /> i
 69    /// parsing failed.
 70    /// </param>
 71    /// <returns><see langword="true" /> if parsing succeeded; otherwise, <see langword="false" />.</returns>
 72    public static bool TryParse(string? value, out StylePosition? result)
 73    {
 74        try
 75        {
 376            result = Parse(value: value);
 77
 178            return true;
 79        }
 280        catch
 81        {
 282            result = null;
 83
 284            return false;
 85        }
 386    }
 87
 88    /// <summary>Implicitly converts a string into a <see cref="StylePosition" /> instance.</summary>
 89    /// <param name="value">The string representation of the position value.</param>
 90    /// <returns>A <see cref="StylePosition" /> instance representing the provided value.</returns>
 91    /// <exception cref="AryArgumentException">
 92    /// Thrown when the provided string cannot be parsed into a valid
 93    /// <see cref="Kind" />.
 94    /// </exception>
 295    public static implicit operator StylePosition(string? value) => Parse(value: value);
 96
 97    /// <summary>Implicitly converts a <see cref="StylePosition" /> instance to its string representation.</summary>
 98    /// <param name="value">The <see cref="StylePosition" /> instance to convert.</param>
 99    /// <returns>
 100    /// The underlying CSS <c>position</c> string value, or an empty string if <paramref name="value" /> is
 101    /// <see langword="null" />.
 102    /// </returns>
 2103    public static implicit operator string(StylePosition? value) => (value?.Value).OrDefaultIfEmpty();
 104}