Files
decePubClient/Components/Daisy/DComponentBase.cs
T

27 lines
1.1 KiB
C#
Raw Normal View History

using Microsoft.AspNetCore.Components;
namespace decePubClient.Components.Daisy;
/// <summary>
/// Base of the daisyUI wrappers. A consumer's <c>class</c> lands in <see cref="Class"/> and is appended after the
/// component's own classes; every other unmatched attribute is passed through to the root element.
/// </summary>
public abstract class DComponentBase : ComponentBase
{
[Parameter] public string Class { get; set; }
[Parameter(CaptureUnmatchedValues = true)] public IReadOnlyDictionary<string, object> AdditionalAttributes { get; set; }
protected static string Cx(params string[] classes) => DCx.Join(classes);
}
public static class DCx
{
/// <summary>
/// Joins the non-empty class names. Every daisyUI class handed to it must be written out whole somewhere in the
/// source, e.g. a switch arm <c>DColor.Primary => "btn-primary"</c>, never assembled like <c>"btn-" + color</c>:
/// Tailwind generates only the classes it finds in .razor and .cs files.
/// </summary>
public static string Join(params string[] classes) =>
string.Join(' ', classes.Where(c => !string.IsNullOrWhiteSpace(c)));
}