opui-css 5.0.0 → 5.0.1
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/CHANGELOG.md +282 -276
- package/LICENSE +21 -21
- package/MIGRATING.md +127 -127
- package/README.md +87 -87
- package/astro/index.ts +46 -46
- package/components/AGENTS.md +248 -248
- package/components/Accordion/Accordion.astro +42 -42
- package/components/Anchor/Anchor.astro +51 -51
- package/components/Avatar/Avatar.astro +38 -38
- package/components/Badge/Badge.astro +59 -59
- package/components/Button/Button.astro +45 -45
- package/components/ButtonGroup/ButtonGroup.astro +29 -29
- package/components/Callout/Callout.astro +75 -75
- package/components/Card/Card.astro +36 -36
- package/components/Checkbox/Checkbox.astro +76 -76
- package/components/Checkbox/CheckboxInput.astro +32 -32
- package/components/Chip/Chip.astro +37 -37
- package/components/ClassicSelect/ClassicSelect.astro +83 -83
- package/components/DescriptionList/Description.astro +12 -12
- package/components/DescriptionList/DescriptionList.astro +22 -22
- package/components/DescriptionList/Item.astro +12 -12
- package/components/DescriptionList/Term.astro +12 -12
- package/components/DescriptionList/index.ts +12 -12
- package/components/Dialog/Dialog.astro +41 -41
- package/components/Divider/Divider.astro +17 -17
- package/components/Drawer/Drawer.astro +49 -49
- package/components/Drawer/DrawerFooter.astro +14 -14
- package/components/Drawer/DrawerHeader.astro +31 -31
- package/components/FieldDescription/FieldDescription.astro +13 -13
- package/components/FieldGroup/FieldGroup.astro +31 -31
- package/components/FieldLegend/FieldLegend.astro +15 -15
- package/components/FieldSet/FieldSet.astro +15 -15
- package/components/Form/Form.astro +15 -15
- package/components/IconButton/IconButton.astro +26 -26
- package/components/List/List.astro +36 -36
- package/components/ListItem/ListItem.astro +118 -118
- package/components/Progress/Progress.astro +41 -40
- package/components/Radio/Radio.astro +70 -70
- package/components/Radio/RadioInput.astro +24 -24
- package/components/Range/Range.astro +136 -136
- package/components/Select/Select.astro +106 -106
- package/components/Switch/Switch.astro +101 -101
- package/components/Switch/SwitchInput.astro +25 -25
- package/components/Table/Body.astro +13 -13
- package/components/Table/Cell.astro +13 -13
- package/components/Table/Column.astro +15 -15
- package/components/Table/ColumnGroup.astro +13 -13
- package/components/Table/Head.astro +13 -13
- package/components/Table/HeaderCell.astro +13 -13
- package/components/Table/Row.astro +13 -13
- package/components/Table/Table.astro +18 -18
- package/components/Table/index.ts +20 -20
- package/components/Tabs/Tabs.astro +28 -28
- package/components/Tabs/TabsItem.astro +47 -47
- package/components/Tabs/TabsPanel.astro +21 -21
- package/components/Tabs/TabsTab.astro +19 -19
- package/components/Tabs/index.ts +14 -14
- package/components/TextField/TextField.astro +128 -128
- package/components/Textarea/Textarea.astro +106 -106
- package/components/Toast/Toast.astro +42 -42
- package/components/ToggleButton/ToggleButton.astro +53 -53
- package/components/ToggleGroup/ToggleGroup.astro +49 -49
- package/components/Tooltip/Tooltip.astro +30 -30
- package/core/normalize.css +194 -194
- package/core/palette.css +59 -59
- package/core/utils.css +71 -71
- package/css/components/accordion.css +174 -174
- package/css/components/anchor.css +27 -27
- package/css/components/avatar.css +65 -65
- package/css/components/badge.css +107 -107
- package/css/components/button-group.css +179 -179
- package/css/components/button.css +215 -215
- package/css/components/callout.css +109 -109
- package/css/components/card.css +117 -117
- package/css/components/checkbox.css +205 -205
- package/css/components/chip.css +87 -87
- package/css/components/description-list.css +80 -80
- package/css/components/dialog.css +68 -68
- package/css/components/divider.css +20 -20
- package/css/components/drawer.css +171 -171
- package/css/components/form.css +146 -146
- package/css/components/icon-button.css +139 -139
- package/css/components/link.css +21 -21
- package/css/components/list.css +345 -345
- package/css/components/progress.css +102 -97
- package/css/components/radio.css +172 -172
- package/css/components/range.css +337 -337
- package/css/components/select.css +169 -169
- package/css/components/spinner.css +37 -37
- package/css/components/switch.css +268 -268
- package/css/components/table.css +179 -179
- package/css/components/tabs.css +83 -83
- package/css/components/text-field.css +450 -450
- package/css/components/text-input.css +64 -64
- package/css/components/textarea.css +24 -24
- package/css/components/toast.css +161 -161
- package/css/components/toggle-button.css +87 -87
- package/css/components/toggle-group.css +56 -56
- package/css/components/tooltip.css +67 -67
- package/css/components/typography.css +585 -585
- package/css/components.css +41 -41
- package/css/imports.css +16 -16
- package/css/js/checkbox.js +21 -21
- package/css/js/toast.js +94 -94
- package/css/theme.css +132 -132
- package/dist/op.css +65 -65
- package/dist/op.css.map +1 -1
- package/dist/opui.components.css +5159 -5154
- package/dist/opui.components.css.map +1 -1
- package/dist/opui.css +5668 -5663
- package/dist/opui.css.map +1 -1
- package/env.d.ts +14 -14
- package/open-props.css +9 -9
- package/package.json +81 -81
package/components/AGENTS.md
CHANGED
|
@@ -1,248 +1,248 @@
|
|
|
1
|
-
# UI Component Implementation Guide
|
|
2
|
-
|
|
3
|
-
This guide defines the standards for implementing reusable Astro UI components in this package (`packages/opui/components/<Name>/<Name>.astro`) based on the documentation specs at `src/docs/components/`. Use it as a reference for maintaining consistency and accessibility across the library.
|
|
4
|
-
|
|
5
|
-
**CRITICAL INSTRUCTION**: Always use components from this package (imported via the `@opui/astro` alias) and their corresponding CSS from `packages/opui/css/components/` whenever possible. Avoid writing custom CSS if an existing component or utility can achieve the desired result.
|
|
6
|
-
|
|
7
|
-
## 0. Implementation Checklist
|
|
8
|
-
|
|
9
|
-
When implementing or updating a component, ensure:
|
|
10
|
-
- [ ] **Title Export**: `export const title = "Component Name"` is present.
|
|
11
|
-
- [ ] **Props Type**: Used `type Props = { ... }` (avoid interfaces).
|
|
12
|
-
- [ ] **Sorting**: Props, Destructuring, and Classes are sorted alphabetically.
|
|
13
|
-
- [ ] **Rest Props**: `...rest` is captured and spread onto the root element.
|
|
14
|
-
- [ ] **Class Management**: Used `class:list` for all class manipulations.
|
|
15
|
-
- [ ] **ID Stability**: Used `Astro.locals.$id` for any internal element linking.
|
|
16
|
-
- [ ] **Accessibility**: ARIA labels, roles, and relationships are correctly handled.
|
|
17
|
-
- [ ] **Slot Strategy**: Named slots are used for structural content (icons, actions).
|
|
18
|
-
|
|
19
|
-
---
|
|
20
|
-
|
|
21
|
-
## 1. Frontmatter Structure
|
|
22
|
-
|
|
23
|
-
Every component must follow this exact frontmatter layout:
|
|
24
|
-
|
|
25
|
-
```astro
|
|
26
|
-
---
|
|
27
|
-
type Props = {
|
|
28
|
-
[key: string]: any // Required for ...rest support
|
|
29
|
-
class?: string
|
|
30
|
-
disabled?: boolean
|
|
31
|
-
label?: string
|
|
32
|
-
size?: "small" | "large"
|
|
33
|
-
variant?: "outlined" | "tonal" | "filled"
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export const title = "My Component"
|
|
37
|
-
|
|
38
|
-
const {
|
|
39
|
-
class: className,
|
|
40
|
-
disabled,
|
|
41
|
-
label,
|
|
42
|
-
size,
|
|
43
|
-
variant = "outlined", // Default values in destructuring
|
|
44
|
-
...rest
|
|
45
|
-
} = Astro.props
|
|
46
|
-
---
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
### Key Rules:
|
|
50
|
-
- **Alphabetical Sorting**: Sort property definitions in `type Props` and variables in the destructuring statement.
|
|
51
|
-
- **REST Support**: Always include `[key: string]: any` in props and `...rest` in destructuring.
|
|
52
|
-
- **Title Export**: This is mandatory for documentation generation.
|
|
53
|
-
|
|
54
|
-
---
|
|
55
|
-
|
|
56
|
-
## 2. Component Composition & Tags
|
|
57
|
-
|
|
58
|
-
### Dynamic Elements (Polymorphism)
|
|
59
|
-
For components that can be different HTML elements (e.g., `Button` as `<a>` or `<button>`), use a dynamic `Tag` variable.
|
|
60
|
-
|
|
61
|
-
```astro
|
|
62
|
-
---
|
|
63
|
-
const { as: Tag = Astro.props.href ? "a" : "button", ...rest } = Astro.props
|
|
64
|
-
---
|
|
65
|
-
<Tag {...rest}><slot /></Tag>
|
|
66
|
-
```
|
|
67
|
-
- **Inference**: Default to `"a"` if `href` is present.
|
|
68
|
-
- **Override**: Allow manual override via the `as` prop.
|
|
69
|
-
|
|
70
|
-
### Styling Inheritance
|
|
71
|
-
Components should often inherit styles from others (e.g., `Dialog` looking like a `Card`). Use conditional classes to apply the inherited base class. All library classes are prefixed with `ui-`.
|
|
72
|
-
|
|
73
|
-
```astro
|
|
74
|
-
<dialog class:list={["ui-dialog", { "ui-card": variant }, variant && `ui-${variant}`, className]} {...rest}>
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
---
|
|
78
|
-
|
|
79
|
-
## 3. Class Management
|
|
80
|
-
|
|
81
|
-
Use `class:list` exclusively. Every library-owned class is prefixed with `ui-`; the public prop API stays unprefixed (`<Button size="small" variant="outlined">`) and the component interpolates the prefix when rendering.
|
|
82
|
-
|
|
83
|
-
Follow this order for readability:
|
|
84
|
-
1. **Component Base Class**: The primary CSS class, prefixed (e.g., `"ui-button"`).
|
|
85
|
-
2. **State Objects**: Boolean flags as quoted prefixed keys (e.g., `{ "ui-disabled": disabled }`).
|
|
86
|
-
3. **Variant Props**: Interpolate the prefix from the prop value (e.g., `size && \`ui-${size}\``).
|
|
87
|
-
4. **External Class**: Always include `className` at the end to allow for overrides. Do not prefix `className`.
|
|
88
|
-
|
|
89
|
-
```astro
|
|
90
|
-
<div
|
|
91
|
-
class:list={[
|
|
92
|
-
"ui-chip",
|
|
93
|
-
{
|
|
94
|
-
"ui-multiline": isMultiline,
|
|
95
|
-
},
|
|
96
|
-
size && `ui-${size}`,
|
|
97
|
-
variant && `ui-${variant}`,
|
|
98
|
-
className,
|
|
99
|
-
]}
|
|
100
|
-
>
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
---
|
|
104
|
-
|
|
105
|
-
## 4. Slot Patterns
|
|
106
|
-
|
|
107
|
-
### Default Slots vs Label Props
|
|
108
|
-
For simple text-based components, provide both a `label` prop and a default slot.
|
|
109
|
-
|
|
110
|
-
```astro
|
|
111
|
-
<div class="ui-component">
|
|
112
|
-
{ (label || Astro.slots.has("default")) && (
|
|
113
|
-
<span class="ui-text">
|
|
114
|
-
{label}
|
|
115
|
-
<slot />
|
|
116
|
-
</span>
|
|
117
|
-
)}
|
|
118
|
-
</div>
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
### Named Slots (Icons & Actions)
|
|
122
|
-
Use named slots for specific functional areas. Check for existence before rendering wrapper tags.
|
|
123
|
-
|
|
124
|
-
```astro
|
|
125
|
-
<div class="ui-card">
|
|
126
|
-
{Astro.slots.has("header") && <header><slot name="header" /></header>}
|
|
127
|
-
<slot />
|
|
128
|
-
{Astro.slots.has("actions") && <footer class="ui-actions"><slot name="actions" /></footer>}
|
|
129
|
-
</div>
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
---
|
|
133
|
-
|
|
134
|
-
## 5. Form & Input Patterns
|
|
135
|
-
|
|
136
|
-
### Label Wrapping
|
|
137
|
-
Most inputs should be wrapped in a `<label>` to provide a larger hit area and built-in accessibility.
|
|
138
|
-
|
|
139
|
-
```astro
|
|
140
|
-
<label class:list={["ui-field", { "ui-disabled": disabled, "ui-critical": error }]}>
|
|
141
|
-
<span class="ui-label">{label}</span>
|
|
142
|
-
<input type="text" {...rest} />
|
|
143
|
-
{endText && <span class="ui-end-text">{endText}</span>}
|
|
144
|
-
</label>
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
### End Text & ARIA
|
|
148
|
-
When providing `endText`, use `Astro.locals.$id` to link it to the input via `aria-describedby`.
|
|
149
|
-
|
|
150
|
-
```astro
|
|
151
|
-
---
|
|
152
|
-
const { $id } = Astro.locals
|
|
153
|
-
const helpId = $id("help")
|
|
154
|
-
---
|
|
155
|
-
<input aria-describedby={endText ? helpId : undefined} />
|
|
156
|
-
{endText && <span id={helpId}>{endText}</span>}
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
### Input Attribute Mapping
|
|
160
|
-
Explicitly define and pass through native input attributes in the `Props` type for better IDE support.
|
|
161
|
-
|
|
162
|
-
```astro
|
|
163
|
-
<input
|
|
164
|
-
disabled={disabled}
|
|
165
|
-
name={name}
|
|
166
|
-
required={required}
|
|
167
|
-
type={type}
|
|
168
|
-
value={value}
|
|
169
|
-
{...rest}
|
|
170
|
-
/>
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
### Sub-component Decomposition
|
|
174
|
-
For complex inputs (like `Checkbox` with custom visuals), split the component into a public wrapper (`Checkbox.astro`) and a private raw input (`CheckboxInput.astro`) to keep the root element clean.
|
|
175
|
-
|
|
176
|
-
### Form Structure: FieldSet, FieldLegend, FieldDescription, FieldGroup
|
|
177
|
-
When building forms, follow this nesting order inside a `FieldSet`:
|
|
178
|
-
1. `FieldLegend` - The heading/label for the fieldset
|
|
179
|
-
2. `FieldDescription` - Optional helper text
|
|
180
|
-
3. `FieldGroup` - Wrapper for the actual form controls
|
|
181
|
-
|
|
182
|
-
**Always wrap form elements in a `FieldGroup`**, never place them directly after `FieldLegend` or `FieldDescription`.
|
|
183
|
-
|
|
184
|
-
```astro
|
|
185
|
-
<!-- ✅ Correct -->
|
|
186
|
-
<FieldSet>
|
|
187
|
-
<FieldLegend>Username</FieldLegend>
|
|
188
|
-
<FieldDescription>Enter your preferred username.</FieldDescription>
|
|
189
|
-
<FieldGroup>
|
|
190
|
-
<TextField placeholder="e.g. jdoe" />
|
|
191
|
-
</FieldGroup>
|
|
192
|
-
</FieldSet>
|
|
193
|
-
|
|
194
|
-
<!-- ❌ Incorrect - TextField directly after FieldDescription -->
|
|
195
|
-
<FieldSet>
|
|
196
|
-
<FieldLegend>Username</FieldLegend>
|
|
197
|
-
<FieldDescription>Enter your preferred username.</FieldDescription>
|
|
198
|
-
<TextField placeholder="e.g. jdoe" />
|
|
199
|
-
</FieldSet>
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
---
|
|
203
|
-
|
|
204
|
-
## 6. Identification & Accessibility
|
|
205
|
-
|
|
206
|
-
### Unique IDs
|
|
207
|
-
Always use `Astro.locals.$id` for IDs. This ensures stability across server and client rendering and prevents ID collisions when multiple instances of the same component are on a page.
|
|
208
|
-
|
|
209
|
-
```astro
|
|
210
|
-
const { $id } = Astro.locals
|
|
211
|
-
const fieldId = id || $id("input") // Prefer passed ID if available
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
### Default Icons
|
|
215
|
-
Components like `Callout` or `Toast` should provide default SVG icons within their named slots, while allowing users to override them.
|
|
216
|
-
|
|
217
|
-
```astro
|
|
218
|
-
<slot name="icon">
|
|
219
|
-
{severity === "error" && <svg>...</svg>}
|
|
220
|
-
</slot>
|
|
221
|
-
```
|
|
222
|
-
|
|
223
|
-
---
|
|
224
|
-
|
|
225
|
-
## 7. Data-Driven Components
|
|
226
|
-
|
|
227
|
-
For repetitive structures (DescriptionLists, Menus, Selects), prefer an `items` prop alongside standard slots.
|
|
228
|
-
|
|
229
|
-
```astro
|
|
230
|
-
type Item = { label: string; value: any }
|
|
231
|
-
type Props = { items?: Item[] }
|
|
232
|
-
|
|
233
|
-
<ul>
|
|
234
|
-
{items.map(item => <li>{item.label}</li>)}
|
|
235
|
-
<slot /> <!-- Still allow manual entries -->
|
|
236
|
-
</ul>
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
---
|
|
240
|
-
|
|
241
|
-
## 8. Development Workflow
|
|
242
|
-
|
|
243
|
-
1. **Read the Spec**: Open `src/docs/components/[name].astro` to see required HTML and CSS classes. (Component docs live under `src/docs/components/` now; `src/pages/components/` only contains route shells.)
|
|
244
|
-
2. **Analyze the API**: Check `src/component-api/[name]/` (`Astro.astro` and `HTML.astro`) or `src/component-api/[name]-api.astro` for the documented props.
|
|
245
|
-
3. **Implement**: Follow the checklist in Section 0.
|
|
246
|
-
4. **Verify**: Check that your implementation matches the "HTML" preview in the rendered `Example` for the spec page (`/components/[name]`). For framework-specific behaviour, also verify the Astro variant at `/astro/components/[name]`.
|
|
247
|
-
|
|
248
|
-
|
|
1
|
+
# UI Component Implementation Guide
|
|
2
|
+
|
|
3
|
+
This guide defines the standards for implementing reusable Astro UI components in this package (`packages/opui/components/<Name>/<Name>.astro`) based on the documentation specs at `src/docs/components/`. Use it as a reference for maintaining consistency and accessibility across the library.
|
|
4
|
+
|
|
5
|
+
**CRITICAL INSTRUCTION**: Always use components from this package (imported via the `@opui/astro` alias) and their corresponding CSS from `packages/opui/css/components/` whenever possible. Avoid writing custom CSS if an existing component or utility can achieve the desired result.
|
|
6
|
+
|
|
7
|
+
## 0. Implementation Checklist
|
|
8
|
+
|
|
9
|
+
When implementing or updating a component, ensure:
|
|
10
|
+
- [ ] **Title Export**: `export const title = "Component Name"` is present.
|
|
11
|
+
- [ ] **Props Type**: Used `type Props = { ... }` (avoid interfaces).
|
|
12
|
+
- [ ] **Sorting**: Props, Destructuring, and Classes are sorted alphabetically.
|
|
13
|
+
- [ ] **Rest Props**: `...rest` is captured and spread onto the root element.
|
|
14
|
+
- [ ] **Class Management**: Used `class:list` for all class manipulations.
|
|
15
|
+
- [ ] **ID Stability**: Used `Astro.locals.$id` for any internal element linking.
|
|
16
|
+
- [ ] **Accessibility**: ARIA labels, roles, and relationships are correctly handled.
|
|
17
|
+
- [ ] **Slot Strategy**: Named slots are used for structural content (icons, actions).
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## 1. Frontmatter Structure
|
|
22
|
+
|
|
23
|
+
Every component must follow this exact frontmatter layout:
|
|
24
|
+
|
|
25
|
+
```astro
|
|
26
|
+
---
|
|
27
|
+
type Props = {
|
|
28
|
+
[key: string]: any // Required for ...rest support
|
|
29
|
+
class?: string
|
|
30
|
+
disabled?: boolean
|
|
31
|
+
label?: string
|
|
32
|
+
size?: "small" | "large"
|
|
33
|
+
variant?: "outlined" | "tonal" | "filled"
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const title = "My Component"
|
|
37
|
+
|
|
38
|
+
const {
|
|
39
|
+
class: className,
|
|
40
|
+
disabled,
|
|
41
|
+
label,
|
|
42
|
+
size,
|
|
43
|
+
variant = "outlined", // Default values in destructuring
|
|
44
|
+
...rest
|
|
45
|
+
} = Astro.props
|
|
46
|
+
---
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Key Rules:
|
|
50
|
+
- **Alphabetical Sorting**: Sort property definitions in `type Props` and variables in the destructuring statement.
|
|
51
|
+
- **REST Support**: Always include `[key: string]: any` in props and `...rest` in destructuring.
|
|
52
|
+
- **Title Export**: This is mandatory for documentation generation.
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## 2. Component Composition & Tags
|
|
57
|
+
|
|
58
|
+
### Dynamic Elements (Polymorphism)
|
|
59
|
+
For components that can be different HTML elements (e.g., `Button` as `<a>` or `<button>`), use a dynamic `Tag` variable.
|
|
60
|
+
|
|
61
|
+
```astro
|
|
62
|
+
---
|
|
63
|
+
const { as: Tag = Astro.props.href ? "a" : "button", ...rest } = Astro.props
|
|
64
|
+
---
|
|
65
|
+
<Tag {...rest}><slot /></Tag>
|
|
66
|
+
```
|
|
67
|
+
- **Inference**: Default to `"a"` if `href` is present.
|
|
68
|
+
- **Override**: Allow manual override via the `as` prop.
|
|
69
|
+
|
|
70
|
+
### Styling Inheritance
|
|
71
|
+
Components should often inherit styles from others (e.g., `Dialog` looking like a `Card`). Use conditional classes to apply the inherited base class. All library classes are prefixed with `ui-`.
|
|
72
|
+
|
|
73
|
+
```astro
|
|
74
|
+
<dialog class:list={["ui-dialog", { "ui-card": variant }, variant && `ui-${variant}`, className]} {...rest}>
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## 3. Class Management
|
|
80
|
+
|
|
81
|
+
Use `class:list` exclusively. Every library-owned class is prefixed with `ui-`; the public prop API stays unprefixed (`<Button size="small" variant="outlined">`) and the component interpolates the prefix when rendering.
|
|
82
|
+
|
|
83
|
+
Follow this order for readability:
|
|
84
|
+
1. **Component Base Class**: The primary CSS class, prefixed (e.g., `"ui-button"`).
|
|
85
|
+
2. **State Objects**: Boolean flags as quoted prefixed keys (e.g., `{ "ui-disabled": disabled }`).
|
|
86
|
+
3. **Variant Props**: Interpolate the prefix from the prop value (e.g., `size && \`ui-${size}\``).
|
|
87
|
+
4. **External Class**: Always include `className` at the end to allow for overrides. Do not prefix `className`.
|
|
88
|
+
|
|
89
|
+
```astro
|
|
90
|
+
<div
|
|
91
|
+
class:list={[
|
|
92
|
+
"ui-chip",
|
|
93
|
+
{
|
|
94
|
+
"ui-multiline": isMultiline,
|
|
95
|
+
},
|
|
96
|
+
size && `ui-${size}`,
|
|
97
|
+
variant && `ui-${variant}`,
|
|
98
|
+
className,
|
|
99
|
+
]}
|
|
100
|
+
>
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## 4. Slot Patterns
|
|
106
|
+
|
|
107
|
+
### Default Slots vs Label Props
|
|
108
|
+
For simple text-based components, provide both a `label` prop and a default slot.
|
|
109
|
+
|
|
110
|
+
```astro
|
|
111
|
+
<div class="ui-component">
|
|
112
|
+
{ (label || Astro.slots.has("default")) && (
|
|
113
|
+
<span class="ui-text">
|
|
114
|
+
{label}
|
|
115
|
+
<slot />
|
|
116
|
+
</span>
|
|
117
|
+
)}
|
|
118
|
+
</div>
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Named Slots (Icons & Actions)
|
|
122
|
+
Use named slots for specific functional areas. Check for existence before rendering wrapper tags.
|
|
123
|
+
|
|
124
|
+
```astro
|
|
125
|
+
<div class="ui-card">
|
|
126
|
+
{Astro.slots.has("header") && <header><slot name="header" /></header>}
|
|
127
|
+
<slot />
|
|
128
|
+
{Astro.slots.has("actions") && <footer class="ui-actions"><slot name="actions" /></footer>}
|
|
129
|
+
</div>
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## 5. Form & Input Patterns
|
|
135
|
+
|
|
136
|
+
### Label Wrapping
|
|
137
|
+
Most inputs should be wrapped in a `<label>` to provide a larger hit area and built-in accessibility.
|
|
138
|
+
|
|
139
|
+
```astro
|
|
140
|
+
<label class:list={["ui-field", { "ui-disabled": disabled, "ui-critical": error }]}>
|
|
141
|
+
<span class="ui-label">{label}</span>
|
|
142
|
+
<input type="text" {...rest} />
|
|
143
|
+
{endText && <span class="ui-end-text">{endText}</span>}
|
|
144
|
+
</label>
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### End Text & ARIA
|
|
148
|
+
When providing `endText`, use `Astro.locals.$id` to link it to the input via `aria-describedby`.
|
|
149
|
+
|
|
150
|
+
```astro
|
|
151
|
+
---
|
|
152
|
+
const { $id } = Astro.locals
|
|
153
|
+
const helpId = $id("help")
|
|
154
|
+
---
|
|
155
|
+
<input aria-describedby={endText ? helpId : undefined} />
|
|
156
|
+
{endText && <span id={helpId}>{endText}</span>}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Input Attribute Mapping
|
|
160
|
+
Explicitly define and pass through native input attributes in the `Props` type for better IDE support.
|
|
161
|
+
|
|
162
|
+
```astro
|
|
163
|
+
<input
|
|
164
|
+
disabled={disabled}
|
|
165
|
+
name={name}
|
|
166
|
+
required={required}
|
|
167
|
+
type={type}
|
|
168
|
+
value={value}
|
|
169
|
+
{...rest}
|
|
170
|
+
/>
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Sub-component Decomposition
|
|
174
|
+
For complex inputs (like `Checkbox` with custom visuals), split the component into a public wrapper (`Checkbox.astro`) and a private raw input (`CheckboxInput.astro`) to keep the root element clean.
|
|
175
|
+
|
|
176
|
+
### Form Structure: FieldSet, FieldLegend, FieldDescription, FieldGroup
|
|
177
|
+
When building forms, follow this nesting order inside a `FieldSet`:
|
|
178
|
+
1. `FieldLegend` - The heading/label for the fieldset
|
|
179
|
+
2. `FieldDescription` - Optional helper text
|
|
180
|
+
3. `FieldGroup` - Wrapper for the actual form controls
|
|
181
|
+
|
|
182
|
+
**Always wrap form elements in a `FieldGroup`**, never place them directly after `FieldLegend` or `FieldDescription`.
|
|
183
|
+
|
|
184
|
+
```astro
|
|
185
|
+
<!-- ✅ Correct -->
|
|
186
|
+
<FieldSet>
|
|
187
|
+
<FieldLegend>Username</FieldLegend>
|
|
188
|
+
<FieldDescription>Enter your preferred username.</FieldDescription>
|
|
189
|
+
<FieldGroup>
|
|
190
|
+
<TextField placeholder="e.g. jdoe" />
|
|
191
|
+
</FieldGroup>
|
|
192
|
+
</FieldSet>
|
|
193
|
+
|
|
194
|
+
<!-- ❌ Incorrect - TextField directly after FieldDescription -->
|
|
195
|
+
<FieldSet>
|
|
196
|
+
<FieldLegend>Username</FieldLegend>
|
|
197
|
+
<FieldDescription>Enter your preferred username.</FieldDescription>
|
|
198
|
+
<TextField placeholder="e.g. jdoe" />
|
|
199
|
+
</FieldSet>
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## 6. Identification & Accessibility
|
|
205
|
+
|
|
206
|
+
### Unique IDs
|
|
207
|
+
Always use `Astro.locals.$id` for IDs. This ensures stability across server and client rendering and prevents ID collisions when multiple instances of the same component are on a page.
|
|
208
|
+
|
|
209
|
+
```astro
|
|
210
|
+
const { $id } = Astro.locals
|
|
211
|
+
const fieldId = id || $id("input") // Prefer passed ID if available
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### Default Icons
|
|
215
|
+
Components like `Callout` or `Toast` should provide default SVG icons within their named slots, while allowing users to override them.
|
|
216
|
+
|
|
217
|
+
```astro
|
|
218
|
+
<slot name="icon">
|
|
219
|
+
{severity === "error" && <svg>...</svg>}
|
|
220
|
+
</slot>
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
## 7. Data-Driven Components
|
|
226
|
+
|
|
227
|
+
For repetitive structures (DescriptionLists, Menus, Selects), prefer an `items` prop alongside standard slots.
|
|
228
|
+
|
|
229
|
+
```astro
|
|
230
|
+
type Item = { label: string; value: any }
|
|
231
|
+
type Props = { items?: Item[] }
|
|
232
|
+
|
|
233
|
+
<ul>
|
|
234
|
+
{items.map(item => <li>{item.label}</li>)}
|
|
235
|
+
<slot /> <!-- Still allow manual entries -->
|
|
236
|
+
</ul>
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
## 8. Development Workflow
|
|
242
|
+
|
|
243
|
+
1. **Read the Spec**: Open `src/docs/components/[name].astro` to see required HTML and CSS classes. (Component docs live under `src/docs/components/` now; `src/pages/components/` only contains route shells.)
|
|
244
|
+
2. **Analyze the API**: Check `src/component-api/[name]/` (`Astro.astro` and `HTML.astro`) or `src/component-api/[name]-api.astro` for the documented props.
|
|
245
|
+
3. **Implement**: Follow the checklist in Section 0.
|
|
246
|
+
4. **Verify**: Check that your implementation matches the "HTML" preview in the rendered `Example` for the spec page (`/components/[name]`). For framework-specific behaviour, also verify the Astro variant at `/astro/components/[name]`.
|
|
247
|
+
|
|
248
|
+
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
---
|
|
2
|
-
type Props = {
|
|
3
|
-
class?: string
|
|
4
|
-
name?: string
|
|
5
|
-
open?: boolean
|
|
6
|
-
variant?: "default" | "outlined" | "elevated" | "tonal"
|
|
7
|
-
[key: string]: any
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const title = "Accordion"
|
|
11
|
-
|
|
12
|
-
const { $id } = Astro.locals
|
|
13
|
-
const { class: className, name, open, variant, ...rest } = Astro.props
|
|
14
|
-
|
|
15
|
-
const summaryId = $id("summary")
|
|
16
|
-
const contentId = $id("content")
|
|
17
|
-
---
|
|
18
|
-
|
|
19
|
-
<details
|
|
20
|
-
name={name}
|
|
21
|
-
class:list={["ui-accordion", "ui-card", variant && `ui-${variant}`, className]}
|
|
22
|
-
open={open}
|
|
23
|
-
{...rest}
|
|
24
|
-
>
|
|
25
|
-
<!-- Summary -->
|
|
26
|
-
<!-- prettier-ignore -->
|
|
27
|
-
<summary id={summaryId} aria-controls={contentId}><slot name="summary" /><slot name="marker" /></summary>
|
|
28
|
-
|
|
29
|
-
<!-- Content -->
|
|
30
|
-
<div id={contentId} class="ui-content" role="region" aria-labelledby={summaryId}>
|
|
31
|
-
<slot />
|
|
32
|
-
</div>
|
|
33
|
-
|
|
34
|
-
<!-- Actions -->
|
|
35
|
-
{
|
|
36
|
-
Astro.slots.has("actions") && (
|
|
37
|
-
<div class="ui-actions">
|
|
38
|
-
<slot name="actions" />
|
|
39
|
-
</div>
|
|
40
|
-
)
|
|
41
|
-
}
|
|
42
|
-
</details>
|
|
1
|
+
---
|
|
2
|
+
type Props = {
|
|
3
|
+
class?: string
|
|
4
|
+
name?: string
|
|
5
|
+
open?: boolean
|
|
6
|
+
variant?: "default" | "outlined" | "elevated" | "tonal"
|
|
7
|
+
[key: string]: any
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const title = "Accordion"
|
|
11
|
+
|
|
12
|
+
const { $id } = Astro.locals
|
|
13
|
+
const { class: className, name, open, variant, ...rest } = Astro.props
|
|
14
|
+
|
|
15
|
+
const summaryId = $id("summary")
|
|
16
|
+
const contentId = $id("content")
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
<details
|
|
20
|
+
name={name}
|
|
21
|
+
class:list={["ui-accordion", "ui-card", variant && `ui-${variant}`, className]}
|
|
22
|
+
open={open}
|
|
23
|
+
{...rest}
|
|
24
|
+
>
|
|
25
|
+
<!-- Summary -->
|
|
26
|
+
<!-- prettier-ignore -->
|
|
27
|
+
<summary id={summaryId} aria-controls={contentId}><slot name="summary" /><slot name="marker" /></summary>
|
|
28
|
+
|
|
29
|
+
<!-- Content -->
|
|
30
|
+
<div id={contentId} class="ui-content" role="region" aria-labelledby={summaryId}>
|
|
31
|
+
<slot />
|
|
32
|
+
</div>
|
|
33
|
+
|
|
34
|
+
<!-- Actions -->
|
|
35
|
+
{
|
|
36
|
+
Astro.slots.has("actions") && (
|
|
37
|
+
<div class="ui-actions">
|
|
38
|
+
<slot name="actions" />
|
|
39
|
+
</div>
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
</details>
|