@antadesign/anta 0.3.18 → 0.3.20
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 +38 -242
- package/dist/anta_helpers.d.ts +2 -2
- package/dist/components/Banner.d.ts +3 -3
- package/dist/components/Button.d.ts +1 -1
- package/dist/components/Calendar.d.ts +11 -12
- package/dist/components/Card.d.ts +1 -1
- package/dist/components/Card.js +1 -1
- package/dist/components/Checkbox.d.ts +8 -9
- package/dist/components/Dialog.d.ts +1 -1
- package/dist/components/Expander.d.ts +5 -6
- package/dist/components/Input.d.ts +6 -3
- package/dist/components/Input.js +3 -1
- package/dist/components/InputAutocomplete.d.ts +8 -8
- package/dist/components/InputDate.css +1 -0
- package/dist/components/InputDate.d.ts +1 -0
- package/dist/components/InputDate.js +5 -5
- package/dist/components/InputTime.d.ts +3 -3
- package/dist/components/InputTime.js +1 -1
- package/dist/components/Menu.d.ts +7 -3
- package/dist/components/Menu.js +3 -2
- package/dist/components/MenuItem.d.ts +1 -1
- package/dist/components/MenuItem.js +1 -1
- package/dist/components/Progress.d.ts +1 -1
- package/dist/components/RadioGroup.d.ts +12 -13
- package/dist/components/Select.d.ts +32 -38
- package/dist/components/Select.js +9 -13
- package/dist/components/SelectFaceted.d.ts +28 -33
- package/dist/components/SelectFaceted.js +29 -23
- package/dist/components/Slider.d.ts +5 -5
- package/dist/components/Switch.d.ts +4 -4
- package/dist/components/Tabs.d.ts +7 -7
- package/dist/components/Title.d.ts +1 -1
- package/dist/components/Toaster.d.ts +1 -1
- package/dist/components/Tooltip.d.ts +1 -1
- package/dist/components/select-parts.css +1 -0
- package/dist/elements/a-card.css +1 -1
- package/dist/elements/a-dialog.css +1 -1
- package/dist/elements/a-expander.css +1 -1
- package/dist/elements/a-expander.d.ts +1 -0
- package/dist/elements/a-expander.js +12 -2
- package/dist/elements/a-input.css +1 -1
- package/dist/elements/a-menu.js +12 -0
- package/dist/elements/a-progress.css +1 -1
- package/dist/elements/a-slider.css +1 -1
- package/dist/elements/a-tabs.css +1 -1
- package/dist/elements/a-tabs.d.ts +3 -0
- package/dist/elements/a-tabs.js +40 -1
- package/dist/elements/a-tooltip.css +1 -1
- package/dist/elements/a-tooltip.d.ts +1 -1
- package/dist/elements/a-tooltip.js +1 -1
- package/dist/elements/index.d.ts +1 -1
- package/dist/general_types.d.ts +24 -22
- package/dist/index.d.ts +3 -3
- package/dist/jsx-runtime.d.ts +9 -0
- package/docs/accessibility.md +34 -0
- package/docs/changelog.md +561 -0
- package/docs/colors.md +42 -0
- package/docs/comparison.md +28 -0
- package/docs/components/banner.md +267 -0
- package/docs/components/button.md +603 -0
- package/docs/components/card.md +321 -0
- package/docs/components/checkbox.md +296 -0
- package/docs/components/dialog.md +314 -0
- package/docs/components/expander.md +526 -0
- package/docs/components/icon.md +155 -0
- package/docs/components/input-autocomplete.md +100 -0
- package/docs/components/input-date.md +401 -0
- package/docs/components/input-time.md +174 -0
- package/docs/components/input.md +610 -0
- package/docs/components/loader.md +139 -0
- package/docs/components/menu.md +511 -0
- package/docs/components/progress.md +182 -0
- package/docs/components/radio.md +368 -0
- package/docs/components/select-faceted.md +451 -0
- package/docs/components/select.md +926 -0
- package/docs/components/slider.md +147 -0
- package/docs/components/switch.md +198 -0
- package/docs/components/tabs.md +471 -0
- package/docs/components/tag.md +185 -0
- package/docs/components/text.md +148 -0
- package/docs/components/title.md +146 -0
- package/docs/components/toaster.md +313 -0
- package/docs/components/tooltip.md +177 -0
- package/docs/credits.md +18 -0
- package/docs/index.md +52 -0
- package/docs/install-config.md +240 -0
- package/docs/normalization.md +102 -0
- package/docs/overview.md +10 -0
- package/docs/packages/stickers.md +187 -0
- package/docs/packages/table.md +153 -0
- package/docs/theming.md +13 -0
- package/package.json +10 -6
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
# Banner
|
|
2
|
+
|
|
3
|
+
A full-width message strip for a page- or section-level notice: an announcement, a
|
|
4
|
+
status change, a promotion. The `Banner` JSX wrapper renders an `<a-banner>` whose
|
|
5
|
+
content is a single centered row — `message`, optional `children`, then `actions` —
|
|
6
|
+
with a dismiss ✕ on the right edge. It's **closable** by default.
|
|
7
|
+
|
|
8
|
+
Its surface reuses `Expander`'s primary vocabulary — a toned box that tracks light
|
|
9
|
+
and dark — but laid out as a short horizontal strip sitting edge to edge, about
|
|
10
|
+
twice the resting height of `Progress`. It's **borderless by default**; add a rule
|
|
11
|
+
under it or an outline around it with `border-bottom-width` / `border-width`, the
|
|
12
|
+
same opt-in as `Progress` ([Styling](#styling)).
|
|
13
|
+
|
|
14
|
+
## Tones
|
|
15
|
+
|
|
16
|
+
Pick a semantic `tone` to tint the surface and text together — and the ✕ adopts the
|
|
17
|
+
same tone (it also sets the border color, used if you opt into a border). The set
|
|
18
|
+
matches `Expander` / `Tag`: `neutral` (the default) plus `brand`, `info`, `success`,
|
|
19
|
+
`warning`, and `critical`. Color comes from the theme tokens, so every tone tracks
|
|
20
|
+
light and dark mode automatically.
|
|
21
|
+
|
|
22
|
+
```tsx
|
|
23
|
+
<Banner tone="neutral" message="Neutral — a plain notice." /> {/* neutral is the default */}
|
|
24
|
+
<Banner tone="brand" message="Brand — a product announcement." />
|
|
25
|
+
<Banner tone="info" message="Info — a new release is available." />
|
|
26
|
+
<Banner tone="success" message="Success — your changes were saved." />
|
|
27
|
+
<Banner tone="warning" message="Warning — your trial ends in 3 days." />
|
|
28
|
+
<Banner tone="critical" message="Critical — the last deploy failed." />
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
`tone` also accepts **any literal CSS color** for a one-off tint — the hue is kept
|
|
32
|
+
while lightness and chroma are pinned to the named-tone curve (and re-tuned for
|
|
33
|
+
dark mode), the same mechanism as `Expander` / `Tag`:
|
|
34
|
+
|
|
35
|
+
```tsx
|
|
36
|
+
<Banner tone="#ff1493" message="…" />
|
|
37
|
+
<Banner tone="rebeccapurple" message="…" />
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Round
|
|
41
|
+
|
|
42
|
+
`round` rounds the corners for a **standalone** banner that floats inside a
|
|
43
|
+
container, rather than the edge-to-edge strip. It stays borderless (add
|
|
44
|
+
`border-width` for an outline). Bare `round` clamps to a stadium (half the height);
|
|
45
|
+
pass a `number` (px) or a CSS length string for a custom radius.
|
|
46
|
+
|
|
47
|
+
```tsx
|
|
48
|
+
<Banner round tone="info" message="A rounded, standalone banner." />
|
|
49
|
+
<Banner round={12} tone="success" message="A custom 12px radius." />
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Message and content
|
|
53
|
+
|
|
54
|
+
`message` is the leading content — a string (rendered at the banner type scale) or
|
|
55
|
+
any node. `children` sit between the message and the actions, for a chip, a link,
|
|
56
|
+
or a secondary line. Both are centered as one row.
|
|
57
|
+
|
|
58
|
+
```tsx
|
|
59
|
+
<Banner tone="info" message="Deployment complete.">
|
|
60
|
+
<Text size="small" priority="tertiary">· 2 minutes ago</Text>
|
|
61
|
+
</Banner>
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Actions
|
|
65
|
+
|
|
66
|
+
Pass `actions` to render trailing controls — buttons, links — as a compact row
|
|
67
|
+
after the message and children. Keep them small; the banner is a single line.
|
|
68
|
+
Give each action the banner's `tone` so the controls read as part of the strip.
|
|
69
|
+
|
|
70
|
+
```tsx
|
|
71
|
+
<Banner
|
|
72
|
+
tone="brand"
|
|
73
|
+
message="Upgrade to Pro for unlimited runs."
|
|
74
|
+
actions={<Button size="small" priority="secondary" tone="brand" label="Upgrade" />}
|
|
75
|
+
/>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Stack several actions by priority in one banner: a `primary` call to action, a
|
|
79
|
+
`secondary` alternative, and a low-emphasis `tertiary` choice, all sharing the
|
|
80
|
+
banner's tone.
|
|
81
|
+
|
|
82
|
+
```tsx
|
|
83
|
+
<Banner
|
|
84
|
+
tone="info"
|
|
85
|
+
message="A new version is ready to install."
|
|
86
|
+
actions={
|
|
87
|
+
<>
|
|
88
|
+
<Button size="small" priority="primary" tone="info" label="Update now" />
|
|
89
|
+
<Button size="small" priority="secondary" tone="info" label="Release notes" />
|
|
90
|
+
<Button size="small" priority="tertiary" tone="info" label="Later" />
|
|
91
|
+
</>
|
|
92
|
+
}
|
|
93
|
+
/>
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Dismiss
|
|
97
|
+
|
|
98
|
+
A banner is **closable** by default: a full-height ✕ on the right edge dismisses it.
|
|
99
|
+
It rests dimmed and brightens when you hover or focus it (the `Input` `dim-actions`
|
|
100
|
+
affordance). On dismiss the bar collapses its height and fades out, clipped to the
|
|
101
|
+
box (instant under `prefers-reduced-motion`).
|
|
102
|
+
|
|
103
|
+
Leave it *uncontrolled* and the banner hides itself when the ✕ is clicked (try it):
|
|
104
|
+
|
|
105
|
+
```tsx
|
|
106
|
+
{/* uncontrolled — the ✕ self-dismisses */}
|
|
107
|
+
<Banner tone="success" message="Dismiss me — I'll disappear." />
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Set `closable={false}` to drop the built-in ✕ — for a permanent banner, or when you
|
|
111
|
+
drive dismissal from your own control.
|
|
112
|
+
|
|
113
|
+
```tsx
|
|
114
|
+
<Banner tone="warning" message="A permanent notice — no dismiss button." closable={false} />
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Dismiss from an action
|
|
118
|
+
|
|
119
|
+
Give any control inside the banner **`data-banner-dismiss`** and it dismisses the
|
|
120
|
+
banner on click, through the same state contract as the ✕ — for an action that
|
|
121
|
+
closes the banner as it runs (an "Undo", a "Got it"). Try it:
|
|
122
|
+
|
|
123
|
+
```tsx
|
|
124
|
+
<Banner
|
|
125
|
+
tone="success"
|
|
126
|
+
message="Draft saved."
|
|
127
|
+
actions={<Button size="small" priority="secondary" tone="success" label="Undo" onClick={undo} data-banner-dismiss />}
|
|
128
|
+
/>
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
It's matched by presence on the nearest banner, so it works on any activated
|
|
132
|
+
control — `Button`, a plain `<a>`, or a `MenuItem` inside a dropdown — and from the
|
|
133
|
+
keyboard, since Enter/Space activation is a real click. Put it on the **terminal**
|
|
134
|
+
control, not a dropdown *trigger* (which would dismiss the banner as the menu opens):
|
|
135
|
+
|
|
136
|
+
```tsx
|
|
137
|
+
<Banner
|
|
138
|
+
message="Export ready."
|
|
139
|
+
actions={
|
|
140
|
+
<Menu trigger={<Button size="small" label="Download" iconTrailing="chevron-down" />}>
|
|
141
|
+
<MenuItem label="As CSV" onClick={csv} data-banner-dismiss />
|
|
142
|
+
<MenuItem label="As JSON" onClick={json} data-banner-dismiss />
|
|
143
|
+
</Menu>
|
|
144
|
+
}
|
|
145
|
+
/>
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
In controlled mode the click *requests* a dismiss like the ✕ does — drive the
|
|
149
|
+
result through `dismissed` (below).
|
|
150
|
+
|
|
151
|
+
## Controlled vs uncontrolled
|
|
152
|
+
|
|
153
|
+
Dismissal follows Anta's shared **state contract**. For uncontrolled use, pass
|
|
154
|
+
`defaultDismissed`; clicking ✕ then dismisses the banner. For controlled use,
|
|
155
|
+
pass `dismissed` and `onDismiss`. The banner follows `dismissed` and reports a
|
|
156
|
+
dismissal request when ✕ is clicked. Update `dismissed` to accept the request,
|
|
157
|
+
or leave it unchanged to reject it. The wrapper uses booleans, while the element
|
|
158
|
+
uses a `state` string (`closed` means dismissed):
|
|
159
|
+
|
|
160
|
+
| | `<Banner>` (JSX) | `<a-banner>` (element) |
|
|
161
|
+
|---|---|---|
|
|
162
|
+
| **Uncontrolled** | `defaultDismissed` | `default-state="open" \| "closed"` |
|
|
163
|
+
| **Controlled** | `dismissed` + `onDismiss` | `state="open" \| "closed"` + `statechange` |
|
|
164
|
+
| **Change signal** | `onDismiss()`, fired on a dismiss request | `statechange`, a cancelable `CustomEvent<{ next, prev }>` of `'open'` / `'closed'` |
|
|
165
|
+
|
|
166
|
+
Controlling it is how you persist a dismissal (write it to storage) or re-show the
|
|
167
|
+
banner later. The element never self-applies in controlled mode: set `dismissed` to
|
|
168
|
+
`true` to accept the request, or do nothing to reject.
|
|
169
|
+
|
|
170
|
+
```tsx
|
|
171
|
+
// controlled — persist the dismissal across reloads
|
|
172
|
+
const [hidden, setHidden] = useState(() => localStorage.getItem('release-banner') === 'hidden')
|
|
173
|
+
<Banner
|
|
174
|
+
tone="info"
|
|
175
|
+
message="A new release is available."
|
|
176
|
+
dismissed={hidden}
|
|
177
|
+
onDismiss={() => {
|
|
178
|
+
setHidden(true)
|
|
179
|
+
localStorage.setItem('release-banner', 'hidden')
|
|
180
|
+
}}
|
|
181
|
+
/>
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
At the element level `statechange` is **cancelable** and fires *before* the banner
|
|
185
|
+
applies anything, so a vanilla `<a-banner>` listener can `preventDefault()` a
|
|
186
|
+
dismiss. The `<Banner>` wrapper's `onDismiss` is notification-only — drive rejection
|
|
187
|
+
through `dismissed` instead.
|
|
188
|
+
|
|
189
|
+
### Props
|
|
190
|
+
|
|
191
|
+
| Prop | Type | Default | Description |
|
|
192
|
+
|------|------|---------|-------------|
|
|
193
|
+
| `actions?` | ReactNode | — | Trailing controls (buttons, links) rendered as a compact row after the
|
|
194
|
+
message and `children`. |
|
|
195
|
+
| `children?` | ReactNode | — | Free content placed BETWEEN the message and the actions. |
|
|
196
|
+
| `closable?` | boolean | true | Whether the trailing ✕ dismiss button is present. `false` removes it — drive
|
|
197
|
+
dismissal yourself (a controlled `dismissed`, or your own control) instead.
|
|
198
|
+
It removes the built-in ✕ without making the banner un-dismissible. |
|
|
199
|
+
| `defaultDismissed?` | boolean | — | Initial dismissed state for the uncontrolled case (read once on mount). |
|
|
200
|
+
| `dismissed?` | boolean | — | Controlled dismissed state. When provided, the consumer owns visibility: the
|
|
201
|
+
banner follows this prop only, and clicking ✕ *requests* dismissal (reject by
|
|
202
|
+
not updating). **Requires `onDismiss`** — controlled mode never self-hides, so
|
|
203
|
+
without a handler to set `dismissed` the ✕ can't close the banner. Leave
|
|
204
|
+
undefined for uncontrolled. |
|
|
205
|
+
| `message?` | ReactNode | — | Leading message — a string (rendered at the banner type scale) or any node.
|
|
206
|
+
Centered in the bar, followed by `children` and then `actions`. |
|
|
207
|
+
| `onDismiss?` | () => void | — | Fired when the user dismisses the banner (clicks ✕). Uncontrolled, the banner
|
|
208
|
+
hides itself and this notifies. Controlled, use it to accept the
|
|
209
|
+
request — set `dismissed` to `true` (or ignore to reject); pair it with
|
|
210
|
+
`dismissed`, or the banner can't be closed. |
|
|
211
|
+
| `role?` | string | 'status' | ARIA role for the strip host. `'status'` (a polite live region, so the notice
|
|
212
|
+
reaches assistive tech) by default; pass `'alert'` for an urgent notice that
|
|
213
|
+
should interrupt, or a landmark role. |
|
|
214
|
+
| `round?` | boolean \| number \| string | — | Rounded corners for a standalone, floating banner (`border-radius: 999px`,
|
|
215
|
+
which clamps to a stadium) instead of the edge-to-edge strip. Still borderless
|
|
216
|
+
by default. Pass a `number` (px) or a CSS length string for a custom radius. |
|
|
217
|
+
| `tone?` | 'neutral' \| 'brand' \| 'info' \| 'success' \| 'warning' \| 'critical' \| (string & {}) | 'neutral' | Semantic tone, or any literal CSS color (`'#ff1493'`, `'rebeccapurple'`) for
|
|
218
|
+
a one-off custom tone. Named tones re-point the surface, text, and border
|
|
219
|
+
color (used if you opt into a border); a custom color keeps its hue while
|
|
220
|
+
lightness/chroma are pinned. `'neutral'` (the default) is the same as omitting it. |
|
|
221
|
+
|
|
222
|
+
Use the web component directly when you are not using React or Preact and a native control does not fit.
|
|
223
|
+
|
|
224
|
+
Slots hold the message, actions, and close control. A close button dispatches
|
|
225
|
+
`dismissrequest` through `data-custom-event`.
|
|
226
|
+
|
|
227
|
+
```html
|
|
228
|
+
<a-banner role="status" tone="info">
|
|
229
|
+
<a-banner-message slot="message">A new version is ready to install.</a-banner-message>
|
|
230
|
+
<a-button slot="actions" role="button" tabindex="0" size="small" priority="primary" tone="info">
|
|
231
|
+
<a-button-label>Update now</a-button-label>
|
|
232
|
+
</a-button>
|
|
233
|
+
<a-button slot="close" role="button" tabindex="0" priority="quaternary" tone="info"
|
|
234
|
+
aria-label="Dismiss" data-custom-event="dismissrequest"><a-icon shape="x" aria-hidden="true"></a-icon></a-button>
|
|
235
|
+
</a-banner>
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
Reach for the props first: **`tone`** sets the color (any CSS color for a custom
|
|
239
|
+
tone — it derives the surface, text, and border color in oklch), **`round`** the
|
|
240
|
+
corners. The one knob worth keeping is **`--banner-tone-source`** — the color a
|
|
241
|
+
custom `tone` derives from, so set it to drive the palette from your own variable.
|
|
242
|
+
Everything else is plain CSS on the host: `min-height` for a taller bar, a
|
|
243
|
+
`border-*-width` for a rule or outline (below).
|
|
244
|
+
|
|
245
|
+
```tsx
|
|
246
|
+
<Banner tone="#e0457b" message="Custom" />
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
**Add a border.** The banner is borderless by default, but its border style and
|
|
250
|
+
color are preset at `0` width (the `Progress` reset), so you opt in by setting only
|
|
251
|
+
the **width** — `border-bottom-width` for a rule under the strip, `border-width` for
|
|
252
|
+
a full outline. The color is already tone-aware (`--banner-border`), so a toned
|
|
253
|
+
banner's border matches its tone with no extra work.
|
|
254
|
+
|
|
255
|
+
```tsx
|
|
256
|
+
<Banner tone="info" message="A rule under the strip." style={{ borderBottomWidth: 1 }} />
|
|
257
|
+
<Banner round tone="success" message="A full outline on a round banner." style={{ borderWidth: 1 }} />
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
The host `a-banner` **is** the centered bar — its surface, text, border, and layout
|
|
261
|
+
are all plain CSS on the host (`@layer anta`, so an un-layered rule of yours wins
|
|
262
|
+
without `!important`). For the individual regions, `<a-banner>` exposes
|
|
263
|
+
`::part(message)` / `::part(content)` / `::part(actions)` / `::part(close)`.
|
|
264
|
+
|
|
265
|
+
```tsx
|
|
266
|
+
<Banner tone="info" message="A taller bar." style={{ minHeight: 56 }} />
|
|
267
|
+
```
|