@yamada-ui/react 2.2.9 → 2.2.10-dev-20261007032253
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/cjs/components/group/use-group.cjs.map +1 -1
- package/dist/cjs/hooks/use-animation/index.cjs +3 -3
- package/dist/cjs/hooks/use-animation/index.cjs.map +1 -1
- package/dist/cjs/hooks/use-clickable/index.cjs.map +1 -1
- package/dist/cjs/hooks/use-pan-event/index.cjs.map +1 -1
- package/dist/esm/components/group/use-group.js.map +1 -1
- package/dist/esm/hooks/use-animation/index.js +3 -3
- package/dist/esm/hooks/use-animation/index.js.map +1 -1
- package/dist/esm/hooks/use-clickable/index.js.map +1 -1
- package/dist/esm/hooks/use-pan-event/index.js.map +1 -1
- package/dist/types/components/chart/cartesian-chart.style.d.ts +1 -1
- package/dist/types/components/chart/polar-chart.style.d.ts +1 -1
- package/dist/types/components/data-list/data-list.style.d.ts +1 -1
- package/dist/types/components/group/index.d.ts +2 -2
- package/dist/types/components/group/use-group.d.ts +2 -2
- package/dist/types/components/number-input/number-input.style.d.ts +1 -1
- package/dist/types/components/steps/steps.style.d.ts +1 -1
- package/dist/types/components/timeline/timeline.d.ts +1 -1
- package/dist/types/components/timeline/timeline.style.d.ts +1 -1
- package/dist/types/hooks/use-animation/index.d.ts +6 -5
- package/dist/types/hooks/use-clickable/index.d.ts +3 -3
- package/dist/types/hooks/use-pan-event/index.d.ts +3 -3
- package/dist/types/index.d.ts +6 -6
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-group.cjs","names":["useValidChildren","useMemo","cloneElement"],"sources":["../../../../src/components/group/use-group.ts"],"sourcesContent":["import type { CSSProperties, DataAttributes, ReactNode } from \"react\"\nimport { cloneElement, useMemo } from \"react\"\nimport { dataAttr, isNull, isUndefined, useValidChildren } from \"../../utils\"\n\nexport const useGroup = (children?: ReactNode) => {\n const validChildren = useValidChildren(children)\n const omittedChildren = useMemo(\n () =>\n validChildren.filter((child) => {\n const ungrouped = child.props[\"data-ungrouped\"]\n\n return isUndefined(ungrouped) || isNull(ungrouped)\n }),\n [validChildren],\n )\n const count = omittedChildren.length\n const cloneChildren = useMemo(\n () =>\n validChildren.map((child) => {\n const index = omittedChildren.indexOf(child)\n const ungrouped = index === -1\n\n if (ungrouped) return child\n\n return cloneElement(child, {\n ...child.props,\n style: {\n \"--group-count\": count,\n \"--group-index\": index,\n ...child.props?.style,\n },\n \"data-group-between\": dataAttr(index > 0 && index < count - 1),\n \"data-group-end\": dataAttr(index === count - 1),\n \"data-group-start\": dataAttr(index === 0),\n \"data-peer\": \"\",\n })\n }),\n [validChildren, omittedChildren, count],\n )\n\n return cloneChildren\n}\n\nexport type UseGroupReturn = ReturnType<typeof useGroup>\n\
|
|
1
|
+
{"version":3,"file":"use-group.cjs","names":["useValidChildren","useMemo","cloneElement"],"sources":["../../../../src/components/group/use-group.ts"],"sourcesContent":["import type { CSSProperties, DataAttributes, ReactNode } from \"react\"\nimport { cloneElement, useMemo } from \"react\"\nimport { dataAttr, isNull, isUndefined, useValidChildren } from \"../../utils\"\n\nexport const useGroup = (children?: ReactNode) => {\n const validChildren = useValidChildren(children)\n const omittedChildren = useMemo(\n () =>\n validChildren.filter((child) => {\n const ungrouped = child.props[\"data-ungrouped\"]\n\n return isUndefined(ungrouped) || isNull(ungrouped)\n }),\n [validChildren],\n )\n const count = omittedChildren.length\n const cloneChildren = useMemo(\n () =>\n validChildren.map((child) => {\n const index = omittedChildren.indexOf(child)\n const ungrouped = index === -1\n\n if (ungrouped) return child\n\n return cloneElement(child, {\n ...child.props,\n style: {\n \"--group-count\": count,\n \"--group-index\": index,\n ...child.props?.style,\n },\n \"data-group-between\": dataAttr(index > 0 && index < count - 1),\n \"data-group-end\": dataAttr(index === count - 1),\n \"data-group-start\": dataAttr(index === 0),\n \"data-peer\": \"\",\n })\n }),\n [validChildren, omittedChildren, count],\n )\n\n return cloneChildren\n}\n\nexport type UseGroupReturn = ReturnType<typeof useGroup>\n\nexport interface UseGroupItemProps extends DataAttributes {\n style?: CSSProperties\n}\n\nexport const useGroupItemProps = <Y extends UseGroupItemProps>({\n style: {\n \"--group-count\": groupCount,\n \"--group-index\": groupIndex,\n ...style\n } = {},\n \"data-group-between\": dataGroupBetween,\n \"data-group-end\": dataGroupEnd,\n \"data-group-start\": dataGroupStart,\n \"data-peer\": dataPeer,\n ...rest\n}: Y) => {\n const pickedProps = useMemo(\n () => ({\n style: {\n \"--group-count\": groupCount!,\n \"--group-index\": groupIndex!,\n },\n \"data-group-between\": dataGroupBetween,\n \"data-group-end\": dataGroupEnd,\n \"data-group-start\": dataGroupStart,\n \"data-peer\": dataPeer,\n }),\n [\n groupCount,\n groupIndex,\n dataGroupBetween,\n dataGroupEnd,\n dataGroupStart,\n dataPeer,\n ],\n )\n const omittedProps = useMemo(() => ({ style, ...rest }), [style, rest])\n\n return [pickedProps, omittedProps] as const\n}\n\nexport type UseGroupItemReturn = ReturnType<typeof useGroupItemProps>\n"],"mappings":";;;;AAIA,MAAa,YAAY,aAAyB;CAChD,MAAM,gBAAgBA,iBAAAA,iBAAiB,QAAQ;CAC/C,MAAM,mBAAA,GAAkBC,MAAAA,QAAAA,OAEpB,cAAc,QAAQ,UAAU;EAC9B,MAAM,YAAY,MAAM,MAAM;EAE9B,QAAA,GAAA,oBAAA,cAAO,YAAA,CAAY,SAAS,MAAA,GAAA,oBAAA,cAAK,OAAA,CAAO,SAAS;CACnD,CAAC,GACH,CAAC,aAAa,CAChB;CACA,MAAM,QAAQ,gBAAgB;CAyB9B,QAAA,GAxBsBA,MAAAA,QAAAA,OAElB,cAAc,KAAK,UAAU;EAC3B,MAAM,QAAQ,gBAAgB,QAAQ,KAAK;EAG3C,IAFkB,UAAU,IAEb,OAAO;EAEtB,QAAA,GAAOC,MAAAA,aAAAA,CAAa,OAAO;GACzB,GAAG,MAAM;GACT,OAAO;IACL,iBAAiB;IACjB,iBAAiB;IACjB,GAAG,MAAM,OAAO;GAClB;GACA,uBAAA,GAAA,oBAAA,cAAsB,SAAA,CAAS,QAAQ,KAAK,QAAQ,QAAQ,CAAC;GAC7D,mBAAA,GAAA,oBAAA,cAAkB,SAAA,CAAS,UAAU,QAAQ,CAAC;GAC9C,qBAAA,GAAA,oBAAA,cAAoB,SAAA,CAAS,UAAU,CAAC;GACxC,aAAa;EACf,CAAC;CACH,CAAC,GACH;EAAC;EAAe;EAAiB;CAAK,CAGrB;AACrB;AAQA,MAAa,qBAAkD,EAC7D,OAAO,EACL,iBAAiB,YACjB,iBAAiB,YACjB,GAAG,UACD,CAAC,GACL,sBAAsB,kBACtB,kBAAkB,cAClB,oBAAoB,gBACpB,aAAa,UACb,GAAG,WACI;CAuBP,OAAO,EAAA,GAtBaD,MAAAA,QAAAA,QACX;EACL,OAAO;GACL,iBAAiB;GACjB,iBAAiB;EACnB;EACA,sBAAsB;EACtB,kBAAkB;EAClB,oBAAoB;EACpB,aAAa;CACf,IACA;EACE;EACA;EACA;EACA;EACA;EACA;CACF,CAIgB,IAAA,GAFGA,MAAAA,QAAAA,QAAe;EAAE;EAAO,GAAG;CAAK,IAAI,CAAC,OAAO,IAAI,CAErC,CAAC;AACnC"}
|
|
@@ -11,13 +11,13 @@ let react = require("react");
|
|
|
11
11
|
*
|
|
12
12
|
* @see https://yamada-ui.com/docs/hooks/use-animation
|
|
13
13
|
*/
|
|
14
|
-
const useAnimation = (
|
|
14
|
+
const useAnimation = (arrayOrObj) => {
|
|
15
15
|
const system = require_system_provider.useSystem();
|
|
16
|
-
if ((0, require_utils_index.utils_exports.isArray)(
|
|
16
|
+
if ((0, require_utils_index.utils_exports.isArray)(arrayOrObj)) return arrayOrObj.map((obj) => require_animation.animation(obj, {
|
|
17
17
|
css: require_css.css,
|
|
18
18
|
system
|
|
19
19
|
})).join(", ");
|
|
20
|
-
else return require_animation.animation(
|
|
20
|
+
else return require_animation.animation(arrayOrObj, {
|
|
21
21
|
css: require_css.css,
|
|
22
22
|
system
|
|
23
23
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["useSystem","animation","useRef","useState","useCallback"],"sources":["../../../../src/hooks/use-animation/index.ts"],"sourcesContent":["\"use client\"\n\nimport type { CSSAnimationObject, Token } from \"../../core\"\nimport { useCallback, useRef, useState } from \"react\"\nimport { animation, css, useSystem } from \"../../core\"\nimport { isArray, isUndefined, runIfFn } from \"../../utils\"\n\
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["useSystem","animation","useRef","useState","useCallback"],"sources":["../../../../src/hooks/use-animation/index.ts"],"sourcesContent":["\"use client\"\n\nimport type { CSSAnimationObject, Token } from \"../../core\"\nimport { useCallback, useRef, useState } from \"react\"\nimport { animation, css, useSystem } from \"../../core\"\nimport { isArray, isUndefined, runIfFn } from \"../../utils\"\n\nexport type UseAnimationProps =\n | Token<CSSAnimationObject, \"animations\">\n | Token<CSSAnimationObject, \"animations\">[]\n\n/**\n * `useAnimation` is a custom hook that implements animations similar to CSS `keyframes`.\n *\n * @see https://yamada-ui.com/docs/hooks/use-animation\n */\nexport const useAnimation = (arrayOrObj: UseAnimationProps): string => {\n const system = useSystem()\n\n if (isArray(arrayOrObj))\n return arrayOrObj.map((obj) => animation(obj, { css, system })).join(\", \")\n else return animation(arrayOrObj, { css, system })\n}\n\nexport type UseDynamicAnimationProps =\n | Token<CSSAnimationObject, \"animations\">[]\n | { [key: string]: UseAnimationProps }\n\n/**\n * `useDynamicAnimation` is a custom hook used to switch animations.\n *\n * @see https://yamada-ui.com/docs/hooks/use-dynamic-animation\n */\nexport const useDynamicAnimation = <Y extends UseDynamicAnimationProps>(\n arrayOrObj: Y,\n init?: (keyof Y)[] | keyof Y,\n): [\n string | undefined,\n (\n key:\n | ((key: (keyof Y)[] | keyof Y | undefined) => (keyof Y)[] | keyof Y)\n | (keyof Y)[]\n | keyof Y,\n ) => void,\n] => {\n const system = useSystem()\n\n const keys = useRef<string | string[] | undefined>(\n !isUndefined(init)\n ? isArray(init)\n ? init.map(String)\n : String(init)\n : undefined,\n )\n const cache = useRef<Map<string, string>>(new Map<string, string>())\n\n const [animations, setAnimations] = useState<string | undefined>(() => {\n for (const [key, styles] of Object.entries(arrayOrObj))\n if (isArray(styles))\n cache.current.set(\n key,\n styles.map((style) => animation(style, { css, system })).join(\", \"),\n )\n else cache.current.set(key, animation(styles, { css, system }))\n\n if (isArray(keys.current))\n return keys.current.map((key) => cache.current.get(key)).join(\", \")\n else return cache.current.get(keys.current ?? \"\")\n })\n\n const setAnimation = useCallback(\n (\n keysOrFunc:\n | ((key: (keyof Y)[] | keyof Y | undefined) => (keyof Y)[] | keyof Y)\n | (keyof Y)[]\n | keyof Y,\n ) => {\n const args = (() => {\n if (!isUndefined(keys.current) && isArray(arrayOrObj))\n return isArray(keys.current)\n ? keys.current.map(Number)\n : Number(keys.current)\n else return keys.current\n })() as (keyof Y)[] | keyof Y | undefined\n\n const keyOrArray = runIfFn(keysOrFunc, args)\n\n keys.current = isArray(keyOrArray)\n ? keyOrArray.map(String)\n : String(keyOrArray)\n\n if (isArray(keys.current))\n setAnimations(\n keys.current.map((key) => cache.current.get(key)).join(\", \"),\n )\n else setAnimations(cache.current.get(keys.current))\n },\n [arrayOrObj],\n )\n\n return [animations, setAnimation]\n}\n"],"mappings":";;;;;;;;;;;;;AAgBA,MAAa,gBAAgB,eAA0C;CACrE,MAAM,SAASA,wBAAAA,UAAU;CAEzB,KAAA,GAAA,oBAAA,cAAI,QAAA,CAAQ,UAAU,GACpB,OAAO,WAAW,KAAK,QAAQC,kBAAAA,UAAU,KAAK;EAAE,KAAA,YAAA;EAAK;CAAO,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI;MACtE,OAAOA,kBAAAA,UAAU,YAAY;EAAE,KAAA,YAAA;EAAK;CAAO,CAAC;AACnD;;;;;;AAWA,MAAa,uBACX,YACA,SASG;CACH,MAAM,SAASD,wBAAAA,UAAU;CAEzB,MAAM,QAAA,GAAOE,MAAAA,OAAAA,CACX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AAK,WAAA,GAAA,oBAAA,cAAU,QAAA,CAAQ,UAAU,IAC7B,WAAW,IAAI,MAAM,IACrB,OAAO,UAAU;EAErB,KAAA,GAAA,oBAAA,cAAI,QAAA,CAAQ,KAAK,OAAO,GACtB,cACE,KAAK,QAAQ,KAAK,QAAQ,MAAM,QAAQ,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,IAAI,CAC7D;OACG,cAAc,MAAM,QAAQ,IAAI,KAAK,OAAO,CAAC;CACpD,GACA,CAAC,UAAU,CAGkB,CAAC;AAClC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["useState","useEventListeners","useCallback","mergeRefs"],"sources":["../../../../src/hooks/use-clickable/index.ts"],"sourcesContent":["\"use client\"\n\nimport type { HTMLAttributes, KeyboardEvent, MouseEvent, Ref } from \"react\"\nimport type { StyledProps } from \"../../core\"\nimport { useCallback, useState } from \"react\"\nimport { dataAttr, isTouchDevice, mergeRefs } from \"../../utils\"\nimport { useEventListeners } from \"../use-event-listener\"\n\ntype Props<Y extends HTMLElement = HTMLElement> = Omit<\n HTMLAttributes<Y>,\n \"ref\" | \"size\" | keyof StyledProps\n>\n\nexport type UseClickableProps<\n Y extends HTMLElement = HTMLElement,\n M extends Props<Y> = Props<Y>,\n> = M & {\n /**\n * Whether or not trigger click on pressing `Enter`.\n *\n * @default true\n */\n clickOnEnter?: boolean\n /**\n * Whether or not trigger click on pressing `Space`.\n *\n * @default true\n */\n clickOnSpace?: boolean\n /**\n * If `true`, the element will be disabled. It will set the `disabled` HTML attribute.\n *\n * @default false\n */\n disabled?: boolean\n /**\n * Disable the touch device behavior.\n *\n * @default true\n */\n disableTouchBehavior?: boolean\n /**\n * If `true` and isDisabled, the element will have only `aria-disabled` set to `true`.\n *\n * @default false\n */\n focusable?: boolean\n /**\n * Whether or not to focus the element when it is clicked.\n * If `true`, the element will receive focus upon click.\n *\n * @default true\n */\n focusOnClick?: boolean\n /**\n * The ref for the element.\n */\n ref?: Ref<Y>\n}\n\nconst isValidElement = (\n ev: KeyboardEvent | KeyboardEvent[\"nativeEvent\"],\n): boolean => {\n const { isContentEditable, tagName } = ev.target as HTMLElement\n\n return tagName !== \"INPUT\" && tagName !== \"TEXTAREA\" && !isContentEditable\n}\n\nexport const useClickable = <\n Y extends HTMLElement = HTMLElement,\n M extends Props<Y> = Props<Y>,\n>(\n {\n ref,\n clickOnEnter = true,\n clickOnSpace = true,\n disabled,\n disableTouchBehavior = true,\n focusable,\n focusOnClick = true,\n tabIndex: tabIndexProp,\n onClick: onClickProp,\n onKeyDown: onKeyDownProp,\n onKeyUp: onKeyUpProp,\n onMouseDown: onMouseDownProp,\n onMouseLeave: onMouseLeaveProp,\n onMouseOver: onMouseOverProp,\n onMouseUp: onMouseUpProp,\n ...props\n }: UseClickableProps<Y, M> = {} as UseClickableProps<Y, M>,\n) => {\n const [button, setButton] = useState<boolean>(true)\n const [pressed, setPressed] = useState<boolean>(false)\n\n const listeners = useEventListeners()\n\n const tabIndex = button ? tabIndexProp : tabIndexProp || 0\n const trulyDisabled = disabled && !focusable\n\n const refCb = (node: any) => {\n if (!node) return\n\n if (node.tagName !== \"BUTTON\") setButton(false)\n }\n\n const onClick = useCallback(\n (ev: MouseEvent<Y>) => {\n if (disabled) {\n ev.stopPropagation()\n ev.preventDefault()\n\n return\n }\n\n if (focusOnClick) ev.currentTarget.focus()\n onClickProp?.(ev)\n },\n [disabled, focusOnClick, onClickProp],\n )\n\n const onDocumentKeyUp = useCallback(\n (ev: globalThis.KeyboardEvent) => {\n if (pressed && isValidElement(ev)) {\n ev.preventDefault()\n ev.stopPropagation()\n\n setPressed(false)\n\n listeners.remove(document, \"keyup\", onDocumentKeyUp, false)\n }\n },\n [pressed, listeners],\n )\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<Y>) => {\n onKeyDownProp?.(ev)\n\n if (disabled || ev.defaultPrevented || ev.metaKey) return\n\n if (!isValidElement(ev.nativeEvent) || button) return\n\n if (clickOnSpace && ev.key === \" \") {\n ev.preventDefault()\n setPressed(true)\n }\n\n if (clickOnEnter && ev.key === \"Enter\") {\n ev.preventDefault()\n ev.currentTarget.click()\n }\n\n listeners.add(document, \"keyup\", onDocumentKeyUp, false)\n },\n [\n disabled,\n button,\n onKeyDownProp,\n clickOnEnter,\n clickOnSpace,\n listeners,\n onDocumentKeyUp,\n ],\n )\n\n const onKeyUp = useCallback(\n (ev: KeyboardEvent<Y>) => {\n onKeyUpProp?.(ev)\n\n if (disabled || ev.defaultPrevented || ev.metaKey) return\n\n if (!isValidElement(ev.nativeEvent) || button) return\n\n if (clickOnSpace && ev.key === \" \") {\n ev.preventDefault()\n setPressed(false)\n\n ev.currentTarget.click()\n }\n },\n [clickOnSpace, button, disabled, onKeyUpProp],\n )\n\n const onDocumentMouseUp = useCallback(\n (ev: globalThis.MouseEvent) => {\n if (ev.button !== 0) return\n\n setPressed(false)\n\n listeners.remove(document, \"mouseup\", onDocumentMouseUp, false)\n },\n [listeners],\n )\n\n const onMouseDown = useCallback(\n (ev: MouseEvent<Y>) => {\n if (ev.button !== 0) return\n\n if (disabled) {\n ev.stopPropagation()\n ev.preventDefault()\n\n return\n }\n\n if (!button) setPressed(true)\n\n if (focusOnClick) ev.currentTarget.focus({ preventScroll: true })\n\n listeners.add(document, \"mouseup\", onDocumentMouseUp, false)\n\n onMouseDownProp?.(ev)\n },\n [\n disabled,\n button,\n onMouseDownProp,\n listeners,\n onDocumentMouseUp,\n focusOnClick,\n ],\n )\n\n const onMouseUp = useCallback(\n (ev: MouseEvent<Y>) => {\n if (ev.button !== 0) return\n\n if (!button) setPressed(false)\n\n onMouseUpProp?.(ev)\n },\n [onMouseUpProp, button],\n )\n\n const onMouseOver = useCallback(\n (ev: MouseEvent<Y>) => {\n if (disabled) {\n ev.preventDefault()\n\n return\n }\n\n if (disableTouchBehavior && isTouchDevice()) return\n\n onMouseOverProp?.(ev)\n },\n [disabled, onMouseOverProp, disableTouchBehavior],\n )\n\n const onMouseLeave = useCallback(\n (ev: MouseEvent<Y>) => {\n if (pressed) {\n ev.preventDefault()\n\n setPressed(false)\n }\n\n if (disableTouchBehavior && isTouchDevice()) return\n\n onMouseLeaveProp?.(ev)\n },\n [pressed, onMouseLeaveProp, disableTouchBehavior],\n )\n\n if (button)\n return {\n ...props,\n ref: mergeRefs(ref, refCb),\n type: \"button\" as const,\n \"aria-disabled\": trulyDisabled ? undefined : disabled,\n disabled: trulyDisabled,\n onClick: onClick,\n onKeyDown: onKeyDownProp,\n onKeyUp: onKeyUpProp,\n onMouseDown: onMouseDownProp,\n onMouseLeave: onMouseLeaveProp,\n onMouseOver: onMouseOverProp,\n onMouseUp: onMouseUpProp,\n }\n else\n return {\n ...props,\n ref: mergeRefs(ref, refCb),\n \"aria-disabled\": disabled ? (\"true\" as const) : undefined,\n \"data-active\": dataAttr(pressed),\n role: \"button\",\n tabIndex: trulyDisabled ? undefined : tabIndex,\n onClick,\n onKeyDown,\n onKeyUp,\n onMouseDown,\n onMouseLeave,\n onMouseOver,\n onMouseUp,\n }\n}\n\nexport type UseClickableReturn = ReturnType<typeof useClickable>\n"],"mappings":";;;;;;;AA4DA,MAAM,kBACJ,OACY;CACZ,MAAM,EAAE,mBAAmB,YAAY,GAAG;CAE1C,OAAO,YAAY,WAAW,YAAY,cAAc,CAAC;AAC3D;AAEA,MAAa,gBAIX,EACE,KACA,eAAe,MACf,eAAe,MACf,UACA,uBAAuB,MACvB,WACA,eAAe,MACf,UAAU,cACV,SAAS,aACT,WAAW,eACX,SAAS,aACT,aAAa,iBACb,cAAc,kBACd,aAAa,iBACb,WAAW,eACX,GAAG,UACwB,CAAC,MAC3B;CACH,MAAM,CAAC,QAAQ,cAAA,GAAaA,MAAAA,SAAAA,CAAkB,IAAI;CAClD,MAAM,CAAC,SAAS,eAAA,GAAcA,MAAAA,SAAAA,CAAkB,KAAK;CAErD,MAAM,YAAYC,uCAAAA,kBAAkB;CAEpC,MAAM,WAAW,SAAS,eAAe,gBAAgB;CACz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B,EAAE;CACvB,GACA;EAAC;EAAS;EAAkB;CAAoB,CAClD;CAEA,IAAI,QACF,OAAO;EACL,GAAG;EACH,KAAKC,YAAAA,UAAU,KAAK,KAAK;EACzB,MAAM;EACN,iBAAiB,gBAAgB,KAAA,IAAY;EAC7C,UAAU;EACD;EACT,WAAW;EACX,SAAS;EACT,aAAa;EACb,cAAc;EACd,aAAa;EACb,WAAW;CACb;MAEA,OAAO;EACL,GAAG;EACH,KAAKA,YAAAA,UAAU,KAAK,KAAK;EACzB,iBAAiB,WAAY,SAAmB,KAAA;EAChD,gBAAA,GAAA,oBAAA,cAAe,SAAA,CAAS,OAAO;EAC/B,MAAM;EACN,UAAU,gBAAgB,KAAA,IAAY;EACtC;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACJ"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["useState","useEventListeners","useCallback","mergeRefs"],"sources":["../../../../src/hooks/use-clickable/index.ts"],"sourcesContent":["\"use client\"\n\nimport type { HTMLAttributes, KeyboardEvent, MouseEvent, Ref } from \"react\"\nimport type { StyledProps } from \"../../core\"\nimport { useCallback, useState } from \"react\"\nimport { dataAttr, isTouchDevice, mergeRefs } from \"../../utils\"\nimport { useEventListeners } from \"../use-event-listener\"\n\nexport type UseClickableElementProps<Y extends HTMLElement = HTMLElement> =\n Omit<HTMLAttributes<Y>, \"ref\" | \"size\" | keyof StyledProps>\n\nexport type UseClickableProps<\n Y extends HTMLElement = HTMLElement,\n M extends UseClickableElementProps<Y> = UseClickableElementProps<Y>,\n> = M & {\n /**\n * Whether or not trigger click on pressing `Enter`.\n *\n * @default true\n */\n clickOnEnter?: boolean\n /**\n * Whether or not trigger click on pressing `Space`.\n *\n * @default true\n */\n clickOnSpace?: boolean\n /**\n * If `true`, the element will be disabled. It will set the `disabled` HTML attribute.\n *\n * @default false\n */\n disabled?: boolean\n /**\n * Disable the touch device behavior.\n *\n * @default true\n */\n disableTouchBehavior?: boolean\n /**\n * If `true` and isDisabled, the element will have only `aria-disabled` set to `true`.\n *\n * @default false\n */\n focusable?: boolean\n /**\n * Whether or not to focus the element when it is clicked.\n * If `true`, the element will receive focus upon click.\n *\n * @default true\n */\n focusOnClick?: boolean\n /**\n * The ref for the element.\n */\n ref?: Ref<Y>\n}\n\nconst isValidElement = (\n ev: KeyboardEvent | KeyboardEvent[\"nativeEvent\"],\n): boolean => {\n const { isContentEditable, tagName } = ev.target as HTMLElement\n\n return tagName !== \"INPUT\" && tagName !== \"TEXTAREA\" && !isContentEditable\n}\n\nexport const useClickable = <\n Y extends HTMLElement = HTMLElement,\n M extends UseClickableElementProps<Y> = UseClickableElementProps<Y>,\n>(\n {\n ref,\n clickOnEnter = true,\n clickOnSpace = true,\n disabled,\n disableTouchBehavior = true,\n focusable,\n focusOnClick = true,\n tabIndex: tabIndexProp,\n onClick: onClickProp,\n onKeyDown: onKeyDownProp,\n onKeyUp: onKeyUpProp,\n onMouseDown: onMouseDownProp,\n onMouseLeave: onMouseLeaveProp,\n onMouseOver: onMouseOverProp,\n onMouseUp: onMouseUpProp,\n ...props\n }: UseClickableProps<Y, M> = {} as UseClickableProps<Y, M>,\n) => {\n const [button, setButton] = useState<boolean>(true)\n const [pressed, setPressed] = useState<boolean>(false)\n\n const listeners = useEventListeners()\n\n const tabIndex = button ? tabIndexProp : tabIndexProp || 0\n const trulyDisabled = disabled && !focusable\n\n const refCb = (node: any) => {\n if (!node) return\n\n if (node.tagName !== \"BUTTON\") setButton(false)\n }\n\n const onClick = useCallback(\n (ev: MouseEvent<Y>) => {\n if (disabled) {\n ev.stopPropagation()\n ev.preventDefault()\n\n return\n }\n\n if (focusOnClick) ev.currentTarget.focus()\n onClickProp?.(ev)\n },\n [disabled, focusOnClick, onClickProp],\n )\n\n const onDocumentKeyUp = useCallback(\n (ev: globalThis.KeyboardEvent) => {\n if (pressed && isValidElement(ev)) {\n ev.preventDefault()\n ev.stopPropagation()\n\n setPressed(false)\n\n listeners.remove(document, \"keyup\", onDocumentKeyUp, false)\n }\n },\n [pressed, listeners],\n )\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<Y>) => {\n onKeyDownProp?.(ev)\n\n if (disabled || ev.defaultPrevented || ev.metaKey) return\n\n if (!isValidElement(ev.nativeEvent) || button) return\n\n if (clickOnSpace && ev.key === \" \") {\n ev.preventDefault()\n setPressed(true)\n }\n\n if (clickOnEnter && ev.key === \"Enter\") {\n ev.preventDefault()\n ev.currentTarget.click()\n }\n\n listeners.add(document, \"keyup\", onDocumentKeyUp, false)\n },\n [\n disabled,\n button,\n onKeyDownProp,\n clickOnEnter,\n clickOnSpace,\n listeners,\n onDocumentKeyUp,\n ],\n )\n\n const onKeyUp = useCallback(\n (ev: KeyboardEvent<Y>) => {\n onKeyUpProp?.(ev)\n\n if (disabled || ev.defaultPrevented || ev.metaKey) return\n\n if (!isValidElement(ev.nativeEvent) || button) return\n\n if (clickOnSpace && ev.key === \" \") {\n ev.preventDefault()\n setPressed(false)\n\n ev.currentTarget.click()\n }\n },\n [clickOnSpace, button, disabled, onKeyUpProp],\n )\n\n const onDocumentMouseUp = useCallback(\n (ev: globalThis.MouseEvent) => {\n if (ev.button !== 0) return\n\n setPressed(false)\n\n listeners.remove(document, \"mouseup\", onDocumentMouseUp, false)\n },\n [listeners],\n )\n\n const onMouseDown = useCallback(\n (ev: MouseEvent<Y>) => {\n if (ev.button !== 0) return\n\n if (disabled) {\n ev.stopPropagation()\n ev.preventDefault()\n\n return\n }\n\n if (!button) setPressed(true)\n\n if (focusOnClick) ev.currentTarget.focus({ preventScroll: true })\n\n listeners.add(document, \"mouseup\", onDocumentMouseUp, false)\n\n onMouseDownProp?.(ev)\n },\n [\n disabled,\n button,\n onMouseDownProp,\n listeners,\n onDocumentMouseUp,\n focusOnClick,\n ],\n )\n\n const onMouseUp = useCallback(\n (ev: MouseEvent<Y>) => {\n if (ev.button !== 0) return\n\n if (!button) setPressed(false)\n\n onMouseUpProp?.(ev)\n },\n [onMouseUpProp, button],\n )\n\n const onMouseOver = useCallback(\n (ev: MouseEvent<Y>) => {\n if (disabled) {\n ev.preventDefault()\n\n return\n }\n\n if (disableTouchBehavior && isTouchDevice()) return\n\n onMouseOverProp?.(ev)\n },\n [disabled, onMouseOverProp, disableTouchBehavior],\n )\n\n const onMouseLeave = useCallback(\n (ev: MouseEvent<Y>) => {\n if (pressed) {\n ev.preventDefault()\n\n setPressed(false)\n }\n\n if (disableTouchBehavior && isTouchDevice()) return\n\n onMouseLeaveProp?.(ev)\n },\n [pressed, onMouseLeaveProp, disableTouchBehavior],\n )\n\n if (button)\n return {\n ...props,\n ref: mergeRefs(ref, refCb),\n type: \"button\" as const,\n \"aria-disabled\": trulyDisabled ? undefined : disabled,\n disabled: trulyDisabled,\n onClick: onClick,\n onKeyDown: onKeyDownProp,\n onKeyUp: onKeyUpProp,\n onMouseDown: onMouseDownProp,\n onMouseLeave: onMouseLeaveProp,\n onMouseOver: onMouseOverProp,\n onMouseUp: onMouseUpProp,\n }\n else\n return {\n ...props,\n ref: mergeRefs(ref, refCb),\n \"aria-disabled\": disabled ? (\"true\" as const) : undefined,\n \"data-active\": dataAttr(pressed),\n role: \"button\",\n tabIndex: trulyDisabled ? undefined : tabIndex,\n onClick,\n onKeyDown,\n onKeyUp,\n onMouseDown,\n onMouseLeave,\n onMouseOver,\n onMouseUp,\n }\n}\n\nexport type UseClickableReturn = ReturnType<typeof useClickable>\n"],"mappings":";;;;;;;AA0DA,MAAM,kBACJ,OACY;CACZ,MAAM,EAAE,mBAAmB,YAAY,GAAG;CAE1C,OAAO,YAAY,WAAW,YAAY,cAAc,CAAC;AAC3D;AAEA,MAAa,gBAIX,EACE,KACA,eAAe,MACf,eAAe,MACf,UACA,uBAAuB,MACvB,WACA,eAAe,MACf,UAAU,cACV,SAAS,aACT,WAAW,eACX,SAAS,aACT,aAAa,iBACb,cAAc,kBACd,aAAa,iBACb,WAAW,eACX,GAAG,UACwB,CAAC,MAC3B;CACH,MAAM,CAAC,QAAQ,cAAA,GAAaA,MAA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AA,GAAeA,MAAAA,YAAAA,EAClB,OAAsB;EACrB,IAAI,SAAS;GACX,GAAG,eAAe;GAElB,WAAW,KAAK;EAClB;EAEA,IAAI,yBAAA,GAAA,oBAAA,cAAwB,cAAA,CAAc,GAAG;EAE7C,mBAAmB,EAAE;CACvB,GACA;EAAC;EAAS;EAAkB;CAAoB,CAClD;CAEA,IAAI,QACF,OAAO;EACL,GAAG;EACH,KAAKC,YAAAA,UAAU,KAAK,KAAK;EACzB,MAAM;EACN,iBAAiB,gBAAgB,KAAA,IAAY;EAC7C,UAAU;EACD;EACT,WAAW;EACX,SAAS;EACT,aAAa;EACb,cAAc;EACd,aAAa;EACb,WAAW;CACb;MAEA,OAAO;EACL,GAAG;EACH,KAAKA,YAAAA,UAAU,KAAK,KAAK;EACzB,iBAAiB,WAAY,SAAmB,KAAA;EAChD,gBAAA,GAAA,oBAAA,cAAe,SAAA,CAAS,OAAO;EAC/B,MAAM;EACN,UAAU,gBAAgB,KAAA,IAAY;EACtC;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["useEnvironment","useCallbackRef","useRef","useCallback","mergeRefs"],"sources":["../../../../src/hooks/use-pan-event/index.ts"],"sourcesContent":["\"use client\"\n\nimport type {\n DataAttributes,\n HTMLAttributes,\n RefAttributes,\n RefObject,\n} from \"react\"\nimport type { Point } from \"../../utils\"\nimport { useCallback, useRef } from \"react\"\nimport { useEnvironment } from \"../../core\"\nimport {\n addDomEvent,\n getEventPoint,\n handlerAll,\n isMultiTouchEvent,\n mergeRefs,\n useCallbackRef,\n useUnmountEffect,\n} from \"../../utils\"\n\nexport interface
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["useEnvironment","useCallbackRef","useRef","useCallback","mergeRefs"],"sources":["../../../../src/hooks/use-pan-event/index.ts"],"sourcesContent":["\"use client\"\n\nimport type {\n DataAttributes,\n HTMLAttributes,\n RefAttributes,\n RefObject,\n} from \"react\"\nimport type { Point } from \"../../utils\"\nimport { useCallback, useRef } from \"react\"\nimport { useEnvironment } from \"../../core\"\nimport {\n addDomEvent,\n getEventPoint,\n handlerAll,\n isMultiTouchEvent,\n mergeRefs,\n useCallbackRef,\n useUnmountEffect,\n} from \"../../utils\"\n\nexport interface UsePanEventProps {\n threshold?: number\n onEnd?: (ev: PointerEvent, point: Point, rect: DOMRect) => void\n onMove?: (ev: PointerEvent, point: Point, rect: DOMRect) => void\n onStart?: (ev: PointerEvent, point: Point, rect: DOMRect) => void\n}\n\nexport interface UsePanEventElementProps<Y extends HTMLElement>\n extends DataAttributes, HTMLAttributes<Y>, RefAttributes<Y> {}\n\nexport const usePanEvent = <Y extends HTMLElement>({\n threshold = 3,\n ...rest\n}: UsePanEventProps = {}): [\n RefObject<null | Y>,\n (props?: UsePanEventElementProps<Y>) => UsePanEventElementProps<Y>,\n] => {\n const { getWindow } = useEnvironment()\n const onStart = useCallbackRef(rest.onStart)\n const onMove = useCallbackRef(rest.onMove)\n const onEnd = useCallbackRef(rest.onEnd)\n const latestPoint = useRef<null | Point>(null)\n const unsubscribe = useRef<(() => void)[]>([])\n const ref = useRef<Y>(null)\n\n const cleanup = useCallback(() => {\n unsubscribe.current.forEach((unsubscribe) => unsubscribe())\n\n latestPoint.current = null\n unsubscribe.current = []\n }, [])\n\n const shouldMove = useCallback(\n (point: Point) => {\n if (threshold === 0) return true\n if (!latestPoint.current) return true\n\n const distance = Math.sqrt(\n Math.pow(point.x - latestPoint.current.x, 2) +\n Math.pow(point.y - latestPoint.current.y, 2),\n )\n\n return distance >= threshold\n },\n [threshold],\n )\n\n useUnmountEffect(() => {\n cleanup()\n })\n\n const getProps = useCallback(\n (props: UsePanEventElementProps<Y> = {}) => {\n return {\n ...props,\n ref: mergeRefs(ref, props.ref),\n onPointerDown: handlerAll(props.onPointerDown, (ev) => {\n const win = ev.nativeEvent.view ?? getWindow()\n\n if (!win) return\n if (isMultiTouchEvent(ev.nativeEvent)) return\n if (!ref.current) return\n\n ev.preventDefault()\n\n const point = getEventPoint(ev.nativeEvent)\n const rect = ref.current.getBoundingClientRect()\n\n onStart(ev.nativeEvent, point, rect)\n\n latestPoint.current = point\n\n unsubscribe.current.push(\n addDomEvent(win, \"pointermove\", (ev) => {\n if (!ref.current) return\n\n const point = getEventPoint(ev)\n const rect = ref.current.getBoundingClientRect()\n\n if (!shouldMove(point)) return\n\n latestPoint.current = point\n\n onMove(ev, point, rect)\n }),\n )\n\n unsubscribe.current.push(\n addDomEvent(win, \"pointerup\", (ev) => {\n if (!ref.current) return\n\n cleanup()\n\n const point = getEventPoint(ev)\n const rect = ref.current.getBoundingClientRect()\n\n onEnd(ev, point, rect)\n }),\n )\n\n unsubscribe.current.push(\n addDomEvent(win, \"pointercancel\", (ev) => {\n if (!ref.current) return\n\n cleanup()\n\n const point = getEventPoint(ev)\n const rect = ref.current.getBoundingClientRect()\n\n onEnd(ev, point, rect)\n }),\n )\n }),\n }\n },\n [cleanup, getWindow, onEnd, onMove, onStart, shouldMove],\n )\n\n return [ref, getProps] as const\n}\n\nexport type UsePanEventReturn = ReturnType<typeof usePanEvent>\n"],"mappings":";;;;;;;;AA+BA,MAAa,eAAsC,EACjD,YAAY,GACZ,GAAG,SACiB,CAAC,MAGlB;CACH,MAAM,EAAE,cAAcA,6BAAAA,eAAe;CACrC,MAAM,UAAUC,YAAAA,eAAe,KAAK,OAAO;CAC3C,MAAM,SAASA,YAAAA,eAAe,KAAK,MAAM;CACzC,MAAM,QAAQA,YAAAA,eAAe,KAAK,KAAK;CACvC,MAAM,eAAA,GAAcC,MAAAA,OAAAA,CAAqB,IAAI;CAC7C,MAAM,eAAA,GAAcA,MAAAA,OAAAA,CAAuB,CAAC,CAAC;CAC7C,MAAM,OAAA,GAAMA,MAAAA,OAAAA,CAAU,IAAI;CAE1B,MAAM,WAAA,GAAUC,MAAAA,YAAAA,OAAkB;EAChC,YAAY,QAAQ,SAAS,gBAAgB,YAAY,CAAC;EAE1D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I;IACxB,CAAC,CACH;IAEA,YAAY,QAAQ,MAAA,GAAA,oBAAA,cAClB,YAAA,CAAY,KAAK,cAAc,OAAO;KACpC,IAAI,CAAC,IAAI,SAAS;KAElB,QAAQ;KAER,MAAM,SAAA,GAAA,oBAAA,cAAQ,cAAA,CAAc,EAAE;KAC9B,MAAM,OAAO,IAAI,QAAQ,sBAAsB;KAE/C,MAAM,IAAI,OAAO,IAAI;IACvB,CAAC,CACH;IAEA,YAAY,QAAQ,MAAA,GAAA,oBAAA,cAClB,YAAA,CAAY,KAAK,kBAAkB,OAAO;KACxC,IAAI,CAAC,IAAI,SAAS;KAElB,QAAQ;KAER,MAAM,SAAA,GAAA,oBAAA,cAAQ,cAAA,CAAc,EAAE;KAC9B,MAAM,OAAO,IAAI,QAAQ,sBAAsB;KAE/C,MAAM,IAAI,OAAO,IAAI;IACvB,CAAC,CACH;GACF,CAAC;EACH;CACF,GACA;EAAC;EAAS;EAAW;EAAO;EAAQ;EAAS;CAAU,CAGrC,CAAC;AACvB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-group.js","names":["isUndefined","isNull","dataAttr"],"sources":["../../../../src/components/group/use-group.ts"],"sourcesContent":["import type { CSSProperties, DataAttributes, ReactNode } from \"react\"\nimport { cloneElement, useMemo } from \"react\"\nimport { dataAttr, isNull, isUndefined, useValidChildren } from \"../../utils\"\n\nexport const useGroup = (children?: ReactNode) => {\n const validChildren = useValidChildren(children)\n const omittedChildren = useMemo(\n () =>\n validChildren.filter((child) => {\n const ungrouped = child.props[\"data-ungrouped\"]\n\n return isUndefined(ungrouped) || isNull(ungrouped)\n }),\n [validChildren],\n )\n const count = omittedChildren.length\n const cloneChildren = useMemo(\n () =>\n validChildren.map((child) => {\n const index = omittedChildren.indexOf(child)\n const ungrouped = index === -1\n\n if (ungrouped) return child\n\n return cloneElement(child, {\n ...child.props,\n style: {\n \"--group-count\": count,\n \"--group-index\": index,\n ...child.props?.style,\n },\n \"data-group-between\": dataAttr(index > 0 && index < count - 1),\n \"data-group-end\": dataAttr(index === count - 1),\n \"data-group-start\": dataAttr(index === 0),\n \"data-peer\": \"\",\n })\n }),\n [validChildren, omittedChildren, count],\n )\n\n return cloneChildren\n}\n\nexport type UseGroupReturn = ReturnType<typeof useGroup>\n\
|
|
1
|
+
{"version":3,"file":"use-group.js","names":["isUndefined","isNull","dataAttr"],"sources":["../../../../src/components/group/use-group.ts"],"sourcesContent":["import type { CSSProperties, DataAttributes, ReactNode } from \"react\"\nimport { cloneElement, useMemo } from \"react\"\nimport { dataAttr, isNull, isUndefined, useValidChildren } from \"../../utils\"\n\nexport const useGroup = (children?: ReactNode) => {\n const validChildren = useValidChildren(children)\n const omittedChildren = useMemo(\n () =>\n validChildren.filter((child) => {\n const ungrouped = child.props[\"data-ungrouped\"]\n\n return isUndefined(ungrouped) || isNull(ungrouped)\n }),\n [validChildren],\n )\n const count = omittedChildren.length\n const cloneChildren = useMemo(\n () =>\n validChildren.map((child) => {\n const index = omittedChildren.indexOf(child)\n const ungrouped = index === -1\n\n if (ungrouped) return child\n\n return cloneElement(child, {\n ...child.props,\n style: {\n \"--group-count\": count,\n \"--group-index\": index,\n ...child.props?.style,\n },\n \"data-group-between\": dataAttr(index > 0 && index < count - 1),\n \"data-group-end\": dataAttr(index === count - 1),\n \"data-group-start\": dataAttr(index === 0),\n \"data-peer\": \"\",\n })\n }),\n [validChildren, omittedChildren, count],\n )\n\n return cloneChildren\n}\n\nexport type UseGroupReturn = ReturnType<typeof useGroup>\n\nexport interface UseGroupItemProps extends DataAttributes {\n style?: CSSProperties\n}\n\nexport const useGroupItemProps = <Y extends UseGroupItemProps>({\n style: {\n \"--group-count\": groupCount,\n \"--group-index\": groupIndex,\n ...style\n } = {},\n \"data-group-between\": dataGroupBetween,\n \"data-group-end\": dataGroupEnd,\n \"data-group-start\": dataGroupStart,\n \"data-peer\": dataPeer,\n ...rest\n}: Y) => {\n const pickedProps = useMemo(\n () => ({\n style: {\n \"--group-count\": groupCount!,\n \"--group-index\": groupIndex!,\n },\n \"data-group-between\": dataGroupBetween,\n \"data-group-end\": dataGroupEnd,\n \"data-group-start\": dataGroupStart,\n \"data-peer\": dataPeer,\n }),\n [\n groupCount,\n groupIndex,\n dataGroupBetween,\n dataGroupEnd,\n dataGroupStart,\n dataPeer,\n ],\n )\n const omittedProps = useMemo(() => ({ style, ...rest }), [style, rest])\n\n return [pickedProps, omittedProps] as const\n}\n\nexport type UseGroupItemReturn = ReturnType<typeof useGroupItemProps>\n"],"mappings":";;;;AAIA,MAAa,YAAY,aAAyB;CAChD,MAAM,gBAAgB,iBAAiB,QAAQ;CAC/C,MAAM,kBAAkB,cAEpB,cAAc,QAAQ,UAAU;EAC9B,MAAM,YAAY,MAAM,MAAM;EAE9B,QAAA,GAAOA,cAAAA,YAAAA,CAAY,SAAS,MAAA,GAAKC,cAAAA,OAAAA,CAAO,SAAS;CACnD,CAAC,GACH,CAAC,aAAa,CAChB;CACA,MAAM,QAAQ,gBAAgB;CAyB9B,OAxBsB,cAElB,cAAc,KAAK,UAAU;EAC3B,MAAM,QAAQ,gBAAgB,QAAQ,KAAK;EAG3C,IAFkB,UAAU,IAEb,OAAO;EAEtB,OAAO,aAAa,OAAO;GACzB,GAAG,MAAM;GACT,OAAO;IACL,iBAAiB;IACjB,iBAAiB;IACjB,GAAG,MAAM,OAAO;GAClB;GACA,uBAAA,GAAsBC,cAAAA,SAAAA,CAAS,QAAQ,KAAK,QAAQ,QAAQ,CAAC;GAC7D,mBAAA,GAAkBA,cAAAA,SAAAA,CAAS,UAAU,QAAQ,CAAC;GAC9C,qBAAA,GAAoBA,cAAAA,SAAAA,CAAS,UAAU,CAAC;GACxC,aAAa;EACf,CAAC;CACH,CAAC,GACH;EAAC;EAAe;EAAiB;CAAK,CAGrB;AACrB;AAQA,MAAa,qBAAkD,EAC7D,OAAO,EACL,iBAAiB,YACjB,iBAAiB,YACjB,GAAG,UACD,CAAC,GACL,sBAAsB,kBACtB,kBAAkB,cAClB,oBAAoB,gBACpB,aAAa,UACb,GAAG,WACI;CAuBP,OAAO,CAtBa,eACX;EACL,OAAO;GACL,iBAAiB;GACjB,iBAAiB;EACnB;EACA,sBAAsB;EACtB,kBAAkB;EAClB,oBAAoB;EACpB,aAAa;CACf,IACA;EACE;EACA;EACA;EACA;EACA;EACA;CACF,CAIgB,GAFG,eAAe;EAAE;EAAO,GAAG;CAAK,IAAI,CAAC,OAAO,IAAI,CAErC,CAAC;AACnC"}
|
|
@@ -10,13 +10,13 @@ import { useCallback, useRef, useState } from "react";
|
|
|
10
10
|
*
|
|
11
11
|
* @see https://yamada-ui.com/docs/hooks/use-animation
|
|
12
12
|
*/
|
|
13
|
-
const useAnimation = (
|
|
13
|
+
const useAnimation = (arrayOrObj) => {
|
|
14
14
|
const system = useSystem();
|
|
15
|
-
if ((0, utils_exports.isArray)(
|
|
15
|
+
if ((0, utils_exports.isArray)(arrayOrObj)) return arrayOrObj.map((obj) => animation(obj, {
|
|
16
16
|
css,
|
|
17
17
|
system
|
|
18
18
|
})).join(", ");
|
|
19
|
-
else return animation(
|
|
19
|
+
else return animation(arrayOrObj, {
|
|
20
20
|
css,
|
|
21
21
|
system
|
|
22
22
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["isArray","isUndefined","runIfFn"],"sources":["../../../../src/hooks/use-animation/index.ts"],"sourcesContent":["\"use client\"\n\nimport type { CSSAnimationObject, Token } from \"../../core\"\nimport { useCallback, useRef, useState } from \"react\"\nimport { animation, css, useSystem } from \"../../core\"\nimport { isArray, isUndefined, runIfFn } from \"../../utils\"\n\
|
|
1
|
+
{"version":3,"file":"index.js","names":["isArray","isUndefined","runIfFn"],"sources":["../../../../src/hooks/use-animation/index.ts"],"sourcesContent":["\"use client\"\n\nimport type { CSSAnimationObject, Token } from \"../../core\"\nimport { useCallback, useRef, useState } from \"react\"\nimport { animation, css, useSystem } from \"../../core\"\nimport { isArray, isUndefined, runIfFn } from \"../../utils\"\n\nexport type UseAnimationProps =\n | Token<CSSAnimationObject, \"animations\">\n | Token<CSSAnimationObject, \"animations\">[]\n\n/**\n * `useAnimation` is a custom hook that implements animations similar to CSS `keyframes`.\n *\n * @see https://yamada-ui.com/docs/hooks/use-animation\n */\nexport const useAnimation = (arrayOrObj: UseAnimationProps): string => {\n const system = useSystem()\n\n if (isArray(arrayOrObj))\n return arrayOrObj.map((obj) => animation(obj, { css, system })).join(\", \")\n else return animation(arrayOrObj, { css, system })\n}\n\nexport type UseDynamicAnimationProps =\n | Token<CSSAnimationObject, \"animations\">[]\n | { [key: string]: UseAnimationProps }\n\n/**\n * `useDynamicAnimation` is a custom hook used to switch animations.\n *\n * @see https://yamada-ui.com/docs/hooks/use-dynamic-animation\n */\nexport const useDynamicAnimation = <Y extends UseDynamicAnimationProps>(\n arrayOrObj: Y,\n init?: (keyof Y)[] | keyof Y,\n): [\n string | undefined,\n (\n key:\n | ((key: (keyof Y)[] | keyof Y | undefined) => (keyof Y)[] | keyof Y)\n | (keyof Y)[]\n | keyof Y,\n ) => void,\n] => {\n const system = useSystem()\n\n const keys = useRef<string | string[] | undefined>(\n !isUndefined(init)\n ? isArray(init)\n ? init.map(String)\n : String(init)\n : undefined,\n )\n const cache = useRef<Map<string, string>>(new Map<string, string>())\n\n const [animations, setAnimations] = useState<string | undefined>(() => {\n for (const [key, styles] of Object.entries(arrayOrObj))\n if (isArray(styles))\n cache.current.set(\n key,\n styles.map((style) => animation(style, { css, system })).join(\", \"),\n )\n else cache.current.set(key, animation(styles, { css, system }))\n\n if (isArray(keys.current))\n return keys.current.map((key) => cache.current.get(key)).join(\", \")\n else return cache.current.get(keys.current ?? \"\")\n })\n\n const setAnimation = useCallback(\n (\n keysOrFunc:\n | ((key: (keyof Y)[] | keyof Y | undefined) => (keyof Y)[] | keyof Y)\n | (keyof Y)[]\n | keyof Y,\n ) => {\n const args = (() => {\n if (!isUndefined(keys.current) && isArray(arrayOrObj))\n return isArray(keys.current)\n ? keys.current.map(Number)\n : Number(keys.current)\n else return keys.current\n })() as (keyof Y)[] | keyof Y | undefined\n\n const keyOrArray = runIfFn(keysOrFunc, args)\n\n keys.current = isArray(keyOrArray)\n ? keyOrArray.map(String)\n : String(keyOrArray)\n\n if (isArray(keys.current))\n setAnimations(\n keys.current.map((key) => cache.current.get(key)).join(\", \"),\n )\n else setAnimations(cache.current.get(keys.current))\n },\n [arrayOrObj],\n )\n\n return [animations, setAnimation]\n}\n"],"mappings":";;;;;;;;;;;;AAgBA,MAAa,gBAAgB,eAA0C;CACrE,MAAM,SAAS,UAAU;CAEzB,KAAA,GAAIA,cAAAA,QAAAA,CAAQ,UAAU,GACpB,OAAO,WAAW,KAAK,QAAQ,UAAU,KAAK;EAAE;EAAK;CAAO,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI;MACtE,OAAO,UAAU,YAAY;EAAE;EAAK;CAAO,CAAC;AACnD;;;;;;AAWA,MAAa,uBACX,YACA,SASG;CACH,MAAM,SAAS,UAAU;CAEzB,MAAM,OAAO,OACX,EAAA,GAACC,cAAAA,YAAAA,CAAY,IAAI,KAAA,GACbD,cAAAA,QAAAA,CAAQ,IAAI,IACV,KAAK,IAAI,MAAM,IACf,OAAO,IAAI,IACb,KAAA,CACN;CACA,MAAM,QAAQ,uBAA4B,IAAI,IAAoB,CAAC;CAEnE,MAAM,CAAC,YAAY,iBAAiB,eAAmC;EACrE,KAAK,MAAM,CAAC,KAAK,WAAW,OAAO,QAAQ,UAAU,GACnD,KAAA,GAAIA,cAAAA,QAAAA,CAAQ,MAAM,GAChB,MAAM,QAAQ,IACZ,KACA,OAAO,KAAK,UAAU,UAAU,OAAO;GAAE;GAAK;EAAO,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CACpE;OACG,MAAM,QAAQ,IAAI,KAAK,UAAU,QAAQ;GAAE;GAAK;EAAO,CAAC,CAAC;EAEhE,KAAA,GAAIA,cAAAA,QAAAA,CAAQ,KAAK,OAAO,GACtB,OAAO,KAAK,QAAQ,KAAK,QAAQ,MAAM,QAAQ,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,IAAI;OAC/D,OAAO,MAAM,QAAQ,IAAI,KAAK,WAAW,EAAE;CAClD,CAAC;CAgCD,OAAO,CAAC,YA9Ba,aAEjB,eAIG;EACH,MAAM,cAAc;GAClB,IAAI,EAAA,GAACC,cAAAA,YAAAA,CAAY,KAAK,OAAO,MAAA,GAAKD,cAAAA,QAAAA,CAAQ,UAAU,GAClD,QAAA,GAAOA,cAAAA,QAAAA,CAAQ,KAAK,OAAO,IACvB,KAAK,QAAQ,IAAI,MAAM,IACvB,OAAO,KAAK,OAAO;QACpB,OAAO,KAAK;EACnB,EAAA,CAAG;EAEH,MAAM,cAAA,GAAaE,cAAAA,QAAAA,CAAQ,YAAY,IAAI;EAE3C,KAAK,WAAA,GAAUF,cAAAA,QAAAA,CAAQ,UAAU,IAC7B,WAAW,IAAI,MAAM,IACrB,OAAO,UAAU;EAErB,KAAA,GAAIA,cAAAA,QAAAA,CAAQ,KAAK,OAAO,GACtB,cACE,KAAK,QAAQ,KAAK,QAAQ,MAAM,QAAQ,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,IAAI,CAC7D;OACG,cAAc,MAAM,QAAQ,IAAI,KAAK,OAAO,CAAC;CACpD,GACA,CAAC,UAAU,CAGkB,CAAC;AAClC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["isValidElement","isTouchDevice","dataAttr"],"sources":["../../../../src/hooks/use-clickable/index.ts"],"sourcesContent":["\"use client\"\n\nimport type { HTMLAttributes, KeyboardEvent, MouseEvent, Ref } from \"react\"\nimport type { StyledProps } from \"../../core\"\nimport { useCallback, useState } from \"react\"\nimport { dataAttr, isTouchDevice, mergeRefs } from \"../../utils\"\nimport { useEventListeners } from \"../use-event-listener\"\n\ntype Props<Y extends HTMLElement = HTMLElement> = Omit<\n HTMLAttributes<Y>,\n \"ref\" | \"size\" | keyof StyledProps\n>\n\nexport type UseClickableProps<\n Y extends HTMLElement = HTMLElement,\n M extends Props<Y> = Props<Y>,\n> = M & {\n /**\n * Whether or not trigger click on pressing `Enter`.\n *\n * @default true\n */\n clickOnEnter?: boolean\n /**\n * Whether or not trigger click on pressing `Space`.\n *\n * @default true\n */\n clickOnSpace?: boolean\n /**\n * If `true`, the element will be disabled. It will set the `disabled` HTML attribute.\n *\n * @default false\n */\n disabled?: boolean\n /**\n * Disable the touch device behavior.\n *\n * @default true\n */\n disableTouchBehavior?: boolean\n /**\n * If `true` and isDisabled, the element will have only `aria-disabled` set to `true`.\n *\n * @default false\n */\n focusable?: boolean\n /**\n * Whether or not to focus the element when it is clicked.\n * If `true`, the element will receive focus upon click.\n *\n * @default true\n */\n focusOnClick?: boolean\n /**\n * The ref for the element.\n */\n ref?: Ref<Y>\n}\n\nconst isValidElement = (\n ev: KeyboardEvent | KeyboardEvent[\"nativeEvent\"],\n): boolean => {\n const { isContentEditable, tagName } = ev.target as HTMLElement\n\n return tagName !== \"INPUT\" && tagName !== \"TEXTAREA\" && !isContentEditable\n}\n\nexport const useClickable = <\n Y extends HTMLElement = HTMLElement,\n M extends Props<Y> = Props<Y>,\n>(\n {\n ref,\n clickOnEnter = true,\n clickOnSpace = true,\n disabled,\n disableTouchBehavior = true,\n focusable,\n focusOnClick = true,\n tabIndex: tabIndexProp,\n onClick: onClickProp,\n onKeyDown: onKeyDownProp,\n onKeyUp: onKeyUpProp,\n onMouseDown: onMouseDownProp,\n onMouseLeave: onMouseLeaveProp,\n onMouseOver: onMouseOverProp,\n onMouseUp: onMouseUpProp,\n ...props\n }: UseClickableProps<Y, M> = {} as UseClickableProps<Y, M>,\n) => {\n const [button, setButton] = useState<boolean>(true)\n const [pressed, setPressed] = useState<boolean>(false)\n\n const listeners = useEventListeners()\n\n const tabIndex = button ? tabIndexProp : tabIndexProp || 0\n const trulyDisabled = disabled && !focusable\n\n const refCb = (node: any) => {\n if (!node) return\n\n if (node.tagName !== \"BUTTON\") setButton(false)\n }\n\n const onClick = useCallback(\n (ev: MouseEvent<Y>) => {\n if (disabled) {\n ev.stopPropagation()\n ev.preventDefault()\n\n return\n }\n\n if (focusOnClick) ev.currentTarget.focus()\n onClickProp?.(ev)\n },\n [disabled, focusOnClick, onClickProp],\n )\n\n const onDocumentKeyUp = useCallback(\n (ev: globalThis.KeyboardEvent) => {\n if (pressed && isValidElement(ev)) {\n ev.preventDefault()\n ev.stopPropagation()\n\n setPressed(false)\n\n listeners.remove(document, \"keyup\", onDocumentKeyUp, false)\n }\n },\n [pressed, listeners],\n )\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<Y>) => {\n onKeyDownProp?.(ev)\n\n if (disabled || ev.defaultPrevented || ev.metaKey) return\n\n if (!isValidElement(ev.nativeEvent) || button) return\n\n if (clickOnSpace && ev.key === \" \") {\n ev.preventDefault()\n setPressed(true)\n }\n\n if (clickOnEnter && ev.key === \"Enter\") {\n ev.preventDefault()\n ev.currentTarget.click()\n }\n\n listeners.add(document, \"keyup\", onDocumentKeyUp, false)\n },\n [\n disabled,\n button,\n onKeyDownProp,\n clickOnEnter,\n clickOnSpace,\n listeners,\n onDocumentKeyUp,\n ],\n )\n\n const onKeyUp = useCallback(\n (ev: KeyboardEvent<Y>) => {\n onKeyUpProp?.(ev)\n\n if (disabled || ev.defaultPrevented || ev.metaKey) return\n\n if (!isValidElement(ev.nativeEvent) || button) return\n\n if (clickOnSpace && ev.key === \" \") {\n ev.preventDefault()\n setPressed(false)\n\n ev.currentTarget.click()\n }\n },\n [clickOnSpace, button, disabled, onKeyUpProp],\n )\n\n const onDocumentMouseUp = useCallback(\n (ev: globalThis.MouseEvent) => {\n if (ev.button !== 0) return\n\n setPressed(false)\n\n listeners.remove(document, \"mouseup\", onDocumentMouseUp, false)\n },\n [listeners],\n )\n\n const onMouseDown = useCallback(\n (ev: MouseEvent<Y>) => {\n if (ev.button !== 0) return\n\n if (disabled) {\n ev.stopPropagation()\n ev.preventDefault()\n\n return\n }\n\n if (!button) setPressed(true)\n\n if (focusOnClick) ev.currentTarget.focus({ preventScroll: true })\n\n listeners.add(document, \"mouseup\", onDocumentMouseUp, false)\n\n onMouseDownProp?.(ev)\n },\n [\n disabled,\n button,\n onMouseDownProp,\n listeners,\n onDocumentMouseUp,\n focusOnClick,\n ],\n )\n\n const onMouseUp = useCallback(\n (ev: MouseEvent<Y>) => {\n if (ev.button !== 0) return\n\n if (!button) setPressed(false)\n\n onMouseUpProp?.(ev)\n },\n [onMouseUpProp, button],\n )\n\n const onMouseOver = useCallback(\n (ev: MouseEvent<Y>) => {\n if (disabled) {\n ev.preventDefault()\n\n return\n }\n\n if (disableTouchBehavior && isTouchDevice()) return\n\n onMouseOverProp?.(ev)\n },\n [disabled, onMouseOverProp, disableTouchBehavior],\n )\n\n const onMouseLeave = useCallback(\n (ev: MouseEvent<Y>) => {\n if (pressed) {\n ev.preventDefault()\n\n setPressed(false)\n }\n\n if (disableTouchBehavior && isTouchDevice()) return\n\n onMouseLeaveProp?.(ev)\n },\n [pressed, onMouseLeaveProp, disableTouchBehavior],\n )\n\n if (button)\n return {\n ...props,\n ref: mergeRefs(ref, refCb),\n type: \"button\" as const,\n \"aria-disabled\": trulyDisabled ? undefined : disabled,\n disabled: trulyDisabled,\n onClick: onClick,\n onKeyDown: onKeyDownProp,\n onKeyUp: onKeyUpProp,\n onMouseDown: onMouseDownProp,\n onMouseLeave: onMouseLeaveProp,\n onMouseOver: onMouseOverProp,\n onMouseUp: onMouseUpProp,\n }\n else\n return {\n ...props,\n ref: mergeRefs(ref, refCb),\n \"aria-disabled\": disabled ? (\"true\" as const) : undefined,\n \"data-active\": dataAttr(pressed),\n role: \"button\",\n tabIndex: trulyDisabled ? undefined : tabIndex,\n onClick,\n onKeyDown,\n onKeyUp,\n onMouseDown,\n onMouseLeave,\n onMouseOver,\n onMouseUp,\n }\n}\n\nexport type UseClickableReturn = ReturnType<typeof useClickable>\n"],"mappings":";;;;;;AA4DA,MAAMA,oBACJ,OACY;CACZ,MAAM,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,CAAc,GAAG;EAE7C,kBAAkB,EAAE;CACtB,GACA;EAAC;EAAU;EAAiB;CAAoB,CAClD;CAEA,MAAM,eAAe,aAClB,OAAsB;EACrB,IAAI,SAAS;GACX,GAAG,eAAe;GAElB,WAAW,KAAK;EAClB;EAEA,IAAI,yBAAA,GAAwBA,cAAAA,cAAAA,CAAc,GAAG;EAE7C,mBAAmB,EAAE;CACvB,GACA;EAAC;EAAS;EAAkB;CAAoB,CAClD;CAEA,IAAI,QACF,OAAO;EACL,GAAG;EACH,KAAK,UAAU,KAAK,KAAK;EACzB,MAAM;EACN,iBAAiB,gBAAgB,KAAA,IAAY;EAC7C,UAAU;EACD;EACT,WAAW;EACX,SAAS;EACT,aAAa;EACb,cAAc;EACd,aAAa;EACb,WAAW;CACb;MAEA,OAAO;EACL,GAAG;EACH,KAAK,UAAU,KAAK,KAAK;EACzB,iBAAiB,WAAY,SAAmB,KAAA;EAChD,gBAAA,GAAeC,cAAAA,SAAAA,CAAS,OAAO;EAC/B,MAAM;EACN,UAAU,gBAAgB,KAAA,IAAY;EACtC;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACJ"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["isValidElement","isTouchDevice","dataAttr"],"sources":["../../../../src/hooks/use-clickable/index.ts"],"sourcesContent":["\"use client\"\n\nimport type { HTMLAttributes, KeyboardEvent, MouseEvent, Ref } from \"react\"\nimport type { StyledProps } from \"../../core\"\nimport { useCallback, useState } from \"react\"\nimport { dataAttr, isTouchDevice, mergeRefs } from \"../../utils\"\nimport { useEventListeners } from \"../use-event-listener\"\n\nexport type UseClickableElementProps<Y extends HTMLElement = HTMLElement> =\n Omit<HTMLAttributes<Y>, \"ref\" | \"size\" | keyof StyledProps>\n\nexport type UseClickableProps<\n Y extends HTMLElement = HTMLElement,\n M extends UseClickableElementProps<Y> = UseClickableElementProps<Y>,\n> = M & {\n /**\n * Whether or not trigger click on pressing `Enter`.\n *\n * @default true\n */\n clickOnEnter?: boolean\n /**\n * Whether or not trigger click on pressing `Space`.\n *\n * @default true\n */\n clickOnSpace?: boolean\n /**\n * If `true`, the element will be disabled. It will set the `disabled` HTML attribute.\n *\n * @default false\n */\n disabled?: boolean\n /**\n * Disable the touch device behavior.\n *\n * @default true\n */\n disableTouchBehavior?: boolean\n /**\n * If `true` and isDisabled, the element will have only `aria-disabled` set to `true`.\n *\n * @default false\n */\n focusable?: boolean\n /**\n * Whether or not to focus the element when it is clicked.\n * If `true`, the element will receive focus upon click.\n *\n * @default true\n */\n focusOnClick?: boolean\n /**\n * The ref for the element.\n */\n ref?: Ref<Y>\n}\n\nconst isValidElement = (\n ev: KeyboardEvent | KeyboardEvent[\"nativeEvent\"],\n): boolean => {\n const { isContentEditable, tagName } = ev.target as HTMLElement\n\n return tagName !== \"INPUT\" && tagName !== \"TEXTAREA\" && !isContentEditable\n}\n\nexport const useClickable = <\n Y extends HTMLElement = HTMLElement,\n M extends UseClickableElementProps<Y> = UseClickableElementProps<Y>,\n>(\n {\n ref,\n clickOnEnter = true,\n clickOnSpace = true,\n disabled,\n disableTouchBehavior = true,\n focusable,\n focusOnClick = true,\n tabIndex: tabIndexProp,\n onClick: onClickProp,\n onKeyDown: onKeyDownProp,\n onKeyUp: onKeyUpProp,\n onMouseDown: onMouseDownProp,\n onMouseLeave: onMouseLeaveProp,\n onMouseOver: onMouseOverProp,\n onMouseUp: onMouseUpProp,\n ...props\n }: UseClickableProps<Y, M> = {} as UseClickableProps<Y, M>,\n) => {\n const [button, setButton] = useState<boolean>(true)\n const [pressed, setPressed] = useState<boolean>(false)\n\n const listeners = useEventListeners()\n\n const tabIndex = button ? tabIndexProp : tabIndexProp || 0\n const trulyDisabled = disabled && !focusable\n\n const refCb = (node: any) => {\n if (!node) return\n\n if (node.tagName !== \"BUTTON\") setButton(false)\n }\n\n const onClick = useCallback(\n (ev: MouseEvent<Y>) => {\n if (disabled) {\n ev.stopPropagation()\n ev.preventDefault()\n\n return\n }\n\n if (focusOnClick) ev.currentTarget.focus()\n onClickProp?.(ev)\n },\n [disabled, focusOnClick, onClickProp],\n )\n\n const onDocumentKeyUp = useCallback(\n (ev: globalThis.KeyboardEvent) => {\n if (pressed && isValidElement(ev)) {\n ev.preventDefault()\n ev.stopPropagation()\n\n setPressed(false)\n\n listeners.remove(document, \"keyup\", onDocumentKeyUp, false)\n }\n },\n [pressed, listeners],\n )\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<Y>) => {\n onKeyDownProp?.(ev)\n\n if (disabled || ev.defaultPrevented || ev.metaKey) return\n\n if (!isValidElement(ev.nativeEvent) || button) return\n\n if (clickOnSpace && ev.key === \" \") {\n ev.preventDefault()\n setPressed(true)\n }\n\n if (clickOnEnter && ev.key === \"Enter\") {\n ev.preventDefault()\n ev.currentTarget.click()\n }\n\n listeners.add(document, \"keyup\", onDocumentKeyUp, false)\n },\n [\n disabled,\n button,\n onKeyDownProp,\n clickOnEnter,\n clickOnSpace,\n listeners,\n onDocumentKeyUp,\n ],\n )\n\n const onKeyUp = useCallback(\n (ev: KeyboardEvent<Y>) => {\n onKeyUpProp?.(ev)\n\n if (disabled || ev.defaultPrevented || ev.metaKey) return\n\n if (!isValidElement(ev.nativeEvent) || button) return\n\n if (clickOnSpace && ev.key === \" \") {\n ev.preventDefault()\n setPressed(false)\n\n ev.currentTarget.click()\n }\n },\n [clickOnSpace, button, disabled, onKeyUpProp],\n )\n\n const onDocumentMouseUp = useCallback(\n (ev: globalThis.MouseEvent) => {\n if (ev.button !== 0) return\n\n setPressed(false)\n\n listeners.remove(document, \"mouseup\", onDocumentMouseUp, false)\n },\n [listeners],\n )\n\n const onMouseDown = useCallback(\n (ev: MouseEvent<Y>) => {\n if (ev.button !== 0) return\n\n if (disabled) {\n ev.stopPropagation()\n ev.preventDefault()\n\n return\n }\n\n if (!button) setPressed(true)\n\n if (focusOnClick) ev.currentTarget.focus({ preventScroll: true })\n\n listeners.add(document, \"mouseup\", onDocumentMouseUp, false)\n\n onMouseDownProp?.(ev)\n },\n [\n disabled,\n button,\n onMouseDownProp,\n listeners,\n onDocumentMouseUp,\n focusOnClick,\n ],\n )\n\n const onMouseUp = useCallback(\n (ev: MouseEvent<Y>) => {\n if (ev.button !== 0) return\n\n if (!button) setPressed(false)\n\n onMouseUpProp?.(ev)\n },\n [onMouseUpProp, button],\n )\n\n const onMouseOver = useCallback(\n (ev: MouseEvent<Y>) => {\n if (disabled) {\n ev.preventDefault()\n\n return\n }\n\n if (disableTouchBehavior && isTouchDevice()) return\n\n onMouseOverProp?.(ev)\n },\n [disabled, onMouseOverProp, disableTouchBehavior],\n )\n\n const onMouseLeave = useCallback(\n (ev: MouseEvent<Y>) => {\n if (pressed) {\n ev.preventDefault()\n\n setPressed(false)\n }\n\n if (disableTouchBehavior && isTouchDevice()) return\n\n onMouseLeaveProp?.(ev)\n },\n [pressed, onMouseLeaveProp, disableTouchBehavior],\n )\n\n if (button)\n return {\n ...props,\n ref: mergeRefs(ref, refCb),\n type: \"button\" as const,\n \"aria-disabled\": trulyDisabled ? undefined : disabled,\n disabled: trulyDisabled,\n onClick: onClick,\n onKeyDown: onKeyDownProp,\n onKeyUp: onKeyUpProp,\n onMouseDown: onMouseDownProp,\n onMouseLeave: onMouseLeaveProp,\n onMouseOver: onMouseOverProp,\n onMouseUp: onMouseUpProp,\n }\n else\n return {\n ...props,\n ref: mergeRefs(ref, refCb),\n \"aria-disabled\": disabled ? (\"true\" as const) : undefined,\n \"data-active\": dataAttr(pressed),\n role: \"button\",\n tabIndex: trulyDisabled ? undefined : tabIndex,\n onClick,\n onKeyDown,\n onKeyUp,\n onMouseDown,\n onMouseLeave,\n onMouseOver,\n onMouseUp,\n }\n}\n\nexport type UseClickableReturn = ReturnType<typeof useClickable>\n"],"mappings":";;;;;;AA0DA,MAAMA,oBACJ,OACY;CACZ,MAAM,EAAE,mBAAmB,YAAY,GAAG;CAE1C,OAAO,YAAY,WAAW,YAAY,cAAc,CAAC;AAC3D;AAEA,MAAa,gBAIX,EACE,KACA,eA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;EACrB,IAAI,SAAS;GACX,GAAG,eAAe;GAElB,WAAW,KAAK;EAClB;EAEA,IAAI,yBAAA,GAAwBA,cAAAA,cAAAA,CAAc,GAAG;EAE7C,mBAAmB,EAAE;CACvB,GACA;EAAC;EAAS;EAAkB;CAAoB,CAClD;CAEA,IAAI,QACF,OAAO;EACL,GAAG;EACH,KAAK,UAAU,KAAK,KAAK;EACzB,MAAM;EACN,iBAAiB,gBAAgB,KAAA,IAAY;EAC7C,UAAU;EACD;EACT,WAAW;EACX,SAAS;EACT,aAAa;EACb,cAAc;EACd,aAAa;EACb,WAAW;CACb;MAEA,OAAO;EACL,GAAG;EACH,KAAK,UAAU,KAAK,KAAK;EACzB,iBAAiB,WAAY,SAAmB,KAAA;EAChD,gBAAA,GAAeC,cAAAA,SAAAA,CAAS,OAAO;EAC/B,MAAM;EACN,UAAU,gBAAgB,KAAA,IAAY;EACtC;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["handlerAll","isMultiTouchEvent","getEventPoint","addDomEvent"],"sources":["../../../../src/hooks/use-pan-event/index.ts"],"sourcesContent":["\"use client\"\n\nimport type {\n DataAttributes,\n HTMLAttributes,\n RefAttributes,\n RefObject,\n} from \"react\"\nimport type { Point } from \"../../utils\"\nimport { useCallback, useRef } from \"react\"\nimport { useEnvironment } from \"../../core\"\nimport {\n addDomEvent,\n getEventPoint,\n handlerAll,\n isMultiTouchEvent,\n mergeRefs,\n useCallbackRef,\n useUnmountEffect,\n} from \"../../utils\"\n\nexport interface
|
|
1
|
+
{"version":3,"file":"index.js","names":["handlerAll","isMultiTouchEvent","getEventPoint","addDomEvent"],"sources":["../../../../src/hooks/use-pan-event/index.ts"],"sourcesContent":["\"use client\"\n\nimport type {\n DataAttributes,\n HTMLAttributes,\n RefAttributes,\n RefObject,\n} from \"react\"\nimport type { Point } from \"../../utils\"\nimport { useCallback, useRef } from \"react\"\nimport { useEnvironment } from \"../../core\"\nimport {\n addDomEvent,\n getEventPoint,\n handlerAll,\n isMultiTouchEvent,\n mergeRefs,\n useCallbackRef,\n useUnmountEffect,\n} from \"../../utils\"\n\nexport interface UsePanEventProps {\n threshold?: number\n onEnd?: (ev: PointerEvent, point: Point, rect: DOMRect) => void\n onMove?: (ev: PointerEvent, point: Point, rect: DOMRect) => void\n onStart?: (ev: PointerEvent, point: Point, rect: DOMRect) => void\n}\n\nexport interface UsePanEventElementProps<Y extends HTMLElement>\n extends DataAttributes, HTMLAttributes<Y>, RefAttributes<Y> {}\n\nexport const usePanEvent = <Y extends HTMLElement>({\n threshold = 3,\n ...rest\n}: UsePanEventProps = {}): [\n RefObject<null | Y>,\n (props?: UsePanEventElementProps<Y>) => UsePanEventElementProps<Y>,\n] => {\n const { getWindow } = useEnvironment()\n const onStart = useCallbackRef(rest.onStart)\n const onMove = useCallbackRef(rest.onMove)\n const onEnd = useCallbackRef(rest.onEnd)\n const latestPoint = useRef<null | Point>(null)\n const unsubscribe = useRef<(() => void)[]>([])\n const ref = useRef<Y>(null)\n\n const cleanup = useCallback(() => {\n unsubscribe.current.forEach((unsubscribe) => unsubscribe())\n\n latestPoint.current = null\n unsubscribe.current = []\n }, [])\n\n const shouldMove = useCallback(\n (point: Point) => {\n if (threshold === 0) return true\n if (!latestPoint.current) return true\n\n const distance = Math.sqrt(\n Math.pow(point.x - latestPoint.current.x, 2) +\n Math.pow(point.y - latestPoint.current.y, 2),\n )\n\n return distance >= threshold\n },\n [threshold],\n )\n\n useUnmountEffect(() => {\n cleanup()\n })\n\n const getProps = useCallback(\n (props: UsePanEventElementProps<Y> = {}) => {\n return {\n ...props,\n ref: mergeRefs(ref, props.ref),\n onPointerDown: handlerAll(props.onPointerDown, (ev) => {\n const win = ev.nativeEvent.view ?? getWindow()\n\n if (!win) return\n if (isMultiTouchEvent(ev.nativeEvent)) return\n if (!ref.current) return\n\n ev.preventDefault()\n\n const point = getEventPoint(ev.nativeEvent)\n const rect = ref.current.getBoundingClientRect()\n\n onStart(ev.nativeEvent, point, rect)\n\n latestPoint.current = point\n\n unsubscribe.current.push(\n addDomEvent(win, \"pointermove\", (ev) => {\n if (!ref.current) return\n\n const point = getEventPoint(ev)\n const rect = ref.current.getBoundingClientRect()\n\n if (!shouldMove(point)) return\n\n latestPoint.current = point\n\n onMove(ev, point, rect)\n }),\n )\n\n unsubscribe.current.push(\n addDomEvent(win, \"pointerup\", (ev) => {\n if (!ref.current) return\n\n cleanup()\n\n const point = getEventPoint(ev)\n const rect = ref.current.getBoundingClientRect()\n\n onEnd(ev, point, rect)\n }),\n )\n\n unsubscribe.current.push(\n addDomEvent(win, \"pointercancel\", (ev) => {\n if (!ref.current) return\n\n cleanup()\n\n const point = getEventPoint(ev)\n const rect = ref.current.getBoundingClientRect()\n\n onEnd(ev, point, rect)\n }),\n )\n }),\n }\n },\n [cleanup, getWindow, onEnd, onMove, onStart, shouldMove],\n )\n\n return [ref, getProps] as const\n}\n\nexport type UsePanEventReturn = ReturnType<typeof usePanEvent>\n"],"mappings":";;;;;;;AA+BA,MAAa,eAAsC,EACjD,YAAY,GACZ,GAAG,SACiB,CAAC,MAGlB;CACH,MAAM,EAAE,cAAc,eAAe;CACrC,MAAM,UAAU,eAAe,KAAK,OAAO;CAC3C,MAAM,SAAS,eAAe,KAAK,MAAM;CACzC,MAAM,QAAQ,eAAe,KAAK,KAAK;CACvC,MAAM,cAAc,OAAqB,IAAI;CAC7C,MAAM,cAAc,OAAuB,CAAC,CAAC;CAC7C,MAAM,MAAM,OAAU,IAAI;CAE1B,MAAM,UAAU,kBAAkB;EAChC,YAAY,QAAQ,SAAS,gBAAgB,YAAY,CAAC;EAE1D,YAAY,UAAU;EACtB,YAAY,UAAU,CAAC;CACzB,GAAG,CAAC,CAAC;CAEL,MAAM,aAAa,aAChB,UAAiB;EAChB,IAAI,cAAc,GAAG,OAAO;EAC5B,IAAI,CAAC,YAAY,SAAS,OAAO;EAOjC,OALiB,KAAK,KACpB,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AAC,CACH;IAEA,YAAY,QAAQ,MAAA,GAClBC,cAAAA,YAAAA,CAAY,KAAK,kBAAkB,OAAO;KACxC,IAAI,CAAC,IAAI,SAAS;KAElB,QAAQ;KAER,MAAM,SAAA,GAAQD,cAAAA,cAAAA,CAAc,EAAE;KAC9B,MAAM,OAAO,IAAI,QAAQ,sBAAsB;KAE/C,MAAM,IAAI,OAAO,IAAI;IACvB,CAAC,CACH;GACF,CAAC;EACH;CACF,GACA;EAAC;EAAS;EAAW;EAAO;EAAQ;EAAS;CAAU,CAGrC,CAAC;AACvB"}
|
|
@@ -2,7 +2,7 @@ import { ComponentSlotStyle } from "../../core/system/index.type.js";
|
|
|
2
2
|
import { CSSModifierObject, CSSPropObject, CSSSlotObject } from "../../core/css/index.type.js";
|
|
3
3
|
import "../../index.js";
|
|
4
4
|
//#region src/components/chart/cartesian-chart.style.d.ts
|
|
5
|
-
export declare const cartesianChartStyle: ComponentSlotStyle<"area" | "line" | "grid" | "bar" | "dot" | "root" | "
|
|
5
|
+
export declare const cartesianChartStyle: ComponentSlotStyle<"area" | "line" | "grid" | "bar" | "dot" | "root" | "labelList" | "activeDot" | "referenceLine" | "referenceLineLabel" | "xAxis" | "xAxisLabel" | "xAxisTick" | "xAxisTickLine" | "yAxis" | "yAxisLabel" | "yAxisTick" | "yAxisTickLine", CSSPropObject<CSSSlotObject<"area" | "line" | "grid" | "bar" | "dot" | "root" | "labelList" | "activeDot" | "referenceLine" | "referenceLineLabel" | "xAxis" | "xAxisLabel" | "xAxisTick" | "xAxisTickLine" | "yAxis" | "yAxisLabel" | "yAxisTick" | "yAxisTickLine">>, CSSModifierObject<CSSSlotObject<"area" | "line" | "grid" | "bar" | "dot" | "root" | "labelList" | "activeDot" | "referenceLine" | "referenceLineLabel" | "xAxis" | "xAxisLabel" | "xAxisTick" | "xAxisTickLine" | "yAxis" | "yAxisLabel" | "yAxisTick" | "yAxisTickLine">>, CSSModifierObject<CSSSlotObject<"area" | "line" | "grid" | "bar" | "dot" | "root" | "labelList" | "activeDot" | "referenceLine" | "referenceLineLabel" | "xAxis" | "xAxisLabel" | "xAxisTick" | "xAxisTickLine" | "yAxis" | "yAxisLabel" | "yAxisTick" | "yAxisTickLine">>>;
|
|
6
6
|
export type CartesianChartStyle = typeof cartesianChartStyle;
|
|
7
7
|
//#endregion
|
|
8
8
|
//# sourceMappingURL=cartesian-chart.style.d.ts.map
|
|
@@ -2,7 +2,7 @@ import { ComponentSlotStyle } from "../../core/system/index.type.js";
|
|
|
2
2
|
import { CSSModifierObject, CSSPropObject, CSSSlotObject } from "../../core/css/index.type.js";
|
|
3
3
|
import "../../index.js";
|
|
4
4
|
//#region src/components/chart/polar-chart.style.d.ts
|
|
5
|
-
export declare const polarChartStyle: ComponentSlotStyle<"label" | "grid" | "dot" | "root" | "activeDot" | "angleAxis" | "angleAxisLabel" | "angleAxisLine" | "angleAxisTick" | "angleAxisTickLine" | "labelLine" | "
|
|
5
|
+
export declare const polarChartStyle: ComponentSlotStyle<"label" | "grid" | "dot" | "root" | "labelList" | "activeDot" | "angleAxis" | "angleAxisLabel" | "angleAxisLine" | "angleAxisTick" | "angleAxisTickLine" | "labelLine" | "pie" | "radar" | "radial" | "radialBackground" | "radiusAxis" | "radiusAxisLabel" | "radiusAxisLine" | "radiusAxisTick" | "radiusAxisTickLine" | "sector", CSSPropObject<CSSSlotObject<"label" | "grid" | "dot" | "root" | "labelList" | "activeDot" | "angleAxis" | "angleAxisLabel" | "angleAxisLine" | "angleAxisTick" | "angleAxisTickLine" | "labelLine" | "pie" | "radar" | "radial" | "radialBackground" | "radiusAxis" | "radiusAxisLabel" | "radiusAxisLine" | "radiusAxisTick" | "radiusAxisTickLine" | "sector">>, CSSModifierObject<CSSSlotObject<"label" | "grid" | "dot" | "root" | "labelList" | "activeDot" | "angleAxis" | "angleAxisLabel" | "angleAxisLine" | "angleAxisTick" | "angleAxisTickLine" | "labelLine" | "pie" | "radar" | "radial" | "radialBackground" | "radiusAxis" | "radiusAxisLabel" | "radiusAxisLine" | "radiusAxisTick" | "radiusAxisTickLine" | "sector">>, CSSModifierObject<CSSSlotObject<"label" | "grid" | "dot" | "root" | "labelList" | "activeDot" | "angleAxis" | "angleAxisLabel" | "angleAxisLine" | "angleAxisTick" | "angleAxisTickLine" | "labelLine" | "pie" | "radar" | "radial" | "radialBackground" | "radiusAxis" | "radiusAxisLabel" | "radiusAxisLine" | "radiusAxisTick" | "radiusAxisTickLine" | "sector">>>;
|
|
6
6
|
export type PolarChartStyle = typeof polarChartStyle;
|
|
7
7
|
//#endregion
|
|
8
8
|
//# sourceMappingURL=polar-chart.style.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ComponentSlotStyle } from "../../core/system/index.type.js";
|
|
2
2
|
import "../../index.js";
|
|
3
3
|
//#region src/components/data-list/data-list.style.d.ts
|
|
4
|
-
export declare const dataListStyle: ComponentSlotStyle<"term" | "root" | "
|
|
4
|
+
export declare const dataListStyle: ComponentSlotStyle<"term" | "root" | "description" | "item", {
|
|
5
5
|
/**
|
|
6
6
|
* The orientation of the data list.
|
|
7
7
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { GroupStyle, groupStyle } from "./group.style.js";
|
|
2
2
|
import { Group, GroupProps, GroupPropsContext, useGroupPropsContext } from "./group.js";
|
|
3
|
-
import { UseGroupItemReturn, UseGroupReturn, useGroup, useGroupItemProps } from "./use-group.js";
|
|
4
|
-
export { Group, type GroupProps, GroupPropsContext, GroupStyle, UseGroupItemReturn, UseGroupReturn, groupStyle, useGroup, useGroupItemProps, useGroupPropsContext };
|
|
3
|
+
import { UseGroupItemProps, UseGroupItemReturn, UseGroupReturn, useGroup, useGroupItemProps } from "./use-group.js";
|
|
4
|
+
export { Group, type GroupProps, GroupPropsContext, GroupStyle, UseGroupItemProps, UseGroupItemReturn, UseGroupReturn, groupStyle, useGroup, useGroupItemProps, useGroupPropsContext };
|
|
@@ -2,10 +2,10 @@ import { CSSProperties, DataAttributes, ReactNode } from "react";
|
|
|
2
2
|
//#region src/components/group/use-group.d.ts
|
|
3
3
|
export declare const useGroup: (children?: ReactNode) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>[];
|
|
4
4
|
export type UseGroupReturn = ReturnType<typeof useGroup>;
|
|
5
|
-
interface
|
|
5
|
+
export interface UseGroupItemProps extends DataAttributes {
|
|
6
6
|
style?: CSSProperties;
|
|
7
7
|
}
|
|
8
|
-
export declare const useGroupItemProps: <Y extends
|
|
8
|
+
export declare const useGroupItemProps: <Y extends UseGroupItemProps>({ style: { "--group-count": groupCount, "--group-index": groupIndex, ...style }, "data-group-between": dataGroupBetween, "data-group-end": dataGroupEnd, "data-group-start": dataGroupStart, "data-peer": dataPeer, ...rest }: Y) => readonly [{
|
|
9
9
|
style: {
|
|
10
10
|
"--group-count": string | number;
|
|
11
11
|
"--group-index": string | number;
|
|
@@ -2,7 +2,7 @@ import { ComponentSlotStyle } from "../../core/system/index.type.js";
|
|
|
2
2
|
import { CSSPropObject, CSSSlotObject } from "../../core/css/index.type.js";
|
|
3
3
|
import "../../index.js";
|
|
4
4
|
//#region src/components/number-input/number-input.style.d.ts
|
|
5
|
-
export declare const numberInputStyle: ComponentSlotStyle<"button" | "root" | "
|
|
5
|
+
export declare const numberInputStyle: ComponentSlotStyle<"button" | "root" | "field" | "control" | "decrement" | "increment", CSSPropObject<CSSSlotObject<"button" | "root" | "field" | "control" | "decrement" | "increment">>, {
|
|
6
6
|
xs: {
|
|
7
7
|
control: {
|
|
8
8
|
boxSize: "calc({--height} - {spaces.2})";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ComponentSlotStyle } from "../../core/system/index.type.js";
|
|
2
2
|
import "../../index.js";
|
|
3
3
|
//#region src/components/steps/steps.style.d.ts
|
|
4
|
-
export declare const stepsStyle: ComponentSlotStyle<"title" | "list" | "separator" | "root" | "indicator" | "
|
|
4
|
+
export declare const stepsStyle: ComponentSlotStyle<"title" | "list" | "separator" | "root" | "indicator" | "description" | "item", {
|
|
5
5
|
/**
|
|
6
6
|
* The orientation of the steps.
|
|
7
7
|
*
|
|
@@ -62,7 +62,7 @@ declare const TimelinePropsContext: import("react").Context<Partial<TimelineRoot
|
|
|
62
62
|
*
|
|
63
63
|
* @see https://yamada-ui.com/docs/components/timeline
|
|
64
64
|
*/
|
|
65
|
-
export declare const TimelineRoot: Component<({ variant: variantProp, children, index, items, ...rest }: WithoutThemeProps<TimelineRootProps, ComponentSlotStyle<"title" | "content" | "root" | "indicator" | "
|
|
65
|
+
export declare const TimelineRoot: Component<({ variant: variantProp, children, index, items, ...rest }: WithoutThemeProps<TimelineRootProps, ComponentSlotStyle<"title" | "content" | "root" | "indicator" | "description" | "item" | "connector", {
|
|
66
66
|
align: {
|
|
67
67
|
center: {
|
|
68
68
|
content: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ComponentSlotStyle } from "../../core/system/index.type.js";
|
|
2
2
|
import "../../index.js";
|
|
3
3
|
//#region src/components/timeline/timeline.style.d.ts
|
|
4
|
-
export declare const timelineStyle: ComponentSlotStyle<"title" | "content" | "root" | "indicator" | "
|
|
4
|
+
export declare const timelineStyle: ComponentSlotStyle<"title" | "content" | "root" | "indicator" | "description" | "item" | "connector", {
|
|
5
5
|
/**
|
|
6
6
|
* The alignment of the timeline.
|
|
7
7
|
*
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import { CSSAnimationObject, Token } from "../../core/css/index.type.js";
|
|
2
2
|
import "../../core/index.js";
|
|
3
3
|
//#region src/hooks/use-animation/index.d.ts
|
|
4
|
-
type
|
|
4
|
+
export type UseAnimationProps = Token<CSSAnimationObject, "animations"> | Token<CSSAnimationObject, "animations">[];
|
|
5
5
|
/**
|
|
6
6
|
* `useAnimation` is a custom hook that implements animations similar to CSS `keyframes`.
|
|
7
7
|
*
|
|
8
8
|
* @see https://yamada-ui.com/docs/hooks/use-animation
|
|
9
9
|
*/
|
|
10
|
-
export declare const useAnimation: (
|
|
10
|
+
export declare const useAnimation: (arrayOrObj: UseAnimationProps) => string;
|
|
11
|
+
export type UseDynamicAnimationProps = Token<CSSAnimationObject, "animations">[] | {
|
|
12
|
+
[key: string]: UseAnimationProps;
|
|
13
|
+
};
|
|
11
14
|
/**
|
|
12
15
|
* `useDynamicAnimation` is a custom hook used to switch animations.
|
|
13
16
|
*
|
|
14
17
|
* @see https://yamada-ui.com/docs/hooks/use-dynamic-animation
|
|
15
18
|
*/
|
|
16
|
-
export declare const useDynamicAnimation: <Y extends
|
|
17
|
-
[key: string]: CSSObject;
|
|
18
|
-
}>(arrayOrObj: Y, init?: (keyof Y)[] | keyof Y) => [string | undefined, (key: ((key: (keyof Y)[] | keyof Y | undefined) => (keyof Y)[] | keyof Y) | (keyof Y)[] | keyof Y) => void];
|
|
19
|
+
export declare const useDynamicAnimation: <Y extends UseDynamicAnimationProps>(arrayOrObj: Y, init?: (keyof Y)[] | keyof Y) => [string | undefined, (key: ((key: (keyof Y)[] | keyof Y | undefined) => (keyof Y)[] | keyof Y) | (keyof Y)[] | keyof Y) => void];
|
|
19
20
|
//#endregion
|
|
20
21
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -2,8 +2,8 @@ import { StyledProps } from "../../core/components/index.type.js";
|
|
|
2
2
|
import "../../core/index.js";
|
|
3
3
|
import { HTMLAttributes, KeyboardEvent, MouseEvent, Ref } from "react";
|
|
4
4
|
//#region src/hooks/use-clickable/index.d.ts
|
|
5
|
-
type
|
|
6
|
-
export type UseClickableProps<Y extends HTMLElement = HTMLElement, M extends
|
|
5
|
+
export type UseClickableElementProps<Y extends HTMLElement = HTMLElement> = Omit<HTMLAttributes<Y>, "ref" | "size" | keyof StyledProps>;
|
|
6
|
+
export type UseClickableProps<Y extends HTMLElement = HTMLElement, M extends UseClickableElementProps<Y> = UseClickableElementProps<Y>> = M & {
|
|
7
7
|
/**
|
|
8
8
|
* Whether or not trigger click on pressing `Enter`.
|
|
9
9
|
*
|
|
@@ -46,7 +46,7 @@ export type UseClickableProps<Y extends HTMLElement = HTMLElement, M extends Pro
|
|
|
46
46
|
*/
|
|
47
47
|
ref?: Ref<Y>;
|
|
48
48
|
};
|
|
49
|
-
export declare const useClickable: <Y extends HTMLElement = HTMLElement, M extends
|
|
49
|
+
export declare const useClickable: <Y extends HTMLElement = HTMLElement, M extends UseClickableElementProps<Y> = UseClickableElementProps<Y>>({ ref, clickOnEnter, clickOnSpace, disabled, disableTouchBehavior, focusable, focusOnClick, tabIndex: tabIndexProp, onClick: onClickProp, onKeyDown: onKeyDownProp, onKeyUp: onKeyUpProp, onMouseDown: onMouseDownProp, onMouseLeave: onMouseLeaveProp, onMouseOver: onMouseOverProp, onMouseUp: onMouseUpProp, ...props }?: UseClickableProps<Y, M>) => (Omit<UseClickableProps<Y, M>, "disabled" | "ref" | "tabIndex" | "onKeyDown" | "onKeyUp" | "onClick" | "onMouseDown" | "onMouseLeave" | "onMouseOver" | "onMouseUp" | "clickOnEnter" | "clickOnSpace" | "disableTouchBehavior" | "focusable" | "focusOnClick"> & {
|
|
50
50
|
ref: (node: any) => void;
|
|
51
51
|
type: "button";
|
|
52
52
|
"aria-disabled": boolean | undefined;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Point } from "../../utils/index.js";
|
|
2
2
|
import { DataAttributes, HTMLAttributes, RefAttributes, RefObject } from "react";
|
|
3
3
|
//#region src/hooks/use-pan-event/index.d.ts
|
|
4
|
-
export interface
|
|
4
|
+
export interface UsePanEventProps {
|
|
5
5
|
threshold?: number;
|
|
6
6
|
onEnd?: (ev: PointerEvent, point: Point, rect: DOMRect) => void;
|
|
7
7
|
onMove?: (ev: PointerEvent, point: Point, rect: DOMRect) => void;
|
|
8
8
|
onStart?: (ev: PointerEvent, point: Point, rect: DOMRect) => void;
|
|
9
9
|
}
|
|
10
|
-
interface
|
|
11
|
-
export declare const usePanEvent: <Y extends HTMLElement>({ threshold, ...rest }?:
|
|
10
|
+
export interface UsePanEventElementProps<Y extends HTMLElement> extends DataAttributes, HTMLAttributes<Y>, RefAttributes<Y> {}
|
|
11
|
+
export declare const usePanEvent: <Y extends HTMLElement>({ threshold, ...rest }?: UsePanEventProps) => [RefObject<null | Y>, (props?: UsePanEventElementProps<Y>) => UsePanEventElementProps<Y>];
|
|
12
12
|
export type UsePanEventReturn = ReturnType<typeof usePanEvent>;
|
|
13
13
|
//#endregion
|
|
14
14
|
//# sourceMappingURL=index.d.ts.map
|