< Summary

Information
Class: Allyaria.Theming.StyleTypes.StyleScrollBehavior
Assembly: Allyaria.Theming
File(s): /home/runner/work/allyaria/allyaria/src/Allyaria.Theming/StyleTypes/StyleScrollBehavior.cs
Line coverage
100%
Covered lines: 12
Uncovered lines: 0
Coverable lines: 12
Total lines: 82
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/StyleScrollBehavior.cs

#LineLine coverage
 1namespace Allyaria.Theming.StyleTypes;
 2
 3/// <summary>
 4/// Represents a CSS <c>scroll-behavior</c> value within the Allyaria theming system. Provides a strongly typed wrapper 
 5/// controlling the scrolling animation behavior for in-page navigation and programmatic scrolls.
 6/// </summary>
 7public sealed record StyleScrollBehavior : StyleValueBase
 8{
 9    /// <summary>
 10    /// Initializes a new instance of the <see cref="StyleScrollBehavior" /> record using the specified <see cref="Kind"
 11    /// value.
 12    /// </summary>
 13    /// <param name="kind">The scroll behavior kind to represent.</param>
 14    public StyleScrollBehavior(Kind kind)
 5015        : base(value: kind.GetDescription()) { }
 16
 17    /// <summary>Defines the supported CSS <c>scroll-behavior</c> property values.</summary>
 18    public enum Kind
 19    {
 20        /// <summary>Uses the default instant scrolling behavior without animation.</summary>
 21        [Description(description: "auto")]
 22        Auto,
 23
 24        /// <summary>Enables smooth animated scrolling behavior for in-page navigation or element scrolling.</summary>
 25        [Description(description: "smooth")]
 26        Smooth
 27    }
 28
 29    /// <summary>
 30    /// Parses a string representation of a CSS <c>scroll-behavior</c> value into a <see cref="StyleScrollBehavior" />
 31    /// instance.
 32    /// </summary>
 33    /// <param name="value">The string representation of the scroll-behavior value.</param>
 34    /// <returns>A new <see cref="StyleScrollBehavior" /> instance representing the parsed value.</returns>
 35    /// <exception cref="AryArgumentException">
 36    /// Thrown when the provided <paramref name="value" /> does not correspond to a valid <see cref="Kind" />.
 37    /// </exception>
 38    public static StyleScrollBehavior Parse(string? value)
 939        => value.TryParseEnum<Kind>(result: out var kind)
 940            ? new StyleScrollBehavior(kind: kind)
 941            : throw new AryArgumentException(message: $"Invalid style: {value}", argName: nameof(value));
 42
 43    /// <summary>Attempts to parse a string into a <see cref="StyleScrollBehavior" /> instance.</summary>
 44    /// <param name="value">The string representation of the scroll-behavior value to parse.</param>
 45    /// <param name="result">
 46    /// When this method returns, contains the parsed <see cref="StyleScrollBehavior" /> instance or <see langword="null
 47    /// parsing failed.
 48    /// </param>
 49    /// <returns><see langword="true" /> if parsing succeeded; otherwise, <see langword="false" />.</returns>
 50    public static bool TryParse(string? value, out StyleScrollBehavior? result)
 51    {
 52        try
 53        {
 354            result = Parse(value: value);
 55
 156            return true;
 57        }
 258        catch
 59        {
 260            result = null;
 61
 262            return false;
 63        }
 364    }
 65
 66    /// <summary>Implicitly converts a string into a <see cref="StyleScrollBehavior" /> instance.</summary>
 67    /// <param name="value">The string representation of the scroll-behavior value.</param>
 68    /// <returns>A <see cref="StyleScrollBehavior" /> instance representing the provided value.</returns>
 69    /// <exception cref="AryArgumentException">
 70    /// Thrown when the provided string cannot be parsed into a valid
 71    /// <see cref="Kind" />.
 72    /// </exception>
 273    public static implicit operator StyleScrollBehavior(string? value) => Parse(value: value);
 74
 75    /// <summary>Implicitly converts a <see cref="StyleScrollBehavior" /> instance to its string representation.</summar
 76    /// <param name="value">The <see cref="StyleScrollBehavior" /> instance to convert.</param>
 77    /// <returns>
 78    /// The underlying CSS <c>scroll-behavior</c> string value, or an empty string if <paramref name="value" /> is
 79    /// <see langword="null" />.
 80    /// </returns>
 281    public static implicit operator string(StyleScrollBehavior? value) => (value?.Value).OrDefaultIfEmpty();
 82}