Skip to content

Commit

Permalink
feat(components): apply data-slot attribute to all component parts (#…
Browse files Browse the repository at this point in the history
…127)

* feat(accordion): add `data-slot` attributes to all slots of the component(s)

* feat(card): add `data-slot` attribute to all slots of the component(s)

* feat(checkbox): add `data-slot` attribute to all slots of the component

* feat(checkbox-group): add `data-slot` attribute to all slots of the component

* feat(navbar): add `data-slot` attribute to all slots of the component

* feat(radio-group): add `data-slot` attribute to all slots of the components

* feat(switch): add `data-slot` attribute to all slots of the component
  • Loading branch information
desmondinho authored Dec 29, 2024
1 parent 8a103db commit f1ae82e
Show file tree
Hide file tree
Showing 17 changed files with 77 additions and 36 deletions.
4 changes: 3 additions & 1 deletion src/LumexUI/Components/Accordion/LumexAccordionItem.razor
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
</div>
@if( Context.Owner.ShowIndicators )
{
<span class="@IndicatorClass" data-opened="@_expanded">
<span class="@IndicatorClass"
data-slot="indicator"
data-opened="@_expanded">
<LumexIcon Icon="@Indicator(_expanded)" />
</span>
}
Expand Down
4 changes: 2 additions & 2 deletions src/LumexUI/Components/Card/LumexCard.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<CascadingValue TValue="CardContext" Value="@_context" IsFixed="@true">
<LumexComponent Class="@RootClass"
Style="@RootStyle"
@attributes="@AdditionalAttributes"
data-slot="root">
data-slot="base"
@attributes="@AdditionalAttributes">
@ChildContent
</LumexComponent>
</CascadingValue>
4 changes: 2 additions & 2 deletions src/LumexUI/Components/Card/LumexCardBody.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<LumexComponent Class="@RootClass"
Style="@RootStyle"
@attributes="@AdditionalAttributes"
data-slot="body">
data-slot="body"
@attributes="@AdditionalAttributes">
@ChildContent
</LumexComponent>
4 changes: 2 additions & 2 deletions src/LumexUI/Components/Card/LumexCardFooter.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<LumexComponent Class="@RootClass"
Style="@RootStyle"
@attributes="@AdditionalAttributes"
data-slot="footer">
data-slot="footer"
@attributes="@AdditionalAttributes">
@ChildContent
</LumexComponent>
4 changes: 2 additions & 2 deletions src/LumexUI/Components/Card/LumexCardHeader.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<LumexComponent Class="@RootClass"
Style="@RootStyle"
@attributes="@AdditionalAttributes"
data-slot="header">
data-slot="header"
@attributes="@AdditionalAttributes">
@ChildContent
</LumexComponent>
15 changes: 10 additions & 5 deletions src/LumexUI/Components/Checkbox/LumexCheckbox.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
<LumexComponent As="label"
Class="@RootClass"
Style="@RootStyle"
tabindex="0"
data-slot="base"
data-checked="@CurrentValue.ToAttributeValue()"
data-disabled="@GetDisabledState().ToAttributeValue()"
data-readonly="@GetReadOnlyState().ToAttributeValue()"
tabindex="0"
@attributes="@AdditionalAttributes"
@onclick:stopPropagation="@true">
<span class="@WrapperClass">
<span class="@WrapperClass" data-slot="wrapper">
<span class="@StyleUtils.VisuallyHidden">
<input type="checkbox"
value="@true"
Expand All @@ -21,7 +22,9 @@

