@antadesign/anta 0.3.12 → 0.3.14
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 +31 -36
- package/dist/anta_helpers.d.ts +10 -2
- package/dist/anta_helpers.js +5 -0
- package/dist/components/Banner.d.ts +79 -0
- package/dist/components/Banner.js +69 -0
- package/dist/components/Button.d.ts +17 -4
- package/dist/components/Button.js +8 -0
- package/dist/components/InputDate.d.ts +9 -1
- package/dist/components/InputDate.js +4 -1
- package/dist/components/Menu.d.ts +6 -5
- package/dist/components/Select.d.ts +81 -51
- package/dist/components/Select.js +21 -9
- package/dist/components/SelectFaceted.d.ts +21 -16
- package/dist/components/SelectFaceted.js +4 -4
- package/dist/components/SelectFaceted.module.css +1 -1
- package/dist/components/Text.d.ts +2 -2
- package/dist/components/Title.d.ts +2 -2
- package/dist/components/Toaster.d.ts +48 -0
- package/dist/components/Toaster.js +56 -0
- package/dist/components/Tooltip.d.ts +1 -1
- package/dist/components/select-options.d.ts +10 -5
- package/dist/components/select-options.js +1 -1
- package/dist/elements/a-banner.css +1 -0
- package/dist/elements/a-banner.d.ts +10 -0
- package/dist/elements/a-banner.js +141 -0
- package/dist/elements/a-button.css +1 -1
- package/dist/elements/a-checkbox.css +1 -1
- package/dist/elements/a-expander.css +1 -1
- package/dist/elements/a-expander.js +1 -0
- package/dist/elements/a-input-time.css +1 -1
- package/dist/elements/a-input.css +1 -1
- package/dist/elements/a-input.js +2 -2
- package/dist/elements/a-menu-item.css +1 -1
- package/dist/elements/a-menu-item.js +6 -1
- package/dist/elements/a-menu.css +1 -1
- package/dist/elements/a-menu.d.ts +6 -2
- package/dist/elements/a-menu.js +67 -28
- package/dist/elements/a-radio-group.css +1 -1
- package/dist/elements/a-radio-group.d.ts +1 -0
- package/dist/elements/a-radio-group.js +11 -2
- package/dist/elements/a-radio.css +1 -1
- package/dist/elements/a-tabs.css +1 -1
- package/dist/elements/a-tabs.d.ts +1 -0
- package/dist/elements/a-tabs.js +35 -6
- package/dist/elements/a-tag.css +1 -1
- package/dist/elements/a-text.css +1 -1
- package/dist/elements/a-title.css +1 -1
- package/dist/elements/a-toast.css +1 -0
- package/dist/elements/a-toast.d.ts +70 -0
- package/dist/elements/a-toast.js +283 -0
- package/dist/elements/a-toaster.css +1 -0
- package/dist/elements/a-toaster.d.ts +30 -0
- package/dist/elements/a-toaster.js +98 -0
- package/dist/elements/a-tooltip.js +1 -1
- package/dist/elements/index.d.ts +1 -0
- package/dist/elements/index.js +3 -0
- package/dist/general_types.d.ts +52 -9
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -0
- package/dist/jsx-runtime.d.ts +3 -1
- package/dist/reset.css +1 -1
- package/dist/theme-anta.css +1 -0
- package/dist/toaster.d.ts +99 -0
- package/dist/toaster.js +100 -0
- package/dist/tokens.css +1 -1
- package/package.json +2 -1
- package/dist/components/Card.module.css +0 -35
- package/dist/components/Progress.module.css +0 -0
- package/dist/components/Radio.d.ts +0 -37
- package/dist/components/Radio.js +0 -33
- package/dist/components/Tab.d.ts +0 -37
- package/dist/components/Tab.js +0 -5
- package/dist/components/Tabs.module.css +0 -1
- package/dist/components/Text.module.css +0 -0
package/README.md
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
# @antadesign/anta
|
|
2
2
|
|
|
3
|
-
<a href="https://antithesis.com" target="_blank" rel="noopener noreferrer">Antithesis</a> design system, **Anta**, has three layers: global CSS tokens, framework-agnostic web components that work
|
|
3
|
+
<a href="https://antithesis.com" target="_blank" rel="noopener noreferrer">Antithesis</a> design system, **Anta**, has three layers: global CSS tokens with swappable themes, framework-agnostic web components that work in plain HTML, and JSX wrappers for React and Preact.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
This constraint shapes the architecture: the web components carry the core styling and the occasional browser-API call (e.g. `getBoundingClientRect()`) without imposing a framework. Majority of web components are stateless. The React/Preact wrappers exist for dynamic state and conditional rendering.
|
|
5
|
+
One constraint shapes the architecture. Antithesis runs most of its UI in a Worker thread, driven by a custom reactive engine, and a component that mutates its own attributes would desync the Worker from the UI thread. So Anta's web components are **fully declarative**: they never touch their own attributes, and internal state lives in Shadow DOM, invisible to the outer document. The components carry the styling without imposing a framework, and most are stateless; the JSX wrappers exist for dynamic state and conditional rendering.
|
|
8
6
|
|
|
9
7
|
## Installation
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
```sh
|
|
10
|
+
npm install @antadesign/anta # or pnpm / bun
|
|
11
|
+
```
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Pin an exact version in your `package.json` (`"@antadesign/anta": "0.3.12"`) rather than a floating tag like `"latest"`, which can change between installs.
|
|
14
14
|
|
|
15
15
|
### Usage
|
|
16
16
|
|
|
@@ -25,24 +25,23 @@ import { Progress } from '@antadesign/anta'
|
|
|
25
25
|
|
|
26
26
|
### What you import (and why)
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
Five imports, listed in the order you'd add them. Tokens + elements + the JSX layer render a styled component; the reset is recommended; the theme is opt-in.
|
|
29
29
|
|
|
30
30
|
| Import | Provides | Skip if… |
|
|
31
31
|
|---|---|---|
|
|
32
|
-
| `@antadesign/anta/tokens.css` | The CSS custom properties
|
|
33
|
-
| `@antadesign/anta/reset.css` |
|
|
34
|
-
| `@antadesign/anta/elements` | Side-effect import
|
|
35
|
-
| `@antadesign/anta` | The JSX wrappers (`Progress`, `Text`, `Icon
|
|
32
|
+
| `@antadesign/anta/tokens.css` | The CSS custom properties: six tone seeds (`--anta-seed-neutral`, `--anta-seed-brand`, …), the role scales derived from them (`--bg-1…5`, `--text-1…5`, `--border-1…5`), the `.dark` ancestor toggle, and the base `font-size: 15px`. Also declares the `@layer base, anta, components, utilities` order. Override a seed to reskin its whole tone. | You're supplying your own values for the same variables. |
|
|
33
|
+
| `@antadesign/anta/reset.css` | Small modern reset (box-sizing, margins, form-control font inheritance) plus Anta's typography for headings, lists, and links. Lives in `@layer anta`. | You already have a reset and don't want Anta's typography defaults. |
|
|
34
|
+
| `@antadesign/anta/elements` | Side-effect import: registers every `<a-*>` element and attaches its CSS (also `@layer anta`). Per-element entries register just one — see [Registering elements](#registering-elements). | You render only on the server, or you import per-element entries instead. |
|
|
35
|
+
| `@antadesign/anta` | The JSX wrappers (`Progress`, `Text`, `Icon`, …): typed React/Preact components that emit `<a-*>` tags. | You write the `<a-*>` elements by hand. |
|
|
36
|
+
| `@antadesign/anta/theme-anta.css` *(optional)* | Anta's hand-tuned reference palette. The default palette is seed-derived; import this last for the exact hand-tuned values. | The seed-derived default, or your own palette, is what you want. |
|
|
36
37
|
|
|
37
|
-
The
|
|
38
|
-
|
|
39
|
-
`@antadesign/anta/elements` registers **all** elements — convenient, but it includes every element's code (and deps). To keep your bundle lean, import only the elements you use from their per-element entry points instead: `import '@antadesign/anta/elements/a-tooltip'` registers just `<a-tooltip>` **and loads just its CSS**. Unused elements — and any dependencies they pull in — then never enter your bundle. See [Registering elements](#registering-elements).
|
|
38
|
+
The order matters at the top: the element CSS reads `var(--text-1)`, `var(--bg-2)`, and friends, and only `tokens.css` defines them. Skip the tokens import and components render unstyled.
|
|
40
39
|
|
|
41
40
|
### Cascade layers
|
|
42
41
|
|
|
43
|
-
Anta's reset and element CSS live in `@layer anta`. `tokens.css` pre-declares
|
|
42
|
+
Anta's reset and element CSS live in `@layer anta`. `tokens.css` pre-declares `@layer base, anta, components, utilities;`: Anta's defaults sit above preflight resets (Tailwind's `@layer base`, Normalize) and below your `@layer components` rules and utility frameworks.
|
|
44
43
|
|
|
45
|
-
|
|
44
|
+
For a different order, declare it in your own CSS loaded **before** `tokens.css` — the first mention of each layer name fixes its position:
|
|
46
45
|
|
|
47
46
|
```css
|
|
48
47
|
/* your global.css, loaded before anta */
|
|
@@ -51,37 +50,33 @@ If you need a different order, declare it in your *own* CSS file that loads **be
|
|
|
51
50
|
|
|
52
51
|
CSS custom properties (the `:root { --… }` declarations in `tokens.css`) stay unlayered so they take effect everywhere unconditionally.
|
|
53
52
|
|
|
54
|
-
> **Gotcha: unlayered hard
|
|
55
|
-
>
|
|
56
|
-
> A snippet like this in your global CSS — common copy-paste from older reset guides — silently overrides every element rule Anta ships:
|
|
53
|
+
> **Gotcha: an unlayered hard reset defeats Anta's element rules.**
|
|
57
54
|
>
|
|
58
55
|
> ```css
|
|
59
56
|
> *, *::before, *::after { box-sizing: border-box; }
|
|
60
57
|
> * { margin: 0; }
|
|
61
58
|
> ```
|
|
62
59
|
>
|
|
63
|
-
> Unlayered styles
|
|
64
|
-
>
|
|
65
|
-
> If you're importing `@antadesign/anta/reset.css`, Anta already does the same universal `box-sizing` and margin reset, *inside* `@layer anta`. The element-level rules sitting on top are intentionally polite defaults — sensible out of the box, trivially overridable when you want something else (any rule in `@layer components` / `@layer utilities`, or any unlayered rule of your own that targets specific elements, wins automatically). **Delete the duplicate hard reset from your global CSS** so those defaults can apply. If you want to keep your own reset, wrap it in `@layer base { … }` so it sits below `anta` in the declared order and Anta's rules still win element-by-element.
|
|
60
|
+
> Unlayered styles beat layered ones regardless of specificity, so this common copy-paste outranks every per-element default Anta ships (`p` margins, list padding, and the rest). `reset.css` already does the same universal reset inside `@layer anta` — delete the duplicate from your global CSS, or wrap your own reset in `@layer base { … }` so Anta's element rules still win.
|
|
66
61
|
|
|
67
62
|
## Registering elements
|
|
68
63
|
|
|
69
|
-
The JSX wrappers
|
|
64
|
+
The JSX wrappers render `<a-*>` tags, and the classes behind those tags must be registered **before** they appear in the DOM. Registration needs `HTMLElement`, which exists only in the UI thread of a real browser; in Node.js (SSR) and Worker threads the import is a silent no-op that costs nothing but bundle size.
|
|
70
65
|
|
|
71
66
|
```ts
|
|
72
67
|
import '@antadesign/anta/elements' // auto-registers all elements
|
|
73
68
|
```
|
|
74
69
|
|
|
75
|
-
**Register only what you use.** `/elements`
|
|
70
|
+
**Register only what you use.** `/elements` registers everything; per-element entry points register one element and load just its CSS, keeping unused elements (and their dependencies) out of your bundle:
|
|
76
71
|
|
|
77
72
|
```ts
|
|
78
73
|
import '@antadesign/anta/elements/a-tooltip' // only <a-tooltip> + its CSS
|
|
79
74
|
import '@antadesign/anta/elements/a-button' // only <a-button> + its CSS
|
|
80
75
|
```
|
|
81
76
|
|
|
82
|
-
Both
|
|
77
|
+
Both forms are side-effect imports, idempotent, and SSR-safe.
|
|
83
78
|
|
|
84
|
-
The cleanest pattern is a
|
|
79
|
+
The cleanest pattern is a static import at your app's entry file, outside any component or hook:
|
|
85
80
|
|
|
86
81
|
```ts
|
|
87
82
|
// src/main.tsx (or wherever your root render lives)
|
|
@@ -91,19 +86,18 @@ import App from './App'
|
|
|
91
86
|
createRoot(document.getElementById('root')!).render(<App />)
|
|
92
87
|
```
|
|
93
88
|
|
|
94
|
-
Bundlers resolve this at module-init time, so
|
|
89
|
+
Bundlers resolve this at module-init time, so the element classes are registered before anything renders: no flash of un-upgraded elements.
|
|
95
90
|
|
|
96
91
|
> **Why not `useEffect(() => import('@antadesign/anta/elements'), [])`?**
|
|
97
|
-
>
|
|
98
|
-
> `useEffect` fires after paint, and the dynamic `import()` itself is asynchronous. In practice the browser paints unregistered custom elements (which collapse to nothing) for a few hundred milliseconds before the upgrade catches up. `useLayoutEffect` doesn't help either: the async import still resolves after paint, and `useLayoutEffect` warns during SSR hydration. A static import at the entry file avoids all of this.
|
|
92
|
+
> `useEffect` fires after paint and the dynamic import resolves later still, so the browser paints unregistered elements (which collapse to nothing) until the upgrade catches up. `useLayoutEffect` doesn't help: the import is still async, and it warns during SSR hydration.
|
|
99
93
|
|
|
100
|
-
Where
|
|
94
|
+
Where the static import goes depends on the runtime:
|
|
101
95
|
|
|
102
|
-
**Plain HTML / static sites** —
|
|
96
|
+
**Plain HTML / static sites** — a `<script type="module">` tag in the document head.
|
|
103
97
|
|
|
104
|
-
**SSR frameworks (Astro, Next.js)** —
|
|
98
|
+
**SSR frameworks (Astro, Next.js)** — a script the framework ships only to the client. In Astro: `<script>import '@antadesign/anta/elements'</script>` (Astro `<script>` tags are client-side by default). In Next.js: a top-level import in a `'use client'` file, which only enters the client chunk.
|
|
105
99
|
|
|
106
|
-
**
|
|
100
|
+
**UI in a Worker thread (the Antithesis setup)** — the UI-thread bootstrap, the script that owns the real DOM. The Worker has no `HTMLElement`, so the import must not run there.
|
|
107
101
|
|
|
108
102
|
## Framework setup
|
|
109
103
|
|
|
@@ -137,7 +131,7 @@ If you only use the JSX wrappers (`<Button>`, `<Progress>`, …) you need no set
|
|
|
137
131
|
|
|
138
132
|
Every `a-*` tag type-checks, all standard HTML tags keep working, and importing anything from `@antadesign/stickers` adds the sticker tags automatically.
|
|
139
133
|
|
|
140
|
-
**Option B** — if you can't change `jsxImportSource` (a shared tsconfig, Emotion's `@emotion/react` source
|
|
134
|
+
**Option B** — if you can't change `jsxImportSource` (a shared tsconfig, Emotion's `@emotion/react` source), merge anta's tag map into your JSX namespace yourself: anta exports it as `AntaIntrinsicElements` (and `@antadesign/stickers` as `StickerIntrinsicElements`), one `extends` in any `.d.ts` your tsconfig covers:
|
|
141
135
|
|
|
142
136
|
```ts
|
|
143
137
|
import type { AntaIntrinsicElements } from '@antadesign/anta'
|
|
@@ -166,8 +160,9 @@ Either way the tags stay fully typed — unknown `a-*` tags and wrong prop types
|
|
|
166
160
|
|
|
167
161
|
### Raw web components (no JSX)
|
|
168
162
|
|
|
163
|
+
The elements work in plain HTML; registering them also loads their CSS. The bare specifier needs a bundler or an import map to resolve.
|
|
164
|
+
|
|
169
165
|
```html
|
|
170
|
-
<link rel="stylesheet" href="@antadesign/anta/elements/a-progress.css">
|
|
171
166
|
<script type="module">
|
|
172
167
|
import '@antadesign/anta/elements'
|
|
173
168
|
</script>
|
|
@@ -187,7 +182,7 @@ Add the `dark` class to any ancestor element:
|
|
|
187
182
|
|
|
188
183
|
## Fonts
|
|
189
184
|
|
|
190
|
-
Anta is designed
|
|
185
|
+
Anta is designed for a customized <a href="https://typetype.org/fonts/tt-interphases-pro" target="_blank" rel="noopener noreferrer">TT Interphases Pro</a> but ships no font binaries. Components reference families through the `--sans-serif` and `--monospace` variables and fall back to system stacks. The base size is `font-size: 15px` on `:root` (so `1rem = 15px`), a deliberate step down from the browser's 16px for Antithesis's information-dense layouts. Both live in `tokens.css`.
|
|
191
186
|
|
|
192
187
|
To use the Antithesis fonts, register your own `@font-face` declarations and override the variables:
|
|
193
188
|
|
package/dist/anta_helpers.d.ts
CHANGED
|
@@ -29,9 +29,17 @@ export declare function wrapLabel(kids: React.ReactNode, tag: string): React.Rea
|
|
|
29
29
|
* `currentTarget` is still live. (Read as `true` for the falsy-event guard so a
|
|
30
30
|
* missing event never spuriously reads as bubbled.)
|
|
31
31
|
*/
|
|
32
|
-
|
|
32
|
+
/**
|
|
33
|
+
* The event a cross-renderer `statechange` handler receives: React wraps the native
|
|
34
|
+
* `CustomEvent` in a synthetic event (`.nativeEvent`); Preact passes it directly. `D`
|
|
35
|
+
* is the per-component `detail` vocabulary. Pair with `nativeStateChange` to unwrap.
|
|
36
|
+
* Exported so the stateful wrappers (`Banner`, and future ones) don't each re-declare
|
|
37
|
+
* this union — the CLAUDE.md "reuse shared wrapper helpers" rule.
|
|
38
|
+
*/
|
|
39
|
+
export type StateChangeEvent<D> = CustomEvent<D> | {
|
|
33
40
|
nativeEvent: CustomEvent<D>;
|
|
34
|
-
}
|
|
41
|
+
};
|
|
42
|
+
export declare function nativeStateChange<D>(e: StateChangeEvent<D>): {
|
|
35
43
|
event: CustomEvent<D>;
|
|
36
44
|
detail?: D;
|
|
37
45
|
isOwn: boolean;
|
package/dist/anta_helpers.js
CHANGED
|
@@ -86,6 +86,11 @@ class SelectableChildElement extends HTMLElementBase {
|
|
|
86
86
|
ariaProp = "ariaChecked";
|
|
87
87
|
internals = this.attachInternals?.();
|
|
88
88
|
connectedCallback() {
|
|
89
|
+
if (Object.prototype.hasOwnProperty.call(this, "selected")) {
|
|
90
|
+
const v = this.selected;
|
|
91
|
+
delete this.selected;
|
|
92
|
+
this.selected = v;
|
|
93
|
+
}
|
|
89
94
|
if (this.hasAttribute("selected")) this.applyState(true);
|
|
90
95
|
}
|
|
91
96
|
attributeChangedCallback(name) {
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { BaseProps } from "../general_types";
|
|
2
|
+
/** Public props for the `<Banner>` message strip. `message` is the leading
|
|
3
|
+
* content, `children` sit between it and `actions`, all centered in one row. */
|
|
4
|
+
export interface BannerProps extends BaseProps {
|
|
5
|
+
/** Leading message — a string (rendered at the banner type scale) or any node.
|
|
6
|
+
* Centered in the bar, followed by `children` and then `actions`. */
|
|
7
|
+
message?: React.ReactNode;
|
|
8
|
+
/** Trailing controls (buttons, links) rendered as a compact row after the
|
|
9
|
+
* message and `children`. */
|
|
10
|
+
actions?: React.ReactNode;
|
|
11
|
+
/** Free content placed BETWEEN the message and the actions. */
|
|
12
|
+
children?: React.ReactNode;
|
|
13
|
+
/** Semantic tone, or any literal CSS color (`'#ff1493'`, `'rebeccapurple'`) for
|
|
14
|
+
* a one-off custom tone. Named tones re-point the surface, text, and border
|
|
15
|
+
* colour (used if you opt into a border); a custom color keeps its hue while
|
|
16
|
+
* lightness/chroma are pinned. `'neutral'` (the default) is the same as omitting it.
|
|
17
|
+
* @defaultValue 'neutral' */
|
|
18
|
+
tone?: "neutral" | "brand" | "info" | "success" | "warning" | "critical" | (string & {});
|
|
19
|
+
/** Rounded corners for a standalone, floating banner (`border-radius: 999px`,
|
|
20
|
+
* which clamps to a stadium) instead of the edge-to-edge strip. Still borderless
|
|
21
|
+
* by default. Pass a `number` (px) or a CSS length string for a custom radius. */
|
|
22
|
+
round?: boolean | number | string;
|
|
23
|
+
/** Whether the trailing ✕ dismiss button is present. `false` removes it — drive
|
|
24
|
+
* dismissal yourself (a controlled `dismissed`, or your own control) instead.
|
|
25
|
+
* It doesn't make the banner un-dismissible, it just drops the built-in ✕.
|
|
26
|
+
* @defaultValue true */
|
|
27
|
+
closable?: boolean;
|
|
28
|
+
/** ARIA role for the strip host. `'status'` (a polite live region, so the notice
|
|
29
|
+
* reaches assistive tech) by default; pass `'alert'` for an urgent notice that
|
|
30
|
+
* should interrupt, or a landmark role.
|
|
31
|
+
* @defaultValue 'status' */
|
|
32
|
+
role?: string;
|
|
33
|
+
/** Controlled dismissed state. When provided, the consumer owns visibility: the
|
|
34
|
+
* banner follows this prop only, and clicking ✕ *requests* dismissal (reject by
|
|
35
|
+
* not updating). **Requires `onDismiss`** — controlled mode never self-hides, so
|
|
36
|
+
* without a handler to set `dismissed` the ✕ can't close the banner. Leave
|
|
37
|
+
* undefined for uncontrolled. */
|
|
38
|
+
dismissed?: boolean;
|
|
39
|
+
/** Initial dismissed state for the uncontrolled case (read once on mount). */
|
|
40
|
+
defaultDismissed?: boolean;
|
|
41
|
+
/** Fired when the user dismisses the banner (clicks ✕). Uncontrolled, the banner
|
|
42
|
+
* hides itself and this just notifies. Controlled, it's how you accept the
|
|
43
|
+
* request — set `dismissed` to `true` (or ignore to reject); pair it with
|
|
44
|
+
* `dismissed`, or the banner can't be closed. */
|
|
45
|
+
onDismiss?: () => void;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* `<Banner>` — a full-width, dismissible message strip with a bottom border.
|
|
49
|
+
*
|
|
50
|
+
* A close cousin of `<Card>` with a small, centered horizontal payload:
|
|
51
|
+
* `message` leads, `children` sit in the middle, `actions` trail, and (when
|
|
52
|
+
* `closable`) a 40px-wide, full-height ✕ fills the right edge without shifting the centered group.
|
|
53
|
+
*
|
|
54
|
+
* A pure, stateless pass-through to `<a-banner>`: the element owns dismissal and
|
|
55
|
+
* visibility, so the wrapper holds no state and grabs no ref — it maps props to
|
|
56
|
+
* attributes (safe wherever the host DOM is reconciled, incl. off the UI thread).
|
|
57
|
+
*
|
|
58
|
+
* Uncontrolled (`defaultDismissed`): the element owns visibility and the ✕
|
|
59
|
+
* self-dismisses. Controlled (`dismissed` + `onDismiss`): the wrapper emits
|
|
60
|
+
* `state="open"|"closed"`; the element treats the attribute as the source of
|
|
61
|
+
* truth and the ✕ only *requests* dismissal. The element uses Anta's shared
|
|
62
|
+
* open/closed state contract under the hood — the wrapper presents it as the
|
|
63
|
+
* banner-natural `dismissed` (closed = dismissed). See STATEFUL-COMPONENTS.md.
|
|
64
|
+
*
|
|
65
|
+
* Requires `@antadesign/anta/elements` to be imported (client-side only) to
|
|
66
|
+
* register the underlying custom element.
|
|
67
|
+
*
|
|
68
|
+
* @example Basic usage
|
|
69
|
+
* ```tsx
|
|
70
|
+
* <Banner tone="info" message="A new release is available." actions={<Button size="small" label="Update" />} />
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @example Controlled
|
|
74
|
+
* ```tsx
|
|
75
|
+
* const [hidden, setHidden] = useState(false)
|
|
76
|
+
* <Banner message="Saved." dismissed={hidden} onDismiss={() => setHidden(true)} />
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare const Banner: ({ message, actions, tone, round, closable, role, dismissed, defaultDismissed, onDismiss, className, style, children, ...rest }: BannerProps) => any;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { jsx, jsxs } from "@antadesign/anta/jsx-runtime";
|
|
2
|
+
import { nativeStateChange, toneStyle, roundStyle, roundAttr } from "../anta_helpers";
|
|
3
|
+
import { Button } from "./Button";
|
|
4
|
+
const Banner = ({
|
|
5
|
+
message,
|
|
6
|
+
actions,
|
|
7
|
+
tone,
|
|
8
|
+
round,
|
|
9
|
+
closable,
|
|
10
|
+
role = "status",
|
|
11
|
+
dismissed,
|
|
12
|
+
defaultDismissed,
|
|
13
|
+
onDismiss,
|
|
14
|
+
className,
|
|
15
|
+
style,
|
|
16
|
+
children,
|
|
17
|
+
...rest
|
|
18
|
+
}) => {
|
|
19
|
+
const controlled = dismissed != null;
|
|
20
|
+
const computedStyle = roundStyle(
|
|
21
|
+
round,
|
|
22
|
+
"--banner-round",
|
|
23
|
+
toneStyle(tone, "--banner-tone-source", style)
|
|
24
|
+
);
|
|
25
|
+
const messageNode = message == null ? null : typeof message === "string" || typeof message === "number" ? /* @__PURE__ */ jsx("a-banner-message", { slot: "message", children: message }) : /* @__PURE__ */ jsx("span", { slot: "message", style: { display: "contents" }, children: message });
|
|
26
|
+
return /* @__PURE__ */ jsxs(
|
|
27
|
+
"a-banner",
|
|
28
|
+
{
|
|
29
|
+
state: controlled ? dismissed ? "closed" : "open" : void 0,
|
|
30
|
+
"default-state": !controlled ? defaultDismissed ? "closed" : "open" : void 0,
|
|
31
|
+
tone: tone && tone !== "neutral" ? tone : void 0,
|
|
32
|
+
round: roundAttr(round),
|
|
33
|
+
role,
|
|
34
|
+
onstatechange: onDismiss ? (e) => {
|
|
35
|
+
const { detail, isOwn } = nativeStateChange(e);
|
|
36
|
+
if (isOwn && detail?.next === "closed") onDismiss();
|
|
37
|
+
} : void 0,
|
|
38
|
+
class: className,
|
|
39
|
+
style: computedStyle,
|
|
40
|
+
...rest,
|
|
41
|
+
children: [
|
|
42
|
+
messageNode,
|
|
43
|
+
children,
|
|
44
|
+
actions != null && /* @__PURE__ */ jsx("span", { slot: "actions", style: { display: "contents" }, children: actions }),
|
|
45
|
+
closable !== false && // A real <a-button> (light DOM → fully styled, keyboard-focusable) in the
|
|
46
|
+
// element's `close` slot. It fires the bubbling `dismissrequest` event via
|
|
47
|
+
// a-button's global listener, so dismissing works even without framework
|
|
48
|
+
// hydration; the element turns that into a dismiss request.
|
|
49
|
+
// CONTRACT: `data-custom-event` below MUST match `DISMISS_TRIGGER` in the
|
|
50
|
+
// element (src/elements/a-banner.ts). Duplicated, not shared — importing
|
|
51
|
+
// the element module here would self-register it and break the
|
|
52
|
+
// wrapper/element decoupling. Rename in both places.
|
|
53
|
+
/* @__PURE__ */ jsx("span", { slot: "close", style: { display: "contents" }, children: /* @__PURE__ */ jsx(
|
|
54
|
+
Button,
|
|
55
|
+
{
|
|
56
|
+
priority: "quaternary",
|
|
57
|
+
icon: "x",
|
|
58
|
+
tone,
|
|
59
|
+
"aria-label": "Dismiss",
|
|
60
|
+
"data-custom-event": "dismissrequest"
|
|
61
|
+
}
|
|
62
|
+
) })
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
export {
|
|
68
|
+
Banner
|
|
69
|
+
};
|
|
@@ -56,10 +56,23 @@ export type ContentMode = {
|
|
|
56
56
|
};
|
|
57
57
|
/** Submit axis — anchors (href) don't carry form-submission props; buttons
|
|
58
58
|
* don't carry anchor props. (Copy is no longer a Button concern — `ButtonCopy`
|
|
59
|
-
* composes a `<a-copy>` child; see `copy-props.ts`.)
|
|
59
|
+
* composes a `<a-copy>` child; see `copy-props.ts`.)
|
|
60
|
+
*
|
|
61
|
+
* `href` is **optional** so a conditional URL just works: `href={maybeUrl}`
|
|
62
|
+
* (`string | undefined`) type-checks, and a falsy href degrades to a plain
|
|
63
|
+
* button — a definite string renders `<a role="button">`, an absent / `undefined`
|
|
64
|
+
* href renders `<a-button>`, mirroring the `href != null` runtime check. Keeping
|
|
65
|
+
* it required forced a two-render (`href ? … : …`) or a conditional spread, and
|
|
66
|
+
* made TypeScript blame the wrong prop: with `href: string | undefined` matching
|
|
67
|
+
* neither branch, the intersection fell through to `PriorityMode` and reported a
|
|
68
|
+
* spurious "`priority` is missing". The anchor props (`href` / `target` / `rel` /
|
|
69
|
+
* `download` / `ping`) still can't combine with the button props (`type` /
|
|
70
|
+
* `form`). */
|
|
60
71
|
export type SubmitMode = {
|
|
61
|
-
/**
|
|
62
|
-
|
|
72
|
+
/** URL to link to. A definite string renders `<a role="button">`; omit it
|
|
73
|
+
* (or pass `undefined`) to render `<a-button>`, so `href={maybeUrl}`
|
|
74
|
+
* degrades to a plain button when the URL is absent. */
|
|
75
|
+
href?: string;
|
|
63
76
|
/** Anchor target. */
|
|
64
77
|
target?: string;
|
|
65
78
|
/** Anchor rel. */
|
|
@@ -122,4 +135,4 @@ export type ButtonProps = BaseButtonProps & PriorityMode & ContentMode & SubmitM
|
|
|
122
135
|
* <Button href="/docs" target="_blank" label="Read the docs" />
|
|
123
136
|
* ```
|
|
124
137
|
*/
|
|
125
|
-
export declare const Button: ({ priority, tone, underline, icon, iconTrailing, paddingless, label, size, loading, disabled, selected, round, href, type, form, className, style, children, ...rest }: ButtonProps) => any;
|
|
138
|
+
export declare const Button: ({ priority, tone, underline, icon, iconTrailing, paddingless, label, size, loading, disabled, selected, round, href, target, rel, download, ping, type, form, className, style, children, ...rest }: ButtonProps) => any;
|
|
@@ -14,6 +14,10 @@ const Button = ({
|
|
|
14
14
|
selected,
|
|
15
15
|
round,
|
|
16
16
|
href,
|
|
17
|
+
target,
|
|
18
|
+
rel,
|
|
19
|
+
download,
|
|
20
|
+
ping,
|
|
17
21
|
type,
|
|
18
22
|
form,
|
|
19
23
|
className,
|
|
@@ -72,6 +76,10 @@ const Button = ({
|
|
|
72
76
|
{
|
|
73
77
|
href,
|
|
74
78
|
"data-anta": "",
|
|
79
|
+
target,
|
|
80
|
+
rel,
|
|
81
|
+
download,
|
|
82
|
+
ping,
|
|
75
83
|
...sharedAttrs,
|
|
76
84
|
...rest,
|
|
77
85
|
children: inner
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { BaseProps } from '../general_types';
|
|
2
2
|
import type { IconShape } from '../elements/a-icon.shapes';
|
|
3
|
+
import { type MenuProps } from './Menu';
|
|
3
4
|
/** Snapshot passed as the 2nd argument to `onValueChange` — the new ISO value
|
|
4
5
|
* (`''` when cleared) plus the field name (mirrors `Input` / `Calendar`). */
|
|
5
6
|
export interface InputDateChangeAttrs {
|
|
@@ -43,6 +44,13 @@ export interface InputDateProps extends Omit<BaseProps, 'children'> {
|
|
|
43
44
|
status?: 'neutral' | 'brand' | 'info' | 'success' | 'warning' | 'critical';
|
|
44
45
|
/** Round the field corners — `true` for fully round, or a number / CSS length. */
|
|
45
46
|
round?: boolean | number | string;
|
|
47
|
+
/** Preferred placement of the calendar menu relative to the field. Same values as
|
|
48
|
+
* `Menu`; it auto-flips and clamps when space runs out.
|
|
49
|
+
* @defaultValue bottom-start */
|
|
50
|
+
placement?: MenuProps['placement'];
|
|
51
|
+
/** Gap in pixels between the field and the calendar menu.
|
|
52
|
+
* @defaultValue 4 */
|
|
53
|
+
offset?: number;
|
|
46
54
|
/** Show a clear button once the field has a value. */
|
|
47
55
|
clearable?: boolean;
|
|
48
56
|
/** Leading icon at the start of the field — the calendar affordance. Pass
|
|
@@ -87,4 +95,4 @@ export interface InputDateProps extends Omit<BaseProps, 'children'> {
|
|
|
87
95
|
* <InputDate label="Starts" time defaultValue="2026-06-15T09:00" onValueChange={(v) => save(v)} />
|
|
88
96
|
* ```
|
|
89
97
|
*/
|
|
90
|
-
export declare const InputDate: ({ value, defaultValue, min, max, locale, name, size, disabled, label, hint, placeholder, status, round, clearable, icon, time, hour12, onValueChange, className, style, ...rest }: InputDateProps) => any;
|
|
98
|
+
export declare const InputDate: ({ value, defaultValue, min, max, locale, name, size, disabled, label, hint, placeholder, status, round, placement, offset, clearable, icon, time, hour12, onValueChange, className, style, ...rest }: InputDateProps) => any;
|
|
@@ -33,6 +33,8 @@ const InputDate = ({
|
|
|
33
33
|
placeholder,
|
|
34
34
|
status,
|
|
35
35
|
round,
|
|
36
|
+
placement,
|
|
37
|
+
offset,
|
|
36
38
|
clearable,
|
|
37
39
|
icon,
|
|
38
40
|
time,
|
|
@@ -154,7 +156,8 @@ const InputDate = ({
|
|
|
154
156
|
Menu,
|
|
155
157
|
{
|
|
156
158
|
open,
|
|
157
|
-
placement: "bottom-start",
|
|
159
|
+
placement: placement ?? "bottom-start",
|
|
160
|
+
offset,
|
|
158
161
|
autoWidth: true,
|
|
159
162
|
className: styles.calendarMenu,
|
|
160
163
|
onStateChange: (_e, { next }) => setOpen(next),
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { BaseProps } from '../general_types';
|
|
2
2
|
export interface MenuProps extends BaseProps {
|
|
3
|
-
/** Preferred placement relative to the trigger.
|
|
4
|
-
*
|
|
5
|
-
* `
|
|
6
|
-
*
|
|
3
|
+
/** Preferred placement relative to the trigger. `bottom` / `top` place the menu
|
|
4
|
+
* below / above; `right` / `left` place it beside (like a submenu flyout). The
|
|
5
|
+
* cross-axis suffix (`-start` / `-end`) aligns the near / far edges, and no suffix
|
|
6
|
+
* centers on the trigger. The menu flips to the opposite side when the preferred
|
|
7
|
+
* one lacks room, and clamps to the viewport.
|
|
7
8
|
* @defaultValue bottom-start */
|
|
8
|
-
placement?: 'bottom-start' | 'bottom-end' | 'top-start' | 'top-end' | 'bottom' | 'top';
|
|
9
|
+
placement?: 'bottom-start' | 'bottom-end' | 'top-start' | 'top-end' | 'bottom' | 'top' | 'right-start' | 'right-end' | 'left-start' | 'left-end' | 'right' | 'left';
|
|
9
10
|
/** Open on right-click (the `contextmenu` event) of the trigger region
|
|
10
11
|
* instead of a left click, positioned at the pointer. */
|
|
11
12
|
context?: boolean;
|