@plexui/ui 0.54.1 → 0.56.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/dist/es/components/ColorPicker/ColorWell.js.map +1 -1
- package/dist/es/components/NavigationRow/NavigationRow.js +60 -3
- package/dist/es/components/NavigationRow/NavigationRow.js.map +1 -1
- package/dist/es/components/Stepper/Stepper.js +20 -6
- package/dist/es/components/Stepper/Stepper.js.map +1 -1
- package/dist/types/components/ColorPicker/ColorWell.d.ts +2 -2
- package/dist/types/components/NavigationRow/NavigationRow.d.ts +6 -1
- package/dist/types/components/Stepper/Stepper.d.ts +8 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ColorWell.js","sourceRoot":"","sources":["../../../../src/components/ColorPicker/ColorWell.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAsC,MAAM,OAAO,CAAA;AAC9F,OAAO,CAAC,MAAM,8DAA8D,CAAA;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAClC,OAAO,EAAE,UAAU,EAAE,CAAC,EAAE,MAAM,SAAS,CAAA;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACpC,OAAO,EAAE,WAAW,EAAyB,MAAM,eAAe,CAAA;AAClE,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,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E,gBAAgB,CAAC,IAAI,CAAC,GAAoB,IACrD,EACV,KAAC,MAAM,CAAC,MAAM,cACZ,KAAC,MAAM,CAAC,KAAK,cAAE,KAAK,GAAgB,GACtB,EAChB,KAAC,MAAM,CAAC,IAAI,IAAC,SAAS,EAAE,CAAC,CAAC,SAAS,YAAG,MAAM,GAAe,IAC5C,IACV,CACV,IACA,CACJ,CAAA;AACH,CAAC","sourcesContent":["\"use client\"\n\nimport clsx from \"clsx\"\nimport { useEffect, useId, useRef, useState, type CSSProperties, type ReactNode } from \"react\"\nimport s from \"@plexui/styles/components/ColorPicker/ColorPicker.module.css\"\nimport { useBreakpoint } from \"../../hooks/useBreakpoints\"\nimport { useLatestValue } from \"../../hooks/useLatestValue\"\nimport { Button, NavigationButton } from \"../Button\"\nimport { Dialog } from \"../Dialog\"\nimport { Eyedropper, X } from \"../Icon\"\nimport { Popover } from \"../Popover\"\nimport { Toolbar } from \"../Toolbar\"\nimport { ColorPicker, type ColorPickerProps } from \"./ColorPicker\"\nimport { alphaPercent, cssColor, eyeDropper, formatColor, hexDigits, parseColor } from \"./shared\"\n\nexport type ColorWellProps = Omit<ColorPickerProps, \"value\" | \"defaultValue\" | \"onChange\" | \"aria-label\" | \"className\" | \"id\"> & {\n /** The `id` of the well. */\n id?: string\n /** The controlled color, `#rrggbb` or `#rrggbbaa`; `null` shows the rainbow well with no color. Use with `onChange`. */\n value?: string | null\n /** The color when it is initially rendered. Use when you do not need to control the color. @default null */\n defaultValue?: string | null\n /** Called with the color the picker chose. */\n onChange?: (value: string) => void\n /** The title of the picker. @default \"Colors\" */\n title?: string\n /** Shows the eyedropper in the picker where the browser can pick a color from the screen (EyeDropper API). @default true */\n supportsEyedropper?: boolean\n /** The kit's Picker Button sizes: `sm` 28px, `lg` 36px. @default \"sm\" */\n size?: \"sm\" | \"lg\"\n /** When `true`, prevents the user from opening the picker. */\n disabled?: boolean\n /** The name of the well. Submits its color with the owning form. */\n name?: string\n /** Accessible name of the well. @default \"Color\" */\n \"aria-label\"?: string\n /** The `id` of the visible label of the well. */\n \"aria-labelledby\"?: string\n /** CSS classes applied to the well */\n className?: string\n}\n\n/**\n * A color well, as `UIColorWell`: the kit's Picker Button (5739:34128), a rainbow ring around the chosen color. It\n * opens the color picker, in a Popover from the well, and on a phone in a sheet, as the system picker.\n */\nexport function ColorWell({\n id,\n value: valueProp,\n defaultValue = null,\n onChange,\n title = \"Colors\",\n supportsEyedropper = true,\n size = \"sm\",\n disabled = false,\n name,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n className,\n ...pickerProps\n}: ColorWellProps) {\n const wide = useBreakpoint(\"md\")\n const valueId = `${useId()}-value`\n const [open, setOpen] = useState(false)\n const [internalValue, setInternalValue] = useState<string | null>(defaultValue)\n const value = valueProp === undefined ? internalValue : valueProp\n const color = parseColor(value)\n const options = useLatestValue({ controlled: valueProp !== undefined, onChange })\n // The EyeDropper API exists only in a browser, so the button appears after hydration.\n const [canPick, setCanPick] = useState(false)\n useEffect(() => setCanPick(eyeDropper() !== null), [])\n const picking = useRef(false)\n\n const choose = (next: string) => {\n if (!options.current.controlled) setInternalValue(next)\n options.current.onChange?.(next)\n }\n\n const pick = async () => {\n const EyeDropper = eyeDropper()\n if (!EyeDropper || picking.current) return\n picking.current = true\n try {\n const picked = parseColor((await new EyeDropper().open()).sRGBHex)\n if (picked) choose(formatColor({ ...picked, a: color?.a ?? 1 }))\n } catch {\n // Escape, or a click the browser did not hand to the page, cancels the pick.\n } finally {\n picking.current = false\n }\n }\n\n const well = (\n <button\n id={id}\n type=\"button\"\n className={clsx(s.Well, className)}\n data-size={size}\n data-selected={color ? \"\" : undefined}\n disabled={disabled}\n aria-label={ariaLabelledBy ? undefined : ariaLabel ?? \"Color\"}\n aria-labelledby={ariaLabelledBy}\n aria-describedby={color ? valueId : undefined}\n style={color ? { \"--color-well-color\": cssColor(color) } as CSSProperties : undefined}\n >\n {color && <span className={s.WellColor} />}\n {/* The color, read as the well's description. */}\n {color && <span id={valueId} hidden>{`#${hexDigits(color)}${color.a < 1 ? `, ${alphaPercent(color.a)}% opacity` : \"\"}`}</span>}\n </button>\n )\n\n const picker = (\n <ColorPicker {...pickerProps} value={formatColor(color ?? { r: 0, g: 0, b: 0, a: 1 })} onChange={choose} aria-label={title} />\n )\n const eyedropperButton = (glass: boolean): ReactNode => supportsEyedropper && canPick && (\n <Button\n color=\"secondary\"\n variant={glass ? \"soft\" : \"ghost\"}\n mobileMaterial={glass ? \"glass\" : undefined}\n size={glass ? \"lg\" : \"sm\"}\n uniform\n pill\n aria-label=\"Eyedropper\"\n onClick={() => void pick()}\n >\n <Eyedropper />\n </Button>\n )\n\n return (\n <>\n {name !== undefined && <input type=\"hidden\" name={name} value={value ?? \"\"} disabled={disabled} />}\n {wide ? (\n <Popover open={open} onOpenChange={setOpen}>\n <Popover.Trigger>{well}</Popover.Trigger>\n <Popover.Content className={s.Popover} width=\"auto\" side=\"bottom\" align=\"center\">\n <div className={s.PopoverHeader}>\n <div className={s.PopoverLeading}>{eyedropperButton(false)}</div>\n <span className={s.PopoverTitle}>{title}</span>\n <div className={s.PopoverTrailing}>\n <Button color=\"secondary\" variant=\"ghost\" size=\"sm\" uniform pill aria-label=\"Close\" onClick={() => setOpen(false)}>\n <X />\n </Button>\n </div>\n </div>\n {picker}\n </Popover.Content>\n </Popover>\n ) : (\n <Dialog open={open} onOpenChange={setOpen}>\n <Dialog.Trigger>{well}</Dialog.Trigger>\n <Dialog.Content mobileVariant=\"sheet\" surface=\"grouped\" showClose={false} className={s.Sheet}>\n {/* iOS 27.2 sets Close first and the eyedropper last (UIColorPickerViewController on an iPhone 17); the\n iOS 26 kit had them the other way round. */}\n <Toolbar background=\"solid\">\n <Toolbar.Leading>\n <Dialog.Close>\n <NavigationButton action=\"close\" />\n </Dialog.Close>\n </Toolbar.Leading>\n <Toolbar.Title>{title}</Toolbar.Title>\n <Toolbar.Trailing>{eyedropperButton(true)}</Toolbar.Trailing>\n </Toolbar>\n <Dialog.Header>\n <Dialog.Title>{title}</Dialog.Title>\n </Dialog.Header>\n <Dialog.Body className={s.SheetBody}>{picker}</Dialog.Body>\n </Dialog.Content>\n </Dialog>\n )}\n </>\n )\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ColorWell.js","sourceRoot":"","sources":["../../../../src/components/ColorPicker/ColorWell.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAsC,MAAM,OAAO,CAAA;AAC9F,OAAO,CAAC,MAAM,8DAA8D,CAAA;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAClC,OAAO,EAAE,UAAU,EAAE,CAAC,EAAE,MAAM,SAAS,CAAA;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACpC,OAAO,EAAE,WAAW,EAAyB,MAAM,eAAe,CAAA;AAClE,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AA6BjG;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,EACxB,EAAE,EACF,KAAK,EAAE,SAAS,EAChB,YAAY,GAAG,IAAI,EACnB,QAAQ,EACR,KAAK,GAAG,QAAQ,EAChB,kBAAkB,GAAG,IAAI,EACzB,IAAI,GAAG,IAAI,EACX,QAAQ,GAAG,KAAK,EAChB,IAAI,EACJ,YAAY,EAAE,SAAS,EACvB,iBAAiB,EAAE,cAAc,EACjC,S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useId, useRef, useState, type CSSProperties, type ReactNode } from \"react\"\nimport s from \"@plexui/styles/components/ColorPicker/ColorPicker.module.css\"\nimport { useBreakpoint } from \"../../hooks/useBreakpoints\"\nimport { useLatestValue } from \"../../hooks/useLatestValue\"\nimport { Button, NavigationButton } from \"../Button\"\nimport { Dialog } from \"../Dialog\"\nimport { Eyedropper, X } from \"../Icon\"\nimport { Popover } from \"../Popover\"\nimport { Toolbar } from \"../Toolbar\"\nimport { ColorPicker, type ColorPickerProps } from \"./ColorPicker\"\nimport { alphaPercent, cssColor, eyeDropper, formatColor, hexDigits, parseColor } from \"./shared\"\n\nexport type ColorWellProps = Omit<ColorPickerProps, \"value\" | \"defaultValue\" | \"onChange\" | \"aria-label\" | \"className\" | \"id\"> & {\n /** The `id` of the well. */\n id?: string\n /** The controlled color, `#rrggbb` or `#rrggbbaa`; `null` shows the rainbow well with no color. Use with `onChange`. */\n value?: string | null\n /** The color when it is initially rendered. Use when you do not need to control the color. @default null */\n defaultValue?: string | null\n /** Called with the color the picker chose. */\n onChange?: (value: string) => void\n /** The title of the picker. @default \"Colors\" */\n title?: string\n /** Shows the eyedropper in the picker where the browser can pick a color from the screen (EyeDropper API). @default true */\n supportsEyedropper?: boolean\n /** The kit's Picker Button sizes, `sm` 28px and `lg` 36px, and `xs` 24px for the start of a 32px field. @default \"sm\" */\n size?: \"xs\" | \"sm\" | \"lg\"\n /** When `true`, prevents the user from opening the picker. */\n disabled?: boolean\n /** The name of the well. Submits its color with the owning form. */\n name?: string\n /** Accessible name of the well. @default \"Color\" */\n \"aria-label\"?: string\n /** The `id` of the visible label of the well. */\n \"aria-labelledby\"?: string\n /** CSS classes applied to the well */\n className?: string\n}\n\n/**\n * A color well, as `UIColorWell`: the kit's Picker Button (5739:34128), a rainbow ring around the chosen color. It\n * opens the color picker, in a Popover from the well, and on a phone in a sheet, as the system picker.\n */\nexport function ColorWell({\n id,\n value: valueProp,\n defaultValue = null,\n onChange,\n title = \"Colors\",\n supportsEyedropper = true,\n size = \"sm\",\n disabled = false,\n name,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n className,\n ...pickerProps\n}: ColorWellProps) {\n const wide = useBreakpoint(\"md\")\n const valueId = `${useId()}-value`\n const [open, setOpen] = useState(false)\n const [internalValue, setInternalValue] = useState<string | null>(defaultValue)\n const value = valueProp === undefined ? internalValue : valueProp\n const color = parseColor(value)\n const options = useLatestValue({ controlled: valueProp !== undefined, onChange })\n // The EyeDropper API exists only in a browser, so the button appears after hydration.\n const [canPick, setCanPick] = useState(false)\n useEffect(() => setCanPick(eyeDropper() !== null), [])\n const picking = useRef(false)\n\n const choose = (next: string) => {\n if (!options.current.controlled) setInternalValue(next)\n options.current.onChange?.(next)\n }\n\n const pick = async () => {\n const EyeDropper = eyeDropper()\n if (!EyeDropper || picking.current) return\n picking.current = true\n try {\n const picked = parseColor((await new EyeDropper().open()).sRGBHex)\n if (picked) choose(formatColor({ ...picked, a: color?.a ?? 1 }))\n } catch {\n // Escape, or a click the browser did not hand to the page, cancels the pick.\n } finally {\n picking.current = false\n }\n }\n\n const well = (\n <button\n id={id}\n type=\"button\"\n className={clsx(s.Well, className)}\n data-size={size}\n data-selected={color ? \"\" : undefined}\n disabled={disabled}\n aria-label={ariaLabelledBy ? undefined : ariaLabel ?? \"Color\"}\n aria-labelledby={ariaLabelledBy}\n aria-describedby={color ? valueId : undefined}\n style={color ? { \"--color-well-color\": cssColor(color) } as CSSProperties : undefined}\n >\n {color && <span className={s.WellColor} />}\n {/* The color, read as the well's description. */}\n {color && <span id={valueId} hidden>{`#${hexDigits(color)}${color.a < 1 ? `, ${alphaPercent(color.a)}% opacity` : \"\"}`}</span>}\n </button>\n )\n\n const picker = (\n <ColorPicker {...pickerProps} value={formatColor(color ?? { r: 0, g: 0, b: 0, a: 1 })} onChange={choose} aria-label={title} />\n )\n const eyedropperButton = (glass: boolean): ReactNode => supportsEyedropper && canPick && (\n <Button\n color=\"secondary\"\n variant={glass ? \"soft\" : \"ghost\"}\n mobileMaterial={glass ? \"glass\" : undefined}\n size={glass ? \"lg\" : \"sm\"}\n uniform\n pill\n aria-label=\"Eyedropper\"\n onClick={() => void pick()}\n >\n <Eyedropper />\n </Button>\n )\n\n return (\n <>\n {name !== undefined && <input type=\"hidden\" name={name} value={value ?? \"\"} disabled={disabled} />}\n {wide ? (\n <Popover open={open} onOpenChange={setOpen}>\n <Popover.Trigger>{well}</Popover.Trigger>\n <Popover.Content className={s.Popover} width=\"auto\" side=\"bottom\" align=\"center\">\n <div className={s.PopoverHeader}>\n <div className={s.PopoverLeading}>{eyedropperButton(false)}</div>\n <span className={s.PopoverTitle}>{title}</span>\n <div className={s.PopoverTrailing}>\n <Button color=\"secondary\" variant=\"ghost\" size=\"sm\" uniform pill aria-label=\"Close\" onClick={() => setOpen(false)}>\n <X />\n </Button>\n </div>\n </div>\n {picker}\n </Popover.Content>\n </Popover>\n ) : (\n <Dialog open={open} onOpenChange={setOpen}>\n <Dialog.Trigger>{well}</Dialog.Trigger>\n <Dialog.Content mobileVariant=\"sheet\" surface=\"grouped\" showClose={false} className={s.Sheet}>\n {/* iOS 27.2 sets Close first and the eyedropper last (UIColorPickerViewController on an iPhone 17); the\n iOS 26 kit had them the other way round. */}\n <Toolbar background=\"solid\">\n <Toolbar.Leading>\n <Dialog.Close>\n <NavigationButton action=\"close\" />\n </Dialog.Close>\n </Toolbar.Leading>\n <Toolbar.Title>{title}</Toolbar.Title>\n <Toolbar.Trailing>{eyedropperButton(true)}</Toolbar.Trailing>\n </Toolbar>\n <Dialog.Header>\n <Dialog.Title>{title}</Dialog.Title>\n </Dialog.Header>\n <Dialog.Body className={s.SheetBody}>{picker}</Dialog.Body>\n </Dialog.Content>\n </Dialog>\n )}\n </>\n )\n}\n"]}
|
|
@@ -1,22 +1,79 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import clsx from "clsx";
|
|
4
|
+
import { useLayoutEffect, useRef, useState } from "react";
|
|
4
5
|
import s from "@plexui/styles/components/NavigationRow/NavigationRow.module.css";
|
|
5
6
|
import { Button, ButtonLink } from "../Button/index.js";
|
|
6
7
|
import { Disclosure } from "../Icon/index.js";
|
|
8
|
+
import { useFieldColumns } from "../../lib/fieldRow.js";
|
|
7
9
|
const shown = (value) => value !== null && value !== undefined && value !== false && value !== "";
|
|
10
|
+
/** Whether the label and the value of a row fit beside each other on one line: measured in the end layout, unwrapped */
|
|
11
|
+
const valueFitsBeside = (row) => {
|
|
12
|
+
const content = row.querySelector("[data-navigation-row-content]");
|
|
13
|
+
if (!content)
|
|
14
|
+
return true;
|
|
15
|
+
const below = row.hasAttribute("data-value-below");
|
|
16
|
+
row.removeAttribute("data-value-below");
|
|
17
|
+
row.setAttribute("data-measuring", "");
|
|
18
|
+
const fits = [content, ...content.querySelectorAll("[data-navigation-row-part]")].every((element) => element.scrollWidth <= element.clientWidth + 0.5);
|
|
19
|
+
row.removeAttribute("data-measuring");
|
|
20
|
+
if (below)
|
|
21
|
+
row.setAttribute("data-value-below", "");
|
|
22
|
+
return fits;
|
|
23
|
+
};
|
|
8
24
|
/**
|
|
9
25
|
* A FieldGroup row that opens what it holds, as an iOS Settings drill-in: label, current value, chevron, one press.
|
|
10
26
|
* Every other prop (id, events, ARIA, data attributes, className) goes to the pressable, so a caller states what
|
|
11
27
|
* the row opens (`aria-haspopup`, `aria-expanded`) itself.
|
|
12
28
|
*/
|
|
13
29
|
export function NavigationRow(props) {
|
|
14
|
-
const { label, value, description, href, external, as, disabled, className, ref, target, rel, download, hrefLang, ping, referrerPolicy, ...rest } = props;
|
|
30
|
+
const { label, value, description, href, external, as, disabled, valuePlacement = "end", className, ref, target, rel, download, hrefLang, ping, referrerPolicy, ...rest } = props;
|
|
15
31
|
// Only the link attributes given: an undefined `target` would override the new tab of an external link
|
|
16
32
|
const linkAttributes = Object.fromEntries(Object.entries({ target, rel, download, hrefLang, ping, referrerPolicy }).filter(([, attribute]) => attribute !== undefined));
|
|
17
33
|
const hasValue = shown(value);
|
|
18
34
|
const hasDescription = shown(description);
|
|
19
|
-
const
|
|
35
|
+
const rowRef = useRef(null);
|
|
36
|
+
// FieldGroup columns give the label a column of its own: a change of them measures again
|
|
37
|
+
const columns = useFieldColumns();
|
|
38
|
+
const [fits, setFits] = useState(true);
|
|
39
|
+
const auto = valuePlacement === "auto" && hasValue;
|
|
40
|
+
// "auto": measure on mount, when the label or value changes, and when the row's width changes
|
|
41
|
+
useLayoutEffect(() => {
|
|
42
|
+
const row = rowRef.current;
|
|
43
|
+
if (!auto || !row)
|
|
44
|
+
return;
|
|
45
|
+
let live = true;
|
|
46
|
+
const check = () => {
|
|
47
|
+
if (live)
|
|
48
|
+
setFits(valueFitsBeside(row));
|
|
49
|
+
};
|
|
50
|
+
check();
|
|
51
|
+
// A web font that arrives late (font-display: swap) changes the words' widths, not the row's
|
|
52
|
+
const fonts = typeof document !== "undefined" ? document.fonts : undefined;
|
|
53
|
+
fonts?.ready.then(check);
|
|
54
|
+
fonts?.addEventListener?.("loadingdone", check);
|
|
55
|
+
const stop = () => {
|
|
56
|
+
live = false;
|
|
57
|
+
fonts?.removeEventListener?.("loadingdone", check);
|
|
58
|
+
};
|
|
59
|
+
if (typeof ResizeObserver === "undefined")
|
|
60
|
+
return stop;
|
|
61
|
+
let width = row.getBoundingClientRect().width;
|
|
62
|
+
const observer = new ResizeObserver(() => {
|
|
63
|
+
const next = row.getBoundingClientRect().width;
|
|
64
|
+
if (next === width)
|
|
65
|
+
return;
|
|
66
|
+
width = next;
|
|
67
|
+
check();
|
|
68
|
+
});
|
|
69
|
+
observer.observe(row);
|
|
70
|
+
return () => {
|
|
71
|
+
stop();
|
|
72
|
+
observer.disconnect();
|
|
73
|
+
};
|
|
74
|
+
}, [auto, label, value, description, columns]);
|
|
75
|
+
const below = hasValue && (valuePlacement === "below" || (auto && !fits));
|
|
76
|
+
const content = (_jsxs("span", { className: s.Content, "data-navigation-row-content": "", children: [_jsxs("span", { className: s.Text, children: [_jsx("span", { className: s.Label, "data-navigation-row-part": "", children: label }), hasDescription && _jsx("span", { className: s.Description, children: description })] }), hasValue && _jsx("span", { className: s.Value, "data-navigation-row-part": "", children: value }), _jsx(Disclosure, { className: s.Disclosure, "aria-hidden": "true", "data-no-autosize": "" })] }));
|
|
20
77
|
const shared = {
|
|
21
78
|
className: clsx(s.Pressable, className),
|
|
22
79
|
block: true,
|
|
@@ -24,6 +81,6 @@ export function NavigationRow(props) {
|
|
|
24
81
|
variant: "ghost",
|
|
25
82
|
"data-navigation-row": "",
|
|
26
83
|
};
|
|
27
|
-
return (_jsx("div", { className: s.NavigationRow, "data-row": "", "data-value": hasValue ? "" : undefined, "data-description": hasDescription ? "" : undefined, children: href !== undefined && !disabled ? (_jsx(ButtonLink, { ...rest, ...shared, ref: ref, href: href, external: external, as: as, ...linkAttributes, children: content })) : (_jsx(Button, { ...rest, ...shared, ref: ref, disabled: disabled, children: content })) }));
|
|
84
|
+
return (_jsx("div", { ref: rowRef, className: s.NavigationRow, "data-row": "", "data-value-below": below ? "" : undefined, "data-value": hasValue ? "" : undefined, "data-description": hasDescription ? "" : undefined, children: href !== undefined && !disabled ? (_jsx(ButtonLink, { ...rest, ...shared, ref: ref, href: href, external: external, as: as, ...linkAttributes, children: content })) : (_jsx(Button, { ...rest, ...shared, ref: ref, disabled: disabled, children: content })) }));
|
|
28
85
|
}
|
|
29
86
|
//# sourceMappingURL=NavigationRow.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NavigationRow.js","sourceRoot":"","sources":["../../../../src/components/NavigationRow/NavigationRow.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,IAAI,MAAM,MAAM,CAAA;AAEvB,OAAO,CAAC,MAAM,kEAAkE,CAAA;AAChF,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,SAA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M,sBAAkB,EAAE,GAAG,IACzE,CACR,CAAA;IAED,MAAM,MAAM,GAAG;QACb,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,SAAS,EAAE,SAAS,CAAC;QACvC,KAAK,EAAE,IAAI;QACX,KAAK,EAAE,WAAW;QAClB,OAAO,EAAE,OAAO;QAChB,qBAAqB,EAAE,EAAE;KACjB,CAAA;IAEV,OAAO,CACL,cACE,SAAS,EAAE,CAAC,CAAC,aAAa,cACjB,EAAE,gBACC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,sBACnB,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,YAEhD,IAAI,KAAK,SAAS,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CACjC,KAAC,UAAU,OACJ,IAAgC,KACjC,MAAM,EACV,GAAG,EAAE,GAA6B,EAClC,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,QAAQ,EAClB,EAAE,EAAE,EAA0B,KAC1B,cAAc,YAEjB,OAAO,GACG,CACd,CAAC,CAAC,CAAC,CACF,KAAC,MAAM,OAAM,IAAgD,KAAM,MAAM,EAAE,GAAG,EAAE,GAA6B,EAAE,QAAQ,EAAE,QAAQ,YAC9H,OAAO,GACD,CACV,GACG,CACP,CAAA;AACH,CAAC","sourcesContent":["\"use client\"\n\nimport clsx from \"clsx\"\nimport type { AnchorHTMLAttributes, ButtonHTMLAttributes, ComponentType, ReactNode, Ref } from \"react\"\nimport s from \"@plexui/styles/components/NavigationRow/NavigationRow.module.css\"\nimport { Button, ButtonLink } from \"../Button\"\nimport { Disclosure } from \"../Icon\"\n\ntype LinkAttributes = Pick<\n AnchorHTMLAttributes<HTMLAnchorElement>,\n \"target\" | \"rel\" | \"download\" | \"hrefLang\" | \"ping\" | \"referrerPolicy\"\n>\n\n// Events come from a button or, with `href`, a link (a disabled link is a button again), so handlers see either\nexport type NavigationRowProps = Omit<ButtonHTMLAttributes<HTMLButtonElement | HTMLAnchorElement>, \"children\" | \"value\" | \"type\"> &\n LinkAttributes & {\n /** The row's name, where a row's label starts */\n label: ReactNode\n /** The current value, at the end of the row in the secondary label. `0` shows; `null`, `undefined` and `\"\"` do not. */\n value?: ReactNode\n /** A line under the label; the row grows from 52 to hold it */\n description?: ReactNode\n /** Where the row goes. With it the row is a link (through `PlexUIProvider`'s `linkComponent`, or `as`). */\n href?: string\n /** Force external-link behavior for `href` */\n external?: boolean\n /** Link component for `href`, e.g. a router's link. @default PlexUIProvider linkComponent */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n as?: ComponentType<any> | \"a\"\n /** The row can't be pressed. A disabled link renders as a disabled button, so it never navigates. */\n disabled?: boolean\n /** Ref for the row's pressable (a `button`, or the link's element) */\n ref?: Ref<HTMLButtonElement | HTMLAnchorElement | null>\n}\n\nconst shown = (value: ReactNode) => value !== null && value !== undefined && value !== false && value !== \"\"\n\n/**\n * A FieldGroup row that opens what it holds, as an iOS Settings drill-in: label, current value, chevron, one press.\n * Every other prop (id, events, ARIA, data attributes, className) goes to the pressable, so a caller states what\n * the row opens (`aria-haspopup`, `aria-expanded`) itself.\n */\nexport function NavigationRow(props: NavigationRowProps) {\n const { label, value, description, href, external, as, disabled, className, ref, target, rel, download, hrefLang, ping, referrerPolicy, ...rest } = props\n // Only the link attributes given: an undefined `target` would override the new tab of an external link\n const linkAttributes = Object.fromEntries(\n Object.entries({ target, rel, download, hrefLang, ping, referrerPolicy }).filter(([, attribute]) => attribute !== undefined),\n )\n const hasValue = shown(value)\n const hasDescription = shown(description)\n\n const content = (\n <span className={s.Content}>\n <span className={s.Text}>\n <span className={s.Label}>{label}</span>\n {hasDescription && <span className={s.Description}>{description}</span>}\n </span>\n {hasValue && <span className={s.Value}>{value}</span>}\n <Disclosure className={s.Disclosure} aria-hidden=\"true\" data-no-autosize=\"\" />\n </span>\n )\n\n const shared = {\n className: clsx(s.Pressable, className),\n block: true,\n color: \"secondary\",\n variant: \"ghost\",\n \"data-navigation-row\": \"\",\n } as const\n\n return (\n <div\n className={s.NavigationRow}\n data-row=\"\"\n data-value={hasValue ? \"\" : undefined}\n data-description={hasDescription ? \"\" : undefined}\n >\n {href !== undefined && !disabled ? (\n <ButtonLink\n {...(rest as Record<string, unknown>)}\n {...shared}\n ref={ref as Ref<HTMLAnchorElement>}\n href={href}\n external={external}\n as={as as PlexUI.LinkComponent}\n {...linkAttributes}\n >\n {content}\n </ButtonLink>\n ) : (\n <Button {...(rest as ButtonHTMLAttributes<HTMLButtonElement>)} {...shared} ref={ref as Ref<HTMLButtonElement>} disabled={disabled}>\n {content}\n </Button>\n )}\n </div>\n )\n}\n"]}
|
|
1
|
+
{"version":3,"file":"NavigationRow.js","sourceRoot":"","sources":["../../../../src/components/NavigationRow/NavigationRow.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAsG,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC7J,OAAO,CAAC,MAAM,kEAAkE,CAAA;AAChF,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAkCpD,MAAM,KAAK,GAAG,CAAC,KAAgB,EAAE,EAAE,CAAC,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,KAAK,IAAI,KAAK,KAAK,EAAE,CAAA;AAE5G,wHAAwH;AACxH,MAAM,eAAe,GAAG,CAAC,GAAgB,EAAE,EAAE;IAC3C,MAAM,OAAO,GAAG,GAAG,CAAC,aAAa,CAAc,+BAA+B,CAAC,CAAA;IAC/E,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,CAAA;IACzB,MAAM,KAAK,GAAG,GAAG,CAAC,YAAY,CAAC,kBAAkB,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,EAAE,sBACO,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,gBAC5B,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,sBACnB,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,YAEhD,IAAI,KAAK,SAAS,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CACjC,KAAC,UAAU,OACJ,IAAgC,KACjC,MAAM,EACV,GAAG,EAAE,GAA6B,EAClC,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,QAAQ,EAClB,EAAE,EAAE,EAA0B,KAC1B,cAAc,YAEjB,OAAO,GACG,CACd,CAAC,CAAC,CAAC,CACF,KAAC,MAAM,OAAM,IAAgD,KAAM,MAAM,EAAE,GAAG,EAAE,GAA6B,EAAE,QAAQ,EAAE,QAAQ,YAC9H,OAAO,GACD,CACV,GACG,CACP,CAAA;AACH,CAAC","sourcesContent":["\"use client\"\n\nimport clsx from \"clsx\"\nimport { type AnchorHTMLAttributes, type ButtonHTMLAttributes, type ComponentType, type ReactNode, type Ref, useLayoutEffect, useRef, useState } from \"react\"\nimport s from \"@plexui/styles/components/NavigationRow/NavigationRow.module.css\"\nimport { Button, ButtonLink } from \"../Button\"\nimport { Disclosure } from \"../Icon\"\nimport { useFieldColumns } from \"../../lib/fieldRow\"\n\ntype LinkAttributes = Pick<\n AnchorHTMLAttributes<HTMLAnchorElement>,\n \"target\" | \"rel\" | \"download\" | \"hrefLang\" | \"ping\" | \"referrerPolicy\"\n>\n\n// Events come from a button or, with `href`, a link (a disabled link is a button again), so handlers see either\nexport type NavigationRowProps = Omit<ButtonHTMLAttributes<HTMLButtonElement | HTMLAnchorElement>, \"children\" | \"value\" | \"type\"> &\n LinkAttributes & {\n /** The row's name, where a row's label starts */\n label: ReactNode\n /** The current value, at the end of the row in the secondary label. `0` shows; `null`, `undefined` and `\"\"` do not. */\n value?: ReactNode\n /** A line under the label; the row grows from 52 to hold it */\n description?: ReactNode\n /** Where the row goes. With it the row is a link (through `PlexUIProvider`'s `linkComponent`, or `as`). */\n href?: string\n /** Force external-link behavior for `href` */\n external?: boolean\n /** Link component for `href`, e.g. a router's link. @default PlexUIProvider linkComponent */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n as?: ComponentType<any> | \"a\"\n /** The row can't be pressed. A disabled link renders as a disabled button, so it never navigates. */\n disabled?: boolean\n /**\n * Where the value stands: at the `end` of the row, `below` the label at the full width, or `auto`: at the end while\n * it fits beside the label on one line, otherwise below (as Calendar sets a long value). @default \"end\"\n */\n valuePlacement?: \"end\" | \"below\" | \"auto\"\n /** Ref for the row's pressable (a `button`, or the link's element) */\n ref?: Ref<HTMLButtonElement | HTMLAnchorElement | null>\n}\n\nconst shown = (value: ReactNode) => value !== null && value !== undefined && value !== false && value !== \"\"\n\n/** Whether the label and the value of a row fit beside each other on one line: measured in the end layout, unwrapped */\nconst valueFitsBeside = (row: HTMLElement) => {\n const content = row.querySelector<HTMLElement>(\"[data-navigation-row-content]\")\n if (!content) return true\n const below = row.hasAttribute(\"data-value-below\")\n row.removeAttribute(\"data-value-below\")\n row.setAttribute(\"data-measuring\", \"\")\n const fits = [content, ...content.querySelectorAll<HTMLElement>(\"[data-navigation-row-part]\")].every(\n (element) => element.scrollWidth <= element.clientWidth + 0.5,\n )\n row.removeAttribute(\"data-measuring\")\n if (below) row.setAttribute(\"data-value-below\", \"\")\n return fits\n}\n\n/**\n * A FieldGroup row that opens what it holds, as an iOS Settings drill-in: label, current value, chevron, one press.\n * Every other prop (id, events, ARIA, data attributes, className) goes to the pressable, so a caller states what\n * the row opens (`aria-haspopup`, `aria-expanded`) itself.\n */\nexport function NavigationRow(props: NavigationRowProps) {\n const { label, value, description, href, external, as, disabled, valuePlacement = \"end\", className, ref, target, rel, download, hrefLang, ping, referrerPolicy, ...rest } = props\n // Only the link attributes given: an undefined `target` would override the new tab of an external link\n const linkAttributes = Object.fromEntries(\n Object.entries({ target, rel, download, hrefLang, ping, referrerPolicy }).filter(([, attribute]) => attribute !== undefined),\n )\n const hasValue = shown(value)\n const hasDescription = shown(description)\n const rowRef = useRef<HTMLDivElement>(null)\n // FieldGroup columns give the label a column of its own: a change of them measures again\n const columns = useFieldColumns()\n const [fits, setFits] = useState(true)\n const auto = valuePlacement === \"auto\" && hasValue\n\n // \"auto\": measure on mount, when the label or value changes, and when the row's width changes\n useLayoutEffect(() => {\n const row = rowRef.current\n if (!auto || !row) return\n let live = true\n const check = () => {\n if (live) setFits(valueFitsBeside(row))\n }\n check()\n // A web font that arrives late (font-display: swap) changes the words' widths, not the row's\n const fonts = typeof document !== \"undefined\" ? document.fonts : undefined\n fonts?.ready.then(check)\n fonts?.addEventListener?.(\"loadingdone\", check)\n const stop = () => {\n live = false\n fonts?.removeEventListener?.(\"loadingdone\", check)\n }\n if (typeof ResizeObserver === \"undefined\") return stop\n let width = row.getBoundingClientRect().width\n const observer = new ResizeObserver(() => {\n const next = row.getBoundingClientRect().width\n if (next === width) return\n width = next\n check()\n })\n observer.observe(row)\n return () => {\n stop()\n observer.disconnect()\n }\n }, [auto, label, value, description, columns])\n\n const below = hasValue && (valuePlacement === \"below\" || (auto && !fits))\n\n const content = (\n <span className={s.Content} data-navigation-row-content=\"\">\n <span className={s.Text}>\n <span className={s.Label} data-navigation-row-part=\"\">{label}</span>\n {hasDescription && <span className={s.Description}>{description}</span>}\n </span>\n {hasValue && <span className={s.Value} data-navigation-row-part=\"\">{value}</span>}\n <Disclosure className={s.Disclosure} aria-hidden=\"true\" data-no-autosize=\"\" />\n </span>\n )\n\n const shared = {\n className: clsx(s.Pressable, className),\n block: true,\n color: \"secondary\",\n variant: \"ghost\",\n \"data-navigation-row\": \"\",\n } as const\n\n return (\n <div\n ref={rowRef}\n className={s.NavigationRow}\n data-row=\"\"\n data-value-below={below ? \"\" : undefined}\n data-value={hasValue ? \"\" : undefined}\n data-description={hasDescription ? \"\" : undefined}\n >\n {href !== undefined && !disabled ? (\n <ButtonLink\n {...(rest as Record<string, unknown>)}\n {...shared}\n ref={ref as Ref<HTMLAnchorElement>}\n href={href}\n external={external}\n as={as as PlexUI.LinkComponent}\n {...linkAttributes}\n >\n {content}\n </ButtonLink>\n ) : (\n <Button {...(rest as ButtonHTMLAttributes<HTMLButtonElement>)} {...shared} ref={ref as Ref<HTMLButtonElement>} disabled={disabled}>\n {content}\n </Button>\n )}\n </div>\n )\n}\n"]}
|
|
@@ -4,7 +4,7 @@ import clsx from "clsx";
|
|
|
4
4
|
import { useCallback, useEffect, useRef, useState, } from "react";
|
|
5
5
|
import s from "@plexui/styles/components/Stepper/Stepper.module.css";
|
|
6
6
|
import { useLatestValue } from "../../hooks/useLatestValue.js";
|
|
7
|
-
import { Minus, Plus } from "../Icon/index.js";
|
|
7
|
+
import { Minus, Plus, RemoveTrash } from "../Icon/index.js";
|
|
8
8
|
/** Delay before a held segment starts repeating, and the time between repeats, in ms. */
|
|
9
9
|
const REPEAT_DELAY = 400;
|
|
10
10
|
const REPEAT_INTERVAL = 100;
|
|
@@ -27,7 +27,7 @@ export const stepValue = (current, direction, { min, max, step, wrap }) => {
|
|
|
27
27
|
* name it with `aria-label` or `aria-labelledby` and show the value beside it. Keyboard focus lands on the
|
|
28
28
|
* stepper, a spin button: Up and Down step, Page Up and Page Down step ten times, Home and End go to the range ends.
|
|
29
29
|
*/
|
|
30
|
-
export function Stepper({ id, value: valueProp, defaultValue, onChange, min = 0, max = 100, step = 1, wrap = false, autoRepeat = true, disabled = false, pill = true, decrementLabel = "Decrease", incrementLabel = "Increase", name, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, onFocus, onBlur, className, }) {
|
|
30
|
+
export function Stepper({ id, value: valueProp, defaultValue, onChange, min = 0, max = 100, step = 1, wrap = false, autoRepeat = true, disabled = false, pill = true, decrementLabel = "Decrease", incrementLabel = "Increase", onRemove, removeLabel = "Remove", name, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, onFocus, onBlur, className, }) {
|
|
31
31
|
const [internalValue, setInternalValue] = useState(() => defaultValue ?? min);
|
|
32
32
|
const value = valueProp ?? internalValue;
|
|
33
33
|
// Timers and key handlers read the value through this ref; an uncontrolled step advances it at once.
|
|
@@ -61,9 +61,18 @@ export function Stepper({ id, value: valueProp, defaultValue, onChange, min = 0,
|
|
|
61
61
|
useEffect(() => stopRepeat, [stopRepeat]);
|
|
62
62
|
const atMin = !wrap && value <= min;
|
|
63
63
|
const atMax = !wrap && value >= max;
|
|
64
|
+
// At the minimum the decrement segment removes the item, when the owner can remove it
|
|
65
|
+
const removes = atMin && onRemove !== undefined;
|
|
66
|
+
const onRemoveRef = useLatestValue(onRemove);
|
|
64
67
|
const startPress = (segment, event) => {
|
|
65
68
|
if (event.button !== 0 || disabled)
|
|
66
69
|
return;
|
|
70
|
+
if (segment === "decrement" && removes) {
|
|
71
|
+
event.currentTarget.setPointerCapture?.(event.pointerId);
|
|
72
|
+
setPressed(segment);
|
|
73
|
+
onRemoveRef.current?.();
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
67
76
|
if (segment === "decrement" ? atMin : atMax)
|
|
68
77
|
return;
|
|
69
78
|
event.currentTarget.setPointerCapture?.(event.pointerId);
|
|
@@ -83,6 +92,8 @@ export function Stepper({ id, value: valueProp, defaultValue, onChange, min = 0,
|
|
|
83
92
|
const handleClick = (segment, event) => {
|
|
84
93
|
if (event.detail !== 0 || disabled)
|
|
85
94
|
return;
|
|
95
|
+
if (segment === "decrement" && removes)
|
|
96
|
+
return onRemoveRef.current?.();
|
|
86
97
|
stepBy(segment === "decrement" ? -1 : 1);
|
|
87
98
|
};
|
|
88
99
|
const handleKeyDown = (event) => {
|
|
@@ -95,6 +106,8 @@ export function Stepper({ id, value: valueProp, defaultValue, onChange, min = 0,
|
|
|
95
106
|
PageDown: () => stepBy(-1, 10),
|
|
96
107
|
Home: () => commit(min),
|
|
97
108
|
End: () => commit(max),
|
|
109
|
+
// At the minimum Delete or Backspace removes, as the trash can does; the arrows never do
|
|
110
|
+
...(removes && { Delete: () => onRemoveRef.current?.(), Backspace: () => onRemoveRef.current?.() }),
|
|
98
111
|
};
|
|
99
112
|
const action = keys[event.key];
|
|
100
113
|
if (!action)
|
|
@@ -103,12 +116,13 @@ export function Stepper({ id, value: valueProp, defaultValue, onChange, min = 0,
|
|
|
103
116
|
action();
|
|
104
117
|
};
|
|
105
118
|
const segment = (kind) => {
|
|
106
|
-
const
|
|
107
|
-
const
|
|
108
|
-
|
|
119
|
+
const remove = kind === "decrement" && removes;
|
|
120
|
+
const atEnd = !remove && (kind === "decrement" ? atMin : atMax);
|
|
121
|
+
const Icon = remove ? RemoveTrash : kind === "decrement" ? Minus : Plus;
|
|
122
|
+
return (_jsx("button", { type: "button", tabIndex: -1, "aria-label": remove ? removeLabel : kind === "decrement" ? decrementLabel : incrementLabel, "aria-disabled": atEnd || undefined, disabled: disabled, className: s.Segment, "data-segment": kind, "data-remove": remove ? "" : undefined, "data-disabled": atEnd || disabled ? "" : undefined, "data-pressed": pressed === kind && !disabled ? "" : undefined,
|
|
109
123
|
// Keeps the focus where it is, as a native stepper takes none.
|
|
110
124
|
onMouseDown: (event) => event.preventDefault(), onPointerDown: (event) => startPress(kind, event), onPointerUp: stopRepeat, onPointerCancel: stopRepeat, onLostPointerCapture: stopRepeat, onClick: (event) => handleClick(kind, event), children: _jsx(Icon, { className: s.Icon }) }));
|
|
111
125
|
};
|
|
112
|
-
return (_jsxs("div", { id: id, role: "spinbutton", tabIndex: disabled ? -1 : 0, "aria-valuenow": value, "aria-valuemin": min, "aria-valuemax": max, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, "aria-disabled": disabled || undefined, className: clsx(s.Stepper, className), "data-disabled": disabled ? "" : undefined, "data-pill": pill ? "" : undefined, onKeyDown: handleKeyDown, onFocus: onFocus, onBlur: onBlur, children: [segment("decrement"), _jsx("span", { className: s.Separator, "aria-hidden": "true" }), segment("increment"), name !== undefined && _jsx("input", { type: "hidden", name: name, value: value, disabled: disabled })] }));
|
|
126
|
+
return (_jsxs("div", { id: id, role: "spinbutton", tabIndex: disabled ? -1 : 0, "aria-valuenow": value, "aria-valuemin": min, "aria-valuemax": max, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, "aria-keyshortcuts": removes ? "Delete" : undefined, "aria-disabled": disabled || undefined, className: clsx(s.Stepper, className), "data-disabled": disabled ? "" : undefined, "data-pill": pill ? "" : undefined, onKeyDown: handleKeyDown, onFocus: onFocus, onBlur: onBlur, children: [segment("decrement"), _jsx("span", { className: s.Separator, "aria-hidden": "true" }), segment("increment"), name !== undefined && _jsx("input", { type: "hidden", name: name, value: value, disabled: disabled })] }));
|
|
113
127
|
}
|
|
114
128
|
//# sourceMappingURL=Stepper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Stepper.js","sourceRoot":"","sources":["../../../../src/components/Stepper/Stepper.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAKL,WAAW,EACX,SAAS,EACT,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAA;AACd,OAAO,CAAC,MAAM,sDAAsD,CAAA;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AA6CrC,yFAAyF;AACzF,MAAM,YAAY,GAAG,GAAG,CAAA;AACxB,MAAM,eAAe,GAAG,GAAG,CAAA;AAE3B,MAAM,QAAQ,GAAG,CAAC,CAAS,EAAE,EAAE;IAC7B,MAAM,CAAC,EAAE,QAAQ,GAAG,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC9C,OAAO,QAAQ,CAAC,MAAM,C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cAAc,sBACb,eAAe,mBAClB,QAAQ,IAAI,SAAS,EACpC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,mBACtB,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,eAC7B,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,EAChC,SAAS,EAAE,aAAa,EACxB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,aAEb,OAAO,CAAC,WAAW,CAAC,EACrB,eAAM,SAAS,EAAE,CAAC,CAAC,SAAS,iBAAc,MAAM,GAAG,EAClD,OAAO,CAAC,WAAW,CAAC,EACpB,IAAI,KAAK,SAAS,IAAI,gBAAO,IAAI,EAAC,QAAQ,EAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,GAAI,IACxF,CACP,CAAA;AACH,CAAC","sourcesContent":["\"use client\"\n\nimport clsx from \"clsx\"\nimport {\n type FocusEventHandler,\n type KeyboardEvent,\n type MouseEvent,\n type PointerEvent,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from \"react\"\nimport s from \"@plexui/styles/components/Stepper/Stepper.module.css\"\nimport { useLatestValue } from \"../../hooks/useLatestValue\"\nimport { Minus, Plus } from \"../Icon\"\n\nexport type StepperProps = {\n /** The `id` of the stepper. */\n id?: string\n /** The controlled value. Use with `onChange`. */\n value?: number\n /** The value when it is initially rendered. Use when you do not need to control the value. @default min */\n defaultValue?: number\n /** Called with the next value after a step. */\n onChange?: (value: number) => void\n /** The lowest value. @default 0 */\n min?: number\n /** The highest value. @default 100 */\n max?: number\n /** The amount each step adds or removes. @default 1 */\n step?: number\n /** A step past `max` continues from `min`, and one below `min` from `max`. @default false */\n wrap?: boolean\n /** Holding a segment keeps stepping, as a native stepper does. @default true */\n autoRepeat?: boolean\n /** When `true`, prevents the user from interacting with the stepper. */\n disabled?: boolean\n /** Fully rounded ends. @default true */\n pill?: boolean\n /** Accessible name of the decrement segment. @default \"Decrease\" */\n decrementLabel?: string\n /** Accessible name of the increment segment. @default \"Increase\" */\n incrementLabel?: string\n /** The name of the stepper. Submits its value with the owning form. */\n name?: string\n /** Accessible name of the value the stepper changes, when no visible label names it. */\n \"aria-label\"?: string\n /** The `id` of the visible label of the value the stepper changes. */\n \"aria-labelledby\"?: string\n /** The `id` of an element that describes the stepper, such as the text that shows its value. */\n \"aria-describedby\"?: string\n /** Event handler called when the stepper gains focus. */\n onFocus?: FocusEventHandler<HTMLDivElement>\n /** Event handler called when the stepper loses focus. */\n onBlur?: FocusEventHandler<HTMLDivElement>\n /** CSS classes applied to the stepper */\n className?: string\n}\n\n/** Delay before a held segment starts repeating, and the time between repeats, in ms. */\nconst REPEAT_DELAY = 400\nconst REPEAT_INTERVAL = 100\n\nconst decimals = (n: number) => {\n const [, fraction = \"\"] = String(n).split(\".\")\n return fraction.length\n}\n\n/** The value one step away, clamped to the range or wrapped, without floating point drift. */\nexport const stepValue = (current: number, direction: 1 | -1, { min, max, step, wrap }: { min: number; max: number; step: number; wrap: boolean }) => {\n const precision = Math.max(decimals(step), decimals(min), decimals(current))\n const next = Number((current + direction * step).toFixed(precision))\n if (next > max) return wrap ? min : max\n if (next < min) return wrap ? max : min\n return next\n}\n\n/**\n * Two segments that decrease and increase a number, as the iOS 26 stepper does. It shows no value of its own:\n * name it with `aria-label` or `aria-labelledby` and show the value beside it. Keyboard focus lands on the\n * stepper, a spin button: Up and Down step, Page Up and Page Down step ten times, Home and End go to the range ends.\n */\nexport function Stepper({\n id,\n value: valueProp,\n defaultValue,\n onChange,\n min = 0,\n max = 100,\n step = 1,\n wrap = false,\n autoRepeat = true,\n disabled = false,\n pill = true,\n decrementLabel = \"Decrease\",\n incrementLabel = \"Increase\",\n name,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-describedby\": ariaDescribedBy,\n onFocus,\n onBlur,\n className,\n}: StepperProps) {\n const [internalValue, setInternalValue] = useState(() => defaultValue ?? min)\n const value = valueProp ?? internalValue\n // Timers and key handlers read the value through this ref; an uncontrolled step advances it at once.\n const valueRef = useLatestValue(value)\n const onChangeRef = useLatestValue(onChange)\n const optionsRef = useLatestValue({ min, max, step, wrap, disabled, controlled: valueProp !== undefined })\n const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)\n const [pressed, setPressed] = useState<\"decrement\" | \"increment\" | null>(null)\n\n const commit = useCallback((next: number) => {\n if (next === valueRef.current) return false\n // A controlled value changes only when the owner passes it back, as in Vue.\n if (!optionsRef.current.controlled) {\n valueRef.current = next\n setInternalValue(next)\n }\n onChangeRef.current?.(next)\n return true\n }, [valueRef, optionsRef, onChangeRef])\n\n const stepBy = useCallback((direction: 1 | -1, times = 1) => {\n let next = valueRef.current\n for (let i = 0; i < times; i++) next = stepValue(next, direction, optionsRef.current)\n return commit(next)\n }, [commit, valueRef, optionsRef])\n\n const stopRepeat = useCallback(() => {\n clearTimeout(timer.current)\n timer.current = undefined\n setPressed(null)\n }, [])\n\n useEffect(() => stopRepeat, [stopRepeat])\n\n const atMin = !wrap && value <= min\n const atMax = !wrap && value >= max\n\n const startPress = (segment: \"decrement\" | \"increment\", event: PointerEvent<HTMLButtonElement>) => {\n if (event.button !== 0 || disabled) return\n if (segment === \"decrement\" ? atMin : atMax) return\n event.currentTarget.setPointerCapture?.(event.pointerId)\n setPressed(segment)\n const direction = segment === \"decrement\" ? -1 : 1\n stepBy(direction)\n if (!autoRepeat) return\n const repeat = () => {\n if (optionsRef.current.disabled || !stepBy(direction)) return stopRepeat()\n timer.current = setTimeout(repeat, REPEAT_INTERVAL)\n }\n timer.current = setTimeout(repeat, REPEAT_DELAY)\n }\n\n // A pointer steps on press, so only a click without one (assistive technology, `element.click()`) steps here.\n const handleClick = (segment: \"decrement\" | \"increment\", event: MouseEvent<HTMLButtonElement>) => {\n if (event.detail !== 0 || disabled) return\n stepBy(segment === \"decrement\" ? -1 : 1)\n }\n\n const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n if (disabled || event.altKey || event.ctrlKey || event.metaKey) return\n const keys: Record<string, () => void> = {\n ArrowUp: () => stepBy(1),\n ArrowDown: () => stepBy(-1),\n PageUp: () => stepBy(1, 10),\n PageDown: () => stepBy(-1, 10),\n Home: () => commit(min),\n End: () => commit(max),\n }\n const action = keys[event.key]\n if (!action) return\n event.preventDefault()\n action()\n }\n\n const segment = (kind: \"decrement\" | \"increment\") => {\n const atEnd = kind === \"decrement\" ? atMin : atMax\n const Icon = kind === \"decrement\" ? Minus : Plus\n return (\n <button\n type=\"button\"\n tabIndex={-1}\n aria-label={kind === \"decrement\" ? decrementLabel : incrementLabel}\n aria-disabled={atEnd || undefined}\n disabled={disabled}\n className={s.Segment}\n data-segment={kind}\n data-disabled={atEnd || disabled ? \"\" : undefined}\n data-pressed={pressed === kind && !disabled ? \"\" : undefined}\n // Keeps the focus where it is, as a native stepper takes none.\n onMouseDown={(event) => event.preventDefault()}\n onPointerDown={(event) => startPress(kind, event)}\n onPointerUp={stopRepeat}\n onPointerCancel={stopRepeat}\n onLostPointerCapture={stopRepeat}\n onClick={(event) => handleClick(kind, event)}\n >\n <Icon className={s.Icon} />\n </button>\n )\n }\n\n return (\n <div\n id={id}\n role=\"spinbutton\"\n tabIndex={disabled ? -1 : 0}\n aria-valuenow={value}\n aria-valuemin={min}\n aria-valuemax={max}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n aria-describedby={ariaDescribedBy}\n aria-disabled={disabled || undefined}\n className={clsx(s.Stepper, className)}\n data-disabled={disabled ? \"\" : undefined}\n data-pill={pill ? \"\" : undefined}\n onKeyDown={handleKeyDown}\n onFocus={onFocus}\n onBlur={onBlur}\n >\n {segment(\"decrement\")}\n <span className={s.Separator} aria-hidden=\"true\" />\n {segment(\"increment\")}\n {name !== undefined && <input type=\"hidden\" name={name} value={value} disabled={disabled} />}\n </div>\n )\n}\n"]}
|
|
1
|
+
{"version":3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E,CAAC,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,YAE5C,KAAC,IAAI,IAAC,SAAS,EAAE,CAAC,CAAC,IAAI,GAAI,GACpB,CACV,CAAA;IACH,CAAC,CAAA;IAED,OAAO,CACL,eACE,EAAE,EAAE,EAAE,EACN,IAAI,EAAC,YAAY,EACjB,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,mBACZ,KAAK,mBACL,GAAG,mBACH,GAAG,gBACN,SAAS,qBACJ,cAAc,sBACb,eAAe,uBACd,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,mBAClC,QAAQ,IAAI,SAAS,EACpC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,mBACtB,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,eAC7B,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,EAChC,SAAS,EAAE,aAAa,EACxB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,aAEb,OAAO,CAAC,WAAW,CAAC,EACrB,eAAM,SAAS,EAAE,CAAC,CAAC,SAAS,iBAAc,MAAM,GAAG,EAClD,OAAO,CAAC,WAAW,CAAC,EACpB,IAAI,KAAK,SAAS,IAAI,gBAAO,IAAI,EAAC,QAAQ,EAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,GAAI,IACxF,CACP,CAAA;AACH,CAAC","sourcesContent":["\"use client\"\n\nimport clsx from \"clsx\"\nimport {\n type FocusEventHandler,\n type KeyboardEvent,\n type MouseEvent,\n type PointerEvent,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from \"react\"\nimport s from \"@plexui/styles/components/Stepper/Stepper.module.css\"\nimport { useLatestValue } from \"../../hooks/useLatestValue\"\nimport { Minus, Plus, RemoveTrash } from \"../Icon\"\n\nexport type StepperProps = {\n /** The `id` of the stepper. */\n id?: string\n /** The controlled value. Use with `onChange`. */\n value?: number\n /** The value when it is initially rendered. Use when you do not need to control the value. @default min */\n defaultValue?: number\n /** Called with the next value after a step. */\n onChange?: (value: number) => void\n /** The lowest value. @default 0 */\n min?: number\n /** The highest value. @default 100 */\n max?: number\n /** The amount each step adds or removes. @default 1 */\n step?: number\n /** A step past `max` continues from `min`, and one below `min` from `max`. @default false */\n wrap?: boolean\n /** Holding a segment keeps stepping, as a native stepper does. @default true */\n autoRepeat?: boolean\n /** When `true`, prevents the user from interacting with the stepper. */\n disabled?: boolean\n /** Fully rounded ends. @default true */\n pill?: boolean\n /** Accessible name of the decrement segment. @default \"Decrease\" */\n decrementLabel?: string\n /** Accessible name of the increment segment. @default \"Increase\" */\n incrementLabel?: string\n /**\n * Called when the decrement segment is pressed at `min`. With it, the segment shows a trash can there and removes\n * the item, as a cart's stepper does at a quantity of one (without `wrap`).\n */\n onRemove?: () => void\n /** Accessible name of the decrement segment when it removes. @default \"Remove\" */\n removeLabel?: string\n /** The name of the stepper. Submits its value with the owning form. */\n name?: string\n /** Accessible name of the value the stepper changes, when no visible label names it. */\n \"aria-label\"?: string\n /** The `id` of the visible label of the value the stepper changes. */\n \"aria-labelledby\"?: string\n /** The `id` of an element that describes the stepper, such as the text that shows its value. */\n \"aria-describedby\"?: string\n /** Event handler called when the stepper gains focus. */\n onFocus?: FocusEventHandler<HTMLDivElement>\n /** Event handler called when the stepper loses focus. */\n onBlur?: FocusEventHandler<HTMLDivElement>\n /** CSS classes applied to the stepper */\n className?: string\n}\n\n/** Delay before a held segment starts repeating, and the time between repeats, in ms. */\nconst REPEAT_DELAY = 400\nconst REPEAT_INTERVAL = 100\n\nconst decimals = (n: number) => {\n const [, fraction = \"\"] = String(n).split(\".\")\n return fraction.length\n}\n\n/** The value one step away, clamped to the range or wrapped, without floating point drift. */\nexport const stepValue = (current: number, direction: 1 | -1, { min, max, step, wrap }: { min: number; max: number; step: number; wrap: boolean }) => {\n const precision = Math.max(decimals(step), decimals(min), decimals(current))\n const next = Number((current + direction * step).toFixed(precision))\n if (next > max) return wrap ? min : max\n if (next < min) return wrap ? max : min\n return next\n}\n\n/**\n * Two segments that decrease and increase a number, as the iOS 26 stepper does. It shows no value of its own:\n * name it with `aria-label` or `aria-labelledby` and show the value beside it. Keyboard focus lands on the\n * stepper, a spin button: Up and Down step, Page Up and Page Down step ten times, Home and End go to the range ends.\n */\nexport function Stepper({\n id,\n value: valueProp,\n defaultValue,\n onChange,\n min = 0,\n max = 100,\n step = 1,\n wrap = false,\n autoRepeat = true,\n disabled = false,\n pill = true,\n decrementLabel = \"Decrease\",\n incrementLabel = \"Increase\",\n onRemove,\n removeLabel = \"Remove\",\n name,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-describedby\": ariaDescribedBy,\n onFocus,\n onBlur,\n className,\n}: StepperProps) {\n const [internalValue, setInternalValue] = useState(() => defaultValue ?? min)\n const value = valueProp ?? internalValue\n // Timers and key handlers read the value through this ref; an uncontrolled step advances it at once.\n const valueRef = useLatestValue(value)\n const onChangeRef = useLatestValue(onChange)\n const optionsRef = useLatestValue({ min, max, step, wrap, disabled, controlled: valueProp !== undefined })\n const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)\n const [pressed, setPressed] = useState<\"decrement\" | \"increment\" | null>(null)\n\n const commit = useCallback((next: number) => {\n if (next === valueRef.current) return false\n // A controlled value changes only when the owner passes it back, as in Vue.\n if (!optionsRef.current.controlled) {\n valueRef.current = next\n setInternalValue(next)\n }\n onChangeRef.current?.(next)\n return true\n }, [valueRef, optionsRef, onChangeRef])\n\n const stepBy = useCallback((direction: 1 | -1, times = 1) => {\n let next = valueRef.current\n for (let i = 0; i < times; i++) next = stepValue(next, direction, optionsRef.current)\n return commit(next)\n }, [commit, valueRef, optionsRef])\n\n const stopRepeat = useCallback(() => {\n clearTimeout(timer.current)\n timer.current = undefined\n setPressed(null)\n }, [])\n\n useEffect(() => stopRepeat, [stopRepeat])\n\n const atMin = !wrap && value <= min\n const atMax = !wrap && value >= max\n // At the minimum the decrement segment removes the item, when the owner can remove it\n const removes = atMin && onRemove !== undefined\n const onRemoveRef = useLatestValue(onRemove)\n\n const startPress = (segment: \"decrement\" | \"increment\", event: PointerEvent<HTMLButtonElement>) => {\n if (event.button !== 0 || disabled) return\n if (segment === \"decrement\" && removes) {\n event.currentTarget.setPointerCapture?.(event.pointerId)\n setPressed(segment)\n onRemoveRef.current?.()\n return\n }\n if (segment === \"decrement\" ? atMin : atMax) return\n event.currentTarget.setPointerCapture?.(event.pointerId)\n setPressed(segment)\n const direction = segment === \"decrement\" ? -1 : 1\n stepBy(direction)\n if (!autoRepeat) return\n const repeat = () => {\n if (optionsRef.current.disabled || !stepBy(direction)) return stopRepeat()\n timer.current = setTimeout(repeat, REPEAT_INTERVAL)\n }\n timer.current = setTimeout(repeat, REPEAT_DELAY)\n }\n\n // A pointer steps on press, so only a click without one (assistive technology, `element.click()`) steps here.\n const handleClick = (segment: \"decrement\" | \"increment\", event: MouseEvent<HTMLButtonElement>) => {\n if (event.detail !== 0 || disabled) return\n if (segment === \"decrement\" && removes) return onRemoveRef.current?.()\n stepBy(segment === \"decrement\" ? -1 : 1)\n }\n\n const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n if (disabled || event.altKey || event.ctrlKey || event.metaKey) return\n const keys: Record<string, () => void> = {\n ArrowUp: () => stepBy(1),\n ArrowDown: () => stepBy(-1),\n PageUp: () => stepBy(1, 10),\n PageDown: () => stepBy(-1, 10),\n Home: () => commit(min),\n End: () => commit(max),\n // At the minimum Delete or Backspace removes, as the trash can does; the arrows never do\n ...(removes && { Delete: () => onRemoveRef.current?.(), Backspace: () => onRemoveRef.current?.() }),\n }\n const action = keys[event.key]\n if (!action) return\n event.preventDefault()\n action()\n }\n\n const segment = (kind: \"decrement\" | \"increment\") => {\n const remove = kind === \"decrement\" && removes\n const atEnd = !remove && (kind === \"decrement\" ? atMin : atMax)\n const Icon = remove ? RemoveTrash : kind === \"decrement\" ? Minus : Plus\n return (\n <button\n type=\"button\"\n tabIndex={-1}\n aria-label={remove ? removeLabel : kind === \"decrement\" ? decrementLabel : incrementLabel}\n aria-disabled={atEnd || undefined}\n disabled={disabled}\n className={s.Segment}\n data-segment={kind}\n data-remove={remove ? \"\" : undefined}\n data-disabled={atEnd || disabled ? \"\" : undefined}\n data-pressed={pressed === kind && !disabled ? \"\" : undefined}\n // Keeps the focus where it is, as a native stepper takes none.\n onMouseDown={(event) => event.preventDefault()}\n onPointerDown={(event) => startPress(kind, event)}\n onPointerUp={stopRepeat}\n onPointerCancel={stopRepeat}\n onLostPointerCapture={stopRepeat}\n onClick={(event) => handleClick(kind, event)}\n >\n <Icon className={s.Icon} />\n </button>\n )\n }\n\n return (\n <div\n id={id}\n role=\"spinbutton\"\n tabIndex={disabled ? -1 : 0}\n aria-valuenow={value}\n aria-valuemin={min}\n aria-valuemax={max}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n aria-describedby={ariaDescribedBy}\n aria-keyshortcuts={removes ? \"Delete\" : undefined}\n aria-disabled={disabled || undefined}\n className={clsx(s.Stepper, className)}\n data-disabled={disabled ? \"\" : undefined}\n data-pill={pill ? \"\" : undefined}\n onKeyDown={handleKeyDown}\n onFocus={onFocus}\n onBlur={onBlur}\n >\n {segment(\"decrement\")}\n <span className={s.Separator} aria-hidden=\"true\" />\n {segment(\"increment\")}\n {name !== undefined && <input type=\"hidden\" name={name} value={value} disabled={disabled} />}\n </div>\n )\n}\n"]}
|
|
@@ -12,8 +12,8 @@ export type ColorWellProps = Omit<ColorPickerProps, "value" | "defaultValue" | "
|
|
|
12
12
|
title?: string;
|
|
13
13
|
/** Shows the eyedropper in the picker where the browser can pick a color from the screen (EyeDropper API). @default true */
|
|
14
14
|
supportsEyedropper?: boolean;
|
|
15
|
-
/** The kit's Picker Button sizes
|
|
16
|
-
size?: "sm" | "lg";
|
|
15
|
+
/** The kit's Picker Button sizes, `sm` 28px and `lg` 36px, and `xs` 24px for the start of a 32px field. @default "sm" */
|
|
16
|
+
size?: "xs" | "sm" | "lg";
|
|
17
17
|
/** When `true`, prevents the user from opening the picker. */
|
|
18
18
|
disabled?: boolean;
|
|
19
19
|
/** The name of the well. Submits its color with the owning form. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type AnchorHTMLAttributes, type ButtonHTMLAttributes, type ComponentType, type ReactNode, type Ref } from "react";
|
|
2
2
|
type LinkAttributes = Pick<AnchorHTMLAttributes<HTMLAnchorElement>, "target" | "rel" | "download" | "hrefLang" | "ping" | "referrerPolicy">;
|
|
3
3
|
export type NavigationRowProps = Omit<ButtonHTMLAttributes<HTMLButtonElement | HTMLAnchorElement>, "children" | "value" | "type"> & LinkAttributes & {
|
|
4
4
|
/** The row's name, where a row's label starts */
|
|
@@ -15,6 +15,11 @@ export type NavigationRowProps = Omit<ButtonHTMLAttributes<HTMLButtonElement | H
|
|
|
15
15
|
as?: ComponentType<any> | "a";
|
|
16
16
|
/** The row can't be pressed. A disabled link renders as a disabled button, so it never navigates. */
|
|
17
17
|
disabled?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Where the value stands: at the `end` of the row, `below` the label at the full width, or `auto`: at the end while
|
|
20
|
+
* it fits beside the label on one line, otherwise below (as Calendar sets a long value). @default "end"
|
|
21
|
+
*/
|
|
22
|
+
valuePlacement?: "end" | "below" | "auto";
|
|
18
23
|
/** Ref for the row's pressable (a `button`, or the link's element) */
|
|
19
24
|
ref?: Ref<HTMLButtonElement | HTMLAnchorElement | null>;
|
|
20
25
|
};
|
|
@@ -26,6 +26,13 @@ export type StepperProps = {
|
|
|
26
26
|
decrementLabel?: string;
|
|
27
27
|
/** Accessible name of the increment segment. @default "Increase" */
|
|
28
28
|
incrementLabel?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Called when the decrement segment is pressed at `min`. With it, the segment shows a trash can there and removes
|
|
31
|
+
* the item, as a cart's stepper does at a quantity of one (without `wrap`).
|
|
32
|
+
*/
|
|
33
|
+
onRemove?: () => void;
|
|
34
|
+
/** Accessible name of the decrement segment when it removes. @default "Remove" */
|
|
35
|
+
removeLabel?: string;
|
|
29
36
|
/** The name of the stepper. Submits its value with the owning form. */
|
|
30
37
|
name?: string;
|
|
31
38
|
/** Accessible name of the value the stepper changes, when no visible label names it. */
|
|
@@ -53,4 +60,4 @@ export declare const stepValue: (current: number, direction: 1 | -1, { min, max,
|
|
|
53
60
|
* name it with `aria-label` or `aria-labelledby` and show the value beside it. Keyboard focus lands on the
|
|
54
61
|
* stepper, a spin button: Up and Down step, Page Up and Page Down step ten times, Home and End go to the range ends.
|
|
55
62
|
*/
|
|
56
|
-
export declare function Stepper({ id, value: valueProp, defaultValue, onChange, min, max, step, wrap, autoRepeat, disabled, pill, decrementLabel, incrementLabel, name, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, onFocus, onBlur, className, }: StepperProps): import("react/jsx-runtime").JSX.Element;
|
|
63
|
+
export declare function Stepper({ id, value: valueProp, defaultValue, onChange, min, max, step, wrap, autoRepeat, disabled, pill, decrementLabel, incrementLabel, onRemove, removeLabel, name, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, onFocus, onBlur, className, }: StepperProps): import("react/jsx-runtime").JSX.Element;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plexui/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.56.0",
|
|
4
4
|
"description": "Modern design system for building high-quality applications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -99,7 +99,7 @@
|
|
|
99
99
|
"@maskito/core": "^5.2.2",
|
|
100
100
|
"@maskito/kit": "^5.2.2",
|
|
101
101
|
"@maskito/react": "^5.2.2",
|
|
102
|
-
"@plexui/styles": "^0.
|
|
102
|
+
"@plexui/styles": "^0.14.0",
|
|
103
103
|
"@radix-ui/react-dismissable-layer": "1.2.1",
|
|
104
104
|
"@radix-ui/react-focus-guards": "1.2.0",
|
|
105
105
|
"@radix-ui/react-focus-scope": "1.3.1",
|