@nizivo/react 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/README.md +120 -2
- package/THIRD_PARTY_NOTICES +61 -0
- package/dist/_engines/react-aria/dialog.client.js +134 -0
- package/dist/_engines/react-aria/dom-allowlist.js +19 -0
- package/dist/_engines/react-aria/dom.js +31 -0
- package/dist/_engines/react-aria/locale.client.js +13 -0
- package/dist/_engines/react-aria/menu.client.js +225 -0
- package/dist/_engines/react-aria/overlay.client.js +41 -0
- package/dist/_engines/react-aria/popup.client.js +127 -0
- package/dist/_engines/react-aria/select.client.js +170 -0
- package/dist/_engines/react-aria/tabs.client.js +95 -0
- package/dist/_engines/react-aria/tooltip.client.js +72 -0
- package/dist/_internal/cx.js +11 -0
- package/dist/_internal/engine-part.d.ts +1 -0
- package/dist/_internal/field.js +20 -0
- package/dist/_internal/glyphs.js +34 -0
- package/dist/_internal/keys.js +62 -0
- package/dist/_internal/overlay.d.ts +9 -0
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/alert/alert-dismiss.client.d.ts +32 -0
- package/dist/alert/alert-dismiss.client.js +36 -0
- package/dist/alert/alert.d.ts +28 -0
- package/dist/alert/alert.js +44 -0
- package/dist/alert/index.d.ts +3 -0
- package/dist/alert/index.js +3 -0
- package/dist/augment.d.ts +13 -0
- package/dist/augment.js +0 -0
- package/dist/badge/badge.d.ts +19 -0
- package/dist/badge/badge.js +22 -0
- package/dist/badge/index.d.ts +2 -0
- package/dist/badge/index.js +1 -0
- package/dist/button/button.d.ts +54 -0
- package/dist/button/button.js +62 -0
- package/dist/button/index.d.ts +2 -0
- package/dist/button/index.js +1 -0
- package/dist/card/card.d.ts +57 -0
- package/dist/card/card.js +62 -0
- package/dist/card/card.parts.d.ts +6 -0
- package/dist/card/card.parts.js +14 -0
- package/dist/card/index.d.ts +3 -0
- package/dist/card/index.js +3 -0
- package/dist/checkbox/checkbox.client.d.ts +37 -0
- package/dist/checkbox/checkbox.client.js +81 -0
- package/dist/checkbox/index.d.ts +2 -0
- package/dist/checkbox/index.js +1 -0
- package/dist/config/config.client.d.ts +9 -0
- package/dist/config/config.client.js +18 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.js +1 -0
- package/dist/container/container.d.ts +13 -0
- package/dist/container/container.js +16 -0
- package/dist/container/index.d.ts +2 -0
- package/dist/container/index.js +1 -0
- package/dist/contracts/details.d.ts +13 -0
- package/dist/contracts/details.js +9 -0
- package/dist/contracts/index.d.ts +5 -0
- package/dist/contracts/index.js +5 -0
- package/dist/contracts/merge-props.d.ts +16 -0
- package/dist/contracts/merge-props.js +76 -0
- package/dist/contracts/render.d.ts +17 -0
- package/dist/contracts/render.js +43 -0
- package/dist/contracts/state.d.ts +42 -0
- package/dist/contracts/state.js +42 -0
- package/dist/css/alert.css +2 -0
- package/dist/css/badge.css +2 -0
- package/dist/css/base.css +2 -0
- package/dist/css/button.css +2 -0
- package/dist/css/card.css +2 -0
- package/dist/css/checkbox.css +2 -0
- package/dist/css/container.css +2 -0
- package/dist/css/delta.css +2 -0
- package/dist/css/dialog.css +2 -0
- package/dist/css/empty-state.css +2 -0
- package/dist/css/field.css +2 -0
- package/dist/css/fieldset.css +2 -0
- package/dist/css/grid.css +2 -0
- package/dist/css/heading.css +2 -0
- package/dist/css/icon-button.css +2 -0
- package/dist/css/image.css +2 -0
- package/dist/css/inline-error.css +2 -0
- package/dist/css/inline.css +2 -0
- package/dist/css/input.css +2 -0
- package/dist/css/kbd.css +2 -0
- package/dist/css/menu.css +2 -0
- package/dist/css/meter.css +2 -0
- package/dist/css/native-select.css +2 -0
- package/dist/css/progress-bar.css +2 -0
- package/dist/css/progress-ring.css +2 -0
- package/dist/css/radio-group.css +2 -0
- package/dist/css/segmented-control.css +2 -0
- package/dist/css/select.css +2 -0
- package/dist/css/separator.css +2 -0
- package/dist/css/skeleton.css +2 -0
- package/dist/css/stack.css +2 -0
- package/dist/css/switch.css +2 -0
- package/dist/css/tab-nav.css +2 -0
- package/dist/css/tabs.css +2 -0
- package/dist/css/text.css +2 -0
- package/dist/css/textarea.css +2 -0
- package/dist/css/tooltip.css +2 -0
- package/dist/delta/delta.d.ts +32 -0
- package/dist/delta/delta.js +50 -0
- package/dist/delta/index.d.ts +2 -0
- package/dist/delta/index.js +1 -0
- package/dist/dialog/dialog.client.d.ts +25 -0
- package/dist/dialog/dialog.client.js +167 -0
- package/dist/dialog/dialog.contract.d.ts +97 -0
- package/dist/dialog/dialog.parts.d.ts +6 -0
- package/dist/dialog/dialog.parts.js +15 -0
- package/dist/dialog/index.d.ts +5 -0
- package/dist/dialog/index.js +3 -0
- package/dist/empty-state/empty-state.d.ts +18 -0
- package/dist/empty-state/empty-state.js +32 -0
- package/dist/empty-state/index.d.ts +2 -0
- package/dist/empty-state/index.js +1 -0
- package/dist/field/field-scope.client.d.ts +50 -0
- package/dist/field/field-scope.client.js +205 -0
- package/dist/field/field-static.d.ts +122 -0
- package/dist/field/field-static.js +159 -0
- package/dist/field/field.d.ts +5 -0
- package/dist/field/field.js +53 -0
- package/dist/field/index.d.ts +4 -0
- package/dist/field/index.js +4 -0
- package/dist/fieldset/fieldset.d.ts +36 -0
- package/dist/fieldset/fieldset.js +63 -0
- package/dist/fieldset/index.d.ts +2 -0
- package/dist/fieldset/index.js +1 -0
- package/dist/grid/grid.d.ts +38 -0
- package/dist/grid/grid.js +28 -0
- package/dist/grid/index.d.ts +2 -0
- package/dist/grid/index.js +1 -0
- package/dist/heading/heading.d.ts +27 -0
- package/dist/heading/heading.js +26 -0
- package/dist/heading/index.d.ts +2 -0
- package/dist/heading/index.js +1 -0
- package/dist/icon-button/icon-button-static.d.ts +23 -0
- package/dist/icon-button/icon-button-static.js +83 -0
- package/dist/icon-button/icon-button.client.js +29 -0
- package/dist/icon-button/icon-button.contract.d.ts +89 -0
- package/dist/icon-button/icon-button.d.ts +5 -0
- package/dist/icon-button/icon-button.js +21 -0
- package/dist/icon-button/index.d.ts +4 -0
- package/dist/icon-button/index.js +3 -0
- package/dist/image/image.d.ts +28 -0
- package/dist/image/image.js +24 -0
- package/dist/image/index.d.ts +2 -0
- package/dist/image/index.js +1 -0
- package/dist/index.d.ts +95 -0
- package/dist/index.js +51 -0
- package/dist/inline/index.d.ts +2 -0
- package/dist/inline/index.js +1 -0
- package/dist/inline/inline.d.ts +16 -0
- package/dist/inline/inline.js +14 -0
- package/dist/inline-error/index.d.ts +2 -0
- package/dist/inline-error/index.js +1 -0
- package/dist/inline-error/inline-error.d.ts +17 -0
- package/dist/inline-error/inline-error.js +33 -0
- package/dist/input/index.d.ts +2 -0
- package/dist/input/index.js +1 -0
- package/dist/input/input.client.d.ts +39 -0
- package/dist/input/input.client.js +82 -0
- package/dist/kbd/index.d.ts +2 -0
- package/dist/kbd/index.js +1 -0
- package/dist/kbd/kbd.d.ts +19 -0
- package/dist/kbd/kbd.js +68 -0
- package/dist/menu/index.d.ts +5 -0
- package/dist/menu/index.js +3 -0
- package/dist/menu/menu.client.d.ts +14 -0
- package/dist/menu/menu.client.js +152 -0
- package/dist/menu/menu.contract.d.ts +152 -0
- package/dist/menu/menu.parts.d.ts +6 -0
- package/dist/menu/menu.parts.js +17 -0
- package/dist/meter/index.d.ts +2 -0
- package/dist/meter/index.js +1 -0
- package/dist/meter/meter.d.ts +43 -0
- package/dist/meter/meter.js +59 -0
- package/dist/native-select/index.d.ts +2 -0
- package/dist/native-select/index.js +1 -0
- package/dist/native-select/native-select.d.ts +43 -0
- package/dist/native-select/native-select.js +56 -0
- package/dist/progress-bar/index.d.ts +2 -0
- package/dist/progress-bar/index.js +1 -0
- package/dist/progress-bar/progress-bar.d.ts +34 -0
- package/dist/progress-bar/progress-bar.js +55 -0
- package/dist/progress-ring/index.d.ts +2 -0
- package/dist/progress-ring/index.js +1 -0
- package/dist/progress-ring/progress-ring.d.ts +38 -0
- package/dist/progress-ring/progress-ring.js +67 -0
- package/dist/radio-group/index.d.ts +3 -0
- package/dist/radio-group/index.js +3 -0
- package/dist/radio-group/radio-group.client.d.ts +22 -0
- package/dist/radio-group/radio-group.client.js +70 -0
- package/dist/radio-group/radio-group.d.ts +28 -0
- package/dist/radio-group/radio-group.js +35 -0
- package/dist/segmented-control/index.d.ts +3 -0
- package/dist/segmented-control/index.js +3 -0
- package/dist/segmented-control/segmented-control.client.d.ts +61 -0
- package/dist/segmented-control/segmented-control.client.js +156 -0
- package/dist/segmented-control/segmented-control.parts.d.ts +6 -0
- package/dist/segmented-control/segmented-control.parts.js +9 -0
- package/dist/select/index.d.ts +5 -0
- package/dist/select/index.js +3 -0
- package/dist/select/select.client.d.ts +12 -0
- package/dist/select/select.client.js +152 -0
- package/dist/select/select.contract.d.ts +119 -0
- package/dist/select/select.parts.d.ts +6 -0
- package/dist/select/select.parts.js +15 -0
- package/dist/separator/index.d.ts +2 -0
- package/dist/separator/index.js +1 -0
- package/dist/separator/separator.d.ts +26 -0
- package/dist/separator/separator.js +23 -0
- package/dist/skeleton/index.d.ts +2 -0
- package/dist/skeleton/index.js +1 -0
- package/dist/skeleton/skeleton.d.ts +20 -0
- package/dist/skeleton/skeleton.js +19 -0
- package/dist/stack/index.d.ts +2 -0
- package/dist/stack/index.js +1 -0
- package/dist/stack/stack.d.ts +17 -0
- package/dist/stack/stack.js +14 -0
- package/dist/styles.css +536 -0
- package/dist/switch/index.d.ts +2 -0
- package/dist/switch/index.js +1 -0
- package/dist/switch/switch.client.d.ts +33 -0
- package/dist/switch/switch.client.js +63 -0
- package/dist/tab-nav/index.d.ts +3 -0
- package/dist/tab-nav/index.js +3 -0
- package/dist/tab-nav/tab-nav.d.ts +36 -0
- package/dist/tab-nav/tab-nav.js +47 -0
- package/dist/tab-nav/tab-nav.parts.d.ts +6 -0
- package/dist/tab-nav/tab-nav.parts.js +9 -0
- package/dist/tabs/index.d.ts +4 -0
- package/dist/tabs/index.js +3 -0
- package/dist/tabs/tabs.client.d.ts +8 -0
- package/dist/tabs/tabs.client.js +68 -0
- package/dist/tabs/tabs.contract.d.ts +89 -0
- package/dist/tabs/tabs.parts.d.ts +6 -0
- package/dist/tabs/tabs.parts.js +11 -0
- package/dist/text/index.d.ts +2 -0
- package/dist/text/index.js +1 -0
- package/dist/text/text.d.ts +21 -0
- package/dist/text/text.js +17 -0
- package/dist/textarea/index.d.ts +2 -0
- package/dist/textarea/index.js +1 -0
- package/dist/textarea/textarea.client.d.ts +18 -0
- package/dist/textarea/textarea.client.js +31 -0
- package/dist/theme-script/index.d.ts +2 -0
- package/dist/theme-script/index.js +1 -0
- package/dist/theme-script/theme-script.d.ts +43 -0
- package/dist/theme-script/theme-script.js +46 -0
- package/dist/tooltip/index.d.ts +5 -0
- package/dist/tooltip/index.js +3 -0
- package/dist/tooltip/tooltip.client.d.ts +12 -0
- package/dist/tooltip/tooltip.client.js +51 -0
- package/dist/tooltip/tooltip.contract.d.ts +60 -0
- package/dist/tooltip/tooltip.parts.d.ts +6 -0
- package/dist/tooltip/tooltip.parts.js +10 -0
- package/package.json +284 -3
package/dist/kbd/kbd.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { cx } from "../_internal/cx.js";
|
|
2
|
+
import { renderElement } from "../contracts/render.js";
|
|
3
|
+
import { splitKeys } from "../_internal/keys.js";
|
|
4
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
//#region src/kbd/kbd.tsx
|
|
6
|
+
/** Key name → [Apple glyph, other platforms]. Anything else is drawn as written; one letter is uppercased. */
|
|
7
|
+
const KEYS = {
|
|
8
|
+
mod: ["⌘", "Ctrl"],
|
|
9
|
+
cmd: ["⌘", "Win"],
|
|
10
|
+
command: ["⌘", "Win"],
|
|
11
|
+
meta: ["⌘", "Win"],
|
|
12
|
+
ctrl: ["⌃", "Ctrl"],
|
|
13
|
+
control: ["⌃", "Ctrl"],
|
|
14
|
+
alt: ["⌥", "Alt"],
|
|
15
|
+
option: ["⌥", "Alt"],
|
|
16
|
+
shift: ["⇧", "Shift"],
|
|
17
|
+
enter: ["↵", "Enter"],
|
|
18
|
+
return: ["↵", "Enter"],
|
|
19
|
+
esc: ["esc", "esc"],
|
|
20
|
+
escape: ["esc", "esc"],
|
|
21
|
+
tab: ["⇥", "Tab"],
|
|
22
|
+
backspace: ["⌫", "Backspace"],
|
|
23
|
+
delete: ["⌦", "Del"],
|
|
24
|
+
space: ["Space", "Space"],
|
|
25
|
+
plus: ["+", "+"],
|
|
26
|
+
up: ["↑", "↑"],
|
|
27
|
+
down: ["↓", "↓"],
|
|
28
|
+
left: ["←", "←"],
|
|
29
|
+
right: ["→", "→"]
|
|
30
|
+
};
|
|
31
|
+
/** `"mod+shift+d"` → `["⌘⇧D", "Ctrl+Shift+D"]`: Apple glyphs run together, others join with `+`. */
|
|
32
|
+
function formatKeys(keys) {
|
|
33
|
+
const apple = [];
|
|
34
|
+
const other = [];
|
|
35
|
+
for (const key of splitKeys(keys)) {
|
|
36
|
+
const known = KEYS[key.toLowerCase()];
|
|
37
|
+
const text = key.length === 1 ? key.toUpperCase() : key;
|
|
38
|
+
apple.push(known?.[0] ?? text);
|
|
39
|
+
other.push(known?.[1] ?? text);
|
|
40
|
+
}
|
|
41
|
+
return [apple.join(""), other.join("+")];
|
|
42
|
+
}
|
|
43
|
+
function Kbd({ keys, render, className, children, ...rest }) {
|
|
44
|
+
return renderElement("kbd", render, {}, {
|
|
45
|
+
"data-slot": "kbd",
|
|
46
|
+
...rest,
|
|
47
|
+
className: cx("nz-kbd", className),
|
|
48
|
+
children: keys === void 0 ? children : glyphs(keys)
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/** One span per platform when they differ; CSS hides the other (kbd.css). */
|
|
52
|
+
function glyphs(keys) {
|
|
53
|
+
const [apple, other] = formatKeys(keys);
|
|
54
|
+
if (apple === other) return apple;
|
|
55
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
|
|
56
|
+
className: "nz-kbd-glyphs",
|
|
57
|
+
"data-slot": "kbd-glyphs",
|
|
58
|
+
"data-platform": "apple",
|
|
59
|
+
children: apple
|
|
60
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
61
|
+
className: "nz-kbd-glyphs",
|
|
62
|
+
"data-slot": "kbd-glyphs",
|
|
63
|
+
"data-platform": "other",
|
|
64
|
+
children: other
|
|
65
|
+
})] });
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
export { Kbd };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { OpenReason } from "../contracts/details.js";
|
|
2
|
+
import { MenuCheckboxItemProps, MenuCheckedReason, MenuGroupLabelProps, MenuGroupProps, MenuItemProps, MenuItemState, MenuItemTone, MenuLabels, MenuPopupProps, MenuPopupState, MenuRadioGroupProps, MenuRadioItemProps, MenuRootProps, MenuSeparatorProps, MenuSide, MenuTriggerProps, MenuTriggerState } from "./menu.contract.js";
|
|
3
|
+
import { MenuCheckboxItem, MenuGroup, MenuGroupLabel, MenuItem, MenuPopup, MenuRadioGroup, MenuRadioItem, MenuRoot, MenuSeparator, MenuTrigger } from "./menu.client.js";
|
|
4
|
+
import { menu_parts_d_exports } from "./menu.parts.js";
|
|
5
|
+
export { menu_parts_d_exports as Menu, MenuCheckboxItem, type MenuCheckboxItemProps, type MenuCheckedReason, MenuGroup, MenuGroupLabel, type MenuGroupLabelProps, type MenuGroupProps, MenuItem, type MenuItemProps, type MenuItemState, type MenuItemTone, type MenuLabels, MenuPopup, type MenuPopupProps, type MenuPopupState, MenuRadioGroup, type MenuRadioGroupProps, MenuRadioItem, type MenuRadioItemProps, MenuRoot, type MenuRootProps, MenuSeparator, type MenuSeparatorProps, type MenuSide, MenuTrigger, type MenuTriggerProps, type MenuTriggerState, type OpenReason };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { MenuCheckboxItem, MenuGroup, MenuGroupLabel, MenuItem, MenuPopup, MenuRadioGroup, MenuRadioItem, MenuRoot, MenuSeparator, MenuTrigger } from "./menu.client.js";
|
|
2
|
+
import { menu_parts_exports } from "./menu.parts.js";
|
|
3
|
+
export { menu_parts_exports as Menu, MenuCheckboxItem, MenuGroup, MenuGroupLabel, MenuItem, MenuPopup, MenuRadioGroup, MenuRadioItem, MenuRoot, MenuSeparator, MenuTrigger };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { MenuCheckboxItemProps, MenuGroupLabelProps, MenuGroupProps, MenuItemProps, MenuPopupProps, MenuRadioGroupProps, MenuRadioItemProps, MenuRootProps, MenuSeparatorProps, MenuTriggerProps } from "./menu.contract.js";
|
|
2
|
+
import { JSX } from "react";
|
|
3
|
+
//#region src/menu/menu.client.d.ts
|
|
4
|
+
export declare function MenuRoot(props: MenuRootProps): JSX.Element;
|
|
5
|
+
export declare function MenuTrigger({ className, render, ...rest }: MenuTriggerProps): JSX.Element;
|
|
6
|
+
export declare function MenuPopup({ side, align, sideOffset, container, "aria-label": label, className, style, children }: MenuPopupProps): JSX.Element;
|
|
7
|
+
export declare function MenuItem({ className, tone, icon, shortcut, textValue, "aria-keyshortcuts": keyshortcuts, href, render, children, ...rest }: MenuItemProps): JSX.Element;
|
|
8
|
+
export declare function MenuCheckboxItem({ className, tone, icon, shortcut, indicator, textValue, "aria-keyshortcuts": keyshortcuts, render, children, ...rest }: MenuCheckboxItemProps): JSX.Element;
|
|
9
|
+
export declare function MenuRadioGroup({ className, render, ...rest }: MenuRadioGroupProps): JSX.Element;
|
|
10
|
+
export declare function MenuRadioItem({ className, tone, icon, shortcut, indicator, textValue, "aria-keyshortcuts": keyshortcuts, render, children, ...rest }: MenuRadioItemProps): JSX.Element;
|
|
11
|
+
export declare function MenuGroup({ className, render, ...rest }: MenuGroupProps): JSX.Element;
|
|
12
|
+
export declare function MenuGroupLabel({ className, render, ...rest }: MenuGroupLabelProps): JSX.Element;
|
|
13
|
+
export declare function MenuSeparator({ className, render, ...rest }: MenuSeparatorProps): JSX.Element;
|
|
14
|
+
//#endregion
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cx } from "../_internal/cx.js";
|
|
3
|
+
import { toRenderFn } from "../contracts/render.js";
|
|
4
|
+
import { CheckGlyph } from "../_internal/glyphs.js";
|
|
5
|
+
import { ariaKeyShortcuts } from "../_internal/keys.js";
|
|
6
|
+
import { Kbd } from "../kbd/kbd.js";
|
|
7
|
+
import { CheckboxItem, Group, GroupLabel, Item, Popup, RadioGroup, RadioItem, Root, Separator, Trigger } from "../_engines/react-aria/menu.client.js";
|
|
8
|
+
import { isValidElement } from "react";
|
|
9
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
//#region src/menu/menu.client.tsx
|
|
11
|
+
const renderDiv = toRenderFn(void 0, "div");
|
|
12
|
+
function MenuRoot(props) {
|
|
13
|
+
return /* @__PURE__ */ jsx(Root, { ...props });
|
|
14
|
+
}
|
|
15
|
+
function MenuTrigger({ className, render, ...rest }) {
|
|
16
|
+
return /* @__PURE__ */ jsx(Trigger, {
|
|
17
|
+
...rest,
|
|
18
|
+
className: cx("nz-menu-trigger", className),
|
|
19
|
+
"data-slot": "menu-trigger",
|
|
20
|
+
render: toRenderFn(render, "button")
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
function MenuPopup({ side = "bottom", align = "start", sideOffset = 8, container, "aria-label": label, className, style, children }) {
|
|
24
|
+
return /* @__PURE__ */ jsx(Popup, {
|
|
25
|
+
side,
|
|
26
|
+
align,
|
|
27
|
+
sideOffset,
|
|
28
|
+
container,
|
|
29
|
+
className: cx("nz-menu-popup", className),
|
|
30
|
+
style,
|
|
31
|
+
"data-slot": "menu-popup",
|
|
32
|
+
render: renderDiv,
|
|
33
|
+
list: {
|
|
34
|
+
className: "nz-menu-list",
|
|
35
|
+
"data-slot": "menu-list",
|
|
36
|
+
"aria-label": label
|
|
37
|
+
},
|
|
38
|
+
children
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The row's content in Figma order. The inner spans carry classes only: every item kind shares them,
|
|
43
|
+
* and a `data-slot` belongs to one component. `indicator` is set only on checkbox and radio items.
|
|
44
|
+
*/
|
|
45
|
+
function itemContent(icon, children, shortcut, indicator) {
|
|
46
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
47
|
+
icon != null && /* @__PURE__ */ jsx("span", {
|
|
48
|
+
className: "nz-menu-item-icon",
|
|
49
|
+
"aria-hidden": "true",
|
|
50
|
+
children: icon
|
|
51
|
+
}),
|
|
52
|
+
/* @__PURE__ */ jsx("span", {
|
|
53
|
+
className: "nz-menu-item-label",
|
|
54
|
+
children
|
|
55
|
+
}),
|
|
56
|
+
shortcut !== void 0 && /* @__PURE__ */ jsx(Kbd, {
|
|
57
|
+
keys: shortcut,
|
|
58
|
+
className: "nz-menu-item-shortcut",
|
|
59
|
+
"aria-hidden": "true"
|
|
60
|
+
}),
|
|
61
|
+
indicator !== void 0 && /* @__PURE__ */ jsx("span", {
|
|
62
|
+
className: "nz-menu-item-indicator",
|
|
63
|
+
"aria-hidden": "true",
|
|
64
|
+
children: indicator ?? /* @__PURE__ */ jsx(CheckGlyph, {})
|
|
65
|
+
})
|
|
66
|
+
] });
|
|
67
|
+
}
|
|
68
|
+
/** Typeahead text and the announced shortcut, shared by every item kind. */
|
|
69
|
+
function itemBehaviour(children, textValue, shortcut, keyshortcuts) {
|
|
70
|
+
return {
|
|
71
|
+
textValue: textValue ?? (typeof children === "string" ? children : void 0),
|
|
72
|
+
"aria-keyshortcuts": keyshortcuts ?? (shortcut === void 0 ? void 0 : ariaKeyShortcuts(shortcut))
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/** The `href` of a `render={<Link href="…" />}` element, which makes the item a link item (§9.3 rule 3). */
|
|
76
|
+
function elementHref(render) {
|
|
77
|
+
if (!isValidElement(render)) return void 0;
|
|
78
|
+
const { href } = render.props;
|
|
79
|
+
return typeof href === "string" ? href : void 0;
|
|
80
|
+
}
|
|
81
|
+
function MenuItem({ className, tone = "neutral", icon, shortcut, textValue, "aria-keyshortcuts": keyshortcuts, href, render, children, ...rest }) {
|
|
82
|
+
const link = href ?? elementHref(render);
|
|
83
|
+
return /* @__PURE__ */ jsx(Item, {
|
|
84
|
+
...rest,
|
|
85
|
+
...itemBehaviour(children, textValue, shortcut, keyshortcuts),
|
|
86
|
+
className: cx("nz-menu-item", className),
|
|
87
|
+
"data-slot": "menu-item",
|
|
88
|
+
"data-tone": tone,
|
|
89
|
+
"data-focus-inset": "",
|
|
90
|
+
href: link,
|
|
91
|
+
render: toRenderFn(render, link === void 0 ? "div" : "a"),
|
|
92
|
+
children: itemContent(icon, children, shortcut)
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
function MenuCheckboxItem({ className, tone = "neutral", icon, shortcut, indicator, textValue, "aria-keyshortcuts": keyshortcuts, render, children, ...rest }) {
|
|
96
|
+
return /* @__PURE__ */ jsx(CheckboxItem, {
|
|
97
|
+
...rest,
|
|
98
|
+
...itemBehaviour(children, textValue, shortcut, keyshortcuts),
|
|
99
|
+
className: cx("nz-menu-checkbox-item", className),
|
|
100
|
+
"data-slot": "menu-checkbox-item",
|
|
101
|
+
"data-tone": tone,
|
|
102
|
+
"data-focus-inset": "",
|
|
103
|
+
render: toRenderFn(render, "div"),
|
|
104
|
+
children: itemContent(icon, children, shortcut, indicator ?? null)
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
function MenuRadioGroup({ className, render, ...rest }) {
|
|
108
|
+
return /* @__PURE__ */ jsx(RadioGroup, {
|
|
109
|
+
...rest,
|
|
110
|
+
className: cx("nz-menu-radio-group", className),
|
|
111
|
+
"data-slot": "menu-radio-group",
|
|
112
|
+
render: toRenderFn(render, "section")
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
function MenuRadioItem({ className, tone = "neutral", icon, shortcut, indicator, textValue, "aria-keyshortcuts": keyshortcuts, render, children, ...rest }) {
|
|
116
|
+
return /* @__PURE__ */ jsx(RadioItem, {
|
|
117
|
+
...rest,
|
|
118
|
+
...itemBehaviour(children, textValue, shortcut, keyshortcuts),
|
|
119
|
+
className: cx("nz-menu-radio-item", className),
|
|
120
|
+
"data-slot": "menu-radio-item",
|
|
121
|
+
"data-tone": tone,
|
|
122
|
+
"data-focus-inset": "",
|
|
123
|
+
render: toRenderFn(render, "div"),
|
|
124
|
+
children: itemContent(icon, children, shortcut, indicator ?? null)
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
function MenuGroup({ className, render, ...rest }) {
|
|
128
|
+
return /* @__PURE__ */ jsx(Group, {
|
|
129
|
+
...rest,
|
|
130
|
+
className: cx("nz-menu-group", className),
|
|
131
|
+
"data-slot": "menu-group",
|
|
132
|
+
render: toRenderFn(render, "section")
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
function MenuGroupLabel({ className, render, ...rest }) {
|
|
136
|
+
return /* @__PURE__ */ jsx(GroupLabel, {
|
|
137
|
+
...rest,
|
|
138
|
+
className: cx("nz-menu-group-label", className),
|
|
139
|
+
"data-slot": "menu-group-label",
|
|
140
|
+
render: toRenderFn(render, "header")
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
function MenuSeparator({ className, render, ...rest }) {
|
|
144
|
+
return /* @__PURE__ */ jsx(Separator, {
|
|
145
|
+
...rest,
|
|
146
|
+
className: cx("nz-menu-separator", className),
|
|
147
|
+
"data-slot": "menu-separator",
|
|
148
|
+
render: toRenderFn(render, "div")
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
//#endregion
|
|
152
|
+
export { MenuCheckboxItem, MenuGroup, MenuGroupLabel, MenuItem, MenuPopup, MenuRadioGroup, MenuRadioItem, MenuRoot, MenuSeparator, MenuTrigger };
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { RenderProp } from "../contracts/render.js";
|
|
2
|
+
import { ChangeDetails, OpenReason } from "../contracts/details.js";
|
|
3
|
+
import { Align, Side } from "../contracts/state.js";
|
|
4
|
+
import "../_internal/engine-part.js";
|
|
5
|
+
import { CSSProperties, ComponentPropsWithRef, HTMLAttributeAnchorTarget, HTMLAttributeReferrerPolicy, ReactElement, ReactNode } from "react";
|
|
6
|
+
//#region src/menu/menu.contract.d.ts
|
|
7
|
+
/** Logical side; the resolved physical side is `data-side` on the popup. */
|
|
8
|
+
export type MenuSide = "top" | "bottom" | "start" | "end";
|
|
9
|
+
/** Figma Menu Item `State=Critical`. `critical` items sit last, after a separator. */
|
|
10
|
+
export type MenuItemTone = "neutral" | "critical";
|
|
11
|
+
/** Why a checkbox item changed: the item was activated (pointer, touch or keyboard). */
|
|
12
|
+
export type MenuCheckedReason = "item-press";
|
|
13
|
+
/**
|
|
14
|
+
* Strings the engine renders (§9.3 rule 7). Engine-owned with React Aria (not overridable): `dismiss`,
|
|
15
|
+
* the visually hidden "Dismiss" buttons at both ends of the popup.
|
|
16
|
+
*/
|
|
17
|
+
export interface MenuLabels {
|
|
18
|
+
dismiss: string;
|
|
19
|
+
}
|
|
20
|
+
export interface MenuRootProps {
|
|
21
|
+
open?: boolean;
|
|
22
|
+
defaultOpen?: boolean;
|
|
23
|
+
/** `details.reason` is `'unknown'` with React Aria, which reports no cause. */
|
|
24
|
+
onOpenChange?: (open: boolean, details: ChangeDetails<OpenReason>) => void;
|
|
25
|
+
children: ReactNode;
|
|
26
|
+
}
|
|
27
|
+
export interface MenuTriggerState {
|
|
28
|
+
open: boolean;
|
|
29
|
+
pressed: boolean;
|
|
30
|
+
focusVisible: boolean;
|
|
31
|
+
disabled: boolean;
|
|
32
|
+
}
|
|
33
|
+
export interface MenuPopupState {
|
|
34
|
+
entering: boolean;
|
|
35
|
+
exiting: boolean;
|
|
36
|
+
side: Side;
|
|
37
|
+
}
|
|
38
|
+
export interface MenuItemState {
|
|
39
|
+
highlighted: boolean;
|
|
40
|
+
disabled: boolean;
|
|
41
|
+
focusVisible: boolean;
|
|
42
|
+
/** Checkbox and radio items only; always `false` on a plain item. */
|
|
43
|
+
checked: boolean;
|
|
44
|
+
}
|
|
45
|
+
export interface MenuTriggerProps extends Omit<ComponentPropsWithRef<"button">, "children"> {
|
|
46
|
+
/**
|
|
47
|
+
* Must render a `<button>`, for example an `IconButton` for a row's "…" menu:
|
|
48
|
+
* `render={<IconButton label="More actions" icon={<Ellipsis />} />}`.
|
|
49
|
+
*/
|
|
50
|
+
render?: RenderProp<MenuTriggerState>;
|
|
51
|
+
children?: ReactNode;
|
|
52
|
+
}
|
|
53
|
+
export interface MenuPopupProps {
|
|
54
|
+
/** @default 'bottom' */
|
|
55
|
+
side?: MenuSide;
|
|
56
|
+
/** @default 'start' */
|
|
57
|
+
align?: Align;
|
|
58
|
+
/** Distance from the trigger in px. @default 8 */
|
|
59
|
+
sideOffset?: number;
|
|
60
|
+
/** Portal container. Defaults to the parent overlay, else `document.body` (§12.1 L2). */
|
|
61
|
+
container?: Element | null;
|
|
62
|
+
/** Names the menu when the trigger's text does not (the trigger names it by default). */
|
|
63
|
+
"aria-label"?: string;
|
|
64
|
+
className?: string;
|
|
65
|
+
style?: CSSProperties;
|
|
66
|
+
children: ReactNode;
|
|
67
|
+
}
|
|
68
|
+
/** What every item kind shares. */
|
|
69
|
+
interface MenuItemBaseProps extends Omit<ComponentPropsWithRef<"div">, "children" | "id"> {
|
|
70
|
+
/** Typeahead text; defaults to `children` when it is a string. */
|
|
71
|
+
textValue?: string;
|
|
72
|
+
disabled?: boolean;
|
|
73
|
+
/** Called when the item is activated by pointer, touch or keyboard (Enter or Space). */
|
|
74
|
+
onAction?: () => void;
|
|
75
|
+
/** Whether activating the item closes the menu. @default true (false for a checkbox item) */
|
|
76
|
+
closeOnSelect?: boolean;
|
|
77
|
+
/** A leading glyph (16 px), for example `<Copy />` from `@nizivo/icons`. Decorative. */
|
|
78
|
+
icon?: ReactNode;
|
|
79
|
+
/**
|
|
80
|
+
* A keyboard shortcut drawn at the end with `Kbd` (`"mod+d"`), and announced through
|
|
81
|
+
* `aria-keyshortcuts`. A visual hint: the app implements the shortcut itself.
|
|
82
|
+
*/
|
|
83
|
+
shortcut?: string;
|
|
84
|
+
/** @default 'neutral' */
|
|
85
|
+
tone?: MenuItemTone;
|
|
86
|
+
children: ReactNode;
|
|
87
|
+
}
|
|
88
|
+
export interface MenuItemProps extends MenuItemBaseProps {
|
|
89
|
+
/** Makes the item a link item: it renders an `<a>` and Enter follows it (§9.3 rule 3). */
|
|
90
|
+
href?: string;
|
|
91
|
+
target?: HTMLAttributeAnchorTarget;
|
|
92
|
+
rel?: string;
|
|
93
|
+
download?: boolean | string;
|
|
94
|
+
hrefLang?: string;
|
|
95
|
+
ping?: string;
|
|
96
|
+
referrerPolicy?: HTMLAttributeReferrerPolicy;
|
|
97
|
+
/**
|
|
98
|
+
* Renders a `<div>`, or an `<a>` with `href`. A router link works through `render`:
|
|
99
|
+
* `render={<Link href="/orders" />}` (the element's `href` makes it a link item, §9.3 rule 3).
|
|
100
|
+
*/
|
|
101
|
+
render?: RenderProp<MenuItemState>;
|
|
102
|
+
}
|
|
103
|
+
export interface MenuCheckboxItemProps extends MenuItemBaseProps {
|
|
104
|
+
checked?: boolean;
|
|
105
|
+
/**
|
|
106
|
+
* The popup unmounts on close, so the Root keeps an uncontrolled item's state, keyed by the item's
|
|
107
|
+
* text (`textValue`, or string `children`): two checkbox items with the same text in one menu share
|
|
108
|
+
* it, and an item with neither starts from `defaultChecked` on every open. Use `checked` for state
|
|
109
|
+
* the app owns.
|
|
110
|
+
*/
|
|
111
|
+
defaultChecked?: boolean;
|
|
112
|
+
onCheckedChange?: (checked: boolean, details: ChangeDetails<MenuCheckedReason>) => void;
|
|
113
|
+
/** Replaces the check glyph shown while checked. */
|
|
114
|
+
indicator?: ReactNode;
|
|
115
|
+
/** Must render a `<div>`. */
|
|
116
|
+
render?: RenderProp<MenuItemState>;
|
|
117
|
+
}
|
|
118
|
+
export interface MenuRadioGroupProps extends Omit<ComponentPropsWithRef<"section">, "id" | "defaultValue"> {
|
|
119
|
+
value?: string | null;
|
|
120
|
+
/**
|
|
121
|
+
* The popup unmounts on close, so the Root keeps an uncontrolled group's choice, keyed by its
|
|
122
|
+
* items' `value`s (radio items placed directly, or through fragments and wrapper elements).
|
|
123
|
+
*/
|
|
124
|
+
defaultValue?: string | null;
|
|
125
|
+
/** `details.reason` is `'unknown'` with React Aria, which reports no cause. */
|
|
126
|
+
onValueChange?: (value: string, details: ChangeDetails<MenuCheckedReason>) => void;
|
|
127
|
+
/** Must render a `<section>`. */
|
|
128
|
+
render?: RenderProp<Record<string, never>>;
|
|
129
|
+
}
|
|
130
|
+
export interface MenuRadioItemProps extends MenuItemBaseProps {
|
|
131
|
+
/** The value the group reports when this item is chosen. */
|
|
132
|
+
value: string;
|
|
133
|
+
/** Replaces the check glyph shown while chosen. */
|
|
134
|
+
indicator?: ReactNode;
|
|
135
|
+
/** Must render a `<div>`. */
|
|
136
|
+
render?: RenderProp<MenuItemState>;
|
|
137
|
+
}
|
|
138
|
+
type NoState = Record<string, never>;
|
|
139
|
+
export interface MenuGroupProps extends Omit<ComponentPropsWithRef<"section">, "id"> {
|
|
140
|
+
/** Must render a `<section>`. */
|
|
141
|
+
render?: RenderProp<NoState>;
|
|
142
|
+
}
|
|
143
|
+
export interface MenuGroupLabelProps extends Omit<ComponentPropsWithRef<"header">, "id"> {
|
|
144
|
+
/** Must render a `<header>`. */
|
|
145
|
+
render?: RenderProp<NoState>;
|
|
146
|
+
}
|
|
147
|
+
export interface MenuSeparatorProps extends Omit<ComponentPropsWithRef<"div">, "children"> {
|
|
148
|
+
/** Must render a `<div>`. */
|
|
149
|
+
render?: RenderProp<NoState>;
|
|
150
|
+
}
|
|
151
|
+
//#endregion
|
|
152
|
+
export type { OpenReason };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { MenuCheckboxItem, MenuGroup, MenuGroupLabel, MenuItem, MenuPopup, MenuRadioGroup, MenuRadioItem, MenuRoot, MenuSeparator, MenuTrigger } from "./menu.client.js";
|
|
2
|
+
declare namespace menu_parts_d_exports {
|
|
3
|
+
export { MenuCheckboxItem as CheckboxItem, MenuGroup as Group, MenuGroupLabel as GroupLabel, MenuItem as Item, MenuPopup as Popup, MenuRadioGroup as RadioGroup, MenuRadioItem as RadioItem, MenuRoot as Root, MenuSeparator as Separator, MenuTrigger as Trigger };
|
|
4
|
+
}
|
|
5
|
+
//#endregion
|
|
6
|
+
export { MenuCheckboxItem as CheckboxItem, MenuGroup as Group, MenuGroupLabel as GroupLabel, MenuItem as Item, MenuPopup as Popup, MenuRadioGroup as RadioGroup, MenuRadioItem as RadioItem, MenuRoot as Root, MenuSeparator as Separator, MenuTrigger as Trigger, menu_parts_d_exports };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { MenuCheckboxItem, MenuGroup, MenuGroupLabel, MenuItem, MenuPopup, MenuRadioGroup, MenuRadioItem, MenuRoot, MenuSeparator, MenuTrigger } from "./menu.client.js";
|
|
3
|
+
//#region src/menu/menu.parts.ts
|
|
4
|
+
var menu_parts_exports = /* @__PURE__ */ __exportAll({
|
|
5
|
+
CheckboxItem: () => MenuCheckboxItem,
|
|
6
|
+
Group: () => MenuGroup,
|
|
7
|
+
GroupLabel: () => MenuGroupLabel,
|
|
8
|
+
Item: () => MenuItem,
|
|
9
|
+
Popup: () => MenuPopup,
|
|
10
|
+
RadioGroup: () => MenuRadioGroup,
|
|
11
|
+
RadioItem: () => MenuRadioItem,
|
|
12
|
+
Root: () => MenuRoot,
|
|
13
|
+
Separator: () => MenuSeparator,
|
|
14
|
+
Trigger: () => MenuTrigger
|
|
15
|
+
});
|
|
16
|
+
//#endregion
|
|
17
|
+
export { MenuCheckboxItem as CheckboxItem, MenuGroup as Group, MenuGroupLabel as GroupLabel, MenuItem as Item, MenuPopup as Popup, MenuRadioGroup as RadioGroup, MenuRadioItem as RadioItem, MenuRoot as Root, MenuSeparator as Separator, MenuTrigger as Trigger, menu_parts_exports };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Meter } from "./meter.js";
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { RenderProp } from "../contracts/render.js";
|
|
2
|
+
import { ComponentPropsWithRef, ReactElement, ReactNode } from "react";
|
|
3
|
+
//#region src/meter/meter.d.ts
|
|
4
|
+
/** The colour of the optimum region. Outside it the browser's ranges pick warning, then critical. */
|
|
5
|
+
export type MeterTone = "brand" | "success" | "warning" | "critical" | "neutral";
|
|
6
|
+
export interface MeterState {
|
|
7
|
+
tone: MeterTone;
|
|
8
|
+
/** The value clamped to `min…max`. */
|
|
9
|
+
value: number;
|
|
10
|
+
min: number;
|
|
11
|
+
max: number;
|
|
12
|
+
}
|
|
13
|
+
export interface MeterProps extends Omit<ComponentPropsWithRef<"div">, "children"> {
|
|
14
|
+
/** A measurement within a known range (storage used, stock left), not progress. Clamped to `min…max`. */
|
|
15
|
+
value: number;
|
|
16
|
+
/** @default 0 */
|
|
17
|
+
min?: number;
|
|
18
|
+
/** Must be above `min`. @default 100 */
|
|
19
|
+
max?: number;
|
|
20
|
+
/** Upper end of the low range. */
|
|
21
|
+
low?: number;
|
|
22
|
+
/** Lower end of the high range. */
|
|
23
|
+
high?: number;
|
|
24
|
+
/**
|
|
25
|
+
* The best value. Without it the browser puts the optimum in the middle of the range. For a quota or
|
|
26
|
+
* usage meter where high is bad, set `optimum={min}`; for stock, where low is bad, set `optimum={max}`.
|
|
27
|
+
*/
|
|
28
|
+
optimum?: number;
|
|
29
|
+
/** The visible name. Without it, name the meter with `aria-label` or `aria-labelledby`. */
|
|
30
|
+
label?: ReactNode;
|
|
31
|
+
/** Shows the value beside the label (hidden from assistive technology, which reads the meter itself). @default true */
|
|
32
|
+
showValue?: boolean;
|
|
33
|
+
/** @default 'brand' */
|
|
34
|
+
tone?: MeterTone;
|
|
35
|
+
/** BCP 47 tag for the percentage. @default 'en-US' */
|
|
36
|
+
locale?: string;
|
|
37
|
+
/** Replaces the shown percentage and is read instead of it, for example "310 of 500". */
|
|
38
|
+
valueText?: string;
|
|
39
|
+
/** Composition of the root; the native `<meter>` inside keeps its semantics. */
|
|
40
|
+
render?: RenderProp<MeterState>;
|
|
41
|
+
}
|
|
42
|
+
export declare function Meter({ value, min, max, low, high, optimum, label, showValue, tone, locale, valueText, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, render, className, ...rest }: MeterProps): ReactElement;
|
|
43
|
+
//#endregion
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { cx } from "../_internal/cx.js";
|
|
2
|
+
import { renderElement } from "../contracts/render.js";
|
|
3
|
+
import { useId } from "react";
|
|
4
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
//#region src/meter/meter.tsx
|
|
6
|
+
function Meter({ value, min = 0, max = 100, low, high, optimum, label, showValue = true, tone = "brand", locale = "en-US", valueText, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, render, className, ...rest }) {
|
|
7
|
+
const labelId = useId();
|
|
8
|
+
const lo = Number.isFinite(min) ? min : 0;
|
|
9
|
+
const hi = Number.isFinite(max) && max > lo ? max : lo + 100;
|
|
10
|
+
const current = Number.isFinite(value) ? Math.min(Math.max(value, lo), hi) : lo;
|
|
11
|
+
const shown = valueText ?? new Intl.NumberFormat(locale, {
|
|
12
|
+
style: "percent",
|
|
13
|
+
maximumFractionDigits: 0
|
|
14
|
+
}).format((current - lo) / (hi - lo));
|
|
15
|
+
const hasLabel = label != null;
|
|
16
|
+
return renderElement("div", render, {
|
|
17
|
+
tone,
|
|
18
|
+
value: current,
|
|
19
|
+
min: lo,
|
|
20
|
+
max: hi
|
|
21
|
+
}, {
|
|
22
|
+
"data-slot": "meter",
|
|
23
|
+
"data-tone": tone,
|
|
24
|
+
...rest,
|
|
25
|
+
className: cx("nz-meter", className),
|
|
26
|
+
children: /* @__PURE__ */ jsxs(Fragment, { children: [(hasLabel || showValue) && /* @__PURE__ */ jsxs("div", {
|
|
27
|
+
className: "nz-meter-header",
|
|
28
|
+
"data-slot": "meter-header",
|
|
29
|
+
children: [hasLabel && /* @__PURE__ */ jsx("span", {
|
|
30
|
+
id: labelId,
|
|
31
|
+
className: "nz-meter-label",
|
|
32
|
+
"data-slot": "meter-label",
|
|
33
|
+
children: label
|
|
34
|
+
}), showValue && /* @__PURE__ */ jsx("span", {
|
|
35
|
+
className: "nz-meter-value",
|
|
36
|
+
"data-slot": "meter-value",
|
|
37
|
+
"aria-hidden": "true",
|
|
38
|
+
children: shown
|
|
39
|
+
})]
|
|
40
|
+
}), /* @__PURE__ */ jsx("meter", {
|
|
41
|
+
className: "nz-meter-track",
|
|
42
|
+
"data-slot": "meter-track",
|
|
43
|
+
min: lo,
|
|
44
|
+
max: hi,
|
|
45
|
+
value: current,
|
|
46
|
+
low: finite(low),
|
|
47
|
+
high: finite(high),
|
|
48
|
+
optimum: finite(optimum),
|
|
49
|
+
"aria-label": ariaLabel,
|
|
50
|
+
"aria-labelledby": ariaLabelledBy ?? (hasLabel ? labelId : void 0),
|
|
51
|
+
"aria-valuetext": valueText
|
|
52
|
+
})] })
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
function finite(value) {
|
|
56
|
+
return value !== void 0 && Number.isFinite(value) ? value : void 0;
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
export { Meter };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { NativeSelect } from "./native-select.js";
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { RenderProp } from "../contracts/render.js";
|
|
2
|
+
import { ControlSize } from "../augment.js";
|
|
3
|
+
import { ComponentPropsWithRef, ReactElement, ReactNode } from "react";
|
|
4
|
+
//#region src/native-select/native-select.d.ts
|
|
5
|
+
export interface NativeSelectState {
|
|
6
|
+
size: ControlSize;
|
|
7
|
+
/** An error message is presented: the `invalid` prop, or `aria-invalid` from a Field. */
|
|
8
|
+
invalid: boolean;
|
|
9
|
+
disabled: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface NativeSelectProps extends Omit<ComponentPropsWithRef<"select">, "size" | "multiple" | "readOnly"> {
|
|
12
|
+
/** 32 / 40 / 48 px, the Select trigger's heights. @default 'md' */
|
|
13
|
+
size?: ControlSize;
|
|
14
|
+
/**
|
|
15
|
+
* An error message is presented for this select (§8.3). A Field's function child passes
|
|
16
|
+
* `aria-invalid`, which counts too.
|
|
17
|
+
*/
|
|
18
|
+
invalid?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Text of a first, empty option shown until a value is chosen (`value=""`). With `required`,
|
|
21
|
+
* submitting it fails `valueMissing`. When neither `value` nor `defaultValue` is given, it is
|
|
22
|
+
* selected initially.
|
|
23
|
+
*/
|
|
24
|
+
placeholder?: string;
|
|
25
|
+
/** Decorative icon before the value (`aria-hidden`), as on the Select trigger. */
|
|
26
|
+
leadingIcon?: ReactNode;
|
|
27
|
+
/** Replaces the chevron glyph. Decorative. */
|
|
28
|
+
indicator?: ReactNode;
|
|
29
|
+
/**
|
|
30
|
+
* `readOnly` is accepted and dropped, so a Field function child can be spread as it is: a
|
|
31
|
+
* `<select>` has no read-only state.
|
|
32
|
+
*/
|
|
33
|
+
readOnly?: boolean | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Composition of the wrapper. `className` and `style` go on the wrapper too; every other prop,
|
|
36
|
+
* `ref` included, goes on the native `<select>`.
|
|
37
|
+
*/
|
|
38
|
+
render?: RenderProp<NativeSelectState>;
|
|
39
|
+
/** `<option>` and `<optgroup>` elements. */
|
|
40
|
+
children?: ReactNode;
|
|
41
|
+
}
|
|
42
|
+
export declare function NativeSelect({ size, invalid, placeholder, leadingIcon, indicator, readOnly: _readOnly, render, className, style, value, defaultValue, disabled, "aria-invalid": ariaInvalid, children, ...rest }: NativeSelectProps): ReactElement;
|
|
43
|
+
//#endregion
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { cx } from "../_internal/cx.js";
|
|
2
|
+
import { renderElement } from "../contracts/render.js";
|
|
3
|
+
import { ChevronsUpDownGlyph } from "../_internal/glyphs.js";
|
|
4
|
+
import { stateAttrs } from "../contracts/state.js";
|
|
5
|
+
import { FIELD_CONTROL } from "../_internal/field.js";
|
|
6
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
//#region src/native-select/native-select.tsx
|
|
8
|
+
function NativeSelect({ size = "md", invalid, placeholder, leadingIcon, indicator, readOnly: _readOnly, render, className, style, value, defaultValue, disabled = false, "aria-invalid": ariaInvalid, children, ...rest }) {
|
|
9
|
+
const state = {
|
|
10
|
+
size,
|
|
11
|
+
invalid: invalid ?? (ariaInvalid === true || ariaInvalid === "true"),
|
|
12
|
+
disabled
|
|
13
|
+
};
|
|
14
|
+
const initial = placeholder !== void 0 && value === void 0 && defaultValue === void 0 ? "" : defaultValue;
|
|
15
|
+
return renderElement("span", render, state, {
|
|
16
|
+
"data-slot": "native-select",
|
|
17
|
+
"data-size": size,
|
|
18
|
+
...stateAttrs({
|
|
19
|
+
invalid: state.invalid,
|
|
20
|
+
disabled
|
|
21
|
+
}),
|
|
22
|
+
className: cx("nz-native-select", className),
|
|
23
|
+
style,
|
|
24
|
+
children: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
25
|
+
leadingIcon != null && /* @__PURE__ */ jsx("span", {
|
|
26
|
+
className: "nz-native-select-icon",
|
|
27
|
+
"data-slot": "native-select-icon",
|
|
28
|
+
"aria-hidden": "true",
|
|
29
|
+
children: leadingIcon
|
|
30
|
+
}),
|
|
31
|
+
/* @__PURE__ */ jsxs("select", {
|
|
32
|
+
...rest,
|
|
33
|
+
...value !== void 0 && { value },
|
|
34
|
+
...initial !== void 0 && { defaultValue: initial },
|
|
35
|
+
...disabled && { disabled: true },
|
|
36
|
+
"aria-invalid": state.invalid || void 0,
|
|
37
|
+
className: "nz-native-select-trigger",
|
|
38
|
+
"data-slot": "native-select-trigger",
|
|
39
|
+
children: [placeholder !== void 0 && /* @__PURE__ */ jsx("option", {
|
|
40
|
+
value: "",
|
|
41
|
+
disabled: true,
|
|
42
|
+
children: placeholder
|
|
43
|
+
}), children]
|
|
44
|
+
}),
|
|
45
|
+
/* @__PURE__ */ jsx("span", {
|
|
46
|
+
className: "nz-native-select-chevron",
|
|
47
|
+
"data-slot": "native-select-chevron",
|
|
48
|
+
"aria-hidden": "true",
|
|
49
|
+
children: indicator ?? /* @__PURE__ */ jsx(ChevronsUpDownGlyph, {})
|
|
50
|
+
})
|
|
51
|
+
] })
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
Object.defineProperty(NativeSelect, FIELD_CONTROL, { value: true });
|
|
55
|
+
//#endregion
|
|
56
|
+
export { NativeSelect };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ProgressBar } from "./progress-bar.js";
|