@antadesign/anta 0.2.1 → 0.3.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 +14 -0
- package/dist/anta_helpers.d.ts +39 -1
- package/dist/anta_helpers.js +30 -2
- package/dist/components/Button.d.ts +7 -4
- package/dist/components/Button.js +12 -14
- package/dist/components/Checkbox.d.ts +97 -0
- package/dist/components/Checkbox.js +77 -0
- package/dist/components/Expander.d.ts +74 -0
- package/dist/components/Expander.js +53 -0
- package/dist/components/Input.d.ts +159 -0
- package/dist/components/Input.js +150 -0
- package/dist/components/Menu.d.ts +70 -0
- package/dist/components/Menu.js +42 -0
- package/dist/components/MenuGroup.d.ts +24 -0
- package/dist/components/MenuGroup.js +19 -0
- package/dist/components/MenuItem.d.ts +50 -0
- package/dist/components/MenuItem.js +41 -0
- package/dist/components/MenuSeparator.d.ts +14 -0
- package/dist/components/MenuSeparator.js +7 -0
- package/dist/components/Progress.d.ts +12 -6
- package/dist/components/Progress.js +7 -4
- package/dist/components/Radio.d.ts +37 -0
- package/dist/components/Radio.js +33 -0
- package/dist/components/RadioGroup.d.ts +119 -0
- package/dist/components/RadioGroup.js +108 -0
- package/dist/components/Tag.d.ts +38 -5
- package/dist/components/Tag.js +9 -5
- package/dist/components/Text.d.ts +27 -12
- package/dist/components/Text.js +6 -3
- package/dist/components/Title.d.ts +10 -1
- package/dist/components/Tooltip.d.ts +19 -9
- package/dist/components/Tooltip.js +2 -2
- package/dist/elements/a-button.css +1 -1
- package/dist/elements/a-button.d.ts +56 -0
- package/dist/elements/a-button.js +13 -11
- package/dist/elements/a-checkbox.css +1 -0
- package/dist/elements/a-checkbox.d.ts +52 -0
- package/dist/elements/a-checkbox.js +130 -0
- package/dist/elements/a-expander.css +1 -0
- package/dist/elements/a-expander.d.ts +28 -0
- package/dist/elements/a-expander.js +237 -0
- package/dist/elements/a-icon.d.ts +14 -0
- package/dist/elements/a-icon.shapes.css +1 -1
- package/dist/elements/a-icon.shapes.d.ts +10 -2
- package/dist/elements/a-icon.shapes.js +12 -3
- package/dist/elements/a-input.css +1 -0
- package/dist/elements/a-input.d.ts +68 -0
- package/dist/elements/a-input.js +511 -0
- package/dist/elements/a-menu-group.css +1 -0
- package/dist/elements/a-menu-group.d.ts +13 -0
- package/dist/elements/a-menu-group.js +15 -0
- package/dist/elements/a-menu-item.css +1 -0
- package/dist/elements/a-menu-item.d.ts +47 -0
- package/dist/elements/a-menu-item.js +30 -0
- package/dist/elements/a-menu-separator.css +1 -0
- package/dist/elements/a-menu-separator.d.ts +13 -0
- package/dist/elements/a-menu-separator.js +15 -0
- package/dist/elements/a-menu.css +1 -0
- package/dist/elements/a-menu.d.ts +171 -0
- package/dist/elements/a-menu.js +714 -0
- package/dist/elements/a-progress.css +1 -1
- package/dist/elements/a-progress.d.ts +12 -0
- package/dist/elements/a-progress.js +1 -0
- package/dist/elements/a-radio-group.css +1 -0
- package/dist/elements/a-radio-group.d.ts +33 -0
- package/dist/elements/a-radio-group.js +160 -0
- package/dist/elements/a-radio.css +1 -0
- package/dist/elements/a-radio.d.ts +14 -0
- package/dist/elements/a-radio.js +46 -0
- package/dist/elements/a-tag.css +1 -1
- package/dist/elements/a-text.css +1 -1
- package/dist/elements/a-text.d.ts +42 -3
- package/dist/elements/a-text.js +73 -33
- package/dist/elements/a-title.css +1 -1
- package/dist/elements/a-tooltip.d.ts +65 -15
- package/dist/elements/a-tooltip.js +155 -115
- package/dist/elements/index.d.ts +9 -0
- package/dist/elements/index.js +27 -0
- package/dist/general_types.d.ts +471 -19
- package/dist/index.d.ts +16 -0
- package/dist/index.js +16 -0
- package/dist/jsx-runtime.d.ts +42 -7
- package/dist/jsx-runtime.js +14 -2
- package/dist/tokens.css +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { jsx, jsxs } from "@antadesign/anta/jsx-runtime";
|
|
2
|
+
import { nativeStateChange, toneStyle } from "../anta_helpers";
|
|
3
|
+
import { Button } from "./Button";
|
|
4
|
+
import { Icon } from "./Icon";
|
|
5
|
+
const presence = (on) => on ? "" : void 0;
|
|
6
|
+
const isStringish = (n) => typeof n === "string" || typeof n === "number";
|
|
7
|
+
const attrsOf = (e) => {
|
|
8
|
+
const el = e?.target ?? {};
|
|
9
|
+
const value = el.value ?? "";
|
|
10
|
+
return {
|
|
11
|
+
value,
|
|
12
|
+
name: el.getAttribute?.("name") ?? void 0,
|
|
13
|
+
empty: !value,
|
|
14
|
+
valid: el.validity ? el.validity.valid : void 0,
|
|
15
|
+
validationMessage: el.validationMessage ?? ""
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
const AUTOCOMPLETE_BY_TYPE = { email: "email", tel: "tel", url: "url" };
|
|
19
|
+
const INPUTMODE_BY_TYPE = {
|
|
20
|
+
email: "email",
|
|
21
|
+
tel: "tel",
|
|
22
|
+
url: "url",
|
|
23
|
+
number: "numeric"
|
|
24
|
+
};
|
|
25
|
+
const STATUS_ICON = {
|
|
26
|
+
critical: "warning-diamond",
|
|
27
|
+
warning: "warning-triangle",
|
|
28
|
+
success: "circle-check",
|
|
29
|
+
info: "info",
|
|
30
|
+
brand: "circle-small-solid"
|
|
31
|
+
};
|
|
32
|
+
const Input = ({
|
|
33
|
+
label,
|
|
34
|
+
hint,
|
|
35
|
+
status,
|
|
36
|
+
statusIcon,
|
|
37
|
+
tone,
|
|
38
|
+
size,
|
|
39
|
+
value,
|
|
40
|
+
defaultValue,
|
|
41
|
+
multiline,
|
|
42
|
+
rows,
|
|
43
|
+
maxRows,
|
|
44
|
+
clearable,
|
|
45
|
+
leading,
|
|
46
|
+
trailing,
|
|
47
|
+
type,
|
|
48
|
+
autoComplete,
|
|
49
|
+
inputMode,
|
|
50
|
+
name,
|
|
51
|
+
placeholder,
|
|
52
|
+
disabled,
|
|
53
|
+
readOnly,
|
|
54
|
+
required,
|
|
55
|
+
dimActions,
|
|
56
|
+
spellCheck,
|
|
57
|
+
maxLength,
|
|
58
|
+
minLength,
|
|
59
|
+
pattern,
|
|
60
|
+
min,
|
|
61
|
+
max,
|
|
62
|
+
step,
|
|
63
|
+
onInput,
|
|
64
|
+
onChange,
|
|
65
|
+
onAnyChange,
|
|
66
|
+
onClearClick,
|
|
67
|
+
onClearInput,
|
|
68
|
+
children,
|
|
69
|
+
className,
|
|
70
|
+
style,
|
|
71
|
+
...rest
|
|
72
|
+
}) => {
|
|
73
|
+
const statusTone = status && status !== "neutral" ? status : void 0;
|
|
74
|
+
const glyph = statusIcon === void 0 ? statusTone ? STATUS_ICON[statusTone] : void 0 : statusIcon;
|
|
75
|
+
return /* @__PURE__ */ jsxs(
|
|
76
|
+
"a-input",
|
|
77
|
+
{
|
|
78
|
+
size: size && size !== "medium" ? size : void 0,
|
|
79
|
+
value,
|
|
80
|
+
defaultvalue: defaultValue,
|
|
81
|
+
multiline: presence(multiline || rows != null),
|
|
82
|
+
rows: rows != null ? String(rows) : void 0,
|
|
83
|
+
maxrows: maxRows != null ? String(maxRows) : void 0,
|
|
84
|
+
status: statusTone,
|
|
85
|
+
tone: tone || void 0,
|
|
86
|
+
type: !multiline && rows == null ? type : void 0,
|
|
87
|
+
name,
|
|
88
|
+
placeholder,
|
|
89
|
+
disabled: presence(disabled),
|
|
90
|
+
readonly: presence(readOnly),
|
|
91
|
+
required: presence(required),
|
|
92
|
+
"dim-actions": presence(dimActions),
|
|
93
|
+
autocomplete: autoComplete ?? (!multiline && rows == null && type ? AUTOCOMPLETE_BY_TYPE[type] : void 0),
|
|
94
|
+
inputmode: inputMode ?? (!multiline && rows == null && type ? INPUTMODE_BY_TYPE[type] : void 0),
|
|
95
|
+
spellcheck: spellCheck != null ? spellCheck ? "true" : "false" : void 0,
|
|
96
|
+
maxlength: maxLength != null ? String(maxLength) : void 0,
|
|
97
|
+
minlength: minLength != null ? String(minLength) : void 0,
|
|
98
|
+
pattern,
|
|
99
|
+
min,
|
|
100
|
+
max,
|
|
101
|
+
step,
|
|
102
|
+
"aria-invalid": status === "critical" ? "true" : void 0,
|
|
103
|
+
oninput: onInput || onAnyChange ? (e) => {
|
|
104
|
+
onInput?.(e);
|
|
105
|
+
onAnyChange?.(e, attrsOf(e));
|
|
106
|
+
} : void 0,
|
|
107
|
+
onchange: onChange || onAnyChange ? (e) => {
|
|
108
|
+
onChange?.(e);
|
|
109
|
+
onAnyChange?.(e, attrsOf(e));
|
|
110
|
+
} : void 0,
|
|
111
|
+
onclearclick: onClearClick ? (e) => onClearClick(nativeStateChange(e).event) : void 0,
|
|
112
|
+
onclearinput: onClearInput ? (e) => onClearInput(nativeStateChange(e).event) : void 0,
|
|
113
|
+
class: className,
|
|
114
|
+
style: toneStyle(tone, "--input-tone-source", style),
|
|
115
|
+
...rest,
|
|
116
|
+
children: [
|
|
117
|
+
label != null && (isStringish(label) ? /* @__PURE__ */ jsx("span", { slot: "label", children: label }) : /* @__PURE__ */ jsx("span", { slot: "label", style: { display: "contents" }, children: label })),
|
|
118
|
+
leading != null && /* @__PURE__ */ jsx("span", { slot: "leading", style: { display: "contents" }, children: leading }),
|
|
119
|
+
clearable && // A real <a-button> (light DOM → fully styled, keyboard-focusable) in
|
|
120
|
+
// the element's `clear` slot — the element owns its visibility (shown
|
|
121
|
+
// only when filled + editable). It fires the bubbling `clearrequest`
|
|
122
|
+
// event via a-button's global listener, so clearing works even without
|
|
123
|
+
// framework hydration; the element turns that into clearclick→clear().
|
|
124
|
+
// CONTRACT: the `data-custom-event` value below MUST match `CLEAR_TRIGGER`
|
|
125
|
+
// in the element (src/elements/a-input.ts). The string is duplicated, not
|
|
126
|
+
// shared — importing the element module here would self-register it and
|
|
127
|
+
// break the wrapper/element decoupling. Rename in both places.
|
|
128
|
+
/* @__PURE__ */ jsx("span", { slot: "clear", style: { display: "contents" }, children: /* @__PURE__ */ jsx(
|
|
129
|
+
Button,
|
|
130
|
+
{
|
|
131
|
+
priority: "tertiary",
|
|
132
|
+
size,
|
|
133
|
+
icon: "x",
|
|
134
|
+
"aria-label": "Clear",
|
|
135
|
+
"data-custom-event": "clearrequest"
|
|
136
|
+
}
|
|
137
|
+
) }),
|
|
138
|
+
trailing != null && /* @__PURE__ */ jsx("span", { slot: "trailing", style: { display: "contents" }, children: trailing }),
|
|
139
|
+
hint != null && /* @__PURE__ */ jsxs("span", { slot: "hint", style: { display: "contents" }, children: [
|
|
140
|
+
glyph && /* @__PURE__ */ jsx(Icon, { shape: glyph, "aria-hidden": "true" }),
|
|
141
|
+
/* @__PURE__ */ jsx("span", { children: hint })
|
|
142
|
+
] }),
|
|
143
|
+
children
|
|
144
|
+
]
|
|
145
|
+
}
|
|
146
|
+
);
|
|
147
|
+
};
|
|
148
|
+
export {
|
|
149
|
+
Input
|
|
150
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { BaseProps } from '../general_types';
|
|
2
|
+
export interface MenuProps extends BaseProps {
|
|
3
|
+
/** Preferred placement relative to the trigger. The cross-axis suffix
|
|
4
|
+
* (`-start` / `-end`) aligns the left / right edges; no suffix (`bottom` /
|
|
5
|
+
* `top`) centers the menu on the trigger. The menu auto-flips vertically and
|
|
6
|
+
* clamps horizontally when there isn't room.
|
|
7
|
+
* @defaultValue bottom-start */
|
|
8
|
+
placement?: 'bottom-start' | 'bottom-end' | 'top-start' | 'top-end' | 'bottom' | 'top';
|
|
9
|
+
/** Open on right-click (the `contextmenu` event) of the trigger region
|
|
10
|
+
* instead of a left click, positioned at the pointer. */
|
|
11
|
+
context?: boolean;
|
|
12
|
+
/** Open at the pointer coordinates rather than aligned to the trigger box.
|
|
13
|
+
* Pairs naturally with `context`; on its own it positions a left-click
|
|
14
|
+
* menu at the cursor. */
|
|
15
|
+
coord?: boolean;
|
|
16
|
+
/** For a submenu (a `<Menu>` nested inside a `MenuItem`): also open it on
|
|
17
|
+
* hover (with intent timing), not only on click. No effect on a root menu. */
|
|
18
|
+
hover?: boolean;
|
|
19
|
+
/** Gap in pixels between the trigger and the menu.
|
|
20
|
+
* @defaultValue 4 */
|
|
21
|
+
offset?: number;
|
|
22
|
+
/** Controlled open state. Omit for the default **uncontrolled** menu (it
|
|
23
|
+
* opens/closes itself via its triggers). Pass a boolean to **control** it:
|
|
24
|
+
* the menu's visibility follows `open`, and user dismiss (Esc, outside-click,
|
|
25
|
+
* select) fires `onStateChange` *without* self-closing — you update `open`
|
|
26
|
+
* in response. Submenus are always uncontrolled regardless of this. See
|
|
27
|
+
* STATEFUL-COMPONENTS.md. */
|
|
28
|
+
open?: boolean;
|
|
29
|
+
/** Fired before the open state changes — on open, and on every dismiss (Esc,
|
|
30
|
+
* outside-click, scroll, selecting an item). `event` is the cancelable
|
|
31
|
+
* `statechange`; `detail.next`/`detail.prev` are the requested/previous open
|
|
32
|
+
* state (booleans). It's the declarative way to observe a menu, and the
|
|
33
|
+
* handler you pair with `open` to drive a controlled menu (apply
|
|
34
|
+
* `detail.next` to `open`). Uncontrolled, `event.preventDefault()` vetoes the
|
|
35
|
+
* transition (e.g. keep the menu open). */
|
|
36
|
+
onStateChange?: (event: CustomEvent, detail: {
|
|
37
|
+
next: boolean;
|
|
38
|
+
prev: boolean;
|
|
39
|
+
}) => void;
|
|
40
|
+
/** The menu's contents: `MenuItem`, `MenuSeparator`, `MenuGroup`, or any
|
|
41
|
+
* custom element. */
|
|
42
|
+
children?: React.ReactNode;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Menu — a dropdown / context menu that anchors to any target and "just
|
|
46
|
+
* works". Place `<Menu>` immediately after the trigger element (a button,
|
|
47
|
+
* say); it opens on click by default. For a whole-area right-click menu, put
|
|
48
|
+
* it after the region and pass `context`.
|
|
49
|
+
*
|
|
50
|
+
* Open state is uncontrolled by default — listen for `onStateChange`
|
|
51
|
+
* (`detail: { next, prev }`) to observe it, or pass `open` to control it. You
|
|
52
|
+
* can also grab a `ref` and call `.open()` / `.close()` / `.toggle()`.
|
|
53
|
+
* Selecting a `MenuItem` closes the menu;
|
|
54
|
+
* arbitrary injected content does not. Add `data-menu-open` to any item /
|
|
55
|
+
* container to keep it open, or `data-menu-close` to a custom element to let it
|
|
56
|
+
* close.
|
|
57
|
+
*
|
|
58
|
+
* Requires `@antadesign/anta/elements` to be imported (client-side only).
|
|
59
|
+
*
|
|
60
|
+
* @example Dropdown from a button
|
|
61
|
+
* ```tsx
|
|
62
|
+
* <a-button>Actions</a-button>
|
|
63
|
+
* <Menu>
|
|
64
|
+
* <MenuItem icon="edit" label="Edit" kbd="⌘E" onSelect={onEdit} />
|
|
65
|
+
* <MenuSeparator />
|
|
66
|
+
* <MenuItem tone="critical" icon="trash" label="Delete" onSelect={onDelete} />
|
|
67
|
+
* </Menu>
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare const Menu: ({ placement, context, coord, hover, offset, open, onStateChange, className, children, ...rest }: MenuProps) => any;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { jsx } from "@antadesign/anta/jsx-runtime";
|
|
2
|
+
import { nativeStateChange } from "../anta_helpers";
|
|
3
|
+
const Menu = ({
|
|
4
|
+
placement,
|
|
5
|
+
context,
|
|
6
|
+
coord,
|
|
7
|
+
hover,
|
|
8
|
+
offset,
|
|
9
|
+
open,
|
|
10
|
+
onStateChange,
|
|
11
|
+
className,
|
|
12
|
+
children,
|
|
13
|
+
...rest
|
|
14
|
+
}) => {
|
|
15
|
+
return /* @__PURE__ */ jsx(
|
|
16
|
+
"a-menu",
|
|
17
|
+
{
|
|
18
|
+
placement: placement && placement !== "bottom-start" ? placement : void 0,
|
|
19
|
+
context: context ? "" : void 0,
|
|
20
|
+
coord: coord ? "" : void 0,
|
|
21
|
+
hover: hover ? "" : void 0,
|
|
22
|
+
offset: offset != null ? String(offset) : void 0,
|
|
23
|
+
state: open === void 0 ? void 0 : open ? "open" : "closed",
|
|
24
|
+
onstatechange: onStateChange ? (e) => {
|
|
25
|
+
const { event, detail } = nativeStateChange(e);
|
|
26
|
+
if (detail)
|
|
27
|
+
onStateChange(event, {
|
|
28
|
+
next: detail.next === "open",
|
|
29
|
+
prev: detail.prev === "open"
|
|
30
|
+
});
|
|
31
|
+
} : void 0,
|
|
32
|
+
role: "menu",
|
|
33
|
+
"aria-orientation": "vertical",
|
|
34
|
+
class: className,
|
|
35
|
+
...rest,
|
|
36
|
+
children
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
};
|
|
40
|
+
export {
|
|
41
|
+
Menu
|
|
42
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { BaseProps } from '../general_types';
|
|
2
|
+
export interface MenuGroupProps extends BaseProps {
|
|
3
|
+
/** The section heading shown above the grouped items (also the group's
|
|
4
|
+
* accessible name). */
|
|
5
|
+
label?: string;
|
|
6
|
+
/** The grouped `MenuItem`s. */
|
|
7
|
+
children?: React.ReactNode;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* MenuGroup — a titled section that organises related `MenuItem`s. Keyboard
|
|
11
|
+
* navigation flattens items across groups, skipping the heading.
|
|
12
|
+
*
|
|
13
|
+
* Add `data-menu-open` to keep the menu open after any item in the group is
|
|
14
|
+
* chosen (it forwards to the element).
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* <MenuGroup label="Edit">
|
|
19
|
+
* <MenuItem icon="copy" label="Copy" />
|
|
20
|
+
* <MenuItem icon="cut" label="Cut" />
|
|
21
|
+
* </MenuGroup>
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare const MenuGroup: ({ label, className, children, ...rest }: MenuGroupProps) => any;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx, jsxs } from "@antadesign/anta/jsx-runtime";
|
|
2
|
+
const MenuGroup = ({ label, className, children, ...rest }) => {
|
|
3
|
+
return /* @__PURE__ */ jsxs(
|
|
4
|
+
"a-menu-group",
|
|
5
|
+
{
|
|
6
|
+
role: "group",
|
|
7
|
+
"aria-label": label,
|
|
8
|
+
class: className,
|
|
9
|
+
...rest,
|
|
10
|
+
children: [
|
|
11
|
+
label != null && /* @__PURE__ */ jsx("a-menu-group-label", { "aria-hidden": "true", children: label }),
|
|
12
|
+
children
|
|
13
|
+
]
|
|
14
|
+
}
|
|
15
|
+
);
|
|
16
|
+
};
|
|
17
|
+
export {
|
|
18
|
+
MenuGroup
|
|
19
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { BaseProps } from '../general_types';
|
|
2
|
+
import type { IconShape } from '../elements/a-icon.shapes';
|
|
3
|
+
export interface MenuItemProps extends BaseProps {
|
|
4
|
+
/** Leading icon shape. */
|
|
5
|
+
icon?: IconShape;
|
|
6
|
+
/** The item's text. Omit and pass `children` for richer content. */
|
|
7
|
+
label?: string;
|
|
8
|
+
/** A trailing keyboard-shortcut hint, e.g. `"⌘E"`. */
|
|
9
|
+
kbd?: string;
|
|
10
|
+
/** A trailing icon (ignored when `submenu` is set — the chevron takes its
|
|
11
|
+
* place). */
|
|
12
|
+
iconTrailing?: IconShape;
|
|
13
|
+
/** Disable the item: greyed out, not focusable for activation, no close. */
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
/** Semantic tone — colors the label, icon, and hover tint. `critical` is the
|
|
16
|
+
* destructive action; `neutral` (the default) is the standard gray.
|
|
17
|
+
* @defaultValue neutral */
|
|
18
|
+
tone?: 'neutral' | 'brand' | 'info' | 'success' | 'warning' | 'critical';
|
|
19
|
+
/** Marks this item as a submenu parent: adds the trailing chevron,
|
|
20
|
+
* `aria-haspopup="menu"`, and an `aria-expanded` baseline (kept in sync by
|
|
21
|
+
* the nested menu). Nest the flyout as a `<Menu>` child. */
|
|
22
|
+
submenu?: boolean;
|
|
23
|
+
/** Convenience activation handler — fires on click / Enter / Space unless
|
|
24
|
+
* the item is disabled. (Mapped to the underlying click.) */
|
|
25
|
+
onSelect?: (e: any) => void;
|
|
26
|
+
/** Item content. With `label` set, children are extra content — most
|
|
27
|
+
* notably the nested `<Menu>` for a submenu parent. */
|
|
28
|
+
children?: React.ReactNode;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* MenuItem — a single selectable row inside a `Menu`. Composes a leading
|
|
32
|
+
* `icon`, a `label` (or `children`), an optional trailing `kbd` hint, and an
|
|
33
|
+
* optional trailing icon. For a submenu, set `submenu` and nest a
|
|
34
|
+
* `<Menu>` as a child — a chevron is added automatically.
|
|
35
|
+
*
|
|
36
|
+
* Selecting an item closes the menu; add `data-menu-open` to keep it open
|
|
37
|
+
* (toggles / multi-select) — it forwards to the element.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```tsx
|
|
41
|
+
* <MenuItem icon="copy" label="Duplicate" kbd="⌘D" onSelect={dup} />
|
|
42
|
+
* <MenuItem label="Word wrap" data-menu-open onSelect={toggleWrap} />
|
|
43
|
+
* <MenuItem label="Share" submenu>
|
|
44
|
+
* <Menu hover>
|
|
45
|
+
* <MenuItem label="Copy link" onSelect={copyLink} />
|
|
46
|
+
* </Menu>
|
|
47
|
+
* </MenuItem>
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare const MenuItem: ({ icon, label, kbd, iconTrailing, disabled, tone, submenu, onSelect, className, children, ...rest }: MenuItemProps) => any;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { jsx, jsxs } from "@antadesign/anta/jsx-runtime";
|
|
2
|
+
const MenuItem = ({
|
|
3
|
+
icon,
|
|
4
|
+
label,
|
|
5
|
+
kbd,
|
|
6
|
+
iconTrailing,
|
|
7
|
+
disabled,
|
|
8
|
+
tone,
|
|
9
|
+
submenu,
|
|
10
|
+
onSelect,
|
|
11
|
+
className,
|
|
12
|
+
children,
|
|
13
|
+
...rest
|
|
14
|
+
}) => {
|
|
15
|
+
return /* @__PURE__ */ jsxs(
|
|
16
|
+
"a-menu-item",
|
|
17
|
+
{
|
|
18
|
+
role: "menuitem",
|
|
19
|
+
tabIndex: 0,
|
|
20
|
+
disabled: disabled ? "" : void 0,
|
|
21
|
+
tone: tone && tone !== "neutral" ? tone : void 0,
|
|
22
|
+
submenu: submenu ? "" : void 0,
|
|
23
|
+
"aria-haspopup": submenu ? "menu" : void 0,
|
|
24
|
+
"aria-expanded": submenu ? "false" : void 0,
|
|
25
|
+
"aria-disabled": disabled ? "true" : void 0,
|
|
26
|
+
onClick: disabled ? void 0 : onSelect,
|
|
27
|
+
class: className,
|
|
28
|
+
...rest,
|
|
29
|
+
children: [
|
|
30
|
+
icon && /* @__PURE__ */ jsx("a-icon", { shape: icon, "aria-hidden": "true" }),
|
|
31
|
+
label != null && /* @__PURE__ */ jsx("a-menu-item-label", { children: label }),
|
|
32
|
+
kbd && /* @__PURE__ */ jsx("kbd", { children: kbd }),
|
|
33
|
+
submenu ? /* @__PURE__ */ jsx("a-icon", { shape: "chevron-right", "aria-hidden": "true" }) : iconTrailing && /* @__PURE__ */ jsx("a-icon", { shape: iconTrailing, "aria-hidden": "true" }),
|
|
34
|
+
children
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
};
|
|
39
|
+
export {
|
|
40
|
+
MenuItem
|
|
41
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { BaseProps } from '../general_types';
|
|
2
|
+
export interface MenuSeparatorProps extends BaseProps {
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* MenuSeparator — a thin divider between groups of `MenuItem`s.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* <MenuItem label="Edit" />
|
|
10
|
+
* <MenuSeparator />
|
|
11
|
+
* <MenuItem tone="critical" label="Delete" />
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare const MenuSeparator: ({ className, ...rest }: MenuSeparatorProps) => any;
|
|
@@ -5,12 +5,18 @@ export interface ProgressProps extends BaseProps {
|
|
|
5
5
|
/** Upper bound of the range.
|
|
6
6
|
* @defaultValue 100 */
|
|
7
7
|
max?: number;
|
|
8
|
-
/**
|
|
9
|
-
*
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
/** Colour variant, or any literal CSS colour for a one-off custom tone (the
|
|
9
|
+
* surface / indicator / text are derived from it in oklch). Named tones track
|
|
10
|
+
* light/dark automatically.
|
|
11
|
+
* @defaultValue 'neutral' */
|
|
12
|
+
tone?: 'neutral' | 'brand' | 'info' | 'success' | 'warning' | 'critical' | (string & {});
|
|
13
|
+
/** Text label displayed after the percentage. When you provide custom
|
|
14
|
+
* `children` (which replace the default label row), `label` is no longer
|
|
15
|
+
* rendered — but it still supplies the progressbar's accessible name, so
|
|
16
|
+
* pass it for screen readers to announce more than the bare percentage. */
|
|
12
17
|
label?: string;
|
|
13
|
-
/** Right-aligned hint text (e.g. "3 of 7").
|
|
18
|
+
/** Right-aligned hint text (e.g. "3 of 7"). Like `label`, it's not rendered
|
|
19
|
+
* when custom `children` are provided but still feeds the accessible name. */
|
|
14
20
|
hint?: string;
|
|
15
21
|
}
|
|
16
22
|
/**
|
|
@@ -40,4 +46,4 @@ export interface ProgressProps extends BaseProps {
|
|
|
40
46
|
* <Progress value={75} tone="info" label="Processing" />
|
|
41
47
|
* ```
|
|
42
48
|
*/
|
|
43
|
-
export declare const Progress: ({ value, max, tone, label, hint, className, children, ...rest }: ProgressProps) => any;
|
|
49
|
+
export declare const Progress: ({ value, max, tone, label, hint, className, style, children, ...rest }: ProgressProps) => any;
|
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import { jsx, jsxs } from "@antadesign/anta/jsx-runtime";
|
|
2
|
-
import { hasChildren } from "../anta_helpers";
|
|
3
|
-
const Progress = ({ value, max = 100, tone, label, hint, className, children, ...rest }) => {
|
|
2
|
+
import { hasChildren, toneStyle } from "../anta_helpers";
|
|
3
|
+
const Progress = ({ value, max = 100, tone, label, hint, className, style, children, ...rest }) => {
|
|
4
4
|
const percent = max > 0 ? Math.round(Math.min(100, Math.max(0, value / max * 100))) : 0;
|
|
5
|
+
const clampedValue = max > 0 ? Math.min(max, Math.max(0, value)) : 0;
|
|
5
6
|
const ariaLabel = [label, `${percent}%`, hint].filter(Boolean).join(" \xB7 ") || void 0;
|
|
6
7
|
return /* @__PURE__ */ jsx(
|
|
7
8
|
"a-progress",
|
|
8
9
|
{
|
|
9
10
|
value,
|
|
10
11
|
max,
|
|
11
|
-
tone,
|
|
12
|
+
tone: tone && tone !== "neutral" ? tone : void 0,
|
|
12
13
|
role: "progressbar",
|
|
13
|
-
"aria-valuenow":
|
|
14
|
+
"aria-valuenow": clampedValue,
|
|
15
|
+
"aria-valuemin": 0,
|
|
14
16
|
"aria-valuemax": max,
|
|
15
17
|
"aria-label": ariaLabel,
|
|
16
18
|
class: className,
|
|
19
|
+
style: toneStyle(tone, "--progress-tone-source", style),
|
|
17
20
|
...rest,
|
|
18
21
|
children: hasChildren(children) ? children : /* @__PURE__ */ jsxs("a-progress-label", { children: [
|
|
19
22
|
/* @__PURE__ */ jsxs("a-progress-number", { children: [
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { BaseProps } from "../general_types";
|
|
2
|
+
/** Public props for a single `<Radio>` option. */
|
|
3
|
+
export interface RadioProps extends BaseProps {
|
|
4
|
+
/** This option's value — its identity within the group and the value
|
|
5
|
+
* submitted when it's selected. */
|
|
6
|
+
value: string;
|
|
7
|
+
/** Disable just this option. */
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
/** Semantic tone, or any literal CSS color (`'#ff1493'`, `'rebeccapurple'`)
|
|
10
|
+
* for a one-off custom tone. Named tones track light/dark mode automatically;
|
|
11
|
+
* a custom colour keeps its hue + chroma and pins lightness to the brand
|
|
12
|
+
* fill curve. Defaults to the group's tone (or `brand`).
|
|
13
|
+
* @defaultValue 'brand' */
|
|
14
|
+
tone?: "brand" | "neutral" | "info" | "success" | "warning" | "critical" | (string & {});
|
|
15
|
+
/** Size variant. Defaults to the group's size (or `medium`); set it here to
|
|
16
|
+
* override a single option.
|
|
17
|
+
* @defaultValue 'medium' */
|
|
18
|
+
size?: "small" | "medium" | "large";
|
|
19
|
+
/** The label. Plain text, or any nodes (e.g. text + an info `<Icon>`). */
|
|
20
|
+
children?: React.ReactNode;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* `<Radio>` — one option in a `<RadioGroup>`.
|
|
24
|
+
*
|
|
25
|
+
* A pure, stateless pass-through to `<a-radio>`: selection, keyboard, roving
|
|
26
|
+
* tabindex, and form value are all owned by the enclosing `<a-radio-group>`
|
|
27
|
+
* (see `<RadioGroup>`), so this wrapper only maps props to attributes and
|
|
28
|
+
* projects the label. Renders nothing interactive on its own — use it inside a
|
|
29
|
+
* `<RadioGroup>`.
|
|
30
|
+
*
|
|
31
|
+
* `role="radio"` and `aria-disabled` are set here. `aria-checked` is **not** —
|
|
32
|
+
* `<a-radio>` publishes it through `ElementInternals` (off the DOM), driven by
|
|
33
|
+
* the `selected` property the enclosing `<RadioGroup>` sets.
|
|
34
|
+
*
|
|
35
|
+
* Requires `@antadesign/anta/elements` to be imported (client-side only).
|
|
36
|
+
*/
|
|
37
|
+
export declare const Radio: ({ value, disabled, tone, size, className, style, children, ...rest }: RadioProps) => any;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { jsx } from "@antadesign/anta/jsx-runtime";
|
|
2
|
+
const NAMED_TONES = /* @__PURE__ */ new Set(["brand", "neutral", "info", "success", "warning", "critical"]);
|
|
3
|
+
const Radio = ({
|
|
4
|
+
value,
|
|
5
|
+
disabled,
|
|
6
|
+
tone,
|
|
7
|
+
size,
|
|
8
|
+
className,
|
|
9
|
+
style,
|
|
10
|
+
children,
|
|
11
|
+
...rest
|
|
12
|
+
}) => {
|
|
13
|
+
const isCustomTone = tone != null && !NAMED_TONES.has(tone);
|
|
14
|
+
const computedStyle = isCustomTone ? { ...style, ["--radio-tone-source"]: tone } : style;
|
|
15
|
+
return /* @__PURE__ */ jsx(
|
|
16
|
+
"a-radio",
|
|
17
|
+
{
|
|
18
|
+
role: "radio",
|
|
19
|
+
"aria-disabled": disabled ? "true" : void 0,
|
|
20
|
+
...rest,
|
|
21
|
+
value,
|
|
22
|
+
tone: tone && tone !== "brand" ? tone : void 0,
|
|
23
|
+
size: size && size !== "medium" ? size : void 0,
|
|
24
|
+
disabled: disabled ? "" : void 0,
|
|
25
|
+
class: className,
|
|
26
|
+
style: computedStyle,
|
|
27
|
+
children
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
};
|
|
31
|
+
export {
|
|
32
|
+
Radio
|
|
33
|
+
};
|