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,193 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
let react = require("react");
|
|
4
|
+
const require_Calendar = require("./Calendar.js");
|
|
5
|
+
const require_dates = require("./dates.js");
|
|
6
|
+
const require_glyphs = require("./glyphs.js");
|
|
7
|
+
const require_PillField = require("./PillField.js");
|
|
8
|
+
const require_popover = require("./popover.js");
|
|
9
|
+
const require_validity = require("./validity.js");
|
|
10
|
+
const require_react = require("../utils/react.js");
|
|
11
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
12
|
+
|
|
13
|
+
// src/PillForm/PillDate.tsx
|
|
14
|
+
const PLACEHOLDERS = {
|
|
15
|
+
date: "Pick a date",
|
|
16
|
+
month: "Pick a month",
|
|
17
|
+
week: "Pick a week",
|
|
18
|
+
time: "Pick a time",
|
|
19
|
+
"datetime-local": "Pick a date and time"
|
|
20
|
+
};
|
|
21
|
+
const subscribe = () => () => {};
|
|
22
|
+
/** False on the server and as the page wakes up: dates are written in the reader's language, which the server doesn't know. */
|
|
23
|
+
const useIsClient = () => (0, react.useSyncExternalStore)(subscribe, () => true, () => false);
|
|
24
|
+
/**
|
|
25
|
+
* A date, a month, a week, a time, or a date and time, chosen in a calendar of
|
|
26
|
+
* the pill's. It sends what the native input of its type would.
|
|
27
|
+
*/
|
|
28
|
+
const PillDate = (0, react.forwardRef)(function PillDate({ label, hideLabel, hint, error, optional, type = "date", name, value: controlled, defaultValue = "", onChange, min, max, step, disabledDate, required = false, disabled = false, placeholder = PLACEHOLDERS[type], locale, firstDay, format, labels, inline = false, layout, icon, className }, ref) {
|
|
29
|
+
const inputRef = (0, react.useRef)(null);
|
|
30
|
+
const triggerRef = (0, react.useRef)(null);
|
|
31
|
+
const boxRef = (0, react.useRef)(null);
|
|
32
|
+
const popoverRef = (0, react.useRef)(null);
|
|
33
|
+
(0, react.useImperativeHandle)(ref, () => triggerRef.current);
|
|
34
|
+
const validity = require_validity.useValidity(error, inputRef);
|
|
35
|
+
const isClient = useIsClient();
|
|
36
|
+
const [own, setOwn] = (0, react.useState)(defaultValue);
|
|
37
|
+
const [isOpen, setIsOpen] = (0, react.useState)(false);
|
|
38
|
+
const [draft, setDraft] = (0, react.useState)(null);
|
|
39
|
+
require_validity.useFormReset(inputRef, () => setOwn(defaultValue));
|
|
40
|
+
const value = controlled ?? own;
|
|
41
|
+
const day = draft?.day ?? require_dates.dayOf(value, type);
|
|
42
|
+
const time = draft?.time ?? require_dates.timeOf(value, type);
|
|
43
|
+
const isFirst = (0, react.useRef)(true);
|
|
44
|
+
(0, react.useEffect)(() => {
|
|
45
|
+
if (!isFirst.current) inputRef.current?.dispatchEvent(new Event("input", { bubbles: true }));
|
|
46
|
+
isFirst.current = false;
|
|
47
|
+
}, [value]);
|
|
48
|
+
const close = (focus) => {
|
|
49
|
+
setIsOpen(false);
|
|
50
|
+
setDraft(null);
|
|
51
|
+
if (focus) triggerRef.current?.focus();
|
|
52
|
+
};
|
|
53
|
+
require_popover.usePopover(popoverRef, boxRef, isOpen && !inline, () => close(false));
|
|
54
|
+
const handleChoice = (nextDay, nextTime, isFinal) => {
|
|
55
|
+
const next = nextDay || nextTime ? require_dates.toValue(type, nextDay, nextTime) : "";
|
|
56
|
+
setDraft(isFinal ? null : {
|
|
57
|
+
day: nextDay,
|
|
58
|
+
time: nextTime
|
|
59
|
+
});
|
|
60
|
+
if (next !== value) {
|
|
61
|
+
setOwn(next);
|
|
62
|
+
onChange?.(next);
|
|
63
|
+
}
|
|
64
|
+
if (isFinal && isOpen) close(true);
|
|
65
|
+
};
|
|
66
|
+
const handleKeys = (event) => {
|
|
67
|
+
if (event.key === "Escape") {
|
|
68
|
+
event.preventDefault();
|
|
69
|
+
event.stopPropagation();
|
|
70
|
+
close(true);
|
|
71
|
+
} else if (event.key === "Tab") {
|
|
72
|
+
const stops = [...event.currentTarget.querySelectorAll("button:not(:disabled), [tabindex=\"0\"]")].filter((stop) => stop.tabIndex === 0);
|
|
73
|
+
const edge = event.shiftKey ? stops[0] : stops[stops.length - 1];
|
|
74
|
+
if (document.activeElement === edge) {
|
|
75
|
+
event.preventDefault();
|
|
76
|
+
(event.shiftKey ? stops[stops.length - 1] : stops[0])?.focus();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const calendar = (isInline) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Calendar.Calendar, {
|
|
81
|
+
type,
|
|
82
|
+
day,
|
|
83
|
+
time,
|
|
84
|
+
min,
|
|
85
|
+
max,
|
|
86
|
+
step,
|
|
87
|
+
locale,
|
|
88
|
+
firstDay,
|
|
89
|
+
disabledDate,
|
|
90
|
+
labels: {
|
|
91
|
+
...require_Calendar.CALENDAR_LABELS,
|
|
92
|
+
...labels
|
|
93
|
+
},
|
|
94
|
+
canClear: !required,
|
|
95
|
+
autoFocus: !isInline,
|
|
96
|
+
onChoose: handleChoice,
|
|
97
|
+
onDone: isInline ? void 0 : () => close(true)
|
|
98
|
+
});
|
|
99
|
+
const TypeGlyph = type === "time" ? require_glyphs.ClockGlyph : require_glyphs.CalendarGlyph;
|
|
100
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PillField.FieldShell, {
|
|
101
|
+
label,
|
|
102
|
+
hideLabel,
|
|
103
|
+
hint,
|
|
104
|
+
optional,
|
|
105
|
+
layout,
|
|
106
|
+
className,
|
|
107
|
+
error: validity.error,
|
|
108
|
+
isText: !inline,
|
|
109
|
+
"data-kind": "text",
|
|
110
|
+
children: (control) => {
|
|
111
|
+
const native = /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
112
|
+
ref: inputRef,
|
|
113
|
+
type,
|
|
114
|
+
name,
|
|
115
|
+
value,
|
|
116
|
+
min,
|
|
117
|
+
max,
|
|
118
|
+
required,
|
|
119
|
+
disabled,
|
|
120
|
+
step: "any",
|
|
121
|
+
tabIndex: -1,
|
|
122
|
+
"aria-hidden": "true",
|
|
123
|
+
"data-mp": "date-value",
|
|
124
|
+
onChange: () => {},
|
|
125
|
+
onFocus: () => (triggerRef.current ?? boxRef.current?.querySelector("[tabindex=\"0\"]"))?.focus(),
|
|
126
|
+
onInput: validity.handlers.onInput,
|
|
127
|
+
onInvalid: validity.handlers.onInvalid
|
|
128
|
+
});
|
|
129
|
+
if (inline) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
130
|
+
ref: boxRef,
|
|
131
|
+
"data-mp": "calendar",
|
|
132
|
+
"data-inline": "",
|
|
133
|
+
role: "group",
|
|
134
|
+
"aria-labelledby": `${control.id}label`,
|
|
135
|
+
...require_react.inertProps(disabled),
|
|
136
|
+
children: [native, isClient && calendar(true)]
|
|
137
|
+
});
|
|
138
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
139
|
+
ref: boxRef,
|
|
140
|
+
"data-mp": "field-box",
|
|
141
|
+
"data-type": "pill-date",
|
|
142
|
+
children: [
|
|
143
|
+
native,
|
|
144
|
+
icon && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
145
|
+
"data-mp": "field-icon",
|
|
146
|
+
"aria-hidden": "true",
|
|
147
|
+
children: icon
|
|
148
|
+
}),
|
|
149
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
150
|
+
...control,
|
|
151
|
+
ref: triggerRef,
|
|
152
|
+
type: "button",
|
|
153
|
+
"data-mp": "field-trigger",
|
|
154
|
+
"data-empty": value ? void 0 : "",
|
|
155
|
+
disabled,
|
|
156
|
+
"aria-labelledby": `${control.id}label ${control.id}value`,
|
|
157
|
+
"aria-haspopup": "dialog",
|
|
158
|
+
"aria-expanded": isOpen,
|
|
159
|
+
onClick: () => isOpen ? close(false) : setIsOpen(true),
|
|
160
|
+
onKeyDown: (event) => {
|
|
161
|
+
if (event.key === "ArrowDown") {
|
|
162
|
+
event.preventDefault();
|
|
163
|
+
setIsOpen(true);
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
167
|
+
id: `${control.id}value`,
|
|
168
|
+
dir: "auto",
|
|
169
|
+
children: value ? isClient ? require_dates.formatValue(value, type, locale, format) : value : placeholder
|
|
170
|
+
})
|
|
171
|
+
}),
|
|
172
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
173
|
+
"data-mp": "field-icon",
|
|
174
|
+
"aria-hidden": "true",
|
|
175
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TypeGlyph, {})
|
|
176
|
+
}),
|
|
177
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
178
|
+
ref: popoverRef,
|
|
179
|
+
popover: "manual",
|
|
180
|
+
role: "dialog",
|
|
181
|
+
"aria-labelledby": `${control.id}label`,
|
|
182
|
+
"data-mp": "calendar",
|
|
183
|
+
"data-open": isOpen ? "" : void 0,
|
|
184
|
+
onKeyDown: handleKeys,
|
|
185
|
+
children: isOpen && calendar(false)
|
|
186
|
+
})
|
|
187
|
+
]
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
exports.PillDate = PillDate;
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { forwardRef, useEffect, useImperativeHandle, useRef, useState, useSyncExternalStore } from "react";
|
|
4
|
+
import { CALENDAR_LABELS, Calendar } from "./Calendar.mjs";
|
|
5
|
+
import { dayOf, formatValue, timeOf, toValue } from "./dates.mjs";
|
|
6
|
+
import { CalendarGlyph, ClockGlyph } from "./glyphs.mjs";
|
|
7
|
+
import { FieldShell } from "./PillField.mjs";
|
|
8
|
+
import { usePopover } from "./popover.mjs";
|
|
9
|
+
import { useFormReset, useValidity } from "./validity.mjs";
|
|
10
|
+
import { inertProps } from "../utils/react.mjs";
|
|
11
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
+
|
|
13
|
+
// src/PillForm/PillDate.tsx
|
|
14
|
+
const PLACEHOLDERS = {
|
|
15
|
+
date: "Pick a date",
|
|
16
|
+
month: "Pick a month",
|
|
17
|
+
week: "Pick a week",
|
|
18
|
+
time: "Pick a time",
|
|
19
|
+
"datetime-local": "Pick a date and time"
|
|
20
|
+
};
|
|
21
|
+
const subscribe = () => () => {};
|
|
22
|
+
/** False on the server and as the page wakes up: dates are written in the reader's language, which the server doesn't know. */
|
|
23
|
+
const useIsClient = () => useSyncExternalStore(subscribe, () => true, () => false);
|
|
24
|
+
/**
|
|
25
|
+
* A date, a month, a week, a time, or a date and time, chosen in a calendar of
|
|
26
|
+
* the pill's. It sends what the native input of its type would.
|
|
27
|
+
*/
|
|
28
|
+
const PillDate = forwardRef(function PillDate({ label, hideLabel, hint, error, optional, type = "date", name, value: controlled, defaultValue = "", onChange, min, max, step, disabledDate, required = false, disabled = false, placeholder = PLACEHOLDERS[type], locale, firstDay, format, labels, inline = false, layout, icon, className }, ref) {
|
|
29
|
+
const inputRef = useRef(null);
|
|
30
|
+
const triggerRef = useRef(null);
|
|
31
|
+
const boxRef = useRef(null);
|
|
32
|
+
const popoverRef = useRef(null);
|
|
33
|
+
useImperativeHandle(ref, () => triggerRef.current);
|
|
34
|
+
const validity = useValidity(error, inputRef);
|
|
35
|
+
const isClient = useIsClient();
|
|
36
|
+
const [own, setOwn] = useState(defaultValue);
|
|
37
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
38
|
+
const [draft, setDraft] = useState(null);
|
|
39
|
+
useFormReset(inputRef, () => setOwn(defaultValue));
|
|
40
|
+
const value = controlled ?? own;
|
|
41
|
+
const day = draft?.day ?? dayOf(value, type);
|
|
42
|
+
const time = draft?.time ?? timeOf(value, type);
|
|
43
|
+
const isFirst = useRef(true);
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (!isFirst.current) inputRef.current?.dispatchEvent(new Event("input", { bubbles: true }));
|
|
46
|
+
isFirst.current = false;
|
|
47
|
+
}, [value]);
|
|
48
|
+
const close = (focus) => {
|
|
49
|
+
setIsOpen(false);
|
|
50
|
+
setDraft(null);
|
|
51
|
+
if (focus) triggerRef.current?.focus();
|
|
52
|
+
};
|
|
53
|
+
usePopover(popoverRef, boxRef, isOpen && !inline, () => close(false));
|
|
54
|
+
const handleChoice = (nextDay, nextTime, isFinal) => {
|
|
55
|
+
const next = nextDay || nextTime ? toValue(type, nextDay, nextTime) : "";
|
|
56
|
+
setDraft(isFinal ? null : {
|
|
57
|
+
day: nextDay,
|
|
58
|
+
time: nextTime
|
|
59
|
+
});
|
|
60
|
+
if (next !== value) {
|
|
61
|
+
setOwn(next);
|
|
62
|
+
onChange?.(next);
|
|
63
|
+
}
|
|
64
|
+
if (isFinal && isOpen) close(true);
|
|
65
|
+
};
|
|
66
|
+
const handleKeys = (event) => {
|
|
67
|
+
if (event.key === "Escape") {
|
|
68
|
+
event.preventDefault();
|
|
69
|
+
event.stopPropagation();
|
|
70
|
+
close(true);
|
|
71
|
+
} else if (event.key === "Tab") {
|
|
72
|
+
const stops = [...event.currentTarget.querySelectorAll("button:not(:disabled), [tabindex=\"0\"]")].filter((stop) => stop.tabIndex === 0);
|
|
73
|
+
const edge = event.shiftKey ? stops[0] : stops[stops.length - 1];
|
|
74
|
+
if (document.activeElement === edge) {
|
|
75
|
+
event.preventDefault();
|
|
76
|
+
(event.shiftKey ? stops[stops.length - 1] : stops[0])?.focus();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const calendar = (isInline) => /* @__PURE__ */ jsx(Calendar, {
|
|
81
|
+
type,
|
|
82
|
+
day,
|
|
83
|
+
time,
|
|
84
|
+
min,
|
|
85
|
+
max,
|
|
86
|
+
step,
|
|
87
|
+
locale,
|
|
88
|
+
firstDay,
|
|
89
|
+
disabledDate,
|
|
90
|
+
labels: {
|
|
91
|
+
...CALENDAR_LABELS,
|
|
92
|
+
...labels
|
|
93
|
+
},
|
|
94
|
+
canClear: !required,
|
|
95
|
+
autoFocus: !isInline,
|
|
96
|
+
onChoose: handleChoice,
|
|
97
|
+
onDone: isInline ? void 0 : () => close(true)
|
|
98
|
+
});
|
|
99
|
+
const TypeGlyph = type === "time" ? ClockGlyph : CalendarGlyph;
|
|
100
|
+
return /* @__PURE__ */ jsx(FieldShell, {
|
|
101
|
+
label,
|
|
102
|
+
hideLabel,
|
|
103
|
+
hint,
|
|
104
|
+
optional,
|
|
105
|
+
layout,
|
|
106
|
+
className,
|
|
107
|
+
error: validity.error,
|
|
108
|
+
isText: !inline,
|
|
109
|
+
"data-kind": "text",
|
|
110
|
+
children: (control) => {
|
|
111
|
+
const native = /* @__PURE__ */ jsx("input", {
|
|
112
|
+
ref: inputRef,
|
|
113
|
+
type,
|
|
114
|
+
name,
|
|
115
|
+
value,
|
|
116
|
+
min,
|
|
117
|
+
max,
|
|
118
|
+
required,
|
|
119
|
+
disabled,
|
|
120
|
+
step: "any",
|
|
121
|
+
tabIndex: -1,
|
|
122
|
+
"aria-hidden": "true",
|
|
123
|
+
"data-mp": "date-value",
|
|
124
|
+
onChange: () => {},
|
|
125
|
+
onFocus: () => (triggerRef.current ?? boxRef.current?.querySelector("[tabindex=\"0\"]"))?.focus(),
|
|
126
|
+
onInput: validity.handlers.onInput,
|
|
127
|
+
onInvalid: validity.handlers.onInvalid
|
|
128
|
+
});
|
|
129
|
+
if (inline) return /* @__PURE__ */ jsxs("div", {
|
|
130
|
+
ref: boxRef,
|
|
131
|
+
"data-mp": "calendar",
|
|
132
|
+
"data-inline": "",
|
|
133
|
+
role: "group",
|
|
134
|
+
"aria-labelledby": `${control.id}label`,
|
|
135
|
+
...inertProps(disabled),
|
|
136
|
+
children: [native, isClient && calendar(true)]
|
|
137
|
+
});
|
|
138
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
139
|
+
ref: boxRef,
|
|
140
|
+
"data-mp": "field-box",
|
|
141
|
+
"data-type": "pill-date",
|
|
142
|
+
children: [
|
|
143
|
+
native,
|
|
144
|
+
icon && /* @__PURE__ */ jsx("span", {
|
|
145
|
+
"data-mp": "field-icon",
|
|
146
|
+
"aria-hidden": "true",
|
|
147
|
+
children: icon
|
|
148
|
+
}),
|
|
149
|
+
/* @__PURE__ */ jsx("button", {
|
|
150
|
+
...control,
|
|
151
|
+
ref: triggerRef,
|
|
152
|
+
type: "button",
|
|
153
|
+
"data-mp": "field-trigger",
|
|
154
|
+
"data-empty": value ? void 0 : "",
|
|
155
|
+
disabled,
|
|
156
|
+
"aria-labelledby": `${control.id}label ${control.id}value`,
|
|
157
|
+
"aria-haspopup": "dialog",
|
|
158
|
+
"aria-expanded": isOpen,
|
|
159
|
+
onClick: () => isOpen ? close(false) : setIsOpen(true),
|
|
160
|
+
onKeyDown: (event) => {
|
|
161
|
+
if (event.key === "ArrowDown") {
|
|
162
|
+
event.preventDefault();
|
|
163
|
+
setIsOpen(true);
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
167
|
+
id: `${control.id}value`,
|
|
168
|
+
dir: "auto",
|
|
169
|
+
children: value ? isClient ? formatValue(value, type, locale, format) : value : placeholder
|
|
170
|
+
})
|
|
171
|
+
}),
|
|
172
|
+
/* @__PURE__ */ jsx("span", {
|
|
173
|
+
"data-mp": "field-icon",
|
|
174
|
+
"aria-hidden": "true",
|
|
175
|
+
children: /* @__PURE__ */ jsx(TypeGlyph, {})
|
|
176
|
+
}),
|
|
177
|
+
/* @__PURE__ */ jsx("div", {
|
|
178
|
+
ref: popoverRef,
|
|
179
|
+
popover: "manual",
|
|
180
|
+
role: "dialog",
|
|
181
|
+
"aria-labelledby": `${control.id}label`,
|
|
182
|
+
"data-mp": "calendar",
|
|
183
|
+
"data-open": isOpen ? "" : void 0,
|
|
184
|
+
onKeyDown: handleKeys,
|
|
185
|
+
children: isOpen && calendar(false)
|
|
186
|
+
})
|
|
187
|
+
]
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
export { PillDate };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ComponentPropsWithoutRef, ReactNode } from "react";
|
|
2
|
+
import { FieldLayout } from "./FormContext.mjs";
|
|
3
|
+
/** What every field takes. */
|
|
4
|
+
export interface FieldProps {
|
|
5
|
+
/** Always required: it's the accessible name. */
|
|
6
|
+
label: ReactNode;
|
|
7
|
+
/** Keep the label for assistive technology only. */
|
|
8
|
+
hideLabel?: boolean;
|
|
9
|
+
/** Under the control, and read with it. */
|
|
10
|
+
hint?: ReactNode;
|
|
11
|
+
/** Your own error, e.g. from the server. It wins over the browser's. */
|
|
12
|
+
error?: ReactNode;
|
|
13
|
+
/** Writes "optional" after the label, or your own word. */
|
|
14
|
+
optional?: boolean | string;
|
|
15
|
+
}
|
|
16
|
+
/** To spread on the control. */
|
|
17
|
+
export interface FieldControlProps {
|
|
18
|
+
id: string;
|
|
19
|
+
"aria-describedby": string | undefined;
|
|
20
|
+
"aria-invalid": true | undefined;
|
|
21
|
+
}
|
|
22
|
+
export interface PillFieldProps extends FieldProps, Omit<ComponentPropsWithoutRef<"div">, "children" | "title"> {
|
|
23
|
+
/** The control, wired: `{(control) => <input {...control} />}`. */
|
|
24
|
+
children: (control: FieldControlProps) => ReactNode;
|
|
25
|
+
/** The label above the control (default), or beside it. */
|
|
26
|
+
layout?: FieldLayout;
|
|
27
|
+
/** At the end of the label's line, e.g. a slider's value. */
|
|
28
|
+
aside?: ReactNode;
|
|
29
|
+
/** Several controls under one label: the field is a group (a `<fieldset>`). */
|
|
30
|
+
group?: "group" | "radiogroup";
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A label, a hint and an error, wired to a control of yours.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* <PillField label="Rating">{(control) => <StarRating {...control} />}</PillField>
|
|
37
|
+
*/
|
|
38
|
+
export declare const PillField: import("react").ForwardRefExoticComponent<PillFieldProps & import("react").RefAttributes<HTMLElement>>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ComponentPropsWithoutRef, ReactNode } from "react";
|
|
2
|
+
import { FieldLayout } from "./FormContext.js";
|
|
3
|
+
/** What every field takes. */
|
|
4
|
+
export interface FieldProps {
|
|
5
|
+
/** Always required: it's the accessible name. */
|
|
6
|
+
label: ReactNode;
|
|
7
|
+
/** Keep the label for assistive technology only. */
|
|
8
|
+
hideLabel?: boolean;
|
|
9
|
+
/** Under the control, and read with it. */
|
|
10
|
+
hint?: ReactNode;
|
|
11
|
+
/** Your own error, e.g. from the server. It wins over the browser's. */
|
|
12
|
+
error?: ReactNode;
|
|
13
|
+
/** Writes "optional" after the label, or your own word. */
|
|
14
|
+
optional?: boolean | string;
|
|
15
|
+
}
|
|
16
|
+
/** To spread on the control. */
|
|
17
|
+
export interface FieldControlProps {
|
|
18
|
+
id: string;
|
|
19
|
+
"aria-describedby": string | undefined;
|
|
20
|
+
"aria-invalid": true | undefined;
|
|
21
|
+
}
|
|
22
|
+
export interface PillFieldProps extends FieldProps, Omit<ComponentPropsWithoutRef<"div">, "children" | "title"> {
|
|
23
|
+
/** The control, wired: `{(control) => <input {...control} />}`. */
|
|
24
|
+
children: (control: FieldControlProps) => ReactNode;
|
|
25
|
+
/** The label above the control (default), or beside it. */
|
|
26
|
+
layout?: FieldLayout;
|
|
27
|
+
/** At the end of the label's line, e.g. a slider's value. */
|
|
28
|
+
aside?: ReactNode;
|
|
29
|
+
/** Several controls under one label: the field is a group (a `<fieldset>`). */
|
|
30
|
+
group?: "group" | "radiogroup";
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A label, a hint and an error, wired to a control of yours.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* <PillField label="Rating">{(control) => <StarRating {...control} />}</PillField>
|
|
37
|
+
*/
|
|
38
|
+
export declare const PillField: import("react").ForwardRefExoticComponent<PillFieldProps & import("react").RefAttributes<HTMLElement>>;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
let react = require("react");
|
|
4
|
+
const require_FormContext = require("./FormContext.js");
|
|
5
|
+
const require_glyphs = require("./glyphs.js");
|
|
6
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
7
|
+
|
|
8
|
+
// src/PillForm/PillField.tsx
|
|
9
|
+
/** The shell, with the options only our own fields use. */
|
|
10
|
+
const FieldShell = (0, react.forwardRef)(function FieldShell({ label, hideLabel, hint, error, optional, layout, aside, group, isText, children, ...rest }, ref) {
|
|
11
|
+
const form = (0, react.useContext)(require_FormContext.FormContext);
|
|
12
|
+
const id = (0, react.useId)();
|
|
13
|
+
const hintId = `${id}hint`;
|
|
14
|
+
const errorId = `${id}error`;
|
|
15
|
+
const control = {
|
|
16
|
+
id,
|
|
17
|
+
"aria-describedby": [hint && hintId, error && errorId].filter(Boolean).join(" ") || void 0,
|
|
18
|
+
"aria-invalid": error ? true : void 0
|
|
19
|
+
};
|
|
20
|
+
const Root = group ? "fieldset" : "div";
|
|
21
|
+
const Label = group ? "legend" : "label";
|
|
22
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Root, {
|
|
23
|
+
...rest,
|
|
24
|
+
...group && {
|
|
25
|
+
role: group,
|
|
26
|
+
"aria-describedby": control["aria-describedby"],
|
|
27
|
+
"aria-invalid": group === "radiogroup" ? control["aria-invalid"] : void 0
|
|
28
|
+
},
|
|
29
|
+
ref,
|
|
30
|
+
"data-mp": "field",
|
|
31
|
+
"data-layout": layout ?? (isText && form.layout || "stacked"),
|
|
32
|
+
"data-invalid": error ? "" : void 0,
|
|
33
|
+
children: [
|
|
34
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Label, {
|
|
35
|
+
id: `${id}label`,
|
|
36
|
+
...!group && { htmlFor: id },
|
|
37
|
+
"data-mp": "field-label",
|
|
38
|
+
"data-hidden": hideLabel ? "" : void 0,
|
|
39
|
+
children: [label, optional && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [" ", /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
40
|
+
"data-mp": "field-optional",
|
|
41
|
+
children: optional === true ? "optional" : optional
|
|
42
|
+
})] })]
|
|
43
|
+
}),
|
|
44
|
+
aside !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("output", {
|
|
45
|
+
"data-mp": "field-aside",
|
|
46
|
+
htmlFor: id,
|
|
47
|
+
children: aside
|
|
48
|
+
}),
|
|
49
|
+
children(control),
|
|
50
|
+
hint && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
51
|
+
id: hintId,
|
|
52
|
+
"data-mp": "field-hint",
|
|
53
|
+
children: hint
|
|
54
|
+
}),
|
|
55
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
56
|
+
id: errorId,
|
|
57
|
+
"data-mp": "field-error",
|
|
58
|
+
"aria-live": "polite",
|
|
59
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: error && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
|
|
60
|
+
"aria-hidden": "true",
|
|
61
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_glyphs.AlertGlyph, {})
|
|
62
|
+
}), error] }) })
|
|
63
|
+
})
|
|
64
|
+
]
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
/**
|
|
68
|
+
* A label, a hint and an error, wired to a control of yours.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* <PillField label="Rating">{(control) => <StarRating {...control} />}</PillField>
|
|
72
|
+
*/
|
|
73
|
+
const PillField = (0, react.forwardRef)(function PillField(props, ref) {
|
|
74
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FieldShell, {
|
|
75
|
+
...props,
|
|
76
|
+
ref
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
exports.FieldShell = FieldShell;
|
|
81
|
+
exports.PillField = PillField;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { forwardRef, useContext, useId } from "react";
|
|
4
|
+
import { FormContext } from "./FormContext.mjs";
|
|
5
|
+
import { AlertGlyph } from "./glyphs.mjs";
|
|
6
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
|
|
8
|
+
// src/PillForm/PillField.tsx
|
|
9
|
+
/** The shell, with the options only our own fields use. */
|
|
10
|
+
const FieldShell = forwardRef(function FieldShell({ label, hideLabel, hint, error, optional, layout, aside, group, isText, children, ...rest }, ref) {
|
|
11
|
+
const form = useContext(FormContext);
|
|
12
|
+
const id = useId();
|
|
13
|
+
const hintId = `${id}hint`;
|
|
14
|
+
const errorId = `${id}error`;
|
|
15
|
+
const control = {
|
|
16
|
+
id,
|
|
17
|
+
"aria-describedby": [hint && hintId, error && errorId].filter(Boolean).join(" ") || void 0,
|
|
18
|
+
"aria-invalid": error ? true : void 0
|
|
19
|
+
};
|
|
20
|
+
const Root = group ? "fieldset" : "div";
|
|
21
|
+
const Label = group ? "legend" : "label";
|
|
22
|
+
return /* @__PURE__ */ jsxs(Root, {
|
|
23
|
+
...rest,
|
|
24
|
+
...group && {
|
|
25
|
+
role: group,
|
|
26
|
+
"aria-describedby": control["aria-describedby"],
|
|
27
|
+
"aria-invalid": group === "radiogroup" ? control["aria-invalid"] : void 0
|
|
28
|
+
},
|
|
29
|
+
ref,
|
|
30
|
+
"data-mp": "field",
|
|
31
|
+
"data-layout": layout ?? (isText && form.layout || "stacked"),
|
|
32
|
+
"data-invalid": error ? "" : void 0,
|
|
33
|
+
children: [
|
|
34
|
+
/* @__PURE__ */ jsxs(Label, {
|
|
35
|
+
id: `${id}label`,
|
|
36
|
+
...!group && { htmlFor: id },
|
|
37
|
+
"data-mp": "field-label",
|
|
38
|
+
"data-hidden": hideLabel ? "" : void 0,
|
|
39
|
+
children: [label, optional && /* @__PURE__ */ jsxs(Fragment$1, { children: [" ", /* @__PURE__ */ jsx("span", {
|
|
40
|
+
"data-mp": "field-optional",
|
|
41
|
+
children: optional === true ? "optional" : optional
|
|
42
|
+
})] })]
|
|
43
|
+
}),
|
|
44
|
+
aside !== void 0 && /* @__PURE__ */ jsx("output", {
|
|
45
|
+
"data-mp": "field-aside",
|
|
46
|
+
htmlFor: id,
|
|
47
|
+
children: aside
|
|
48
|
+
}),
|
|
49
|
+
children(control),
|
|
50
|
+
hint && /* @__PURE__ */ jsx("div", {
|
|
51
|
+
id: hintId,
|
|
52
|
+
"data-mp": "field-hint",
|
|
53
|
+
children: hint
|
|
54
|
+
}),
|
|
55
|
+
/* @__PURE__ */ jsx("div", {
|
|
56
|
+
id: errorId,
|
|
57
|
+
"data-mp": "field-error",
|
|
58
|
+
"aria-live": "polite",
|
|
59
|
+
children: /* @__PURE__ */ jsx("div", { children: error && /* @__PURE__ */ jsxs("span", { children: [/* @__PURE__ */ jsx("i", {
|
|
60
|
+
"aria-hidden": "true",
|
|
61
|
+
children: /* @__PURE__ */ jsx(AlertGlyph, {})
|
|
62
|
+
}), error] }) })
|
|
63
|
+
})
|
|
64
|
+
]
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
/**
|
|
68
|
+
* A label, a hint and an error, wired to a control of yours.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* <PillField label="Rating">{(control) => <StarRating {...control} />}</PillField>
|
|
72
|
+
*/
|
|
73
|
+
const PillField = forwardRef(function PillField(props, ref) {
|
|
74
|
+
return /* @__PURE__ */ jsx(FieldShell, {
|
|
75
|
+
...props,
|
|
76
|
+
ref
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
export { FieldShell, PillField };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ComponentPropsWithoutRef, ReactNode } from "react";
|
|
2
|
+
export interface PillFieldsProps extends ComponentPropsWithoutRef<"fieldset"> {
|
|
3
|
+
/** What they're about. */
|
|
4
|
+
label?: ReactNode;
|
|
5
|
+
/** Two fields side by side, where there's room. */
|
|
6
|
+
columns?: 1 | 2;
|
|
7
|
+
/** A line between one field and the next. */
|
|
8
|
+
separators?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/** Fields that go together. */
|
|
11
|
+
export declare const PillFields: import("react").ForwardRefExoticComponent<PillFieldsProps & import("react").RefAttributes<HTMLFieldSetElement>>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ComponentPropsWithoutRef, ReactNode } from "react";
|
|
2
|
+
export interface PillFieldsProps extends ComponentPropsWithoutRef<"fieldset"> {
|
|
3
|
+
/** What they're about. */
|
|
4
|
+
label?: ReactNode;
|
|
5
|
+
/** Two fields side by side, where there's room. */
|
|
6
|
+
columns?: 1 | 2;
|
|
7
|
+
/** A line between one field and the next. */
|
|
8
|
+
separators?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/** Fields that go together. */
|
|
11
|
+
export declare const PillFields: import("react").ForwardRefExoticComponent<PillFieldsProps & import("react").RefAttributes<HTMLFieldSetElement>>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
let react = require("react");
|
|
2
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
3
|
+
|
|
4
|
+
// src/PillForm/PillFields.tsx
|
|
5
|
+
/** Fields that go together. */
|
|
6
|
+
const PillFields = (0, react.forwardRef)(function PillFields({ label, columns = 1, separators = false, children, ...rest }, ref) {
|
|
7
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("fieldset", {
|
|
8
|
+
role: label ? void 0 : "none",
|
|
9
|
+
...rest,
|
|
10
|
+
ref,
|
|
11
|
+
"data-mp": "fields",
|
|
12
|
+
"data-columns": columns,
|
|
13
|
+
"data-separators": separators ? "" : void 0,
|
|
14
|
+
children: [label && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("legend", {
|
|
15
|
+
"data-mp": "fields-label",
|
|
16
|
+
children: label
|
|
17
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children })]
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
exports.PillFields = PillFields;
|