@slurp-ui/react 1.2.0 → 1.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/CHANGELOG.md +14 -0
- package/dist/AvatarGroup/AvatarGroup.d.ts +26 -0
- package/dist/AvatarGroup/AvatarGroup.js +46 -0
- package/dist/AvatarGroup/AvatarGroup.js.map +1 -0
- package/dist/AvatarGroup/index.d.ts +3 -0
- package/dist/AvatarGroup/index.js +2 -0
- package/dist/Compare/Compare.d.ts +23 -0
- package/dist/Compare/Compare.js +61 -0
- package/dist/Compare/Compare.js.map +1 -0
- package/dist/Compare/index.d.ts +3 -0
- package/dist/Compare/index.js +2 -0
- package/dist/Consent/Consent.d.ts +30 -0
- package/dist/Consent/Consent.js +70 -0
- package/dist/Consent/Consent.js.map +1 -0
- package/dist/Consent/index.d.ts +3 -0
- package/dist/Consent/index.js +2 -0
- package/dist/Dialog/Dialog.d.ts +2 -0
- package/dist/Dialog/Dialog.js +19 -8
- package/dist/Dialog/Dialog.js.map +1 -1
- package/dist/Lightbox/Lightbox.d.ts +30 -0
- package/dist/Lightbox/Lightbox.js +74 -0
- package/dist/Lightbox/Lightbox.js.map +1 -0
- package/dist/Lightbox/index.d.ts +3 -0
- package/dist/Lightbox/index.js +2 -0
- package/dist/Menu/Menu.d.ts +13 -0
- package/dist/Menu/Menu.js +43 -11
- package/dist/Menu/Menu.js.map +1 -1
- package/dist/Menu/index.d.ts +2 -2
- package/dist/Menu/index.js +1 -1
- package/dist/MultiSuggest/MultiSuggest.d.ts +39 -0
- package/dist/MultiSuggest/MultiSuggest.js +267 -0
- package/dist/MultiSuggest/MultiSuggest.js.map +1 -0
- package/dist/MultiSuggest/index.d.ts +3 -0
- package/dist/MultiSuggest/index.js +2 -0
- package/dist/Sheet/Sheet.d.ts +8 -3
- package/dist/Sheet/Sheet.js +1 -1
- package/dist/Sheet/Sheet.js.map +1 -1
- package/dist/Sheet/index.d.ts +2 -2
- package/dist/Table/Table.d.ts +12 -0
- package/dist/Table/Table.js +54 -10
- package/dist/Table/Table.js.map +1 -1
- package/dist/Timeline/Timeline.d.ts +23 -0
- package/dist/Timeline/Timeline.js +49 -0
- package/dist/Timeline/Timeline.js.map +1 -0
- package/dist/Timeline/index.d.ts +3 -0
- package/dist/Timeline/index.js +2 -0
- package/dist/Tree/Tree.d.ts +24 -0
- package/dist/Tree/Tree.js +113 -0
- package/dist/Tree/Tree.js.map +1 -0
- package/dist/Tree/index.d.ts +3 -0
- package/dist/Tree/index.js +2 -0
- package/dist/index.d.ts +19 -5
- package/dist/index.js +9 -2
- package/dist/lib/labels.d.ts +36 -1
- package/dist/lib/labels.js +24 -1
- package/dist/lib/labels.js.map +1 -1
- package/dist/lib/theme.d.ts +36 -1
- package/dist/lib/theme.js.map +1 -1
- package/dist/styles.css +555 -37
- package/package.json +5 -5
package/dist/Menu/Menu.d.ts
CHANGED
|
@@ -13,11 +13,15 @@ export type MenuProps<E extends ElementType = 'div'> = PolymorphicProps<E, Omit<
|
|
|
13
13
|
export declare function Menu<E extends ElementType = 'div'>(props: MenuProps<E>): import("react").JSX.Element;
|
|
14
14
|
export declare namespace Menu {
|
|
15
15
|
var Item: typeof MenuItem;
|
|
16
|
+
var Group: typeof MenuGroup;
|
|
17
|
+
var Separator: typeof MenuSeparator;
|
|
16
18
|
}
|
|
17
19
|
export interface MenuItemOwnProps {
|
|
18
20
|
/** Runs the action; the menu closes afterwards (unless the handler calls preventDefault). */
|
|
19
21
|
onSelect?: (event: MouseEvent<HTMLButtonElement>) => void;
|
|
20
22
|
icon?: ReactNode;
|
|
23
|
+
/** The key combination that runs it elsewhere, shown at the end (`⌘K`): a hint, not a binding. */
|
|
24
|
+
shortcut?: string;
|
|
21
25
|
disabled?: boolean;
|
|
22
26
|
/** `danger` for destructive actions (the text says so too). */
|
|
23
27
|
tone?: 'neutral' | 'danger';
|
|
@@ -26,4 +30,13 @@ export interface MenuItemOwnProps {
|
|
|
26
30
|
export type MenuItemProps<E extends ElementType = 'button'> = PolymorphicProps<E, MenuItemOwnProps>;
|
|
27
31
|
/** One action of a Menu. */
|
|
28
32
|
export declare function MenuItem<E extends ElementType = 'button'>(props: MenuItemProps<E>): import("react").JSX.Element;
|
|
33
|
+
export interface MenuGroupProps {
|
|
34
|
+
/** Names the group (shown above it and read by screen readers). */
|
|
35
|
+
label: string;
|
|
36
|
+
children?: ReactNode;
|
|
37
|
+
}
|
|
38
|
+
/** A named set of items inside a Menu. */
|
|
39
|
+
export declare function MenuGroup({ label, children }: MenuGroupProps): import("react").JSX.Element;
|
|
40
|
+
/** A line between two sets of items. */
|
|
41
|
+
export declare function MenuSeparator(): import("react").JSX.Element;
|
|
29
42
|
//# sourceMappingURL=Menu.d.ts.map
|
package/dist/Menu/Menu.js
CHANGED
|
@@ -3,7 +3,7 @@ import { cx } from "../utils/src/index.js";
|
|
|
3
3
|
import { useThemeProps } from "../internal/styled.js";
|
|
4
4
|
import { moveFocus } from "../utils/focus.js";
|
|
5
5
|
import { Bloom } from "../Bloom/Bloom.js";
|
|
6
|
-
import { createContext, useContext, useRef } from "react";
|
|
6
|
+
import { createContext, useContext, useId, useRef } from "react";
|
|
7
7
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
8
|
// src/Menu/Menu.tsx
|
|
9
9
|
const MenuContext = createContext(null);
|
|
@@ -32,7 +32,7 @@ function Menu(props) {
|
|
|
32
32
|
}
|
|
33
33
|
/** One action of a Menu. */
|
|
34
34
|
function MenuItem(props) {
|
|
35
|
-
const { as, css: _css, className, onSelect, icon, disabled, tone = "neutral", children, ...rest } = props;
|
|
35
|
+
const { as, css: _css, className, onSelect, icon, shortcut, disabled, tone = "neutral", children, ...rest } = props;
|
|
36
36
|
const close = useContext(MenuContext);
|
|
37
37
|
const Root = as ?? "button";
|
|
38
38
|
return /* @__PURE__ */ jsxs(Root, {
|
|
@@ -48,17 +48,49 @@ function MenuItem(props) {
|
|
|
48
48
|
if (!e.defaultPrevented) close?.(true);
|
|
49
49
|
},
|
|
50
50
|
...rest,
|
|
51
|
-
children: [
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
51
|
+
children: [
|
|
52
|
+
icon != null && /* @__PURE__ */ jsx("span", {
|
|
53
|
+
className: "slurp-bloom-item-icon",
|
|
54
|
+
"aria-hidden": "true",
|
|
55
|
+
children: icon
|
|
56
|
+
}),
|
|
57
|
+
/* @__PURE__ */ jsx("span", {
|
|
58
|
+
className: "slurp-bloom-item-label",
|
|
59
|
+
children
|
|
60
|
+
}),
|
|
61
|
+
shortcut != null && /* @__PURE__ */ jsx("kbd", {
|
|
62
|
+
className: "slurp-menu-shortcut",
|
|
63
|
+
"aria-keyshortcuts": shortcut,
|
|
64
|
+
children: shortcut
|
|
65
|
+
})
|
|
66
|
+
]
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/** A named set of items inside a Menu. */
|
|
70
|
+
function MenuGroup({ label, children }) {
|
|
71
|
+
const id = useId();
|
|
72
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
73
|
+
role: "group",
|
|
74
|
+
"aria-labelledby": id,
|
|
75
|
+
className: "slurp-menu-group",
|
|
76
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
77
|
+
id,
|
|
78
|
+
className: "slurp-menu-group-label",
|
|
79
|
+
role: "presentation",
|
|
80
|
+
children: label
|
|
81
|
+
}), children]
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
/** A line between two sets of items. */
|
|
85
|
+
function MenuSeparator() {
|
|
86
|
+
return /* @__PURE__ */ jsx("div", {
|
|
87
|
+
role: "separator",
|
|
88
|
+
className: "slurp-menu-separator"
|
|
59
89
|
});
|
|
60
90
|
}
|
|
61
91
|
Menu.Item = MenuItem;
|
|
62
|
-
|
|
92
|
+
Menu.Group = MenuGroup;
|
|
93
|
+
Menu.Separator = MenuSeparator;
|
|
94
|
+
export { Menu, MenuGroup, MenuItem, MenuSeparator };
|
|
63
95
|
|
|
64
96
|
//# sourceMappingURL=Menu.js.map
|
package/dist/Menu/Menu.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Menu.js","names":[],"sources":["../../src/Menu/Menu.tsx"],"sourcesContent":["import { cx } from '@slurp-ui/utils';\nimport {\n createContext,\n useContext,\n useRef,\n type ElementType,\n type MouseEvent,\n type ReactNode,\n} from 'react';\n\nimport { Bloom, type BloomOwnProps } from '../Bloom/Bloom';\nimport { useThemeProps } from '../internal/styled';\nimport type { PolymorphicProps } from '../lib/polymorphic';\nimport { moveFocus } from '../utils/focus';\n\nconst MenuContext = createContext<((restoreFocus?: boolean) => void) | null>(null);\n\nexport type MenuProps<E extends ElementType = 'div'> = PolymorphicProps<\n E,\n Omit<BloomOwnProps, 'role' | 'children'> & {\n /** MenuItem elements (other content, like a heading, is allowed too). */\n children?: ReactNode;\n }\n>;\n\n/**\n * A list of actions on Bloom: the trigger becomes the menu. Arrow keys move (looping), Home / End go to the ends,\n * Enter or Space run the item, which closes the menu and gives focus back to the trigger.\n */\nexport function Menu<E extends ElementType = 'div'>(props: MenuProps<E>) {\n const { children, width = 260, className, ...rest } = useThemeProps('Menu', props as MenuProps);\n const list = useRef<HTMLDivElement>(null);\n return (\n <Bloom {...rest} role=\"menu\" width={width} className={cx('slurp-menu', className)}>\n {(close) => (\n <MenuContext value={close}>\n <div\n ref={list}\n className=\"slurp-menu-list\"\n onKeyDown={(e) => moveFocus(e, list.current, '[role=\"menuitem\"]', { loop: true })}\n >\n {children}\n </div>\n </MenuContext>\n )}\n </Bloom>\n );\n}\n\nexport interface MenuItemOwnProps {\n /** Runs the action; the menu closes afterwards (unless the handler calls preventDefault). */\n onSelect?: (event: MouseEvent<HTMLButtonElement>) => void;\n icon?: ReactNode;\n disabled?: boolean;\n /** `danger` for destructive actions (the text says so too). */\n tone?: 'neutral' | 'danger';\n children?: ReactNode;\n}\n\nexport type MenuItemProps<E extends ElementType = 'button'> = PolymorphicProps<E, MenuItemOwnProps>;\n\n/** One action of a Menu. */\nexport function MenuItem<E extends ElementType = 'button'>(props: MenuItemProps<E>) {\n const {\n as,\n css: _css,\n className,\n onSelect,\n icon,\n disabled,\n tone = 'neutral',\n children,\n ...rest\n } = props as MenuItemProps;\n const close = useContext(MenuContext);\n const Root = (as ?? 'button') as ElementType;\n return (\n <Root\n role=\"menuitem\"\n tabIndex={-1}\n className={cx('slurp-bloom-item', className)}\n aria-disabled={disabled || undefined}\n data-tone={tone}\n {...(Root === 'button' ? { type: 'button' } : null)}\n onClick={(e: MouseEvent<HTMLButtonElement>) => {\n if (disabled) return;\n onSelect?.(e);\n if (!e.defaultPrevented) close?.(true);\n }}\n {...rest}\n >\n {icon != null && (\n <span className=\"slurp-bloom-item-icon\" aria-hidden=\"true\">\n {icon}\n </span>\n )}\n <span className=\"slurp-bloom-item-label\">{children}</span>\n </Root>\n );\n}\n\nMenu.Item = MenuItem;\n"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"Menu.js","names":[],"sources":["../../src/Menu/Menu.tsx"],"sourcesContent":["import { cx } from '@slurp-ui/utils';\nimport {\n createContext,\n useContext,\n useId,\n useRef,\n type ElementType,\n type MouseEvent,\n type ReactNode,\n} from 'react';\n\nimport { Bloom, type BloomOwnProps } from '../Bloom/Bloom';\nimport { useThemeProps } from '../internal/styled';\nimport type { PolymorphicProps } from '../lib/polymorphic';\nimport { moveFocus } from '../utils/focus';\n\nconst MenuContext = createContext<((restoreFocus?: boolean) => void) | null>(null);\n\nexport type MenuProps<E extends ElementType = 'div'> = PolymorphicProps<\n E,\n Omit<BloomOwnProps, 'role' | 'children'> & {\n /** MenuItem elements (other content, like a heading, is allowed too). */\n children?: ReactNode;\n }\n>;\n\n/**\n * A list of actions on Bloom: the trigger becomes the menu. Arrow keys move (looping), Home / End go to the ends,\n * Enter or Space run the item, which closes the menu and gives focus back to the trigger.\n */\nexport function Menu<E extends ElementType = 'div'>(props: MenuProps<E>) {\n const { children, width = 260, className, ...rest } = useThemeProps('Menu', props as MenuProps);\n const list = useRef<HTMLDivElement>(null);\n return (\n <Bloom {...rest} role=\"menu\" width={width} className={cx('slurp-menu', className)}>\n {(close) => (\n <MenuContext value={close}>\n <div\n ref={list}\n className=\"slurp-menu-list\"\n onKeyDown={(e) => moveFocus(e, list.current, '[role=\"menuitem\"]', { loop: true })}\n >\n {children}\n </div>\n </MenuContext>\n )}\n </Bloom>\n );\n}\n\nexport interface MenuItemOwnProps {\n /** Runs the action; the menu closes afterwards (unless the handler calls preventDefault). */\n onSelect?: (event: MouseEvent<HTMLButtonElement>) => void;\n icon?: ReactNode;\n /** The key combination that runs it elsewhere, shown at the end (`⌘K`): a hint, not a binding. */\n shortcut?: string;\n disabled?: boolean;\n /** `danger` for destructive actions (the text says so too). */\n tone?: 'neutral' | 'danger';\n children?: ReactNode;\n}\n\nexport type MenuItemProps<E extends ElementType = 'button'> = PolymorphicProps<E, MenuItemOwnProps>;\n\n/** One action of a Menu. */\nexport function MenuItem<E extends ElementType = 'button'>(props: MenuItemProps<E>) {\n const {\n as,\n css: _css,\n className,\n onSelect,\n icon,\n shortcut,\n disabled,\n tone = 'neutral',\n children,\n ...rest\n } = props as MenuItemProps;\n const close = useContext(MenuContext);\n const Root = (as ?? 'button') as ElementType;\n return (\n <Root\n role=\"menuitem\"\n tabIndex={-1}\n className={cx('slurp-bloom-item', className)}\n aria-disabled={disabled || undefined}\n data-tone={tone}\n {...(Root === 'button' ? { type: 'button' } : null)}\n onClick={(e: MouseEvent<HTMLButtonElement>) => {\n if (disabled) return;\n onSelect?.(e);\n if (!e.defaultPrevented) close?.(true);\n }}\n {...rest}\n >\n {icon != null && (\n <span className=\"slurp-bloom-item-icon\" aria-hidden=\"true\">\n {icon}\n </span>\n )}\n <span className=\"slurp-bloom-item-label\">{children}</span>\n {shortcut != null && (\n <kbd className=\"slurp-menu-shortcut\" aria-keyshortcuts={shortcut}>\n {shortcut}\n </kbd>\n )}\n </Root>\n );\n}\n\nexport interface MenuGroupProps {\n /** Names the group (shown above it and read by screen readers). */\n label: string;\n children?: ReactNode;\n}\n\n/** A named set of items inside a Menu. */\nexport function MenuGroup({ label, children }: MenuGroupProps) {\n const id = useId();\n return (\n <div role=\"group\" aria-labelledby={id} className=\"slurp-menu-group\">\n <div id={id} className=\"slurp-menu-group-label\" role=\"presentation\">\n {label}\n </div>\n {children}\n </div>\n );\n}\n\n/** A line between two sets of items. */\nexport function MenuSeparator() {\n return <div role=\"separator\" className=\"slurp-menu-separator\" />;\n}\n\nMenu.Item = MenuItem;\nMenu.Group = MenuGroup;\nMenu.Separator = MenuSeparator;\n"],"mappings":";;;;;;;;AAgBA,MAAM,cAAc,cAAyD,IAAI;;;;;AAcjF,SAAgB,KAAoC,OAAqB;CACvE,MAAM,EAAE,UAAU,QAAQ,KAAK,WAAW,GAAG,SAAS,cAAc,QAAQ,KAAkB;CAC9F,MAAM,OAAO,OAAuB,IAAI;CACxC,OACE,oBAAC,OAAD;EAAO,GAAI;EAAM,MAAK;EAAc;EAAO,WAAW,GAAG,cAAc,SAAS;EAC5E,WAAA,UACA,oBAAC,aAAD;GAAa,OAAO;GAClB,UAAA,oBAAC,OAAD;IACE,KAAK;IACL,WAAU;IACV,YAAY,MAAM,UAAU,GAAG,KAAK,SAAS,uBAAqB,EAAE,MAAM,KAAK,CAAC;IAE/E;GACE,CAAA;EACM,CAAA;CAEV,CAAA;AAEX;;AAiBA,SAAgB,SAA2C,OAAyB;CAClF,MAAM,EACJ,IACA,KAAK,MACL,WACA,UACA,MACA,UACA,UACA,OAAO,WACP,UACA,GAAG,SACD;CACJ,MAAM,QAAQ,WAAW,WAAW;CACpC,MAAM,OAAQ,MAAM;CACpB,OACE,qBAAC,MAAD;EACE,MAAK;EACL,UAAU;EACV,WAAW,GAAG,oBAAoB,SAAS;EAC3C,iBAAe,YAAY,KAAA;EAC3B,aAAW;EACX,GAAK,SAAS,WAAW,EAAE,MAAM,SAAS,IAAI;EAC9C,UAAU,MAAqC;GAC7C,IAAI,UAAU;GACd,WAAW,CAAC;GACZ,IAAI,CAAC,EAAE,kBAAkB,QAAQ,IAAI;EACvC;EACA,GAAI;EAZN,UAAA;GAcG,QAAQ,QACP,oBAAC,QAAD;IAAM,WAAU;IAAwB,eAAY;IACjD,UAAA;GACG,CAAA;GAER,oBAAC,QAAD;IAAM,WAAU;IAA0B;GAAe,CAAA;GACxD,YAAY,QACX,oBAAC,OAAD;IAAK,WAAU;IAAsB,qBAAmB;IACrD,UAAA;GACE,CAAA;EAEH;;AAEV;;AASA,SAAgB,UAAU,EAAE,OAAO,YAA4B;CAC7D,MAAM,KAAK,MAAM;CACjB,OACE,qBAAC,OAAD;EAAK,MAAK;EAAQ,mBAAiB;EAAI,WAAU;EAAjD,UAAA,CACE,oBAAC,OAAD;GAAS;GAAI,WAAU;GAAyB,MAAK;GAClD,UAAA;EACE,CAAA,GACJ,QACE;;AAET;;AAGA,SAAgB,gBAAgB;CAC9B,OAAO,oBAAC,OAAD;EAAK,MAAK;EAAY,WAAU;CAAwB,CAAA;AACjE;AAEA,KAAK,OAAO;AACZ,KAAK,QAAQ;AACb,KAAK,YAAY"}
|
package/dist/Menu/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
|
|
2
|
-
import { Menu, MenuItem, MenuItemProps, MenuProps } from "./Menu.js";
|
|
3
|
-
export { Menu, MenuItem, type MenuItemProps, type MenuProps, Menu as default };
|
|
2
|
+
import { Menu, MenuGroup, MenuGroupProps, MenuItem, MenuItemProps, MenuProps, MenuSeparator } from "./Menu.js";
|
|
3
|
+
export { Menu, MenuGroup, type MenuGroupProps, MenuItem, type MenuItemProps, type MenuProps, MenuSeparator, Menu as default };
|
package/dist/Menu/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
|
|
2
|
-
export { Menu, MenuItem, Menu as default } from "./Menu.js";
|
|
2
|
+
export { Menu, MenuGroup, MenuItem, MenuSeparator, Menu as default } from "./Menu.js";
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
|
|
2
|
+
import { PartsProps, PolymorphicProps } from "../lib/polymorphic.js";
|
|
3
|
+
import { InputAttributes } from "../Field/Field.js";
|
|
4
|
+
import { SuggestOption } from "../Suggest/Suggest.js";
|
|
5
|
+
import { ElementType, ReactNode } from "react";
|
|
6
|
+
export interface MultiSuggestLabels {
|
|
7
|
+
/** Number of suggestions, announced politely while typing. */
|
|
8
|
+
results: (count: number) => string;
|
|
9
|
+
/** Shown in the list, and announced, when nothing matches. */
|
|
10
|
+
empty: string;
|
|
11
|
+
/** Names the button that removes a chosen option: `remove('Rosso')`. */
|
|
12
|
+
remove: (label: string) => string;
|
|
13
|
+
/** Names the list of chosen options. */
|
|
14
|
+
chosen: string;
|
|
15
|
+
}
|
|
16
|
+
export declare const MULTI_SUGGEST_LABELS: MultiSuggestLabels;
|
|
17
|
+
export interface MultiSuggestOwnProps<V extends string = string> extends Omit<InputAttributes, 'type'>, PartsProps<'label' | 'control' | 'list' | 'option' | 'tags' | 'tag' | 'hint' | 'error'> {
|
|
18
|
+
label: ReactNode;
|
|
19
|
+
hint?: ReactNode;
|
|
20
|
+
/** Error message: marks the field invalid. */
|
|
21
|
+
error?: ReactNode;
|
|
22
|
+
options: SuggestOption<V>[];
|
|
23
|
+
/** The chosen values, in the order they were chosen. */
|
|
24
|
+
value?: V[];
|
|
25
|
+
defaultValue?: V[];
|
|
26
|
+
onValueChange?: (value: V[]) => void;
|
|
27
|
+
/** Which options match the text (default: every word, any order, ignoring case and accents). */
|
|
28
|
+
filter?: ((option: SuggestOption<V>, text: string) => boolean) | false;
|
|
29
|
+
/** Most suggestions listed. Default 8. */
|
|
30
|
+
limit?: number;
|
|
31
|
+
labels?: Partial<MultiSuggestLabels>;
|
|
32
|
+
}
|
|
33
|
+
export type MultiSuggestProps<V extends string = string, E extends ElementType = 'div'> = PolymorphicProps<E, MultiSuggestOwnProps<V>>;
|
|
34
|
+
/**
|
|
35
|
+
* Suggest for several choices: the list stays open while you pick, each pick becomes a removable tag under the field,
|
|
36
|
+
* Backspace in an empty field removes the last one. Submits one hidden input per value when it has a `name`.
|
|
37
|
+
*/
|
|
38
|
+
export declare function MultiSuggest<V extends string = string, E extends ElementType = 'div'>(props: MultiSuggestProps<V, E>): import("react").JSX.Element;
|
|
39
|
+
//# sourceMappingURL=MultiSuggest.d.ts.map
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useLabels } from "../internal/labels.js";
|
|
3
|
+
import { cx } from "../utils/src/index.js";
|
|
4
|
+
import { useAnimationRoot } from "../internal/animation.js";
|
|
5
|
+
import { useCss, useParts, useThemeProps } from "../internal/styled.js";
|
|
6
|
+
import { useControlled } from "../utils/useControlled.js";
|
|
7
|
+
import { splitInputProps } from "../Field/Field.js";
|
|
8
|
+
import { useDismiss } from "../utils/useDismiss.js";
|
|
9
|
+
import { matchesAll } from "../lib/layout.js";
|
|
10
|
+
import { Mark } from "../Mark/Mark.js";
|
|
11
|
+
import { Fragment, useEffect, useId, useMemo, useRef, useState } from "react";
|
|
12
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { CheckIcon, CloseIcon, ErrorIcon } from "@slurp-ui/icons";
|
|
14
|
+
// src/MultiSuggest/MultiSuggest.tsx
|
|
15
|
+
const MULTI_SUGGEST_LABELS = {
|
|
16
|
+
results: (n) => n === 1 ? "1 suggerimento" : `${n} suggerimenti`,
|
|
17
|
+
empty: "Nessun suggerimento",
|
|
18
|
+
remove: (label) => `Rimuovi ${label}`,
|
|
19
|
+
chosen: "Scelte"
|
|
20
|
+
};
|
|
21
|
+
const matches = (o, text) => matchesAll(o.description ? `${o.label} ${o.description}` : o.label, text);
|
|
22
|
+
/**
|
|
23
|
+
* Suggest for several choices: the list stays open while you pick, each pick becomes a removable tag under the field,
|
|
24
|
+
* Backspace in an empty field removes the last one. Submits one hidden input per value when it has a `name`.
|
|
25
|
+
*/
|
|
26
|
+
function MultiSuggest(props) {
|
|
27
|
+
const { as, css, className, label, hint, error, options, value: valueProp, defaultValue = [], onValueChange, filter, limit = 8, labels: labelsProp, parts, partProps, classNames, ...others } = useThemeProps("MultiSuggest", props);
|
|
28
|
+
const labels = {
|
|
29
|
+
...MULTI_SUGGEST_LABELS,
|
|
30
|
+
...useLabels("MultiSuggest"),
|
|
31
|
+
...labelsProp
|
|
32
|
+
};
|
|
33
|
+
const { input, root: rest } = splitInputProps(others);
|
|
34
|
+
const { name, disabled, onKeyDown, onFocus, onBlur, ...inputRest } = input;
|
|
35
|
+
const [value, setValue] = useControlled({
|
|
36
|
+
value: valueProp,
|
|
37
|
+
defaultValue,
|
|
38
|
+
onChange: onValueChange
|
|
39
|
+
});
|
|
40
|
+
const [text, setText] = useState("");
|
|
41
|
+
const [open, setOpen] = useState(false);
|
|
42
|
+
const [active, setActive] = useState(-1);
|
|
43
|
+
const box = useRef(null);
|
|
44
|
+
const id = useId();
|
|
45
|
+
const inputId = `${id}-input`;
|
|
46
|
+
const listId = `${id}-list`;
|
|
47
|
+
const hintId = hint != null ? `${id}-hint` : void 0;
|
|
48
|
+
const errorId = error != null && error !== false ? `${id}-error` : void 0;
|
|
49
|
+
const Root = as ?? "div";
|
|
50
|
+
const styled = useCss("MultiSuggest", "root", css);
|
|
51
|
+
const { part, style } = useParts("MultiSuggest", {
|
|
52
|
+
parts,
|
|
53
|
+
partProps,
|
|
54
|
+
classNames
|
|
55
|
+
});
|
|
56
|
+
const root = useAnimationRoot(rest);
|
|
57
|
+
const query = text.trim();
|
|
58
|
+
const found = useMemo(() => {
|
|
59
|
+
return (filter === false || !query ? options : options.filter((o) => (filter ?? matches)(o, query))).slice(0, Math.max(0, limit));
|
|
60
|
+
}, [
|
|
61
|
+
options,
|
|
62
|
+
filter,
|
|
63
|
+
query,
|
|
64
|
+
limit
|
|
65
|
+
]);
|
|
66
|
+
const close = () => {
|
|
67
|
+
setOpen(false);
|
|
68
|
+
setActive(-1);
|
|
69
|
+
};
|
|
70
|
+
const dismiss = useDismiss({
|
|
71
|
+
ref: box,
|
|
72
|
+
open,
|
|
73
|
+
onDismiss: close
|
|
74
|
+
});
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (open && active >= 0) document.getElementById(`${listId}-${active}`)?.scrollIntoView?.({ block: "nearest" });
|
|
77
|
+
}, [
|
|
78
|
+
open,
|
|
79
|
+
active,
|
|
80
|
+
listId
|
|
81
|
+
]);
|
|
82
|
+
const next = (from, step) => {
|
|
83
|
+
const n = found.length;
|
|
84
|
+
for (let k = 1; k <= n; k++) {
|
|
85
|
+
const i = ((from + step * k) % n + n) % n;
|
|
86
|
+
if (!found[i]?.disabled) return i;
|
|
87
|
+
}
|
|
88
|
+
return -1;
|
|
89
|
+
};
|
|
90
|
+
const toggle = (o) => {
|
|
91
|
+
if (o.disabled) return;
|
|
92
|
+
setValue(value.includes(o.value) ? value.filter((v) => v !== o.value) : [...value, o.value]);
|
|
93
|
+
setText("");
|
|
94
|
+
};
|
|
95
|
+
const remove = (v) => {
|
|
96
|
+
setValue(value.filter((x) => x !== v));
|
|
97
|
+
document.getElementById(inputId)?.focus();
|
|
98
|
+
};
|
|
99
|
+
const keys = (e) => {
|
|
100
|
+
onKeyDown?.(e);
|
|
101
|
+
if (e.defaultPrevented) return;
|
|
102
|
+
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
103
|
+
e.preventDefault();
|
|
104
|
+
const step = e.key === "ArrowDown" ? 1 : -1;
|
|
105
|
+
if (!open) {
|
|
106
|
+
setOpen(true);
|
|
107
|
+
setActive(next(step === 1 ? -1 : 0, step));
|
|
108
|
+
} else setActive(next(active < 0 && step === -1 ? 0 : active, step));
|
|
109
|
+
} else if (e.key === "Enter" && open && active >= 0) {
|
|
110
|
+
e.preventDefault();
|
|
111
|
+
const o = found[active];
|
|
112
|
+
if (o) toggle(o);
|
|
113
|
+
} else if (e.key === "Escape" && open) {
|
|
114
|
+
e.preventDefault();
|
|
115
|
+
e.stopPropagation();
|
|
116
|
+
close();
|
|
117
|
+
} else if (e.key === "Backspace" && !text && value.length) setValue(value.slice(0, -1));
|
|
118
|
+
};
|
|
119
|
+
const showing = open && !disabled;
|
|
120
|
+
const status = showing && query ? found.length ? labels.results(found.length) : labels.empty : "";
|
|
121
|
+
const byValue = new Map(options.map((o) => [o.value, o]));
|
|
122
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
123
|
+
styled.style,
|
|
124
|
+
style,
|
|
125
|
+
/* @__PURE__ */ jsxs(Root, {
|
|
126
|
+
className: cx("slurp-suggest slurp-multisuggest", styled.className, className),
|
|
127
|
+
"data-open": showing ? "" : void 0,
|
|
128
|
+
"data-invalid": errorId ? "" : void 0,
|
|
129
|
+
"data-disabled": disabled ? "" : void 0,
|
|
130
|
+
...root,
|
|
131
|
+
children: [
|
|
132
|
+
part("label", "label", {
|
|
133
|
+
id: `${id}-label`,
|
|
134
|
+
htmlFor: inputId,
|
|
135
|
+
className: "slurp-suggest-label",
|
|
136
|
+
children: label
|
|
137
|
+
}),
|
|
138
|
+
/* @__PURE__ */ jsx("div", {
|
|
139
|
+
ref: box,
|
|
140
|
+
className: "slurp-suggest-box",
|
|
141
|
+
onBlur: dismiss.containerProps.onBlur,
|
|
142
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
143
|
+
className: "slurp-suggest-surface",
|
|
144
|
+
children: [part("control", "input", {
|
|
145
|
+
...inputRest,
|
|
146
|
+
id: inputId,
|
|
147
|
+
type: "text",
|
|
148
|
+
role: "combobox",
|
|
149
|
+
className: "slurp-suggest-control",
|
|
150
|
+
disabled,
|
|
151
|
+
autoComplete: inputRest.autoComplete ?? "off",
|
|
152
|
+
"aria-expanded": showing,
|
|
153
|
+
"aria-controls": listId,
|
|
154
|
+
"aria-autocomplete": "list",
|
|
155
|
+
"aria-activedescendant": showing && active >= 0 ? `${listId}-${active}` : void 0,
|
|
156
|
+
"aria-invalid": errorId ? true : void 0,
|
|
157
|
+
"aria-describedby": cx(errorId, hintId) || void 0,
|
|
158
|
+
value: text,
|
|
159
|
+
onChange: (e) => {
|
|
160
|
+
setText(e.target.value);
|
|
161
|
+
setOpen(true);
|
|
162
|
+
setActive(-1);
|
|
163
|
+
},
|
|
164
|
+
onKeyDown: keys,
|
|
165
|
+
onFocus,
|
|
166
|
+
onBlur,
|
|
167
|
+
onClick: () => {
|
|
168
|
+
if (!open) setOpen(true);
|
|
169
|
+
}
|
|
170
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
171
|
+
className: "slurp-suggest-clip",
|
|
172
|
+
children: found.length > 0 ? part("list", "ul", {
|
|
173
|
+
id: listId,
|
|
174
|
+
role: "listbox",
|
|
175
|
+
"aria-multiselectable": true,
|
|
176
|
+
"aria-labelledby": `${id}-label`,
|
|
177
|
+
className: "slurp-suggest-list",
|
|
178
|
+
children: found.map((o, i) => {
|
|
179
|
+
const on = value.includes(o.value);
|
|
180
|
+
return /* @__PURE__ */ jsx(Fragment, { children: part("option", "li", {
|
|
181
|
+
id: `${listId}-${i}`,
|
|
182
|
+
role: "option",
|
|
183
|
+
className: "slurp-suggest-option",
|
|
184
|
+
"aria-selected": on,
|
|
185
|
+
"aria-disabled": o.disabled || void 0,
|
|
186
|
+
"data-active": showing && i === active ? "" : void 0,
|
|
187
|
+
"data-chosen": on ? "" : void 0,
|
|
188
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
189
|
+
onPointerMove: () => {
|
|
190
|
+
if (!o.disabled && i !== active) setActive(i);
|
|
191
|
+
},
|
|
192
|
+
onClick: () => toggle(o),
|
|
193
|
+
children: /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("span", {
|
|
194
|
+
className: "slurp-suggest-option-text",
|
|
195
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
196
|
+
className: "slurp-suggest-option-label",
|
|
197
|
+
children: /* @__PURE__ */ jsx(Mark, {
|
|
198
|
+
text: o.label,
|
|
199
|
+
query
|
|
200
|
+
})
|
|
201
|
+
}), o.description && /* @__PURE__ */ jsx("span", {
|
|
202
|
+
className: "slurp-suggest-option-description",
|
|
203
|
+
children: /* @__PURE__ */ jsx(Mark, {
|
|
204
|
+
text: o.description,
|
|
205
|
+
query
|
|
206
|
+
})
|
|
207
|
+
})]
|
|
208
|
+
}), on && /* @__PURE__ */ jsx("span", {
|
|
209
|
+
className: "slurp-suggest-option-check",
|
|
210
|
+
"aria-hidden": "true",
|
|
211
|
+
children: /* @__PURE__ */ jsx(CheckIcon, { size: 18 })
|
|
212
|
+
})] })
|
|
213
|
+
}) }, o.value);
|
|
214
|
+
})
|
|
215
|
+
}) : /* @__PURE__ */ jsx("p", {
|
|
216
|
+
id: listId,
|
|
217
|
+
className: "slurp-suggest-empty",
|
|
218
|
+
children: labels.empty
|
|
219
|
+
})
|
|
220
|
+
})]
|
|
221
|
+
})
|
|
222
|
+
}),
|
|
223
|
+
value.length > 0 && part("tags", "ul", {
|
|
224
|
+
"aria-label": labels.chosen,
|
|
225
|
+
className: "slurp-multisuggest-tags",
|
|
226
|
+
children: value.map((v) => {
|
|
227
|
+
const text = byValue.get(v)?.label ?? v;
|
|
228
|
+
return /* @__PURE__ */ jsx("li", { children: part("tag", "button", {
|
|
229
|
+
type: "button",
|
|
230
|
+
className: "slurp-multisuggest-tag",
|
|
231
|
+
disabled,
|
|
232
|
+
"aria-label": labels.remove(text),
|
|
233
|
+
onClick: () => remove(v),
|
|
234
|
+
children: /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("span", { children: text }), /* @__PURE__ */ jsx(CloseIcon, {
|
|
235
|
+
size: 14,
|
|
236
|
+
"aria-hidden": "true"
|
|
237
|
+
})] })
|
|
238
|
+
}) }, v);
|
|
239
|
+
})
|
|
240
|
+
}),
|
|
241
|
+
hintId && part("hint", "p", {
|
|
242
|
+
id: hintId,
|
|
243
|
+
className: "slurp-suggest-hint",
|
|
244
|
+
children: hint
|
|
245
|
+
}),
|
|
246
|
+
errorId && part("error", "p", {
|
|
247
|
+
id: errorId,
|
|
248
|
+
className: "slurp-suggest-error",
|
|
249
|
+
children: /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(ErrorIcon, { size: 16 }), /* @__PURE__ */ jsx("span", { children: error })] })
|
|
250
|
+
}),
|
|
251
|
+
/* @__PURE__ */ jsx("span", {
|
|
252
|
+
className: "slurp-visually-hidden",
|
|
253
|
+
role: "status",
|
|
254
|
+
children: status
|
|
255
|
+
}),
|
|
256
|
+
name && value.map((v) => /* @__PURE__ */ jsx("input", {
|
|
257
|
+
type: "hidden",
|
|
258
|
+
name,
|
|
259
|
+
value: v
|
|
260
|
+
}, v))
|
|
261
|
+
]
|
|
262
|
+
})
|
|
263
|
+
] });
|
|
264
|
+
}
|
|
265
|
+
export { MULTI_SUGGEST_LABELS, MultiSuggest };
|
|
266
|
+
|
|
267
|
+
//# sourceMappingURL=MultiSuggest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MultiSuggest.js","names":[],"sources":["../../src/MultiSuggest/MultiSuggest.tsx"],"sourcesContent":["import { CheckIcon, CloseIcon, ErrorIcon } from '@slurp-ui/icons';\nimport { cx } from '@slurp-ui/utils';\nimport {\n Fragment,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n type ChangeEvent,\n type ElementType,\n type KeyboardEvent,\n type MouseEvent,\n type ReactNode,\n} from 'react';\n\nimport { splitInputProps, type InputAttributes } from '../Field/Field';\nimport { useAnimationRoot } from '../internal/animation';\nimport { useLabels } from '../internal/labels';\nimport { useCss, useParts, useThemeProps } from '../internal/styled';\nimport { matchesAll } from '../lib/layout';\nimport type { PartsProps, PolymorphicProps } from '../lib/polymorphic';\nimport { Mark } from '../Mark/Mark';\nimport type { SuggestOption } from '../Suggest/Suggest';\nimport { useControlled } from '../utils/useControlled';\nimport { useDismiss } from '../utils/useDismiss';\n\nexport interface MultiSuggestLabels {\n /** Number of suggestions, announced politely while typing. */\n results: (count: number) => string;\n /** Shown in the list, and announced, when nothing matches. */\n empty: string;\n /** Names the button that removes a chosen option: `remove('Rosso')`. */\n remove: (label: string) => string;\n /** Names the list of chosen options. */\n chosen: string;\n}\n\nexport const MULTI_SUGGEST_LABELS: MultiSuggestLabels = {\n results: (n) => (n === 1 ? '1 suggerimento' : `${n} suggerimenti`),\n empty: 'Nessun suggerimento',\n remove: (label) => `Rimuovi ${label}`,\n chosen: 'Scelte',\n};\n\nexport interface MultiSuggestOwnProps<V extends string = string>\n extends\n Omit<InputAttributes, 'type'>,\n PartsProps<'label' | 'control' | 'list' | 'option' | 'tags' | 'tag' | 'hint' | 'error'> {\n label: ReactNode;\n hint?: ReactNode;\n /** Error message: marks the field invalid. */\n error?: ReactNode;\n options: SuggestOption<V>[];\n /** The chosen values, in the order they were chosen. */\n value?: V[];\n defaultValue?: V[];\n onValueChange?: (value: V[]) => void;\n /** Which options match the text (default: every word, any order, ignoring case and accents). */\n filter?: ((option: SuggestOption<V>, text: string) => boolean) | false;\n /** Most suggestions listed. Default 8. */\n limit?: number;\n labels?: Partial<MultiSuggestLabels>;\n}\n\nexport type MultiSuggestProps<\n V extends string = string,\n E extends ElementType = 'div',\n> = PolymorphicProps<E, MultiSuggestOwnProps<V>>;\n\nconst matches = (o: SuggestOption, text: string) =>\n matchesAll(o.description ? `${o.label} ${o.description}` : o.label, text);\n\n/**\n * Suggest for several choices: the list stays open while you pick, each pick becomes a removable tag under the field,\n * Backspace in an empty field removes the last one. Submits one hidden input per value when it has a `name`.\n */\nexport function MultiSuggest<V extends string = string, E extends ElementType = 'div'>(\n props: MultiSuggestProps<V, E>,\n) {\n const {\n as,\n css,\n className,\n label,\n hint,\n error,\n options,\n value: valueProp,\n defaultValue = [],\n onValueChange,\n filter,\n limit = 8,\n labels: labelsProp,\n parts,\n partProps,\n classNames,\n ...others\n } = useThemeProps('MultiSuggest', props as unknown as MultiSuggestProps);\n const labels = { ...MULTI_SUGGEST_LABELS, ...useLabels('MultiSuggest'), ...labelsProp };\n const { input, root: rest } = splitInputProps(others);\n const { name, disabled, onKeyDown, onFocus, onBlur, ...inputRest } = input as InputAttributes;\n const [value, setValue] = useControlled<string[]>({\n value: valueProp,\n defaultValue,\n onChange: onValueChange as ((v: string[]) => void) | undefined,\n });\n const [text, setText] = useState('');\n const [open, setOpen] = useState(false);\n const [active, setActive] = useState(-1);\n const box = useRef<HTMLDivElement>(null);\n const id = useId();\n const inputId = `${id}-input`;\n const listId = `${id}-list`;\n const hintId = hint != null ? `${id}-hint` : undefined;\n const errorId = error != null && error !== false ? `${id}-error` : undefined;\n const Root = (as ?? 'div') as ElementType;\n const styled = useCss('MultiSuggest', 'root', css);\n const { part, style } = useParts('MultiSuggest', { parts, partProps, classNames });\n const root = useAnimationRoot(rest);\n\n const query = text.trim();\n const found = useMemo(() => {\n const all =\n filter === false || !query ? options : options.filter((o) => (filter ?? matches)(o, query));\n return all.slice(0, Math.max(0, limit));\n }, [options, filter, query, limit]);\n\n const close = () => {\n setOpen(false);\n setActive(-1);\n };\n const dismiss = useDismiss({ ref: box, open, onDismiss: close });\n\n useEffect(() => {\n if (open && active >= 0)\n document.getElementById(`${listId}-${active}`)?.scrollIntoView?.({ block: 'nearest' });\n }, [open, active, listId]);\n\n const next = (from: number, step: 1 | -1) => {\n const n = found.length;\n for (let k = 1; k <= n; k++) {\n const i = (((from + step * k) % n) + n) % n;\n if (!found[i]?.disabled) return i;\n }\n return -1;\n };\n\n const toggle = (o: SuggestOption) => {\n if (o.disabled) return;\n setValue(value.includes(o.value) ? value.filter((v) => v !== o.value) : [...value, o.value]);\n setText('');\n };\n const remove = (v: string) => {\n setValue(value.filter((x) => x !== v));\n document.getElementById(inputId)?.focus();\n };\n\n const keys = (e: KeyboardEvent<HTMLInputElement>) => {\n onKeyDown?.(e);\n if (e.defaultPrevented) return;\n if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {\n e.preventDefault();\n const step = e.key === 'ArrowDown' ? 1 : -1;\n if (!open) {\n setOpen(true);\n setActive(next(step === 1 ? -1 : 0, step));\n } else setActive(next(active < 0 && step === -1 ? 0 : active, step));\n } else if (e.key === 'Enter' && open && active >= 0) {\n e.preventDefault();\n const o = found[active];\n if (o) toggle(o);\n } else if (e.key === 'Escape' && open) {\n e.preventDefault();\n e.stopPropagation();\n close();\n } else if (e.key === 'Backspace' && !text && value.length) {\n setValue(value.slice(0, -1));\n }\n };\n\n const showing = open && !disabled;\n const status =\n showing && query ? (found.length ? labels.results(found.length) : labels.empty) : '';\n const byValue = new Map(options.map((o) => [o.value as string, o]));\n\n return (\n <>\n {styled.style}\n {style}\n <Root\n className={cx('slurp-suggest slurp-multisuggest', styled.className, className)}\n data-open={showing ? '' : undefined}\n data-invalid={errorId ? '' : undefined}\n data-disabled={disabled ? '' : undefined}\n {...root}\n >\n {part('label', 'label', {\n id: `${id}-label`,\n htmlFor: inputId,\n className: 'slurp-suggest-label',\n children: label,\n })}\n <div ref={box} className=\"slurp-suggest-box\" onBlur={dismiss.containerProps.onBlur}>\n <div className=\"slurp-suggest-surface\">\n {part('control', 'input', {\n ...inputRest,\n id: inputId,\n type: 'text',\n role: 'combobox',\n className: 'slurp-suggest-control',\n disabled,\n autoComplete: inputRest.autoComplete ?? 'off',\n 'aria-expanded': showing,\n 'aria-controls': listId,\n 'aria-autocomplete': 'list',\n 'aria-activedescendant': showing && active >= 0 ? `${listId}-${active}` : undefined,\n 'aria-invalid': errorId ? true : undefined,\n 'aria-describedby': cx(errorId, hintId) || undefined,\n value: text,\n onChange: (e: ChangeEvent<HTMLInputElement>) => {\n setText(e.target.value);\n setOpen(true);\n setActive(-1);\n },\n onKeyDown: keys,\n onFocus,\n onBlur,\n onClick: () => {\n if (!open) setOpen(true);\n },\n })}\n <div className=\"slurp-suggest-clip\">\n {found.length > 0 ? (\n part('list', 'ul', {\n id: listId,\n role: 'listbox',\n 'aria-multiselectable': true,\n 'aria-labelledby': `${id}-label`,\n className: 'slurp-suggest-list',\n children: found.map((o, i) => {\n const on = value.includes(o.value);\n return (\n <Fragment key={o.value}>\n {part('option', 'li', {\n id: `${listId}-${i}`,\n role: 'option',\n className: 'slurp-suggest-option',\n 'aria-selected': on,\n 'aria-disabled': o.disabled || undefined,\n 'data-active': showing && i === active ? '' : undefined,\n 'data-chosen': on ? '' : undefined,\n onMouseDown: (e: MouseEvent) => e.preventDefault(),\n onPointerMove: () => {\n if (!o.disabled && i !== active) setActive(i);\n },\n onClick: () => toggle(o),\n children: (\n <>\n <span className=\"slurp-suggest-option-text\">\n <span className=\"slurp-suggest-option-label\">\n <Mark text={o.label} query={query} />\n </span>\n {o.description && (\n <span className=\"slurp-suggest-option-description\">\n <Mark text={o.description} query={query} />\n </span>\n )}\n </span>\n {on && (\n <span className=\"slurp-suggest-option-check\" aria-hidden=\"true\">\n <CheckIcon size={18} />\n </span>\n )}\n </>\n ),\n })}\n </Fragment>\n );\n }),\n })\n ) : (\n <p id={listId} className=\"slurp-suggest-empty\">\n {labels.empty}\n </p>\n )}\n </div>\n </div>\n </div>\n {value.length > 0 &&\n part('tags', 'ul', {\n 'aria-label': labels.chosen,\n className: 'slurp-multisuggest-tags',\n children: value.map((v) => {\n const text = byValue.get(v)?.label ?? v;\n return (\n <li key={v}>\n {part('tag', 'button', {\n type: 'button',\n className: 'slurp-multisuggest-tag',\n disabled,\n 'aria-label': labels.remove(text),\n onClick: () => remove(v),\n children: (\n <>\n <span>{text}</span>\n <CloseIcon size={14} aria-hidden=\"true\" />\n </>\n ),\n })}\n </li>\n );\n }),\n })}\n {hintId &&\n part('hint', 'p', { id: hintId, className: 'slurp-suggest-hint', children: hint })}\n {errorId &&\n part('error', 'p', {\n id: errorId,\n className: 'slurp-suggest-error',\n children: (\n <>\n <ErrorIcon size={16} />\n <span>{error}</span>\n </>\n ),\n })}\n <span className=\"slurp-visually-hidden\" role=\"status\">\n {status}\n </span>\n {name && value.map((v) => <input key={v} type=\"hidden\" name={name} value={v} />)}\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;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B,MAAK;KAC1C,UAAA;IACG,CAAA;IACL,QAAQ,MAAM,KAAK,MAAM,oBAAC,SAAD;KAAe,MAAK;KAAe;KAAM,OAAO;IAAI,GAAxC,CAAwC,CAAC;GAC3E;;CACN,EAAA,CAAA;AAEN"}
|
package/dist/Sheet/Sheet.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
|
|
2
|
-
import {
|
|
2
|
+
import { PolymorphicProps } from "../lib/polymorphic.js";
|
|
3
|
+
import { DialogOwnProps, SheetSide } from "../Dialog/Dialog.js";
|
|
3
4
|
import { ElementType } from "react";
|
|
4
|
-
export
|
|
5
|
-
/**
|
|
5
|
+
export interface SheetOwnProps extends DialogOwnProps {
|
|
6
|
+
/** The edge it comes from: `bottom` (default), or `start` / `end` as a side panel (flipped in RTL). */
|
|
7
|
+
side?: SheetSide;
|
|
8
|
+
}
|
|
9
|
+
export type SheetProps<E extends ElementType = 'dialog'> = PolymorphicProps<E, SheetOwnProps>;
|
|
10
|
+
/** Modal panel that rises from the bottom edge (full width on phones), or slides in from a side. Same API as Dialog. */
|
|
6
11
|
export declare function Sheet<E extends ElementType = 'dialog'>(props: SheetProps<E>): import("react").JSX.Element;
|
|
7
12
|
//# sourceMappingURL=Sheet.d.ts.map
|
package/dist/Sheet/Sheet.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { useThemeProps } from "../internal/styled.js";
|
|
3
3
|
import { useModal } from "../Dialog/Dialog.js";
|
|
4
4
|
// src/Sheet/Sheet.tsx
|
|
5
|
-
/** Modal panel that rises from the bottom edge (full width on phones). Same API as Dialog. */
|
|
5
|
+
/** Modal panel that rises from the bottom edge (full width on phones), or slides in from a side. Same API as Dialog. */
|
|
6
6
|
function Sheet(props) {
|
|
7
7
|
return useModal(useThemeProps("Sheet", props), "sheet");
|
|
8
8
|
}
|
package/dist/Sheet/Sheet.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Sheet.js","names":[],"sources":["../../src/Sheet/Sheet.tsx"],"sourcesContent":["import type { ElementType } from 'react';\n\nimport { useModal, type DialogProps } from '../Dialog/Dialog';\nimport { useThemeProps } from '../internal/styled';\n\nexport type SheetProps<E extends ElementType = 'dialog'> =
|
|
1
|
+
{"version":3,"file":"Sheet.js","names":[],"sources":["../../src/Sheet/Sheet.tsx"],"sourcesContent":["import type { ElementType } from 'react';\n\nimport { useModal, type DialogOwnProps, type DialogProps, type SheetSide } from '../Dialog/Dialog';\nimport { useThemeProps } from '../internal/styled';\nimport type { PolymorphicProps } from '../lib/polymorphic';\n\nexport interface SheetOwnProps extends DialogOwnProps {\n /** The edge it comes from: `bottom` (default), or `start` / `end` as a side panel (flipped in RTL). */\n side?: SheetSide;\n}\n\nexport type SheetProps<E extends ElementType = 'dialog'> = PolymorphicProps<E, SheetOwnProps>;\n\n/** Modal panel that rises from the bottom edge (full width on phones), or slides in from a side. Same API as Dialog. */\nexport function Sheet<E extends ElementType = 'dialog'>(props: SheetProps<E>) {\n return useModal(useThemeProps('Sheet', props as DialogProps), 'sheet');\n}\n"],"mappings":";;;;;AAcA,SAAgB,MAAwC,OAAsB;CAC5E,OAAO,SAAS,cAAc,SAAS,KAAoB,GAAG,OAAO;AACvE"}
|
package/dist/Sheet/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
|
|
2
|
-
import { Sheet, SheetProps } from "./Sheet.js";
|
|
3
|
-
export { Sheet, type SheetProps, Sheet as default };
|
|
2
|
+
import { Sheet, SheetOwnProps, SheetProps } from "./Sheet.js";
|
|
3
|
+
export { Sheet, type SheetOwnProps, type SheetProps, Sheet as default };
|
package/dist/Table/Table.d.ts
CHANGED
|
@@ -25,6 +25,10 @@ export interface TableSort {
|
|
|
25
25
|
export interface TableLabels {
|
|
26
26
|
/** Shown in place of the rows when there are none. */
|
|
27
27
|
empty: string;
|
|
28
|
+
/** Names the checkbox of the header (selects or clears every row). */
|
|
29
|
+
selectAll: string;
|
|
30
|
+
/** Names the checkbox of a row. */
|
|
31
|
+
selectRow: string;
|
|
28
32
|
}
|
|
29
33
|
export declare const TABLE_LABELS: TableLabels;
|
|
30
34
|
export interface TableOwnProps<R extends Row = Row> extends PartsProps<'table' | 'caption'> {
|
|
@@ -40,6 +44,14 @@ export interface TableOwnProps<R extends Row = Row> extends PartsProps<'table' |
|
|
|
40
44
|
onSortChange?: (sort: TableSort) => void;
|
|
41
45
|
/** The rows are already sorted (by a server): the table only reports `onSortChange`. */
|
|
42
46
|
manualSort?: boolean;
|
|
47
|
+
/** A checkbox on every row and one in the header that selects them all. Needs a stable `rowKey`. */
|
|
48
|
+
selectable?: boolean;
|
|
49
|
+
/** Keys of the selected rows. */
|
|
50
|
+
selected?: Key[];
|
|
51
|
+
defaultSelected?: Key[];
|
|
52
|
+
onSelectedChange?: (keys: Key[]) => void;
|
|
53
|
+
/** Keeps the header in view while the rows scroll: the table scrolls inside this height (CSS value). */
|
|
54
|
+
maxHeight?: string | number;
|
|
43
55
|
labels?: Partial<TableLabels>;
|
|
44
56
|
}
|
|
45
57
|
export type TableProps<R extends Row = Row, E extends ElementType = 'div'> = PolymorphicProps<E, TableOwnProps<R>>;
|