seam-react 0.1.1 → 0.3.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/README.md +5 -4
- package/dist/Dialog.d.ts +62 -5
- package/dist/Tooltip.d.ts +112 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1156 -390
- package/dist/index.js.map +1 -1
- package/dist/motion.d.ts +14 -0
- package/dist/styles.cjs +171 -175
- package/dist/styles.cjs.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/styles.js +172 -176
- package/dist/styles.js.map +1 -1
- package/package.json +8 -4
- package/dist/Toast.d.ts +0 -43
package/README.md
CHANGED
|
@@ -30,11 +30,12 @@ export function Root() {
|
|
|
30
30
|
}
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
组件包含:Button、Input、Switch、Tabs、Dialog、
|
|
33
|
+
组件包含:Button、Input、Switch、Tabs、Dialog、Tooltip。
|
|
34
34
|
|
|
35
|
-
- Tabs
|
|
36
|
-
-
|
|
37
|
-
-
|
|
35
|
+
- Tabs 支持方向键切换、ARIA 关联与 fluid 指示器。
|
|
36
|
+
- Switch 支持点击、键盘和拖拽 spring。
|
|
37
|
+
- Dialog 提供 Root / Trigger / Content 与语义化内容层,自带 Motion 进出场、焦点陷阱、Esc 关闭与滚动锁定。
|
|
38
|
+
- Tooltip 提供延迟显示、键盘与触屏访问、视口翻转/避让,以及可让相邻触发器共享并连续移动表面的 Group / Item 组合。
|
|
38
39
|
|
|
39
40
|
完整文档:[chenhaojie9527.github.io/ui-kit](https://chenhaojie9527.github.io/ui-kit/)
|
|
40
41
|
|
package/dist/Dialog.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ReactElement, type ReactNode, type RefObject } from "react";
|
|
1
|
+
import { type ForwardRefExoticComponent, type HTMLAttributes, type ReactElement, type ReactNode, type RefAttributes, type RefObject } from "react";
|
|
2
2
|
export interface DialogProps {
|
|
3
3
|
/** 是否打开。由调用方控制,配合 onOpenChange 使用。 */
|
|
4
4
|
open: boolean;
|
|
@@ -22,11 +22,68 @@ export interface DialogProps {
|
|
|
22
22
|
className?: string;
|
|
23
23
|
"aria-label"?: string;
|
|
24
24
|
}
|
|
25
|
+
export interface DialogRootProps {
|
|
26
|
+
children: ReactNode;
|
|
27
|
+
/** 受控打开状态。 */
|
|
28
|
+
open?: boolean;
|
|
29
|
+
/** 非受控模式下的初始状态。 */
|
|
30
|
+
defaultOpen?: boolean;
|
|
31
|
+
/** 打开状态变化时触发。 */
|
|
32
|
+
onOpenChange?: (open: boolean) => void;
|
|
33
|
+
}
|
|
34
|
+
/** Dialog 状态与语义 ID 的根节点。 */
|
|
35
|
+
declare function DialogRoot({ children, open, defaultOpen, onOpenChange, }: DialogRootProps): ReactElement;
|
|
36
|
+
export interface DialogTriggerProps {
|
|
37
|
+
children: ReactElement;
|
|
38
|
+
}
|
|
39
|
+
/** 包装一个交互元素,同步 dialog 的状态与 ARIA 关联。 */
|
|
40
|
+
declare function DialogTrigger({ children }: DialogTriggerProps): ReactElement;
|
|
41
|
+
export interface DialogCloseProps {
|
|
42
|
+
children?: ReactElement;
|
|
43
|
+
label?: string;
|
|
44
|
+
}
|
|
45
|
+
/** 包装关闭触发器,或渲染一个默认关闭按钮。 */
|
|
46
|
+
declare function DialogClose({ children, label, }: DialogCloseProps): ReactElement;
|
|
47
|
+
export type DialogHeaderProps = HTMLAttributes<HTMLElement>;
|
|
48
|
+
declare const DialogHeader: ForwardRefExoticComponent<DialogHeaderProps & RefAttributes<HTMLElement>>;
|
|
49
|
+
export type DialogTitleProps = HTMLAttributes<HTMLHeadingElement>;
|
|
50
|
+
declare const DialogTitle: ForwardRefExoticComponent<DialogTitleProps & RefAttributes<HTMLHeadingElement>>;
|
|
51
|
+
export type DialogDescriptionProps = HTMLAttributes<HTMLParagraphElement>;
|
|
52
|
+
declare const DialogDescription: ForwardRefExoticComponent<DialogDescriptionProps & RefAttributes<HTMLParagraphElement>>;
|
|
53
|
+
export type DialogBodyProps = HTMLAttributes<HTMLDivElement>;
|
|
54
|
+
declare const DialogBody: ForwardRefExoticComponent<DialogBodyProps & RefAttributes<HTMLDivElement>>;
|
|
55
|
+
export type DialogFooterProps = HTMLAttributes<HTMLElement>;
|
|
56
|
+
declare const DialogFooter: ForwardRefExoticComponent<DialogFooterProps & RefAttributes<HTMLElement>>;
|
|
57
|
+
export interface DialogContentProps {
|
|
58
|
+
children?: ReactNode;
|
|
59
|
+
className?: string;
|
|
60
|
+
closeOnBackdropClick?: boolean;
|
|
61
|
+
closeOnEscape?: boolean;
|
|
62
|
+
initialFocusRef?: RefObject<HTMLElement | null>;
|
|
63
|
+
returnFocusRef?: RefObject<HTMLElement | null>;
|
|
64
|
+
"aria-label"?: string;
|
|
65
|
+
"aria-labelledby"?: string;
|
|
66
|
+
"aria-describedby"?: string;
|
|
67
|
+
}
|
|
68
|
+
/** Portal、原生 dialog、焦点与 presence 生命周期的语义层。 */
|
|
69
|
+
declare function DialogContent({ children, closeOnBackdropClick, closeOnEscape, initialFocusRef, returnFocusRef, className, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, }: DialogContentProps): ReactElement | null;
|
|
70
|
+
export interface DialogComponent {
|
|
71
|
+
(props: DialogProps): ReactElement;
|
|
72
|
+
Root: typeof DialogRoot;
|
|
73
|
+
Trigger: typeof DialogTrigger;
|
|
74
|
+
Content: typeof DialogContent;
|
|
75
|
+
Header: typeof DialogHeader;
|
|
76
|
+
Title: typeof DialogTitle;
|
|
77
|
+
Description: typeof DialogDescription;
|
|
78
|
+
Body: typeof DialogBody;
|
|
79
|
+
Footer: typeof DialogFooter;
|
|
80
|
+
Close: typeof DialogClose;
|
|
81
|
+
}
|
|
25
82
|
/**
|
|
26
83
|
* 模态对话框。
|
|
27
84
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* 组件本身额外提供受控开关、关闭按钮、遮罩点击与 body 滚动锁定。
|
|
85
|
+
* 组合式 API 由 Root / Trigger / Content 和各语义层组成;无子组件的调用
|
|
86
|
+
* 保留既有 title / description / footer slot API。
|
|
31
87
|
*/
|
|
32
|
-
export declare
|
|
88
|
+
export declare const Dialog: DialogComponent;
|
|
89
|
+
export {};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { type HTMLAttributes, type ReactElement, type ReactNode } from "react";
|
|
2
|
+
export type TooltipSide = "top" | "right" | "bottom" | "left";
|
|
3
|
+
export type TooltipAlign = "start" | "center" | "end";
|
|
4
|
+
export interface TooltipRootProps {
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
/** 受控打开状态。 */
|
|
7
|
+
open?: boolean;
|
|
8
|
+
/** 非受控模式下的初始打开状态。 */
|
|
9
|
+
defaultOpen?: boolean;
|
|
10
|
+
/** 打开状态变化时触发。 */
|
|
11
|
+
onOpenChange?: (open: boolean) => void;
|
|
12
|
+
/** 指针停留或聚焦多久后显示,默认 300ms。 */
|
|
13
|
+
delayDuration?: number;
|
|
14
|
+
/** 离开触发器后多久关闭,默认 80ms。 */
|
|
15
|
+
closeDelay?: number;
|
|
16
|
+
}
|
|
17
|
+
/** Tooltip 的状态、计时器与语义 ID 根节点。 */
|
|
18
|
+
declare function TooltipRoot({ children, open, defaultOpen, onOpenChange, delayDuration, closeDelay, }: TooltipRootProps): ReactElement;
|
|
19
|
+
export interface TooltipTriggerProps {
|
|
20
|
+
/** 单个可聚焦的交互元素;事件和 ref 会与调用方传入的值合并。 */
|
|
21
|
+
children: ReactElement;
|
|
22
|
+
}
|
|
23
|
+
/** 为原生交互元素补充 hover、focus、Escape 与 aria-describedby。 */
|
|
24
|
+
declare function TooltipTrigger({ children }: TooltipTriggerProps): ReactElement;
|
|
25
|
+
export interface TooltipContentProps extends Omit<HTMLAttributes<HTMLDivElement>, "id" | "role"> {
|
|
26
|
+
children?: ReactNode;
|
|
27
|
+
/** 首选方向,空间不足时自动翻转。 */
|
|
28
|
+
side?: TooltipSide;
|
|
29
|
+
/** 沿首选方向与触发器的对齐方式。 */
|
|
30
|
+
align?: TooltipAlign;
|
|
31
|
+
/** 与触发器之间的间距,默认 8px。 */
|
|
32
|
+
sideOffset?: number;
|
|
33
|
+
/** 与视口边缘的最小间距,默认 8px。 */
|
|
34
|
+
collisionPadding?: number;
|
|
35
|
+
/** 是否根据视口空间翻转和避让,默认 true。 */
|
|
36
|
+
avoidCollisions?: boolean;
|
|
37
|
+
}
|
|
38
|
+
interface Rectangle {
|
|
39
|
+
top: number;
|
|
40
|
+
right: number;
|
|
41
|
+
bottom: number;
|
|
42
|
+
left: number;
|
|
43
|
+
width: number;
|
|
44
|
+
height: number;
|
|
45
|
+
}
|
|
46
|
+
interface TooltipPosition {
|
|
47
|
+
x: number;
|
|
48
|
+
y: number;
|
|
49
|
+
side: TooltipSide;
|
|
50
|
+
arrowOffset: number;
|
|
51
|
+
}
|
|
52
|
+
export declare function calculateTooltipPosition({ trigger, tooltip, side, align, sideOffset, collisionPadding, avoidCollisions, viewportWidth, viewportHeight, }: {
|
|
53
|
+
trigger: Rectangle;
|
|
54
|
+
tooltip: Rectangle;
|
|
55
|
+
side: TooltipSide;
|
|
56
|
+
align: TooltipAlign;
|
|
57
|
+
sideOffset: number;
|
|
58
|
+
collisionPadding: number;
|
|
59
|
+
avoidCollisions: boolean;
|
|
60
|
+
viewportWidth: number;
|
|
61
|
+
viewportHeight: number;
|
|
62
|
+
}): TooltipPosition;
|
|
63
|
+
/** Portal 并管理 Tooltip 的测量、定位、presence 与退出生命周期。 */
|
|
64
|
+
declare function TooltipContent(props: TooltipContentProps): ReactElement | null;
|
|
65
|
+
export interface TooltipGroupProps {
|
|
66
|
+
children: ReactNode;
|
|
67
|
+
/** 组内所有 Tooltip 共用的方向。 */
|
|
68
|
+
side?: TooltipSide;
|
|
69
|
+
/** 组内所有 Tooltip 共用的对齐方式。 */
|
|
70
|
+
align?: TooltipAlign;
|
|
71
|
+
sideOffset?: number;
|
|
72
|
+
collisionPadding?: number;
|
|
73
|
+
avoidCollisions?: boolean;
|
|
74
|
+
/** 刚进入组时延迟多久显示,默认 180ms;组已经打开后切换立即生效。 */
|
|
75
|
+
delayDuration?: number;
|
|
76
|
+
/** 完全离开组内触发器后多久关闭,默认 80ms。 */
|
|
77
|
+
closeDelay?: number;
|
|
78
|
+
contentClassName?: string;
|
|
79
|
+
}
|
|
80
|
+
export interface TooltipItemProps {
|
|
81
|
+
/** 组内唯一值,用于切换共享 Tooltip。 */
|
|
82
|
+
value: string;
|
|
83
|
+
/** 该项激活时显示在共享 Tooltip 中的内容。 */
|
|
84
|
+
content: ReactNode;
|
|
85
|
+
/** 单个可聚焦交互元素。 */
|
|
86
|
+
children: ReactElement;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* 一组共享同一浮动表面的 Tooltip。
|
|
90
|
+
*
|
|
91
|
+
* 首次进入按 delayDuration 显示;已打开后在相邻 Item 间切换会立即更新内容,
|
|
92
|
+
* 并由 Motion layout 连续移动到新触发器的位置。
|
|
93
|
+
*/
|
|
94
|
+
declare function TooltipGroup({ children, side, align, sideOffset, collisionPadding, avoidCollisions, delayDuration, closeDelay, contentClassName, }: TooltipGroupProps): ReactElement;
|
|
95
|
+
/** 注册组内触发器与内容,但不改变触发器的 DOM 结构或交互语义。 */
|
|
96
|
+
declare function TooltipItem({ value, content, children, }: TooltipItemProps): ReactElement;
|
|
97
|
+
export interface TooltipComponent {
|
|
98
|
+
Root: typeof TooltipRoot;
|
|
99
|
+
Trigger: typeof TooltipTrigger;
|
|
100
|
+
Content: typeof TooltipContent;
|
|
101
|
+
Group: typeof TooltipGroup;
|
|
102
|
+
Item: typeof TooltipItem;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* 简短说明性浮层。
|
|
106
|
+
*
|
|
107
|
+
* 组合式 API:单个 Tooltip 使用 Root / Trigger / Content;相邻说明使用
|
|
108
|
+
* Group / Item 共享同一个浮动表面。触发器保留原生语义,Content 只承担
|
|
109
|
+
* role="tooltip";需要交互或较长内容时应使用可见说明或 Popover。
|
|
110
|
+
*/
|
|
111
|
+
export declare const Tooltip: TooltipComponent;
|
|
112
|
+
export {};
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),s=require("react"),P=require("react-dom"),y=require("seam-hooks");function j(...t){return t.filter(Boolean).join(" ")}const $=s.forwardRef(function({variant:a="primary",size:c="md",loading:r=!1,iconOnly:u=!1,type:d="button",className:o,children:h,...i},l){return n.jsxs("button",{...i,ref:l,type:d,className:j("uk-button",o),"data-variant":a,"data-size":c,"data-loading":r?"true":void 0,"data-icon-only":u?"true":void 0,disabled:i.disabled||r,"aria-busy":r||void 0,children:[r?n.jsx("span",{className:"uk-button__spinner","aria-hidden":"true"}):null,h]})}),U=s.forwardRef(function({inputSize:a="md",invalid:c=!1,className:r,"aria-invalid":u,...d},o){return n.jsx("input",{...d,ref:o,className:j("uk-input",r),"data-size":a,"aria-invalid":c?!0:u})}),H=s.forwardRef(function({checked:a,defaultChecked:c,onCheckedChange:r,disabled:u,className:d,children:o,id:h,...i},l){const g=s.useId(),x=h??g,[C,v]=y.useControllableState({value:a,defaultValue:c??!1,onChange:r});return n.jsxs("label",{className:j("uk-switch",d),"data-disabled":u?"true":void 0,htmlFor:x,children:[n.jsx("input",{...i,ref:l,id:x,type:"checkbox",role:"switch",className:"uk-switch__input",checked:C,disabled:u,"aria-checked":C,onChange:k=>v(k.target.checked)}),n.jsx("span",{className:"uk-switch__track","aria-hidden":"true",children:n.jsx("span",{className:"uk-switch__thumb"})}),o?n.jsx("span",{className:"uk-switch__label",children:o}):null]})}),q=s.createContext(null);function D(t){const a=s.useContext(q);if(!a)throw new Error(`<${t}> must be rendered inside <Tabs>`);return a}function z(t,a){return`${t}-tab-${encodeURIComponent(a)}`}function B(t,a){return`${t}-panel-${encodeURIComponent(a)}`}function K({value:t,defaultValue:a,onValueChange:c,orientation:r="horizontal",className:u,children:d}){const o=s.useId(),[h,i]=y.useControllableState({value:t,defaultValue:a??"",onChange:c}),l=s.useMemo(()=>({baseId:o,value:h,setValue:i,orientation:r}),[o,h,r,i]);return n.jsx(q.Provider,{value:l,children:n.jsx("div",{className:j("uk-tabs",u),"data-orientation":r,children:d})})}const O=s.forwardRef(function({className:a,onKeyDown:c,...r},u){const{orientation:d}=D("Tabs.List");return n.jsx("div",{...r,ref:u,role:"tablist","aria-orientation":d,tabIndex:-1,className:j("uk-tabs__list",a),onKeyDown:o=>{if(c?.(o),o.defaultPrevented)return;const i=o.target?.closest('[role="tab"]');if(!i||i.hasAttribute("disabled"))return;const l=Array.from(o.currentTarget.querySelectorAll('[role="tab"]:not([disabled])')),g=l.indexOf(i);if(g===-1)return;const x=d==="horizontal"?"ArrowRight":"ArrowDown",C=d==="horizontal"?"ArrowLeft":"ArrowUp";let v=-1;switch(o.key){case x:v=(g+1)%l.length;break;case C:v=(g-1+l.length)%l.length;break;case"Home":v=0;break;case"End":v=l.length-1;break;default:return}o.preventDefault();const k=l[v];k&&(k.focus(),k.click())}})}),W=s.forwardRef(function({value:a,type:c="button",className:r,onClick:u,...d},o){const h=D("Tabs.Trigger"),i=h.value===a;return n.jsx("button",{...d,ref:o,type:c,role:"tab",id:z(h.baseId,a),"aria-selected":i,"aria-controls":B(h.baseId,a),tabIndex:i?0:-1,"data-state":i?"active":"inactive",className:j("uk-tabs__trigger",r),onClick:l=>{u?.(l),l.defaultPrevented||h.setValue(a)}})}),X=s.forwardRef(function({value:a,className:c,...r},u){const d=D("Tabs.Content"),o=d.value===a;return n.jsx("div",{...r,ref:u,role:"tabpanel",id:B(d.baseId,a),"aria-labelledby":z(d.baseId,a),hidden:!o,tabIndex:0,"data-state":o?"active":"inactive",className:j("uk-tabs__panel",c)})}),G=Object.assign(K,{List:O,Trigger:W,Content:X}),J=()=>()=>{},Q=()=>!0,Y=()=>!1;function Z({open:t,onOpenChange:a,title:c,description:r,footer:u,children:d,closeLabel:o="Close",showCloseButton:h=!0,closeOnBackdropClick:i=!0,closeOnEscape:l=!0,initialFocusRef:g,returnFocusRef:x,className:C,"aria-label":v}){const k=s.useRef(null),_=s.useRef(null),p=s.useRef(t),R=s.useId(),T=s.useId(),N=s.useSyncExternalStore(J,Q,Y),w=y.useEventCallback(()=>{p.current&&a(!1)});return y.useLockBodyScroll(t),s.useEffect(()=>{p.current=t},[t]),s.useEffect(()=>{const f=k.current;f&&(t&&!f.open?(_.current=document.activeElement instanceof HTMLElement?document.activeElement:null,typeof f.showModal=="function"?f.showModal():f.setAttribute("open","")):!t&&f.open&&(typeof f.close=="function"?f.close():f.removeAttribute("open")))},[t]),y.useFocusTrap({active:t,containerRef:k,initialFocusRef:g,returnFocusRef:x??_}),s.useEffect(()=>{const f=k.current;if(!f)return;const E=()=>w(),I=e=>{l||e.preventDefault()},S=e=>{i&&e.target===f&&w()};return f.addEventListener("close",E),f.addEventListener("cancel",I),f.addEventListener("click",S),()=>{f.removeEventListener("close",E),f.removeEventListener("cancel",I),f.removeEventListener("click",S)}},[i,l,w]),N?P.createPortal(n.jsx("dialog",{ref:k,className:j("uk-dialog",C),"aria-label":v,"aria-labelledby":c?R:void 0,"aria-describedby":r?T:void 0,children:n.jsxs("div",{className:"uk-dialog__panel",children:[c||r||h?n.jsxs("header",{className:"uk-dialog__header",children:[n.jsxs("div",{className:"uk-dialog__heading",children:[c?n.jsx("h2",{id:R,className:"uk-dialog__title",children:c}):null,r?n.jsx("p",{id:T,className:"uk-dialog__description",children:r}):null]}),h?n.jsx($,{variant:"ghost",size:"sm",iconOnly:!0,"aria-label":o,className:"uk-dialog__close",onClick:w,children:n.jsx("svg",{viewBox:"0 0 20 20",width:"16",height:"16","aria-hidden":"true",children:n.jsx("path",{d:"M5 5l10 10M15 5L5 15",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round"})})}):null]}):null,n.jsx("div",{className:"uk-dialog__body",children:d}),u?n.jsx("footer",{className:"uk-dialog__footer",children:u}):null]})}),document.body):null}const V=s.createContext(null),ee=200,te=()=>()=>{},se=()=>!0,ne=()=>!1;function ae({record:t,closeLabel:a,onDismiss:c,onPause:r,onResume:u}){return n.jsxs("div",{className:"uk-toast","data-variant":t.variant,"data-state":t.leaving?"closed":"open",onMouseEnter:()=>r(t.id),onMouseLeave:()=>u(t.id),onFocusCapture:()=>r(t.id),onBlurCapture:()=>u(t.id),children:[n.jsxs("div",{className:"uk-toast__body",children:[t.title?n.jsx("div",{className:"uk-toast__title",children:t.title}):null,t.description?n.jsx("div",{className:"uk-toast__description",children:t.description}):null]}),n.jsx("button",{type:"button",className:"uk-toast__close","aria-label":a,onClick:()=>c(t.id),children:n.jsx("svg",{viewBox:"0 0 20 20",width:"14",height:"14","aria-hidden":"true",children:n.jsx("path",{d:"M5 5l10 10M15 5L5 15",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round"})})})]})}function re({children:t,placement:a="top-right",duration:c=4e3,maxToasts:r=4,label:u="Notifications",closeLabel:d="Close"}){const[o,h]=s.useState([]),i=s.useRef([]),l=s.useRef(new Map),g=s.useRef(new Map),x=s.useRef(new Map),C=s.useRef(0),v=s.useId(),k=s.useSyncExternalStore(te,se,ne),_=s.useCallback(e=>{i.current=e,h(e)},[]),p=s.useCallback(e=>{const b=g.current.get(e);b!==void 0&&(clearTimeout(b),g.current.delete(e))},[]),R=s.useCallback(e=>{const b=x.current.get(e);b!==void 0&&(clearTimeout(b),x.current.delete(e))},[]),T=s.useCallback(e=>{p(e),!(x.current.has(e)||!i.current.some(m=>m.id===e))&&(_(i.current.map(m=>m.id===e?{...m,leaving:!0}:m)),x.current.set(e,setTimeout(()=>{x.current.delete(e),l.current.delete(e),_(i.current.filter(m=>m.id!==e))},ee)))},[p,_]),N=s.useCallback((e,b)=>{p(e),!(b<=0)&&g.current.set(e,setTimeout(()=>{g.current.delete(e),T(e)},b))},[p,T]),w=s.useCallback(e=>{const b=`${v}-${C.current}`;C.current+=1;const m={id:b,title:e.title,description:e.description,variant:e.variant??"info",duration:e.duration??c,leaving:!1},L=[...i.current,m],M=Math.max(0,L.length-r);(M>0?L.slice(0,M):[]).forEach(A=>{p(A.id),R(A.id),l.current.delete(A.id)});const F=M>0?L.slice(M):L;return l.current.set(b,m.duration),_(F),N(b,m.duration),b},[v,p,R,_,c,r,N]),f=s.useCallback(e=>{p(e)},[p]),E=s.useCallback(e=>{const b=l.current.get(e);b!==void 0&&N(e,b)},[N]),I=s.useCallback(()=>{i.current.forEach(e=>T(e.id))},[T]),S=s.useMemo(()=>({toast:w,dismiss:T,dismissAll:I}),[T,I,w]);return s.useEffect(()=>{const e=g.current,b=x.current;return()=>{e.forEach(m=>clearTimeout(m)),b.forEach(m=>clearTimeout(m)),e.clear(),b.clear()}},[]),n.jsxs(V.Provider,{value:S,children:[t,k?P.createPortal(n.jsx("section",{className:"uk-toast-viewport","data-placement":a,"aria-label":u,"aria-live":"polite","aria-atomic":"false",children:o.map(e=>n.jsx(ae,{record:e,closeLabel:d,onDismiss:T,onPause:f,onResume:E},e.id))}),document.body):null]})}function oe(){const t=s.useContext(V);if(!t)throw new Error("useToast must be used within <ToastProvider>");return t}exports.Button=$;exports.Dialog=Z;exports.Input=U;exports.Switch=H;exports.Tabs=G;exports.ToastProvider=re;exports.useToast=oe;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react/jsx-runtime"),s=require("react"),k=require("motion/react"),q=require("react-dom"),v=require("seam-hooks");function I(...t){return t.filter(Boolean).join(" ")}const H=s.forwardRef(function({variant:e="primary",size:n="md",loading:o=!1,iconOnly:r=!1,type:c="button",className:a,children:u,...p},i){return f.jsxs("button",{...p,ref:i,type:c,className:I("uk-button",a),"data-variant":e,"data-size":n,"data-loading":o?"true":void 0,"data-icon-only":r?"true":void 0,disabled:p.disabled||o,"aria-busy":o||void 0,children:[o?f.jsx("span",{className:"uk-button__spinner","aria-hidden":"true"}):null,u]})}),ve=s.forwardRef(function({inputSize:e="md",invalid:n=!1,className:o,"aria-invalid":r,...c},a){return f.jsx("input",{...c,ref:a,className:I("uk-input",o),"data-size":e,"aria-invalid":n?!0:r})}),B=[.23,1,.32,1],X={type:"spring",bounce:0,duration:.3},Y={type:"spring",bounce:.04,duration:.38},Ie={type:"spring",bounce:.08,duration:.34},Q={duration:.12,ease:B},Ee={layout:{type:"spring",bounce:0,duration:.22},opacity:{duration:.12,ease:B},scale:{duration:.12,ease:B}},O={duration:.12,ease:B},Re=s.forwardRef(function({checked:e,defaultChecked:n,onCheckedChange:o,disabled:r,className:c,children:a,id:u,...p},i){const b=s.useId(),g=u??b,d=k.useReducedMotion()??!1,h=s.useRef(!1),m=s.useRef(null),[x,y]=v.useControllableState({value:e,defaultValue:n??!1,onChange:o}),T=k.useMotionValue(x?16:0);s.useEffect(()=>{if(m.current)return;const l=k.animate(T,x?16:0,d?{duration:0}:X);return()=>l.stop()},[x,d,T]);const C=l=>{const w=m.current;if(!(!w||w.pointerId!==l.pointerId)){if(w.moved){const R=w.samples[0],j=w.samples[w.samples.length-1],P=R&&j?Math.max(j.time-R.time,1):1,_=R&&j?(j.x-R.x)/P*1e3:0,E=Math.abs(_)>220?_>0:T.get()>=8;h.current=!0,m.current=null,y(E),k.animate(T,E?16:0,d?{duration:0}:{...X,velocity:_}),window.setTimeout(()=>{h.current=!1},0)}else m.current=null;l.currentTarget.hasPointerCapture(l.pointerId)&&typeof l.currentTarget.releasePointerCapture=="function"&&l.currentTarget.releasePointerCapture(l.pointerId)}};return f.jsxs("label",{className:I("uk-switch",c),"data-disabled":r?"true":void 0,htmlFor:g,onClickCapture:l=>{h.current&&(l.preventDefault(),l.stopPropagation())},children:[f.jsx("input",{...p,ref:i,id:g,type:"checkbox",role:"switch",className:"uk-switch__input",checked:x,disabled:r,"aria-checked":x,onChange:l=>y(l.target.checked)}),f.jsx("span",{className:"uk-switch__track","aria-hidden":"true",onPointerDown:l=>{r||(m.current={pointerId:l.pointerId,startX:l.clientX,startValue:T.get(),moved:!1,samples:[{x:l.clientX,time:performance.now()}]},typeof l.currentTarget.setPointerCapture=="function"&&l.currentTarget.setPointerCapture(l.pointerId))},onPointerMove:l=>{const w=m.current;if(!w||w.pointerId!==l.pointerId)return;const R=l.clientX-w.startX;Math.abs(R)>4&&(w.moved=!0),w.moved&&(l.preventDefault(),T.set(Math.max(0,Math.min(16,w.startValue+R))),w.samples.push({x:l.clientX,time:performance.now()}),w.samples=w.samples.filter(j=>performance.now()-j.time<120))},onPointerUp:C,onPointerCancel:C,children:f.jsx(k.motion.span,{className:"uk-switch__thumb",style:{x:T}})}),a?f.jsx("span",{className:"uk-switch__label",children:a}):null]})}),W=s.createContext(null);function z(t){const e=s.useContext(W);if(!e)throw new Error(`<${t}> must be rendered inside <Tabs>`);return e}function Z(t,e){return`${t}-tab-${encodeURIComponent(e)}`}function ee(t,e){return`${t}-panel-${encodeURIComponent(e)}`}function je({value:t,defaultValue:e,onValueChange:n,orientation:o="horizontal",className:r,children:c}){const a=s.useId(),[u,p]=v.useControllableState({value:t,defaultValue:e??"",onChange:n}),i=s.useMemo(()=>({baseId:a,value:u,setValue:p,orientation:o,indicatorId:`${a}-indicator`}),[a,u,o,p]);return f.jsx(W.Provider,{value:i,children:f.jsx("div",{className:I("uk-tabs",r),"data-orientation":o,children:c})})}const De=s.forwardRef(function({className:e,onKeyDown:n,...o},r){const{orientation:c}=z("Tabs.List");return f.jsx("div",{...o,ref:r,role:"tablist","aria-orientation":c,tabIndex:-1,className:I("uk-tabs__list",e),onKeyDown:a=>{if(n?.(a),a.defaultPrevented)return;const p=a.target?.closest('[role="tab"]');if(!p||p.hasAttribute("disabled"))return;const i=Array.from(a.currentTarget.querySelectorAll('[role="tab"]:not([disabled])')),b=i.indexOf(p);if(b===-1)return;const g=c==="horizontal"?"ArrowRight":"ArrowDown",d=c==="horizontal"?"ArrowLeft":"ArrowUp";let h=-1;switch(a.key){case g:h=(b+1)%i.length;break;case d:h=(b-1+i.length)%i.length;break;case"Home":h=0;break;case"End":h=i.length-1;break;default:return}a.preventDefault();const m=i[h];m&&(m.focus(),m.click())}})}),_e=s.forwardRef(function({value:e,type:n="button",className:o,onClick:r,children:c,...a},u){const p=z("Tabs.Trigger"),i=p.value===e,b=k.useReducedMotion()??!1;return f.jsxs("button",{...a,ref:u,type:n,role:"tab",id:Z(p.baseId,e),"aria-selected":i,"aria-controls":ee(p.baseId,e),tabIndex:i?0:-1,"data-state":i?"active":"inactive",className:I("uk-tabs__trigger",o),onClick:g=>{r?.(g),g.defaultPrevented||p.setValue(e)},children:[c,i?f.jsx(k.motion.span,{className:"uk-tabs__indicator",layoutId:p.indicatorId,"aria-hidden":"true",transition:b?{duration:0}:Ie}):null]})}),Pe=s.forwardRef(function({value:e,className:n,...o},r){const c=z("Tabs.Content"),a=c.value===e;return f.jsx("div",{...o,ref:r,role:"tabpanel",id:ee(c.baseId,e),"aria-labelledby":Z(c.baseId,e),hidden:!a,tabIndex:0,"data-state":a?"active":"inactive",className:I("uk-tabs__panel",n)})}),Se=Object.assign(je,{List:De,Trigger:_e,Content:Pe}),te=s.createContext(null),Le=()=>()=>{},Me=()=>!0,Ne=()=>!1;function $(t){const e=s.useContext(te);if(!e)throw new Error(`<${t}> must be rendered inside <Dialog.Root>`);return e}function ne(t,e){return n=>{t?.(n),n.defaultPrevented||e(n)}}function oe({children:t,open:e,defaultOpen:n,onOpenChange:o}){const r=s.useId(),[c,a]=s.useState(!1),[u,p]=s.useState(!1),[i,b]=v.useControllableState({value:e,defaultValue:n??!1,onChange:o}),g=s.useMemo(()=>({open:i,setOpen:b,triggerId:`${r}-trigger`,contentId:`${r}-content`,titleId:`${r}-title`,descriptionId:`${r}-description`,hasTitle:c,setHasTitle:a,hasDescription:u,setHasDescription:p}),[r,i,u,c,b]);return f.jsx(te.Provider,{value:g,children:t})}function Oe({children:t}){const e=$("Dialog.Trigger"),n=t,o=n.props.onClick;return s.cloneElement(n,{id:e.triggerId,"aria-haspopup":"dialog","aria-expanded":e.open,"aria-controls":e.open?e.contentId:void 0,onClick:ne(o,()=>{e.setOpen(!e.open)})})}function re({children:t,label:e="Close"}){const n=$("Dialog.Close");if(s.isValidElement(t)){const o=t,r=o.props.onClick;return s.cloneElement(o,{onClick:ne(r,()=>{n.setOpen(!1)})})}return f.jsx(H,{variant:"ghost",onClick:()=>n.setOpen(!1),children:e})}const se=s.forwardRef(function({className:e,...n},o){return f.jsx("header",{...n,ref:o,className:I("uk-dialog__header",e)})}),ie=s.forwardRef(function({className:e,children:n,...o},r){const c=$("Dialog.Title"),a=c.setHasTitle;return s.useEffect(()=>(a(!0),()=>a(!1)),[a]),f.jsx("h2",{...o,ref:r,id:c.titleId,className:I("uk-dialog__title",e),children:n})}),ae=s.forwardRef(function({className:e,...n},o){const r=$("Dialog.Description"),c=r.setHasDescription;return s.useEffect(()=>(c(!0),()=>c(!1)),[c]),f.jsx("p",{...n,ref:o,id:r.descriptionId,className:I("uk-dialog__description",e)})}),ce=s.forwardRef(function({className:e,...n},o){return f.jsx("div",{...n,ref:o,className:I("uk-dialog__body",e)})}),le=s.forwardRef(function({className:e,...n},o){return f.jsx("footer",{...n,ref:o,className:I("uk-dialog__footer",e)})});function $e({requestClose:t,contentId:e,titleId:n,descriptionId:o,hasTitle:r,hasDescription:c,children:a,closeOnBackdropClick:u=!0,closeOnEscape:p=!0,initialFocusRef:i,returnFocusRef:b,className:g,"aria-label":d,"aria-labelledby":h,"aria-describedby":m}){const x=s.useRef(null),y=s.useRef(null),T=k.useIsPresent(),C=k.useReducedMotion()??!1;return v.useLockBodyScroll(!0),s.useLayoutEffect(()=>{const l=x.current;l&&(y.current??(y.current=document.activeElement instanceof HTMLElement?document.activeElement:null),!l.open&&(typeof l.showModal=="function"?l.showModal():l.setAttribute("open","")))},[]),v.useFocusTrap({active:!0,containerRef:x,initialFocusRef:i,returnFocusRef:b??y}),s.useEffect(()=>{const l=x.current;if(!l)return;const w=()=>{l.open||(typeof l.showModal=="function"?l.showModal():l.setAttribute("open",""))},R=()=>{if(!p){w();return}t()},j=E=>{E.preventDefault(),p&&t()},P=E=>{p||E.key!=="Escape"||E.defaultPrevented||(E.preventDefault(),E.stopPropagation())},_=E=>{u&&E.target===l&&t()};return l.addEventListener("close",R),l.addEventListener("cancel",j),l.addEventListener("keydown",P,!0),l.addEventListener("click",_),()=>{l.removeEventListener("close",R),l.removeEventListener("cancel",j),l.removeEventListener("keydown",P,!0),l.removeEventListener("click",_)}},[u,p,t]),f.jsx("dialog",{ref:x,id:e,className:I("uk-dialog",g),closedby:p||u?"any":"none","data-state":T?"open":"closed",inert:!T,"aria-label":d,"aria-labelledby":h??(d?void 0:r?n:void 0),"aria-describedby":m??(c?o:void 0),children:f.jsx(k.motion.div,{className:"uk-dialog__panel",initial:C?{opacity:0}:{opacity:0,transform:"translateY(12px) scale(0.96)"},animate:{opacity:1,transform:"translateY(0px) scale(1)",transition:C?O:{...Y,delay:.06}},exit:C?{opacity:0,transition:O}:{opacity:0,transform:"translateY(8px) scale(0.97)",transition:Y},children:a})})}function ue({children:t,closeOnBackdropClick:e=!0,closeOnEscape:n=!0,initialFocusRef:o,returnFocusRef:r,className:c,"aria-label":a,"aria-labelledby":u,"aria-describedby":p}){const i=$("Dialog.Content"),b=v.useEventCallback(()=>{i.setOpen(!1)});return s.useSyncExternalStore(Le,Me,Ne)?q.createPortal(f.jsx(k.MotionConfig,{reducedMotion:"user",children:f.jsx(k.AnimatePresence,{children:i.open?f.jsx($e,{requestClose:b,contentId:i.contentId,titleId:i.titleId,descriptionId:i.descriptionId,hasTitle:i.hasTitle,hasDescription:i.hasDescription,closeOnBackdropClick:e,closeOnEscape:n,initialFocusRef:o,returnFocusRef:r,className:c,"aria-label":a,"aria-labelledby":u,"aria-describedby":p,children:t},"uk-dialog"):null})}),document.body):null}function Ae({open:t,onOpenChange:e,title:n,description:o,footer:r,children:c,closeLabel:a="Close",showCloseButton:u=!0,closeOnBackdropClick:p=!0,closeOnEscape:i=!0,initialFocusRef:b,returnFocusRef:g,className:d,"aria-label":h}){return f.jsx(oe,{open:t,onOpenChange:e,children:f.jsxs(ue,{className:d,closeOnBackdropClick:p,closeOnEscape:i,initialFocusRef:b,returnFocusRef:g,"aria-label":h,children:[n||o||u?f.jsxs(se,{children:[f.jsxs("div",{className:"uk-dialog__heading",children:[n?f.jsx(ie,{children:n}):null,o?f.jsx(ae,{children:o}):null]}),u?f.jsx(re,{children:f.jsx(H,{variant:"ghost",size:"sm",iconOnly:!0,"aria-label":a,className:"uk-dialog__close",children:f.jsx("svg",{viewBox:"0 0 20 20",width:"16",height:"16","aria-hidden":"true",children:f.jsx("path",{d:"M5 5l10 10M15 5L5 15",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round"})})})}):null]}):null,f.jsx(ce,{children:c}),r?f.jsx(le,{children:r}):null]})})}const Be=Object.assign(Ae,{Root:oe,Trigger:Oe,Content:ue,Header:se,Title:ie,Description:ae,Body:ce,Footer:le,Close:re}),de=s.createContext(null),fe=()=>()=>{},pe=()=>!0,me=()=>!1;function he(t){const e=s.useContext(de);if(!e)throw new Error(`<${t}> must be rendered inside <Tooltip.Root>`);return e}function be(t,e){typeof t=="function"?t(e):t&&(t.current=e)}function ge(t,e){const n=typeof t=="string"?t.split(/\s+/).filter(Boolean):[];return Array.from(new Set([...n,e])).join(" ")}function D(t,e){return n=>{t?.(n),n.defaultPrevented||e(n)}}function Ve({children:t,open:e,defaultOpen:n,onOpenChange:o,delayDuration:r=300,closeDelay:c=80}){const a=s.useId(),[u,p]=s.useState(null),i=s.useRef(null),b=s.useRef(null),[g,d]=v.useControllableState({value:e,defaultValue:n??!1,onChange:o}),h=s.useCallback(()=>{i.current!==null&&(clearTimeout(i.current),i.current=null)},[]),m=s.useCallback(()=>{b.current!==null&&(clearTimeout(b.current),b.current=null)},[]),x=v.useEventCallback((l=!1)=>{if(h(),m(),!g){if(l||r<=0){d(!0);return}i.current=setTimeout(()=>{i.current=null,d(!0)},r)}}),y=v.useEventCallback(()=>{if(h(),m(),!!g){if(c<=0){d(!1);return}b.current=setTimeout(()=>{b.current=null,d(!1)},c)}}),T=v.useEventCallback(()=>{h(),m(),d(!1)});s.useEffect(()=>{g?m():h()},[m,h,g]),s.useEffect(()=>()=>{h(),m()},[m,h]);const C=s.useMemo(()=>({open:g,triggerElement:u,setTriggerElement:p,contentId:a,requestOpen:x,requestClose:y,dismiss:T}),[a,g,T,y,x,u]);return f.jsx(de.Provider,{value:C,children:t})}function Fe({children:t}){const e=he("Tooltip.Trigger"),{setTriggerElement:n}=e;if(!s.isValidElement(t))throw new Error("<Tooltip.Trigger> expects a single valid React element");const o=t,r=o.props,c=r.ref??o.ref,a=r.onPointerEnter,u=r.onPointerLeave,p=r.onFocus,i=r.onBlur,b=r.onKeyDown,g=s.useCallback(d=>{be(c,d),n(d)},[c,n]);return s.cloneElement(o,{ref:g,"aria-describedby":e.open?ge(r["aria-describedby"],e.contentId):r["aria-describedby"],onPointerEnter:D(a,d=>{e.requestOpen(d.pointerType==="touch")}),onPointerLeave:D(u,d=>{d.pointerType!=="touch"&&e.requestClose()}),onFocus:D(p,()=>{e.requestOpen()}),onBlur:D(i,()=>{e.requestClose()}),onKeyDown:D(b,d=>{d.key==="Escape"&&e.open&&(d.preventDefault(),d.stopPropagation(),e.dismiss())})})}function A(t,e,n){return n<e?e:Math.min(Math.max(t,e),n)}function qe(t){switch(t){case"top":return"bottom";case"right":return"left";case"bottom":return"top";case"left":return"right"}}function F(t,e,n,o,r){switch(e){case"top":return t.top-r;case"right":return n-t.right-r;case"bottom":return o-t.bottom-r;case"left":return t.left-r}}function J(t,e,n,o,r,c,a){return F(t,n,r,c,a)>=(n==="top"||n==="bottom"?e.height:e.width)+o}function He({trigger:t,tooltip:e,side:n,align:o,sideOffset:r,collisionPadding:c,avoidCollisions:a,viewportWidth:u,viewportHeight:p}){let i=n;if(a&&!J(t,e,n,r,u,p,c)){const y=qe(n),T=J(t,e,y,r,u,p,c),C=F(t,n,u,p,c),l=F(t,y,u,p,c);(T||l>C)&&(i=y)}const b=t.left+t.width/2,g=t.top+t.height/2;let d=0,h=0;switch(i){case"top":case"bottom":d=o==="start"?t.left:o==="end"?t.right-e.width:b-e.width/2,h=i==="top"?t.top-e.height-r:t.bottom+r;break;case"left":case"right":d=i==="left"?t.left-e.width-r:t.right+r,h=o==="start"?t.top:o==="end"?t.bottom-e.height:g-e.height/2;break}a&&(d=A(d,c,u-e.width-c),h=A(h,c,p-e.height-c));const m=10,x=i==="top"||i==="bottom"?A(b-d,m,Math.max(m,e.width-m)):A(g-h,m,Math.max(m,e.height-m));return{x:d,y:h,side:i,arrowOffset:x}}function xe(t,e,{side:n,align:o,sideOffset:r,collisionPadding:c,avoidCollisions:a}){const[u,p]=s.useState(null);return s.useLayoutEffect(()=>{const i=e.current;if(!i||!t)return;const b=()=>{const d=t.getBoundingClientRect(),h=i.getBoundingClientRect();p(He({trigger:d,tooltip:h,side:n,align:o,sideOffset:r,collisionPadding:c,avoidCollisions:a,viewportWidth:window.innerWidth||document.documentElement.clientWidth,viewportHeight:window.innerHeight||document.documentElement.clientHeight}))};b(),window.addEventListener("resize",b),window.addEventListener("scroll",b,!0);const g=typeof ResizeObserver>"u"?null:new ResizeObserver(b);return g?.observe(t),g?.observe(i),()=>{window.removeEventListener("resize",b),window.removeEventListener("scroll",b,!0),g?.disconnect()}},[o,a,c,e,n,r,t]),u}function ye(t,e,n){s.useEffect(()=>{const o=a=>{const u=a.target;u instanceof Node&&(t.contains(u)||e.current?.contains(u)||n())},r=()=>{document.visibilityState==="hidden"&&n()},c=a=>{const u=a.target;a.key!=="Escape"||u instanceof Node&&t.contains(u)||n()};return document.addEventListener("pointerdown",o,!0),document.addEventListener("visibilitychange",r),document.addEventListener("keydown",c,!0),window.addEventListener("blur",n),()=>{document.removeEventListener("pointerdown",o,!0),document.removeEventListener("visibilitychange",r),document.removeEventListener("keydown",c,!0),window.removeEventListener("blur",n)}},[n,e,t])}function Te(t){switch(t){case"top":return"center bottom";case"bottom":return"center top";case"left":return"right center";case"right":return"left center";default:return"center"}}function ze({contentId:t,triggerElement:e,dismiss:n,children:o,className:r,style:c,side:a="top",align:u="center",sideOffset:p=8,collisionPadding:i=8,avoidCollisions:b=!0,...g}){const d=s.useRef(null),h=k.useReducedMotion()??!1,m=k.useIsPresent(),x=xe(e,d,{side:a,align:u,sideOffset:p,collisionPadding:i,avoidCollisions:b});ye(e,d,n);const y=Te(x?.side??a),T={...c,left:x?`${x.x}px`:0,top:x?`${x.y}px`:0,visibility:x?"visible":"hidden"};return f.jsx("div",{...g,ref:d,id:t,role:"tooltip","data-side":x?.side??a,"data-align":u,"data-state":m?"open":"closed","aria-hidden":m?void 0:!0,className:I("uk-tooltip",r),style:T,children:f.jsxs(k.motion.div,{className:"uk-tooltip__surface",style:{transformOrigin:y},initial:h?{opacity:0}:{opacity:0,scale:.96},animate:{opacity:1,scale:1},exit:h?{opacity:0}:{opacity:0,scale:.96},transition:h?O:Q,children:[f.jsx("span",{className:"uk-tooltip__arrow","aria-hidden":"true",style:{"--uk-tooltip-arrow-offset":`${x?.arrowOffset??0}px`}}),o]})})}function Ke(t){const e=he("Tooltip.Content"),o=s.useSyncExternalStore(fe,pe,me)&&e.triggerElement?e.triggerElement.closest("dialog")??document.body:null;return!o||!e.triggerElement?null:q.createPortal(f.jsx(k.MotionConfig,{reducedMotion:"user",children:f.jsx(k.AnimatePresence,{children:e.open?f.jsx(ze,{contentId:e.contentId,triggerElement:e.triggerElement,dismiss:e.dismiss,...t},"uk-tooltip"):null})}),o)}const we=s.createContext(null);function Ge(t){const e=s.useContext(we);if(!e)throw new Error(`<${t}> must be rendered inside <Tooltip.Group>`);return e}function Ue({activeValue:t,content:e,contentClassName:n,contentId:o,dismiss:r,triggerElement:c,side:a,align:u,sideOffset:p,collisionPadding:i,avoidCollisions:b}){const g=s.useRef(null),d=k.useReducedMotion()??!1,h=k.useIsPresent(),m=xe(c,g,{side:a,align:u,sideOffset:p,collisionPadding:i,avoidCollisions:b});ye(c,g,r);const x={left:m?`${m.x}px`:0,top:m?`${m.y}px`:0,transformOrigin:Te(m?.side??a),visibility:m?"visible":"hidden"};return f.jsxs(k.motion.div,{ref:g,id:o,role:"tooltip",layout:!d,layoutDependency:t,"data-side":m?.side??a,"data-align":u,"data-state":h?"open":"closed","aria-hidden":h?void 0:!0,className:I("uk-tooltip","uk-tooltip__surface","uk-tooltip--group",n),style:x,initial:d?{opacity:0}:{opacity:0,scale:.96},animate:{opacity:1,scale:1},exit:d?{opacity:0}:{opacity:0,scale:.96},transition:d?{...O,layout:{duration:0}}:Ee,children:[f.jsx("span",{className:"uk-tooltip__arrow","aria-hidden":"true",style:{"--uk-tooltip-arrow-offset":`${m?.arrowOffset??0}px`}}),f.jsx(k.motion.div,{className:"uk-tooltip__content",initial:{opacity:0},animate:{opacity:1},transition:d?O:Q,children:e},t)]})}function Xe({children:t,side:e="top",align:n="center",sideOffset:o=8,collisionPadding:r=8,avoidCollisions:c=!0,delayDuration:a=180,closeDelay:u=80,contentClassName:p}){const i=s.useId(),[b,g]=s.useState(()=>new Map),[d,h]=s.useState(!1),[m,x]=s.useState(null),y=s.useRef(null),T=s.useRef(null),C=s.useSyncExternalStore(fe,pe,me),l=s.useCallback(()=>{y.current!==null&&(clearTimeout(y.current),y.current=null)},[]),w=s.useCallback(()=>{T.current!==null&&(clearTimeout(T.current),T.current=null)},[]),R=v.useEventCallback((L,S=!1)=>{if(l(),w(),x(L),!d){if(S||a<=0){h(!0);return}y.current=setTimeout(()=>{y.current=null,h(!0)},a)}}),j=v.useEventCallback(()=>{if(l(),w(),!!d){if(u<=0){h(!1);return}T.current=setTimeout(()=>{T.current=null,h(!1)},u)}}),P=v.useEventCallback(()=>{l(),w(),h(!1)}),_=v.useEventCallback((L,S,N)=>{g(V=>{const G=V.get(L);if(G?.triggerElement===S&&Object.is(G.content,N))return V;const U=new Map(V);return U.set(L,{triggerElement:S,content:N}),U})}),E=v.useEventCallback(L=>{g(S=>{if(!S.has(L))return S;const N=new Map(S);return N.delete(L),N})});s.useEffect(()=>()=>{l(),w()},[w,l]);const Ce=s.useMemo(()=>({open:d,activeValue:m,contentId:i,activate:R,requestClose:j,dismiss:P,register:_,unregister:E}),[R,m,i,P,d,_,j,E]),M=m?b.get(m):void 0,ke=d&&!!M,K=C&&M?M.triggerElement.closest("dialog")??document.body:null;return f.jsxs(we.Provider,{value:Ce,children:[t,K&&M?q.createPortal(f.jsx(k.MotionConfig,{reducedMotion:"user",children:f.jsx(k.AnimatePresence,{children:ke?f.jsx(Ue,{activeValue:m??"",content:M.content,contentClassName:p,contentId:i,dismiss:P,triggerElement:M.triggerElement,side:e,align:n,sideOffset:o,collisionPadding:r,avoidCollisions:c},"uk-tooltip-group"):null})}),K):null]})}function Ye({value:t,content:e,children:n}){const o=Ge("Tooltip.Item"),{register:r,unregister:c}=o,[a,u]=s.useState(null);if(!s.isValidElement(n))throw new Error("<Tooltip.Item> expects a single valid React element");const p=n,i=p.props,b=i.ref??p.ref,g=i.onPointerEnter,d=i.onPointerLeave,h=i.onFocus,m=i.onBlur,x=i.onKeyDown,y=o.open&&o.activeValue===t,T=s.useCallback(C=>{be(b,C),u(C)},[b,u]);return s.useLayoutEffect(()=>{if(a)return r(t,a,e),()=>c(t)},[e,r,a,c,t]),s.cloneElement(p,{ref:T,"aria-describedby":y?ge(i["aria-describedby"],o.contentId):i["aria-describedby"],onPointerEnter:D(g,C=>{o.activate(t,C.pointerType==="touch")}),onPointerLeave:D(d,C=>{C.pointerType!=="touch"&&o.requestClose()}),onFocus:D(h,()=>{o.activate(t)}),onBlur:D(m,()=>{o.requestClose()}),onKeyDown:D(x,C=>{C.key==="Escape"&&y&&(C.preventDefault(),C.stopPropagation(),o.dismiss())})})}const Je={Root:Ve,Trigger:Fe,Content:Ke,Group:Xe,Item:Ye};exports.Button=H;exports.Dialog=Be;exports.Input=ve;exports.Switch=Re;exports.Tabs=Se;exports.Tooltip=Je;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|