@if( !string.IsNullOrEmpty( CheckIcon ) )
{
<LumexIcon Icon="@CheckIcon" Class="@IconClass" />
<LumexIcon Icon="@CheckIcon"
Class="@IconClass"
data-slot="icon" />
}
else
{
Expand All @@ -31,7 +34,7 @@

@if( ChildContent is not null )
{
<span class="@LabelClass">
<span class="@LabelClass" data-slot="label">
@ChildContent
</span>
}
Expand All @@ -44,7 +47,9 @@
.Add( "transition", "stroke-dashoffset 0.2s linear 0.15s", when: CurrentValue )
.ToString();

<svg class="@IconClass" viewBox="0 0 17 18">
<svg class="@IconClass"
viewBox="0 0 17 18"
data-slot="icon">
<polyline fill="none"
points="1 9 7 14 15 4"
stroke="currentColor"
Expand Down
15 changes: 11 additions & 4 deletions src/LumexUI/Components/Checkbox/LumexCheckboxGroup.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,26 @@
@inherits LumexComponentBase

<CascadingValue TValue="CheckboxGroupContext" Value="@_context" IsFixed="@true">
<div class="@RootClass" style="@RootStyle" @attributes="@AdditionalAttributes">
<div class="@RootClass"
style="@RootStyle"
data-slot="base"
@attributes="@AdditionalAttributes">
@if( !string.IsNullOrEmpty( Label ) )
{
<span class="@LabelClass">@Label</span>
<span class="@LabelClass" data-slot="label">
@Label
</span>
}

<div class="@WrapperClass">
<div class="@WrapperClass" data-slot="wrapper">
@ChildContent
</div>

@if( !string.IsNullOrEmpty( Description ) )
{
<div class="@DescriptionClass">@Description</div>
<div class="@DescriptionClass" data-slot="description">
@Description
</div>
}
</div>
</CascadingValue>
3 changes: 2 additions & 1 deletion src/LumexUI/Components/Navbar/LumexNavbar.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
<LumexComponent As="@As"
Class="@RootClass"
Style="@RootStyle"
data-slot="base"
@attributes="@AdditionalAttributes">
<nav class="@WrapperClass">
<nav class="@WrapperClass" data-slot="wrapper">
@ChildContent
</nav>
</LumexComponent>
Expand Down
1 change: 1 addition & 0 deletions src/LumexUI/Components/Navbar/LumexNavbarBrand.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<LumexComponent As="@As"
Class="@RootClass"
Style="@RootStyle"
data-slot="brand"
@attributes="@AdditionalAttributes">
@ChildContent
</LumexComponent>
1 change: 1 addition & 0 deletions src/LumexUI/Components/Navbar/LumexNavbarContent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<LumexComponent As="@As"
Class="@RootClass"
Style="@RootStyle"
data-slot="content"
@attributes="@AdditionalAttributes">
@ChildContent
</LumexComponent>
1 change: 1 addition & 0 deletions src/LumexUI/Components/Navbar/LumexNavbarItem.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<LumexComponent As="@As"
Class="@RootClass"
Style="@RootStyle"
data-slot="item"
@attributes="@AdditionalAttributes">
@ChildContent
</LumexComponent>
1 change: 1 addition & 0 deletions src/LumexUI/Components/Navbar/LumexNavbarMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Class="@RootClass"
Style="@RootStyle"
Expanded="@Expanded"
data-slot="menu"
@attributes="@AdditionalAttributes">
@ChildContent
</LumexCollapse>
1 change: 1 addition & 0 deletions src/LumexUI/Components/Navbar/LumexNavbarMenuItem.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<LumexComponent As="@As"
Class="@RootClass"
Style="@RootStyle"
data-slot="menu-item"
@attributes="@AdditionalAttributes">
@ChildContent
</LumexComponent>
1 change: 1 addition & 0 deletions src/LumexUI/Components/Navbar/LumexNavbarMenuToggle.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Class="@RootClass"
Style="@RootStyle"
type="button"
data-slot="toggle-icon"
data-expanded="@Context.Menu?.Expanded"
@attributes="@AdditionalAttributes"
@onclick="@Toggle">
Expand Down
13 changes: 7 additions & 6 deletions src/LumexUI/Components/Radio/LumexRadio.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
<LumexComponent As="label"
Class="@RootClass"
Style="@RootStyle"
tabindex="0"
data-slot="base"
data-selected="@GetSelectedState().ToAttributeValue()"
data-disabled="@GetDisabledState().ToAttributeValue()"
data-readonly="@GetReadOnlyState().ToAttributeValue()"
tabindex="0"
@attributes="@AdditionalAttributes"
@onclick:stopPropagation="@true">
<span class="@StyleUtils.VisuallyHidden">
Expand All @@ -20,21 +21,21 @@
@onchange="@Context.ChangeEventCallback" />
</span>

<span class="@ControlWrapperClass">
<span class="@ControlClass" data-slot="control"></span>
<span class="@ControlWrapperClass" data-slot="wrapper">
<span class="@ControlClass" data-slot="control" />
</span>

<div class="@LabelWrapperClass">
<div class="@LabelWrapperClass" data-slot="label-wrapper">
@if (ChildContent is not null)
{
<span class="@LabelClass">
<span class="@LabelClass" data-slot="label">
@ChildContent
</span>
}

@if (Description is not null)
{
<span class="@DescriptionClass">
<span class="@DescriptionClass" data-slot="description">
@Description
</span>
}
Expand Down
17 changes: 13 additions & 4 deletions src/LumexUI/Components/Radio/LumexRadioGroup.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,28 @@ Note that we must not set IsFixed=true on the CascadingValue, because the mutati
are what cause the descendant InputRadio components to re-render themselves
*@
<CascadingValue Value="@_context" Name="Context" TValue="RadioGroupContext<TValue>">
<div class="@RootClass" style="@RootStyle" @attributes="@AdditionalAttributes">
<div class="@RootClass"
style="@RootStyle"
data-slot="base"
@attributes="@AdditionalAttributes">
@if( !string.IsNullOrEmpty( Label ) )
{
<span class="@LabelClass">@Label</span>
<span class="@LabelClass" data-slot="label">
@Label
</span>
}

<div class="@WrapperClass" data-orientation="@(Orientation.ToString().ToLowerInvariant())">
<div class="@WrapperClass"
data-slot="wrapper"
data-orientation="@Orientation.ToString().ToLowerInvariant()">
@ChildContent
</div>

@if( !string.IsNullOrEmpty( Description ) )
{
<div class="@DescriptionClass">@Description</div>
<div class="@DescriptionClass" data-slot="description">
@Description
</div>
}
</div>
</CascadingValue>
24 changes: 17 additions & 7 deletions src/LumexUI/Components/Switch/LumexSwitch.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
<LumexComponent As="label"
Class="@RootClass"
Style="@RootStyle"
tabindex="0"
data-slot="base"
data-checked="@CurrentValue.ToAttributeValue()"
data-disabled="@GetDisabledState().ToAttributeValue()"
data-readonly="@GetReadOnlyState().ToAttributeValue()"
tabindex="0"
@attributes="@AdditionalAttributes">
<span class="@StyleUtils.VisuallyHidden">
<input type="checkbox"
Expand All @@ -17,31 +18,40 @@
@onchange="@OnChangeAsync" />
</span>

<span class="@WrapperClass">
<span class="@WrapperClass" data-slot="wrapper">
@if( !string.IsNullOrEmpty( StartIcon ) )
{
<LumexIcon Icon="@StartIcon" Size="@(new("1em"))" Class="@StartIconClass" />
<LumexIcon Icon="@StartIcon"
Size="@(new("1em"))"
Class="@StartIconClass"
data-slot="start-icon" />
}

<span class="@ThumbClass">
<span class="@ThumbClass" data-slot="thumb">
@{
var thumbIcon = ThumbIcon?.Invoke( CurrentValue );
if( !string.IsNullOrEmpty( thumbIcon ) )
{
<LumexIcon Icon="@thumbIcon" Size="@(new("100%"))" Class="@ThumbIconClass" />
<LumexIcon Icon="@thumbIcon"
Size="@(new("100%"))"
Class="@ThumbIconClass"
data-slot="thumb-icon" />
}
}
</span>

@if( !string.IsNullOrEmpty( EndIcon ) )
{
<LumexIcon Icon="@EndIcon" Size="@(new("1em"))" Class="@EndIconClass" />
<LumexIcon Icon="@EndIcon"
Size="@(new("1em"))"
Class="@EndIconClass"
data-slot="end-icon" />
}
</span>

@if( ChildContent is not null )
{
<span class="@LabelClass">
<span class="@LabelClass" data-slot="label">
@ChildContent
</span>
}
Expand Down

0 comments on commit f1ae82e

Please sign in to comment.