magic-pill 9.0.0 → 9.1.1
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 +50 -0
- package/README.md +259 -15
- package/dist/MagicPill/MagicPill.d.mts +7 -1
- package/dist/MagicPill/MagicPill.d.ts +7 -1
- package/dist/MagicPill/MagicPill.js +40 -17
- package/dist/MagicPill/MagicPill.mjs +42 -19
- package/dist/MagicPill/choreography.js +1 -1
- package/dist/MagicPill/choreography.mjs +1 -1
- package/dist/Pill/Pill.js +53 -17
- package/dist/Pill/Pill.mjs +54 -18
- package/dist/Pill/PillContext.js +3 -1
- package/dist/Pill/PillContext.mjs +3 -1
- package/dist/Pill/PillPanel.d.mts +5 -5
- package/dist/Pill/PillPanel.d.ts +5 -5
- package/dist/Pill/PillPanel.js +28 -20
- package/dist/Pill/PillPanel.mjs +28 -20
- package/dist/Pill/morph.js +25 -7
- package/dist/Pill/morph.mjs +22 -8
- package/dist/Pill/scene.js +90 -0
- package/dist/Pill/scene.mjs +89 -0
- package/dist/Pill/themed.js +36 -0
- package/dist/Pill/themed.mjs +34 -0
- package/dist/Pill/types.d.mts +50 -0
- package/dist/Pill/types.d.ts +50 -0
- package/dist/Pill/zone.js +160 -0
- package/dist/Pill/zone.mjs +159 -0
- package/dist/PillForm/Calendar.d.mts +15 -0
- package/dist/PillForm/Calendar.d.ts +16 -0
- package/dist/PillForm/Calendar.js +371 -0
- package/dist/PillForm/Calendar.mjs +370 -0
- package/dist/PillForm/FormContext.d.mts +2 -0
- package/dist/PillForm/FormContext.d.ts +2 -0
- package/dist/PillForm/FormContext.js +8 -0
- package/dist/PillForm/FormContext.mjs +8 -0
- package/dist/PillForm/PillCheckbox.d.mts +8 -0
- package/dist/PillForm/PillCheckbox.d.ts +8 -0
- package/dist/PillForm/PillCheckbox.js +45 -0
- package/dist/PillForm/PillCheckbox.mjs +45 -0
- package/dist/PillForm/PillChoices.d.mts +39 -0
- package/dist/PillForm/PillChoices.d.ts +39 -0
- package/dist/PillForm/PillChoices.js +103 -0
- package/dist/PillForm/PillChoices.mjs +103 -0
- package/dist/PillForm/PillCode.d.mts +12 -0
- package/dist/PillForm/PillCode.d.ts +12 -0
- package/dist/PillForm/PillCode.js +60 -0
- package/dist/PillForm/PillCode.mjs +60 -0
- package/dist/PillForm/PillColor.d.mts +10 -0
- package/dist/PillForm/PillColor.d.ts +10 -0
- package/dist/PillForm/PillColor.js +56 -0
- package/dist/PillForm/PillColor.mjs +56 -0
- package/dist/PillForm/PillDate.d.mts +44 -0
- package/dist/PillForm/PillDate.d.ts +44 -0
- package/dist/PillForm/PillDate.js +193 -0
- package/dist/PillForm/PillDate.mjs +193 -0
- package/dist/PillForm/PillField.d.mts +38 -0
- package/dist/PillForm/PillField.d.ts +38 -0
- package/dist/PillForm/PillField.js +81 -0
- package/dist/PillForm/PillField.mjs +80 -0
- package/dist/PillForm/PillFields.d.mts +11 -0
- package/dist/PillForm/PillFields.d.ts +11 -0
- package/dist/PillForm/PillFields.js +21 -0
- package/dist/PillForm/PillFields.mjs +21 -0
- package/dist/PillForm/PillFile.d.mts +8 -0
- package/dist/PillForm/PillFile.d.ts +8 -0
- package/dist/PillForm/PillFile.js +55 -0
- package/dist/PillForm/PillFile.mjs +55 -0
- package/dist/PillForm/PillForm.d.mts +29 -0
- package/dist/PillForm/PillForm.d.ts +29 -0
- package/dist/PillForm/PillForm.js +66 -0
- package/dist/PillForm/PillForm.mjs +65 -0
- package/dist/PillForm/PillFormPanel.d.mts +24 -0
- package/dist/PillForm/PillFormPanel.d.ts +24 -0
- package/dist/PillForm/PillFormPanel.js +53 -0
- package/dist/PillForm/PillFormPanel.mjs +53 -0
- package/dist/PillForm/PillInput.d.mts +20 -0
- package/dist/PillForm/PillInput.d.ts +20 -0
- package/dist/PillForm/PillInput.js +84 -0
- package/dist/PillForm/PillInput.mjs +84 -0
- package/dist/PillForm/PillSelect.d.mts +23 -0
- package/dist/PillForm/PillSelect.d.ts +23 -0
- package/dist/PillForm/PillSelect.js +87 -0
- package/dist/PillForm/PillSelect.mjs +87 -0
- package/dist/PillForm/PillSlider.d.mts +17 -0
- package/dist/PillForm/PillSlider.d.ts +17 -0
- package/dist/PillForm/PillSlider.js +61 -0
- package/dist/PillForm/PillSlider.mjs +61 -0
- package/dist/PillForm/PillStepper.d.mts +13 -0
- package/dist/PillForm/PillStepper.d.ts +13 -0
- package/dist/PillForm/PillStepper.js +84 -0
- package/dist/PillForm/PillStepper.mjs +84 -0
- package/dist/PillForm/PillSubmit.d.mts +14 -0
- package/dist/PillForm/PillSubmit.d.ts +14 -0
- package/dist/PillForm/PillSubmit.js +90 -0
- package/dist/PillForm/PillSubmit.mjs +89 -0
- package/dist/PillForm/PillSwitch.d.mts +5 -0
- package/dist/PillForm/PillSwitch.d.ts +5 -0
- package/dist/PillForm/PillSwitch.js +38 -0
- package/dist/PillForm/PillSwitch.mjs +38 -0
- package/dist/PillForm/PillTextarea.d.mts +5 -0
- package/dist/PillForm/PillTextarea.d.ts +5 -0
- package/dist/PillForm/PillTextarea.js +49 -0
- package/dist/PillForm/PillTextarea.mjs +49 -0
- package/dist/PillForm/dates.d.mts +1 -0
- package/dist/PillForm/dates.d.ts +1 -0
- package/dist/PillForm/dates.js +155 -0
- package/dist/PillForm/dates.mjs +139 -0
- package/dist/PillForm/glyphs.js +65 -0
- package/dist/PillForm/glyphs.mjs +56 -0
- package/dist/PillForm/keyboard.js +34 -0
- package/dist/PillForm/keyboard.mjs +34 -0
- package/dist/PillForm/popover.js +84 -0
- package/dist/PillForm/popover.mjs +83 -0
- package/dist/PillForm/send.d.mts +6 -0
- package/dist/PillForm/send.d.ts +6 -0
- package/dist/PillForm/send.js +44 -0
- package/dist/PillForm/send.mjs +44 -0
- package/dist/PillForm/validity.js +74 -0
- package/dist/PillForm/validity.mjs +72 -0
- package/dist/PillNavbar/PillNavbar.d.mts +29 -6
- package/dist/PillNavbar/PillNavbar.d.ts +29 -6
- package/dist/PillNavbar/PillNavbar.js +35 -11
- package/dist/PillNavbar/PillNavbar.mjs +36 -12
- package/dist/PillNavbar/room.js +84 -0
- package/dist/PillNavbar/room.mjs +83 -0
- package/dist/PillNotification/PillNotification.d.mts +6 -0
- package/dist/PillNotification/PillNotification.d.ts +6 -0
- package/dist/PillNotification/PillNotification.js +3 -0
- package/dist/PillNotification/PillNotification.mjs +3 -0
- package/dist/PillOptics/PillOptics.d.mts +8 -0
- package/dist/PillOptics/PillOptics.d.ts +8 -0
- package/dist/PillOptics/PillOptics.js +195 -0
- package/dist/PillOptics/PillOptics.mjs +195 -0
- package/dist/PillOptics/adaptive.js +212 -0
- package/dist/PillOptics/adaptive.mjs +208 -0
- package/dist/PillOptics/lens.js +77 -0
- package/dist/PillOptics/lens.mjs +73 -0
- package/dist/PillOptics/light.js +37 -0
- package/dist/PillOptics/light.mjs +36 -0
- package/dist/calendar.css +499 -0
- package/dist/forms.css +1454 -0
- package/dist/index.d.mts +24 -3
- package/dist/index.d.ts +24 -3
- package/dist/index.js +36 -0
- package/dist/index.mjs +19 -1
- package/dist/styles.css +169 -19
- package/dist/themes.css +449 -0
- package/dist/utils/visuallyHidden.js +18 -0
- package/dist/utils/visuallyHidden.mjs +18 -0
- package/package.json +4 -1
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { forwardRef, useId, useMemo, useRef, useState } from "react";
|
|
4
|
+
import { FieldShell } from "./PillField.mjs";
|
|
5
|
+
import { both, useValidity } from "./validity.mjs";
|
|
6
|
+
import { CalendarGlyph, ClockGlyph, EyeGlyph, SearchGlyph } from "./glyphs.mjs";
|
|
7
|
+
import { mergeRefs } from "../utils/react.mjs";
|
|
8
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
|
|
10
|
+
// src/PillForm/PillInput.tsx
|
|
11
|
+
/** The sign of what the browser opens */
|
|
12
|
+
const PICKERS = {
|
|
13
|
+
date: CalendarGlyph,
|
|
14
|
+
"datetime-local": CalendarGlyph,
|
|
15
|
+
month: CalendarGlyph,
|
|
16
|
+
week: CalendarGlyph,
|
|
17
|
+
time: ClockGlyph
|
|
18
|
+
};
|
|
19
|
+
/** A line of text, a number or a date. Any other prop goes to the native `<input>`. */
|
|
20
|
+
const PillInput = forwardRef(function PillInput({ label, hideLabel, hint, error, optional, layout, type = "text", icon, suffix, suggestions, revealLabel = "Show the password", className, onInput, onBlur, onInvalid, ...rest }, forwardedRef) {
|
|
21
|
+
const inputRef = useRef(null);
|
|
22
|
+
const ref = useMemo(() => mergeRefs(inputRef, forwardedRef), [forwardedRef]);
|
|
23
|
+
const validity = useValidity(error, inputRef);
|
|
24
|
+
const [isRevealed, setIsRevealed] = useState(false);
|
|
25
|
+
const listId = useId();
|
|
26
|
+
const PickerGlyph = PICKERS[type];
|
|
27
|
+
const leading = icon ?? (type === "search" ? /* @__PURE__ */ jsx(SearchGlyph, {}) : void 0);
|
|
28
|
+
return /* @__PURE__ */ jsx(FieldShell, {
|
|
29
|
+
label,
|
|
30
|
+
hideLabel,
|
|
31
|
+
hint,
|
|
32
|
+
optional,
|
|
33
|
+
layout,
|
|
34
|
+
className,
|
|
35
|
+
error: validity.error,
|
|
36
|
+
isText: true,
|
|
37
|
+
"data-kind": "text",
|
|
38
|
+
children: (control) => /* @__PURE__ */ jsxs("div", {
|
|
39
|
+
"data-mp": "field-box",
|
|
40
|
+
"data-type": type,
|
|
41
|
+
children: [
|
|
42
|
+
leading && /* @__PURE__ */ jsx("span", {
|
|
43
|
+
"data-mp": "field-icon",
|
|
44
|
+
"aria-hidden": "true",
|
|
45
|
+
children: leading
|
|
46
|
+
}),
|
|
47
|
+
/* @__PURE__ */ jsx("input", {
|
|
48
|
+
...rest,
|
|
49
|
+
...control,
|
|
50
|
+
ref,
|
|
51
|
+
type: type === "password" && isRevealed ? "text" : type,
|
|
52
|
+
list: suggestions ? listId : rest.list,
|
|
53
|
+
onInput: both(validity.handlers.onInput, onInput),
|
|
54
|
+
onBlur: both(validity.handlers.onBlur, onBlur),
|
|
55
|
+
onInvalid: both(validity.handlers.onInvalid, onInvalid)
|
|
56
|
+
}),
|
|
57
|
+
suffix && /* @__PURE__ */ jsx("span", {
|
|
58
|
+
"data-mp": "field-suffix",
|
|
59
|
+
children: suffix
|
|
60
|
+
}),
|
|
61
|
+
PickerGlyph && /* @__PURE__ */ jsx("span", {
|
|
62
|
+
"data-mp": "field-icon",
|
|
63
|
+
"aria-hidden": "true",
|
|
64
|
+
children: /* @__PURE__ */ jsx(PickerGlyph, {})
|
|
65
|
+
}),
|
|
66
|
+
type === "password" && /* @__PURE__ */ jsx("button", {
|
|
67
|
+
type: "button",
|
|
68
|
+
"data-mp": "field-button",
|
|
69
|
+
"aria-label": revealLabel,
|
|
70
|
+
"aria-pressed": isRevealed,
|
|
71
|
+
disabled: rest.disabled,
|
|
72
|
+
onClick: () => setIsRevealed(!isRevealed),
|
|
73
|
+
children: /* @__PURE__ */ jsx(EyeGlyph, { crossed: isRevealed })
|
|
74
|
+
}),
|
|
75
|
+
suggestions && /* @__PURE__ */ jsx("datalist", {
|
|
76
|
+
id: listId,
|
|
77
|
+
children: suggestions.map((suggestion) => /* @__PURE__ */ jsx("option", { value: suggestion }, suggestion))
|
|
78
|
+
})
|
|
79
|
+
]
|
|
80
|
+
})
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
export { PillInput };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ComponentPropsWithoutRef, ReactNode } from "react";
|
|
2
|
+
import { FieldProps } from "./PillField.mjs";
|
|
3
|
+
import { FieldLayout } from "./FormContext.mjs";
|
|
4
|
+
export interface PillOption {
|
|
5
|
+
value: string;
|
|
6
|
+
label: string;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface PillOptionGroup {
|
|
10
|
+
label: string;
|
|
11
|
+
options: readonly (string | PillOption)[];
|
|
12
|
+
}
|
|
13
|
+
export interface PillSelectProps extends FieldProps, Omit<ComponentPropsWithoutRef<"select">, "children" | "multiple" | "size"> {
|
|
14
|
+
/** A string is both the value and the label. */
|
|
15
|
+
options: readonly (string | PillOption | PillOptionGroup)[];
|
|
16
|
+
/** Shown while nothing is chosen. */
|
|
17
|
+
placeholder?: string;
|
|
18
|
+
/** Under its label (default), or a chip at the end of the row. */
|
|
19
|
+
layout?: FieldLayout;
|
|
20
|
+
icon?: ReactNode;
|
|
21
|
+
}
|
|
22
|
+
/** One of several options, in a native `<select>`. Any other prop goes to it. */
|
|
23
|
+
export declare const PillSelect: import("react").ForwardRefExoticComponent<PillSelectProps & import("react").RefAttributes<HTMLSelectElement>>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ComponentPropsWithoutRef, ReactNode } from "react";
|
|
2
|
+
import { FieldProps } from "./PillField.js";
|
|
3
|
+
import { FieldLayout } from "./FormContext.js";
|
|
4
|
+
export interface PillOption {
|
|
5
|
+
value: string;
|
|
6
|
+
label: string;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface PillOptionGroup {
|
|
10
|
+
label: string;
|
|
11
|
+
options: readonly (string | PillOption)[];
|
|
12
|
+
}
|
|
13
|
+
export interface PillSelectProps extends FieldProps, Omit<ComponentPropsWithoutRef<"select">, "children" | "multiple" | "size"> {
|
|
14
|
+
/** A string is both the value and the label. */
|
|
15
|
+
options: readonly (string | PillOption | PillOptionGroup)[];
|
|
16
|
+
/** Shown while nothing is chosen. */
|
|
17
|
+
placeholder?: string;
|
|
18
|
+
/** Under its label (default), or a chip at the end of the row. */
|
|
19
|
+
layout?: FieldLayout;
|
|
20
|
+
icon?: ReactNode;
|
|
21
|
+
}
|
|
22
|
+
/** One of several options, in a native `<select>`. Any other prop goes to it. */
|
|
23
|
+
export declare const PillSelect: import("react").ForwardRefExoticComponent<PillSelectProps & import("react").RefAttributes<HTMLSelectElement>>;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
let react = require("react");
|
|
4
|
+
const require_PillField = require("./PillField.js");
|
|
5
|
+
const require_glyphs = require("./glyphs.js");
|
|
6
|
+
const require_validity = require("./validity.js");
|
|
7
|
+
const require_react = require("../utils/react.js");
|
|
8
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
9
|
+
|
|
10
|
+
// src/PillForm/PillSelect.tsx
|
|
11
|
+
const renderOption = (option) => {
|
|
12
|
+
if (typeof option === "string") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
13
|
+
value: option,
|
|
14
|
+
children: option
|
|
15
|
+
}, option);
|
|
16
|
+
if ("options" in option) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("optgroup", {
|
|
17
|
+
label: option.label,
|
|
18
|
+
children: option.options.map(renderOption)
|
|
19
|
+
}, option.label);
|
|
20
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
21
|
+
value: option.value,
|
|
22
|
+
disabled: option.disabled,
|
|
23
|
+
children: option.label
|
|
24
|
+
}, option.value);
|
|
25
|
+
};
|
|
26
|
+
const isOpen = (select) => {
|
|
27
|
+
try {
|
|
28
|
+
return select.matches(":open");
|
|
29
|
+
} catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
/** One of several options, in a native `<select>`. Any other prop goes to it. */
|
|
34
|
+
const PillSelect = (0, react.forwardRef)(function PillSelect({ label, hideLabel, hint, error, optional, layout = "stacked", options, placeholder, icon, className, onInput, onBlur, onInvalid, onKeyDown, ...rest }, forwardedRef) {
|
|
35
|
+
const selectRef = (0, react.useRef)(null);
|
|
36
|
+
const ref = (0, react.useMemo)(() => require_react.mergeRefs(selectRef, forwardedRef), [forwardedRef]);
|
|
37
|
+
const validity = require_validity.useValidity(error, selectRef);
|
|
38
|
+
const startsEmpty = placeholder !== void 0 && rest.value === void 0 && rest.defaultValue === void 0;
|
|
39
|
+
const handleKeyDown = (event) => {
|
|
40
|
+
onKeyDown?.(event);
|
|
41
|
+
if (event.key === "Escape" && isOpen(event.currentTarget)) event.stopPropagation();
|
|
42
|
+
};
|
|
43
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PillField.FieldShell, {
|
|
44
|
+
label,
|
|
45
|
+
hideLabel,
|
|
46
|
+
hint,
|
|
47
|
+
optional,
|
|
48
|
+
layout,
|
|
49
|
+
className,
|
|
50
|
+
error: validity.error,
|
|
51
|
+
"data-kind": "select",
|
|
52
|
+
children: (control) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
53
|
+
"data-mp": "field-box",
|
|
54
|
+
"data-type": "select",
|
|
55
|
+
children: [
|
|
56
|
+
icon && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
57
|
+
"data-mp": "field-icon",
|
|
58
|
+
"aria-hidden": "true",
|
|
59
|
+
children: icon
|
|
60
|
+
}),
|
|
61
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("select", {
|
|
62
|
+
...rest,
|
|
63
|
+
...startsEmpty && { defaultValue: "" },
|
|
64
|
+
...control,
|
|
65
|
+
ref,
|
|
66
|
+
onInput: require_validity.both(validity.handlers.onInput, onInput),
|
|
67
|
+
onBlur: require_validity.both(validity.handlers.onBlur, onBlur),
|
|
68
|
+
onInvalid: require_validity.both(validity.handlers.onInvalid, onInvalid),
|
|
69
|
+
onKeyDown: handleKeyDown,
|
|
70
|
+
children: [placeholder !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
71
|
+
value: "",
|
|
72
|
+
disabled: true,
|
|
73
|
+
hidden: true,
|
|
74
|
+
children: placeholder
|
|
75
|
+
}), options.map(renderOption)]
|
|
76
|
+
}),
|
|
77
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
78
|
+
"data-mp": "field-chevron",
|
|
79
|
+
"aria-hidden": "true",
|
|
80
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_glyphs.ChevronGlyph, {})
|
|
81
|
+
})
|
|
82
|
+
]
|
|
83
|
+
})
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
exports.PillSelect = PillSelect;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { forwardRef, useMemo, useRef } from "react";
|
|
4
|
+
import { FieldShell } from "./PillField.mjs";
|
|
5
|
+
import { ChevronGlyph } from "./glyphs.mjs";
|
|
6
|
+
import { both, useValidity } from "./validity.mjs";
|
|
7
|
+
import { mergeRefs } from "../utils/react.mjs";
|
|
8
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
|
|
10
|
+
// src/PillForm/PillSelect.tsx
|
|
11
|
+
const renderOption = (option) => {
|
|
12
|
+
if (typeof option === "string") return /* @__PURE__ */ jsx("option", {
|
|
13
|
+
value: option,
|
|
14
|
+
children: option
|
|
15
|
+
}, option);
|
|
16
|
+
if ("options" in option) return /* @__PURE__ */ jsx("optgroup", {
|
|
17
|
+
label: option.label,
|
|
18
|
+
children: option.options.map(renderOption)
|
|
19
|
+
}, option.label);
|
|
20
|
+
return /* @__PURE__ */ jsx("option", {
|
|
21
|
+
value: option.value,
|
|
22
|
+
disabled: option.disabled,
|
|
23
|
+
children: option.label
|
|
24
|
+
}, option.value);
|
|
25
|
+
};
|
|
26
|
+
const isOpen = (select) => {
|
|
27
|
+
try {
|
|
28
|
+
return select.matches(":open");
|
|
29
|
+
} catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
/** One of several options, in a native `<select>`. Any other prop goes to it. */
|
|
34
|
+
const PillSelect = forwardRef(function PillSelect({ label, hideLabel, hint, error, optional, layout = "stacked", options, placeholder, icon, className, onInput, onBlur, onInvalid, onKeyDown, ...rest }, forwardedRef) {
|
|
35
|
+
const selectRef = useRef(null);
|
|
36
|
+
const ref = useMemo(() => mergeRefs(selectRef, forwardedRef), [forwardedRef]);
|
|
37
|
+
const validity = useValidity(error, selectRef);
|
|
38
|
+
const startsEmpty = placeholder !== void 0 && rest.value === void 0 && rest.defaultValue === void 0;
|
|
39
|
+
const handleKeyDown = (event) => {
|
|
40
|
+
onKeyDown?.(event);
|
|
41
|
+
if (event.key === "Escape" && isOpen(event.currentTarget)) event.stopPropagation();
|
|
42
|
+
};
|
|
43
|
+
return /* @__PURE__ */ jsx(FieldShell, {
|
|
44
|
+
label,
|
|
45
|
+
hideLabel,
|
|
46
|
+
hint,
|
|
47
|
+
optional,
|
|
48
|
+
layout,
|
|
49
|
+
className,
|
|
50
|
+
error: validity.error,
|
|
51
|
+
"data-kind": "select",
|
|
52
|
+
children: (control) => /* @__PURE__ */ jsxs("div", {
|
|
53
|
+
"data-mp": "field-box",
|
|
54
|
+
"data-type": "select",
|
|
55
|
+
children: [
|
|
56
|
+
icon && /* @__PURE__ */ jsx("span", {
|
|
57
|
+
"data-mp": "field-icon",
|
|
58
|
+
"aria-hidden": "true",
|
|
59
|
+
children: icon
|
|
60
|
+
}),
|
|
61
|
+
/* @__PURE__ */ jsxs("select", {
|
|
62
|
+
...rest,
|
|
63
|
+
...startsEmpty && { defaultValue: "" },
|
|
64
|
+
...control,
|
|
65
|
+
ref,
|
|
66
|
+
onInput: both(validity.handlers.onInput, onInput),
|
|
67
|
+
onBlur: both(validity.handlers.onBlur, onBlur),
|
|
68
|
+
onInvalid: both(validity.handlers.onInvalid, onInvalid),
|
|
69
|
+
onKeyDown: handleKeyDown,
|
|
70
|
+
children: [placeholder !== void 0 && /* @__PURE__ */ jsx("option", {
|
|
71
|
+
value: "",
|
|
72
|
+
disabled: true,
|
|
73
|
+
hidden: true,
|
|
74
|
+
children: placeholder
|
|
75
|
+
}), options.map(renderOption)]
|
|
76
|
+
}),
|
|
77
|
+
/* @__PURE__ */ jsx("span", {
|
|
78
|
+
"data-mp": "field-chevron",
|
|
79
|
+
"aria-hidden": "true",
|
|
80
|
+
children: /* @__PURE__ */ jsx(ChevronGlyph, {})
|
|
81
|
+
})
|
|
82
|
+
]
|
|
83
|
+
})
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
export { PillSelect };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ComponentPropsWithoutRef } from "react";
|
|
2
|
+
import { FieldProps } from "./PillField.mjs";
|
|
3
|
+
export interface PillSliderProps extends Omit<FieldProps, "optional">, Omit<ComponentPropsWithoutRef<"input">, "type" | "children" | "min" | "max" | "step" | "value" | "defaultValue"> {
|
|
4
|
+
/** Default 0. */
|
|
5
|
+
min?: number;
|
|
6
|
+
/** Default 100. */
|
|
7
|
+
max?: number;
|
|
8
|
+
/** Default 1. */
|
|
9
|
+
step?: number | "any";
|
|
10
|
+
value?: number;
|
|
11
|
+
/** Default: halfway. */
|
|
12
|
+
defaultValue?: number;
|
|
13
|
+
/** How its value reads, e.g. `(minutes) => `${minutes} min``. */
|
|
14
|
+
format?: (value: number) => string;
|
|
15
|
+
}
|
|
16
|
+
/** A value between two others, on a native range input. */
|
|
17
|
+
export declare const PillSlider: import("react").ForwardRefExoticComponent<PillSliderProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ComponentPropsWithoutRef } from "react";
|
|
2
|
+
import { FieldProps } from "./PillField.js";
|
|
3
|
+
export interface PillSliderProps extends Omit<FieldProps, "optional">, Omit<ComponentPropsWithoutRef<"input">, "type" | "children" | "min" | "max" | "step" | "value" | "defaultValue"> {
|
|
4
|
+
/** Default 0. */
|
|
5
|
+
min?: number;
|
|
6
|
+
/** Default 100. */
|
|
7
|
+
max?: number;
|
|
8
|
+
/** Default 1. */
|
|
9
|
+
step?: number | "any";
|
|
10
|
+
value?: number;
|
|
11
|
+
/** Default: halfway. */
|
|
12
|
+
defaultValue?: number;
|
|
13
|
+
/** How its value reads, e.g. `(minutes) => `${minutes} min``. */
|
|
14
|
+
format?: (value: number) => string;
|
|
15
|
+
}
|
|
16
|
+
/** A value between two others, on a native range input. */
|
|
17
|
+
export declare const PillSlider: import("react").ForwardRefExoticComponent<PillSliderProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
let react = require("react");
|
|
4
|
+
const require_PillField = require("./PillField.js");
|
|
5
|
+
const require_validity = require("./validity.js");
|
|
6
|
+
const require_react = require("../utils/react.js");
|
|
7
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
8
|
+
|
|
9
|
+
// src/PillForm/PillSlider.tsx
|
|
10
|
+
/** A value between two others, on a native range input. */
|
|
11
|
+
const PillSlider = (0, react.forwardRef)(function PillSlider({ label, hideLabel, hint, error, min = 0, max = 100, step = 1, value, defaultValue = (min + max) / 2, format = String, className, onChange, ...rest }, forwardedRef) {
|
|
12
|
+
const inputRef = (0, react.useRef)(null);
|
|
13
|
+
const ref = (0, react.useMemo)(() => require_react.mergeRefs(inputRef, forwardedRef), [forwardedRef]);
|
|
14
|
+
const [ownValue, setOwnValue] = (0, react.useState)(defaultValue);
|
|
15
|
+
require_validity.useFormReset(inputRef, () => setOwnValue(Number(inputRef.current?.value)));
|
|
16
|
+
const shown = value ?? ownValue;
|
|
17
|
+
const text = format(shown);
|
|
18
|
+
const position = max > min ? Math.min(1, Math.max(0, (shown - min) / (max - min))) : 0;
|
|
19
|
+
const handleChange = (event) => {
|
|
20
|
+
setOwnValue(Number(event.currentTarget.value));
|
|
21
|
+
onChange?.(event);
|
|
22
|
+
};
|
|
23
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PillField.FieldShell, {
|
|
24
|
+
label,
|
|
25
|
+
hideLabel,
|
|
26
|
+
hint,
|
|
27
|
+
error,
|
|
28
|
+
className,
|
|
29
|
+
aside: text,
|
|
30
|
+
"data-kind": "slider",
|
|
31
|
+
children: (control) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
32
|
+
"data-mp": "field-control",
|
|
33
|
+
"data-type": "slider",
|
|
34
|
+
style: { "--_mp-at": position },
|
|
35
|
+
children: [
|
|
36
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
37
|
+
...rest,
|
|
38
|
+
...control,
|
|
39
|
+
ref,
|
|
40
|
+
type: "range",
|
|
41
|
+
min,
|
|
42
|
+
max,
|
|
43
|
+
step,
|
|
44
|
+
...value === void 0 ? { defaultValue } : { value },
|
|
45
|
+
"aria-valuetext": text,
|
|
46
|
+
onChange: handleChange
|
|
47
|
+
}),
|
|
48
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
49
|
+
"data-mp": "slider-track",
|
|
50
|
+
"aria-hidden": "true"
|
|
51
|
+
}),
|
|
52
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
53
|
+
"data-mp": "slider-thumb",
|
|
54
|
+
"aria-hidden": "true"
|
|
55
|
+
})
|
|
56
|
+
]
|
|
57
|
+
})
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
exports.PillSlider = PillSlider;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { forwardRef, useMemo, useRef, useState } from "react";
|
|
4
|
+
import { FieldShell } from "./PillField.mjs";
|
|
5
|
+
import { useFormReset } from "./validity.mjs";
|
|
6
|
+
import { mergeRefs } from "../utils/react.mjs";
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
|
|
9
|
+
// src/PillForm/PillSlider.tsx
|
|
10
|
+
/** A value between two others, on a native range input. */
|
|
11
|
+
const PillSlider = forwardRef(function PillSlider({ label, hideLabel, hint, error, min = 0, max = 100, step = 1, value, defaultValue = (min + max) / 2, format = String, className, onChange, ...rest }, forwardedRef) {
|
|
12
|
+
const inputRef = useRef(null);
|
|
13
|
+
const ref = useMemo(() => mergeRefs(inputRef, forwardedRef), [forwardedRef]);
|
|
14
|
+
const [ownValue, setOwnValue] = useState(defaultValue);
|
|
15
|
+
useFormReset(inputRef, () => setOwnValue(Number(inputRef.current?.value)));
|
|
16
|
+
const shown = value ?? ownValue;
|
|
17
|
+
const text = format(shown);
|
|
18
|
+
const position = max > min ? Math.min(1, Math.max(0, (shown - min) / (max - min))) : 0;
|
|
19
|
+
const handleChange = (event) => {
|
|
20
|
+
setOwnValue(Number(event.currentTarget.value));
|
|
21
|
+
onChange?.(event);
|
|
22
|
+
};
|
|
23
|
+
return /* @__PURE__ */ jsx(FieldShell, {
|
|
24
|
+
label,
|
|
25
|
+
hideLabel,
|
|
26
|
+
hint,
|
|
27
|
+
error,
|
|
28
|
+
className,
|
|
29
|
+
aside: text,
|
|
30
|
+
"data-kind": "slider",
|
|
31
|
+
children: (control) => /* @__PURE__ */ jsxs("div", {
|
|
32
|
+
"data-mp": "field-control",
|
|
33
|
+
"data-type": "slider",
|
|
34
|
+
style: { "--_mp-at": position },
|
|
35
|
+
children: [
|
|
36
|
+
/* @__PURE__ */ jsx("input", {
|
|
37
|
+
...rest,
|
|
38
|
+
...control,
|
|
39
|
+
ref,
|
|
40
|
+
type: "range",
|
|
41
|
+
min,
|
|
42
|
+
max,
|
|
43
|
+
step,
|
|
44
|
+
...value === void 0 ? { defaultValue } : { value },
|
|
45
|
+
"aria-valuetext": text,
|
|
46
|
+
onChange: handleChange
|
|
47
|
+
}),
|
|
48
|
+
/* @__PURE__ */ jsx("span", {
|
|
49
|
+
"data-mp": "slider-track",
|
|
50
|
+
"aria-hidden": "true"
|
|
51
|
+
}),
|
|
52
|
+
/* @__PURE__ */ jsx("span", {
|
|
53
|
+
"data-mp": "slider-thumb",
|
|
54
|
+
"aria-hidden": "true"
|
|
55
|
+
})
|
|
56
|
+
]
|
|
57
|
+
})
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
export { PillSlider };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ComponentPropsWithoutRef, ReactNode } from "react";
|
|
2
|
+
import { FieldProps } from "./PillField.mjs";
|
|
3
|
+
export interface PillStepperProps extends Omit<FieldProps, "hideLabel" | "optional">, Omit<ComponentPropsWithoutRef<"input">, "type" | "children" | "min" | "max" | "value" | "defaultValue"> {
|
|
4
|
+
min?: number;
|
|
5
|
+
max?: number;
|
|
6
|
+
value?: number | "";
|
|
7
|
+
/** Default: `min`, or 0. */
|
|
8
|
+
defaultValue?: number;
|
|
9
|
+
/** After the number. */
|
|
10
|
+
unit?: ReactNode;
|
|
11
|
+
}
|
|
12
|
+
/** A number, one step at a time. */
|
|
13
|
+
export declare const PillStepper: import("react").ForwardRefExoticComponent<PillStepperProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ComponentPropsWithoutRef, ReactNode } from "react";
|
|
2
|
+
import { FieldProps } from "./PillField.js";
|
|
3
|
+
export interface PillStepperProps extends Omit<FieldProps, "hideLabel" | "optional">, Omit<ComponentPropsWithoutRef<"input">, "type" | "children" | "min" | "max" | "value" | "defaultValue"> {
|
|
4
|
+
min?: number;
|
|
5
|
+
max?: number;
|
|
6
|
+
value?: number | "";
|
|
7
|
+
/** Default: `min`, or 0. */
|
|
8
|
+
defaultValue?: number;
|
|
9
|
+
/** After the number. */
|
|
10
|
+
unit?: ReactNode;
|
|
11
|
+
}
|
|
12
|
+
/** A number, one step at a time. */
|
|
13
|
+
export declare const PillStepper: import("react").ForwardRefExoticComponent<PillStepperProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
let react = require("react");
|
|
4
|
+
const require_PillField = require("./PillField.js");
|
|
5
|
+
const require_glyphs = require("./glyphs.js");
|
|
6
|
+
const require_validity = require("./validity.js");
|
|
7
|
+
const require_react = require("../utils/react.js");
|
|
8
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
9
|
+
|
|
10
|
+
// src/PillForm/PillStepper.tsx
|
|
11
|
+
/** A number, one step at a time. */
|
|
12
|
+
const PillStepper = (0, react.forwardRef)(function PillStepper({ label, hint, error, className, min, max, value, defaultValue = min ?? 0, unit, onInput, onBlur, onInvalid, ...rest }, forwardedRef) {
|
|
13
|
+
const inputRef = (0, react.useRef)(null);
|
|
14
|
+
const ref = (0, react.useMemo)(() => require_react.mergeRefs(inputRef, forwardedRef), [forwardedRef]);
|
|
15
|
+
const validity = require_validity.useValidity(error, inputRef);
|
|
16
|
+
const [ownValue, setOwnValue] = (0, react.useState)(defaultValue);
|
|
17
|
+
const read = () => {
|
|
18
|
+
const text = inputRef.current?.value ?? "";
|
|
19
|
+
setOwnValue(text === "" ? "" : Number(text));
|
|
20
|
+
};
|
|
21
|
+
require_validity.useFormReset(inputRef, read);
|
|
22
|
+
const shown = value ?? ownValue;
|
|
23
|
+
const handleInput = (event) => {
|
|
24
|
+
read();
|
|
25
|
+
validity.handlers.onInput(event);
|
|
26
|
+
onInput?.(event);
|
|
27
|
+
};
|
|
28
|
+
const step = (direction) => () => {
|
|
29
|
+
const input = inputRef.current;
|
|
30
|
+
if (!input) return;
|
|
31
|
+
if (direction > 0) input.stepUp();
|
|
32
|
+
else input.stepDown();
|
|
33
|
+
input.dispatchEvent(new Event("input", { bubbles: true }));
|
|
34
|
+
};
|
|
35
|
+
const renderButton = (direction, isAtLimit) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
36
|
+
type: "button",
|
|
37
|
+
tabIndex: -1,
|
|
38
|
+
"aria-hidden": "true",
|
|
39
|
+
"data-mp": "stepper-button",
|
|
40
|
+
disabled: rest.disabled || rest.readOnly || isAtLimit,
|
|
41
|
+
onClick: step(direction),
|
|
42
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: direction > 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_glyphs.AddGlyph, {}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_glyphs.MinusGlyph, {}) })
|
|
43
|
+
});
|
|
44
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PillField.FieldShell, {
|
|
45
|
+
label,
|
|
46
|
+
hint,
|
|
47
|
+
className,
|
|
48
|
+
error: validity.error,
|
|
49
|
+
layout: "inline",
|
|
50
|
+
"data-kind": "stepper",
|
|
51
|
+
children: (control) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
52
|
+
"data-mp": "field-control",
|
|
53
|
+
"data-type": "stepper",
|
|
54
|
+
children: [
|
|
55
|
+
renderButton(-1, min !== void 0 && shown !== "" && shown <= min),
|
|
56
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
57
|
+
"data-mp": "stepper-value",
|
|
58
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
59
|
+
inputMode: "numeric",
|
|
60
|
+
...rest,
|
|
61
|
+
...control,
|
|
62
|
+
ref,
|
|
63
|
+
type: "number",
|
|
64
|
+
min,
|
|
65
|
+
max,
|
|
66
|
+
...value === void 0 ? { defaultValue } : { value },
|
|
67
|
+
onInput: handleInput,
|
|
68
|
+
onBlur: (event) => {
|
|
69
|
+
validity.handlers.onBlur(event);
|
|
70
|
+
onBlur?.(event);
|
|
71
|
+
},
|
|
72
|
+
onInvalid: (event) => {
|
|
73
|
+
validity.handlers.onInvalid(event);
|
|
74
|
+
onInvalid?.(event);
|
|
75
|
+
}
|
|
76
|
+
}), unit && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: unit })]
|
|
77
|
+
}),
|
|
78
|
+
renderButton(1, max !== void 0 && shown !== "" && shown >= max)
|
|
79
|
+
]
|
|
80
|
+
})
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
exports.PillStepper = PillStepper;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { forwardRef, useMemo, useRef, useState } from "react";
|
|
4
|
+
import { FieldShell } from "./PillField.mjs";
|
|
5
|
+
import { AddGlyph, MinusGlyph } from "./glyphs.mjs";
|
|
6
|
+
import { useFormReset, useValidity } from "./validity.mjs";
|
|
7
|
+
import { mergeRefs } from "../utils/react.mjs";
|
|
8
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
|
|
10
|
+
// src/PillForm/PillStepper.tsx
|
|
11
|
+
/** A number, one step at a time. */
|
|
12
|
+
const PillStepper = forwardRef(function PillStepper({ label, hint, error, className, min, max, value, defaultValue = min ?? 0, unit, onInput, onBlur, onInvalid, ...rest }, forwardedRef) {
|
|
13
|
+
const inputRef = useRef(null);
|
|
14
|
+
const ref = useMemo(() => mergeRefs(inputRef, forwardedRef), [forwardedRef]);
|
|
15
|
+
const validity = useValidity(error, inputRef);
|
|
16
|
+
const [ownValue, setOwnValue] = useState(defaultValue);
|
|
17
|
+
const read = () => {
|
|
18
|
+
const text = inputRef.current?.value ?? "";
|
|
19
|
+
setOwnValue(text === "" ? "" : Number(text));
|
|
20
|
+
};
|
|
21
|
+
useFormReset(inputRef, read);
|
|
22
|
+
const shown = value ?? ownValue;
|
|
23
|
+
const handleInput = (event) => {
|
|
24
|
+
read();
|
|
25
|
+
validity.handlers.onInput(event);
|
|
26
|
+
onInput?.(event);
|
|
27
|
+
};
|
|
28
|
+
const step = (direction) => () => {
|
|
29
|
+
const input = inputRef.current;
|
|
30
|
+
if (!input) return;
|
|
31
|
+
if (direction > 0) input.stepUp();
|
|
32
|
+
else input.stepDown();
|
|
33
|
+
input.dispatchEvent(new Event("input", { bubbles: true }));
|
|
34
|
+
};
|
|
35
|
+
const renderButton = (direction, isAtLimit) => /* @__PURE__ */ jsx("button", {
|
|
36
|
+
type: "button",
|
|
37
|
+
tabIndex: -1,
|
|
38
|
+
"aria-hidden": "true",
|
|
39
|
+
"data-mp": "stepper-button",
|
|
40
|
+
disabled: rest.disabled || rest.readOnly || isAtLimit,
|
|
41
|
+
onClick: step(direction),
|
|
42
|
+
children: /* @__PURE__ */ jsx("span", { children: direction > 0 ? /* @__PURE__ */ jsx(AddGlyph, {}) : /* @__PURE__ */ jsx(MinusGlyph, {}) })
|
|
43
|
+
});
|
|
44
|
+
return /* @__PURE__ */ jsx(FieldShell, {
|
|
45
|
+
label,
|
|
46
|
+
hint,
|
|
47
|
+
className,
|
|
48
|
+
error: validity.error,
|
|
49
|
+
layout: "inline",
|
|
50
|
+
"data-kind": "stepper",
|
|
51
|
+
children: (control) => /* @__PURE__ */ jsxs("div", {
|
|
52
|
+
"data-mp": "field-control",
|
|
53
|
+
"data-type": "stepper",
|
|
54
|
+
children: [
|
|
55
|
+
renderButton(-1, min !== void 0 && shown !== "" && shown <= min),
|
|
56
|
+
/* @__PURE__ */ jsxs("span", {
|
|
57
|
+
"data-mp": "stepper-value",
|
|
58
|
+
children: [/* @__PURE__ */ jsx("input", {
|
|
59
|
+
inputMode: "numeric",
|
|
60
|
+
...rest,
|
|
61
|
+
...control,
|
|
62
|
+
ref,
|
|
63
|
+
type: "number",
|
|
64
|
+
min,
|
|
65
|
+
max,
|
|
66
|
+
...value === void 0 ? { defaultValue } : { value },
|
|
67
|
+
onInput: handleInput,
|
|
68
|
+
onBlur: (event) => {
|
|
69
|
+
validity.handlers.onBlur(event);
|
|
70
|
+
onBlur?.(event);
|
|
71
|
+
},
|
|
72
|
+
onInvalid: (event) => {
|
|
73
|
+
validity.handlers.onInvalid(event);
|
|
74
|
+
onInvalid?.(event);
|
|
75
|
+
}
|
|
76
|
+
}), unit && /* @__PURE__ */ jsx("span", { children: unit })]
|
|
77
|
+
}),
|
|
78
|
+
renderButton(1, max !== void 0 && shown !== "" && shown >= max)
|
|
79
|
+
]
|
|
80
|
+
})
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
export { PillStepper };
|