magic-pill 9.0.0 → 9.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +44 -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 +1452 -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,103 @@
|
|
|
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
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
8
|
+
|
|
9
|
+
// src/PillForm/PillChoices.tsx
|
|
10
|
+
const NONE = [];
|
|
11
|
+
const toList = (value) => value === void 0 || typeof value !== "string" ? value : [value];
|
|
12
|
+
/** One of several choices, or several of them. */
|
|
13
|
+
function PillChoices(props) {
|
|
14
|
+
const { label, hideLabel, hint, error, optional, name, look = "list", multiple = false, disabled, className } = props;
|
|
15
|
+
const id = (0, react.useId)();
|
|
16
|
+
const firstInputRef = (0, react.useRef)(null);
|
|
17
|
+
const validity = require_validity.useValidity(error, firstInputRef);
|
|
18
|
+
const options = props.options.map((option) => typeof option === "string" ? {
|
|
19
|
+
value: option,
|
|
20
|
+
label: option
|
|
21
|
+
} : option);
|
|
22
|
+
const controlled = toList(props.value);
|
|
23
|
+
const initial = toList(props.defaultValue) ?? NONE;
|
|
24
|
+
const [own, setOwn] = (0, react.useState)(initial);
|
|
25
|
+
const chosen = controlled ?? own;
|
|
26
|
+
require_validity.useFormReset(firstInputRef, () => setOwn(initial));
|
|
27
|
+
const at = options.findIndex((option) => option.value === chosen[0]);
|
|
28
|
+
const isSliding = look === "segmented" && !multiple;
|
|
29
|
+
const previousAt = (0, react.useRef)(at);
|
|
30
|
+
const isAppearing = previousAt.current < 0;
|
|
31
|
+
(0, react.useEffect)(() => {
|
|
32
|
+
previousAt.current = at;
|
|
33
|
+
}, [at]);
|
|
34
|
+
const handleChange = (event) => {
|
|
35
|
+
const { value, checked } = event.currentTarget;
|
|
36
|
+
if (props.multiple) {
|
|
37
|
+
const next = options.map((option) => option.value).filter((option) => option === value ? checked : chosen.includes(option));
|
|
38
|
+
setOwn(next);
|
|
39
|
+
props.onChange?.(next, event);
|
|
40
|
+
} else {
|
|
41
|
+
setOwn([value]);
|
|
42
|
+
props.onChange?.(value, event);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PillField.FieldShell, {
|
|
46
|
+
label,
|
|
47
|
+
hideLabel,
|
|
48
|
+
hint,
|
|
49
|
+
optional,
|
|
50
|
+
className,
|
|
51
|
+
error: validity.error,
|
|
52
|
+
group: multiple ? "group" : "radiogroup",
|
|
53
|
+
"data-kind": "choices",
|
|
54
|
+
children: () => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
55
|
+
"data-mp": "choices",
|
|
56
|
+
"data-look": look,
|
|
57
|
+
"data-slides": isSliding ? "" : void 0,
|
|
58
|
+
style: {
|
|
59
|
+
"--_mp-count": options.length,
|
|
60
|
+
"--_mp-at": Math.max(0, at)
|
|
61
|
+
},
|
|
62
|
+
children: [isSliding && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
63
|
+
"data-mp": "choices-thumb",
|
|
64
|
+
"data-empty": at < 0 ? "" : void 0,
|
|
65
|
+
"data-appearing": isAppearing ? "" : void 0,
|
|
66
|
+
"aria-hidden": "true"
|
|
67
|
+
}), options.map((option, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
|
|
68
|
+
"data-mp": "choice",
|
|
69
|
+
htmlFor: id + option.value,
|
|
70
|
+
children: [
|
|
71
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
72
|
+
ref: index === 0 ? firstInputRef : void 0,
|
|
73
|
+
id: id + option.value,
|
|
74
|
+
type: multiple ? "checkbox" : "radio",
|
|
75
|
+
name: name ?? id,
|
|
76
|
+
value: option.value,
|
|
77
|
+
disabled: disabled || option.disabled,
|
|
78
|
+
required: !multiple && props.required,
|
|
79
|
+
...controlled ? { checked: controlled.includes(option.value) } : { defaultChecked: initial.includes(option.value) },
|
|
80
|
+
onChange: handleChange,
|
|
81
|
+
onInput: validity.handlers.onInput,
|
|
82
|
+
onInvalid: validity.handlers.onInvalid
|
|
83
|
+
}),
|
|
84
|
+
look === "list" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
85
|
+
"data-mp": multiple ? "field-tick" : "field-dot",
|
|
86
|
+
"aria-hidden": "true",
|
|
87
|
+
children: multiple && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_glyphs.TickGlyph, {})
|
|
88
|
+
}),
|
|
89
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
90
|
+
"data-mp": "choice-body",
|
|
91
|
+
children: [option.icon && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
92
|
+
"data-mp": "field-icon",
|
|
93
|
+
"aria-hidden": "true",
|
|
94
|
+
children: option.icon
|
|
95
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: [option.label, option.hint && look === "list" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: option.hint })] })]
|
|
96
|
+
})
|
|
97
|
+
]
|
|
98
|
+
}, option.value))]
|
|
99
|
+
})
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
exports.PillChoices = PillChoices;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
4
|
+
import { FieldShell } from "./PillField.mjs";
|
|
5
|
+
import { TickGlyph } from "./glyphs.mjs";
|
|
6
|
+
import { useFormReset, useValidity } from "./validity.mjs";
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
|
|
9
|
+
// src/PillForm/PillChoices.tsx
|
|
10
|
+
const NONE = [];
|
|
11
|
+
const toList = (value) => value === void 0 || typeof value !== "string" ? value : [value];
|
|
12
|
+
/** One of several choices, or several of them. */
|
|
13
|
+
function PillChoices(props) {
|
|
14
|
+
const { label, hideLabel, hint, error, optional, name, look = "list", multiple = false, disabled, className } = props;
|
|
15
|
+
const id = useId();
|
|
16
|
+
const firstInputRef = useRef(null);
|
|
17
|
+
const validity = useValidity(error, firstInputRef);
|
|
18
|
+
const options = props.options.map((option) => typeof option === "string" ? {
|
|
19
|
+
value: option,
|
|
20
|
+
label: option
|
|
21
|
+
} : option);
|
|
22
|
+
const controlled = toList(props.value);
|
|
23
|
+
const initial = toList(props.defaultValue) ?? NONE;
|
|
24
|
+
const [own, setOwn] = useState(initial);
|
|
25
|
+
const chosen = controlled ?? own;
|
|
26
|
+
useFormReset(firstInputRef, () => setOwn(initial));
|
|
27
|
+
const at = options.findIndex((option) => option.value === chosen[0]);
|
|
28
|
+
const isSliding = look === "segmented" && !multiple;
|
|
29
|
+
const previousAt = useRef(at);
|
|
30
|
+
const isAppearing = previousAt.current < 0;
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
previousAt.current = at;
|
|
33
|
+
}, [at]);
|
|
34
|
+
const handleChange = (event) => {
|
|
35
|
+
const { value, checked } = event.currentTarget;
|
|
36
|
+
if (props.multiple) {
|
|
37
|
+
const next = options.map((option) => option.value).filter((option) => option === value ? checked : chosen.includes(option));
|
|
38
|
+
setOwn(next);
|
|
39
|
+
props.onChange?.(next, event);
|
|
40
|
+
} else {
|
|
41
|
+
setOwn([value]);
|
|
42
|
+
props.onChange?.(value, event);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
return /* @__PURE__ */ jsx(FieldShell, {
|
|
46
|
+
label,
|
|
47
|
+
hideLabel,
|
|
48
|
+
hint,
|
|
49
|
+
optional,
|
|
50
|
+
className,
|
|
51
|
+
error: validity.error,
|
|
52
|
+
group: multiple ? "group" : "radiogroup",
|
|
53
|
+
"data-kind": "choices",
|
|
54
|
+
children: () => /* @__PURE__ */ jsxs("div", {
|
|
55
|
+
"data-mp": "choices",
|
|
56
|
+
"data-look": look,
|
|
57
|
+
"data-slides": isSliding ? "" : void 0,
|
|
58
|
+
style: {
|
|
59
|
+
"--_mp-count": options.length,
|
|
60
|
+
"--_mp-at": Math.max(0, at)
|
|
61
|
+
},
|
|
62
|
+
children: [isSliding && /* @__PURE__ */ jsx("span", {
|
|
63
|
+
"data-mp": "choices-thumb",
|
|
64
|
+
"data-empty": at < 0 ? "" : void 0,
|
|
65
|
+
"data-appearing": isAppearing ? "" : void 0,
|
|
66
|
+
"aria-hidden": "true"
|
|
67
|
+
}), options.map((option, index) => /* @__PURE__ */ jsxs("label", {
|
|
68
|
+
"data-mp": "choice",
|
|
69
|
+
htmlFor: id + option.value,
|
|
70
|
+
children: [
|
|
71
|
+
/* @__PURE__ */ jsx("input", {
|
|
72
|
+
ref: index === 0 ? firstInputRef : void 0,
|
|
73
|
+
id: id + option.value,
|
|
74
|
+
type: multiple ? "checkbox" : "radio",
|
|
75
|
+
name: name ?? id,
|
|
76
|
+
value: option.value,
|
|
77
|
+
disabled: disabled || option.disabled,
|
|
78
|
+
required: !multiple && props.required,
|
|
79
|
+
...controlled ? { checked: controlled.includes(option.value) } : { defaultChecked: initial.includes(option.value) },
|
|
80
|
+
onChange: handleChange,
|
|
81
|
+
onInput: validity.handlers.onInput,
|
|
82
|
+
onInvalid: validity.handlers.onInvalid
|
|
83
|
+
}),
|
|
84
|
+
look === "list" && /* @__PURE__ */ jsx("span", {
|
|
85
|
+
"data-mp": multiple ? "field-tick" : "field-dot",
|
|
86
|
+
"aria-hidden": "true",
|
|
87
|
+
children: multiple && /* @__PURE__ */ jsx(TickGlyph, {})
|
|
88
|
+
}),
|
|
89
|
+
/* @__PURE__ */ jsxs("span", {
|
|
90
|
+
"data-mp": "choice-body",
|
|
91
|
+
children: [option.icon && /* @__PURE__ */ jsx("span", {
|
|
92
|
+
"data-mp": "field-icon",
|
|
93
|
+
"aria-hidden": "true",
|
|
94
|
+
children: option.icon
|
|
95
|
+
}), /* @__PURE__ */ jsxs("span", { children: [option.label, option.hint && look === "list" && /* @__PURE__ */ jsx("small", { children: option.hint })] })]
|
|
96
|
+
})
|
|
97
|
+
]
|
|
98
|
+
}, option.value))]
|
|
99
|
+
})
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export { PillChoices };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ComponentPropsWithoutRef } from "react";
|
|
2
|
+
import { FieldProps } from "./PillField.mjs";
|
|
3
|
+
export interface PillCodeProps extends Omit<FieldProps, "optional">, Omit<ComponentPropsWithoutRef<"input">, "type" | "children" | "pattern" | "maxLength" | "value" | "defaultValue"> {
|
|
4
|
+
/** How many digits. Default 6. */
|
|
5
|
+
length?: number;
|
|
6
|
+
value?: string;
|
|
7
|
+
defaultValue?: string;
|
|
8
|
+
/** Called once they're all there. */
|
|
9
|
+
onComplete?: (code: string) => void;
|
|
10
|
+
}
|
|
11
|
+
/** A one-time code: a single input, drawn as slots, so pasting and SMS autofill work. */
|
|
12
|
+
export declare const PillCode: import("react").ForwardRefExoticComponent<PillCodeProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ComponentPropsWithoutRef } from "react";
|
|
2
|
+
import { FieldProps } from "./PillField.js";
|
|
3
|
+
export interface PillCodeProps extends Omit<FieldProps, "optional">, Omit<ComponentPropsWithoutRef<"input">, "type" | "children" | "pattern" | "maxLength" | "value" | "defaultValue"> {
|
|
4
|
+
/** How many digits. Default 6. */
|
|
5
|
+
length?: number;
|
|
6
|
+
value?: string;
|
|
7
|
+
defaultValue?: string;
|
|
8
|
+
/** Called once they're all there. */
|
|
9
|
+
onComplete?: (code: string) => void;
|
|
10
|
+
}
|
|
11
|
+
/** A one-time code: a single input, drawn as slots, so pasting and SMS autofill work. */
|
|
12
|
+
export declare const PillCode: import("react").ForwardRefExoticComponent<PillCodeProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
@@ -0,0 +1,60 @@
|
|
|
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/PillCode.tsx
|
|
10
|
+
/** A one-time code: a single input, drawn as slots, so pasting and SMS autofill work. */
|
|
11
|
+
const PillCode = (0, react.forwardRef)(function PillCode({ label, hideLabel, hint, error, length = 6, value, defaultValue = "", onComplete, className, onInput, onBlur, onInvalid, ...rest }, forwardedRef) {
|
|
12
|
+
const inputRef = (0, react.useRef)(null);
|
|
13
|
+
const ref = (0, react.useMemo)(() => require_react.mergeRefs(inputRef, forwardedRef), [forwardedRef]);
|
|
14
|
+
const validity = require_validity.useValidity(error, inputRef);
|
|
15
|
+
const [ownValue, setOwnValue] = (0, react.useState)(defaultValue);
|
|
16
|
+
require_validity.useFormReset(inputRef, () => setOwnValue(inputRef.current?.value ?? ""));
|
|
17
|
+
const digits = value ?? ownValue;
|
|
18
|
+
const handleInput = (event) => {
|
|
19
|
+
const input = event.currentTarget;
|
|
20
|
+
const clean = input.value.replace(/\D/g, "").slice(0, length);
|
|
21
|
+
if (clean !== input.value) input.value = clean;
|
|
22
|
+
setOwnValue(clean);
|
|
23
|
+
validity.handlers.onInput(event);
|
|
24
|
+
onInput?.(event);
|
|
25
|
+
if (clean.length === length && clean !== digits) onComplete?.(clean);
|
|
26
|
+
};
|
|
27
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PillField.FieldShell, {
|
|
28
|
+
label,
|
|
29
|
+
hideLabel,
|
|
30
|
+
hint,
|
|
31
|
+
className,
|
|
32
|
+
error: validity.error,
|
|
33
|
+
"data-kind": "code",
|
|
34
|
+
children: (control) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
35
|
+
"data-mp": "field-control",
|
|
36
|
+
"data-type": "code",
|
|
37
|
+
style: { "--_mp-count": length },
|
|
38
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
39
|
+
inputMode: "numeric",
|
|
40
|
+
autoComplete: "one-time-code",
|
|
41
|
+
...rest,
|
|
42
|
+
...control,
|
|
43
|
+
ref,
|
|
44
|
+
type: "text",
|
|
45
|
+
pattern: `[0-9]{${length}}`,
|
|
46
|
+
...value === void 0 ? { defaultValue } : { value },
|
|
47
|
+
onInput: handleInput,
|
|
48
|
+
onBlur: require_validity.both(validity.handlers.onBlur, onBlur),
|
|
49
|
+
onInvalid: require_validity.both(validity.handlers.onInvalid, onInvalid)
|
|
50
|
+
}), Array.from({ length }, (_, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
51
|
+
"data-mp": "code-slot",
|
|
52
|
+
"data-next": index === Math.min(digits.length, length - 1) ? "" : void 0,
|
|
53
|
+
"aria-hidden": "true",
|
|
54
|
+
children: digits[index]
|
|
55
|
+
}, index))]
|
|
56
|
+
})
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
exports.PillCode = PillCode;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { forwardRef, useMemo, useRef, useState } from "react";
|
|
4
|
+
import { FieldShell } from "./PillField.mjs";
|
|
5
|
+
import { both, useFormReset, useValidity } from "./validity.mjs";
|
|
6
|
+
import { mergeRefs } from "../utils/react.mjs";
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
|
|
9
|
+
// src/PillForm/PillCode.tsx
|
|
10
|
+
/** A one-time code: a single input, drawn as slots, so pasting and SMS autofill work. */
|
|
11
|
+
const PillCode = forwardRef(function PillCode({ label, hideLabel, hint, error, length = 6, value, defaultValue = "", onComplete, className, onInput, onBlur, onInvalid, ...rest }, forwardedRef) {
|
|
12
|
+
const inputRef = useRef(null);
|
|
13
|
+
const ref = useMemo(() => mergeRefs(inputRef, forwardedRef), [forwardedRef]);
|
|
14
|
+
const validity = useValidity(error, inputRef);
|
|
15
|
+
const [ownValue, setOwnValue] = useState(defaultValue);
|
|
16
|
+
useFormReset(inputRef, () => setOwnValue(inputRef.current?.value ?? ""));
|
|
17
|
+
const digits = value ?? ownValue;
|
|
18
|
+
const handleInput = (event) => {
|
|
19
|
+
const input = event.currentTarget;
|
|
20
|
+
const clean = input.value.replace(/\D/g, "").slice(0, length);
|
|
21
|
+
if (clean !== input.value) input.value = clean;
|
|
22
|
+
setOwnValue(clean);
|
|
23
|
+
validity.handlers.onInput(event);
|
|
24
|
+
onInput?.(event);
|
|
25
|
+
if (clean.length === length && clean !== digits) onComplete?.(clean);
|
|
26
|
+
};
|
|
27
|
+
return /* @__PURE__ */ jsx(FieldShell, {
|
|
28
|
+
label,
|
|
29
|
+
hideLabel,
|
|
30
|
+
hint,
|
|
31
|
+
className,
|
|
32
|
+
error: validity.error,
|
|
33
|
+
"data-kind": "code",
|
|
34
|
+
children: (control) => /* @__PURE__ */ jsxs("div", {
|
|
35
|
+
"data-mp": "field-control",
|
|
36
|
+
"data-type": "code",
|
|
37
|
+
style: { "--_mp-count": length },
|
|
38
|
+
children: [/* @__PURE__ */ jsx("input", {
|
|
39
|
+
inputMode: "numeric",
|
|
40
|
+
autoComplete: "one-time-code",
|
|
41
|
+
...rest,
|
|
42
|
+
...control,
|
|
43
|
+
ref,
|
|
44
|
+
type: "text",
|
|
45
|
+
pattern: `[0-9]{${length}}`,
|
|
46
|
+
...value === void 0 ? { defaultValue } : { value },
|
|
47
|
+
onInput: handleInput,
|
|
48
|
+
onBlur: both(validity.handlers.onBlur, onBlur),
|
|
49
|
+
onInvalid: both(validity.handlers.onInvalid, onInvalid)
|
|
50
|
+
}), Array.from({ length }, (_, index) => /* @__PURE__ */ jsx("span", {
|
|
51
|
+
"data-mp": "code-slot",
|
|
52
|
+
"data-next": index === Math.min(digits.length, length - 1) ? "" : void 0,
|
|
53
|
+
"aria-hidden": "true",
|
|
54
|
+
children: digits[index]
|
|
55
|
+
}, index))]
|
|
56
|
+
})
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
export { PillCode };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ComponentPropsWithoutRef } from "react";
|
|
2
|
+
import { FieldProps } from "./PillField.mjs";
|
|
3
|
+
export interface PillColorProps extends Omit<FieldProps, "hideLabel" | "optional">, Omit<ComponentPropsWithoutRef<"input">, "type" | "children" | "value" | "defaultValue"> {
|
|
4
|
+
/** `#rrggbb`. */
|
|
5
|
+
value?: string;
|
|
6
|
+
/** Default `#d5d2e8`. */
|
|
7
|
+
defaultValue?: string;
|
|
8
|
+
}
|
|
9
|
+
/** A colour, from the browser's own picker. */
|
|
10
|
+
export declare const PillColor: import("react").ForwardRefExoticComponent<PillColorProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ComponentPropsWithoutRef } from "react";
|
|
2
|
+
import { FieldProps } from "./PillField.js";
|
|
3
|
+
export interface PillColorProps extends Omit<FieldProps, "hideLabel" | "optional">, Omit<ComponentPropsWithoutRef<"input">, "type" | "children" | "value" | "defaultValue"> {
|
|
4
|
+
/** `#rrggbb`. */
|
|
5
|
+
value?: string;
|
|
6
|
+
/** Default `#d5d2e8`. */
|
|
7
|
+
defaultValue?: string;
|
|
8
|
+
}
|
|
9
|
+
/** A colour, from the browser's own picker. */
|
|
10
|
+
export declare const PillColor: import("react").ForwardRefExoticComponent<PillColorProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
@@ -0,0 +1,56 @@
|
|
|
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/PillColor.tsx
|
|
10
|
+
/** A colour, from the browser's own picker. */
|
|
11
|
+
const PillColor = (0, react.forwardRef)(function PillColor({ label, hint, error, className, value, defaultValue = "#d5d2e8", onInput, ...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
|
+
const read = () => setOwnValue(inputRef.current?.value ?? defaultValue);
|
|
16
|
+
require_validity.useFormReset(inputRef, read);
|
|
17
|
+
const color = value ?? ownValue;
|
|
18
|
+
const handleInput = (event) => {
|
|
19
|
+
read();
|
|
20
|
+
onInput?.(event);
|
|
21
|
+
};
|
|
22
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PillField.FieldShell, {
|
|
23
|
+
label,
|
|
24
|
+
hint,
|
|
25
|
+
error,
|
|
26
|
+
className,
|
|
27
|
+
layout: "inline",
|
|
28
|
+
"data-kind": "color",
|
|
29
|
+
children: (control) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
30
|
+
"data-mp": "field-control",
|
|
31
|
+
"data-type": "color",
|
|
32
|
+
style: { "--_mp-color": color },
|
|
33
|
+
children: [
|
|
34
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
35
|
+
...rest,
|
|
36
|
+
...control,
|
|
37
|
+
ref,
|
|
38
|
+
type: "color",
|
|
39
|
+
...value === void 0 ? { defaultValue } : { value },
|
|
40
|
+
onInput: handleInput
|
|
41
|
+
}),
|
|
42
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
43
|
+
"data-mp": "color-value",
|
|
44
|
+
"aria-hidden": "true",
|
|
45
|
+
children: color
|
|
46
|
+
}),
|
|
47
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
48
|
+
"data-mp": "color-swatch",
|
|
49
|
+
"aria-hidden": "true"
|
|
50
|
+
})
|
|
51
|
+
]
|
|
52
|
+
})
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
exports.PillColor = PillColor;
|
|
@@ -0,0 +1,56 @@
|
|
|
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/PillColor.tsx
|
|
10
|
+
/** A colour, from the browser's own picker. */
|
|
11
|
+
const PillColor = forwardRef(function PillColor({ label, hint, error, className, value, defaultValue = "#d5d2e8", onInput, ...rest }, forwardedRef) {
|
|
12
|
+
const inputRef = useRef(null);
|
|
13
|
+
const ref = useMemo(() => mergeRefs(inputRef, forwardedRef), [forwardedRef]);
|
|
14
|
+
const [ownValue, setOwnValue] = useState(defaultValue);
|
|
15
|
+
const read = () => setOwnValue(inputRef.current?.value ?? defaultValue);
|
|
16
|
+
useFormReset(inputRef, read);
|
|
17
|
+
const color = value ?? ownValue;
|
|
18
|
+
const handleInput = (event) => {
|
|
19
|
+
read();
|
|
20
|
+
onInput?.(event);
|
|
21
|
+
};
|
|
22
|
+
return /* @__PURE__ */ jsx(FieldShell, {
|
|
23
|
+
label,
|
|
24
|
+
hint,
|
|
25
|
+
error,
|
|
26
|
+
className,
|
|
27
|
+
layout: "inline",
|
|
28
|
+
"data-kind": "color",
|
|
29
|
+
children: (control) => /* @__PURE__ */ jsxs("span", {
|
|
30
|
+
"data-mp": "field-control",
|
|
31
|
+
"data-type": "color",
|
|
32
|
+
style: { "--_mp-color": color },
|
|
33
|
+
children: [
|
|
34
|
+
/* @__PURE__ */ jsx("input", {
|
|
35
|
+
...rest,
|
|
36
|
+
...control,
|
|
37
|
+
ref,
|
|
38
|
+
type: "color",
|
|
39
|
+
...value === void 0 ? { defaultValue } : { value },
|
|
40
|
+
onInput: handleInput
|
|
41
|
+
}),
|
|
42
|
+
/* @__PURE__ */ jsx("span", {
|
|
43
|
+
"data-mp": "color-value",
|
|
44
|
+
"aria-hidden": "true",
|
|
45
|
+
children: color
|
|
46
|
+
}),
|
|
47
|
+
/* @__PURE__ */ jsx("span", {
|
|
48
|
+
"data-mp": "color-swatch",
|
|
49
|
+
"aria-hidden": "true"
|
|
50
|
+
})
|
|
51
|
+
]
|
|
52
|
+
})
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
export { PillColor };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
import { CalendarLabels } from "./Calendar.mjs";
|
|
3
|
+
import { DateType } from "./dates.mjs";
|
|
4
|
+
import { FieldLayout } from "./FormContext.mjs";
|
|
5
|
+
import { FieldProps } from "./PillField.mjs";
|
|
6
|
+
export interface PillDateProps extends FieldProps {
|
|
7
|
+
/** Default `date`. */
|
|
8
|
+
type?: DateType;
|
|
9
|
+
name?: string;
|
|
10
|
+
/** As the native input of this type writes it: `2026-12-24`, `2026-12`, `2026-W52`, `19:30`, `2026-12-24T19:30`. */
|
|
11
|
+
value?: string;
|
|
12
|
+
defaultValue?: string;
|
|
13
|
+
onChange?: (value: string) => void;
|
|
14
|
+
/** Same format as the value. */
|
|
15
|
+
min?: string;
|
|
16
|
+
max?: string;
|
|
17
|
+
/** In seconds, as on the native input: how far apart the times are. Default: five minutes. */
|
|
18
|
+
step?: number;
|
|
19
|
+
/** Days that can't be chosen, e.g. weekends. */
|
|
20
|
+
disabledDate?: (day: string) => boolean;
|
|
21
|
+
required?: boolean;
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
/** Shown while nothing is chosen. */
|
|
24
|
+
placeholder?: string;
|
|
25
|
+
/** Default: the browser's. */
|
|
26
|
+
locale?: string;
|
|
27
|
+
/** 0 for Sunday. Default: the locale's. Weeks always start on Monday. */
|
|
28
|
+
firstDay?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
29
|
+
/** How the chosen value is written. Default: in full. */
|
|
30
|
+
format?: Intl.DateTimeFormatOptions;
|
|
31
|
+
/** The calendar's own words. Days and months are the locale's. */
|
|
32
|
+
labels?: Partial<CalendarLabels>;
|
|
33
|
+
/** Always there, under the label, instead of in a popover. */
|
|
34
|
+
inline?: boolean;
|
|
35
|
+
/** The label above the field, or beside it. Default: the form's, or above. */
|
|
36
|
+
layout?: FieldLayout;
|
|
37
|
+
icon?: ReactNode;
|
|
38
|
+
className?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A date, a month, a week, a time, or a date and time, chosen in a calendar of
|
|
42
|
+
* the pill's. It sends what the native input of its type would.
|
|
43
|
+
*/
|
|
44
|
+
export declare const PillDate: import("react").ForwardRefExoticComponent<PillDateProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
import { CalendarLabels } from "./Calendar.js";
|
|
3
|
+
import { DateType } from "./dates.js";
|
|
4
|
+
import { FieldLayout } from "./FormContext.js";
|
|
5
|
+
import { FieldProps } from "./PillField.js";
|
|
6
|
+
export interface PillDateProps extends FieldProps {
|
|
7
|
+
/** Default `date`. */
|
|
8
|
+
type?: DateType;
|
|
9
|
+
name?: string;
|
|
10
|
+
/** As the native input of this type writes it: `2026-12-24`, `2026-12`, `2026-W52`, `19:30`, `2026-12-24T19:30`. */
|
|
11
|
+
value?: string;
|
|
12
|
+
defaultValue?: string;
|
|
13
|
+
onChange?: (value: string) => void;
|
|
14
|
+
/** Same format as the value. */
|
|
15
|
+
min?: string;
|
|
16
|
+
max?: string;
|
|
17
|
+
/** In seconds, as on the native input: how far apart the times are. Default: five minutes. */
|
|
18
|
+
step?: number;
|
|
19
|
+
/** Days that can't be chosen, e.g. weekends. */
|
|
20
|
+
disabledDate?: (day: string) => boolean;
|
|
21
|
+
required?: boolean;
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
/** Shown while nothing is chosen. */
|
|
24
|
+
placeholder?: string;
|
|
25
|
+
/** Default: the browser's. */
|
|
26
|
+
locale?: string;
|
|
27
|
+
/** 0 for Sunday. Default: the locale's. Weeks always start on Monday. */
|
|
28
|
+
firstDay?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
29
|
+
/** How the chosen value is written. Default: in full. */
|
|
30
|
+
format?: Intl.DateTimeFormatOptions;
|
|
31
|
+
/** The calendar's own words. Days and months are the locale's. */
|
|
32
|
+
labels?: Partial<CalendarLabels>;
|
|
33
|
+
/** Always there, under the label, instead of in a popover. */
|
|
34
|
+
inline?: boolean;
|
|
35
|
+
/** The label above the field, or beside it. Default: the form's, or above. */
|
|
36
|
+
layout?: FieldLayout;
|
|
37
|
+
icon?: ReactNode;
|
|
38
|
+
className?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A date, a month, a week, a time, or a date and time, chosen in a calendar of
|
|
42
|
+
* the pill's. It sends what the native input of its type would.
|
|
43
|
+
*/
|
|
44
|
+
export declare const PillDate: import("react").ForwardRefExoticComponent<PillDateProps & import("react").RefAttributes<HTMLButtonElement>>;
|