@kumix/ui 0.3.4 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/agents/agent-activity/activity-row.d.ts +1 -1
- package/dist/components/agents/agent-activity/index.d.ts +2 -2
- package/dist/components/agents/agent-activity/index.d.ts.map +1 -1
- package/dist/components/agents/agent-activity/index.js +9 -3
- package/dist/components/agents/agent-activity/index.js.map +1 -1
- package/dist/components/agents/loading-states/reasoning-text.d.ts.map +1 -1
- package/dist/components/agents/loading-states/reasoning-text.js +7 -39
- package/dist/components/agents/loading-states/reasoning-text.js.map +1 -1
- package/dist/components/motion/action-swap.d.ts.map +1 -1
- package/dist/components/motion/action-swap.js +11 -16
- package/dist/components/motion/action-swap.js.map +1 -1
- package/dist/components/motion/bottom-sheet.js +25 -7
- package/dist/components/motion/bottom-sheet.js.map +1 -1
- package/dist/components/motion/combobox/content.d.ts +16 -0
- package/dist/components/motion/combobox/content.d.ts.map +1 -0
- package/dist/components/motion/combobox/content.js +91 -0
- package/dist/components/motion/combobox/content.js.map +1 -0
- package/dist/components/motion/combobox/context.d.ts +63 -0
- package/dist/components/motion/combobox/context.d.ts.map +1 -0
- package/dist/components/motion/combobox/context.js +235 -0
- package/dist/components/motion/combobox/context.js.map +1 -0
- package/dist/components/motion/combobox/list.d.ts +40 -0
- package/dist/components/motion/combobox/list.d.ts.map +1 -0
- package/dist/components/motion/combobox/list.js +143 -0
- package/dist/components/motion/combobox/list.js.map +1 -0
- package/dist/components/motion/combobox/trigger.d.ts +21 -0
- package/dist/components/motion/combobox/trigger.d.ts.map +1 -0
- package/dist/components/motion/combobox/trigger.js +115 -0
- package/dist/components/motion/combobox/trigger.js.map +1 -0
- package/dist/components/motion/combobox.d.ts +5 -0
- package/dist/components/motion/combobox.js +6 -0
- package/dist/components/motion/popover.d.ts.map +1 -1
- package/dist/components/motion/popover.js +22 -25
- package/dist/components/motion/popover.js.map +1 -1
- package/dist/components/motion/project-folder.d.ts +27 -0
- package/dist/components/motion/project-folder.d.ts.map +1 -0
- package/dist/components/motion/project-folder.js +310 -0
- package/dist/components/motion/project-folder.js.map +1 -0
- package/dist/components/motion/tabs.d.ts.map +1 -1
- package/dist/components/motion/tabs.js +2 -0
- package/dist/components/motion/tabs.js.map +1 -1
- package/dist/components/motion/text-scramble.d.ts +17 -0
- package/dist/components/motion/text-scramble.d.ts.map +1 -0
- package/dist/components/motion/text-scramble.js +64 -0
- package/dist/components/motion/text-scramble.js.map +1 -0
- package/dist/components/reui/alert.d.ts +1 -1
- package/dist/components/reui/autocomplete.d.ts +1 -1
- package/dist/components/reui/badge.d.ts +2 -2
- package/dist/components/reui/data-grid/data-grid-column-filter.js +2 -2
- package/dist/components/reui/date-selector.js +1 -1
- package/dist/components/reui/event-calendar/event-calendar-month-view.js +1 -1
- package/dist/components/reui/event-calendar/event-calendar-nav.js +1 -1
- package/dist/components/reui/filters.js +3 -3
- package/dist/components/reui/frame.d.ts +2 -2
- package/dist/components/reui/gantt/gantt-bar.js +1 -1
- package/dist/components/reui/gantt/gantt-nav.js +1 -1
- package/dist/components/reui/gantt/gantt-view.js +3 -3
- package/dist/components/reui/icon-tile.d.ts +2 -2
- package/dist/components/reui/number-field.d.ts +3 -3
- package/dist/components/reui/phone-input.js +1 -1
- package/dist/components/reui/rating.d.ts +1 -1
- package/dist/components/ui/attachment.d.ts +2 -2
- package/dist/components/ui/badge.d.ts +1 -1
- package/dist/components/ui/bubble.d.ts +1 -1
- package/dist/components/ui/button-group.d.ts +1 -1
- package/dist/components/ui/button.d.ts +2 -2
- package/dist/components/ui/field.d.ts +1 -1
- package/dist/components/ui/item.d.ts +2 -2
- package/dist/components/ui/sidebar.d.ts +2 -2
- package/dist/components/ui/sidebar.js +2 -2
- package/dist/components/ui/tabs.d.ts +1 -1
- package/dist/components/ui/toggle.d.ts +2 -2
- package/dist/{types-j36vVGtZ.d.ts → types-kSZH1k8K.d.ts} +11 -1
- package/dist/{types-j36vVGtZ.d.ts.map → types-kSZH1k8K.d.ts.map} +1 -1
- package/package.json +4 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as AgentActivityItem } from "../../../types-
|
|
1
|
+
import { n as AgentActivityItem } from "../../../types-kSZH1k8K.js";
|
|
2
2
|
//#region src/components/agents/agent-activity/activity-row.d.ts
|
|
3
3
|
declare function ActivityRow({ item }: {
|
|
4
4
|
item: AgentActivityItem;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as AgentActivityStatus, c as AgentActivityTool, d as AgentStepStatus, f as AgentTraceKind, i as AgentActivitySearch, l as AgentActivityTrace, n as AgentActivityItem, o as AgentActivityStep, r as AgentActivityProps, s as AgentActivityText, t as AgentActivityContentType, u as AgentSearchResult } from "../../../types-
|
|
1
|
+
import { a as AgentActivityStatus, c as AgentActivityTool, d as AgentStepStatus, f as AgentTraceKind, i as AgentActivitySearch, l as AgentActivityTrace, n as AgentActivityItem, o as AgentActivityStep, r as AgentActivityProps, s as AgentActivityText, t as AgentActivityContentType, u as AgentSearchResult } from "../../../types-kSZH1k8K.js";
|
|
2
2
|
//#region src/components/agents/agent-activity/index.d.ts
|
|
3
|
-
declare function AgentActivity({ items, contentType: initialContentType, status, duration, open, defaultOpen, onOpenChange, collapseOnComplete, activeLabel, summary, maxHeight, className, contentClassName }: AgentActivityProps): import("react").JSX.Element;
|
|
3
|
+
declare function AgentActivity({ items, contentType: initialContentType, status, duration, open, defaultOpen, onOpenChange, collapseOnComplete, activeLabel, summary, renderWorkingStatus, renderCompletedStatus, maxHeight, className, contentClassName }: AgentActivityProps): import("react").JSX.Element;
|
|
4
4
|
//#endregion
|
|
5
5
|
export { AgentActivity, type AgentActivityContentType, type AgentActivityItem, type AgentActivityProps, type AgentActivitySearch, type AgentActivityStatus, type AgentActivityStep, type AgentActivityText, type AgentActivityTool, type AgentActivityTrace, type AgentSearchResult, type AgentStepStatus, type AgentTraceKind };
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/components/agents/agent-activity/index.tsx"],"mappings":";;iBA4GgB,gBACd,OACA,aAAa,oBACb,QACA,UACA,MACA,aACA,cACA,oBACA,aACA,SACA,WACA,WACA,oBACC,qCAAkB,IAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/components/agents/agent-activity/index.tsx"],"mappings":";;iBA4GgB,gBACd,OACA,aAAa,oBACb,QACA,UACA,MACA,aACA,cACA,oBACA,aACA,SACA,qBACA,uBACA,WACA,WACA,oBACC,qCAAkB,IAAA"}
|
|
@@ -49,7 +49,7 @@ function getSummary(type, items, duration) {
|
|
|
49
49
|
}
|
|
50
50
|
return `Completed ${items.length} ${items.length === 1 ? "step" : "steps"}`;
|
|
51
51
|
}
|
|
52
|
-
function AgentActivity({ items, contentType: initialContentType, status = "working", duration = 0, open, defaultOpen = false, onOpenChange, collapseOnComplete = true, activeLabel, summary, maxHeight = 208, className, contentClassName }) {
|
|
52
|
+
function AgentActivity({ items, contentType: initialContentType, status = "working", duration = 0, open, defaultOpen = false, onOpenChange, collapseOnComplete = true, activeLabel, summary, renderWorkingStatus, renderCompletedStatus, maxHeight = 208, className, contentClassName }) {
|
|
53
53
|
const reduce = useReducedMotion() ?? false;
|
|
54
54
|
const baseId = useId();
|
|
55
55
|
const triggerId = `${baseId}-trigger`;
|
|
@@ -104,7 +104,10 @@ function AgentActivity({ items, contentType: initialContentType, status = "worki
|
|
|
104
104
|
id: triggerId,
|
|
105
105
|
role: "status",
|
|
106
106
|
className: "flex h-7 min-w-0 items-center text-muted-foreground",
|
|
107
|
-
children:
|
|
107
|
+
children: renderWorkingStatus ? renderWorkingStatus({
|
|
108
|
+
label: liveLabel,
|
|
109
|
+
duration
|
|
110
|
+
}) : /* @__PURE__ */ jsx(ThinkingShimmer, { children: liveLabel })
|
|
108
111
|
}) : /* @__PURE__ */ jsxs("button", {
|
|
109
112
|
id: triggerId,
|
|
110
113
|
type: "button",
|
|
@@ -114,7 +117,10 @@ function AgentActivity({ items, contentType: initialContentType, status = "worki
|
|
|
114
117
|
className: "group flex h-7 min-w-0 items-center gap-1.5 rounded-md text-left font-medium text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",
|
|
115
118
|
children: [/* @__PURE__ */ jsx("span", {
|
|
116
119
|
className: "truncate",
|
|
117
|
-
children:
|
|
120
|
+
children: renderCompletedStatus ? renderCompletedStatus({
|
|
121
|
+
summary: completedSummary,
|
|
122
|
+
duration
|
|
123
|
+
}) : completedSummary
|
|
118
124
|
}), /* @__PURE__ */ jsx(motion.span, {
|
|
119
125
|
"aria-hidden": "true",
|
|
120
126
|
animate: { rotate: expanded ? 180 : 0 },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../../src/components/agents/agent-activity/index.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type ReactNode,\n useCallback,\n useEffect,\n useId,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\nimport { ChevronDown } from \"lucide-react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { EASE_OUT, SPRING_LAYOUT, SPRING_SWAP } from \"../../../lib/ease\";\nimport { AgentDisclosure } from \"../agent-disclosure\";\nimport { ThinkingShimmer } from \"../loading-states/thinking-shimmer\";\nimport { ActivityRow } from \"./activity-row\";\nimport type { AgentActivityContentType, AgentActivityItem, AgentActivityProps } from \"./types\";\n\nexport type {\n AgentActivityContentType,\n AgentActivityItem,\n AgentActivityProps,\n AgentActivitySearch,\n AgentActivityStatus,\n AgentActivityStep,\n AgentActivityText,\n AgentActivityTool,\n AgentActivityTrace,\n AgentSearchResult,\n AgentStepStatus,\n AgentTraceKind,\n} from \"./types\";\n\nfunction formatDuration(duration: number) {\n const seconds = Math.max(0, Math.round(duration));\n if (seconds < 60) return `${seconds}s`;\n\n const minutes = Math.floor(seconds / 60);\n const remainder = seconds % 60;\n return remainder === 0 ? `${minutes}m` : `${minutes}m ${remainder}s`;\n}\n\nfunction useControllableOpen({\n open,\n defaultOpen,\n onOpenChange,\n}: {\n open?: boolean;\n defaultOpen: boolean;\n onOpenChange?: (open: boolean) => void;\n}) {\n const [internalOpen, setInternalOpen] = useState(defaultOpen);\n const controlled = open !== undefined;\n const currentOpen = open ?? internalOpen;\n\n const setOpen = useCallback(\n (next: boolean) => {\n if (!controlled) setInternalOpen(next);\n onOpenChange?.(next);\n },\n [controlled, onOpenChange],\n );\n\n return [currentOpen, setOpen] as const;\n}\n\nfunction getContentType(items: AgentActivityItem[]): AgentActivityContentType {\n const first = items[0]?.type;\n return first && items.every((item) => item.type === first) ? first : \"mixed\";\n}\n\nfunction getActiveLabel(type: AgentActivityContentType) {\n if (type === \"search\") return \"Searching the web…\";\n if (type === \"tool\") return \"Running tools…\";\n if (type === \"trace\") return \"Working through the run…\";\n if (type === \"mixed\") return \"Working through it…\";\n return \"Thinking…\";\n}\n\nfunction getSummary(\n type: AgentActivityContentType,\n items: AgentActivityItem[],\n duration: number,\n): ReactNode {\n if (type === \"step\" || type === \"text\") {\n return (\n <>\n Thought for <span className=\"tabular-nums\">{formatDuration(duration)}</span>\n </>\n );\n }\n if (type === \"search\") return \"Searched the web\";\n if (type === \"tool\") {\n return `Ran ${items.length} ${items.length === 1 ? \"tool\" : \"tools\"}`;\n }\n if (type === \"trace\") {\n const messages = items.filter(\n (item) => item.type === \"trace\" && (item.kind === \"thinking\" || item.kind === \"message\"),\n ).length;\n const tools = items.length - messages;\n return `${tools} ${tools === 1 ? \"tool call\" : \"tool calls\"}, ${messages} ${messages === 1 ? \"message\" : \"messages\"}`;\n }\n return `Completed ${items.length} ${items.length === 1 ? \"step\" : \"steps\"}`;\n}\n\nexport function AgentActivity({\n items,\n contentType: initialContentType,\n status = \"working\",\n duration = 0,\n open,\n defaultOpen = false,\n onOpenChange,\n collapseOnComplete = true,\n activeLabel,\n summary,\n maxHeight = 208,\n className,\n contentClassName,\n}: AgentActivityProps) {\n const reduce = useReducedMotion() ?? false;\n const baseId = useId();\n const triggerId = `${baseId}-trigger`;\n const contentId = `${baseId}-content`;\n const contentRef = useRef<HTMLDivElement>(null);\n const viewportRef = useRef<HTMLDivElement>(null);\n const previousStatus = useRef(status);\n const [contentHeight, setContentHeight] = useState(0);\n const [currentOpen, setOpen] = useControllableOpen({\n open,\n defaultOpen,\n onOpenChange,\n });\n const working = status === \"working\";\n const expanded = working || currentOpen;\n const contentType = items.length ? getContentType(items) : (initialContentType ?? \"mixed\");\n const cappedHeight = Math.min(contentHeight, Math.max(0, maxHeight));\n const viewportHeight = working ? Math.max(0, maxHeight) : cappedHeight;\n const capped = contentHeight > maxHeight;\n const streamOffset = working ? Math.min(0, viewportHeight - contentHeight) : 0;\n\n useLayoutEffect(() => {\n const node = contentRef.current;\n if (!node) return;\n\n const measure = () => setContentHeight(node.offsetHeight);\n measure();\n\n if (typeof ResizeObserver === \"undefined\") return;\n const observer = new ResizeObserver(measure);\n observer.observe(node);\n return () => observer.disconnect();\n }, []);\n\n useEffect(() => {\n if (previousStatus.current === \"working\" && status === \"complete\") {\n setOpen(!collapseOnComplete);\n }\n previousStatus.current = status;\n }, [collapseOnComplete, setOpen, status]);\n\n const toggle = () => {\n const next = !currentOpen;\n setOpen(next);\n if (next) requestAnimationFrame(() => viewportRef.current?.scrollTo({ top: 0 }));\n };\n\n const liveLabel = activeLabel ?? getActiveLabel(contentType);\n const completedSummary = summary ?? getSummary(contentType, items, duration);\n const maskImage = capped\n ? working\n ? \"linear-gradient(to bottom, transparent, black 12px)\"\n : \"linear-gradient(to bottom, transparent, black 12px, black calc(100% - 12px), transparent)\"\n : undefined;\n\n return (\n <div\n data-state={working ? \"working\" : expanded ? \"open\" : \"closed\"}\n data-content={contentType}\n aria-busy={working}\n className={cn(\"w-full text-sm\", className)}\n >\n {working ? (\n <div\n id={triggerId}\n role=\"status\"\n className=\"flex h-7 min-w-0 items-center text-muted-foreground\"\n >\n <ThinkingShimmer>{liveLabel}</ThinkingShimmer>\n </div>\n ) : (\n <button\n id={triggerId}\n type=\"button\"\n aria-expanded={expanded}\n aria-controls={contentId}\n onClick={toggle}\n className=\"group flex h-7 min-w-0 items-center gap-1.5 rounded-md text-left font-medium text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background\"\n >\n <span className=\"truncate\">{completedSummary}</span>\n <motion.span\n aria-hidden=\"true\"\n animate={{ rotate: expanded ? 180 : 0 }}\n transition={reduce ? { duration: 0 } : SPRING_SWAP}\n className=\"inline-flex shrink-0 text-muted-foreground/70 group-hover:text-foreground\"\n >\n <ChevronDown className=\"size-3.5\" />\n </motion.span>\n </button>\n )}\n\n <AgentDisclosure\n id={contentId}\n role=\"region\"\n aria-labelledby={triggerId}\n open={expanded}\n openHeight={viewportHeight}\n >\n <div\n ref={viewportRef}\n className={cn(\n \"scrollbar-hide pr-1\",\n capped && expanded && !working ? \"overflow-y-auto\" : \"overflow-y-hidden\",\n )}\n style={{ height: viewportHeight, maskImage, WebkitMaskImage: maskImage }}\n >\n <motion.div\n ref={contentRef}\n role=\"list\"\n initial={false}\n animate={{ y: streamOffset }}\n transition={reduce ? { duration: 0 } : SPRING_LAYOUT}\n className={cn(\"space-y-0.5 py-2\", contentClassName)}\n >\n <AnimatePresence mode=\"popLayout\">\n {items.map((item) => (\n <motion.div\n layout=\"position\"\n key={item.id}\n role=\"listitem\"\n initial={reduce ? { opacity: 1 } : { opacity: 0, y: 6 }}\n animate={{ opacity: 1, y: 0 }}\n exit={reduce ? { opacity: 0 } : { opacity: 0, y: -3 }}\n transition={\n reduce\n ? { duration: 0 }\n : {\n opacity: { duration: 0.18, ease: EASE_OUT },\n y: SPRING_LAYOUT,\n layout: SPRING_LAYOUT,\n }\n }\n >\n <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B;GACjB,MAAM;GACN,YAAY;GAEZ,UAAA,oBAAC,OAAD;IACE,KAAK;IACL,WAAW,GACT,uBACA,UAAU,YAAY,CAAC,UAAU,oBAAoB,mBACvD;IACA,OAAO;KAAE,QAAQ;KAAgB;KAAW,iBAAiB;IAAU;IAEvE,UAAA,oBAAC,OAAO,KAAR;KACE,KAAK;KACL,MAAK;KACL,SAAS;KACT,SAAS,EAAE,GAAG,aAAa;KAC3B,YAAY,SAAS,EAAE,UAAU,EAAE,IAAI;KACvC,WAAW,GAAG,oBAAoB,gBAAgB;KAElD,UAAA,oBAAC,iBAAD;MAAiB,MAAK;MACnB,UAAA,MAAM,KAAK,SACV,oBAAC,OAAO,KAAR;OACE,QAAO;OAEP,MAAK;OACL,SAAS,SAAS,EAAE,SAAS,EAAE,IAAI;QAAE,SAAS;QAAG,GAAG;OAAE;OACtD,SAAS;QAAE,SAAS;QAAG,GAAG;OAAE;OAC5B,MAAM,SAAS,EAAE,SAAS,EAAE,IAAI;QAAE,SAAS;QAAG,GAAG;OAAG;OACpD,YACE,SACI,EAAE,UAAU,EAAE,IACd;QACE,SAAS;SAAE,UAAU;SAAM,MAAM;QAAS;QAC1C,GAAG;QACH,QAAQ;OACV;OAGN,UAAA,oBAAC,aAAD,EAAmB,KAAO,CAAA;MAChB,GAhBL,KAAK,EAgBA,CACb;KACc,CAAA;IACP,CAAA;GACT,CAAA;EACU,CAAA,CACd;;AAET"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../src/components/agents/agent-activity/index.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type ReactNode,\n useCallback,\n useEffect,\n useId,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\nimport { ChevronDown } from \"lucide-react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { EASE_OUT, SPRING_LAYOUT, SPRING_SWAP } from \"../../../lib/ease\";\nimport { AgentDisclosure } from \"../agent-disclosure\";\nimport { ThinkingShimmer } from \"../loading-states/thinking-shimmer\";\nimport { ActivityRow } from \"./activity-row\";\nimport type { AgentActivityContentType, AgentActivityItem, AgentActivityProps } from \"./types\";\n\nexport type {\n AgentActivityContentType,\n AgentActivityItem,\n AgentActivityProps,\n AgentActivitySearch,\n AgentActivityStatus,\n AgentActivityStep,\n AgentActivityText,\n AgentActivityTool,\n AgentActivityTrace,\n AgentSearchResult,\n AgentStepStatus,\n AgentTraceKind,\n} from \"./types\";\n\nfunction formatDuration(duration: number) {\n const seconds = Math.max(0, Math.round(duration));\n if (seconds < 60) return `${seconds}s`;\n\n const minutes = Math.floor(seconds / 60);\n const remainder = seconds % 60;\n return remainder === 0 ? `${minutes}m` : `${minutes}m ${remainder}s`;\n}\n\nfunction useControllableOpen({\n open,\n defaultOpen,\n onOpenChange,\n}: {\n open?: boolean;\n defaultOpen: boolean;\n onOpenChange?: (open: boolean) => void;\n}) {\n const [internalOpen, setInternalOpen] = useState(defaultOpen);\n const controlled = open !== undefined;\n const currentOpen = open ?? internalOpen;\n\n const setOpen = useCallback(\n (next: boolean) => {\n if (!controlled) setInternalOpen(next);\n onOpenChange?.(next);\n },\n [controlled, onOpenChange],\n );\n\n return [currentOpen, setOpen] as const;\n}\n\nfunction getContentType(items: AgentActivityItem[]): AgentActivityContentType {\n const first = items[0]?.type;\n return first && items.every((item) => item.type === first) ? first : \"mixed\";\n}\n\nfunction getActiveLabel(type: AgentActivityContentType) {\n if (type === \"search\") return \"Searching the web…\";\n if (type === \"tool\") return \"Running tools…\";\n if (type === \"trace\") return \"Working through the run…\";\n if (type === \"mixed\") return \"Working through it…\";\n return \"Thinking…\";\n}\n\nfunction getSummary(\n type: AgentActivityContentType,\n items: AgentActivityItem[],\n duration: number,\n): ReactNode {\n if (type === \"step\" || type === \"text\") {\n return (\n <>\n Thought for <span className=\"tabular-nums\">{formatDuration(duration)}</span>\n </>\n );\n }\n if (type === \"search\") return \"Searched the web\";\n if (type === \"tool\") {\n return `Ran ${items.length} ${items.length === 1 ? \"tool\" : \"tools\"}`;\n }\n if (type === \"trace\") {\n const messages = items.filter(\n (item) => item.type === \"trace\" && (item.kind === \"thinking\" || item.kind === \"message\"),\n ).length;\n const tools = items.length - messages;\n return `${tools} ${tools === 1 ? \"tool call\" : \"tool calls\"}, ${messages} ${messages === 1 ? \"message\" : \"messages\"}`;\n }\n return `Completed ${items.length} ${items.length === 1 ? \"step\" : \"steps\"}`;\n}\n\nexport function AgentActivity({\n items,\n contentType: initialContentType,\n status = \"working\",\n duration = 0,\n open,\n defaultOpen = false,\n onOpenChange,\n collapseOnComplete = true,\n activeLabel,\n summary,\n renderWorkingStatus,\n renderCompletedStatus,\n maxHeight = 208,\n className,\n contentClassName,\n}: AgentActivityProps) {\n const reduce = useReducedMotion() ?? false;\n const baseId = useId();\n const triggerId = `${baseId}-trigger`;\n const contentId = `${baseId}-content`;\n const contentRef = useRef<HTMLDivElement>(null);\n const viewportRef = useRef<HTMLDivElement>(null);\n const previousStatus = useRef(status);\n const [contentHeight, setContentHeight] = useState(0);\n const [currentOpen, setOpen] = useControllableOpen({\n open,\n defaultOpen,\n onOpenChange,\n });\n const working = status === \"working\";\n const expanded = working || currentOpen;\n const contentType = items.length ? getContentType(items) : (initialContentType ?? \"mixed\");\n const cappedHeight = Math.min(contentHeight, Math.max(0, maxHeight));\n const viewportHeight = working ? Math.max(0, maxHeight) : cappedHeight;\n const capped = contentHeight > maxHeight;\n const streamOffset = working ? Math.min(0, viewportHeight - contentHeight) : 0;\n\n useLayoutEffect(() => {\n const node = contentRef.current;\n if (!node) return;\n\n const measure = () => setContentHeight(node.offsetHeight);\n measure();\n\n if (typeof ResizeObserver === \"undefined\") return;\n const observer = new ResizeObserver(measure);\n observer.observe(node);\n return () => observer.disconnect();\n }, []);\n\n useEffect(() => {\n if (previousStatus.current === \"working\" && status === \"complete\") {\n setOpen(!collapseOnComplete);\n }\n previousStatus.current = status;\n }, [collapseOnComplete, setOpen, status]);\n\n const toggle = () => {\n const next = !currentOpen;\n setOpen(next);\n if (next) requestAnimationFrame(() => viewportRef.current?.scrollTo({ top: 0 }));\n };\n\n const liveLabel = activeLabel ?? getActiveLabel(contentType);\n const completedSummary = summary ?? getSummary(contentType, items, duration);\n const maskImage = capped\n ? working\n ? \"linear-gradient(to bottom, transparent, black 12px)\"\n : \"linear-gradient(to bottom, transparent, black 12px, black calc(100% - 12px), transparent)\"\n : undefined;\n\n return (\n <div\n data-state={working ? \"working\" : expanded ? \"open\" : \"closed\"}\n data-content={contentType}\n aria-busy={working}\n className={cn(\"w-full text-sm\", className)}\n >\n {working ? (\n <div\n id={triggerId}\n role=\"status\"\n className=\"flex h-7 min-w-0 items-center text-muted-foreground\"\n >\n {renderWorkingStatus ? (\n renderWorkingStatus({ label: liveLabel, duration })\n ) : (\n <ThinkingShimmer>{liveLabel}</ThinkingShimmer>\n )}\n </div>\n ) : (\n <button\n id={triggerId}\n type=\"button\"\n aria-expanded={expanded}\n aria-controls={contentId}\n onClick={toggle}\n className=\"group flex h-7 min-w-0 items-center gap-1.5 rounded-md text-left font-medium text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background\"\n >\n <span className=\"truncate\">\n {renderCompletedStatus\n ? renderCompletedStatus({ summary: completedSummary, duration })\n : completedSummary}\n </span>\n <motion.span\n aria-hidden=\"true\"\n animate={{ rotate: expanded ? 180 : 0 }}\n transition={reduce ? { duration: 0 } : SPRING_SWAP}\n className=\"inline-flex shrink-0 text-muted-foreground/70 group-hover:text-foreground\"\n >\n <ChevronDown className=\"size-3.5\" />\n </motion.span>\n </button>\n )}\n\n <AgentDisclosure\n id={contentId}\n role=\"region\"\n aria-labelledby={triggerId}\n open={expanded}\n openHeight={viewportHeight}\n >\n <div\n ref={viewportRef}\n className={cn(\n \"scrollbar-hide pr-1\",\n capped && expanded && !working ? \"overflow-y-auto\" : \"overflow-y-hidden\",\n )}\n style={{ height: viewportHeight, maskImage, WebkitMaskImage: maskImage }}\n >\n <motion.div\n ref={contentRef}\n role=\"list\"\n initial={false}\n animate={{ y: streamOffset }}\n transition={reduce ? { duration: 0 } : SPRING_LAYOUT}\n className={cn(\"space-y-0.5 py-2\", contentClassName)}\n >\n <AnimatePresence mode=\"popLayout\">\n {items.map((item) => (\n <motion.div\n layout=\"position\"\n key={item.id}\n role=\"listitem\"\n initial={reduce ? { opacity: 1 } : { opacity: 0, y: 6 }}\n animate={{ opacity: 1, y: 0 }}\n exit={reduce ? { opacity: 0 } : { opacity: 0, y: -3 }}\n transition={\n reduce\n ? { duration: 0 }\n : {\n opacity: { duration: 0.18, ease: EASE_OUT },\n y: SPRING_LAYOUT,\n layout: SPRING_LAYOUT,\n }\n }\n >\n <ActivityRow item={item} />\n </motion.div>\n ))}\n </AnimatePresence>\n </motion.div>\n </div>\n </AgentDisclosure>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;AAoCA,SAAS,eAAe,UAAkB;CACxC,MAAM,UAAU,KAAK,IAAI,GAAG,KAAK,MAAM,QAAQ,CAAC;CAChD,IAAI,UAAU,IAAI,OAAO,GAAG,QAAQ;CAEpC,MAAM,UAAU,KAAK,MAAM,UAAU,EAAE;CACvC,MAAM,YAAY,UAAU;CAC5B,OAAO,cAAc,IAAI,GAAG,QAAQ,KAAK,GAAG,QAAQ,IAAI,UAAU;AACpE;AAEA,SAAS,oBAAoB,EAC3B,MACA,aACA,gBAKC;CACD,MAAM,CAAC,cAAc,mBAAmB,SAAS,WAAW;CAC5D,MAAM,aAAa,SAAS,KAAA;CAW5B,OAAO,CAVa,QAAQ,cAEZ,aACb,SAAkB;EACjB,IAAI,CAAC,YAAY,gBAAgB,IAAI;EACrC,eAAe,IAAI;CACrB,GACA,CAAC,YAAY,YAAY,CAGA,CAAC;AAC9B;AAEA,SAAS,eAAe,OAAsD;CAC5E,MAAM,QAAQ,MAAM,EAAE,EAAE;CACxB,OAAO,SAAS,MAAM,OAAO,SAAS,KAA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pD,YACE,SACI,EAAE,UAAU,EAAE,IACd;QACE,SAAS;SAAE,UAAU;SAAM,MAAM;QAAS;QAC1C,GAAG;QACH,QAAQ;OACV;OAGN,UAAA,oBAAC,aAAD,EAAmB,KAAO,CAAA;MAChB,GAhBL,KAAK,EAgBA,CACb;KACc,CAAA;IACP,CAAA;GACT,CAAA;EACU,CAAA,CACd;;AAET"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reasoning-text.d.ts","names":[],"sources":["../../../../src/components/agents/loading-states/reasoning-text.tsx"],"mappings":";;KAwBY;UAEK;;EAEf;;EAEA,UAAU;;EAEV;;EAEA;;EAEA,YAAY;EACZ;;
|
|
1
|
+
{"version":3,"file":"reasoning-text.d.ts","names":[],"sources":["../../../../src/components/agents/loading-states/reasoning-text.tsx"],"mappings":";;KAwBY;UAEK;;EAEf;;EAEA,UAAU;;EAEV;;EAEA;;EAEA,YAAY;EACZ;;iBA6Gc,gBACd,SACA,SACA,UACA,iBACA,WACA,aACC,qCAAkB,IAAA"}
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
import { EASE_OUT, SPRING_SWAP } from "../../../lib/ease.js";
|
|
3
3
|
import { TEXT_SHIMMER_CLASS_NAME, TEXT_SHIMMER_KEYFRAMES, textShimmerStyle } from "../../../lib/text-shimmer.js";
|
|
4
4
|
import { Loader } from "../../motion/loader.js";
|
|
5
|
-
import {
|
|
5
|
+
import { TextScramble } from "../../motion/text-scramble.js";
|
|
6
|
+
import { useEffect, useId, useState } from "react";
|
|
6
7
|
import { cn } from "@kumix/utils";
|
|
7
8
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
8
9
|
import { AnimatePresence, motion, useReducedMotion } from "motion/react";
|
|
@@ -13,7 +14,6 @@ const DEFAULT_PHRASES = [
|
|
|
13
14
|
"Connecting the details",
|
|
14
15
|
"Forming a response"
|
|
15
16
|
];
|
|
16
|
-
const SCRAMBLE_GLYPHS = "ABCDEFGHJKLMNPQRSTUVWXYZ0123456789#%&@$?/";
|
|
17
17
|
const CASCADE_STAGGER = .025;
|
|
18
18
|
function CascadePhrase({ phrase, reduce, shimmerDuration }) {
|
|
19
19
|
const text = `${phrase}…`;
|
|
@@ -87,44 +87,12 @@ function SwapPhrase({ phrase, reduce, shimmerDuration }) {
|
|
|
87
87
|
}, phrase)
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
|
-
function ScramblePhrase({ phrase,
|
|
90
|
+
function ScramblePhrase({ phrase, shimmerDuration }) {
|
|
91
91
|
const target = `${phrase}…`;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
mounted.current = true;
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
if (reduce) {
|
|
100
|
-
setDisplay(target);
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
const characters = target.split("");
|
|
104
|
-
const startedAt = performance.now();
|
|
105
|
-
const duration = Math.min(760, Math.max(420, characters.length * 32));
|
|
106
|
-
let frame = 0;
|
|
107
|
-
let lastUpdate = 0;
|
|
108
|
-
const animate = (now) => {
|
|
109
|
-
if (now - lastUpdate >= 40) {
|
|
110
|
-
lastUpdate = now;
|
|
111
|
-
const progress = Math.min((now - startedAt) / duration, 1);
|
|
112
|
-
const settled = Math.floor(progress * characters.length);
|
|
113
|
-
setDisplay(characters.map((character, characterIndex) => {
|
|
114
|
-
if (characterIndex < settled || character === " ") return character;
|
|
115
|
-
return SCRAMBLE_GLYPHS[Math.floor(Math.random() * 41)];
|
|
116
|
-
}).join(""));
|
|
117
|
-
}
|
|
118
|
-
if (now - startedAt < duration) frame = requestAnimationFrame(animate);
|
|
119
|
-
else setDisplay(target);
|
|
120
|
-
};
|
|
121
|
-
frame = requestAnimationFrame(animate);
|
|
122
|
-
return () => cancelAnimationFrame(frame);
|
|
123
|
-
}, [reduce, target]);
|
|
124
|
-
return /* @__PURE__ */ jsx("span", {
|
|
125
|
-
className: cn("col-start-1 row-start-1 inline-block justify-self-start whitespace-pre font-mono tabular-nums", TEXT_SHIMMER_CLASS_NAME),
|
|
126
|
-
style: textShimmerStyle(shimmerDuration),
|
|
127
|
-
children: display
|
|
92
|
+
return /* @__PURE__ */ jsx(TextScramble, {
|
|
93
|
+
text: target,
|
|
94
|
+
className: cn("col-start-1 row-start-1 justify-self-start tabular-nums", TEXT_SHIMMER_CLASS_NAME),
|
|
95
|
+
style: textShimmerStyle(shimmerDuration)
|
|
128
96
|
});
|
|
129
97
|
}
|
|
130
98
|
function ReasoningText({ phrases = DEFAULT_PHRASES, variant = "cascade", interval = 1800, shimmerDuration = 2.2, indicator, className }) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reasoning-text.js","names":[],"sources":["../../../../src/components/agents/loading-states/reasoning-text.tsx"],"sourcesContent":["\"use client\";\n\nimport { type ReactNode, useEffect, useId, useRef, useState } from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { EASE_OUT, SPRING_SWAP } from \"../../../lib/ease\";\nimport {\n TEXT_SHIMMER_CLASS_NAME,\n TEXT_SHIMMER_KEYFRAMES,\n textShimmerStyle,\n} from \"../../../lib/text-shimmer\";\nimport { Loader } from \"../../motion/loader\";\n\nconst DEFAULT_PHRASES = [\n \"Thinking\",\n \"Reading the context\",\n \"Connecting the details\",\n \"Forming a response\",\n];\n\nconst SCRAMBLE_GLYPHS = \"ABCDEFGHJKLMNPQRSTUVWXYZ0123456789#%&@$?/\";\nconst CASCADE_STAGGER = 0.025;\n\nexport type ReasoningTextVariant = \"cascade\" | \"swap\" | \"scramble\";\n\nexport interface ReasoningTextProps {\n /** Phrases cycled through while the agent works. */\n phrases?: string[];\n /** Animation used when the active phrase changes. */\n variant?: ReasoningTextVariant;\n /** Milliseconds each phrase remains visible. */\n interval?: number;\n /** Seconds taken for one shimmer pass. */\n shimmerDuration?: number;\n /** Optional leading visual. Defaults to a terminal-style ASCII loader. */\n indicator?: ReactNode;\n className?: string;\n}\n\ntype PhraseProps = {\n phrase: string;\n reduce: boolean;\n shimmerDuration: number;\n};\n\nfunction CascadePhrase({ phrase, reduce, shimmerDuration }: PhraseProps) {\n const text = `${phrase}…`;\n\n if (reduce) {\n return (\n <span\n className={cn(\n \"col-start-1 row-start-1 inline-block justify-self-start whitespace-pre\",\n TEXT_SHIMMER_CLASS_NAME,\n )}\n style={textShimmerStyle(shimmerDuration)}\n >\n {text}\n </span>\n );\n }\n\n return (\n <AnimatePresence initial={false}>\n <motion.span\n key={phrase}\n className=\"col-start-1 row-start-1 inline-block justify-self-start whitespace-pre\"\n initial=\"initial\"\n animate=\"animate\"\n exit=\"exit\"\n >\n {text.split(\"\").map((character, characterIndex) => (\n <motion.span\n key={characterIndex}\n custom={characterIndex * CASCADE_STAGGER}\n variants={{\n initial: { opacity: 0, y: \"100%\" },\n animate: (delay: number) => ({\n opacity: 1,\n y: \"0%\",\n transition: { ...SPRING_SWAP, delay },\n }),\n exit: (delay: number) => ({\n opacity: 0,\n y: \"-100%\",\n transition: {\n duration: 0.14,\n ease: EASE_OUT,\n delay: delay * 0.45,\n },\n }),\n }}\n className={cn(\n \"inline-block whitespace-pre will-change-[opacity,transform]\",\n TEXT_SHIMMER_CLASS_NAME,\n )}\n style={textShimmerStyle(shimmerDuration)}\n >\n {character}\n </motion.span>\n ))}\n </motion.span>\n </AnimatePresence>\n );\n}\n\nfunction SwapPhrase({ phrase, reduce, shimmerDuration }: PhraseProps) {\n return (\n <AnimatePresence initial={false}>\n <motion.span\n key={phrase}\n className={cn(\n \"col-start-1 row-start-1 inline-block justify-self-start whitespace-nowrap will-change-[opacity,transform]\",\n TEXT_SHIMMER_CLASS_NAME,\n )}\n style={textShimmerStyle(shimmerDuration)}\n initial={reduce ? { opacity: 0 } : { opacity: 0, y: 3 }}\n animate={reduce ? { opacity: 1 } : { opacity: 1, y: 0 }}\n exit={reduce ? { opacity: 0 } : { opacity: 0, y: -3 }}\n transition={{\n duration: reduce ? 0.12 : 0.2,\n ease: EASE_OUT,\n }}\n >\n {phrase}…\n </motion.span>\n </AnimatePresence>\n );\n}\n\nfunction ScramblePhrase({ phrase, reduce, shimmerDuration }: PhraseProps) {\n const target = `${phrase}…`;\n const [display, setDisplay] = useState(target);\n const mounted = useRef(false);\n\n useEffect(() => {\n if (!mounted.current) {\n mounted.current = true;\n return;\n }\n\n if (reduce) {\n setDisplay(target);\n return;\n }\n\n const characters = target.split(\"\");\n const startedAt = performance.now();\n const duration = Math.min(760, Math.max(420, characters.length * 32));\n let frame = 0;\n let lastUpdate = 0;\n\n const animate = (now: number) => {\n if (now - lastUpdate >= 40) {\n lastUpdate = now;\n const progress = Math.min((now - startedAt) / duration, 1);\n const settled = Math.floor(progress * characters.length);\n\n setDisplay(\n characters\n .map((character, characterIndex) => {\n if (characterIndex < settled || character === \" \") {\n return character;\n }\n return SCRAMBLE_GLYPHS[Math.floor(Math.random() * SCRAMBLE_GLYPHS.length)];\n })\n .join(\"\"),\n );\n }\n\n if (now - startedAt < duration) {\n frame = requestAnimationFrame(animate);\n } else {\n setDisplay(target);\n }\n };\n\n frame = requestAnimationFrame(animate);\n return () => cancelAnimationFrame(frame);\n }, [reduce, target]);\n\n return (\n <span\n className={cn(\n \"col-start-1 row-start-1 inline-block justify-self-start whitespace-pre font-mono tabular-nums\",\n TEXT_SHIMMER_CLASS_NAME,\n )}\n style={textShimmerStyle(shimmerDuration)}\n >\n {display}\n </span>\n );\n}\n\nexport function ReasoningText({\n phrases = DEFAULT_PHRASES,\n variant = \"cascade\",\n interval = 1800,\n shimmerDuration = 2.2,\n indicator,\n className,\n}: ReasoningTextProps) {\n const reduce = useReducedMotion() ?? false;\n const [index, setIndex] = useState(0);\n const statusId = useId();\n const safePhrases = phrases.length > 0 ? phrases : DEFAULT_PHRASES;\n const phrase = safePhrases[index % safePhrases.length];\n const longestPhrase = safePhrases.reduce((longest, current) =>\n current.length > longest.length ? current : longest,\n );\n const phraseProps = { phrase, reduce, shimmerDuration };\n\n useEffect(() => {\n if (safePhrases.length < 2) return;\n\n const timer = window.setInterval(\n () => {\n setIndex((current) => (current + 1) % safePhrases.length);\n },\n Math.max(600, interval),\n );\n\n return () => window.clearInterval(timer);\n }, [interval, safePhrases.length]);\n\n return (\n <>\n <style>{TEXT_SHIMMER_KEYFRAMES}</style>\n <span\n role=\"status\"\n aria-live=\"polite\"\n aria-labelledby={statusId}\n className={cn(\n \"inline-flex items-center gap-2 font-medium text-muted-foreground text-sm\",\n className,\n )}\n >\n <span\n aria-hidden=\"true\"\n className=\"inline-flex size-3 shrink-0 items-center justify-center\"\n >\n {indicator ?? <Loader variant=\"ascii-line\" size={14} speed={0.8} label=\"Reasoning\" />}\n </span>\n\n <span aria-hidden=\"true\" className=\"grid overflow-hidden text-left\">\n <span className=\"invisible col-start-1 row-start-1 whitespace-nowrap\">\n {longestPhrase}…\n </span>\n {variant === \"cascade\" ? (\n <CascadePhrase {...phraseProps} />\n ) : variant === \"scramble\" ? (\n <ScramblePhrase {...phraseProps} />\n ) : (\n <SwapPhrase {...phraseProps} />\n )}\n </span>\n\n <span id={statusId} className=\"sr-only\">\n {phrase}\n </span>\n </span>\n </>\n );\n}\n"],"mappings":";;;;;;;;;AAcA,MAAM,kBAAkB;CACtB;CACA;CACA;CACA;AACF;AAEA,MAAM,kBAAkB;AACxB,MAAM,kBAAkB;AAwBxB,SAAS,cAAc,EAAE,QAAQ,QAAQ,mBAAgC;CACvE,MAAM,OAAO,GAAG,OAAO;CAEvB,IAAI,QACF,OACE,oBAAC,QAAD;EACE,WAAW,GACT,0EACA,uBACF;EACA,OAAO,iBAAiB,eAAe;EAEtC,UAAA;CACG,CAAA;CAIV,OACE,oBAAC,iBAAD;EAAiB,SAAS;EACxB,UAAA,oBAAC,OAAO,MAAR;GAEE,WAAU;GACV,SAAQ;GACR,SAAQ;GACR,MAAK;GAEJ,UAAA,KAAK,MAAM,EAAE,CAAC,CAAC,KAAK,WAAW,mBAC9B,oBAA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,kBACb;GACJ,UAAU,aAAa,UAAU,KAAK,YAAY,MAAM;EAC1D,GACA,KAAK,IAAI,KAAK,QAAQ,CACxB;EAEA,aAAa,OAAO,cAAc,KAAK;CACzC,GAAG,CAAC,UAAU,YAAY,MAAM,CAAC;CAEjC,OACE,qBAAA,YAAA,EAAA,UAAA,CACE,oBAAC,SAAD,EAAA,UAAQ,uBAA8B,CAAA,GACtC,qBAAC,QAAD;EACE,MAAK;EACL,aAAU;EACV,mBAAiB;EACjB,WAAW,GACT,4EACA,SACF;EAPF,UAAA;GASE,oBAAC,QAAD;IACE,eAAY;IACZ,WAAU;IAET,UAAA,aAAa,oBAAC,QAAD;KAAQ,SAAQ;KAAa,MAAM;KAAI,OAAO;KAAK,OAAM;IAAa,CAAA;GAChF,CAAA;GAEN,qBAAC,QAAD;IAAM,eAAY;IAAO,WAAU;IAAnC,UAAA,CACE,qBAAC,QAAD;KAAM,WAAU;KAAhB,UAAA,CACG,eAAc,GACX;IACL,CAAA,GAAA,YAAY,YACX,oBAAC,eAAD,EAAe,GAAI,YAAc,CAAA,IAC/B,YAAY,aACd,oBAAC,gBAAD,EAAgB,GAAI,YAAc,CAAA,IAElC,oBAAC,YAAD,EAAY,GAAI,YAAc,CAAA,CAE5B;;GAEN,oBAAC,QAAD;IAAM,IAAI;IAAU,WAAU;IAC3B,UAAA;GACG,CAAA;EACF;CACN,CAAA,CAAA,EAAA,CAAA;AAEN"}
|
|
1
|
+
{"version":3,"file":"reasoning-text.js","names":[],"sources":["../../../../src/components/agents/loading-states/reasoning-text.tsx"],"sourcesContent":["\"use client\";\n\nimport { type ReactNode, useEffect, useId, useState } from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { EASE_OUT, SPRING_SWAP } from \"../../../lib/ease\";\nimport {\n TEXT_SHIMMER_CLASS_NAME,\n TEXT_SHIMMER_KEYFRAMES,\n textShimmerStyle,\n} from \"../../../lib/text-shimmer\";\nimport { Loader } from \"../../motion/loader\";\nimport { TextScramble } from \"../../motion/text-scramble\";\n\nconst DEFAULT_PHRASES = [\n \"Thinking\",\n \"Reading the context\",\n \"Connecting the details\",\n \"Forming a response\",\n];\n\nconst CASCADE_STAGGER = 0.025;\n\nexport type ReasoningTextVariant = \"cascade\" | \"swap\" | \"scramble\";\n\nexport interface ReasoningTextProps {\n /** Phrases cycled through while the agent works. */\n phrases?: string[];\n /** Animation used when the active phrase changes. */\n variant?: ReasoningTextVariant;\n /** Milliseconds each phrase remains visible. */\n interval?: number;\n /** Seconds taken for one shimmer pass. */\n shimmerDuration?: number;\n /** Optional leading visual. Defaults to a terminal-style ASCII loader. */\n indicator?: ReactNode;\n className?: string;\n}\n\ntype PhraseProps = {\n phrase: string;\n reduce: boolean;\n shimmerDuration: number;\n};\n\nfunction CascadePhrase({ phrase, reduce, shimmerDuration }: PhraseProps) {\n const text = `${phrase}…`;\n\n if (reduce) {\n return (\n <span\n className={cn(\n \"col-start-1 row-start-1 inline-block justify-self-start whitespace-pre\",\n TEXT_SHIMMER_CLASS_NAME,\n )}\n style={textShimmerStyle(shimmerDuration)}\n >\n {text}\n </span>\n );\n }\n\n return (\n <AnimatePresence initial={false}>\n <motion.span\n key={phrase}\n className=\"col-start-1 row-start-1 inline-block justify-self-start whitespace-pre\"\n initial=\"initial\"\n animate=\"animate\"\n exit=\"exit\"\n >\n {text.split(\"\").map((character, characterIndex) => (\n <motion.span\n key={characterIndex}\n custom={characterIndex * CASCADE_STAGGER}\n variants={{\n initial: { opacity: 0, y: \"100%\" },\n animate: (delay: number) => ({\n opacity: 1,\n y: \"0%\",\n transition: { ...SPRING_SWAP, delay },\n }),\n exit: (delay: number) => ({\n opacity: 0,\n y: \"-100%\",\n transition: {\n duration: 0.14,\n ease: EASE_OUT,\n delay: delay * 0.45,\n },\n }),\n }}\n className={cn(\n \"inline-block whitespace-pre will-change-[opacity,transform]\",\n TEXT_SHIMMER_CLASS_NAME,\n )}\n style={textShimmerStyle(shimmerDuration)}\n >\n {character}\n </motion.span>\n ))}\n </motion.span>\n </AnimatePresence>\n );\n}\n\nfunction SwapPhrase({ phrase, reduce, shimmerDuration }: PhraseProps) {\n return (\n <AnimatePresence initial={false}>\n <motion.span\n key={phrase}\n className={cn(\n \"col-start-1 row-start-1 inline-block justify-self-start whitespace-nowrap will-change-[opacity,transform]\",\n TEXT_SHIMMER_CLASS_NAME,\n )}\n style={textShimmerStyle(shimmerDuration)}\n initial={reduce ? { opacity: 0 } : { opacity: 0, y: 3 }}\n animate={reduce ? { opacity: 1 } : { opacity: 1, y: 0 }}\n exit={reduce ? { opacity: 0 } : { opacity: 0, y: -3 }}\n transition={{\n duration: reduce ? 0.12 : 0.2,\n ease: EASE_OUT,\n }}\n >\n {phrase}…\n </motion.span>\n </AnimatePresence>\n );\n}\n\nfunction ScramblePhrase({ phrase, shimmerDuration }: PhraseProps) {\n const target = `${phrase}…`;\n\n return (\n <TextScramble\n text={target}\n className={cn(\n \"col-start-1 row-start-1 justify-self-start tabular-nums\",\n TEXT_SHIMMER_CLASS_NAME,\n )}\n style={textShimmerStyle(shimmerDuration)}\n />\n );\n}\n\nexport function ReasoningText({\n phrases = DEFAULT_PHRASES,\n variant = \"cascade\",\n interval = 1800,\n shimmerDuration = 2.2,\n indicator,\n className,\n}: ReasoningTextProps) {\n const reduce = useReducedMotion() ?? false;\n const [index, setIndex] = useState(0);\n const statusId = useId();\n const safePhrases = phrases.length > 0 ? phrases : DEFAULT_PHRASES;\n const phrase = safePhrases[index % safePhrases.length];\n const longestPhrase = safePhrases.reduce((longest, current) =>\n current.length > longest.length ? current : longest,\n );\n const phraseProps = { phrase, reduce, shimmerDuration };\n\n useEffect(() => {\n if (safePhrases.length < 2) return;\n\n const timer = window.setInterval(\n () => {\n setIndex((current) => (current + 1) % safePhrases.length);\n },\n Math.max(600, interval),\n );\n\n return () => window.clearInterval(timer);\n }, [interval, safePhrases.length]);\n\n return (\n <>\n <style>{TEXT_SHIMMER_KEYFRAMES}</style>\n <span\n role=\"status\"\n aria-live=\"polite\"\n aria-labelledby={statusId}\n className={cn(\n \"inline-flex items-center gap-2 font-medium text-muted-foreground text-sm\",\n className,\n )}\n >\n <span\n aria-hidden=\"true\"\n className=\"inline-flex size-3 shrink-0 items-center justify-center\"\n >\n {indicator ?? <Loader variant=\"ascii-line\" size={14} speed={0.8} label=\"Reasoning\" />}\n </span>\n\n <span aria-hidden=\"true\" className=\"grid overflow-hidden text-left\">\n <span className=\"invisible col-start-1 row-start-1 whitespace-nowrap\">\n {longestPhrase}…\n </span>\n {variant === \"cascade\" ? (\n <CascadePhrase {...phraseProps} />\n ) : variant === \"scramble\" ? (\n <ScramblePhrase {...phraseProps} />\n ) : (\n <SwapPhrase {...phraseProps} />\n )}\n </span>\n\n <span id={statusId} className=\"sr-only\">\n {phrase}\n </span>\n </span>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;AAeA,MAAM,kBAAkB;CACtB;CACA;CACA;CACA;AACF;AAEA,MAAM,kBAAkB;AAwBxB,SAAS,cAAc,EAAE,QAAQ,QAAQ,mBAAgC;CACvE,MAAM,OAAO,GAAG,OAAO;CAEvB,IAAI,QACF,OACE,oBAAC,QAAD;EACE,WAAW,GACT,0EACA,uBACF;EACA,OAAO,iBAAiB,eAAe;EAEtC,UAAA;CACG,CAAA;CAIV,OACE,oBAAC,iBAAD;EAAiB,SAAS;EACxB,UAAA,oBAAC,OAAO,MAAR;GAEE,WAAU;GACV,SAAQ;GACR,SAAQ;GACR,MAAK;GAEJ,UAAA,KAAK,MAAM,EAAE,CAAC,CAAC,KAAK,WAAW,mBAC9B,oBAAC,OAAO,MAAR;IAEE,QAAQ,iBAAiB;IACzB,UAAU;KACR,SAAS;MAAE,SAAS;MAAG,GAAG;KAAO;KACjC,UAAU,WAAmB;MAC3B,SAAS;MACT,GAAG;MACH,YAAY;OAAE,GAAG;OAAa;MAAM;KACtC;KACA,OAAO,WAAmB;MACxB,SAAS;MACT,GAAG;MACH,YAAY;OACV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EAAQ;EAAQ;CAAgB;CAEtD,gBAAgB;EACd,IAAI,YAAY,SAAS,GAAG;EAE5B,MAAM,QAAQ,OAAO,kBACb;GACJ,UAAU,aAAa,UAAU,KAAK,YAAY,MAAM;EAC1D,GACA,KAAK,IAAI,KAAK,QAAQ,CACxB;EAEA,aAAa,OAAO,cAAc,KAAK;CACzC,GAAG,CAAC,UAAU,YAAY,MAAM,CAAC;CAEjC,OACE,qBAAA,YAAA,EAAA,UAAA,CACE,oBAAC,SAAD,EAAA,UAAQ,uBAA8B,CAAA,GACtC,qBAAC,QAAD;EACE,MAAK;EACL,aAAU;EACV,mBAAiB;EACjB,WAAW,GACT,4EACA,SACF;EAPF,UAAA;GASE,oBAAC,QAAD;IACE,eAAY;IACZ,WAAU;IAET,UAAA,aAAa,oBAAC,QAAD;KAAQ,SAAQ;KAAa,MAAM;KAAI,OAAO;KAAK,OAAM;IAAa,CAAA;GAChF,CAAA;GAEN,qBAAC,QAAD;IAAM,eAAY;IAAO,WAAU;IAAnC,UAAA,CACE,qBAAC,QAAD;KAAM,WAAU;KAAhB,UAAA,CACG,eAAc,GACX;IACL,CAAA,GAAA,YAAY,YACX,oBAAC,eAAD,EAAe,GAAI,YAAc,CAAA,IAC/B,YAAY,aACd,oBAAC,gBAAD,EAAgB,GAAI,YAAc,CAAA,IAElC,oBAAC,YAAD,EAAY,GAAI,YAAc,CAAA,CAE5B;;GAEN,oBAAC,QAAD;IAAM,IAAI;IAAU,WAAU;IAC3B,UAAA;GACG,CAAA;EACF;CACN,CAAA,CAAA,EAAA,CAAA;AAEN"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action-swap.d.ts","names":[],"sources":["../../../src/components/motion/action-swap.tsx"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"action-swap.d.ts","names":[],"sources":["../../../src/components/motion/action-swap.tsx"],"mappings":";;;KAeY;EACV;EACA,OAAO;EACP,OAAO;EACP;;KAGU;KACA;KACA;UAKK,8BACP,KAAK;EACb,OAAO;EACP;EACA;EACA,iBAAiB,eAAe,MAAM;EACtC,UAAU;EACV,OAAO;EACP,YAAY;EACZ;EACA;;UAGe;EACf;EACA,UAAU;EACV,YAAY;EACZ;;UAGe;EACf;EACA,UAAU;EACV,YAAY;EACZ;;iBA+Gc,iBACd,OACA,UACA,WACA,aACC,sCAAmB,IAAA;iBAyEN,iBACd,OACA,UACA,WACA,aACC,sCAAmB,IAAA;iBA0BN,mBACd,OACA,OACA,cACA,eACA,SACA,MACA,WACA,UACA,OACA,WACA,UACA,YACG,QACF,wCAAqB,IAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { EASE_OUT,
|
|
3
|
-
import {
|
|
2
|
+
import { EASE_OUT, SPRING_PRESS, SPRING_SWAP } from "../../lib/ease.js";
|
|
3
|
+
import { useState } from "react";
|
|
4
4
|
import { cn } from "@kumix/utils";
|
|
5
5
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
6
6
|
import { AnimatePresence, motion, useReducedMotion } from "motion/react";
|
|
@@ -137,27 +137,22 @@ const SIZE_CLASS = {
|
|
|
137
137
|
};
|
|
138
138
|
function ActionSwapText({ value, children, animation = "blur", className }) {
|
|
139
139
|
const reduce = useReducedMotion();
|
|
140
|
-
const measureRef = useRef(null);
|
|
141
|
-
const [width, setWidth] = useState();
|
|
142
|
-
useLayoutEffect(() => {
|
|
143
|
-
const nextWidth = measureRef.current?.offsetWidth;
|
|
144
|
-
if (!nextWidth) return;
|
|
145
|
-
setWidth((currentWidth) => currentWidth === nextWidth ? currentWidth : nextWidth);
|
|
146
|
-
});
|
|
147
140
|
const label = typeof children === "string" ? children : null;
|
|
148
141
|
const cascade = animation === "cascade" && label !== null && !reduce;
|
|
149
142
|
const coreAnimation = animation === "cascade" ? "roll" : animation;
|
|
150
143
|
return /* @__PURE__ */ jsxs("span", {
|
|
151
|
-
className: cn("relative inline-block
|
|
144
|
+
className: cn("relative -my-[0.08em] inline-block whitespace-nowrap py-[0.08em] align-bottom", className),
|
|
152
145
|
style: {
|
|
153
|
-
|
|
154
|
-
|
|
146
|
+
clipPath: "inset(0 -999px)",
|
|
147
|
+
WebkitClipPath: "inset(0 -999px)"
|
|
155
148
|
},
|
|
156
149
|
children: [/* @__PURE__ */ jsx("span", {
|
|
157
|
-
ref: measureRef,
|
|
158
150
|
"aria-hidden": true,
|
|
159
151
|
className: "invisible inline-block whitespace-nowrap",
|
|
160
|
-
children
|
|
152
|
+
children: cascade ? label.split("").map((char, index) => /* @__PURE__ */ jsx("span", {
|
|
153
|
+
className: "inline-block whitespace-pre",
|
|
154
|
+
children: char
|
|
155
|
+
}, index)) : children
|
|
161
156
|
}), cascade ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("span", {
|
|
162
157
|
className: "sr-only",
|
|
163
158
|
children: label
|
|
@@ -168,7 +163,7 @@ function ActionSwapText({ value, children, animation = "blur", className }) {
|
|
|
168
163
|
initial: "initial",
|
|
169
164
|
animate: "animate",
|
|
170
165
|
exit: "exit",
|
|
171
|
-
className: "absolute top-0 left-0 inline-block whitespace-pre",
|
|
166
|
+
className: "absolute top-[0.08em] left-0 inline-block whitespace-pre",
|
|
172
167
|
children: label.split("").map((char, i) => /* @__PURE__ */ jsx(motion.span, {
|
|
173
168
|
custom: i * CASCADE_STAGGER,
|
|
174
169
|
variants: CASCADE_LETTER_VARIANTS,
|
|
@@ -188,7 +183,7 @@ function ActionSwapText({ value, children, animation = "blur", className }) {
|
|
|
188
183
|
y: 0
|
|
189
184
|
} : "animate",
|
|
190
185
|
exit: reduce ? void 0 : "exit",
|
|
191
|
-
className: "absolute top-0 left-0 inline-block will-change-[opacity,filter,transform]",
|
|
186
|
+
className: "absolute top-[0.08em] left-0 inline-block will-change-[opacity,filter,transform]",
|
|
192
187
|
children
|
|
193
188
|
}, `${animation}-${value}`)
|
|
194
189
|
})]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action-swap.js","names":[],"sources":["../../../src/components/motion/action-swap.tsx"],"sourcesContent":["\"use client\";\n\nimport { type ReactNode, useLayoutEffect, useRef, useState } from \"react\";\nimport {\n AnimatePresence,\n type HTMLMotionProps,\n motion,\n useReducedMotion,\n type Variants,\n} from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { EASE_OUT, EASE_OUT_CSS, SPRING_PRESS, SPRING_SWAP } from \"../../lib/ease\";\n\nexport type ActionSwapItem = {\n id: string;\n label: ReactNode;\n icon?: ReactNode;\n ariaLabel?: string;\n};\n\nexport type ActionSwapButtonVariant = \"primary\" | \"secondary\" | \"outline\" | \"ghost\";\nexport type ActionSwapButtonSize = \"sm\" | \"md\" | \"lg\" | \"icon\";\nexport type ActionSwapAnimation = \"blur\" | \"roll\" | \"cascade\";\n\n/** Animations with a single-element variant set (cascade animates per letter). */\ntype CoreAnimation = \"blur\" | \"roll\";\n\nexport interface ActionSwapButtonProps\n extends Omit<HTMLMotionProps<\"button\">, \"children\" | \"onChange\"> {\n items: ActionSwapItem[];\n value?: string;\n defaultValue?: string;\n onValueChange?: (value: string, item: ActionSwapItem) => void;\n variant?: ActionSwapButtonVariant;\n size?: ActionSwapButtonSize;\n animation?: ActionSwapAnimation;\n iconOnly?: boolean;\n cycle?: boolean;\n}\n\nexport interface ActionSwapTextProps {\n value: string;\n children: ReactNode;\n animation?: ActionSwapAnimation;\n className?: string;\n}\n\nexport interface ActionSwapIconProps {\n value: string;\n children: ReactNode;\n animation?: ActionSwapAnimation;\n className?: string;\n}\n\nconst BLUR_TRANSITION = { duration: 0.2, ease: \"easeInOut\" } as const;\nconst ROLL_TRANSITION = SPRING_SWAP;\nconst ROLL_EXIT_TRANSITION = { duration: 0.14, ease: EASE_OUT } as const;\nconst SWAP_BLUR = \"blur(8px)\";\nconst ROLL_BLUR = \"blur(3px)\";\n\n// Cascade rolls the label one letter at a time, left to right. The leaving\n// and landing strings overlap as independent layers (no shared cells), so\n// proportional glyph widths never jitter. Exits cascade at half the enter\n// stagger so the tail of the old label lingers briefly.\nconst CASCADE_STAGGER = 0.025;\n\nconst CASCADE_LETTER_VARIANTS: Variants = {\n initial: { opacity: 0, y: \"105%\", filter: ROLL_BLUR },\n animate: (delay: number = 0) => ({\n opacity: 1,\n y: \"0%\",\n filter: \"blur(0px)\",\n transition: { ...SPRING_SWAP, delay },\n }),\n exit: (delay: number = 0) => ({\n opacity: 0,\n y: \"-105%\",\n filter: ROLL_BLUR,\n transition: { duration: 0.16, ease: EASE_OUT, delay: delay * 0.5 },\n }),\n};\n\nconst TEXT_VARIANTS: Record<CoreAnimation, Variants> = {\n blur: {\n initial: { opacity: 0, scale: 0.94, filter: SWAP_BLUR },\n animate: {\n opacity: 1,\n scale: 1,\n filter: \"blur(0px)\",\n transition: BLUR_TRANSITION,\n },\n exit: {\n opacity: 0,\n scale: 0.94,\n filter: SWAP_BLUR,\n transition: BLUR_TRANSITION,\n },\n },\n roll: {\n initial: { opacity: 0, y: \"90%\", filter: ROLL_BLUR },\n animate: {\n opacity: 1,\n y: \"0%\",\n filter: \"blur(0px)\",\n transition: ROLL_TRANSITION,\n },\n exit: {\n opacity: 0,\n y: \"-90%\",\n filter: ROLL_BLUR,\n transition: ROLL_EXIT_TRANSITION,\n },\n },\n};\n\nconst ICON_VARIANTS: Record<CoreAnimation, Variants> = {\n blur: {\n initial: { opacity: 0, scale: 0.25, filter: SWAP_BLUR },\n animate: {\n opacity: 1,\n scale: 1,\n filter: \"blur(0px)\",\n transition: BLUR_TRANSITION,\n },\n exit: {\n opacity: 0,\n scale: 0.25,\n filter: SWAP_BLUR,\n transition: BLUR_TRANSITION,\n },\n },\n roll: {\n initial: { opacity: 0, y: 12, filter: ROLL_BLUR },\n animate: {\n opacity: 1,\n y: 0,\n filter: \"blur(0px)\",\n transition: ROLL_TRANSITION,\n },\n exit: {\n opacity: 0,\n y: -12,\n filter: ROLL_BLUR,\n transition: ROLL_EXIT_TRANSITION,\n },\n },\n};\n\nconst VARIANT_CLASS: Record<ActionSwapButtonVariant, string> = {\n primary: \"bg-primary text-primary-foreground hover:bg-primary/90\",\n secondary: \"border border-border bg-card text-foreground hover:border-border\",\n outline: \"border border-border bg-transparent text-foreground hover:bg-primary/5\",\n ghost: \"text-muted-foreground hover:bg-primary/5 hover:text-foreground\",\n};\n\nconst SIZE_CLASS: Record<ActionSwapButtonSize, string> = {\n sm: \"h-8 gap-1.5 rounded-full px-3 text-xs\",\n md: \"h-10 gap-2 rounded-full px-4 text-sm\",\n lg: \"h-12 gap-2.5 rounded-full px-5 text-base\",\n icon: \"h-10 w-10 rounded-full\",\n};\n\nexport function ActionSwapText({\n value,\n children,\n animation = \"blur\",\n className,\n}: ActionSwapTextProps) {\n const reduce = useReducedMotion();\n const measureRef = useRef<HTMLSpanElement>(null);\n const [width, setWidth] = useState<number>();\n\n useLayoutEffect(() => {\n const nextWidth = measureRef.current?.offsetWidth;\n if (!nextWidth) return;\n setWidth((currentWidth) => (currentWidth === nextWidth ? currentWidth : nextWidth));\n });\n\n // Cascade needs a plain string to split into letters; non-string content\n // and reduced motion fall back to the closest single-element animation.\n const label = typeof children === \"string\" ? children : null;\n const cascade = animation === \"cascade\" && label !== null && !reduce;\n const coreAnimation: CoreAnimation = animation === \"cascade\" ? \"roll\" : animation;\n\n return (\n <span\n className={cn(\n \"relative inline-block overflow-hidden whitespace-nowrap align-bottom\",\n className,\n )}\n style={{\n width,\n transition: reduce ? undefined : `width 220ms ${EASE_OUT_CSS}`,\n }}\n >\n <span ref={measureRef} aria-hidden className=\"invisible inline-block whitespace-nowrap\">\n {children}\n </span>\n {cascade ? (\n <>\n {/* Letters are decorative fragments; readers get the whole label. */}\n <span className=\"sr-only\">{label}</span>\n <AnimatePresence initial={false}>\n <motion.span\n key={`cascade-${value}`}\n aria-hidden\n initial=\"initial\"\n animate=\"animate\"\n exit=\"exit\"\n className=\"absolute top-0 left-0 inline-block whitespace-pre\"\n >\n {label.split(\"\").map((char, i) => (\n <motion.span\n key={i}\n custom={i * CASCADE_STAGGER}\n variants={CASCADE_LETTER_VARIANTS}\n className=\"inline-block whitespace-pre will-change-[opacity,filter,transform]\"\n >\n {char}\n </motion.span>\n ))}\n </motion.span>\n </AnimatePresence>\n </>\n ) : (\n <AnimatePresence initial={false}>\n <motion.span\n key={`${animation}-${value}`}\n variants={TEXT_VARIANTS[coreAnimation]}\n initial={reduce ? false : \"initial\"}\n animate={reduce ? { opacity: 1, filter: \"blur(0px)\", scale: 1, y: 0 } : \"animate\"}\n exit={reduce ? undefined : \"exit\"}\n className=\"absolute top-0 left-0 inline-block will-change-[opacity,filter,transform]\"\n >\n {children}\n </motion.span>\n </AnimatePresence>\n )}\n </span>\n );\n}\n\nexport function ActionSwapIcon({\n value,\n children,\n animation = \"blur\",\n className,\n}: ActionSwapIconProps) {\n const reduce = useReducedMotion();\n // Icons are single elements — cascade maps to its closest motion, roll.\n const coreAnimation: CoreAnimation = animation === \"cascade\" ? \"roll\" : animation;\n\n return (\n <span\n className={cn(\"relative inline-grid shrink-0 place-items-center overflow-hidden\", className)}\n >\n <AnimatePresence mode=\"popLayout\" initial={false}>\n <motion.span\n key={`${animation}-${value}`}\n aria-hidden\n variants={ICON_VARIANTS[coreAnimation]}\n initial={reduce ? false : \"initial\"}\n animate={reduce ? { opacity: 1, filter: \"blur(0px)\", scale: 1, y: 0 } : \"animate\"}\n exit={reduce ? undefined : \"exit\"}\n className=\"col-start-1 row-start-1 inline-flex items-center justify-center will-change-[opacity,filter,transform]\"\n >\n {children}\n </motion.span>\n </AnimatePresence>\n </span>\n );\n}\n\nexport function ActionSwapButton({\n items,\n value,\n defaultValue,\n onValueChange,\n variant = \"secondary\",\n size = \"md\",\n animation = \"blur\",\n iconOnly = size === \"icon\",\n cycle = true,\n className,\n disabled,\n onClick,\n ...rest\n}: ActionSwapButtonProps) {\n const reduce = useReducedMotion();\n const [internalValue, setInternalValue] = useState(defaultValue ?? items[0]?.id);\n const currentValue = value ?? internalValue;\n const activeIndex = Math.max(\n 0,\n items.findIndex((item) => item.id === currentValue),\n );\n const activeItem = items[activeIndex] ?? items[0];\n const hasIcon = items.some((item) => item.icon);\n const nextItem = cycle && items.length > 0 ? items[(activeIndex + 1) % items.length] : undefined;\n\n if (!activeItem) return null;\n\n const accessibleLabel =\n activeItem.ariaLabel ??\n (iconOnly && typeof activeItem.label === \"string\" ? activeItem.label : undefined);\n\n return (\n <motion.button\n type=\"button\"\n disabled={disabled}\n whileTap={reduce || disabled ? undefined : { scale: 0.97 }}\n transition={SPRING_PRESS}\n className={cn(\n \"inline-flex items-center justify-center overflow-hidden font-medium transition-colors\",\n \"disabled:pointer-events-none disabled:opacity-50\",\n VARIANT_CLASS[variant],\n SIZE_CLASS[size],\n className,\n )}\n aria-label={accessibleLabel}\n onClick={(event) => {\n onClick?.(event);\n if (event.defaultPrevented || disabled || !cycle || !nextItem) return;\n if (value === undefined) setInternalValue(nextItem.id);\n onValueChange?.(nextItem.id, nextItem);\n }}\n {...rest}\n >\n {hasIcon ? (\n <ActionSwapIcon value={activeItem.id} animation={animation} className=\"h-4 w-4\">\n {activeItem.icon ?? null}\n </ActionSwapIcon>\n ) : null}\n {!iconOnly ? (\n <ActionSwapText value={activeItem.id} animation={animation}>\n {activeItem.label}\n </ActionSwapText>\n ) : null}\n </motion.button>\n );\n}\n"],"mappings":";;;;;;;AAuDA,MAAM,kBAAkB;CAAE,UAAU;CAAK,MAAM;AAAY;AAC3D,MAAM,kBAAkB;AACxB,MAAM,uBAAuB;CAAE,UAAU;CAAM,MAAM;AAAS;AAC9D,MAAM,YAAY;AAClB,MAAM,YAAY;AAMlB,MAAM,kBAAkB;AAExB,MAAM,0BAAoC;CACxC,SAAS;EAAE,SAAS;EAAG,GAAG;EAAQ,QAAQ;CAAU;CACpD,UAAU,QAAgB,OAAO;EAC/B,SAAS;EACT,GAAG;EACH,QAAQ;EACR,YAAY;GAAE,GAAG;GAAa;EAAM;CACtC;CACA,OAAO,QAAgB,OAAO;EAC5B,SAAS;EAC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ClB,UAAU,KAAK;GACf,IAAI,MAAM,oBAAoB,YAAY,CAAC,SAAS,CAAC,UAAU;GAC/D,IAAI,UAAU,KAAA,GAAW,iBAAiB,SAAS,EAAE;GACrD,gBAAgB,SAAS,IAAI,QAAQ;EACvC;EACA,GAAI;EAnBN,UAAA,CAqBG,UACC,oBAAC,gBAAD;GAAgB,OAAO,WAAW;GAAe;GAAW,WAAU;GACnE,UAAA,WAAW,QAAQ;EACN,CAAA,IACd,MACH,CAAC,WACA,oBAAC,gBAAD;GAAgB,OAAO,WAAW;GAAe;GAC9C,UAAA,WAAW;EACE,CAAA,IACd,IACS;;AAEnB"}
|
|
1
|
+
{"version":3,"file":"action-swap.js","names":[],"sources":["../../../src/components/motion/action-swap.tsx"],"sourcesContent":["\"use client\";\n\nimport type { ReactNode } from \"react\";\nimport { useState } from \"react\";\nimport {\n AnimatePresence,\n type HTMLMotionProps,\n motion,\n useReducedMotion,\n type Variants,\n} from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { EASE_OUT, SPRING_PRESS, SPRING_SWAP } from \"../../lib/ease\";\n\nexport type ActionSwapItem = {\n id: string;\n label: ReactNode;\n icon?: ReactNode;\n ariaLabel?: string;\n};\n\nexport type ActionSwapButtonVariant = \"primary\" | \"secondary\" | \"outline\" | \"ghost\";\nexport type ActionSwapButtonSize = \"sm\" | \"md\" | \"lg\" | \"icon\";\nexport type ActionSwapAnimation = \"blur\" | \"roll\" | \"cascade\";\n\n/** Animations with a single-element variant set (cascade animates per letter). */\ntype CoreAnimation = \"blur\" | \"roll\";\n\nexport interface ActionSwapButtonProps\n extends Omit<HTMLMotionProps<\"button\">, \"children\" | \"onChange\"> {\n items: ActionSwapItem[];\n value?: string;\n defaultValue?: string;\n onValueChange?: (value: string, item: ActionSwapItem) => void;\n variant?: ActionSwapButtonVariant;\n size?: ActionSwapButtonSize;\n animation?: ActionSwapAnimation;\n iconOnly?: boolean;\n cycle?: boolean;\n}\n\nexport interface ActionSwapTextProps {\n value: string;\n children: ReactNode;\n animation?: ActionSwapAnimation;\n className?: string;\n}\n\nexport interface ActionSwapIconProps {\n value: string;\n children: ReactNode;\n animation?: ActionSwapAnimation;\n className?: string;\n}\n\nconst BLUR_TRANSITION = { duration: 0.2, ease: \"easeInOut\" } as const;\nconst ROLL_TRANSITION = SPRING_SWAP;\nconst ROLL_EXIT_TRANSITION = { duration: 0.14, ease: EASE_OUT } as const;\nconst SWAP_BLUR = \"blur(8px)\";\nconst ROLL_BLUR = \"blur(3px)\";\n\n// Cascade rolls the label one letter at a time, left to right. The leaving\n// and landing strings overlap as independent layers (no shared cells), so\n// proportional glyph widths never jitter. Exits cascade at half the enter\n// stagger so the tail of the old label lingers briefly.\nconst CASCADE_STAGGER = 0.025;\n\nconst CASCADE_LETTER_VARIANTS: Variants = {\n initial: { opacity: 0, y: \"105%\", filter: ROLL_BLUR },\n animate: (delay: number = 0) => ({\n opacity: 1,\n y: \"0%\",\n filter: \"blur(0px)\",\n transition: { ...SPRING_SWAP, delay },\n }),\n exit: (delay: number = 0) => ({\n opacity: 0,\n y: \"-105%\",\n filter: ROLL_BLUR,\n transition: { duration: 0.16, ease: EASE_OUT, delay: delay * 0.5 },\n }),\n};\n\nconst TEXT_VARIANTS: Record<CoreAnimation, Variants> = {\n blur: {\n initial: { opacity: 0, scale: 0.94, filter: SWAP_BLUR },\n animate: {\n opacity: 1,\n scale: 1,\n filter: \"blur(0px)\",\n transition: BLUR_TRANSITION,\n },\n exit: {\n opacity: 0,\n scale: 0.94,\n filter: SWAP_BLUR,\n transition: BLUR_TRANSITION,\n },\n },\n roll: {\n initial: { opacity: 0, y: \"90%\", filter: ROLL_BLUR },\n animate: {\n opacity: 1,\n y: \"0%\",\n filter: \"blur(0px)\",\n transition: ROLL_TRANSITION,\n },\n exit: {\n opacity: 0,\n y: \"-90%\",\n filter: ROLL_BLUR,\n transition: ROLL_EXIT_TRANSITION,\n },\n },\n};\n\nconst ICON_VARIANTS: Record<CoreAnimation, Variants> = {\n blur: {\n initial: { opacity: 0, scale: 0.25, filter: SWAP_BLUR },\n animate: {\n opacity: 1,\n scale: 1,\n filter: \"blur(0px)\",\n transition: BLUR_TRANSITION,\n },\n exit: {\n opacity: 0,\n scale: 0.25,\n filter: SWAP_BLUR,\n transition: BLUR_TRANSITION,\n },\n },\n roll: {\n initial: { opacity: 0, y: 12, filter: ROLL_BLUR },\n animate: {\n opacity: 1,\n y: 0,\n filter: \"blur(0px)\",\n transition: ROLL_TRANSITION,\n },\n exit: {\n opacity: 0,\n y: -12,\n filter: ROLL_BLUR,\n transition: ROLL_EXIT_TRANSITION,\n },\n },\n};\n\nconst VARIANT_CLASS: Record<ActionSwapButtonVariant, string> = {\n primary: \"bg-primary text-primary-foreground hover:bg-primary/90\",\n secondary: \"border border-border bg-card text-foreground hover:border-border\",\n outline: \"border border-border bg-transparent text-foreground hover:bg-primary/5\",\n ghost: \"text-muted-foreground hover:bg-primary/5 hover:text-foreground\",\n};\n\nconst SIZE_CLASS: Record<ActionSwapButtonSize, string> = {\n sm: \"h-8 gap-1.5 rounded-full px-3 text-xs\",\n md: \"h-10 gap-2 rounded-full px-4 text-sm\",\n lg: \"h-12 gap-2.5 rounded-full px-5 text-base\",\n icon: \"h-10 w-10 rounded-full\",\n};\n\nexport function ActionSwapText({\n value,\n children,\n animation = \"blur\",\n className,\n}: ActionSwapTextProps) {\n const reduce = useReducedMotion();\n\n // Cascade needs a plain string to split into letters; non-string content\n // and reduced motion fall back to the closest single-element animation.\n const label = typeof children === \"string\" ? children : null;\n const cascade = animation === \"cascade\" && label !== null && !reduce;\n const coreAnimation: CoreAnimation = animation === \"cascade\" ? \"roll\" : animation;\n\n return (\n <span\n className={cn(\n \"relative -my-[0.08em] inline-block whitespace-nowrap py-[0.08em] align-bottom\",\n className,\n )}\n style={{\n clipPath: \"inset(0 -999px)\",\n WebkitClipPath: \"inset(0 -999px)\",\n }}\n >\n <span aria-hidden className=\"invisible inline-block whitespace-nowrap\">\n {cascade\n ? label.split(\"\").map((char, index) => (\n <span key={index} className=\"inline-block whitespace-pre\">\n {char}\n </span>\n ))\n : children}\n </span>\n {cascade ? (\n <>\n {/* Letters are decorative fragments; readers get the whole label. */}\n <span className=\"sr-only\">{label}</span>\n <AnimatePresence initial={false}>\n <motion.span\n key={`cascade-${value}`}\n aria-hidden\n initial=\"initial\"\n animate=\"animate\"\n exit=\"exit\"\n className=\"absolute top-[0.08em] left-0 inline-block whitespace-pre\"\n >\n {label.split(\"\").map((char, i) => (\n <motion.span\n key={i}\n custom={i * CASCADE_STAGGER}\n variants={CASCADE_LETTER_VARIANTS}\n className=\"inline-block whitespace-pre will-change-[opacity,filter,transform]\"\n >\n {char}\n </motion.span>\n ))}\n </motion.span>\n </AnimatePresence>\n </>\n ) : (\n <AnimatePresence initial={false}>\n <motion.span\n key={`${animation}-${value}`}\n variants={TEXT_VARIANTS[coreAnimation]}\n initial={reduce ? false : \"initial\"}\n animate={reduce ? { opacity: 1, filter: \"blur(0px)\", scale: 1, y: 0 } : \"animate\"}\n exit={reduce ? undefined : \"exit\"}\n className=\"absolute top-[0.08em] left-0 inline-block will-change-[opacity,filter,transform]\"\n >\n {children}\n </motion.span>\n </AnimatePresence>\n )}\n </span>\n );\n}\n\nexport function ActionSwapIcon({\n value,\n children,\n animation = \"blur\",\n className,\n}: ActionSwapIconProps) {\n const reduce = useReducedMotion();\n // Icons are single elements — cascade maps to its closest motion, roll.\n const coreAnimation: CoreAnimation = animation === \"cascade\" ? \"roll\" : animation;\n\n return (\n <span\n className={cn(\"relative inline-grid shrink-0 place-items-center overflow-hidden\", className)}\n >\n <AnimatePresence mode=\"popLayout\" initial={false}>\n <motion.span\n key={`${animation}-${value}`}\n aria-hidden\n variants={ICON_VARIANTS[coreAnimation]}\n initial={reduce ? false : \"initial\"}\n animate={reduce ? { opacity: 1, filter: \"blur(0px)\", scale: 1, y: 0 } : \"animate\"}\n exit={reduce ? undefined : \"exit\"}\n className=\"col-start-1 row-start-1 inline-flex items-center justify-center will-change-[opacity,filter,transform]\"\n >\n {children}\n </motion.span>\n </AnimatePresence>\n </span>\n );\n}\n\nexport function ActionSwapButton({\n items,\n value,\n defaultValue,\n onValueChange,\n variant = \"secondary\",\n size = \"md\",\n animation = \"blur\",\n iconOnly = size === \"icon\",\n cycle = true,\n className,\n disabled,\n onClick,\n ...rest\n}: ActionSwapButtonProps) {\n const reduce = useReducedMotion();\n const [internalValue, setInternalValue] = useState(defaultValue ?? items[0]?.id);\n const currentValue = value ?? internalValue;\n const activeIndex = Math.max(\n 0,\n items.findIndex((item) => item.id === currentValue),\n );\n const activeItem = items[activeIndex] ?? items[0];\n const hasIcon = items.some((item) => item.icon);\n const nextItem = cycle && items.length > 0 ? items[(activeIndex + 1) % items.length] : undefined;\n\n if (!activeItem) return null;\n\n const accessibleLabel =\n activeItem.ariaLabel ??\n (iconOnly && typeof activeItem.label === \"string\" ? activeItem.label : undefined);\n\n return (\n <motion.button\n type=\"button\"\n disabled={disabled}\n whileTap={reduce || disabled ? undefined : { scale: 0.97 }}\n transition={SPRING_PRESS}\n className={cn(\n \"inline-flex items-center justify-center overflow-hidden font-medium transition-colors\",\n \"disabled:pointer-events-none disabled:opacity-50\",\n VARIANT_CLASS[variant],\n SIZE_CLASS[size],\n className,\n )}\n aria-label={accessibleLabel}\n onClick={(event) => {\n onClick?.(event);\n if (event.defaultPrevented || disabled || !cycle || !nextItem) return;\n if (value === undefined) setInternalValue(nextItem.id);\n onValueChange?.(nextItem.id, nextItem);\n }}\n {...rest}\n >\n {hasIcon ? (\n <ActionSwapIcon value={activeItem.id} animation={animation} className=\"h-4 w-4\">\n {activeItem.icon ?? null}\n </ActionSwapIcon>\n ) : null}\n {!iconOnly ? (\n <ActionSwapText value={activeItem.id} animation={animation}>\n {activeItem.label}\n </ActionSwapText>\n ) : null}\n </motion.button>\n );\n}\n"],"mappings":";;;;;;;AAwDA,MAAM,kBAAkB;CAAE,UAAU;CAAK,MAAM;AAAY;AAC3D,MAAM,kBAAkB;AACxB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AAW,WAAW,QAAQ,KAAA;CAEzE,OACE,qBAAC,OAAO,QAAR;EACE,MAAK;EACK;EACV,UAAU,UAAU,WAAW,KAAA,IAAY,EAAE,OAAO,IAAK;EACzD,YAAY;EACZ,WAAW,GACT,yFACA,oDACA,cAAc,UACd,WAAW,OACX,SACF;EACA,cAAY;EACZ,UAAU,UAAU;GAClB,UAAU,KAAK;GACf,IAAI,MAAM,oBAAoB,YAAY,CAAC,SAAS,CAAC,UAAU;GAC/D,IAAI,UAAU,KAAA,GAAW,iBAAiB,SAAS,EAAE;GACrD,gBAAgB,SAAS,IAAI,QAAQ;EACvC;EACA,GAAI;EAnBN,UAAA,CAqBG,UACC,oBAAC,gBAAD;GAAgB,OAAO,WAAW;GAAe;GAAW,WAAU;GACnE,UAAA,WAAW,QAAQ;EACN,CAAA,IACd,MACH,CAAC,WACA,oBAAC,gBAAD;GAAgB,OAAO,WAAW;GAAe;GAC9C,UAAA,WAAW;EACE,CAAA,IACd,IACS;;AAEnB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { EASE_DRAWER } from "../../lib/ease.js";
|
|
3
|
-
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
4
4
|
import { cn } from "@kumix/utils";
|
|
5
5
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
6
|
import { AnimatePresence, motion, useDragControls, useReducedMotion } from "motion/react";
|
|
@@ -17,6 +17,9 @@ function BottomSheet({ open, onOpenChange, snapPoints = [.5, .92], defaultSnap =
|
|
|
17
17
|
const sheetRef = useRef(null);
|
|
18
18
|
const reduce = useReducedMotion();
|
|
19
19
|
const heightRef = useRef(0);
|
|
20
|
+
const uid = useId();
|
|
21
|
+
const titleId = `${uid}-title`;
|
|
22
|
+
const descriptionId = `${uid}-description`;
|
|
20
23
|
useEffect(() => {
|
|
21
24
|
setMounted(true);
|
|
22
25
|
}, []);
|
|
@@ -39,7 +42,15 @@ function BottomSheet({ open, onOpenChange, snapPoints = [.5, .92], defaultSnap =
|
|
|
39
42
|
body.style.left = "0";
|
|
40
43
|
body.style.right = "0";
|
|
41
44
|
body.style.overflow = "hidden";
|
|
45
|
+
const onKey = (event) => {
|
|
46
|
+
if (event.key === "Escape") {
|
|
47
|
+
event.preventDefault();
|
|
48
|
+
onOpenChange(false);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
window.addEventListener("keydown", onKey);
|
|
42
52
|
return () => {
|
|
53
|
+
window.removeEventListener("keydown", onKey);
|
|
43
54
|
body.style.position = prev.position;
|
|
44
55
|
body.style.top = prev.top;
|
|
45
56
|
body.style.left = prev.left;
|
|
@@ -47,7 +58,7 @@ function BottomSheet({ open, onOpenChange, snapPoints = [.5, .92], defaultSnap =
|
|
|
47
58
|
body.style.overflow = prev.overflow;
|
|
48
59
|
window.scrollTo(0, scrollY);
|
|
49
60
|
};
|
|
50
|
-
}, [open]);
|
|
61
|
+
}, [open, onOpenChange]);
|
|
51
62
|
const onDragEnd = (_, info) => {
|
|
52
63
|
const velocity = info.velocity.y;
|
|
53
64
|
const offset = info.offset.y;
|
|
@@ -119,16 +130,23 @@ function BottomSheet({ open, onOpenChange, snapPoints = [.5, .92], defaultSnap =
|
|
|
119
130
|
className: cn("pointer-events-auto absolute right-0 bottom-0 left-0 mx-auto flex max-w-2xl flex-col overflow-hidden rounded-t-3xl will-change-transform", "border border-border bg-background shadow-xl", className),
|
|
120
131
|
role: "dialog",
|
|
121
132
|
"aria-modal": "true",
|
|
122
|
-
"aria-
|
|
133
|
+
"aria-labelledby": title ? titleId : void 0,
|
|
134
|
+
"aria-describedby": description ? descriptionId : void 0,
|
|
135
|
+
"aria-label": title ? void 0 : "Bottom sheet",
|
|
123
136
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
className: "
|
|
137
|
+
className: "flex flex-col items-center px-4 pt-3 pb-2",
|
|
138
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
139
|
+
onPointerDown: (event) => dragControls.start(event),
|
|
140
|
+
className: "flex cursor-grab touch-none items-center justify-center py-1 active:cursor-grabbing",
|
|
141
|
+
children: /* @__PURE__ */ jsx("div", { className: "h-1.5 w-10 rounded-full bg-muted-foreground/40" })
|
|
142
|
+
}), title || description ? /* @__PURE__ */ jsxs("div", {
|
|
143
|
+
className: "mt-2 w-full",
|
|
128
144
|
children: [title ? /* @__PURE__ */ jsx("h2", {
|
|
145
|
+
id: titleId,
|
|
129
146
|
className: "font-semibold text-base text-foreground",
|
|
130
147
|
children: title
|
|
131
148
|
}) : null, description ? /* @__PURE__ */ jsx("p", {
|
|
149
|
+
id: descriptionId,
|
|
132
150
|
className: "mt-0.5 text-muted-foreground text-sm",
|
|
133
151
|
children: description
|
|
134
152
|
}) : null]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bottom-sheet.js","names":[],"sources":["../../../src/components/motion/bottom-sheet.tsx"],"sourcesContent":["\"use client\";\n\nimport { type ReactNode, useEffect, useRef, useState } from \"react\";\nimport {\n AnimatePresence,\n motion,\n type PanInfo,\n useDragControls,\n useReducedMotion,\n} from \"motion/react\";\nimport { createPortal } from \"react-dom\";\n\nimport { cn } from \"@kumix/utils\";\nimport { EASE_DRAWER } from \"../../lib/ease\";\n\n// Vaul-style glide: a long, fully-damped tween reads smoother than a spring on\n// open — no settle/overshoot, just one clean decel. Same curve drives the\n// backdrop fade so the surface and scrim move as one.\nconst DRAWER = { duration: 0.5, ease: EASE_DRAWER } as const;\n\nexport interface BottomSheetProps {\n open: boolean;\n onOpenChange: (open: boolean) => void;\n /** Heights (0-1 = fraction of viewport, or \"auto\"). First entry is default. */\n snapPoints?: (number | \"auto\")[];\n defaultSnap?: number;\n title?: string;\n description?: string;\n children?: ReactNode;\n className?: string;\n /** Min drag distance (px) past current snap to dismiss. */\n dismissThreshold?: number;\n}\n\nexport function BottomSheet({\n open,\n onOpenChange,\n snapPoints = [0.5, 0.92],\n defaultSnap = 0,\n title,\n description,\n children,\n className,\n dismissThreshold = 120,\n}: BottomSheetProps) {\n const [snap, setSnap] = useState(defaultSnap);\n const [mounted, setMounted] = useState(false);\n const dragControls = useDragControls();\n const sheetRef = useRef<HTMLDivElement>(null);\n const reduce = useReducedMotion();\n const heightRef = useRef(0);\n\n useEffect(() => {\n setMounted(true);\n }, []);\n\n useEffect(() => {\n if (open) setSnap(defaultSnap);\n }, [open, defaultSnap]);\n\n // Lock background scroll while open. overflow:hidden alone is ignored by\n // iOS Safari — boundary scrolls inside the sheet chain to the page, which\n // scrolls underneath and ends up somewhere else on close. position:fixed\n // is the lock that actually holds; restore the scroll position after.\n useEffect(() => {\n if (!open) return;\n const body = document.body;\n const scrollY = window.scrollY;\n const prev = {\n position: body.style.position,\n top: body.style.top,\n left: body.style.left,\n right: body.style.right,\n overflow: body.style.overflow,\n };\n body.style.position = \"fixed\";\n body.style.top = `-${scrollY}px`;\n body.style.left = \"0\";\n body.style.right = \"0\";\n body.style.overflow = \"hidden\";\n return () => {\n body.style.position = prev.position;\n body.style.top = prev.top;\n body.style.left = prev.left;\n body.style.right = prev.right;\n body.style.overflow = prev.overflow;\n window.scrollTo(0, scrollY);\n };\n }, [open]);\n\n const onDragEnd = (_: unknown, info: PanInfo) => {\n const velocity = info.velocity.y;\n const offset = info.offset.y;\n\n // Strong downward fling or large drag → dismiss.\n if (velocity > 600 || offset > dismissThreshold) {\n const smaller = snapPoints.map((_, i) => i).filter((i) => i < snap);\n if (smaller.length && velocity < 800 && offset < dismissThreshold * 1.6) {\n setSnap(smaller[smaller.length - 1]);\n } else {\n onOpenChange(false);\n }\n return;\n }\n\n // Strong upward fling → next snap.\n if (velocity < -500) {\n setSnap((current) => Math.min(snapPoints.length - 1, current + 1));\n return;\n }\n\n // Otherwise snap to nearest by current offset.\n setSnap((current) => {\n if (offset > 80 && current > 0) return current - 1;\n if (offset < -80 && current < snapPoints.length - 1) return current + 1;\n return current;\n });\n };\n\n const snapValue = snapPoints[snap];\n const heightStyle =\n snapValue === \"auto\" ? { maxHeight: \"92vh\" } : { height: `${snapValue * 100}vh` };\n\n // Portal to <body>: an ancestor with backdrop-filter or transform becomes\n // the containing block for fixed descendants, which would position the\n // sheet against that ancestor instead of the viewport.\n if (!mounted) return null;\n\n return createPortal(\n <AnimatePresence>\n {open ? (\n <div className=\"pointer-events-none fixed inset-0 z-50\">\n <motion.button\n type=\"button\"\n aria-label=\"Close bottom sheet\"\n initial={{ opacity: 0 }}\n animate={{ opacity: 1 }}\n exit={{ opacity: 0 }}\n transition={DRAWER}\n onClick={() => onOpenChange(false)}\n // A dim scrim with a light blur. backdrop-blur is GPU-expensive and\n // re-rasterizes every frame the sheet drags over it; a small radius\n // plus more opacity keeps the glass look without the jank.\n className=\"pointer-events-auto absolute inset-0 bg-background/40 backdrop-blur-sm\"\n />\n <motion.div\n ref={sheetRef}\n drag=\"y\"\n dragControls={dragControls}\n dragListener={false}\n dragConstraints={{ top: 0, bottom: 0 }}\n dragElastic={{ top: 0.02, bottom: 0.4 }}\n dragMomentum={false}\n onDragEnd={onDragEnd}\n initial={reduce ? { y: 0, opacity: 0 } : { y: \"100%\" }}\n animate={reduce ? { y: 0, opacity: 1 } : { y: 0 }}\n exit={reduce ? { y: 0, opacity: 0 } : { y: \"100%\" }}\n transition={reduce ? { duration: 0.18, ease: EASE_DRAWER } : DRAWER}\n onAnimationComplete={() => {\n if (sheetRef.current) heightRef.current = sheetRef.current.offsetHeight;\n }}\n style={heightStyle}\n className={cn(\n \"pointer-events-auto absolute right-0 bottom-0 left-0 mx-auto flex max-w-2xl flex-col overflow-hidden rounded-t-3xl will-change-transform\",\n \"border border-border bg-background shadow-xl\",\n className,\n )}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-label={title}\n >\n <div\n onPointerDown={(e) => dragControls.start(e)}\n className=\"flex cursor-grab touch-none flex-col items-center px-4 pt-3 pb-2 active:cursor-grabbing\"\n >\n <div className=\"h-1.5 w-10 rounded-full bg-muted-foreground/40\" />\n {title || description ? (\n <div className=\"mt-3 w-full\">\n {title ? (\n <h2 className=\"font-semibold text-base text-foreground\">{title}</h2>\n ) : null}\n {description ? (\n <p className=\"mt-0.5 text-muted-foreground text-sm\">{description}</p>\n ) : null}\n </div>\n ) : null}\n </div>\n {/* overscroll-contain stops boundary scrolls from chaining to the page. */}\n <div className=\"flex-1 overflow-y-auto overscroll-contain px-4 pb-6\">{children}</div>\n </motion.div>\n </div>\n ) : null}\n </AnimatePresence>,\n document.body,\n );\n}\n"],"mappings":";;;;;;;;AAkBA,MAAM,SAAS;CAAE,UAAU;CAAK,MAAM;AAAY;AAgBlD,SAAgB,YAAY,EAC1B,MACA,cACA,aAAa,CAAC,IAAK,GAAI,GACvB,cAAc,GACd,OACA,aACA,UACA,WACA,mBAAmB,OACA;CACnB,MAAM,CAAC,MAAM,WAAW,SAAS,WAAW;CAC5C,MAAM,CAAC,SAAS,cAAc,SAAS,KAAK;CAC5C,MAAM,eAAe,gBAAgB;CACrC,MAAM,WAAW,OAAuB,IAAI;CAC5C,MAAM,SAAS,iBAAiB;CAChC,MAAM,YAAY,OAAO,CAAC;CAE1B,gBAAgB;EACd,WAAW,IAAI;CACjB,GAAG,CAAC,CAAC;CAEL,gBAAgB;EACd,IAAI,MAAM,QAAQ,WAAW;CAC/B,GAAG,CAAC,MAAM,WAAW,CAAC;CAMtB,gBAAgB;EACd,IAAI,CAAC,MAAM;EACX,MAAM,OAAO,SAAS;EACtB,MAAM,UAAU,OAAO;EACvB,MAAM,OAAO;GACX,UAAU,KAAK,MAAM;GACrB,KAAK,KAAK,MAAM;GAChB,MAAM,KAAK,MAAM;GACjB,OAAO,KAAK,MAAM;GAClB,UAAU,KAAK,MAAM;EACvB;EACA,KAAK,MAAM,WAAW;EACtB,KAAK,MAAM,MAAM,IAAI,QAAQ;EAC7B,KAAK,MAAM,OAAO;EAClB,KAAK,MAAM,QAAQ;EACnB,KAAK,MAAM,WAAW;EACtB,a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AAU;EACX,CAAA,GACD,qBAAC,OAAO,KAAR;GACE,KAAK;GACL,MAAK;GACS;GACd,cAAc;GACd,iBAAiB;IAAE,KAAK;IAAG,QAAQ;GAAE;GACrC,aAAa;IAAE,KAAK;IAAM,QAAQ;GAAI;GACtC,cAAc;GACH;GACX,SAAS,SAAS;IAAE,GAAG;IAAG,SAAS;GAAE,IAAI,EAAE,GAAG,OAAO;GACrD,SAAS,SAAS;IAAE,GAAG;IAAG,SAAS;GAAE,IAAI,EAAE,GAAG,EAAE;GAChD,MAAM,SAAS;IAAE,GAAG;IAAG,SAAS;GAAE,IAAI,EAAE,GAAG,OAAO;GAClD,YAAY,SAAS;IAAE,UAAU;IAAM,MAAM;GAAY,IAAI;GAC7D,2BAA2B;IACzB,IAAI,SAAS,SAAS,UAAU,UAAU,SAAS,QAAQ;GAC7D;GACA,OAAO;GACP,WAAW,GACT,4IACA,gDACA,SACF;GACA,MAAK;GACL,cAAW;GACX,cAAY;GAxBd,UAAA,CA0BE,qBAAC,OAAD;IACE,gBAAgB,MAAM,aAAa,MAAM,CAAC;IAC1C,WAAU;IAFZ,UAAA,CAIE,oBAAC,OAAD,EAAK,WAAU,iDAAkD,CAAA,GAChE,SAAS,cACR,qBAAC,OAAD;KAAK,WAAU;KAAf,UAAA,CACG,QACC,oBAAC,MAAD;MAAI,WAAU;MAA2C,UAAA;KAAU,CAAA,IACjE,MACH,cACC,oBAAC,KAAD;MAAG,WAAU;MAAwC,UAAA;KAAe,CAAA,IAClE,IACD;IACH,CAAA,IAAA,IACD;GAEL,CAAA,GAAA,oBAAC,OAAD;IAAK,WAAU;IAAuD;GAAc,CAAA,CAC1E;EACT,CAAA,CAAA;CACH,CAAA,IAAA,KACW,CAAA,GACjB,SAAS,IACX;AACF"}
|
|
1
|
+
{"version":3,"file":"bottom-sheet.js","names":[],"sources":["../../../src/components/motion/bottom-sheet.tsx"],"sourcesContent":["\"use client\";\n\nimport { type ReactNode, useEffect, useId, useRef, useState } from \"react\";\nimport {\n AnimatePresence,\n motion,\n type PanInfo,\n useDragControls,\n useReducedMotion,\n} from \"motion/react\";\nimport { createPortal } from \"react-dom\";\n\nimport { cn } from \"@kumix/utils\";\nimport { EASE_DRAWER } from \"../../lib/ease\";\n\n// Vaul-style glide: a long, fully-damped tween reads smoother than a spring on\n// open — no settle/overshoot, just one clean decel. Same curve drives the\n// backdrop fade so the surface and scrim move as one.\nconst DRAWER = { duration: 0.5, ease: EASE_DRAWER } as const;\n\nexport interface BottomSheetProps {\n open: boolean;\n onOpenChange: (open: boolean) => void;\n /** Heights (0-1 = fraction of viewport, or \"auto\"). First entry is default. */\n snapPoints?: (number | \"auto\")[];\n defaultSnap?: number;\n title?: string;\n description?: string;\n children?: ReactNode;\n className?: string;\n /** Min drag distance (px) past current snap to dismiss. */\n dismissThreshold?: number;\n}\n\nexport function BottomSheet({\n open,\n onOpenChange,\n snapPoints = [0.5, 0.92],\n defaultSnap = 0,\n title,\n description,\n children,\n className,\n dismissThreshold = 120,\n}: BottomSheetProps) {\n const [snap, setSnap] = useState(defaultSnap);\n const [mounted, setMounted] = useState(false);\n const dragControls = useDragControls();\n const sheetRef = useRef<HTMLDivElement>(null);\n const reduce = useReducedMotion();\n const heightRef = useRef(0);\n const uid = useId();\n const titleId = `${uid}-title`;\n const descriptionId = `${uid}-description`;\n\n useEffect(() => {\n setMounted(true);\n }, []);\n\n useEffect(() => {\n if (open) setSnap(defaultSnap);\n }, [open, defaultSnap]);\n\n // Lock background scroll while open. overflow:hidden alone is ignored by\n // iOS Safari — boundary scrolls inside the sheet chain to the page, which\n // scrolls underneath and ends up somewhere else on close. position:fixed\n // is the lock that actually holds; restore the scroll position after.\n useEffect(() => {\n if (!open) return;\n const body = document.body;\n const scrollY = window.scrollY;\n const prev = {\n position: body.style.position,\n top: body.style.top,\n left: body.style.left,\n right: body.style.right,\n overflow: body.style.overflow,\n };\n body.style.position = \"fixed\";\n body.style.top = `-${scrollY}px`;\n body.style.left = \"0\";\n body.style.right = \"0\";\n body.style.overflow = \"hidden\";\n\n const onKey = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") {\n event.preventDefault();\n onOpenChange(false);\n }\n };\n window.addEventListener(\"keydown\", onKey);\n\n return () => {\n window.removeEventListener(\"keydown\", onKey);\n body.style.position = prev.position;\n body.style.top = prev.top;\n body.style.left = prev.left;\n body.style.right = prev.right;\n body.style.overflow = prev.overflow;\n window.scrollTo(0, scrollY);\n };\n }, [open, onOpenChange]);\n\n const onDragEnd = (_: unknown, info: PanInfo) => {\n const velocity = info.velocity.y;\n const offset = info.offset.y;\n\n // Strong downward fling or large drag → dismiss.\n if (velocity > 600 || offset > dismissThreshold) {\n const smaller = snapPoints.map((_, i) => i).filter((i) => i < snap);\n if (smaller.length && velocity < 800 && offset < dismissThreshold * 1.6) {\n setSnap(smaller[smaller.length - 1]);\n } else {\n onOpenChange(false);\n }\n return;\n }\n\n // Strong upward fling → next snap.\n if (velocity < -500) {\n setSnap((current) => Math.min(snapPoints.length - 1, current + 1));\n return;\n }\n\n // Otherwise snap to nearest by current offset.\n setSnap((current) => {\n if (offset > 80 && current > 0) return current - 1;\n if (offset < -80 && current < snapPoints.length - 1) return current + 1;\n return current;\n });\n };\n\n const snapValue = snapPoints[snap];\n const heightStyle =\n snapValue === \"auto\" ? { maxHeight: \"92vh\" } : { height: `${snapValue * 100}vh` };\n\n // Portal to <body>: an ancestor with backdrop-filter or transform becomes\n // the containing block for fixed descendants, which would position the\n // sheet against that ancestor instead of the viewport.\n if (!mounted) return null;\n\n return createPortal(\n <AnimatePresence>\n {open ? (\n <div className=\"pointer-events-none fixed inset-0 z-50\">\n <motion.button\n type=\"button\"\n aria-label=\"Close bottom sheet\"\n initial={{ opacity: 0 }}\n animate={{ opacity: 1 }}\n exit={{ opacity: 0 }}\n transition={DRAWER}\n onClick={() => onOpenChange(false)}\n // A dim scrim with a light blur. backdrop-blur is GPU-expensive and\n // re-rasterizes every frame the sheet drags over it; a small radius\n // plus more opacity keeps the glass look without the jank.\n className=\"pointer-events-auto absolute inset-0 bg-background/40 backdrop-blur-sm\"\n />\n <motion.div\n ref={sheetRef}\n drag=\"y\"\n dragControls={dragControls}\n dragListener={false}\n dragConstraints={{ top: 0, bottom: 0 }}\n dragElastic={{ top: 0.02, bottom: 0.4 }}\n dragMomentum={false}\n onDragEnd={onDragEnd}\n initial={reduce ? { y: 0, opacity: 0 } : { y: \"100%\" }}\n animate={reduce ? { y: 0, opacity: 1 } : { y: 0 }}\n exit={reduce ? { y: 0, opacity: 0 } : { y: \"100%\" }}\n transition={reduce ? { duration: 0.18, ease: EASE_DRAWER } : DRAWER}\n onAnimationComplete={() => {\n if (sheetRef.current) heightRef.current = sheetRef.current.offsetHeight;\n }}\n style={heightStyle}\n className={cn(\n \"pointer-events-auto absolute right-0 bottom-0 left-0 mx-auto flex max-w-2xl flex-col overflow-hidden rounded-t-3xl will-change-transform\",\n \"border border-border bg-background shadow-xl\",\n className,\n )}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-labelledby={title ? titleId : undefined}\n aria-describedby={description ? descriptionId : undefined}\n aria-label={title ? undefined : \"Bottom sheet\"}\n >\n <div className=\"flex flex-col items-center px-4 pt-3 pb-2\">\n {/* Drag only the pill so the title and description stay selectable. */}\n <div\n onPointerDown={(event) => dragControls.start(event)}\n className=\"flex cursor-grab touch-none items-center justify-center py-1 active:cursor-grabbing\"\n >\n <div className=\"h-1.5 w-10 rounded-full bg-muted-foreground/40\" />\n </div>\n {title || description ? (\n <div className=\"mt-2 w-full\">\n {title ? (\n <h2 id={titleId} className=\"font-semibold text-base text-foreground\">\n {title}\n </h2>\n ) : null}\n {description ? (\n <p id={descriptionId} className=\"mt-0.5 text-muted-foreground text-sm\">\n {description}\n </p>\n ) : null}\n </div>\n ) : null}\n </div>\n {/* overscroll-contain stops boundary scrolls from chaining to the page. */}\n <div className=\"flex-1 overflow-y-auto overscroll-contain px-4 pb-6\">{children}</div>\n </motion.div>\n </div>\n ) : null}\n </AnimatePresence>,\n document.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ode } from "react";
|
|
2
|
+
//#region src/components/motion/combobox/content.d.ts
|
|
3
|
+
type Side = "top" | "bottom";
|
|
4
|
+
type Align = "start" | "center" | "end";
|
|
5
|
+
interface ComboboxContentProps {
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
side?: Side;
|
|
8
|
+
align?: Align;
|
|
9
|
+
sideOffset?: number;
|
|
10
|
+
avoidCollisions?: boolean;
|
|
11
|
+
className?: string;
|
|
12
|
+
}
|
|
13
|
+
declare function ComboboxContent({ children, side, align, sideOffset, avoidCollisions, className }: ComboboxContentProps): import("react").ReactPortal | null;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { ComboboxContent, ComboboxContentProps };
|
|
16
|
+
//# sourceMappingURL=content.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content.d.ts","names":[],"sources":["../../../../src/components/motion/combobox/content.tsx"],"mappings":";;KAiBK;KACA;UAWY;EACf,UAAU;EACV,OAAO;EACP,QAAQ;EACR;EACA;EACA;;iBAGc,kBACd,UACA,MACA,OACA,YACA,iBACA,aACC,uCAAoB"}
|