seppia 0.0.0-stage → 0.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/LICENSE +21 -0
- package/README.md +92 -3
- package/dist/chunk-2PABDSNH.cjs +208 -0
- package/dist/chunk-2Z4YKJMT.js +329 -0
- package/dist/chunk-344MRWFO.js +25 -0
- package/dist/chunk-3A2LHCPV.cjs +30 -0
- package/dist/chunk-3NQ776G6.cjs +204 -0
- package/dist/chunk-3XIEBFVO.cjs +130 -0
- package/dist/chunk-4IHNW52F.cjs +197 -0
- package/dist/chunk-4YGBUMQC.js +160 -0
- package/dist/chunk-5ARTY5RT.cjs +66 -0
- package/dist/chunk-5PAJS63K.cjs +156 -0
- package/dist/chunk-5Z32CAHE.cjs +261 -0
- package/dist/chunk-66ITQTT2.js +108 -0
- package/dist/chunk-6EABLOB7.js +190 -0
- package/dist/chunk-6FF73V3S.js +190 -0
- package/dist/chunk-6LRDNOZX.cjs +138 -0
- package/dist/chunk-76MEQHGW.js +192 -0
- package/dist/chunk-7B2YEOYF.js +26 -0
- package/dist/chunk-7Y22U2ZF.js +370 -0
- package/dist/chunk-AFGJQET4.js +186 -0
- package/dist/chunk-AG3OBSP5.cjs +216 -0
- package/dist/chunk-AHRXESD2.js +126 -0
- package/dist/chunk-AJPI65BL.cjs +153 -0
- package/dist/chunk-CCDDQHCS.js +182 -0
- package/dist/chunk-CGX6YCV6.js +130 -0
- package/dist/chunk-CPUW5LDN.cjs +28 -0
- package/dist/chunk-DAO7YH2R.cjs +165 -0
- package/dist/chunk-DO5WEBTN.cjs +139 -0
- package/dist/chunk-DUUDPN7C.cjs +203 -0
- package/dist/chunk-EOPY2VWT.cjs +185 -0
- package/dist/chunk-EUQ6BCML.cjs +175 -0
- package/dist/chunk-EYO4XMKU.js +145 -0
- package/dist/chunk-F7UECO7G.js +175 -0
- package/dist/chunk-FGJDDSUJ.js +303 -0
- package/dist/chunk-G5UZZ2XG.cjs +52 -0
- package/dist/chunk-GJ6WO63L.js +216 -0
- package/dist/chunk-GP32TY6P.cjs +409 -0
- package/dist/chunk-HQLB5Z37.cjs +275 -0
- package/dist/chunk-HSXGQNQ6.js +143 -0
- package/dist/chunk-I2XZ2WMY.js +385 -0
- package/dist/chunk-I525FOTN.cjs +214 -0
- package/dist/chunk-IAPRIVJO.js +157 -0
- package/dist/chunk-IUSSIILO.cjs +393 -0
- package/dist/chunk-JV6GJ3JJ.js +92 -0
- package/dist/chunk-KPG24YFL.js +30 -0
- package/dist/chunk-LGBMJIY6.js +174 -0
- package/dist/chunk-LYEOVFOQ.cjs +148 -0
- package/dist/chunk-LYYMITLC.js +238 -0
- package/dist/chunk-M42F5QS5.cjs +212 -0
- package/dist/chunk-NN3HMY7H.cjs +260 -0
- package/dist/chunk-NU5MGYFP.cjs +167 -0
- package/dist/chunk-OCIKUJ3U.js +117 -0
- package/dist/chunk-PBMXL53R.cjs +39 -0
- package/dist/chunk-PGEK6DFE.cjs +351 -0
- package/dist/chunk-QPWVBVDC.cjs +130 -0
- package/dist/chunk-QWYHH465.cjs +117 -0
- package/dist/chunk-RFCZJPGM.js +116 -0
- package/dist/chunk-RIBXHAKG.cjs +179 -0
- package/dist/chunk-SDWRKTFC.cjs +158 -0
- package/dist/chunk-SMY24MVU.js +92 -0
- package/dist/chunk-SSARMSS3.cjs +325 -0
- package/dist/chunk-T533JPW5.js +131 -0
- package/dist/chunk-T7AMVHIB.js +221 -0
- package/dist/chunk-TVGVZSIA.js +130 -0
- package/dist/chunk-UFU5S3LK.cjs +244 -0
- package/dist/chunk-UFUN2OKY.js +35 -0
- package/dist/chunk-VDSMO63G.cjs +153 -0
- package/dist/chunk-VHXWP5OX.cjs +115 -0
- package/dist/chunk-VW32EE3I.js +153 -0
- package/dist/chunk-WGFJLFTP.js +40 -0
- package/dist/chunk-WSL2OVTO.js +136 -0
- package/dist/chunk-WVWVJSU2.cjs +309 -0
- package/dist/chunk-XLZPYDNI.js +287 -0
- package/dist/chunk-XUBFOAT4.js +239 -0
- package/dist/chunk-Y3UCNSXF.js +253 -0
- package/dist/chunk-YDJMVDAJ.cjs +196 -0
- package/dist/chunk-ZF5HY2K4.cjs +238 -0
- package/dist/chunk-ZXKEYL6L.js +181 -0
- package/dist/chunk-ZZYMYQU2.js +108 -0
- package/dist/components/accordion.cjs +26 -0
- package/dist/components/accordion.d.cts +41 -0
- package/dist/components/accordion.d.ts +41 -0
- package/dist/components/accordion.js +5 -0
- package/dist/components/calendar.cjs +14 -0
- package/dist/components/calendar.d.cts +41 -0
- package/dist/components/calendar.d.ts +41 -0
- package/dist/components/calendar.js +5 -0
- package/dist/components/checkbox.cjs +14 -0
- package/dist/components/checkbox.d.cts +27 -0
- package/dist/components/checkbox.d.ts +27 -0
- package/dist/components/checkbox.js +5 -0
- package/dist/components/chip-select.cjs +14 -0
- package/dist/components/chip-select.d.cts +31 -0
- package/dist/components/chip-select.d.ts +31 -0
- package/dist/components/chip-select.js +5 -0
- package/dist/components/clock.cjs +12 -0
- package/dist/components/clock.d.cts +25 -0
- package/dist/components/clock.d.ts +25 -0
- package/dist/components/clock.js +3 -0
- package/dist/components/color-picker.cjs +14 -0
- package/dist/components/color-picker.d.cts +23 -0
- package/dist/components/color-picker.d.ts +23 -0
- package/dist/components/color-picker.js +5 -0
- package/dist/components/command-palette.cjs +20 -0
- package/dist/components/command-palette.d.cts +53 -0
- package/dist/components/command-palette.d.ts +53 -0
- package/dist/components/command-palette.js +7 -0
- package/dist/components/date-picker.cjs +18 -0
- package/dist/components/date-picker.d.cts +40 -0
- package/dist/components/date-picker.d.ts +40 -0
- package/dist/components/date-picker.js +9 -0
- package/dist/components/drawer.cjs +16 -0
- package/dist/components/drawer.d.cts +22 -0
- package/dist/components/drawer.d.ts +22 -0
- package/dist/components/drawer.js +7 -0
- package/dist/components/floating-panel.cjs +13 -0
- package/dist/components/floating-panel.d.cts +25 -0
- package/dist/components/floating-panel.d.ts +25 -0
- package/dist/components/floating-panel.js +4 -0
- package/dist/components/hold-button.cjs +13 -0
- package/dist/components/hold-button.d.cts +30 -0
- package/dist/components/hold-button.d.ts +30 -0
- package/dist/components/hold-button.js +4 -0
- package/dist/components/knob.cjs +15 -0
- package/dist/components/knob.d.cts +33 -0
- package/dist/components/knob.d.ts +33 -0
- package/dist/components/knob.js +6 -0
- package/dist/components/magnetic-button.cjs +13 -0
- package/dist/components/magnetic-button.d.cts +23 -0
- package/dist/components/magnetic-button.d.ts +23 -0
- package/dist/components/magnetic-button.js +4 -0
- package/dist/components/morph-button.cjs +13 -0
- package/dist/components/morph-button.d.cts +34 -0
- package/dist/components/morph-button.d.ts +34 -0
- package/dist/components/morph-button.js +4 -0
- package/dist/components/morph-dialog.cjs +32 -0
- package/dist/components/morph-dialog.d.cts +30 -0
- package/dist/components/morph-dialog.d.ts +30 -0
- package/dist/components/morph-dialog.js +7 -0
- package/dist/components/number-field.cjs +15 -0
- package/dist/components/number-field.d.cts +32 -0
- package/dist/components/number-field.d.ts +32 -0
- package/dist/components/number-field.js +6 -0
- package/dist/components/pin-input.cjs +14 -0
- package/dist/components/pin-input.d.cts +29 -0
- package/dist/components/pin-input.d.ts +29 -0
- package/dist/components/pin-input.js +5 -0
- package/dist/components/popover.cjs +16 -0
- package/dist/components/popover.d.cts +26 -0
- package/dist/components/popover.d.ts +26 -0
- package/dist/components/popover.js +7 -0
- package/dist/components/progress.cjs +17 -0
- package/dist/components/progress.d.cts +39 -0
- package/dist/components/progress.d.ts +39 -0
- package/dist/components/progress.js +4 -0
- package/dist/components/radial-menu.cjs +14 -0
- package/dist/components/radial-menu.d.cts +31 -0
- package/dist/components/radial-menu.d.ts +31 -0
- package/dist/components/radial-menu.js +5 -0
- package/dist/components/radio-group.cjs +14 -0
- package/dist/components/radio-group.d.cts +34 -0
- package/dist/components/radio-group.d.ts +34 -0
- package/dist/components/radio-group.js +5 -0
- package/dist/components/resizable-panels.cjs +18 -0
- package/dist/components/resizable-panels.d.cts +24 -0
- package/dist/components/resizable-panels.d.ts +24 -0
- package/dist/components/resizable-panels.js +5 -0
- package/dist/components/segmented-control.cjs +14 -0
- package/dist/components/segmented-control.d.cts +34 -0
- package/dist/components/segmented-control.d.ts +34 -0
- package/dist/components/segmented-control.js +5 -0
- package/dist/components/slider.cjs +15 -0
- package/dist/components/slider.d.cts +39 -0
- package/dist/components/slider.d.ts +39 -0
- package/dist/components/slider.js +6 -0
- package/dist/components/sortable-list.cjs +13 -0
- package/dist/components/sortable-list.d.cts +24 -0
- package/dist/components/sortable-list.d.ts +24 -0
- package/dist/components/sortable-list.js +4 -0
- package/dist/components/sparkline.cjs +14 -0
- package/dist/components/sparkline.d.cts +28 -0
- package/dist/components/sparkline.d.ts +28 -0
- package/dist/components/sparkline.js +5 -0
- package/dist/components/swipe-confirm.cjs +13 -0
- package/dist/components/swipe-confirm.d.cts +18 -0
- package/dist/components/swipe-confirm.d.ts +18 -0
- package/dist/components/swipe-confirm.js +4 -0
- package/dist/components/switch.cjs +15 -0
- package/dist/components/switch.d.cts +29 -0
- package/dist/components/switch.d.ts +29 -0
- package/dist/components/switch.js +6 -0
- package/dist/components/tabs.cjs +30 -0
- package/dist/components/tabs.d.cts +29 -0
- package/dist/components/tabs.d.ts +29 -0
- package/dist/components/tabs.js +5 -0
- package/dist/components/tether.cjs +16 -0
- package/dist/components/tether.d.cts +35 -0
- package/dist/components/tether.d.ts +35 -0
- package/dist/components/tether.js +3 -0
- package/dist/components/theme-switch.cjs +14 -0
- package/dist/components/theme-switch.d.cts +24 -0
- package/dist/components/theme-switch.d.ts +24 -0
- package/dist/components/theme-switch.js +5 -0
- package/dist/components/toaster.cjs +21 -0
- package/dist/components/toaster.d.cts +71 -0
- package/dist/components/toaster.d.ts +71 -0
- package/dist/components/toaster.js +4 -0
- package/dist/components/wheel-picker.cjs +15 -0
- package/dist/components/wheel-picker.d.cts +27 -0
- package/dist/components/wheel-picker.d.ts +27 -0
- package/dist/components/wheel-picker.js +6 -0
- package/dist/css/accordion.css +2 -0
- package/dist/css/base.css +2 -0
- package/dist/css/calendar.css +2 -0
- package/dist/css/checkbox.css +2 -0
- package/dist/css/chip-select.css +2 -0
- package/dist/css/clock.css +2 -0
- package/dist/css/color-picker.css +2 -0
- package/dist/css/command-palette.css +2 -0
- package/dist/css/date-picker.css +2 -0
- package/dist/css/drawer.css +2 -0
- package/dist/css/floating-panel.css +2 -0
- package/dist/css/hold-button.css +2 -0
- package/dist/css/knob.css +2 -0
- package/dist/css/magnetic-button.css +2 -0
- package/dist/css/morph-button.css +2 -0
- package/dist/css/morph-dialog.css +2 -0
- package/dist/css/number-field.css +2 -0
- package/dist/css/pin-input.css +2 -0
- package/dist/css/popover.css +2 -0
- package/dist/css/progress.css +2 -0
- package/dist/css/radial-menu.css +2 -0
- package/dist/css/radio-group.css +2 -0
- package/dist/css/resizable-panels.css +2 -0
- package/dist/css/segmented-control.css +2 -0
- package/dist/css/slider.css +2 -0
- package/dist/css/sortable-list.css +2 -0
- package/dist/css/sparkline.css +2 -0
- package/dist/css/swipe-confirm.css +2 -0
- package/dist/css/switch.css +2 -0
- package/dist/css/tabs.css +2 -0
- package/dist/css/tether.css +2 -0
- package/dist/css/theme-switch.css +2 -0
- package/dist/css/toaster.css +2 -0
- package/dist/css/wheel-picker.css +2 -0
- package/dist/index.cjs +249 -0
- package/dist/index.d.cts +77 -0
- package/dist/index.d.ts +77 -0
- package/dist/index.js +40 -0
- package/dist/styles.css +2 -0
- package/package.json +98 -6
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { haptic, useIsoLayoutEffect, mergeRefs } from './chunk-WGFJLFTP.js';
|
|
3
|
+
import { useMotionPreset, cx } from './chunk-UFUN2OKY.js';
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { useMotionValue, useTransform, animate, motion, AnimatePresence } from 'motion/react';
|
|
6
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
7
|
+
|
|
8
|
+
var WIDTH = { type: "spring", stiffness: 380, damping: 30 };
|
|
9
|
+
var SWAP = { type: "spring", stiffness: 520, damping: 34 };
|
|
10
|
+
var MorphButton = React.forwardRef(function MorphButton2({
|
|
11
|
+
onAction,
|
|
12
|
+
status: statusProp,
|
|
13
|
+
variant = "collapse",
|
|
14
|
+
progress = 0,
|
|
15
|
+
children,
|
|
16
|
+
loadingLabel = "Working",
|
|
17
|
+
successLabel = "Done",
|
|
18
|
+
errorLabel = "Try again",
|
|
19
|
+
resetAfter = 1800,
|
|
20
|
+
tone = "ink",
|
|
21
|
+
size = "md",
|
|
22
|
+
haptics = true,
|
|
23
|
+
onStatusChange,
|
|
24
|
+
className,
|
|
25
|
+
disabled,
|
|
26
|
+
...rest
|
|
27
|
+
}, ref) {
|
|
28
|
+
const [internal, setInternal] = React.useState("idle");
|
|
29
|
+
const status = statusProp ?? internal;
|
|
30
|
+
const { t, reduced } = useMotionPreset();
|
|
31
|
+
const local = React.useRef(null);
|
|
32
|
+
const measureRef = React.useRef(null);
|
|
33
|
+
const width = useMotionValue("auto");
|
|
34
|
+
const fill = useMotionValue(0);
|
|
35
|
+
const fillScale = useTransform(fill, (v) => v);
|
|
36
|
+
const timer = React.useRef(void 0);
|
|
37
|
+
const mounted = React.useRef(true);
|
|
38
|
+
React.useEffect(() => () => {
|
|
39
|
+
mounted.current = false;
|
|
40
|
+
clearTimeout(timer.current);
|
|
41
|
+
}, []);
|
|
42
|
+
const prev = React.useRef(status);
|
|
43
|
+
React.useEffect(() => {
|
|
44
|
+
if (prev.current === status) return;
|
|
45
|
+
prev.current = status;
|
|
46
|
+
onStatusChange?.(status);
|
|
47
|
+
if (haptics && status === "success") haptic([6, 40, 10]);
|
|
48
|
+
if (haptics && status === "error") haptic([20, 30, 20]);
|
|
49
|
+
if (status === "error" && local.current && !reduced) {
|
|
50
|
+
animate(local.current, { x: [0, -7, 6, -4, 3, 0] }, { duration: 0.42, ease: "easeOut" });
|
|
51
|
+
}
|
|
52
|
+
if ((status === "success" || status === "error") && statusProp === void 0 && resetAfter > 0) {
|
|
53
|
+
clearTimeout(timer.current);
|
|
54
|
+
timer.current = setTimeout(() => mounted.current && setInternal("idle"), resetAfter);
|
|
55
|
+
}
|
|
56
|
+
}, [status]);
|
|
57
|
+
useIsoLayoutEffect(() => {
|
|
58
|
+
const el = local.current;
|
|
59
|
+
const measure = measureRef.current;
|
|
60
|
+
if (!el || !measure) return;
|
|
61
|
+
if (variant !== "collapse") {
|
|
62
|
+
width.set("auto");
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const natural = measure.offsetWidth;
|
|
66
|
+
const circle = el.offsetHeight;
|
|
67
|
+
const target = status === "loading" ? circle : status === "idle" ? natural : Math.max(circle, natural * 0.86);
|
|
68
|
+
if (width.get() === "auto") {
|
|
69
|
+
width.set(target);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
animate(width, target, t(status === "loading" ? { type: "spring", stiffness: 420, damping: 32 } : { type: "spring", stiffness: 300, damping: 19 }));
|
|
73
|
+
}, [status, variant, size, children, successLabel, errorLabel]);
|
|
74
|
+
React.useEffect(() => {
|
|
75
|
+
if (variant !== "progress") return;
|
|
76
|
+
const target = status === "loading" ? progress : status === "success" ? 1 : 0;
|
|
77
|
+
animate(fill, target, t(status === "idle" ? { duration: 0.2 } : { type: "spring", stiffness: 120, damping: 22 }));
|
|
78
|
+
}, [progress, status, variant]);
|
|
79
|
+
const handleClick = async (event) => {
|
|
80
|
+
if (status === "loading" || disabled) return;
|
|
81
|
+
const result = onAction?.(event);
|
|
82
|
+
if (statusProp !== void 0 || !(result instanceof Promise || result && typeof result.then === "function")) return;
|
|
83
|
+
clearTimeout(timer.current);
|
|
84
|
+
setInternal("loading");
|
|
85
|
+
try {
|
|
86
|
+
await result;
|
|
87
|
+
if (mounted.current) setInternal("success");
|
|
88
|
+
} catch {
|
|
89
|
+
if (mounted.current) setInternal("error");
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
const label = status === "loading" ? loadingLabel : status === "success" ? successLabel : status === "error" ? errorLabel : children;
|
|
93
|
+
const percent = Math.round(Math.min(1, Math.max(0, progress)) * 100);
|
|
94
|
+
return /* @__PURE__ */ jsxs(
|
|
95
|
+
motion.button,
|
|
96
|
+
{
|
|
97
|
+
...rest,
|
|
98
|
+
ref: mergeRefs(local, ref),
|
|
99
|
+
type: rest.type ?? "button",
|
|
100
|
+
layout: variant === "inline" ? true : void 0,
|
|
101
|
+
transition: t(WIDTH),
|
|
102
|
+
style: { ...rest.style, width: variant === "collapse" ? width : void 0, borderRadius: 999 },
|
|
103
|
+
className: cx("fl-reset-button fl-morph", className),
|
|
104
|
+
"data-variant": variant,
|
|
105
|
+
"data-status": status,
|
|
106
|
+
"data-tone": tone,
|
|
107
|
+
"data-size": size,
|
|
108
|
+
disabled,
|
|
109
|
+
"aria-disabled": status === "loading" || void 0,
|
|
110
|
+
"aria-busy": status === "loading" || void 0,
|
|
111
|
+
whileTap: reduced || status === "loading" ? void 0 : { scale: 0.96 },
|
|
112
|
+
onClick: handleClick,
|
|
113
|
+
children: [
|
|
114
|
+
variant === "collapse" && /* @__PURE__ */ jsx("span", { ref: measureRef, className: "fl-morph__measure", "aria-hidden": true, children }),
|
|
115
|
+
variant === "progress" && /* @__PURE__ */ jsx(motion.span, { className: "fl-morph__fill", "aria-hidden": true, style: { scaleX: fillScale } }),
|
|
116
|
+
/* @__PURE__ */ jsx("span", { className: "fl-morph__stage", children: /* @__PURE__ */ jsx(AnimatePresence, { mode: "popLayout", initial: false, children: /* @__PURE__ */ jsxs(
|
|
117
|
+
motion.span,
|
|
118
|
+
{
|
|
119
|
+
className: "fl-morph__content",
|
|
120
|
+
layout: variant === "inline" ? "position" : void 0,
|
|
121
|
+
initial: { opacity: 0, y: variant === "collapse" ? 0 : 14, scale: variant === "collapse" ? 0.6 : 1, filter: "blur(3px)" },
|
|
122
|
+
animate: { opacity: 1, y: 0, scale: 1, filter: "blur(0px)" },
|
|
123
|
+
exit: { opacity: 0, y: variant === "collapse" ? 0 : -14, scale: variant === "collapse" ? 0.6 : 1, filter: "blur(3px)" },
|
|
124
|
+
transition: t({ ...SWAP, filter: { duration: 0.18, ease: "easeOut" } }),
|
|
125
|
+
children: [
|
|
126
|
+
status === "loading" && /* @__PURE__ */ jsx(Spinner, {}),
|
|
127
|
+
status === "success" && /* @__PURE__ */ jsx(Glyph, { kind: "success" }),
|
|
128
|
+
status === "error" && /* @__PURE__ */ jsx(Glyph, { kind: "error" }),
|
|
129
|
+
!(variant === "collapse" && status === "loading") && /* @__PURE__ */ jsxs("span", { className: "fl-morph__label", children: [
|
|
130
|
+
label,
|
|
131
|
+
variant === "progress" && status === "loading" && /* @__PURE__ */ jsxs("span", { className: "fl-morph__percent", children: [
|
|
132
|
+
" ",
|
|
133
|
+
percent,
|
|
134
|
+
"%"
|
|
135
|
+
] })
|
|
136
|
+
] })
|
|
137
|
+
]
|
|
138
|
+
},
|
|
139
|
+
status
|
|
140
|
+
) }) }),
|
|
141
|
+
/* @__PURE__ */ jsx("span", { className: "fl-sr-only", "aria-live": "polite", children: status === "idle" ? "" : typeof label === "string" ? label : status })
|
|
142
|
+
]
|
|
143
|
+
}
|
|
144
|
+
);
|
|
145
|
+
});
|
|
146
|
+
function Spinner() {
|
|
147
|
+
return /* @__PURE__ */ jsxs("svg", { className: "fl-morph__spinner", viewBox: "0 0 20 20", "aria-hidden": true, children: [
|
|
148
|
+
/* @__PURE__ */ jsx("circle", { cx: "10", cy: "10", r: "7.5", fill: "none", stroke: "currentColor", strokeOpacity: "0.22", strokeWidth: "2" }),
|
|
149
|
+
/* @__PURE__ */ jsx("circle", { cx: "10", cy: "10", r: "7.5", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeDasharray: "14 33.1" })
|
|
150
|
+
] });
|
|
151
|
+
}
|
|
152
|
+
function Glyph({ kind }) {
|
|
153
|
+
const { t } = useMotionPreset();
|
|
154
|
+
return /* @__PURE__ */ jsx("svg", { className: "fl-morph__glyph", viewBox: "0 0 20 20", "aria-hidden": true, children: kind === "success" ? /* @__PURE__ */ jsx(
|
|
155
|
+
motion.path,
|
|
156
|
+
{
|
|
157
|
+
d: "M5 10.4 L8.4 13.6 L15 6.6",
|
|
158
|
+
fill: "none",
|
|
159
|
+
stroke: "currentColor",
|
|
160
|
+
strokeWidth: "2.2",
|
|
161
|
+
strokeLinecap: "round",
|
|
162
|
+
strokeLinejoin: "round",
|
|
163
|
+
initial: { pathLength: 0 },
|
|
164
|
+
animate: { pathLength: 1 },
|
|
165
|
+
transition: t({ type: "spring", stiffness: 200, damping: 22, delay: 0.1 })
|
|
166
|
+
}
|
|
167
|
+
) : /* @__PURE__ */ jsx(
|
|
168
|
+
motion.path,
|
|
169
|
+
{
|
|
170
|
+
d: "M6 6 L14 14 M14 6 L6 14",
|
|
171
|
+
fill: "none",
|
|
172
|
+
stroke: "currentColor",
|
|
173
|
+
strokeWidth: "2.2",
|
|
174
|
+
strokeLinecap: "round",
|
|
175
|
+
initial: { pathLength: 0 },
|
|
176
|
+
animate: { pathLength: 1 },
|
|
177
|
+
transition: t({ type: "spring", stiffness: 220, damping: 24, delay: 0.08 })
|
|
178
|
+
}
|
|
179
|
+
) });
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export { MorphButton };
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useScrollLock, useFocusTrap, useEscape } from './chunk-SMY24MVU.js';
|
|
3
|
+
import { Portal } from './chunk-7B2YEOYF.js';
|
|
4
|
+
import { useControllableState } from './chunk-KPG24YFL.js';
|
|
5
|
+
import { cx, useMotionPreset } from './chunk-UFUN2OKY.js';
|
|
6
|
+
import * as React from 'react';
|
|
7
|
+
import { motion, AnimatePresence, MotionConfig } from 'motion/react';
|
|
8
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
9
|
+
|
|
10
|
+
var MorphContext = React.createContext(null);
|
|
11
|
+
var useMorph = () => {
|
|
12
|
+
const ctx = React.useContext(MorphContext);
|
|
13
|
+
if (!ctx) throw new Error("MorphDialog parts must be rendered inside <MorphDialog>.");
|
|
14
|
+
return ctx;
|
|
15
|
+
};
|
|
16
|
+
var MORPH = { type: "spring", stiffness: 320, damping: 32, mass: 0.9 };
|
|
17
|
+
function MorphDialog({ open: openProp, defaultOpen = false, onOpenChange, children, container }) {
|
|
18
|
+
const [open, setOpen] = useControllableState({ value: openProp, defaultValue: defaultOpen, onChange: onOpenChange });
|
|
19
|
+
const id = React.useId();
|
|
20
|
+
const triggerRef = React.useRef(null);
|
|
21
|
+
const { t } = useMotionPreset();
|
|
22
|
+
return /* @__PURE__ */ jsx(MorphContext.Provider, { value: { open, setOpen, id, triggerRef, container }, children: /* @__PURE__ */ jsx(MotionConfig, { transition: t(MORPH), children }) });
|
|
23
|
+
}
|
|
24
|
+
var MorphDialogTrigger = React.forwardRef(function MorphDialogTrigger2({ className, children, style, onClick, ...rest }, ref) {
|
|
25
|
+
const { open, setOpen, id, triggerRef } = useMorph();
|
|
26
|
+
const [size, setSize] = React.useState(null);
|
|
27
|
+
return (
|
|
28
|
+
// The wrapper keeps the trigger's footprint while its surface is "inside" the dialog.
|
|
29
|
+
/* @__PURE__ */ jsx("span", { className: "fl-morph-dialog__slot", style: open && size ? { width: size.width, height: size.height } : void 0, children: !open && /* @__PURE__ */ jsx(
|
|
30
|
+
motion.button,
|
|
31
|
+
{
|
|
32
|
+
...rest,
|
|
33
|
+
ref: (el) => {
|
|
34
|
+
triggerRef.current = el;
|
|
35
|
+
if (typeof ref === "function") ref(el);
|
|
36
|
+
else if (ref) ref.current = el;
|
|
37
|
+
},
|
|
38
|
+
type: "button",
|
|
39
|
+
layoutId: `${id}-surface`,
|
|
40
|
+
"aria-haspopup": "dialog",
|
|
41
|
+
"aria-expanded": false,
|
|
42
|
+
className: cx("fl-reset-button fl-morph-dialog__trigger", className),
|
|
43
|
+
style: { borderRadius: 16, ...style },
|
|
44
|
+
onClick: (e) => {
|
|
45
|
+
onClick?.(e);
|
|
46
|
+
if (e.defaultPrevented) return;
|
|
47
|
+
const el = e.currentTarget;
|
|
48
|
+
setSize({ width: el.offsetWidth, height: el.offsetHeight });
|
|
49
|
+
setOpen(true);
|
|
50
|
+
},
|
|
51
|
+
children
|
|
52
|
+
}
|
|
53
|
+
) })
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
var MorphDialogContent = React.forwardRef(function MorphDialogContent2({ className, children, style, dismissible = true, ...rest }, ref) {
|
|
57
|
+
const { open, setOpen, id, triggerRef, container } = useMorph();
|
|
58
|
+
const panelRef = React.useRef(null);
|
|
59
|
+
const { reduced } = useMotionPreset();
|
|
60
|
+
useScrollLock(open);
|
|
61
|
+
useFocusTrap(panelRef, open);
|
|
62
|
+
useEscape(open, () => setOpen(false));
|
|
63
|
+
return /* @__PURE__ */ jsx(Portal, { container, anchor: triggerRef.current, children: /* @__PURE__ */ jsxs(AnimatePresence, { children: [
|
|
64
|
+
open && /* @__PURE__ */ jsx(
|
|
65
|
+
motion.div,
|
|
66
|
+
{
|
|
67
|
+
className: "fl-overlay fl-morph-dialog__backdrop",
|
|
68
|
+
initial: { opacity: 0 },
|
|
69
|
+
animate: { opacity: 1 },
|
|
70
|
+
exit: { opacity: 0 },
|
|
71
|
+
transition: { duration: 0.2 },
|
|
72
|
+
onClick: () => dismissible && setOpen(false)
|
|
73
|
+
},
|
|
74
|
+
"backdrop"
|
|
75
|
+
),
|
|
76
|
+
open && /* @__PURE__ */ jsx("div", { className: "fl-morph-dialog__frame", children: /* @__PURE__ */ jsx(
|
|
77
|
+
motion.div,
|
|
78
|
+
{
|
|
79
|
+
...rest,
|
|
80
|
+
ref: (el) => {
|
|
81
|
+
panelRef.current = el;
|
|
82
|
+
if (typeof ref === "function") ref(el);
|
|
83
|
+
else if (ref) ref.current = el;
|
|
84
|
+
},
|
|
85
|
+
layoutId: `${id}-surface`,
|
|
86
|
+
role: "dialog",
|
|
87
|
+
"aria-modal": "true",
|
|
88
|
+
"aria-labelledby": `${id}-title`,
|
|
89
|
+
tabIndex: -1,
|
|
90
|
+
className: cx("fl-morph-dialog__panel", className),
|
|
91
|
+
style: { borderRadius: 22, ...style },
|
|
92
|
+
children: /* @__PURE__ */ jsx(
|
|
93
|
+
motion.div,
|
|
94
|
+
{
|
|
95
|
+
className: "fl-morph-dialog__body",
|
|
96
|
+
initial: { opacity: 0, y: reduced ? 0 : 10 },
|
|
97
|
+
animate: { opacity: 1, y: 0, transition: { delay: reduced ? 0 : 0.08, type: "spring", stiffness: 380, damping: 30 } },
|
|
98
|
+
exit: { opacity: 0, transition: { duration: 0.08 } },
|
|
99
|
+
children
|
|
100
|
+
}
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
) }, "frame")
|
|
104
|
+
] }) });
|
|
105
|
+
});
|
|
106
|
+
var MorphDialogTitle = React.forwardRef(function MorphDialogTitle2({ className, children, as = "h2", ...rest }, ref) {
|
|
107
|
+
const { id, open } = useMorph();
|
|
108
|
+
const Tag = motion[as];
|
|
109
|
+
return /* @__PURE__ */ jsx(Tag, { ...rest, ref, id: open ? `${id}-title` : void 0, layoutId: `${id}-title`, layout: "position", className: cx("fl-morph-dialog__title", className), children });
|
|
110
|
+
});
|
|
111
|
+
var MorphDialogClose = React.forwardRef(function MorphDialogClose2({ className, children, onClick, ...rest }, ref) {
|
|
112
|
+
const { setOpen } = useMorph();
|
|
113
|
+
return /* @__PURE__ */ jsx(
|
|
114
|
+
"button",
|
|
115
|
+
{
|
|
116
|
+
...rest,
|
|
117
|
+
ref,
|
|
118
|
+
type: "button",
|
|
119
|
+
"aria-label": children ? void 0 : "Close",
|
|
120
|
+
className: cx("fl-reset-button", children ? "fl-morph-dialog__action" : "fl-morph-dialog__close", className),
|
|
121
|
+
onClick: (e) => {
|
|
122
|
+
onClick?.(e);
|
|
123
|
+
if (!e.defaultPrevented) setOpen(false);
|
|
124
|
+
},
|
|
125
|
+
children: children ?? /* @__PURE__ */ jsx("svg", { viewBox: "0 0 14 14", width: "12", height: "12", "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: "M3 3l8 8M11 3l-8 8", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round" }) })
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
export { MorphDialog, MorphDialogClose, MorphDialogContent, MorphDialogTitle, MorphDialogTrigger };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var chunk5ARTY5RT_cjs = require('./chunk-5ARTY5RT.cjs');
|
|
5
|
+
var reactDom = require('react-dom');
|
|
6
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
7
|
+
|
|
8
|
+
function resolveTheme(anchor) {
|
|
9
|
+
const el = anchor?.closest("[data-theme],[data-fl-theme],.dark,.light");
|
|
10
|
+
if (!el) return void 0;
|
|
11
|
+
const attr = el.getAttribute("data-fl-theme") ?? el.getAttribute("data-theme");
|
|
12
|
+
if (attr === "dark" || attr === "light") return attr;
|
|
13
|
+
if (el.classList.contains("dark")) return "dark";
|
|
14
|
+
if (el.classList.contains("light")) return "light";
|
|
15
|
+
return void 0;
|
|
16
|
+
}
|
|
17
|
+
function Portal({ children, container, anchor, className }) {
|
|
18
|
+
const mounted = chunk5ARTY5RT_cjs.useMounted();
|
|
19
|
+
if (!mounted) return null;
|
|
20
|
+
const target = container ?? document.body;
|
|
21
|
+
const theme = resolveTheme(anchor);
|
|
22
|
+
return reactDom.createPortal(
|
|
23
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: className ? `fl-portal ${className}` : "fl-portal", "data-fl-theme": theme, children }),
|
|
24
|
+
target
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
exports.Portal = Portal;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var chunk5ARTY5RT_cjs = require('./chunk-5ARTY5RT.cjs');
|
|
5
|
+
var chunkPBMXL53R_cjs = require('./chunk-PBMXL53R.cjs');
|
|
6
|
+
var React = require('react');
|
|
7
|
+
var react = require('motion/react');
|
|
8
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
9
|
+
|
|
10
|
+
function _interopNamespace(e) {
|
|
11
|
+
if (e && e.__esModule) return e;
|
|
12
|
+
var n = Object.create(null);
|
|
13
|
+
if (e) {
|
|
14
|
+
Object.keys(e).forEach(function (k) {
|
|
15
|
+
if (k !== 'default') {
|
|
16
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
17
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () { return e[k]; }
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
n.default = e;
|
|
25
|
+
return Object.freeze(n);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
29
|
+
|
|
30
|
+
var RETURN = { type: "spring", stiffness: 380, damping: 14, mass: 0.8 };
|
|
31
|
+
var COMMIT = { type: "spring", stiffness: 500, damping: 34 };
|
|
32
|
+
var SwipeConfirm = React__namespace.forwardRef(function SwipeConfirm2({ label = "Slide to confirm", confirmedLabel = "Confirmed", onConfirm, resetAfter = 2400, tone = "ink", size = "md", disabled, haptics = true, className, ...rest }, ref) {
|
|
33
|
+
const { t, reduced } = chunkPBMXL53R_cjs.useMotionPreset();
|
|
34
|
+
const [trackRef, track] = chunk5ARTY5RT_cjs.useElementSize();
|
|
35
|
+
const thumbSize = size === "sm" ? 36 : size === "lg" ? 52 : 44;
|
|
36
|
+
const pad = 4;
|
|
37
|
+
const maxX = Math.max(0, track.width - thumbSize - pad * 2);
|
|
38
|
+
const x = react.useMotionValue(0);
|
|
39
|
+
const [state, setState] = React__namespace.useState("idle");
|
|
40
|
+
const drag = React__namespace.useRef(null);
|
|
41
|
+
const timer = React__namespace.useRef(void 0);
|
|
42
|
+
React__namespace.useEffect(() => () => clearTimeout(timer.current), []);
|
|
43
|
+
const progress = react.useTransform(x, (v) => maxX ? Math.min(1, Math.max(0, v / maxX)) : 0);
|
|
44
|
+
const fillWidth = react.useTransform(x, (v) => v + thumbSize + pad * 2);
|
|
45
|
+
const confirm = async () => {
|
|
46
|
+
setState("pending");
|
|
47
|
+
if (haptics) chunk5ARTY5RT_cjs.haptic([8, 40, 14]);
|
|
48
|
+
react.animate(x, maxX, t(COMMIT));
|
|
49
|
+
try {
|
|
50
|
+
await onConfirm?.();
|
|
51
|
+
setState("done");
|
|
52
|
+
} catch {
|
|
53
|
+
setState("idle");
|
|
54
|
+
react.animate(x, 0, t(RETURN));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (resetAfter > 0) {
|
|
58
|
+
timer.current = setTimeout(() => {
|
|
59
|
+
setState("idle");
|
|
60
|
+
react.animate(x, 0, t({ type: "spring", stiffness: 260, damping: 26 }));
|
|
61
|
+
}, resetAfter);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const onPointerDown = (event) => {
|
|
65
|
+
if (disabled || state !== "idle" || event.button !== 0) return;
|
|
66
|
+
x.stop();
|
|
67
|
+
drag.current = { x0: event.clientX, start: x.get(), samples: [{ t: performance.now(), x: event.clientX }] };
|
|
68
|
+
event.currentTarget.setPointerCapture?.(event.pointerId);
|
|
69
|
+
};
|
|
70
|
+
const onPointerMove = (event) => {
|
|
71
|
+
const d = drag.current;
|
|
72
|
+
if (!d) return;
|
|
73
|
+
const raw = d.start + event.clientX - d.x0;
|
|
74
|
+
const v = raw < 0 ? raw * 0.2 : raw > maxX ? maxX + (raw - maxX) * 0.2 : raw;
|
|
75
|
+
x.set(v);
|
|
76
|
+
d.samples.push({ t: performance.now(), x: event.clientX });
|
|
77
|
+
if (d.samples.length > 5) d.samples.shift();
|
|
78
|
+
};
|
|
79
|
+
const onPointerUp = () => {
|
|
80
|
+
const d = drag.current;
|
|
81
|
+
if (!d) return;
|
|
82
|
+
drag.current = null;
|
|
83
|
+
const a = d.samples[0];
|
|
84
|
+
const b = d.samples[d.samples.length - 1];
|
|
85
|
+
const velocity = (b.x - a.x) / Math.max(1, b.t - a.t) * 1e3;
|
|
86
|
+
if (x.get() > maxX * 0.86 || velocity > 900 && x.get() > maxX * 0.4) confirm();
|
|
87
|
+
else react.animate(x, 0, reduced ? { duration: 0.15 } : { ...RETURN, velocity });
|
|
88
|
+
};
|
|
89
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
90
|
+
"div",
|
|
91
|
+
{
|
|
92
|
+
...rest,
|
|
93
|
+
ref: (el) => {
|
|
94
|
+
trackRef(el);
|
|
95
|
+
if (typeof ref === "function") ref(el);
|
|
96
|
+
else if (ref) ref.current = el;
|
|
97
|
+
},
|
|
98
|
+
className: chunkPBMXL53R_cjs.cx("fl-swipe", className),
|
|
99
|
+
"data-size": size,
|
|
100
|
+
"data-tone": tone,
|
|
101
|
+
"data-state": state,
|
|
102
|
+
"data-disabled": disabled || void 0,
|
|
103
|
+
style: { ...rest.style, ["--fl-swipe-thumb"]: `${thumbSize}px` },
|
|
104
|
+
children: [
|
|
105
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.motion.span, { className: "fl-swipe__fill", "aria-hidden": true, style: { width: fillWidth } }),
|
|
106
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "fl-swipe__label", "aria-hidden": true, children: /* @__PURE__ */ jsxRuntime.jsx(react.AnimatePresence, { mode: "popLayout", initial: false, children: state === "done" ? /* @__PURE__ */ jsxRuntime.jsx(react.motion.span, { className: "fl-swipe__done", initial: { opacity: 0, y: 8 }, animate: { opacity: 1, y: 0 }, transition: t(COMMIT), children: confirmedLabel }, "done") : /* @__PURE__ */ jsxRuntime.jsx(react.motion.span, { className: "fl-swipe__chars", exit: { opacity: 0 }, style: { paddingLeft: thumbSize }, children: Array.from(label).map((ch, i, all) => /* @__PURE__ */ jsxRuntime.jsx(Char, { ch, i, n: all.length, progress }, i)) }, "label") }) }),
|
|
107
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
108
|
+
react.motion.button,
|
|
109
|
+
{
|
|
110
|
+
type: "button",
|
|
111
|
+
className: "fl-reset-button fl-swipe__thumb",
|
|
112
|
+
"aria-label": state === "done" ? confirmedLabel : `${label}. Press Enter to confirm.`,
|
|
113
|
+
disabled: disabled || state !== "idle",
|
|
114
|
+
style: { x },
|
|
115
|
+
onPointerDown,
|
|
116
|
+
onPointerMove,
|
|
117
|
+
onPointerUp,
|
|
118
|
+
onPointerCancel: onPointerUp,
|
|
119
|
+
onKeyDown: (e) => {
|
|
120
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
121
|
+
e.preventDefault();
|
|
122
|
+
if (state === "idle" && !disabled) confirm();
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
whileTap: reduced ? void 0 : { scale: 0.94 },
|
|
126
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(react.AnimatePresence, { mode: "popLayout", initial: false, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
127
|
+
react.motion.svg,
|
|
128
|
+
{
|
|
129
|
+
viewBox: "0 0 20 20",
|
|
130
|
+
width: "18",
|
|
131
|
+
height: "18",
|
|
132
|
+
"aria-hidden": true,
|
|
133
|
+
initial: { scale: 0.4, opacity: 0 },
|
|
134
|
+
animate: { scale: 1, opacity: 1 },
|
|
135
|
+
exit: { scale: 0.4, opacity: 0 },
|
|
136
|
+
transition: t({ type: "spring", stiffness: 520, damping: 24 }),
|
|
137
|
+
children: [
|
|
138
|
+
state === "idle" && /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M4 10h11M11 6l4 4-4 4", fill: "none", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", strokeLinejoin: "round" }),
|
|
139
|
+
state === "pending" && /* @__PURE__ */ jsxRuntime.jsxs("g", { className: "fl-swipe__spin", children: [
|
|
140
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "10", cy: "10", r: "6.5", fill: "none", stroke: "currentColor", strokeOpacity: "0.25", strokeWidth: "2" }),
|
|
141
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M10 3.5a6.5 6.5 0 0 1 6.5 6.5", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" })
|
|
142
|
+
] }),
|
|
143
|
+
state === "done" && /* @__PURE__ */ jsxRuntime.jsx(react.motion.path, { d: "M5 10.4 8.4 13.6 15 6.6", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", initial: { pathLength: 0 }, animate: { pathLength: 1 }, transition: t({ type: "spring", stiffness: 220, damping: 22 }) })
|
|
144
|
+
]
|
|
145
|
+
},
|
|
146
|
+
state
|
|
147
|
+
) })
|
|
148
|
+
}
|
|
149
|
+
),
|
|
150
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "fl-sr-only", "aria-live": "polite", children: state === "done" ? confirmedLabel : "" })
|
|
151
|
+
]
|
|
152
|
+
}
|
|
153
|
+
);
|
|
154
|
+
});
|
|
155
|
+
function Char({ ch, i, n, progress }) {
|
|
156
|
+
const at = 0.12 + (i + 0.5) / n * 0.72;
|
|
157
|
+
const near = react.useTransform(progress, (p) => {
|
|
158
|
+
const d = at - p;
|
|
159
|
+
return d > 0.1 ? 1 : d < -0.02 ? 0 : (d + 0.02) / 0.12;
|
|
160
|
+
});
|
|
161
|
+
const y = react.useTransform(near, (v) => (1 - v) * -6);
|
|
162
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.motion.span, { style: { opacity: near, y, display: "inline-block", whiteSpace: "pre" }, children: ch });
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
exports.SwipeConfirm = SwipeConfirm;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var chunk5ARTY5RT_cjs = require('./chunk-5ARTY5RT.cjs');
|
|
5
|
+
var chunkG5UZZ2XG_cjs = require('./chunk-G5UZZ2XG.cjs');
|
|
6
|
+
var chunkPBMXL53R_cjs = require('./chunk-PBMXL53R.cjs');
|
|
7
|
+
var React = require('react');
|
|
8
|
+
var react = require('motion/react');
|
|
9
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
10
|
+
|
|
11
|
+
function _interopNamespace(e) {
|
|
12
|
+
if (e && e.__esModule) return e;
|
|
13
|
+
var n = Object.create(null);
|
|
14
|
+
if (e) {
|
|
15
|
+
Object.keys(e).forEach(function (k) {
|
|
16
|
+
if (k !== 'default') {
|
|
17
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
18
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () { return e[k]; }
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
n.default = e;
|
|
26
|
+
return Object.freeze(n);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
30
|
+
|
|
31
|
+
var LAYOUT = { type: "spring", stiffness: 480, damping: 36 };
|
|
32
|
+
function normalize(options) {
|
|
33
|
+
return options.map((o) => typeof o === "string" ? { value: o, label: o } : o);
|
|
34
|
+
}
|
|
35
|
+
function ChipSelectImpl({ options: raw, value: valueProp, defaultValue = [], onValueChange, variant = "check", max, size = "md", disabled, haptics = true, className, ...rest }, ref) {
|
|
36
|
+
const options = React__namespace.useMemo(() => normalize(raw), [raw]);
|
|
37
|
+
const [value, setValue] = chunkG5UZZ2XG_cjs.useControllableState({ value: valueProp, defaultValue, onChange: onValueChange });
|
|
38
|
+
const { t } = chunkPBMXL53R_cjs.useMotionPreset();
|
|
39
|
+
const groupId = React__namespace.useId();
|
|
40
|
+
const full = max !== void 0 && value.length >= max;
|
|
41
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { ...rest, ref, role: "group", className: chunkPBMXL53R_cjs.cx("fl-chips", className), "data-variant": variant, "data-size": size, "data-full": full || void 0, children: /* @__PURE__ */ jsxRuntime.jsx(react.LayoutGroup, { id: groupId, children: options.map((option) => {
|
|
42
|
+
const rank = value.indexOf(option.value);
|
|
43
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
44
|
+
Chip,
|
|
45
|
+
{
|
|
46
|
+
option,
|
|
47
|
+
rank,
|
|
48
|
+
variant,
|
|
49
|
+
blocked: full && rank === -1,
|
|
50
|
+
disabled: disabled || option.disabled,
|
|
51
|
+
transition: t(LAYOUT),
|
|
52
|
+
onToggle: () => {
|
|
53
|
+
if (rank === -1 && full) return false;
|
|
54
|
+
if (haptics) chunk5ARTY5RT_cjs.haptic(rank === -1 ? 6 : 4);
|
|
55
|
+
setValue((prev) => prev.includes(option.value) ? prev.filter((v) => v !== option.value) : [...prev, option.value]);
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
option.value
|
|
60
|
+
);
|
|
61
|
+
}) }) });
|
|
62
|
+
}
|
|
63
|
+
function Chip({
|
|
64
|
+
option,
|
|
65
|
+
rank,
|
|
66
|
+
variant,
|
|
67
|
+
blocked,
|
|
68
|
+
disabled,
|
|
69
|
+
transition,
|
|
70
|
+
onToggle
|
|
71
|
+
}) {
|
|
72
|
+
const [scope, animate] = react.useAnimate();
|
|
73
|
+
const { reduced, t } = chunkPBMXL53R_cjs.useMotionPreset();
|
|
74
|
+
const selected = rank !== -1;
|
|
75
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
76
|
+
react.motion.button,
|
|
77
|
+
{
|
|
78
|
+
ref: scope,
|
|
79
|
+
layout: true,
|
|
80
|
+
type: "button",
|
|
81
|
+
className: "fl-reset-button fl-chip",
|
|
82
|
+
"aria-pressed": selected,
|
|
83
|
+
"aria-disabled": blocked || void 0,
|
|
84
|
+
disabled,
|
|
85
|
+
"data-state": selected ? "on" : "off",
|
|
86
|
+
"data-blocked": blocked || void 0,
|
|
87
|
+
transition,
|
|
88
|
+
style: { borderRadius: 999 },
|
|
89
|
+
whileTap: reduced ? void 0 : { scale: 0.94 },
|
|
90
|
+
onClick: () => {
|
|
91
|
+
const accepted = onToggle();
|
|
92
|
+
if (!accepted && !reduced && scope.current) animate(scope.current, { x: [0, -5, 4, -3, 2, 0] }, { duration: 0.36, ease: "easeOut" });
|
|
93
|
+
},
|
|
94
|
+
children: [
|
|
95
|
+
option.icon && /* @__PURE__ */ jsxRuntime.jsx(react.motion.span, { layout: "position", className: "fl-chip__icon", children: option.icon }),
|
|
96
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.motion.span, { layout: "position", className: "fl-chip__label", children: option.label }),
|
|
97
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.AnimatePresence, { initial: false, mode: "popLayout", children: selected && /* @__PURE__ */ jsxRuntime.jsx(
|
|
98
|
+
react.motion.span,
|
|
99
|
+
{
|
|
100
|
+
layout: "position",
|
|
101
|
+
className: "fl-chip__mark",
|
|
102
|
+
initial: { opacity: 0, scale: 0.3, width: 0 },
|
|
103
|
+
animate: { opacity: 1, scale: 1, width: "auto" },
|
|
104
|
+
exit: { opacity: 0, scale: 0.3, width: 0 },
|
|
105
|
+
transition: t({ type: "spring", stiffness: 520, damping: 26 }),
|
|
106
|
+
children: variant === "rank" ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "fl-chip__rank", children: /* @__PURE__ */ jsxRuntime.jsx(react.AnimatePresence, { initial: false, mode: "popLayout", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
107
|
+
react.motion.span,
|
|
108
|
+
{
|
|
109
|
+
initial: { y: "100%", opacity: 0 },
|
|
110
|
+
animate: { y: "0%", opacity: 1 },
|
|
111
|
+
exit: { y: "-100%", opacity: 0 },
|
|
112
|
+
transition: t({ type: "spring", stiffness: 500, damping: 32 }),
|
|
113
|
+
children: rank + 1
|
|
114
|
+
},
|
|
115
|
+
rank
|
|
116
|
+
) }) }) : /* @__PURE__ */ jsxRuntime.jsx("svg", { viewBox: "0 0 16 16", width: "14", height: "14", "aria-hidden": true, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
117
|
+
react.motion.path,
|
|
118
|
+
{
|
|
119
|
+
d: "M3.6 8.4 L6.6 11.2 L12.4 5",
|
|
120
|
+
fill: "none",
|
|
121
|
+
stroke: "currentColor",
|
|
122
|
+
strokeWidth: "1.8",
|
|
123
|
+
strokeLinecap: "round",
|
|
124
|
+
strokeLinejoin: "round",
|
|
125
|
+
initial: { pathLength: 0 },
|
|
126
|
+
animate: { pathLength: 1 },
|
|
127
|
+
transition: t({ type: "spring", stiffness: 260, damping: 24, delay: 0.08 })
|
|
128
|
+
}
|
|
129
|
+
) })
|
|
130
|
+
},
|
|
131
|
+
"mark"
|
|
132
|
+
) })
|
|
133
|
+
]
|
|
134
|
+
}
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
var ChipSelect = React__namespace.forwardRef(ChipSelectImpl);
|
|
138
|
+
|
|
139
|
+
exports.ChipSelect = ChipSelect;
|