Skip to content

Commit 5dd42e2

Browse files
committed
feat: allow customizing Label component, add Em and Strong elemental components
1 parent fd21bd4 commit 5dd42e2

File tree

4 files changed

+59
-8
lines changed

4 files changed

+59
-8
lines changed

packages/common/CommonLabel.svelte

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<span
1+
<svelte:component
2+
this={component}
23
bind:this={element}
3-
use:useActions={use}
4-
use:forwardEvents
4+
use={[forwardEvents, ...use]}
55
class={classMap({
66
[className]: true,
77
'mdc-button__label': context === 'button',
@@ -18,13 +18,14 @@
1818
})}
1919
{...context === 'snackbar' ? { 'aria-atomic': 'false' } : {}}
2020
{tabindex}
21-
{...$$restProps}><slot /></span
21+
{...$$restProps}><slot /></svelte:component
2222
>
2323

2424
<script>
2525
import { getContext } from 'svelte';
2626
import { get_current_component } from 'svelte/internal';
2727
import { forwardEventsBuilder, classMap, useActions } from './internal.js';
28+
import Span from './Span.svelte';
2829
2930
const forwardEvents = forwardEventsBuilder(get_current_component());
3031
@@ -34,10 +35,12 @@
3435
3536
let element;
3637
38+
export let component = Span;
39+
3740
const context = getContext('SMUI:label:context');
3841
const tabindex = getContext('SMUI:label:tabindex');
3942
4043
export function getElement() {
41-
return element;
44+
return element.getElement();
4245
}
4346
</script>

packages/common/Em.svelte

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<em bind:this={element} use:useActions={use} use:forwardEvents {...$$restProps}
2+
><slot /></em
3+
>
4+
5+
<script>
6+
import { get_current_component } from 'svelte/internal';
7+
import { forwardEventsBuilder, useActions } from './internal.js';
8+
9+
export let use = [];
10+
11+
const forwardEvents = forwardEventsBuilder(get_current_component());
12+
13+
let element = null;
14+
15+
export function getElement() {
16+
return element;
17+
}
18+
</script>

packages/common/README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ The common label is used everywhere that exports a `Label` component.
2020

2121
### Props / Defaults
2222

23+
- `component`: `Span` - A component to use as the root element.
2324
- `use`: `[]` - An array of Svelte actions and/or arrays of an action and its options.
2425
- `class`: `''` - A CSS class string.
2526

@@ -83,6 +84,10 @@ An elemental component for the `button` tag.
8384

8485
An elemental component for the `div` tag.
8586

87+
## Em.svelte
88+
89+
An elemental component for the `em` tag.
90+
8691
## Footer.svelte
8792

8893
An elemental component for the `footer` tag.
@@ -147,6 +152,10 @@ An elemental component for the `section` tag.
147152

148153
An elemental component for the `span` tag.
149154

155+
## Strong.svelte
156+
157+
An elemental component for the `strong` tag.
158+
150159
## Svg.svelte
151160

152161
An elemental component for the `svg` tag.
@@ -392,7 +401,7 @@ An action that takes actions and runs them on the element. Used to allow actions
392401
</div>
393402
394403
<script>
395-
import { useActions } from './internal.js';
404+
import { useActions } from '@smui/common/internal.js';
396405
397406
export let use = [];
398407
</script>
@@ -407,7 +416,7 @@ An action that takes actions and runs them on the element. Used to allow actions
407416
408417
<script>
409418
import MyComponent from './MyComponent.svelte';
410-
import SomeAction from './SomeAction.svelte';
411-
import SomeOtherAction from './SomeOtherAction.svelte';
419+
import SomeAction from './SomeAction.js';
420+
import SomeOtherAction from './SomeOtherAction.js';
412421
</script>
413422
```

packages/common/Strong.svelte

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<strong
2+
bind:this={element}
3+
use:useActions={use}
4+
use:forwardEvents
5+
{...$$restProps}><slot /></strong
6+
>
7+
8+
<script>
9+
import { get_current_component } from 'svelte/internal';
10+
import { forwardEventsBuilder, useActions } from './internal.js';
11+
12+
export let use = [];
13+
14+
const forwardEvents = forwardEventsBuilder(get_current_component());
15+
16+
let element = null;
17+
18+
export function getElement() {
19+
return element;
20+
}
21+
</script>

0 commit comments

Comments
 (0)