@lofid/web 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +85 -2
- package/custom-elements.json +11166 -0
- package/dist/index.d.ts +2784 -0
- package/dist/index.js +18710 -0
- package/dist/index.js.map +1 -0
- package/dist/styles/ag-grid.css +145 -0
- package/dist/styles/motion.css +32 -0
- package/dist/styles/motion.tokens.json +38 -0
- package/dist/styles/vars.css +870 -0
- package/package.json +44 -4
- package/readmes/lof-accordion/README.md +140 -0
- package/readmes/lof-alert/README.md +142 -0
- package/readmes/lof-autocomplete/README.md +209 -0
- package/readmes/lof-avatar/README.md +228 -0
- package/readmes/lof-badge/README.md +102 -0
- package/readmes/lof-breadcrumb/README.md +97 -0
- package/readmes/lof-button/README.md +190 -0
- package/readmes/lof-calendar/README.md +111 -0
- package/readmes/lof-card/README.md +75 -0
- package/readmes/lof-cardmedia/README.md +100 -0
- package/readmes/lof-carousel/README.md +187 -0
- package/readmes/lof-checkbox/README.md +159 -0
- package/readmes/lof-chip/README.md +141 -0
- package/readmes/lof-container/README.md +107 -0
- package/readmes/lof-date-picker/README.md +221 -0
- package/readmes/lof-divider/README.md +88 -0
- package/readmes/lof-drawer/README.md +188 -0
- package/readmes/lof-kbd/README.md +188 -0
- package/readmes/lof-layout/README.md +122 -0
- package/readmes/lof-menu/README.md +187 -0
- package/readmes/lof-menubar/README.md +218 -0
- package/readmes/lof-otp/README.md +167 -0
- package/readmes/lof-pagination/README.md +141 -0
- package/readmes/lof-popover/README.md +220 -0
- package/readmes/lof-progress/README.md +88 -0
- package/readmes/lof-radio/README.md +142 -0
- package/readmes/lof-range-picker/README.md +194 -0
- package/readmes/lof-resizable/README.md +220 -0
- package/readmes/lof-segmented-button/README.md +158 -0
- package/readmes/lof-select/README.md +193 -0
- package/readmes/lof-sheet/README.md +170 -0
- package/readmes/lof-signature-pad/README.md +161 -0
- package/readmes/lof-skeleton/README.md +104 -0
- package/readmes/lof-slider/README.md +140 -0
- package/readmes/lof-snackbar/README.md +170 -0
- package/readmes/lof-split-button/README.md +129 -0
- package/readmes/lof-stepper/README.md +171 -0
- package/readmes/lof-switch/README.md +122 -0
- package/readmes/lof-tab/README.md +184 -0
- package/readmes/lof-textfield/README.md +206 -0
- package/readmes/lof-time-picker/README.md +188 -0
- package/readmes/lof-toast/README.md +174 -0
- package/readmes/lof-tooltip/README.md +120 -0
- package/readmes/lof-tree/README.md +157 -0
- package/readmes/lof-upload/README.md +223 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# lof-stepper
|
|
2
|
+
|
|
3
|
+
A multi-step progress indicator implementing the Figma "Stepper" component: its `Type` axis (default, dot, number, icon indicators), its `Typel` label-placement axis (top, centered, inverted), two sizes and both orientations. Each entry in `steps` renders as a focusable step with a circular indicator, a label and a connector to the next step, styled by its status (`done`, `progress`, `disabled`). Use it to show where the user is in a linear flow (checkout, onboarding, a wizard) and to let them jump back to completed steps; the component is presentation only — it never changes a step's status itself, so drive `steps` from your own state.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```html
|
|
8
|
+
<!-- Horizontal (default), labels under the indicators -->
|
|
9
|
+
<lof-stepper id="checkout"></lof-stepper>
|
|
10
|
+
<script>
|
|
11
|
+
document.getElementById('checkout').steps = [
|
|
12
|
+
{ title: 'Cart', status: 'done' },
|
|
13
|
+
{ title: 'Work', status: 'progress' },
|
|
14
|
+
{ title: 'Payment', status: 'disabled' },
|
|
15
|
+
{ title: 'Confirmation', status: 'disabled' }
|
|
16
|
+
];
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<!-- Vertical, label beside the indicator (Figma Type = Centered).
|
|
20
|
+
`size` is DEPRECATED and deliberately omitted: Figma has no Size axis on the
|
|
21
|
+
Stepper — the connector geometry is fixed — so it was a code-only scale. It is
|
|
22
|
+
still accepted so existing markup keeps working, but it now resolves to the one
|
|
23
|
+
Figma geometry and logs a one-time notice. Retune with
|
|
24
|
+
`--lof-stepper-connector-length` instead. -->
|
|
25
|
+
<lof-stepper id="onboarding" orientation="vertical" label-placement="centered"></lof-stepper>
|
|
26
|
+
<script>
|
|
27
|
+
document.getElementById('onboarding').steps = [
|
|
28
|
+
{ title: 'Create account', status: 'done' },
|
|
29
|
+
{ title: 'Verify email', status: 'done' },
|
|
30
|
+
{ title: 'Set up profile', status: 'progress' },
|
|
31
|
+
{ title: 'Done', status: 'disabled' }
|
|
32
|
+
];
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
<!-- Figma Type axis: dot / number / icon indicators -->
|
|
36
|
+
<lof-stepper type="dot" steps='[{"title":"Plan","status":"done"},{"title":"Build","status":"progress"},{"title":"Ship","status":"disabled"}]'></lof-stepper>
|
|
37
|
+
<lof-stepper type="number" steps='[{"title":"Plan","status":"done"},{"title":"Build","status":"progress"},{"title":"Ship","status":"disabled"}]'></lof-stepper>
|
|
38
|
+
<lof-stepper type="icon" steps='[{"title":"Plan","status":"done"},{"title":"Build","status":"progress"},{"title":"Ship","status":"disabled"}]'></lof-stepper>
|
|
39
|
+
|
|
40
|
+
<!-- Figma .Line Types axis: the CONNECTOR between steps, dashed 2px on / 2px off.
|
|
41
|
+
Distinct from type="dot" above, which is the indicator disc — combine freely. -->
|
|
42
|
+
<lof-stepper connector="dot" steps='[{"title":"Plan","status":"done"},{"title":"Build","status":"progress"},{"title":"Ship","status":"disabled"}]'></lof-stepper>
|
|
43
|
+
<lof-stepper connector="dot" type="dot" steps='[{"title":"Plan","status":"done"},{"title":"Build","status":"progress"},{"title":"Ship","status":"disabled"}]'></lof-stepper>
|
|
44
|
+
|
|
45
|
+
<!-- Label placement (Figma Typel): top-aligned beside the indicator, or indicator above the label -->
|
|
46
|
+
<lof-stepper orientation="vertical" label-placement="top" steps='[{"title":"Review","status":"done"},{"title":"Approve","status":"progress"}]'></lof-stepper>
|
|
47
|
+
<lof-stepper label-placement="inverted" steps='[{"title":"Review","status":"done"},{"title":"Approve","status":"progress"}]'></lof-stepper>
|
|
48
|
+
|
|
49
|
+
<!-- Let users jump back to a completed step -->
|
|
50
|
+
<lof-stepper id="wizard"></lof-stepper>
|
|
51
|
+
<script>
|
|
52
|
+
const wizard = document.getElementById('wizard');
|
|
53
|
+
wizard.steps = [
|
|
54
|
+
{ title: 'Select', status: 'done' },
|
|
55
|
+
{ title: 'Configure', status: 'progress' },
|
|
56
|
+
{ title: 'Review', status: 'disabled' }
|
|
57
|
+
];
|
|
58
|
+
wizard.addEventListener('lof-step-change', (e) => {
|
|
59
|
+
console.log('Activated step', e.detail.index, e.detail.step.title);
|
|
60
|
+
// Recompute statuses and assign a new array so the stepper re-renders
|
|
61
|
+
wizard.steps = wizard.steps.map((s, i) => ({
|
|
62
|
+
...s,
|
|
63
|
+
status: i < e.detail.index ? 'done' : i === e.detail.index ? 'progress' : 'disabled'
|
|
64
|
+
}));
|
|
65
|
+
});
|
|
66
|
+
</script>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Deprecated aliases
|
|
70
|
+
|
|
71
|
+
```html
|
|
72
|
+
<!-- textalign="right" → label-placement="centered"; textalign="below" → label-placement="inverted".
|
|
73
|
+
Still supported and still the fallback when label-placement is unset. Since 1.4.9 a
|
|
74
|
+
non-default value logs a one-time console notice; it had been marked deprecated since the
|
|
75
|
+
rename but never said so at runtime. Setting label-placement supersedes it and stays silent. -->
|
|
76
|
+
<lof-stepper textalign="right" steps='[{"title":"Review","status":"done"},{"title":"Approve","status":"progress"}]'></lof-stepper>
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
The `Step` type and the `StepStatus`, `StepperType`, `StepperConnector` and `LabelPlacement` unions are exported from the package:
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import type { Step } from '@lofid/web';
|
|
83
|
+
|
|
84
|
+
const steps: Step[] = [
|
|
85
|
+
{ title: 'Cart', status: 'done' }, // filled indicator with a check mark
|
|
86
|
+
{ title: 'Work', status: 'progress' }, // current step (aria-current="step")
|
|
87
|
+
{ title: 'Payment', status: 'disabled' } // not yet reachable; rendered at 40% opacity, not focusable
|
|
88
|
+
];
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
<!-- readme-gen:start -->
|
|
92
|
+
|
|
93
|
+
<!-- Generated from lof-stepper.ts — do not edit; run readme-generate.mjs -->
|
|
94
|
+
|
|
95
|
+
## API
|
|
96
|
+
|
|
97
|
+
### Attributes / Properties
|
|
98
|
+
|
|
99
|
+
| Property | Attribute | Type | Default | Description |
|
|
100
|
+
| --- | --- | --- | --- | --- |
|
|
101
|
+
| `steps` | `steps` | `Step[]` | `[]` | The steps in order, each `{ title: string; subtitle?: string; status: "done" \| "progress" \| "disabled" }`. Set as a property (or a JSON array attribute); the component never mutates it — update it from the `lof-step-change` handler. |
|
|
102
|
+
| `orientation` | `orientation` | `"horizontal" \| "vertical"` | `"horizontal"` | Layout axis: `horizontal` (default) lays the steps out in a centred row; `vertical` stacks them. |
|
|
103
|
+
| `type` | `type` | `"default" \| "dot" \| "number" \| "icon"` | `"default"` | Figma "Type" axis — what the INDICATOR shows: `default` (step number, check mark once done), `dot` (8px dot, no glyph), `number` (always the number) or `icon` (always the check mark). Not the same axis as `connector="dot"`, which dashes the line between steps. Reflected. |
|
|
104
|
+
| `connector` | `connector` | `"solid" \| "dot"` | `"solid"` | Figma ".Line Types" axis — how the line BETWEEN steps is drawn: `solid` (an unbroken 1px rule) or `dot` (a 1px rule dashed 2px on, 2px off). Applies to both orientations. Not the same axis as `type="dot"`, which is the indicator disc; the two are independent and can be combined. Reflected. |
|
|
105
|
+
| `labelPlacement` | `label-placement` | `"top" \| "centered" \| "inverted"` | `undefined` | Figma "Typel" axis — where the label sits: `top` (top-aligned beside the indicator), `centered` (vertically centred beside it) or `inverted` (indicator above the label). When unset, the deprecated `textAlign` prop drives the layout (`below` ≈ `inverted`, `right` ≈ `centered`). Figma marks Top + Horizontal as an unsupported combination. Reflected. |
|
|
106
|
+
|
|
107
|
+
#### Deprecated (still supported — removal targeted for 3.0)
|
|
108
|
+
|
|
109
|
+
| Property | Attribute | Type | Use instead |
|
|
110
|
+
| --- | --- | --- | --- |
|
|
111
|
+
| `textAlign` | `textalign` | `"right" \| "below"` | Deprecated alias of `label-placement`; use `label-placement="inverted"` instead of `textalign="below"` and `label-placement="centered"` instead of `textalign="right"`. |
|
|
112
|
+
| `size` | `size` | `"small" \| "large"` | Figma has no Size axis on the Stepper — the connector geometry is fixed — so this was a code-only scale. It stays accepted so existing markup keeps working, and now resolves to the one Figma geometry. Retune it with `--lof-stepper-connector-length` instead. Logs a one-time notice. |
|
|
113
|
+
|
|
114
|
+
## Events
|
|
115
|
+
|
|
116
|
+
| Event | Detail | Bubbles / composed | Description |
|
|
117
|
+
| --- | --- | --- | --- |
|
|
118
|
+
| `lof-step-change` | `{ index, step, }` | bubbles / composed | Fired when a step whose status is not `disabled` is clicked or activated with Enter / Space. Detail: `{ index: number, step: Step }`. Statuses are not changed by the component — update `steps` in the handler. |
|
|
119
|
+
|
|
120
|
+
## Slots
|
|
121
|
+
|
|
122
|
+
| Slot | Description |
|
|
123
|
+
| --- | --- |
|
|
124
|
+
| — | This element has no slots. |
|
|
125
|
+
|
|
126
|
+
## CSS Parts
|
|
127
|
+
|
|
128
|
+
| Part | Description |
|
|
129
|
+
| --- | --- |
|
|
130
|
+
| `indicator` | The 24px circle (8px for `type="dot"`) that holds the step number, check mark or icon. |
|
|
131
|
+
| `track` | The 1px connector line from a step to the next one (not rendered on the last step). |
|
|
132
|
+
| `label` | The step title text. |
|
|
133
|
+
| `subtitle` | The optional second line under the title; rendered only when a step sets `subtitle`. |
|
|
134
|
+
|
|
135
|
+
## Tokens / CSS Variables
|
|
136
|
+
|
|
137
|
+
### Component hooks
|
|
138
|
+
|
|
139
|
+
Set these on the host (or an ancestor) to customise the element without touching design tokens.
|
|
140
|
+
|
|
141
|
+
| Custom property | Default | Description |
|
|
142
|
+
| --- | --- | --- |
|
|
143
|
+
| `--lof-stepper-connector-length` | `var(--lof-stepper-connector-length-lg, 96px)` | Length of the connector line; the step gap is derived from it by adding Figma's clear space at both ends. Defaults to Figma's fixed geometry: 96px horizontally, 34px vertically with `label-placement="centered"`, 51px with `inverted`. |
|
|
144
|
+
| `--lof-stepper-indicator-size` | `24px` | Indicator diameter (default 24px; `type="dot"` is fixed at 8px). |
|
|
145
|
+
|
|
146
|
+
<!-- readme-gen:end -->
|
|
147
|
+
|
|
148
|
+
## Accessibility
|
|
149
|
+
|
|
150
|
+
- The list renders as a `role="group"` with the fixed name "Progress steps" (not configurable).
|
|
151
|
+
- Every step is a `role="button"` element with `aria-label="<title>, step n of N"`, plus ", completed" for `done` steps. The `progress` step carries `aria-current="step"`; `disabled` steps carry `aria-disabled="true"` and `tabindex="-1"` so they are skipped in the Tab order and by the arrow keys.
|
|
152
|
+
- Enabled steps are individual Tab stops (`tabindex="0"`) with a 2px focus ring; the indicators and connectors are purely visual (the check mark SVG is `aria-hidden`).
|
|
153
|
+
- Activating a step only emits `lof-step-change`; nothing is announced and no status changes until you update `steps`.
|
|
154
|
+
|
|
155
|
+
| Key | Action |
|
|
156
|
+
| --- | --- |
|
|
157
|
+
| `Enter` / `Space` | Activate the focused step (emits `lof-step-change`; ignored on `disabled` steps) |
|
|
158
|
+
| `ArrowRight` / `ArrowDown` | Move focus to the next enabled step (wraps to the first) |
|
|
159
|
+
| `ArrowLeft` / `ArrowUp` | Move focus to the previous enabled step (wraps to the last) |
|
|
160
|
+
| `Home` / `End` | Move focus to the first / last enabled step |
|
|
161
|
+
|
|
162
|
+
## Notes / Edge Cases
|
|
163
|
+
|
|
164
|
+
- `label-placement` is the canonical layout switch (Figma `Typel`). When it is unset the deprecated `textalign` prop decides: `below` renders like `inverted` (indicator above the label), `right` renders like `centered` (label beside the indicator). `top` differs from `centered` only in aligning the label to the top of the indicator. Figma marks Top + Horizontal as an unsupported combination.
|
|
165
|
+
- Statuses map to the Figma `.Artwork` states: `done` = inverse fill with a check mark (or the number when `type="number"`, nothing when `type="dot"`), `progress` = neutral fill with a strong 1px border, `disabled` = the same drawn at 40% opacity. Connectors are `border-strong` after a `done` / `progress` step and `border-default` otherwise.
|
|
166
|
+
- `type="icon"` shows the check mark on every step regardless of status; `type="dot"` shrinks the indicator to 8px and fills it for `done` and `progress`.
|
|
167
|
+
- Two axes spell one value "dot" and they are independent: `type="dot"` is the INDICATOR (an 8px disc replacing the number), `connector="dot"` is the LINE between steps. `connector="dot"` draws a 1px rule dashed 2px on / 2px off, matching Figma `.Line Types` `Type=Dot` (`strokeWeight=1`, `strokeDashes=[2,2]`). It is a repeating gradient rather than a dashed border because no engine lets you state a 2/2 dash period. The dash takes the connector's own state colour, so it goes `border-strong` after a `done` / `progress` step like the solid line does.
|
|
168
|
+
- Connector length doubles as the gap between steps and depends on `size` and `orientation`: large = `--lof-stepper-connector-length-lg` (86px) in both orientations; small horizontal = `--lof-stepper-connector-length-md` (60px); small vertical = `--lof-stepper-connector-length-sm` (42px). Note the `md` / `sm` suffixes refer to those defaults, not to a size value.
|
|
169
|
+
- Labels never wrap (`white-space: nowrap`); keep titles short or widen the connector hooks.
|
|
170
|
+
- `steps` is compared by reference: mutate-in-place changes are not picked up — assign a new array.
|
|
171
|
+
- Steps are `<div role="button">` elements, not native buttons, so they do not submit forms and do not get native disabled styling.
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# lof-switch
|
|
2
|
+
|
|
3
|
+
`<lof-switch>` implements the Figma **Switch** component set (9059:11244): Type Line (default; at medium a 44×20 toggle with a thin 10px track and a 20px handle that slides 20px) or Pill (a 44×24 filled track), three sizes, an optional label at either end, and the hover, pressed, focused and disabled states from the Figma State axis. It wraps a native checkbox with `role="switch"`, so keyboard and screen-reader behaviour are native. Use it for settings that take effect immediately (notifications on/off, dark mode); for choices that are collected and submitted with a form use `<lof-checkbox>`.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```html
|
|
8
|
+
<!-- Basic -->
|
|
9
|
+
<lof-switch field-aria-label="Email notifications"></lof-switch>
|
|
10
|
+
|
|
11
|
+
<!-- On by default -->
|
|
12
|
+
<lof-switch checked field-aria-label="Dark mode"></lof-switch>
|
|
13
|
+
|
|
14
|
+
<!-- Disabled, off and on -->
|
|
15
|
+
<lof-switch disabled field-aria-label="Locked setting"></lof-switch>
|
|
16
|
+
<lof-switch checked disabled field-aria-label="Locked setting"></lof-switch>
|
|
17
|
+
|
|
18
|
+
<!-- One handler for several switches: `value` is echoed in the event detail -->
|
|
19
|
+
<lof-switch value="marketing" field-aria-label="Marketing emails"></lof-switch>
|
|
20
|
+
<lof-switch value="product" field-aria-label="Product updates"></lof-switch>
|
|
21
|
+
<script>
|
|
22
|
+
document.addEventListener('lof-change', (e) => {
|
|
23
|
+
if (e.target.tagName !== 'LOF-SWITCH') return;
|
|
24
|
+
console.log(e.detail.value, e.detail.checked); // "marketing", true
|
|
25
|
+
});
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
<!-- Programmatic control (no event is fired) -->
|
|
29
|
+
<lof-switch id="wifi" field-aria-label="Wi-Fi"></lof-switch>
|
|
30
|
+
<script>
|
|
31
|
+
const wifi = document.getElementById('wifi');
|
|
32
|
+
wifi.checked = true;
|
|
33
|
+
</script>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
<!-- readme-gen:start -->
|
|
37
|
+
|
|
38
|
+
<!-- Generated from lof-switch.ts — do not edit; run readme-generate.mjs -->
|
|
39
|
+
|
|
40
|
+
## API
|
|
41
|
+
|
|
42
|
+
### Attributes / Properties
|
|
43
|
+
|
|
44
|
+
| Property | Attribute | Type | Default | Description |
|
|
45
|
+
| --- | --- | --- | --- | --- |
|
|
46
|
+
| `checked` | `checked` | `boolean` | `false` | Whether the switch is on. Set it to control the state programmatically; user toggles update it and fire `lof-change`. |
|
|
47
|
+
| `type` | `type` | `"line" \| "pill"` | `"line"` | Shape (Figma "Type"): `"line"` (default) is the 44x20 control with a thin 40x10 rail and the handle riding on it; `"pill"` is the 44x24 filled track with the handle inside it. Pressing squashes the handle; only `line` also shows a pressed disc behind it. Reflected. |
|
|
48
|
+
| `disabled` | `disabled` | `boolean` | `false` | Disables interaction and swaps in the dulled rail / handle fills (for both types, checked or not) and the disabled label colour; the handle shadow is removed. An ancestor `<fieldset disabled>` disables it the same way, without changing this property. |
|
|
49
|
+
| `value` | `value` | `string` | `""` | Arbitrary string echoed in the `lof-change` event detail — useful when one handler serves several switches. |
|
|
50
|
+
| `fieldAriaLabel` | `field-aria-label` | `string` | `undefined` | Accessible name for the native input when the switch has no visible text. Prefer `label`, slotted text or an outer `<label>` (wrapping the switch, or `for=`), which are visible and clickable. |
|
|
51
|
+
| `label` | `label` | `string` | `undefined` | Visible text beside the control. Clicking it toggles the switch, and it becomes the accessible name — use `fieldAriaLabel` instead when the switch has no visible text. For rich content (a bold word, an icon) slot it in the default slot rather than setting this. |
|
|
52
|
+
| `labelPlacement` | `label-placement` | `"end" \| "start"` | `"end"` | Which side the label sits on: `end` (default) puts it after the control, `start` before it. Note this is a PHYSICAL side, not a writing-direction one, matching every other placement prop in the library. Reflected. |
|
|
53
|
+
| `size` | `size` | `"small" \| "medium" \| "large" \| "sm" \| "md" \| "lg"` | `"medium"` | Control scale: `small`, `medium` (default) or `large`. `sm` / `md` / `lg` are alternative spellings and stay supported — normalised to the full words, not deprecated. Matches Figma's Size axis: controls 36 / 44 / 52px wide, labels body-sm / body-md / body-lg (12 / 14 / 16px). The default stays `medium` (Figma's own default is Large). It does NOT respond to viewport width. Picking a size per breakpoint is the consuming application's decision — a control that silently resized itself at some width would be undocumentable behaviour, and the breakpoint that matters belongs to the layout around it, not to the switch. Reflected. |
|
|
54
|
+
|
|
55
|
+
## Events
|
|
56
|
+
|
|
57
|
+
| Event | Detail | Bubbles / composed | Description |
|
|
58
|
+
| --- | --- | --- | --- |
|
|
59
|
+
| `lof-change` | `{ checked: this.checked, value: this.value, }` | bubbles / composed | Fired when the user toggles the switch (not on programmatic `checked` changes). Detail: `{ checked: boolean, value: string }`. |
|
|
60
|
+
|
|
61
|
+
## Slots
|
|
62
|
+
|
|
63
|
+
| Slot | Description |
|
|
64
|
+
| --- | --- |
|
|
65
|
+
| (default) | Rich label content beside the control, as an alternative to the `label` property. Clicking it toggles the switch. |
|
|
66
|
+
|
|
67
|
+
## CSS Parts
|
|
68
|
+
|
|
69
|
+
| Part | Description |
|
|
70
|
+
| --- | --- |
|
|
71
|
+
| `root` | The `<label>` holding the control and its optional text; carries the `label-placement` order and the keyboard focus ring |
|
|
72
|
+
| `base` | The control box around the hidden input and the track |
|
|
73
|
+
| `track` | The thin rail; the handle is its `::before` pseudo-element |
|
|
74
|
+
| `label` | The text beside the control (body-sm / body-md / body-lg by `size`; `--lof-text-disabled` while disabled); not rendered when there is neither a `label` nor slotted content |
|
|
75
|
+
|
|
76
|
+
## Tokens / CSS Variables
|
|
77
|
+
|
|
78
|
+
### Component hooks
|
|
79
|
+
|
|
80
|
+
Set these on the host (or an ancestor) to customise the element without touching design tokens.
|
|
81
|
+
|
|
82
|
+
| Custom property | Default | Description |
|
|
83
|
+
| --- | --- | --- |
|
|
84
|
+
| `--lof-switch-disabled` | `var(--switch-disabled)` | Handle colour while disabled; default `var(--lof-bg-neutral-elevated-1)` |
|
|
85
|
+
| `--lof-switch-knob-off` | `var(--switch-knob-off)` | Handle colour when unchecked; default `var(--lof-text-static-light)` |
|
|
86
|
+
| `--lof-switch-knob-on` | `var(--switch-knob-on)` | Handle colour when checked; default `var(--lof-bg-neutral-inverse-2)` |
|
|
87
|
+
| `--lof-switch-thumb-size` | `var(--_lof-sw-thumb)` | Handle diameter; defaults to the `size` ramp (16 / 20 / 24px), and the handle always travels its own width minus the 2px inset on each side |
|
|
88
|
+
| `--lof-switch-track` | `var(--switch-track)` | Rail colour; default `var(--lof-bg-neutral-elevated-2)` |
|
|
89
|
+
| `--lof-switch-track-height` | `var(--_lof-sw-h)` | Overall control height; defaults to the `size` ramp — 16 / 20 / 24px for `type="line"`, 20 / 24 / 28px for `type="pill"` |
|
|
90
|
+
| `--lof-switch-track-width` | `var(--_lof-sw-w)` | Overall control width; defaults to the `size` ramp (36 / 44 / 52px) |
|
|
91
|
+
| `--switch-halo` | `var(--lof-action-overlay-hover-strong)` | — |
|
|
92
|
+
|
|
93
|
+
<!-- readme-gen:end -->
|
|
94
|
+
|
|
95
|
+
## Accessibility
|
|
96
|
+
|
|
97
|
+
- Renders a native `<input type="checkbox" role="switch">` with `aria-checked` mirroring `checked`; the input is visually hidden (opacity 0, zero size) inside the `<label part="root">` that also holds the label text, so clicking anywhere on the control or its text toggles it.
|
|
98
|
+
- `field-aria-label` becomes the input's `aria-label`. Use it only when there is no visible text; visible text in `label` or the default slot is clickable and becomes the accessible name.
|
|
99
|
+
- An outer `<label>` works too, wrapped around the switch (`<label><lof-switch></lof-switch> Wi-Fi</label>`) or pointing at it (`<label for="wifi">Wi-Fi</label><lof-switch id="wifi">`). The element is form-associated, so clicking the label's text toggles the switch (once, with one `lof-change`); a disabled switch ignores it. The input lives in the shadow root, where `aria-labelledby` cannot reach the label, so the label's text is copied into the input's `aria-label`. That happens only when the switch has no name of its own: `label`, `field-aria-label` and slotted text each win over an outer label. The copy follows edits to the label's text.
|
|
100
|
+
- Focus: keyboard focus (`:focus-visible`) draws one square 2px `--lof-border-focus` outline around the whole component, control and label together (the same treatment as `lof-checkbox` and `lof-radio`). A pointer click shows no ring.
|
|
101
|
+
- `disabled` disables the native input (removed from the tab order), swaps in the dulled rail and handle fills, drops the handle shadow and colours the label `--lof-text-disabled`.
|
|
102
|
+
- Forced colors (Windows High Contrast): the rail and handle are redrawn from system colours (a CanvasText outline, the handle filled Highlight when on, GrayText while disabled), and the focus ring stays an outline.
|
|
103
|
+
- `prefers-reduced-motion: reduce` removes the track and handle transitions.
|
|
104
|
+
|
|
105
|
+
| Key | Action |
|
|
106
|
+
| --- | --- |
|
|
107
|
+
| `Space` | Toggles the switch (native checkbox behaviour). |
|
|
108
|
+
| `Tab` / `Shift+Tab` | Moves focus to / from the switch. |
|
|
109
|
+
|
|
110
|
+
## Notes / Edge Cases
|
|
111
|
+
|
|
112
|
+
- `lof-change` fires for user toggles only; setting `checked` from JavaScript updates the visuals but emits nothing.
|
|
113
|
+
- Geometry follows the `size` ramp, derived from the Figma Line switch at `medium`: 44×20 control, 40×10 track inset 2px, 20px handle travelling 20px. `small` is 36×16 and `large` 52×24, holding the same invariants (handle = control height, width = 2× height + 4, rail = height ÷ 2, travel = width − 4 − handle). `type="pill"` shares the width, handle and travel but is 4px taller at every size — 20 / 24 / 28 — because its height is the handle plus its 2px inset, where Line's height *is* the handle. Changing `--lof-switch-track-width` widens the control without moving the "on" position.
|
|
114
|
+
- The label type follows the size: body-sm / body-md / body-lg (12 / 14 / 16px) for small / medium / large.
|
|
115
|
+
- **`size` does not respond to viewport width.** It follows Figma's Size axis, and choosing a size per breakpoint is the application's decision — set it from your own media queries or container queries. A control that resized itself at some width would be behaviour a design system cannot document, and the breakpoint that matters belongs to the layout around the switch, not to the switch.
|
|
116
|
+
- A `label` (or slotted content) becomes the switch's accessible name and is clickable, because the root element is the `<label>` that owns the input. Use `field-aria-label` instead when there is no visible text; when both are set, `label` wins.
|
|
117
|
+
- Hover and pressed cover the whole component, label included. Hover tints the track with the action overlay and raises the handle shadow. Pressed (pointer down, or Space held) squashes the handle by 4px on Line (16×12 / 20×16 / 24×20) over an overlay disc 8px wider than the handle, and to (handle + 1) × (handle − 2) on Pill, with no disc; an unchecked rail turns `--lof-bg-neutral-elevated-1` while pressed.
|
|
118
|
+
- Legacy hook aliases still honoured: `--switch-track`, `--switch-knob-on`, `--switch-knob-off` and `--switch-disabled` are read as fallbacks of the `--lof-switch-*` hooks. The old `--switch-halo` name was never read by any rule and is not a hook.
|
|
119
|
+
- `registerOnChange`, `registerOnTouched` and `writeValue` exist for the Angular `ControlValueAccessor` wrapper and are not public API.
|
|
120
|
+
- The element is form-associated (so an outer `<label>` can find it) but sets no form value: it is still NOT submitted with a surrounding `<form>`, and form reset does not touch it. It does now appear in `form.elements`. Read `checked` or listen to `lof-change`.
|
|
121
|
+
- Inside a `<fieldset disabled>` the switch behaves disabled (input disabled, dulled fills, no toggling) without its `disabled` property changing.
|
|
122
|
+
- `el.click()` from script now toggles the switch, like a native checkbox; it used to do nothing.
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# lof-tab
|
|
2
|
+
|
|
3
|
+
`<lof-tab>` implements the Figma **Tab Item** component (6473:1075) as an underline tab strip with roving-tabindex keyboard navigation, optional count or dot badges and a single shared tabpanel below the strip. Tabs are declared either with slotted `<lof-tab-item>` elements (registered by this folder; they render nothing themselves) or with the `tabs` array property. Use it to switch between peer views of the same content in place; for moving between pages use links or the navbar recipe, and for ordered multi-step flows use `<lof-stepper>`.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```html
|
|
8
|
+
<!-- Declarative tabs with badges and a disabled item -->
|
|
9
|
+
<lof-tab id="inbox-tabs" size="medium">
|
|
10
|
+
<lof-tab-item slot="items" label="Inbox" value="inbox" badge="5"></lof-tab-item>
|
|
11
|
+
<lof-tab-item slot="items" label="Drafts" value="drafts" badge-dot></lof-tab-item>
|
|
12
|
+
<lof-tab-item slot="items" label="Archive" value="archive" disabled></lof-tab-item>
|
|
13
|
+
<div id="inbox-panel">Inbox content.</div>
|
|
14
|
+
</lof-tab>
|
|
15
|
+
|
|
16
|
+
<script>
|
|
17
|
+
const tabs = document.getElementById('inbox-tabs');
|
|
18
|
+
tabs.addEventListener('lof-tab-change', (e) => {
|
|
19
|
+
const index = e.detail; // number
|
|
20
|
+
const item = tabs.querySelectorAll('lof-tab-item')[index];
|
|
21
|
+
document.getElementById('inbox-panel').textContent = `${item.value} content.`;
|
|
22
|
+
});
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<!-- Sizes: small (32px), medium (40px), large (48px) -->
|
|
26
|
+
<lof-tab size="small">
|
|
27
|
+
<lof-tab-item slot="items" label="Overview"></lof-tab-item>
|
|
28
|
+
<lof-tab-item slot="items" label="Details"></lof-tab-item>
|
|
29
|
+
</lof-tab>
|
|
30
|
+
<lof-tab size="large" active-index="1">
|
|
31
|
+
<lof-tab-item slot="items" label="Overview"></lof-tab-item>
|
|
32
|
+
<lof-tab-item slot="items" label="Details"></lof-tab-item>
|
|
33
|
+
</lof-tab>
|
|
34
|
+
|
|
35
|
+
<!-- Tabs from the `tabs` property -->
|
|
36
|
+
<lof-tab id="array-tabs"></lof-tab>
|
|
37
|
+
<script>
|
|
38
|
+
document.getElementById('array-tabs').tabs = [
|
|
39
|
+
{ label: 'Overview' },
|
|
40
|
+
{ label: 'Alerts', badge: 2 },
|
|
41
|
+
{ label: 'Beta', badgeDot: true },
|
|
42
|
+
{ label: 'Coming soon', disabled: true },
|
|
43
|
+
];
|
|
44
|
+
</script>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Deprecated aliases
|
|
48
|
+
|
|
49
|
+
```html
|
|
50
|
+
<!-- size="sm" / "md" / "lg" → size="small" / "medium" / "large" (still accepted; no console notice is logged) -->
|
|
51
|
+
<lof-tab size="sm">
|
|
52
|
+
<lof-tab-item slot="items" label="Overview"></lof-tab-item>
|
|
53
|
+
</lof-tab>
|
|
54
|
+
|
|
55
|
+
<!-- activeindex → active-index (since 1.5.0; still works, logs a one-time console notice, removed in 3.0).
|
|
56
|
+
activeIndex still reflects as activeindex in 1.x. -->
|
|
57
|
+
<lof-tab activeindex="1">
|
|
58
|
+
<lof-tab-item slot="items" label="Overview"></lof-tab-item>
|
|
59
|
+
<lof-tab-item slot="items" label="Details"></lof-tab-item>
|
|
60
|
+
</lof-tab>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
<!-- readme-gen:start -->
|
|
64
|
+
|
|
65
|
+
<!-- Generated from lof-tab.ts — do not edit; run readme-generate.mjs -->
|
|
66
|
+
|
|
67
|
+
## Elements
|
|
68
|
+
|
|
69
|
+
| Element | Class | Source |
|
|
70
|
+
| --- | --- | --- |
|
|
71
|
+
| `<lof-tab>` | `LofTab` | `lof-tab.ts` |
|
|
72
|
+
| `<lof-tab-item>` | `LofTabItem` | `lof-tab.ts` |
|
|
73
|
+
|
|
74
|
+
## API
|
|
75
|
+
|
|
76
|
+
### `<lof-tab>`
|
|
77
|
+
|
|
78
|
+
#### Attributes / Properties
|
|
79
|
+
|
|
80
|
+
| Property | Attribute | Type | Default | Description |
|
|
81
|
+
| --- | --- | --- | --- | --- |
|
|
82
|
+
| `tabs` | `tabs` | `TabItem[]` | `[]` | Tab definitions as `{ label, badge?, badgeDot?, disabled? }` objects — normally set as a property (as an attribute it must be a JSON string). Assign a new array to update; mutating in place does not re-render. Ignored when `<lof-tab-item>` children are slotted into `items`. |
|
|
83
|
+
| `activeIndex` | `active-index` | `number` | `0` | Zero-based index of the selected tab. Set it to switch tabs programmatically (no event is fired for programmatic changes). Reflected (as `activeindex` in 1.x). The `activeindex` attribute spelling is deprecated (still works; removal targeted for 3.0). |
|
|
84
|
+
| `size` | `size` | `"sm" \| "md" \| "lg" \| "small" \| "medium" \| "large"` | `"md"` | Tab size — styled via :host([size]) rules. Explicit item heights 32 / 40 / 48px (audit 34); `small\|medium\|large` alias `sm\|md\|lg`. Reflected. |
|
|
85
|
+
| `orientation` | `orientation` | `"horizontal" \| "vertical"` | `"horizontal"` | New in 1.5.0. Tab list layout: `horizontal` (default, a row above the panel) or `vertical` (a column beside the panel as wide as its longest label, tabs 24px apart along a rule on the list's inline-start edge, the active bar on that edge, labels that wrap rather than truncate; Up / Down move between tabs). There is no built-in breakpoint: switch to horizontal on small screens in your app. Reflected. |
|
|
86
|
+
| `iconPlacement` | `icon-placement` | `"start" \| "top"` | `"start"` | New in 1.5.0. Icon position in every tab: `start` (default, before the label) or `top` (stacked above the label, with the badge beside the label). Stacked tabs are 76 / 64 / 52px tall at large / medium / small. Works in both orientations. Reflected. |
|
|
87
|
+
|
|
88
|
+
### Events
|
|
89
|
+
|
|
90
|
+
| Event | Detail | Bubbles / composed | Description |
|
|
91
|
+
| --- | --- | --- | --- |
|
|
92
|
+
| `lof-change` | `index` | bubbles / composed | Prefixed alias of `lof-tab-change`, added in 1.4.9 — fired on the same action with the same detail. Both events fire; listen to one. Prefer this in new code, since every interactive component in the library emits `lof-change`. `lof-tab-change` is kept for as long as 1.x. |
|
|
93
|
+
| `lof-tab-change` | `index` | bubbles / composed | Fired when the user selects a tab by click or keyboard (not on programmatic `activeIndex` changes). Detail: the new active index (number). |
|
|
94
|
+
|
|
95
|
+
### Slots
|
|
96
|
+
|
|
97
|
+
| Slot | Description |
|
|
98
|
+
| --- | --- |
|
|
99
|
+
| (default) | Content of the single tabpanel rendered under the strip (always visible — swap it yourself on `lof-tab-change`) |
|
|
100
|
+
| `items` | `<lof-tab-item>` definitions; when present they take precedence over the `tabs` array |
|
|
101
|
+
|
|
102
|
+
### CSS Parts
|
|
103
|
+
|
|
104
|
+
| Part | Description |
|
|
105
|
+
| --- | --- |
|
|
106
|
+
| `list` | The `role="tablist"` row |
|
|
107
|
+
| `item` | Each `role="tab"` element |
|
|
108
|
+
| `icon` | — |
|
|
109
|
+
| `label` | The text span inside each tab |
|
|
110
|
+
|
|
111
|
+
### Tokens / CSS Variables
|
|
112
|
+
|
|
113
|
+
#### Component hooks
|
|
114
|
+
|
|
115
|
+
Set these on the host (or an ancestor) to customise the element without touching design tokens.
|
|
116
|
+
|
|
117
|
+
| Custom property | Default | Description |
|
|
118
|
+
| --- | --- | --- |
|
|
119
|
+
| `--lof-tab-active-color` | `var(--tab-active-color)` | Underline colour of the active tab; default `var(--lof-bg-brand)` |
|
|
120
|
+
| `--lof-tab-hover-color` | `var(--tab-hover-color)` | Background of an inactive tab on hover; default `transparent` (the design darkens the label instead). Set it to bring a hover fill back. |
|
|
121
|
+
| `--lof-tab-list-width` | `max-content` | Width of the tab list when `orientation="vertical"`; default `max-content` |
|
|
122
|
+
| `--lof-tab-text-default` | `var(--tab-text-default)` | Label colour of the active tab; default `var(--lof-text-default)` |
|
|
123
|
+
| `--lof-tab-text-disabled` | `var(--lof-text-default)` | Label colour of a disabled tab; default `var(--lof-text-disabled)` |
|
|
124
|
+
| `--lof-tab-text-hover` | `var(--tab-text-hover)` | Label colour while hovering an enabled tab; default `var(--lof-text-default)` |
|
|
125
|
+
| `--lof-tab-underline-height` | `var(--tab-underline-height)` | Thickness of the active underline; default 1px (`--lof-stroke-sm`, the weight Figma draws). Set it to restore the heavier 3px bar shipped previously. |
|
|
126
|
+
|
|
127
|
+
### `<lof-tab-item>`
|
|
128
|
+
|
|
129
|
+
#### Attributes / Properties
|
|
130
|
+
|
|
131
|
+
| Property | Attribute | Type | Default | Description |
|
|
132
|
+
| --- | --- | --- | --- | --- |
|
|
133
|
+
| `label` | `label` | `string` | `""` | Text shown on the tab. |
|
|
134
|
+
| `icon` | `icon` | `string` | `""` | Icon name from the generated icon dictionary, rendered before the label (Figma "Show Icon" / "Icon"). Sized 20 / 18 / 16px with the tab's own size step. |
|
|
135
|
+
| `value` | `value` | `string` | `""` | Optional identifier for the tab. `<lof-tab>` does not read it; look it up from the item at `event.detail` when handling `lof-tab-change`. |
|
|
136
|
+
| `badge` | `badge` | `number` | `0` | Count shown in a small badge after the label; `0` hides the badge. |
|
|
137
|
+
| `badgeDot` | `badge-dot` | `boolean` | `false` | Shows a small dot instead of a numbered badge — takes precedence over `badge`. |
|
|
138
|
+
| `disabled` | `disabled` | `boolean` | `false` | Greys the tab out and skips it in click, arrow-key and Home/End navigation. |
|
|
139
|
+
|
|
140
|
+
### Events
|
|
141
|
+
|
|
142
|
+
| Event | Detail | Bubbles / composed | Description |
|
|
143
|
+
| --- | --- | --- | --- |
|
|
144
|
+
| — | — | — | This element emits no custom events. |
|
|
145
|
+
|
|
146
|
+
### Slots
|
|
147
|
+
|
|
148
|
+
| Slot | Description |
|
|
149
|
+
| --- | --- |
|
|
150
|
+
| — | This element has no slots. |
|
|
151
|
+
|
|
152
|
+
### CSS Parts
|
|
153
|
+
|
|
154
|
+
| Part | Description |
|
|
155
|
+
| --- | --- |
|
|
156
|
+
| — | None exposed. |
|
|
157
|
+
|
|
158
|
+
<!-- readme-gen:end -->
|
|
159
|
+
|
|
160
|
+
## Accessibility
|
|
161
|
+
|
|
162
|
+
- The strip is `role="tablist"`; every tab is `role="tab"` with `aria-selected`, `aria-disabled` and `aria-controls` pointing at the shared `role="tabpanel"`, which in turn is `aria-labelledby` the active tab and is focusable (`tabindex="0"`).
|
|
163
|
+
- Roving tabindex: only the active tab is in the Tab order (`tabindex="0"`); other and disabled tabs are `tabindex="-1"`.
|
|
164
|
+
- Arrow keys use automatic activation — moving focus also selects the tab and fires `lof-tab-change`.
|
|
165
|
+
- Focus is shown as a 2px outline inset inside the tab.
|
|
166
|
+
- Disabled tabs ignore clicks and keys and are skipped by arrow, Home and End navigation.
|
|
167
|
+
|
|
168
|
+
| Key | Action |
|
|
169
|
+
| --- | --- |
|
|
170
|
+
| `ArrowRight` | Selects and focuses the next enabled tab (wraps to the first). |
|
|
171
|
+
| `ArrowLeft` | Selects and focuses the previous enabled tab (wraps to the last). |
|
|
172
|
+
| `Home` | Selects and focuses the first enabled tab. |
|
|
173
|
+
| `End` | Selects and focuses the last enabled tab. |
|
|
174
|
+
| `Enter` / `Space` | Selects the focused tab (no-op when disabled). |
|
|
175
|
+
| `Tab` | Leaves the strip (moves to the tabpanel). |
|
|
176
|
+
|
|
177
|
+
## Notes / Edge Cases
|
|
178
|
+
|
|
179
|
+
- There is one always-visible tabpanel (the default slot). The component does not show/hide content per tab — swap or filter the panel content yourself on `lof-tab-change` or by watching `activeIndex`.
|
|
180
|
+
- `lof-tab-change` fires for user selection only; setting `activeIndex` programmatically updates the strip silently.
|
|
181
|
+
- Slotted `<lof-tab-item>` elements take precedence over the `tabs` array. Their `value` is not read by `<lof-tab>` — look it up from the item at `event.detail` when you need an identifier. The `items` slot itself is hidden.
|
|
182
|
+
- `badge-dot` wins over `badge`; a `badge` of `0` renders no badge. Badges use the danger tone on enabled tabs and a neutral inverse tone on disabled tabs.
|
|
183
|
+
- `size` accepts `small` / `medium` / `large` (item heights 32 / 40 / 48px with body-sm / md / lg type); the short forms `sm` / `md` / `lg` are aliases (see Deprecated aliases).
|
|
184
|
+
- Legacy hook aliases still honoured: `--tab-active-color`, `--tab-underline-height`, `--tab-text-default`, `--tab-text-hover`, `--tab-text-disabled` and `--tab-hover-color` are read as fallbacks of the `--lof-tab-*` hooks.
|