@lobehub/ui 6.0.0-beta.3 → 6.0.0-beta.5
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/es/Accordion/style.d.mts +1 -1
- package/es/Anchor/Anchor.mjs +2 -2
- package/es/Anchor/Anchor.mjs.map +1 -1
- package/es/AutoComplete/style.d.mts +1 -1
- package/es/Carousel/Carousel.mjs +1 -1
- package/es/Carousel/Carousel.mjs.map +1 -1
- package/es/CodeDiff/CodeDiff.mjs.map +1 -1
- package/es/CodeDiff/PatchDiff.mjs.map +1 -1
- package/es/CodeDiff/theme.mjs.map +1 -1
- package/es/CodeDiff/type.d.mts +2 -2
- package/es/CodeEditor/CodeEditor.mjs +1 -1
- package/es/CodeEditor/CodeEditor.mjs.map +1 -1
- package/es/ColorPicker/ColorPicker.mjs +1 -1
- package/es/ColorPicker/ColorPicker.mjs.map +1 -1
- package/es/ColorSwatches/ColorSwatches.mjs +1 -1
- package/es/ColorSwatches/ColorSwatches.mjs.map +1 -1
- package/es/ConfigProvider/cdnAssets.mjs +6 -0
- package/es/ConfigProvider/cdnAssets.mjs.map +1 -0
- package/es/ConfigProvider/index.mjs +2 -1
- package/es/ConfigProvider/index.mjs.map +1 -1
- package/es/ContextMenu/store.d.mts +0 -1
- package/es/ContextMenu/store.mjs.map +1 -1
- package/es/DatePicker/DatePicker.mjs +1 -1
- package/es/DatePicker/DatePicker.mjs.map +1 -1
- package/es/DatePicker/DateRangePicker.mjs +1 -1
- package/es/DatePicker/DateRangePicker.mjs.map +1 -1
- package/es/DraggablePanel/atoms.mjs +1 -1
- package/es/DraggablePanel/atoms.mjs.map +1 -1
- package/es/DraggableSideNav/DraggableSideNav.mjs +2 -2
- package/es/DraggableSideNav/DraggableSideNav.mjs.map +1 -1
- package/es/Drawer/atoms.mjs +1 -1
- package/es/Drawer/atoms.mjs.map +1 -1
- package/es/DropdownMenu/atoms.mjs +1 -1
- package/es/DropdownMenu/atoms.mjs.map +1 -1
- package/es/EditableText/ControlInput.mjs +42 -29
- package/es/EditableText/ControlInput.mjs.map +1 -1
- package/es/EditableText/EditableText.mjs +1 -1
- package/es/EditableText/EditableText.mjs.map +1 -1
- package/es/EmojiPicker/EmojiPicker.mjs +3 -9
- package/es/EmojiPicker/EmojiPicker.mjs.map +1 -1
- package/es/EmojiPicker/useEmojiMartI18n.mjs +37 -0
- package/es/EmojiPicker/useEmojiMartI18n.mjs.map +1 -0
- package/es/FormKit/engine/tanstack.mjs +1 -1
- package/es/FormKit/engine/tanstack.mjs.map +1 -1
- package/es/HotkeyInput/HotkeyInput.mjs +1 -1
- package/es/HotkeyInput/HotkeyInput.mjs.map +1 -1
- package/es/Image/viewer/ImageViewer.mjs +1 -1
- package/es/Image/viewer/ImageViewer.mjs.map +1 -1
- package/es/ImageSelect/ImageSelect.mjs +1 -1
- package/es/ImageSelect/ImageSelect.mjs.map +1 -1
- package/es/Input/Input.mjs +7 -5
- package/es/Input/Input.mjs.map +1 -1
- package/es/Input/TextArea.mjs +1 -1
- package/es/Input/TextArea.mjs.map +1 -1
- package/es/Modal/atoms.mjs +3 -3
- package/es/Modal/atoms.mjs.map +1 -1
- package/es/Pagination/Pagination.mjs +1 -1
- package/es/Pagination/Pagination.mjs.map +1 -1
- package/es/Popover/PopoverInGroup.mjs +1 -1
- package/es/Popover/PopoverInGroup.mjs.map +1 -1
- package/es/Popover/atoms.mjs +1 -1
- package/es/Popover/atoms.mjs.map +1 -1
- package/es/Rate/Rate.mjs +1 -1
- package/es/Rate/Rate.mjs.map +1 -1
- package/es/ScrollShadow/ScrollShadow.mjs +1 -1
- package/es/ScrollShadow/ScrollShadow.mjs.map +1 -1
- package/es/SearchBar/SearchBar.mjs +31 -25
- package/es/SearchBar/SearchBar.mjs.map +1 -1
- package/es/Segmented/Segmented.mjs +1 -1
- package/es/Segmented/Segmented.mjs.map +1 -1
- package/es/Select/atoms.mjs +1 -1
- package/es/Select/atoms.mjs.map +1 -1
- package/es/Switch/atoms.mjs +1 -1
- package/es/Switch/atoms.mjs.map +1 -1
- package/es/Tabs/Tabs.mjs +35 -21
- package/es/Tabs/Tabs.mjs.map +1 -1
- package/es/Text/style.d.mts +3 -3
- package/es/ToggleGroup/ToggleGroup.mjs +1 -1
- package/es/ToggleGroup/ToggleGroup.mjs.map +1 -1
- package/es/Tooltip/TooltipInGroup.mjs +1 -1
- package/es/Tooltip/TooltipInGroup.mjs.map +1 -1
- package/es/Tooltip/TooltipStandalone.mjs +1 -1
- package/es/Tooltip/TooltipStandalone.mjs.map +1 -1
- package/es/Tree/Tree.mjs +1 -1
- package/es/Tree/Tree.mjs.map +1 -1
- package/es/Video/context.mjs.map +1 -1
- package/es/Video/parts/Caption.mjs +4 -1
- package/es/Video/parts/Caption.mjs.map +1 -1
- package/es/Video/parts/Controls.mjs +6 -1
- package/es/Video/parts/Controls.mjs.map +1 -1
- package/es/Video/parts/Frame.mjs +9 -2
- package/es/Video/parts/Frame.mjs.map +1 -1
- package/es/awesome/Giscus/style.mjs +9 -9
- package/es/awesome/Giscus/style.mjs.map +1 -1
- package/es/awesome/GridBackground/GridBackground.mjs +1 -1
- package/es/awesome/GridBackground/GridBackground.mjs.map +1 -1
- package/es/awesome/GridBackground/GridShowcase.mjs +4 -4
- package/es/awesome/GridBackground/GridShowcase.mjs.map +1 -1
- package/es/awesome/Spline/ParentSize.mjs +1 -1
- package/es/awesome/Spline/ParentSize.mjs.map +1 -1
- package/es/chat/BackBottom/BackBottom.mjs +1 -1
- package/es/chat/BackBottom/BackBottom.mjs.map +1 -1
- package/es/chat/BackBottom/type.d.mts +2 -2
- package/es/chat/EditableMessage/EditableMessage.mjs +1 -1
- package/es/chat/EditableMessage/EditableMessage.mjs.map +1 -1
- package/es/chat/EditableMessageList/EditableMessageList.mjs +1 -1
- package/es/chat/EditableMessageList/EditableMessageList.mjs.map +1 -1
- package/es/chat/EditableMessageList/messageReducer.mjs +30 -23
- package/es/chat/EditableMessageList/messageReducer.mjs.map +1 -1
- package/es/chat/MessageModal/MessageModal.mjs +1 -1
- package/es/chat/MessageModal/MessageModal.mjs.map +1 -1
- package/es/chat/TokenTag/TokenTag.mjs +2 -3
- package/es/chat/TokenTag/TokenTag.mjs.map +1 -1
- package/es/hooks/useControlledState.mjs +20 -0
- package/es/hooks/useControlledState.mjs.map +1 -0
- package/es/hooks/useHighlight.mjs +2 -2
- package/es/hooks/useHighlight.mjs.map +1 -1
- package/es/hooks/useHover.mjs +22 -0
- package/es/hooks/useHover.mjs.map +1 -0
- package/es/hooks/useScroll.d.mts +8 -0
- package/es/hooks/useScroll.mjs +33 -0
- package/es/hooks/useScroll.mjs.map +1 -0
- package/es/hooks/useSize.mjs +26 -0
- package/es/hooks/useSize.mjs.map +1 -0
- package/es/internal/virtual/VirtualScrollArea.mjs +1 -1
- package/es/internal/virtual/VirtualScrollArea.mjs.map +1 -1
- package/es/mobile/ChatInputArea/ChatInputArea.mjs +1 -1
- package/es/mobile/ChatInputArea/ChatInputArea.mjs.map +1 -1
- package/es/mobile/TabBar/TabBar.mjs +1 -1
- package/es/mobile/TabBar/TabBar.mjs.map +1 -1
- package/es/node_modules/.pnpm/@eslint_core@1.2.1/node_modules/@eslint/core/dist/esm/types.d.mts +2 -46
- package/es/node_modules/.pnpm/@eslint_plugin-kit@0.7.3/node_modules/@eslint/plugin-kit/dist/cjs/index.d.mts +1 -1
- package/es/node_modules/.pnpm/@types_estree@1.0.9/node_modules/@types/estree/index.d.mts +1 -4
- package/es/node_modules/.pnpm/eslint@10.12.0_jiti@2.6.1_supports-color@10.2.2/node_modules/eslint/lib/types/index.d.mts +1 -1
- package/es/styles/theme/token/neutral.mjs +5 -5
- package/es/styles/theme/token/neutral.mjs.map +1 -1
- package/es/utils/colorMath.mjs +52 -0
- package/es/utils/colorMath.mjs.map +1 -0
- package/es/utils/formatNumber.mjs +7 -0
- package/es/utils/formatNumber.mjs.map +1 -0
- package/es/utils/genCdnUrl.mjs +6 -3
- package/es/utils/genCdnUrl.mjs.map +1 -1
- package/es/utils/hashString.mjs +19 -0
- package/es/utils/hashString.mjs.map +1 -0
- package/es/utils/mergeRefs.mjs +20 -0
- package/es/utils/mergeRefs.mjs.map +1 -0
- package/es/utils/placement.d.mts +5 -5
- package/es/utils/placement.mjs.map +1 -1
- package/package.json +16 -42
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
import { styleProps } from "../styles/stylex/props.mjs";
|
|
3
3
|
import Icon from "../Icon/Icon.mjs";
|
|
4
4
|
import FlexBasic_default from "../Flex/FlexBasic.mjs";
|
|
5
|
+
import { useControlledState } from "../hooks/useControlledState.mjs";
|
|
5
6
|
import Img from "../Img/index.mjs";
|
|
6
7
|
import { styles } from "./styles.mjs";
|
|
7
8
|
import { createElement, memo } from "react";
|
|
8
9
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
10
|
import * as stylex from "@stylexjs/stylex";
|
|
10
|
-
import useControlledState from "use-merge-value";
|
|
11
11
|
//#region src/ImageSelect/ImageSelect.tsx
|
|
12
12
|
const ImageSelect = memo(({ ref, className, style, value, defaultValue, onChange, options, width = 144, height = 86, styles: customStyles, classNames, unoptimized, ...rest }) => {
|
|
13
13
|
const [currentValue, setCurrentValue] = useControlledState(defaultValue, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImageSelect.mjs","names":["Flexbox"],"sources":["../../src/ImageSelect/ImageSelect.tsx"],"sourcesContent":["'use client';\n\nimport * as stylex from '@stylexjs/stylex';\nimport { memo } from 'react';\nimport
|
|
1
|
+
{"version":3,"file":"ImageSelect.mjs","names":["Flexbox"],"sources":["../../src/ImageSelect/ImageSelect.tsx"],"sourcesContent":["'use client';\n\nimport * as stylex from '@stylexjs/stylex';\nimport { memo } from 'react';\n\nimport { Flexbox } from '@/Flex';\nimport { useControlledState } from '@/hooks/useControlledState';\nimport Icon from '@/Icon';\nimport Img from '@/Img';\nimport { styleProps } from '@/styles/stylex/props';\n\nimport { styles } from './styles';\nimport type { ImageSelectProps } from './type';\n\nconst ImageSelect = memo<ImageSelectProps>(\n ({\n ref,\n className,\n style,\n value,\n defaultValue,\n onChange,\n options,\n width = 144,\n height = 86,\n styles: customStyles,\n classNames,\n unoptimized,\n ...rest\n }) => {\n const [currentValue, setCurrentValue] = useControlledState<string>(defaultValue, {\n defaultValue,\n onChange,\n value,\n });\n\n return (\n <Flexbox horizontal className={className} gap={16} ref={ref} style={style} {...rest}>\n {options?.map((item) => {\n const isActive = item.value === currentValue;\n return (\n <Flexbox\n align={'center'}\n gap={4}\n {...stylex.props(styles.container, isActive && styles.active)}\n key={item.value}\n onClick={() => setCurrentValue(item.value)}\n >\n <Img\n alt={item.alt || item.value}\n height={height}\n src={item.img}\n unoptimized={unoptimized}\n width={width}\n {...styleProps([styles.img, isActive && styles.imgActive], classNames?.img, {\n ...customStyles?.img,\n height,\n width,\n })}\n />\n\n <Flexbox horizontal align={'center'} gap={4}>\n {item.icon && <Icon icon={item.icon} />}\n {item.label}\n </Flexbox>\n </Flexbox>\n );\n })}\n </Flexbox>\n );\n },\n);\n\nImageSelect.displayName = 'ImageSelect';\n\nexport default ImageSelect;\n"],"mappings":";;;;;;;;;;;AAWA,MAAM,cAAc,MAAwB,EAC1C,KACA,WACA,OACA,OACA,cACA,UACA,SACA,QAAQ,KACR,SAAS,IACT,QAAQ,cACR,YACA,aACA,GAAG,WACC;CACJ,MAAM,CAAC,cAAc,mBAAmB,mBAA2B,cAAc;EAC/E;EACA;EACA;CACF,CAAC;CACD,OAAO,oBAACA,mBAAD;EAAS,YAAA;EAAsB;EAAW,KAAK;EAAS;EAAY;EAAO,GAAI;EAC/E,UAAA,SAAS,KAAI,SAAQ;GACxB,MAAM,WAAW,KAAK,UAAU;GAChC,OAAO,8BAACA,mBAAD;IAAS,OAAO;IAAU,KAAK;IAAG,GAAI,OAAO,MAAM,OAAO,WAAW,YAAY,OAAO,MAAM;IAAG,KAAK,KAAK;IAAO,eAAe,gBAAgB,KAAK,KAAK;GAWnJ,GAVP,oBAAC,KAAD;IAAK,KAAK,KAAK,OAAO,KAAK;IAAe;IAAQ,KAAK,KAAK;IAAkB;IAAoB;IAAO,GAAI,WAAW,CAAC,OAAO,KAAK,YAAY,OAAO,SAAS,GAAG,YAAY,KAAK;KACzL,GAAG,cAAc;KACjB;KACA;IACF,CAAC;GAAI,CAAA,GAEC,qBAACA,mBAAD;IAAS,YAAA;IAAW,OAAO;IAAU,KAAK;IAA1C,UAAA,CACG,KAAK,QAAQ,oBAAC,MAAD,EAAM,MAAM,KAAK,KAAO,CAAA,GACrC,KAAK,KACC;GACF,CAAA,CAAA;EACjB,CAAC;CACU,CAAA;AACf,CAAC;AACD,YAAY,cAAc"}
|
package/es/Input/Input.mjs
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { styleProps } from "../styles/stylex/props.mjs";
|
|
3
|
+
import { useMergeRefs } from "../utils/mergeRefs.mjs";
|
|
3
4
|
import { useThemeMode } from "../styles/theme/scope.mjs";
|
|
5
|
+
import { useEventCallback } from "../hooks/useEventCallback.mjs";
|
|
4
6
|
import { inputRootStyles, styles } from "./style.mjs";
|
|
5
7
|
import ClearButton from "./ClearButton.mjs";
|
|
6
8
|
import { clearNativeValue } from "./clearNativeValue.mjs";
|
|
7
9
|
import { isPressEnter } from "./pressEnter.mjs";
|
|
8
10
|
import { memo, useRef, useState } from "react";
|
|
9
11
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
-
import { useMergeRefs } from "react-merge-refs";
|
|
11
12
|
import { Input } from "@base-ui/react/input";
|
|
12
13
|
//#region src/Input/Input.tsx
|
|
13
14
|
const hasText = (value) => value !== void 0 && value !== null && String(value).length > 0;
|
|
@@ -19,6 +20,10 @@ const Input$1 = memo(({ ref, className, classNames, styles: customStyles, style,
|
|
|
19
20
|
const [filled, setFilled] = useState(() => hasText(value ?? defaultValue));
|
|
20
21
|
const isFilled = value === void 0 ? filled : hasText(value);
|
|
21
22
|
const showClear = allowClear && isFilled && !disabled && !readOnly;
|
|
23
|
+
const handleClear = useEventCallback(() => {
|
|
24
|
+
clearNativeValue(inputRef.current);
|
|
25
|
+
onClear?.();
|
|
26
|
+
});
|
|
22
27
|
return /* @__PURE__ */ jsxs("div", {
|
|
23
28
|
"data-disabled": disabled ? "" : void 0,
|
|
24
29
|
"data-variant": mergedVariant,
|
|
@@ -49,10 +54,7 @@ const Input$1 = memo(({ ref, className, classNames, styles: customStyles, style,
|
|
|
49
54
|
},
|
|
50
55
|
...rest
|
|
51
56
|
}),
|
|
52
|
-
showClear && /* @__PURE__ */ jsx(ClearButton, { onClear:
|
|
53
|
-
clearNativeValue(inputRef.current);
|
|
54
|
-
onClear?.();
|
|
55
|
-
} }),
|
|
57
|
+
showClear && /* @__PURE__ */ jsx(ClearButton, { onClear: handleClear }),
|
|
56
58
|
suffix && /* @__PURE__ */ jsx("span", {
|
|
57
59
|
...styleProps(styles.slot, classNames?.suffix, customStyles?.suffix),
|
|
58
60
|
children: suffix
|
package/es/Input/Input.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Input.mjs","names":["Input","BaseInput"],"sources":["../../src/Input/Input.tsx"],"sourcesContent":["'use client';\n\nimport { Input as BaseInput } from '@base-ui/react/input';\nimport { memo, useRef, useState } from 'react';\nimport {
|
|
1
|
+
{"version":3,"file":"Input.mjs","names":["Input","BaseInput"],"sources":["../../src/Input/Input.tsx"],"sourcesContent":["'use client';\n\nimport { Input as BaseInput } from '@base-ui/react/input';\nimport { memo, useRef, useState } from 'react';\n\nimport { useEventCallback } from '@/hooks/useEventCallback';\nimport { styleProps } from '@/styles/stylex/props';\nimport { useThemeMode } from '@/styles/theme/scope';\nimport { useMergeRefs } from '@/utils/mergeRefs';\n\nimport ClearButton from './ClearButton';\nimport { clearNativeValue } from './clearNativeValue';\nimport { isPressEnter } from './pressEnter';\nimport { inputRootStyles, styles } from './style';\nimport type { InputProps } from './type';\n\nconst hasText = (value: unknown) =>\n value !== undefined && value !== null && String(value).length > 0;\n\nconst Input = memo<InputProps>(\n ({\n ref,\n className,\n classNames,\n styles: customStyles,\n style,\n variant,\n shadow,\n size = 'middle',\n prefix,\n suffix,\n disabled,\n readOnly,\n allowClear,\n onClear,\n onPressEnter,\n onKeyDown,\n onChange,\n value,\n defaultValue,\n ...rest\n }) => {\n const { isDarkMode } = useThemeMode();\n const mergedVariant = variant || (isDarkMode ? 'filled' : 'outlined');\n const inputRef = useRef<HTMLInputElement>(null);\n const mergedRef = useMergeRefs([ref, inputRef]);\n const [filled, setFilled] = useState(() => hasText(value ?? defaultValue));\n const isFilled = value === undefined ? filled : hasText(value);\n const showClear = allowClear && isFilled && !disabled && !readOnly;\n\n const handleClear = useEventCallback(() => {\n clearNativeValue(inputRef.current);\n onClear?.();\n });\n\n return (\n <div\n data-disabled={disabled ? '' : undefined}\n data-variant={mergedVariant}\n {...styleProps(inputRootStyles({ shadow, size, variant: mergedVariant }), className, style)}\n >\n {prefix && (\n <span {...styleProps(styles.slot, classNames?.prefix, customStyles?.prefix)}>\n {prefix}\n </span>\n )}\n <BaseInput\n defaultValue={defaultValue}\n disabled={disabled}\n readOnly={readOnly}\n ref={mergedRef}\n value={value}\n {...styleProps(styles.input, classNames?.input, customStyles?.input)}\n onChange={(event) => {\n setFilled(event.currentTarget.value.length > 0);\n onChange?.(event);\n }}\n onKeyDown={(event) => {\n if (isPressEnter(event)) onPressEnter?.(event);\n onKeyDown?.(event);\n }}\n {...rest}\n />\n {showClear && <ClearButton onClear={handleClear} />}\n {suffix && (\n <span {...styleProps(styles.slot, classNames?.suffix, customStyles?.suffix)}>\n {suffix}\n </span>\n )}\n </div>\n );\n },\n);\n\nInput.displayName = 'Input';\n\nexport default Object.assign(Input, { formBinding: { emptyValue: '' } as const });\n"],"mappings":";;;;;;;;;;;;;AAgBA,MAAM,WAAW,UACf,UAAU,KAAA,KAAa,UAAU,QAAQ,OAAO,KAAK,CAAC,CAAC,SAAS;AAElE,MAAMA,UAAQ,MACX,EACC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AET,CACF;AAEA,QAAM,cAAc;AAEpB,IAAA,gBAAe,OAAO,OAAOD,SAAO,EAAE,aAAa,EAAE,YAAY,GAAG,EAAW,CAAC"}
|
package/es/Input/TextArea.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { styleProps } from "../styles/stylex/props.mjs";
|
|
3
|
+
import { useMergeRefs } from "../utils/mergeRefs.mjs";
|
|
3
4
|
import { useThemeMode } from "../styles/theme/scope.mjs";
|
|
4
5
|
import { inputRootStyles, styles } from "./style.mjs";
|
|
5
6
|
import ClearButton from "./ClearButton.mjs";
|
|
@@ -8,7 +9,6 @@ import { isPressEnter } from "./pressEnter.mjs";
|
|
|
8
9
|
import { memo, useMemo, useRef, useState } from "react";
|
|
9
10
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
11
|
import * as stylex from "@stylexjs/stylex";
|
|
11
|
-
import { useMergeRefs } from "react-merge-refs";
|
|
12
12
|
import { Field } from "@base-ui/react/field";
|
|
13
13
|
//#region src/Input/TextArea.tsx
|
|
14
14
|
const textLength = (value) => value === void 0 || value === null ? 0 : Array.from(String(value)).length;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextArea.mjs","names":[],"sources":["../../src/Input/TextArea.tsx"],"sourcesContent":["'use client';\n\nimport { Field } from '@base-ui/react/field';\nimport * as stylex from '@stylexjs/stylex';\nimport { type CSSProperties, memo, useMemo, useRef, useState } from 'react';\nimport {
|
|
1
|
+
{"version":3,"file":"TextArea.mjs","names":[],"sources":["../../src/Input/TextArea.tsx"],"sourcesContent":["'use client';\n\nimport { Field } from '@base-ui/react/field';\nimport * as stylex from '@stylexjs/stylex';\nimport { type CSSProperties, memo, useMemo, useRef, useState } from 'react';\n\nimport { styleProps } from '@/styles/stylex/props';\nimport { useThemeMode } from '@/styles/theme/scope';\nimport { useMergeRefs } from '@/utils/mergeRefs';\n\nimport ClearButton from './ClearButton';\nimport { clearNativeValue } from './clearNativeValue';\nimport { isPressEnter } from './pressEnter';\nimport { inputRootStyles, styles } from './style';\nimport type { TextAreaProps } from './type';\n\nconst textLength = (value: unknown) =>\n value === undefined || value === null ? 0 : Array.from(String(value)).length;\n\nconst TextArea = memo<TextAreaProps>(\n ({\n ref,\n className,\n classNames,\n styles: customStyles,\n style,\n variant,\n shadow,\n autoSize,\n resize = false,\n disabled,\n readOnly,\n allowClear,\n onClear,\n onPressEnter,\n onKeyDown,\n onChange,\n showCount,\n maxLength,\n value,\n defaultValue,\n ...rest\n }) => {\n const { isDarkMode } = useThemeMode();\n const mergedVariant = variant || (isDarkMode ? 'filled' : 'outlined');\n const textareaRef = useRef<HTMLTextAreaElement>(null);\n const mergedRef = useMergeRefs([ref, textareaRef]);\n const [innerLength, setInnerLength] = useState(() => textLength(value ?? defaultValue));\n const length = value === undefined ? innerLength : textLength(value);\n const showClear = allowClear && length > 0 && !disabled && !readOnly;\n const over = maxLength !== undefined && length > maxLength;\n\n const cssVariables = useMemo<CSSProperties>(() => {\n if (typeof autoSize !== 'object') return {};\n return {\n '--textarea-max-height': autoSize.maxRows ? `calc(1.5em * ${autoSize.maxRows})` : undefined,\n '--textarea-min-rows': autoSize.minRows,\n } as CSSProperties;\n }, [autoSize]);\n\n return (\n <div\n data-disabled={disabled ? '' : undefined}\n data-variant={mergedVariant}\n {...styleProps(\n [\n ...inputRootStyles({ shadow, variant: mergedVariant }),\n styles.textarea,\n showCount && styles.textareaWithCount,\n ],\n className,\n { ...cssVariables, ...style },\n )}\n >\n <Field.Control\n disabled={disabled}\n {...styleProps(\n [\n styles.input,\n styles.textareaControl,\n autoSize && styles.textareaAutoSize,\n resize && styles.textareaResize,\n ],\n classNames?.input,\n customStyles?.input,\n )}\n render={\n <textarea\n defaultValue={defaultValue}\n maxLength={maxLength}\n readOnly={readOnly}\n ref={mergedRef}\n value={value}\n onChange={(event) => {\n setInnerLength(textLength(event.currentTarget.value));\n onChange?.(event);\n }}\n onKeyDown={(event) => {\n if (isPressEnter(event)) onPressEnter?.(event);\n onKeyDown?.(event);\n }}\n {...rest}\n />\n }\n />\n {showClear && (\n <ClearButton\n xstyle={styles.textareaClear}\n onClear={() => {\n clearNativeValue(textareaRef.current);\n onClear?.();\n }}\n />\n )}\n {showCount && (\n <span data-over={over ? '' : undefined} {...stylex.props(styles.count)}>\n {maxLength === undefined ? length : `${length} / ${maxLength}`}\n </span>\n )}\n </div>\n );\n },\n);\n\nTextArea.displayName = 'TextArea';\n\nexport default Object.assign(TextArea, { formBinding: { emptyValue: '' } as const });\n"],"mappings":";;;;;;;;;;;;;AAaA,MAAM,cAAc,UAAmB,UAAU,KAAA,KAAa,UAAU,OAAO,IAAI,MAAM,KAAK,OAAO,KAAK,CAAC,CAAC,CAAC;AAC7G,MAAM,WAAW,MAAqB,EACpC,KACA,WACA,YACA,QAAQ,cACR,OACA,SACA,QACA,UACA,SAAS,OACT,UACA,UACA,YACA,SACA,cACA,WACA,UACA,WACA,WACA,OACA,cACA,GAAG,WACC;CACJ,MAAM,EACJ,eACE,aAAa;CACjB,MAAM,gBAAgB,YAAY,aAAa,WAAW;CAC1D,MAAM,cAAc,OAA4B,IAAI;CACpD,MAAM,YAAY,aAAa,CAAC,KAAK,WAAW,CAAC;CACjD,MAAM,CAAC,aAAa,kBAAkB,eAAe,WAAW,SAAS,YAAY,CAAC;CACtF,MAAM,SAAS,UAAU,KAAA,IAAY,cAAc,WAAW,KAAK;CACnE,MAAM,YAAY,cAAc,SAAS,KAAK,CAAC,YAAY,CAAC;CAC5D,MAAM,OAAO,cAAc,KAAA,KAAa,SAAS;CACjD,MAAM,eAAe,cAA6B;EAChD,IAAI,OAAO,aAAa,UAAU,OAAO,CAAC;EAC1C,OAAO;GACL,yBAAyB,SAAS,UAAU,gBAAgB,SAAS,QAAQ,KAAK,KAAA;GAClF,uBAAuB,SAAS;EAClC;CACF,GAAG,CAAC,QAAQ,CAAC;CACb,OAAO,qBAAC,OAAD;EAAK,iBAAe,WAAW,KAAK,KAAA;EAAW,gBAAc;EAAe,GAAI,WAAW;GAAC,GAAG,gBAAgB;IACpH;IACA,SAAS;GACX,CAAC;GAAG,OAAO;GAAU,aAAa,OAAO;EAAiB,GAAG,WAAW;GACtE,GAAG;GACH,GAAG;EACL,CAAC;EANM,UAAA;GAOD,oBAAC,MAAM,SAAP;IAAyB;IAAU,GAAI,WAAW;KAAC,OAAO;KAAO,OAAO;KAAiB,YAAY,OAAO;KAAkB,UAAU,OAAO;IAAc,GAAG,YAAY,OAAO,cAAc,KAAK;IAAG,QAAQ,oBAAC,YAAD;KAAwB;KAAyB;KAAqB;KAAU,KAAK;KAAkB;KAAO,WAAU,UAAS;MACpV,eAAe,WAAW,MAAM,cAAc,KAAK,CAAC;MACpD,WAAW,KAAK;KAClB;KAAG,YAAW,UAAS;MACrB,IAAI,aAAa,KAAK,GAAG,eAAe,KAAK;MAC7C,YAAY,KAAK;KACnB;KAAG,GAAI;IAAO,CAAA;GAAI,CAAA;GACb,aAAa,oBAAC,aAAD;IAAa,QAAQ,OAAO;IAAe,eAAe;KAC1E,iBAAiB,YAAY,OAAO;KACpC,UAAU;IACZ;GAAI,CAAA;GACC,aAAa,oBAAC,QAAD;IAAM,aAAW,OAAO,KAAK,KAAA;IAAW,GAAI,OAAO,MAAM,OAAO,KAAK;IAC9E,UAAA,cAAc,KAAA,IAAY,SAAS,GAAG,OAAO,KAAK;GAC/C,CAAA;EACL;;AACX,CAAC;AACD,SAAS,cAAc;AACvB,IAAA,mBAAe,OAAO,OAAO,UAAU,EACrC,aAAa,EACX,YAAY,GACd,EACF,CAAC"}
|
package/es/Modal/atoms.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import { useAppElement } from "../ConfigProvider/AppElementContext.mjs";
|
|
|
4
4
|
import { styleProps } from "../styles/stylex/props.mjs";
|
|
5
5
|
import { focusRing } from "../styles/stylex/focusRing.mjs";
|
|
6
6
|
import { useNativeButton } from "../hooks/useNativeButton.mjs";
|
|
7
|
+
import { mergeRefs, useMergeRefs } from "../utils/mergeRefs.mjs";
|
|
7
8
|
import { useLayerZIndex } from "../internal/zIndex/useLayerZIndex.mjs";
|
|
8
9
|
import { backdropTransition, modalMotionConfig } from "./constants.mjs";
|
|
9
10
|
import { ModalLayerProvider, useModalLayer } from "./ModalLayerContext.mjs";
|
|
@@ -14,7 +15,6 @@ import clsx from "clsx";
|
|
|
14
15
|
import * as stylex from "@stylexjs/stylex";
|
|
15
16
|
import { X } from "lucide-react";
|
|
16
17
|
import { mergeProps } from "@base-ui/react/merge-props";
|
|
17
|
-
import { mergeRefs, useMergeRefs } from "react-merge-refs";
|
|
18
18
|
import { Dialog } from "@base-ui/react/dialog";
|
|
19
19
|
import { AnimatePresence } from "motion/react";
|
|
20
20
|
//#region src/Modal/atoms.tsx
|
|
@@ -141,13 +141,13 @@ const ModalPopupImpl = ({ className, children, width, style, motionProps, panelC
|
|
|
141
141
|
children: open ? /* @__PURE__ */ createElement(Motion.div, {
|
|
142
142
|
...modalMotionConfig,
|
|
143
143
|
...motionProps,
|
|
144
|
-
className: clsx(stylex.props(styles.popupInner, panelXstyle).className, panelClassName),
|
|
145
144
|
key: "modal-popup-panel",
|
|
146
145
|
style: {
|
|
147
146
|
maxWidth: width ?? void 0,
|
|
148
147
|
transition: "none",
|
|
149
148
|
...style
|
|
150
|
-
}
|
|
149
|
+
},
|
|
150
|
+
className: clsx(stylex.props(styles.popupInner, panelXstyle).className, panelClassName)
|
|
151
151
|
}, children) : null
|
|
152
152
|
})
|
|
153
153
|
});
|
package/es/Modal/atoms.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atoms.mjs","names":[],"sources":["../../src/Modal/atoms.tsx"],"sourcesContent":["'use client';\n\nimport { Dialog } from '@base-ui/react/dialog';\nimport { mergeProps } from '@base-ui/react/merge-props';\nimport * as stylex from '@stylexjs/stylex';\nimport clsx from 'clsx';\nimport { X } from 'lucide-react';\nimport { AnimatePresence } from 'motion/react';\nimport type React from 'react';\nimport {\n cloneElement,\n createContext,\n isValidElement,\n use,\n useCallback,\n useEffect,\n useMemo,\n useState,\n} from 'react';\nimport { mergeRefs, useMergeRefs } from 'react-merge-refs';\n\nimport { useAppElement } from '@/ConfigProvider/AppElementContext';\nimport { useNativeButton } from '@/hooks/useNativeButton';\nimport { useMotionComponent } from '@/MotionProvider';\nimport { focusRing } from '@/styles/stylex/focusRing';\nimport { styleProps } from '@/styles/stylex/props';\n\nimport { useLayerZIndex } from '../internal/zIndex';\nimport { backdropTransition, modalMotionConfig } from './constants';\nimport { ModalLayerProvider, useModalLayer } from './ModalLayerContext';\nimport { styles } from './style';\n\ntype XStyle = Parameters<typeof styleProps>[0];\n\nconst mergeStateClassName = <TState,>(\n xstyle: XStyle,\n className: string | ((state: TState) => string | undefined) | undefined,\n) => {\n const base = stylex.props(xstyle).className;\n if (typeof className === 'function') return (state: TState) => clsx(base, className(state));\n return clsx(base, className);\n};\n\n// --- Animation Contexts (granular to minimize re-renders) ---\n\n// State: open boolean, null = non-animated mode\nconst ModalOpenContext = createContext<boolean | null>(null);\n\n// Actions: stable callbacks, null = non-animated mode\ninterface ModalAnimationActions {\n onExitComplete: () => void;\n}\nconst ModalActionsContext = createContext<ModalAnimationActions | null>(null);\n\nexport const useModalOpen = () => use(ModalOpenContext);\nexport const useModalActions = () => use(ModalActionsContext);\n\n// --- Root ---\nexport type ModalRootProps = Dialog.Root.Props & {\n onExitComplete?: () => void;\n zIndex?: number;\n};\n\nconst AnimatedModalRoot = ({\n open,\n children,\n onExitComplete: onExitCompleteProp,\n zIndex: explicitZIndex,\n ...rest\n}: Omit<ModalRootProps, 'open'> & { open: boolean }) => {\n const [isPresent, setIsPresent] = useState(!!open);\n\n useEffect(() => {\n if (open) setIsPresent(true);\n }, [open]);\n\n const handleExitComplete = useCallback(() => {\n setIsPresent(false);\n onExitCompleteProp?.();\n }, [onExitCompleteProp]);\n\n const actions = useMemo(() => ({ onExitComplete: handleExitComplete }), [handleExitComplete]);\n\n const { zIndex, ref: popupRef } = useLayerZIndex<HTMLDivElement>('modal', explicitZIndex);\n const layer = useMemo(\n () => ({ popupRef: popupRef as (node: HTMLElement | null) => void, zIndex }),\n [zIndex, popupRef],\n );\n\n if (!isPresent) return null;\n\n return (\n <ModalOpenContext value={open}>\n <ModalActionsContext value={actions}>\n <ModalLayerProvider value={layer}>\n <Dialog.Root modal open {...rest}>\n {children}\n </Dialog.Root>\n </ModalLayerProvider>\n </ModalActionsContext>\n </ModalOpenContext>\n );\n};\n\nconst NonAnimatedModalRoot = ({ zIndex: explicitZIndex, children, ...rest }: ModalRootProps) => {\n const { zIndex, ref: popupRef } = useLayerZIndex<HTMLDivElement>('modal', explicitZIndex);\n const layer = useMemo(\n () => ({ popupRef: popupRef as (node: HTMLElement | null) => void, zIndex }),\n [zIndex, popupRef],\n );\n return (\n <ModalLayerProvider value={layer}>\n <Dialog.Root modal {...rest}>\n {children}\n </Dialog.Root>\n </ModalLayerProvider>\n );\n};\n\nexport const ModalRoot = ({ open, onExitComplete, ...rest }: ModalRootProps) => {\n if (open !== undefined) {\n return <AnimatedModalRoot open={open} onExitComplete={onExitComplete} {...rest} />;\n }\n return <NonAnimatedModalRoot {...rest} />;\n};\n\n// --- Portal ---\nexport type ModalPortalProps = React.ComponentProps<typeof Dialog.Portal> & {\n container?: HTMLElement | null;\n};\nexport const ModalPortal = ({ container, ...rest }: ModalPortalProps) => {\n const appElement = useAppElement();\n return <Dialog.Portal container={container ?? appElement ?? undefined} {...rest} />;\n};\n\n// --- Viewport ---\nexport type ModalViewportProps = React.ComponentProps<typeof Dialog.Viewport>;\nexport const ModalViewport = ({ className, ...rest }: ModalViewportProps) => (\n <Dialog.Viewport\n {...rest}\n className={mergeStateClassName(styles.viewport, className as any) as any}\n />\n);\n\n// --- Backdrop ---\nexport type ModalBackdropProps = React.ComponentProps<typeof Dialog.Backdrop>;\nexport const ModalBackdrop = ({ className, style, ...rest }: ModalBackdropProps) => {\n const open = useModalOpen();\n const layer = useModalLayer();\n const Motion = useMotionComponent();\n const layerStyle = layer?.zIndex !== undefined ? { zIndex: layer.zIndex } : undefined;\n\n if (open !== null) {\n return (\n <Dialog.Backdrop\n {...rest}\n className={clsx(stylex.props(styles.backdrop).className, className as string)}\n style={{ ...layerStyle, ...style, transition: 'none' }}\n render={\n <Motion.div\n animate={{ opacity: open ? 1 : 0 }}\n initial={{ opacity: 0 }}\n transition={backdropTransition}\n />\n }\n />\n );\n }\n\n return (\n <Dialog.Backdrop\n {...rest}\n className={mergeStateClassName(styles.backdrop, className as any) as any}\n style={{ ...layerStyle, ...style }}\n />\n );\n};\n\n// --- Popup ---\nexport type ModalPopupProps = React.ComponentProps<typeof Dialog.Popup> & {\n motionProps?: Record<string, any>;\n panelClassName?: string;\n popupStyle?: React.CSSProperties;\n width?: number | string;\n};\nexport const ModalPopupImpl = ({\n className,\n children,\n width,\n style,\n motionProps,\n panelClassName,\n panelXstyle,\n popupStyle,\n ref: forwardedRef,\n xstyle,\n ...rest\n}: ModalPopupProps & { panelXstyle?: XStyle; xstyle?: XStyle }) => {\n const open = useModalOpen();\n const actions = useModalActions();\n const layer = useModalLayer();\n const Motion = useMotionComponent();\n const popupZIndexStyle = layer?.zIndex !== undefined ? { zIndex: layer.zIndex + 1 } : undefined;\n const composedRef = useMergeRefs([forwardedRef, layer?.popupRef]);\n\n if (open !== null && actions) {\n return (\n <Dialog.Popup\n {...rest}\n className={clsx(stylex.props(styles.popup, xstyle).className, className as string)}\n ref={composedRef as any}\n style={{ ...popupZIndexStyle, ...popupStyle }}\n >\n <AnimatePresence onExitComplete={actions.onExitComplete}>\n {open ? (\n <Motion.div\n {...modalMotionConfig}\n {...motionProps}\n className={clsx(stylex.props(styles.popupInner, panelXstyle).className, panelClassName)}\n key=\"modal-popup-panel\"\n style={{ maxWidth: width ?? undefined, transition: 'none', ...style }}\n >\n {children}\n </Motion.div>\n ) : null}\n </AnimatePresence>\n </Dialog.Popup>\n );\n }\n\n return (\n <Dialog.Popup\n {...rest}\n className={mergeStateClassName([styles.popup, xstyle], className as any) as any}\n ref={composedRef as any}\n style={{ ...popupZIndexStyle, ...popupStyle }}\n >\n <div\n {...styleProps([styles.popupInner, panelXstyle], panelClassName, {\n maxWidth: width ?? undefined,\n ...style,\n })}\n >\n {children}\n </div>\n </Dialog.Popup>\n );\n};\n\nexport const ModalPopup: React.FC<ModalPopupProps> = ModalPopupImpl;\n\n// --- Header ---\nexport type ModalHeaderProps = React.HTMLAttributes<HTMLDivElement> & {\n ref?: React.Ref<HTMLDivElement>;\n};\nexport const ModalHeaderImpl = ({\n className,\n style,\n xstyle,\n ...rest\n}: ModalHeaderProps & { xstyle?: XStyle }) => (\n <div {...rest} {...styleProps([styles.header, xstyle], className, style)} />\n);\nexport const ModalHeader: React.FC<ModalHeaderProps> = ModalHeaderImpl;\n\n// --- Title ---\nexport type ModalTitleProps = React.ComponentProps<typeof Dialog.Title>;\nexport const ModalTitleImpl = ({\n className,\n xstyle,\n ...rest\n}: ModalTitleProps & { xstyle?: XStyle }) => (\n <Dialog.Title\n {...rest}\n className={mergeStateClassName([styles.title, xstyle], className as any) as any}\n />\n);\nexport const ModalTitle: React.FC<ModalTitleProps> = ModalTitleImpl;\n\n// --- Description ---\nexport type ModalDescriptionProps = React.ComponentProps<typeof Dialog.Description>;\nexport const ModalDescription: React.FC<ModalDescriptionProps> = Dialog.Description;\n\n// --- Content ---\nexport type ModalContentProps = React.HTMLAttributes<HTMLDivElement> & {\n ref?: React.Ref<HTMLDivElement>;\n};\nexport const ModalContentImpl = ({\n className,\n style,\n xstyle,\n ...rest\n}: ModalContentProps & { xstyle?: XStyle }) => (\n <div {...rest} {...styleProps([styles.content, xstyle], className, style)} />\n);\nexport const ModalContent: React.FC<ModalContentProps> = ModalContentImpl;\n\n// --- Footer ---\nexport type ModalFooterProps = React.HTMLAttributes<HTMLDivElement> & {\n ref?: React.Ref<HTMLDivElement>;\n};\nexport const ModalFooterImpl = ({\n className,\n style,\n xstyle,\n ...rest\n}: ModalFooterProps & { xstyle?: XStyle }) => (\n <div {...rest} {...styleProps([styles.footer, xstyle], className, style)} />\n);\nexport const ModalFooter: React.FC<ModalFooterProps> = ModalFooterImpl;\n\n// --- Close ---\nexport type ModalCloseProps = React.ComponentProps<typeof Dialog.Close>;\nexport const ModalCloseImpl = ({\n className,\n children,\n xstyle,\n ...rest\n}: ModalCloseProps & { xstyle?: XStyle }) => (\n <Dialog.Close\n {...rest}\n className={\n mergeStateClassName(\n [styles.closeInline, styles.close, focusRing.info, xstyle],\n className as any,\n ) as any\n }\n >\n {children ?? <X size={16} />}\n </Dialog.Close>\n);\nexport const ModalClose: React.FC<ModalCloseProps> = ModalCloseImpl;\n\n// --- Trigger ---\nexport type ModalTriggerProps = Omit<\n React.ComponentPropsWithRef<typeof Dialog.Trigger>,\n 'children' | 'render'\n> & {\n children?: React.ReactNode;\n nativeButton?: boolean;\n};\n\nexport const ModalTrigger = ({\n children,\n className,\n nativeButton,\n ref: refProp,\n ...rest\n}: ModalTriggerProps) => {\n const { isNativeButtonTriggerElement, resolvedNativeButton } = useNativeButton({\n children,\n nativeButton,\n });\n\n const renderer = (props: any) => {\n const resolvedProps = (() => {\n if (isNativeButtonTriggerElement) return props as any;\n // eslint-disable-next-line unused-imports/no-unused-vars\n const { type, ...restProps } = props as any;\n return restProps;\n })();\n\n const mergedProps = mergeProps((children as any).props, resolvedProps);\n return cloneElement(children as any, {\n ...mergedProps,\n ref: mergeRefs([(children as any).ref, (props as any).ref, refProp]),\n });\n };\n\n if (isValidElement(children)) {\n return (\n <Dialog.Trigger\n {...rest}\n className={className}\n nativeButton={resolvedNativeButton}\n render={renderer as any}\n />\n );\n }\n\n return (\n <Dialog.Trigger\n {...rest}\n className={className}\n nativeButton={resolvedNativeButton}\n ref={refProp as any}\n >\n {children}\n </Dialog.Trigger>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAqBA,MAAM,uBAAgC,QAAgB,cAA4E;CAChI,MAAM,OAAO,OAAO,MAAM,MAAM,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AM,cAAc,WAAY,SAAiB,OAAO,aAAa;EACrE,OAAO,aAAa,UAAiB;GACnC,GAAG;GACH,KAAK,UAAU;IAAE,SAAiB;IAAM,MAAc;IAAK;GAAO,CAAC;EACrE,CAAC;CACH;CACA,IAAI,eAAe,QAAQ,GACzB,OAAO,oBAAC,OAAO,SAAR;EAAgB,GAAI;EAAiB;EAAW,cAAc;EAAsB,QAAQ;CAAkB,CAAA;CAEvH,OAAO,oBAAC,OAAO,SAAR;EAAgB,GAAI;EAAiB;EAAW,cAAc;EAAsB,KAAK;EAC3F;CACa,CAAA;AACpB"}
|
|
1
|
+
{"version":3,"file":"atoms.mjs","names":[],"sources":["../../src/Modal/atoms.tsx"],"sourcesContent":["'use client';\n\nimport { Dialog } from '@base-ui/react/dialog';\nimport { mergeProps } from '@base-ui/react/merge-props';\nimport * as stylex from '@stylexjs/stylex';\nimport clsx from 'clsx';\nimport { X } from 'lucide-react';\nimport { AnimatePresence } from 'motion/react';\nimport type React from 'react';\nimport {\n cloneElement,\n createContext,\n isValidElement,\n use,\n useCallback,\n useEffect,\n useMemo,\n useState,\n} from 'react';\n\nimport { useAppElement } from '@/ConfigProvider/AppElementContext';\nimport { useNativeButton } from '@/hooks/useNativeButton';\nimport { useMotionComponent } from '@/MotionProvider';\nimport { focusRing } from '@/styles/stylex/focusRing';\nimport { styleProps } from '@/styles/stylex/props';\nimport { mergeRefs, useMergeRefs } from '@/utils/mergeRefs';\n\nimport { useLayerZIndex } from '../internal/zIndex';\nimport { backdropTransition, modalMotionConfig } from './constants';\nimport { ModalLayerProvider, useModalLayer } from './ModalLayerContext';\nimport { styles } from './style';\n\ntype XStyle = Parameters<typeof styleProps>[0];\n\nconst mergeStateClassName = <TState,>(\n xstyle: XStyle,\n className: string | ((state: TState) => string | undefined) | undefined,\n) => {\n const base = stylex.props(xstyle).className;\n if (typeof className === 'function') return (state: TState) => clsx(base, className(state));\n return clsx(base, className);\n};\n\n// --- Animation Contexts (granular to minimize re-renders) ---\n\n// State: open boolean, null = non-animated mode\nconst ModalOpenContext = createContext<boolean | null>(null);\n\n// Actions: stable callbacks, null = non-animated mode\ninterface ModalAnimationActions {\n onExitComplete: () => void;\n}\nconst ModalActionsContext = createContext<ModalAnimationActions | null>(null);\n\nexport const useModalOpen = () => use(ModalOpenContext);\nexport const useModalActions = () => use(ModalActionsContext);\n\n// --- Root ---\nexport type ModalRootProps = Dialog.Root.Props & {\n onExitComplete?: () => void;\n zIndex?: number;\n};\n\nconst AnimatedModalRoot = ({\n open,\n children,\n onExitComplete: onExitCompleteProp,\n zIndex: explicitZIndex,\n ...rest\n}: Omit<ModalRootProps, 'open'> & { open: boolean }) => {\n const [isPresent, setIsPresent] = useState(!!open);\n\n useEffect(() => {\n if (open) setIsPresent(true);\n }, [open]);\n\n const handleExitComplete = useCallback(() => {\n setIsPresent(false);\n onExitCompleteProp?.();\n }, [onExitCompleteProp]);\n\n const actions = useMemo(() => ({ onExitComplete: handleExitComplete }), [handleExitComplete]);\n\n const { zIndex, ref: popupRef } = useLayerZIndex<HTMLDivElement>('modal', explicitZIndex);\n const layer = useMemo(\n () => ({ popupRef: popupRef as (node: HTMLElement | null) => void, zIndex }),\n [zIndex, popupRef],\n );\n\n if (!isPresent) return null;\n\n return (\n <ModalOpenContext value={open}>\n <ModalActionsContext value={actions}>\n <ModalLayerProvider value={layer}>\n <Dialog.Root modal open {...rest}>\n {children}\n </Dialog.Root>\n </ModalLayerProvider>\n </ModalActionsContext>\n </ModalOpenContext>\n );\n};\n\nconst NonAnimatedModalRoot = ({ zIndex: explicitZIndex, children, ...rest }: ModalRootProps) => {\n const { zIndex, ref: popupRef } = useLayerZIndex<HTMLDivElement>('modal', explicitZIndex);\n const layer = useMemo(\n () => ({ popupRef: popupRef as (node: HTMLElement | null) => void, zIndex }),\n [zIndex, popupRef],\n );\n return (\n <ModalLayerProvider value={layer}>\n <Dialog.Root modal {...rest}>\n {children}\n </Dialog.Root>\n </ModalLayerProvider>\n );\n};\n\nexport const ModalRoot = ({ open, onExitComplete, ...rest }: ModalRootProps) => {\n if (open !== undefined) {\n return <AnimatedModalRoot open={open} onExitComplete={onExitComplete} {...rest} />;\n }\n return <NonAnimatedModalRoot {...rest} />;\n};\n\n// --- Portal ---\nexport type ModalPortalProps = React.ComponentProps<typeof Dialog.Portal> & {\n container?: HTMLElement | null;\n};\nexport const ModalPortal = ({ container, ...rest }: ModalPortalProps) => {\n const appElement = useAppElement();\n return <Dialog.Portal container={container ?? appElement ?? undefined} {...rest} />;\n};\n\n// --- Viewport ---\nexport type ModalViewportProps = React.ComponentProps<typeof Dialog.Viewport>;\nexport const ModalViewport = ({ className, ...rest }: ModalViewportProps) => (\n <Dialog.Viewport\n {...rest}\n className={mergeStateClassName(styles.viewport, className as any) as any}\n />\n);\n\n// --- Backdrop ---\nexport type ModalBackdropProps = React.ComponentProps<typeof Dialog.Backdrop>;\nexport const ModalBackdrop = ({ className, style, ...rest }: ModalBackdropProps) => {\n const open = useModalOpen();\n const layer = useModalLayer();\n const Motion = useMotionComponent();\n const layerStyle = layer?.zIndex !== undefined ? { zIndex: layer.zIndex } : undefined;\n\n if (open !== null) {\n return (\n <Dialog.Backdrop\n {...rest}\n className={clsx(stylex.props(styles.backdrop).className, className as string)}\n style={{ ...layerStyle, ...style, transition: 'none' }}\n render={\n <Motion.div\n animate={{ opacity: open ? 1 : 0 }}\n initial={{ opacity: 0 }}\n transition={backdropTransition}\n />\n }\n />\n );\n }\n\n return (\n <Dialog.Backdrop\n {...rest}\n className={mergeStateClassName(styles.backdrop, className as any) as any}\n style={{ ...layerStyle, ...style }}\n />\n );\n};\n\n// --- Popup ---\nexport type ModalPopupProps = React.ComponentProps<typeof Dialog.Popup> & {\n motionProps?: Record<string, any>;\n panelClassName?: string;\n popupStyle?: React.CSSProperties;\n width?: number | string;\n};\nexport const ModalPopupImpl = ({\n className,\n children,\n width,\n style,\n motionProps,\n panelClassName,\n panelXstyle,\n popupStyle,\n ref: forwardedRef,\n xstyle,\n ...rest\n}: ModalPopupProps & { panelXstyle?: XStyle; xstyle?: XStyle }) => {\n const open = useModalOpen();\n const actions = useModalActions();\n const layer = useModalLayer();\n const Motion = useMotionComponent();\n const popupZIndexStyle = layer?.zIndex !== undefined ? { zIndex: layer.zIndex + 1 } : undefined;\n const composedRef = useMergeRefs([forwardedRef, layer?.popupRef]);\n\n if (open !== null && actions) {\n return (\n <Dialog.Popup\n {...rest}\n className={clsx(stylex.props(styles.popup, xstyle).className, className as string)}\n ref={composedRef as any}\n style={{ ...popupZIndexStyle, ...popupStyle }}\n >\n <AnimatePresence onExitComplete={actions.onExitComplete}>\n {open ? (\n <Motion.div\n {...modalMotionConfig}\n {...motionProps}\n key=\"modal-popup-panel\"\n style={{ maxWidth: width ?? undefined, transition: 'none', ...style }}\n className={clsx(\n stylex.props(styles.popupInner, panelXstyle).className,\n panelClassName,\n )}\n >\n {children}\n </Motion.div>\n ) : null}\n </AnimatePresence>\n </Dialog.Popup>\n );\n }\n\n return (\n <Dialog.Popup\n {...rest}\n className={mergeStateClassName([styles.popup, xstyle], className as any) as any}\n ref={composedRef as any}\n style={{ ...popupZIndexStyle, ...popupStyle }}\n >\n <div\n {...styleProps([styles.popupInner, panelXstyle], panelClassName, {\n maxWidth: width ?? undefined,\n ...style,\n })}\n >\n {children}\n </div>\n </Dialog.Popup>\n );\n};\n\nexport const ModalPopup: React.FC<ModalPopupProps> = ModalPopupImpl;\n\n// --- Header ---\nexport type ModalHeaderProps = React.HTMLAttributes<HTMLDivElement> & {\n ref?: React.Ref<HTMLDivElement>;\n};\nexport const ModalHeaderImpl = ({\n className,\n style,\n xstyle,\n ...rest\n}: ModalHeaderProps & { xstyle?: XStyle }) => (\n <div {...rest} {...styleProps([styles.header, xstyle], className, style)} />\n);\nexport const ModalHeader: React.FC<ModalHeaderProps> = ModalHeaderImpl;\n\n// --- Title ---\nexport type ModalTitleProps = React.ComponentProps<typeof Dialog.Title>;\nexport const ModalTitleImpl = ({\n className,\n xstyle,\n ...rest\n}: ModalTitleProps & { xstyle?: XStyle }) => (\n <Dialog.Title\n {...rest}\n className={mergeStateClassName([styles.title, xstyle], className as any) as any}\n />\n);\nexport const ModalTitle: React.FC<ModalTitleProps> = ModalTitleImpl;\n\n// --- Description ---\nexport type ModalDescriptionProps = React.ComponentProps<typeof Dialog.Description>;\nexport const ModalDescription: React.FC<ModalDescriptionProps> = Dialog.Description;\n\n// --- Content ---\nexport type ModalContentProps = React.HTMLAttributes<HTMLDivElement> & {\n ref?: React.Ref<HTMLDivElement>;\n};\nexport const ModalContentImpl = ({\n className,\n style,\n xstyle,\n ...rest\n}: ModalContentProps & { xstyle?: XStyle }) => (\n <div {...rest} {...styleProps([styles.content, xstyle], className, style)} />\n);\nexport const ModalContent: React.FC<ModalContentProps> = ModalContentImpl;\n\n// --- Footer ---\nexport type ModalFooterProps = React.HTMLAttributes<HTMLDivElement> & {\n ref?: React.Ref<HTMLDivElement>;\n};\nexport const ModalFooterImpl = ({\n className,\n style,\n xstyle,\n ...rest\n}: ModalFooterProps & { xstyle?: XStyle }) => (\n <div {...rest} {...styleProps([styles.footer, xstyle], className, style)} />\n);\nexport const ModalFooter: React.FC<ModalFooterProps> = ModalFooterImpl;\n\n// --- Close ---\nexport type ModalCloseProps = React.ComponentProps<typeof Dialog.Close>;\nexport const ModalCloseImpl = ({\n className,\n children,\n xstyle,\n ...rest\n}: ModalCloseProps & { xstyle?: XStyle }) => (\n <Dialog.Close\n {...rest}\n className={\n mergeStateClassName(\n [styles.closeInline, styles.close, focusRing.info, xstyle],\n className as any,\n ) as any\n }\n >\n {children ?? <X size={16} />}\n </Dialog.Close>\n);\nexport const ModalClose: React.FC<ModalCloseProps> = ModalCloseImpl;\n\n// --- Trigger ---\nexport type ModalTriggerProps = Omit<\n React.ComponentPropsWithRef<typeof Dialog.Trigger>,\n 'children' | 'render'\n> & {\n children?: React.ReactNode;\n nativeButton?: boolean;\n};\n\nexport const ModalTrigger = ({\n children,\n className,\n nativeButton,\n ref: refProp,\n ...rest\n}: ModalTriggerProps) => {\n const { isNativeButtonTriggerElement, resolvedNativeButton } = useNativeButton({\n children,\n nativeButton,\n });\n\n const renderer = (props: any) => {\n const resolvedProps = (() => {\n if (isNativeButtonTriggerElement) return props as any;\n // eslint-disable-next-line unused-imports/no-unused-vars\n const { type, ...restProps } = props as any;\n return restProps;\n })();\n\n const mergedProps = mergeProps((children as any).props, resolvedProps);\n return cloneElement(children as any, {\n ...mergedProps,\n ref: mergeRefs([(children as any).ref, (props as any).ref, refProp]),\n });\n };\n\n if (isValidElement(children)) {\n return (\n <Dialog.Trigger\n {...rest}\n className={className}\n nativeButton={resolvedNativeButton}\n render={renderer as any}\n />\n );\n }\n\n return (\n <Dialog.Trigger\n {...rest}\n className={className}\n nativeButton={resolvedNativeButton}\n ref={refProp as any}\n >\n {children}\n </Dialog.Trigger>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAqBA,MAAM,uBAAgC,QAAgB,cAA4E;CAChI,MAAM,OAAO,OAAO,MAAM,MAAM,CAAC,CAAC;CAClC,IAAI,OAAO,cAAc,YAAY,QAAQ,UAAkB,KAAK,MAAM,UAAU,KAAK,CAAC;CAC1F,OAAO,KAAK,MAAM,SAAS;AAC7B;AAKA,MAAM,mBAAmB,cAA8B,IAAI;AAM3D,MAAM,sBAAsB,cAA4C,IAAI;AAC5E,MAAa,qBAAqB,IAAI,gBAAgB;AACtD,MAAa,wBAAwB,IAAI,mBAAmB;AAO5D,MAAM,qBAAqB,EACzB,MACA,UACA,gBAAgB,oBAChB,QAAQ,gBACR,GAAG,WAGC;CACJ,MAAM,CAAC,WAAW,gBAAgB,SAAS,CAAC,CAAC,IAAI;CACjD,gBAAgB;EACd,IAAI,MAAM,aAAa,IAAI;CAC7B,GAAG,CAAC,IAAI,CAAC;CACT,MAAM,qBAAqB,kBAAkB;EAC3C,aAAa,KAAK;EAClB,qBAAqB;CACvB,GAAG,CAAC,kBAAkB,CAAC;CACvB,MAAM,UAAU,eAAe,EAC7B,g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AAD;CAAK,GAAI;CAAM,GAAI,WAAW,CAAC,OAAO,QAAQ,MAAM,GAAG,WAAW,KAAK;AAAI,CAAA;AACjF,MAAa,cAA0C;AAIvD,MAAa,kBAAkB,EAC7B,WACA,UACA,QACA,GAAG,WAGC,oBAAC,OAAO,OAAR;CAAc,GAAI;CAAM,WAAW,oBAAoB;EAAC,OAAO;EAAa,OAAO;EAAO,UAAU;EAAM;CAAM,GAAG,SAAgB;CACpI,UAAA,YAAY,oBAAC,GAAD,EAAG,MAAM,GAAK,CAAA;AACf,CAAA;AAChB,MAAa,aAAwC;AAOrD,MAAa,gBAAgB,EAC3B,UACA,WACA,cACA,KAAK,SACL,GAAG,WACoB;CACvB,MAAM,EACJ,8BACA,yBACE,gBAAgB;EAClB;EACA;CACF,CAAC;CACD,MAAM,YAAY,UAAe;EAC/B,MAAM,uBAAuB;GAC3B,IAAI,8BAA8B,OAAO;GAEzC,MAAM,EACJ,MACA,GAAG,cACD;GACJ,OAAO;EACT,EAAA,CAAG;EACH,MAAM,cAAc,WAAY,SAAiB,OAAO,aAAa;EACrE,OAAO,aAAa,UAAiB;GACnC,GAAG;GACH,KAAK,UAAU;IAAE,SAAiB;IAAM,MAAc;IAAK;GAAO,CAAC;EACrE,CAAC;CACH;CACA,IAAI,eAAe,QAAQ,GACzB,OAAO,oBAAC,OAAO,SAAR;EAAgB,GAAI;EAAiB;EAAW,cAAc;EAAsB,QAAQ;CAAkB,CAAA;CAEvH,OAAO,oBAAC,OAAO,SAAR;EAAgB,GAAI;EAAiB;EAAW,cAAc;EAAsB,KAAK;EAC3F;CACa,CAAA;AACpB"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { styleProps } from "../styles/stylex/props.mjs";
|
|
3
3
|
import { useEventCallback } from "../hooks/useEventCallback.mjs";
|
|
4
|
+
import { useControlledState } from "../hooks/useControlledState.mjs";
|
|
4
5
|
import Select from "../Select/Select.mjs";
|
|
5
6
|
import { clampPage, getPageCount, getPaginationItems } from "./helpers.mjs";
|
|
6
7
|
import { styles } from "./style.mjs";
|
|
@@ -8,7 +9,6 @@ import { createElement, memo, useEffect, useRef, useState } from "react";
|
|
|
8
9
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
10
|
import * as stylex from "@stylexjs/stylex";
|
|
10
11
|
import { ChevronLeft, ChevronRight } from "lucide-react";
|
|
11
|
-
import useControlledState from "use-merge-value";
|
|
12
12
|
//#region src/Pagination/Pagination.tsx
|
|
13
13
|
const Pagination = memo(({ className, current, defaultCurrent = 1, defaultPageSize = 10, disabled, hideOnSinglePage, onChange, onPageSizeChange, pageSize, pageSizeOptions = [
|
|
14
14
|
10,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Pagination.mjs","names":[],"sources":["../../src/Pagination/Pagination.tsx"],"sourcesContent":["'use client';\n\nimport * as stylex from '@stylexjs/stylex';\nimport { ChevronLeft, ChevronRight } from 'lucide-react';\nimport { memo, useEffect, useRef, useState } from 'react';\nimport useControlledState from '
|
|
1
|
+
{"version":3,"file":"Pagination.mjs","names":[],"sources":["../../src/Pagination/Pagination.tsx"],"sourcesContent":["'use client';\n\nimport * as stylex from '@stylexjs/stylex';\nimport { ChevronLeft, ChevronRight } from 'lucide-react';\nimport { memo, useEffect, useRef, useState } from 'react';\n\nimport { useControlledState } from '@/hooks/useControlledState';\nimport { useEventCallback } from '@/hooks/useEventCallback';\nimport Select from '@/Select';\nimport { styleProps } from '@/styles/stylex/props';\n\nimport { clampPage, getPageCount, getPaginationItems } from './helpers';\nimport { styles } from './style';\nimport type { PaginationProps } from './type';\n\nconst Pagination = memo<PaginationProps>(\n ({\n className,\n current,\n defaultCurrent = 1,\n defaultPageSize = 10,\n disabled,\n hideOnSinglePage,\n onChange,\n onPageSizeChange,\n pageSize,\n pageSizeOptions = [10, 20, 50, 100],\n ref,\n showSizeChanger = false,\n showTotal,\n size = 'middle',\n style,\n total,\n ...rest\n }) => {\n const [mergedPageSize, setMergedPageSize] = useControlledState(defaultPageSize, {\n value: pageSize,\n });\n const pageCount = getPageCount(total, mergedPageSize);\n const [mergedCurrent, setMergedCurrent] = useControlledState(defaultCurrent, {\n value: current,\n });\n const onChangeStable = useEventCallback((nextCurrent: number, nextPageSize: number) => {\n onChange?.(nextCurrent, nextPageSize);\n });\n\n const pendingNotifyRef = useRef<{ current: number; pageSize: number } | null>(null);\n const [prevPageCount, setPrevPageCount] = useState(pageCount);\n\n if (pageCount !== prevPageCount) {\n setPrevPageCount(pageCount);\n\n if (mergedCurrent > pageCount && pageCount >= 1) {\n setMergedCurrent(pageCount);\n pendingNotifyRef.current = { current: pageCount, pageSize: mergedPageSize };\n }\n }\n\n useEffect(() => {\n if (!pendingNotifyRef.current) return;\n\n const { current: nextCurrent, pageSize: nextPageSize } = pendingNotifyRef.current;\n pendingNotifyRef.current = null;\n onChangeStable(nextCurrent, nextPageSize);\n });\n\n const displayCurrent = clampPage(mergedCurrent, pageCount);\n\n if (hideOnSinglePage && pageCount <= 1) return null;\n\n const commitCurrent = (nextCurrent: number, nextPageSize: number) => {\n setMergedCurrent(nextCurrent);\n onChange?.(nextCurrent, nextPageSize);\n };\n\n const goTo = (page: number) => {\n commitCurrent(clampPage(page, pageCount), mergedPageSize);\n };\n\n const handlePageSizeChange = (value: string) => {\n const nextSize = Number(value);\n const nextPageCount = getPageCount(total, nextSize);\n const nextCurrent = clampPage(displayCurrent, nextPageCount);\n\n setMergedPageSize(nextSize);\n commitCurrent(nextCurrent, nextSize);\n onPageSizeChange?.(nextCurrent, nextSize);\n };\n\n const buttonProps = stylex.props(styles.button, size === 'small' && styles.small);\n const items = getPaginationItems(displayCurrent, pageCount);\n const rangeStart = total === 0 ? 0 : (displayCurrent - 1) * mergedPageSize + 1;\n const rangeEnd = Math.min(displayCurrent * mergedPageSize, total);\n\n return (\n <nav\n aria-label=\"Pagination\"\n ref={ref}\n role=\"navigation\"\n {...styleProps(styles.root, className, style)}\n {...rest}\n >\n {showTotal && (\n <span {...stylex.props(styles.total)}>{showTotal(total, [rangeStart, rangeEnd])}</span>\n )}\n <button\n aria-label=\"Previous page\"\n {...buttonProps}\n disabled={disabled || displayCurrent <= 1}\n type=\"button\"\n onClick={() => goTo(displayCurrent - 1)}\n >\n <ChevronLeft size={size === 'small' ? 14 : 16} />\n </button>\n {items.map((item) =>\n typeof item === 'number' ? (\n <button\n aria-current={item === displayCurrent ? 'page' : undefined}\n {...buttonProps}\n disabled={disabled}\n key={item}\n type=\"button\"\n onClick={() => goTo(item)}\n >\n {item}\n </button>\n ) : (\n <span\n key={item}\n {...stylex.props(styles.ellipsis, size === 'small' && styles.smallEllipsis)}\n >\n ···\n </span>\n ),\n )}\n <button\n aria-label=\"Next page\"\n {...buttonProps}\n disabled={disabled || displayCurrent >= pageCount}\n type=\"button\"\n onClick={() => goTo(displayCurrent + 1)}\n >\n <ChevronRight size={size === 'small' ? 14 : 16} />\n </button>\n {showSizeChanger && (\n <Select\n disabled={disabled}\n size={size === 'small' ? 'small' : 'middle'}\n style={{ flex: 'none', marginInlineStart: 8, width: 'auto' }}\n value={String(mergedPageSize)}\n options={pageSizeOptions.map((option) => ({\n label: `${option} / page`,\n value: String(option),\n }))}\n onChange={handlePageSizeChange}\n />\n )}\n </nav>\n );\n },\n);\n\nPagination.displayName = 'Pagination';\n\nexport default Pagination;\n"],"mappings":";;;;;;;;;;;;AAYA,MAAM,aAAa,MAAuB,EACxC,WACA,SACA,iBAAiB,GACjB,kBAAkB,IAClB,UACA,kBACA,UACA,kBACA,UACA,kBAAkB;CAAC;CAAI;CAAI;CAAI;AAAG,GAClC,KACA,kBAAkB,OAClB,WACA,OAAO,UACP,OACA,OACA,GAAG,WACC;CACJ,MAAM,CAAC,gBAAgB,qBAAqB,mBAAmB,iBAAiB,EAC9E,OAAO,SACT,CAAC;CACD,MAAM,YAAY,aAAa,OAAO,cAAc;CACpD,MAAM,CAAC,eAAe,oBAAoB,mBAAmB,gBAAgB,EAC3E,OAAO,QACT,CAAC;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eButton } from "../hooks/useNativeButton.mjs";
|
|
3
|
+
import { mergeRefs } from "../utils/mergeRefs.mjs";
|
|
3
4
|
import { parseTrigger } from "../utils/parseTrigger.mjs";
|
|
4
5
|
import { PopoverGroupHandleContext } from "./groupContext.mjs";
|
|
5
6
|
import { HOVER_ONLY_TRIGGER_ATTR } from "./hoverOnlyPress.mjs";
|
|
@@ -8,7 +9,6 @@ import { cloneElement, isValidElement, use, useMemo } from "react";
|
|
|
8
9
|
import { jsx } from "react/jsx-runtime";
|
|
9
10
|
import clsx from "clsx";
|
|
10
11
|
import { mergeProps } from "@base-ui/react/merge-props";
|
|
11
|
-
import { mergeRefs } from "react-merge-refs";
|
|
12
12
|
import { Popover } from "@base-ui/react/popover";
|
|
13
13
|
//#region src/Popover/PopoverInGroup.tsx
|
|
14
14
|
const PopoverInGroup = ({ children, ref: refProp, ...props }) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PopoverInGroup.mjs","names":["BasePopover"],"sources":["../../src/Popover/PopoverInGroup.tsx"],"sourcesContent":["'use client';\n\nimport { mergeProps } from '@base-ui/react/merge-props';\nimport { Popover as BasePopover } from '@base-ui/react/popover';\nimport clsx from 'clsx';\nimport { cloneElement, type FC, isValidElement, useMemo } from 'react';\nimport { use } from 'react';\nimport {
|
|
1
|
+
{"version":3,"file":"PopoverInGroup.mjs","names":["BasePopover"],"sources":["../../src/Popover/PopoverInGroup.tsx"],"sourcesContent":["'use client';\n\nimport { mergeProps } from '@base-ui/react/merge-props';\nimport { Popover as BasePopover } from '@base-ui/react/popover';\nimport clsx from 'clsx';\nimport { cloneElement, type FC, isValidElement, useMemo } from 'react';\nimport { use } from 'react';\n\nimport { useNativeButton } from '@/hooks/useNativeButton';\nimport { mergeRefs } from '@/utils/mergeRefs';\nimport { parseTrigger } from '@/utils/parseTrigger';\n\nimport { PopoverGroupHandleContext } from './groupContext';\nimport { HOVER_ONLY_TRIGGER_ATTR } from './hoverOnlyPress';\nimport { type PopoverProps } from './type';\nimport { useMergedPopoverProps } from './useMergedPopoverProps';\n\nexport const PopoverInGroup: FC<PopoverProps> = ({ children, ref: refProp, ...props }) => {\n const group = use(PopoverGroupHandleContext);\n const item = useMergedPopoverProps(props);\n\n const { openOnClick, openOnHover } = useMemo(\n () => parseTrigger(item.trigger ?? 'hover'),\n [item.trigger],\n );\n\n const resolvedOpenDelay = item.openDelay ?? (item.mouseEnterDelay ?? 0.1) * 1000;\n const resolvedCloseDelay = item.closeDelay ?? (item.mouseLeaveDelay ?? 0.1) * 1000;\n const disabled = Boolean(item.disabled);\n\n const { isNativeButtonTriggerElement, resolvedNativeButton } = useNativeButton({\n children,\n nativeButton: item.nativeButton,\n });\n\n // Don't render trigger behavior if no content\n if (!item.content) {\n return children as any;\n }\n\n const triggerProps = {\n [HOVER_ONLY_TRIGGER_ATTR]: openOnClick ? undefined : '',\n closeDelay: resolvedCloseDelay,\n delay: resolvedOpenDelay,\n disabled,\n openOnHover: openOnHover && !disabled,\n ...item.triggerProps,\n payload: item,\n };\n\n const triggerClassName = item.classNames?.trigger;\n\n if (isValidElement(children)) {\n return (\n <BasePopover.Trigger\n handle={group ?? undefined}\n {...triggerProps}\n nativeButton={resolvedNativeButton}\n render={(renderProps) => {\n // Base UI's trigger props include `type=\"button\"` by default.\n // If we render into a non-<button> element, that prop is invalid and can warn.\n const resolvedProps = (() => {\n if (isNativeButtonTriggerElement) return renderProps as any;\n // eslint-disable-next-line unused-imports/no-unused-vars\n const { type, ref: triggerRef, ...restProps } = renderProps as any;\n return restProps;\n })();\n\n const mergedProps = mergeProps((children as any).props, resolvedProps);\n return cloneElement(children as any, {\n ...mergedProps,\n className: clsx(mergedProps.className, triggerClassName),\n ref: mergeRefs([(children as any).ref, (renderProps as any).ref, refProp]),\n });\n }}\n />\n );\n }\n\n return (\n <BasePopover.Trigger\n handle={group ?? undefined}\n {...triggerProps}\n className={triggerClassName}\n nativeButton={resolvedNativeButton}\n ref={refProp}\n >\n {children}\n </BasePopover.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,KAAA;EACjB,GAAI;EACJ,WAAW;EACX,cAAc;EACd,KAAK;EAEJ;CACkB,CAAA;AAEzB;AAEA,eAAe,cAAc"}
|
package/es/Popover/atoms.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useNativeButton } from "../hooks/useNativeButton.mjs";
|
|
3
|
+
import { mergeRefs, useMergeRefs } from "../utils/mergeRefs.mjs";
|
|
3
4
|
import { FloatingLayerProvider } from "../hooks/useFloatingLayer.mjs";
|
|
4
5
|
import { getFloatingCollisionPadding } from "../internal/floating/collisionPadding.mjs";
|
|
5
6
|
import { placementMap } from "../utils/placement.mjs";
|
|
@@ -12,7 +13,6 @@ import { jsx } from "react/jsx-runtime";
|
|
|
12
13
|
import clsx from "clsx";
|
|
13
14
|
import * as stylex from "@stylexjs/stylex";
|
|
14
15
|
import { mergeProps } from "@base-ui/react/merge-props";
|
|
15
|
-
import { mergeRefs, useMergeRefs } from "react-merge-refs";
|
|
16
16
|
import { Popover } from "@base-ui/react/popover";
|
|
17
17
|
//#region src/Popover/atoms.tsx
|
|
18
18
|
const PopoverRoot = Popover.Root;
|
package/es/Popover/atoms.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atoms.mjs","names":["BasePopover"],"sources":["../../src/Popover/atoms.tsx"],"sourcesContent":["'use client';\n\nimport { mergeProps } from '@base-ui/react/merge-props';\nimport { Popover as BasePopover } from '@base-ui/react/popover';\nimport * as stylex from '@stylexjs/stylex';\nimport clsx from 'clsx';\nimport {\n cloneElement,\n type ComponentProps,\n type ComponentPropsWithRef,\n isValidElement,\n useState,\n} from 'react';\nimport {
|
|
1
|
+
{"version":3,"file":"atoms.mjs","names":["BasePopover"],"sources":["../../src/Popover/atoms.tsx"],"sourcesContent":["'use client';\n\nimport { mergeProps } from '@base-ui/react/merge-props';\nimport { Popover as BasePopover } from '@base-ui/react/popover';\nimport * as stylex from '@stylexjs/stylex';\nimport clsx from 'clsx';\nimport {\n cloneElement,\n type ComponentProps,\n type ComponentPropsWithRef,\n isValidElement,\n useState,\n} from 'react';\n\nimport { FloatingLayerProvider } from '@/hooks/useFloatingLayer';\nimport { useNativeButton } from '@/hooks/useNativeButton';\nimport { getFloatingCollisionPadding } from '@/internal/floating';\nimport { mergeRefs, useMergeRefs } from '@/utils/mergeRefs';\nimport { placementMap } from '@/utils/placement';\n\nimport { useLayerZIndex } from '../internal/zIndex';\nimport { PopoverArrowIcon } from './ArrowIcon';\nimport { usePopoverPortalContainer } from './PopoverPortal';\nimport { styles } from './style';\nimport { type PopoverPlacement } from './type';\n\nexport const PopoverRoot = BasePopover.Root;\nexport const PopoverBackdrop = BasePopover.Backdrop;\n\nexport type PopoverTriggerElementProps = Omit<\n ComponentPropsWithRef<typeof BasePopover.Trigger>,\n 'children' | 'render'\n> & {\n children: ComponentProps<typeof BasePopover.Trigger>['children'];\n};\n\nexport const PopoverTriggerElement = ({\n children,\n className,\n nativeButton,\n ref: refProp,\n ...rest\n}: PopoverTriggerElementProps) => {\n const { isNativeButtonTriggerElement, resolvedNativeButton } = useNativeButton({\n children,\n nativeButton,\n });\n\n if (isValidElement(children)) {\n return (\n <BasePopover.Trigger\n {...rest}\n nativeButton={resolvedNativeButton}\n render={(props, state) => {\n // Base UI's trigger props include `type=\"button\"` by default.\n // If we render into a non-<button> element, that prop is invalid and can warn.\n const resolvedProps = (() => {\n if (isNativeButtonTriggerElement) return props as any;\n // eslint-disable-next-line unused-imports/no-unused-vars\n const { type, ref: triggerRef, ...restProps } = props as any;\n return restProps;\n })();\n\n const mergedProps = mergeProps((children as any).props, resolvedProps);\n const baseClassName =\n typeof (mergedProps as any).className === 'function'\n ? (mergedProps as any).className(state)\n : (mergedProps as any).className;\n const extraClassName =\n typeof (className as any) === 'function' ? (className as any)(state) : className;\n\n return cloneElement(children as any, {\n ...mergedProps,\n className: clsx(baseClassName, extraClassName),\n ref: mergeRefs([(children as any).ref, (props as any).ref, refProp]),\n });\n }}\n />\n );\n }\n\n return (\n <BasePopover.Trigger\n {...rest}\n className={className}\n nativeButton={resolvedNativeButton}\n ref={refProp}\n >\n {children}\n </BasePopover.Trigger>\n );\n};\n\nPopoverTriggerElement.displayName = 'PopoverTriggerElement';\n\nexport type PopoverPortalAtomProps = Omit<\n ComponentProps<typeof BasePopover.Portal>,\n 'container'\n> & {\n /**\n * Portal container. When not provided, it uses the shared container created by `usePopoverPortalContainer`.\n */\n container?: HTMLElement | null;\n /**\n * Root element used by `usePopoverPortalContainer` to create the default container.\n */\n root?: HTMLElement | ShadowRoot | null;\n};\n\nexport const PopoverPortal = ({ container, root, children, ...rest }: PopoverPortalAtomProps) => {\n const defaultContainer = usePopoverPortalContainer(root);\n const resolvedContainer = container ?? defaultContainer;\n\n if (!resolvedContainer) return null;\n\n return (\n <BasePopover.Portal container={resolvedContainer} {...rest}>\n {children}\n </BasePopover.Portal>\n );\n};\n\nPopoverPortal.displayName = 'PopoverPortal';\n\nexport type PopoverPositionerAtomProps = ComponentProps<typeof BasePopover.Positioner> & {\n hoverTrigger?: boolean;\n placement?: PopoverPlacement;\n};\n\nexport const PopoverPositioner = ({\n children,\n className,\n collisionPadding,\n hoverTrigger,\n placement,\n align,\n side,\n sideOffset,\n style,\n ...rest\n}: PopoverPositionerAtomProps) => {\n const placementConfig = placement ? placementMap[placement] : undefined;\n const [positionerNode, setPositionerNode] = useState<HTMLDivElement | null>(null);\n const explicitZIndex =\n typeof style !== 'function' && style?.zIndex != null && typeof style.zIndex === 'number'\n ? style.zIndex\n : undefined;\n const { zIndex, ref: zRef } = useLayerZIndex<HTMLDivElement>('floating', explicitZIndex);\n const composedRef = useMergeRefs([setPositionerNode, zRef]);\n\n const resolvedStyle =\n typeof style === 'function'\n ? (state: any) => ({ zIndex, ...style(state) })\n : { zIndex, ...style };\n\n return (\n <BasePopover.Positioner\n align={align ?? placementConfig?.align ?? 'center'}\n collisionPadding={collisionPadding ?? getFloatingCollisionPadding()}\n data-hover-trigger={hoverTrigger || undefined}\n data-placement={placement}\n ref={composedRef as any}\n side={side ?? placementConfig?.side ?? 'bottom'}\n sideOffset={sideOffset ?? 6}\n style={resolvedStyle}\n className={(state) =>\n clsx(\n stylex.props(styles.positioner).className,\n typeof className === 'function' ? className(state) : className,\n )\n }\n {...rest}\n >\n <FloatingLayerProvider value={positionerNode}>{children}</FloatingLayerProvider>\n </BasePopover.Positioner>\n );\n};\n\nPopoverPositioner.displayName = 'PopoverPositioner';\n\nexport type PopoverPopupAtomProps = ComponentProps<typeof BasePopover.Popup> & {\n xstyle?: stylex.StyleXStyles;\n};\n\nexport const PopoverPopup = ({ className, xstyle, ...rest }: PopoverPopupAtomProps) => {\n return (\n <BasePopover.Popup\n className={(state) =>\n clsx(\n stylex.props(styles.popup, xstyle).className,\n typeof className === 'function' ? className(state) : className,\n )\n }\n {...rest}\n />\n );\n};\n\nPopoverPopup.displayName = 'PopoverPopup';\n\nexport type PopoverArrowAtomProps = ComponentProps<typeof BasePopover.Arrow>;\n\nexport const PopoverArrow = ({ className, children, ...rest }: PopoverArrowAtomProps) => {\n return (\n <BasePopover.Arrow\n className={(state) =>\n clsx(\n stylex.props(styles.arrow).className,\n typeof className === 'function' ? className(state) : className,\n )\n }\n {...rest}\n >\n {children ?? PopoverArrowIcon}\n </BasePopover.Arrow>\n );\n};\n\nPopoverArrow.displayName = 'PopoverArrow';\n\nexport type PopoverViewportAtomProps = ComponentProps<typeof BasePopover.Viewport>;\n\nexport const PopoverViewport = ({ className, ...rest }: PopoverViewportAtomProps) => {\n return (\n <BasePopover.Viewport\n className={(state) =>\n clsx(\n stylex.props(styles.viewport).className,\n 'lobe-popover-viewport',\n typeof className === 'function' ? className(state) : className,\n )\n }\n {...rest}\n />\n );\n};\n\nPopoverViewport.displayName = 'PopoverViewport';\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,MAAa,cAAcA,QAAY;AACvC,MAAa,kBAAkBA,QAAY;AAI3C,MAAa,yBAAyB,EACpC,UACA,WACA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AAE3B,MAAa,mBAAmB,EAC9B,WACA,GAAG,WAC2B;CAC9B,OAAO,oBAACA,QAAY,UAAb;EAAsB,YAAW,UAAS,KAAK,OAAO,MAAM,OAAO,QAAQ,CAAC,CAAC,WAAW,yBAAyB,OAAO,cAAc,aAAa,UAAU,KAAK,IAAI,SAAS;EAAG,GAAI;CAAO,CAAA;AACtM;AACA,gBAAgB,cAAc"}
|
package/es/Rate/Rate.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { styleProps } from "../styles/stylex/props.mjs";
|
|
3
3
|
import { cssVar } from "../styles/stylex/cssVar.stylex.mjs";
|
|
4
|
+
import { useControlledState } from "../hooks/useControlledState.mjs";
|
|
4
5
|
import { styles } from "./style.mjs";
|
|
5
6
|
import { createElement, memo, useState } from "react";
|
|
6
7
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
8
|
import * as stylex from "@stylexjs/stylex";
|
|
8
9
|
import { Star } from "lucide-react";
|
|
9
|
-
import useControlledState from "use-merge-value";
|
|
10
10
|
//#region src/Rate/Rate.tsx
|
|
11
11
|
const clamp = (value, min, max) => Math.min(max, Math.max(min, value));
|
|
12
12
|
const formatValue = (value) => String(Math.round(value * 100) / 100);
|
package/es/Rate/Rate.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Rate.mjs","names":[],"sources":["../../src/Rate/Rate.tsx"],"sourcesContent":["'use client';\n\nimport * as stylex from '@stylexjs/stylex';\nimport { Star } from 'lucide-react';\nimport { type KeyboardEvent, memo, useState } from 'react';\nimport useControlledState from '
|
|
1
|
+
{"version":3,"file":"Rate.mjs","names":[],"sources":["../../src/Rate/Rate.tsx"],"sourcesContent":["'use client';\n\nimport * as stylex from '@stylexjs/stylex';\nimport { Star } from 'lucide-react';\nimport { type KeyboardEvent, memo, useState } from 'react';\n\nimport { useControlledState } from '@/hooks/useControlledState';\nimport { cssVar } from '@/styles/stylex/cssVar.stylex';\nimport { styleProps } from '@/styles/stylex/props';\n\nimport { styles } from './style';\nimport type { RateProps } from './type';\n\nconst clamp = (value: number, min: number, max: number) => Math.min(max, Math.max(min, value));\n\nconst formatValue = (value: number) => String(Math.round(value * 100) / 100);\n\nconst Rate = memo<RateProps>(\n ({\n allowHalf = false,\n character,\n className,\n color = cssVar.colorWarning,\n count = 5,\n defaultValue = 0,\n disabled = false,\n gap,\n onChange,\n onKeyDown,\n onPointerLeave,\n readOnly = false,\n size = 20,\n style,\n value,\n ...rest\n }) => {\n const [mergedValue, setMergedValue] = useControlledState(defaultValue, { onChange, value });\n const [hoverValue, setHoverValue] = useState<number | null>(null);\n\n const interactive = !readOnly && !disabled;\n const step = allowHalf ? 0.5 : 1;\n const displayValue = clamp(hoverValue ?? mergedValue, 0, count);\n const label = `${formatValue(clamp(mergedValue, 0, count))} out of ${count}`;\n const icon = character ?? <Star fill=\"currentColor\" size={size} />;\n\n const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n onKeyDown?.(event);\n if (!interactive || event.defaultPrevented) return;\n\n const next = {\n ArrowDown: mergedValue - step,\n ArrowLeft: mergedValue - step,\n ArrowRight: mergedValue + step,\n ArrowUp: mergedValue + step,\n End: count,\n Home: 0,\n }[event.key];\n if (next === undefined) return;\n\n event.preventDefault();\n setMergedValue(clamp(Math.round(next / step) * step, 0, count));\n };\n\n const a11yProps = readOnly\n ? { 'aria-label': label, 'role': 'img' }\n : {\n 'aria-disabled': disabled || undefined,\n 'aria-valuemax': count,\n 'aria-valuemin': 0,\n 'aria-valuenow': mergedValue,\n 'aria-valuetext': label,\n 'role': 'slider',\n 'tabIndex': disabled ? -1 : 0,\n };\n\n return (\n <div\n onKeyDown={handleKeyDown}\n onPointerLeave={(event) => {\n onPointerLeave?.(event);\n setHoverValue(null);\n }}\n {...a11yProps}\n {...rest}\n {...styleProps(styles.root, className, { gap: gap ?? size / 2, ...style })}\n >\n {Array.from({ length: count }, (_, index) => {\n const fill = clamp(displayValue - index, 0, 1);\n const targets = allowHalf ? [index + 0.5, index + 1] : [index + 1];\n\n return (\n <span\n aria-hidden=\"true\"\n data-index={index}\n key={index}\n {...styleProps([styles.star, interactive && styles.starInteractive], undefined, {\n fontSize: size,\n height: size,\n })}\n >\n <span {...styleProps([styles.icon, styles.empty], undefined, { minWidth: size })}>\n {icon}\n </span>\n <span {...styleProps(styles.fill, undefined, { color, width: `${fill * 100}%` })}>\n <span {...styleProps(styles.icon, undefined, { minWidth: size })}>{icon}</span>\n </span>\n {interactive &&\n targets.map((target) => (\n <span\n {...stylex.props(styles.half)}\n data-half={target % 1 === 0 && allowHalf ? 'end' : 'start'}\n data-value={target}\n key={target}\n style={allowHalf ? undefined : { width: '100%' }}\n onClick={() => setMergedValue(target)}\n onPointerEnter={() => setHoverValue(target)}\n />\n ))}\n </span>\n );\n })}\n </div>\n );\n },\n);\n\nRate.displayName = 'Rate';\n\nexport default Rate;\n"],"mappings":";;;;;;;;;;AAUA,MAAM,SAAS,OAAe,KAAa,QAAgB,KAAK,IAAI,KAAK,KAAK,IAAI,KAAK,KAAK,CAAC;AAC7F,MAAM,eAAe,UAAkB,OAAO,KAAK,MAAM,QAAQ,GAAG,IAAI,GAAG;AAC3E,MAAM,OAAO,MAAiB,EAC5B,YAAY,OACZ,WACA,WACA,QAAQ,OAAO,cACf,QAAQ,GACR,eAAe,GACf,WAAW,OACX,KACA,UACA,WACA,gBACA,WAAW,OACX,OAAO,IACP,OACA,OACA,GAAG,WACC;CACJ,MAAM,CAAC,aAAa,kBAAkB,mBAAmB,cAAc;EACrE;EACA;CACF,CAAC;CACD,MAAM,CAAC,YAAY,iBAAiB,SAAwB,IAAI;CAChE,MAAM,cAAc,CAAC,YAAY,CAAC;CAClC,MAAM,OAAO,YAAY,KAAM;CAC/B,MAAM,eAAe,MAAM,cAAc,aAAa,GAAG,KAAK;CAC9D,MAAM,QAAQ,GAAG,YAAY,MAAM,aAAa,GAAG,KAAK,CAAC,EAAE,UAAU;CACrE,M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E,UAAU,KACZ,CAAC;MACQ,UAAA;KACG,CAAA;KACN,oBAAC,QAAD;MAAM,GAAI,WAAW,OAAO,MAAM,KAAA,GAAW;OACjD;OACA,OAAO,GAAG,OAAO,IAAI;MACvB,CAAC;MACO,UAAA,oBAAC,QAAD;OAAM,GAAI,WAAW,OAAO,MAAM,KAAA,GAAW,EACjD,UAAU,KACZ,CAAC;OAAI,UAAA;MAAW,CAAA;KACN,CAAA;KACL,eAAe,QAAQ,KAAI,WAAU,8BAAC,QAAD;MAAM,GAAI,OAAO,MAAM,OAAO,IAAI;MAAG,aAAW,SAAS,MAAM,KAAK,YAAY,QAAQ;MAAS,cAAY;MAAQ,KAAK;MAAQ,OAAO,YAAY,KAAA,IAAY,EAC3M,OAAO,OACT;MAAG,eAAe,eAAe,MAAM;MAAG,sBAAsB,cAAc,MAAM;KAAI,CAAA,CAAC;IAC/E;GApB4C,GAAA,KAoB5C;EACd,CAAC;CACM,CAAA;AACX,CAAC;AACD,KAAK,cAAc"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { styleProps } from "../styles/stylex/props.mjs";
|
|
3
|
+
import { mergeRefs } from "../utils/mergeRefs.mjs";
|
|
3
4
|
import FlexBasic_default from "../Flex/FlexBasic.mjs";
|
|
4
5
|
import { useEventCallback } from "../hooks/useEventCallback.mjs";
|
|
5
6
|
import { styles } from "./style.mjs";
|
|
6
7
|
import { useScrollOverflow } from "./useScrollOverflow.mjs";
|
|
7
8
|
import { useMemo, useRef } from "react";
|
|
8
9
|
import { jsx } from "react/jsx-runtime";
|
|
9
|
-
import { mergeRefs } from "react-merge-refs";
|
|
10
10
|
//#region src/ScrollShadow/ScrollShadow.tsx
|
|
11
11
|
const scrollPositionStyles = {
|
|
12
12
|
"bottom": styles.bottom,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScrollShadow.mjs","names":["Flexbox"],"sources":["../../src/ScrollShadow/ScrollShadow.tsx"],"sourcesContent":["'use client';\n\nimport type { FC } from 'react';\nimport { useMemo, useRef } from 'react';\
|
|
1
|
+
{"version":3,"file":"ScrollShadow.mjs","names":["Flexbox"],"sources":["../../src/ScrollShadow/ScrollShadow.tsx"],"sourcesContent":["'use client';\n\nimport type { FC } from 'react';\nimport { useMemo, useRef } from 'react';\n\nimport { Flexbox } from '@/Flex';\nimport { useEventCallback } from '@/hooks/useEventCallback';\nimport { styleProps } from '@/styles/stylex/props';\nimport { mergeRefs } from '@/utils/mergeRefs';\n\nimport { styles } from './style';\nimport type { ScrollShadowProps } from './type';\nimport { useScrollOverflow } from './useScrollOverflow';\n\nconst scrollPositionStyles = {\n 'bottom': styles.bottom,\n 'left': styles.left,\n 'left-right': styles.leftRight,\n 'none': null,\n 'right': styles.right,\n 'top': styles.top,\n 'top-bottom': styles.topBottom,\n};\n\nconst ScrollShadow: FC<ScrollShadowProps> = ({\n className,\n children,\n orientation = 'vertical',\n hideScrollBar = false,\n size = 16,\n offset = 8,\n visibility = 'auto',\n isEnabled = true,\n onVisibilityChange,\n style,\n ref,\n ...rest\n}) => {\n // Convert size prop to CSS variable\n const cssVariables = useMemo<Record<string, string>>(\n () => ({\n '--scroll-shadow-size': `${size}%`,\n }),\n [size],\n );\n const domRef = useRef<HTMLDivElement>(null);\n\n const onVisibilityChangeEvent = useEventCallback<\n NonNullable<ScrollShadowProps['onVisibilityChange']>\n >((visibility) => {\n onVisibilityChange?.(visibility);\n });\n // 使用滚动检测钩子\n const scrollState = useScrollOverflow({\n domRef,\n isEnabled: isEnabled && visibility === 'auto',\n offset,\n onVisibilityChange: onVisibilityChangeEvent,\n orientation,\n updateDeps: [children],\n });\n\n // 决定最终的滚动状态\n const finalScrollState = useMemo(() => {\n if (visibility === 'always') {\n return {\n bottom: true,\n left: true,\n right: true,\n top: true,\n };\n }\n\n if (visibility === 'never') {\n return {\n bottom: false,\n left: false,\n right: false,\n top: false,\n };\n }\n\n return scrollState;\n }, [visibility, scrollState]);\n\n // 计算数据属性\n const dataAttributes = useMemo(() => {\n const attributes: Record<string, boolean | string> = {\n 'data-orientation': orientation,\n };\n\n if (orientation === 'vertical') {\n if (finalScrollState.top && finalScrollState.bottom) {\n attributes['data-top-bottom-scroll'] = true;\n } else if (finalScrollState.top) {\n attributes['data-top-scroll'] = true;\n } else if (finalScrollState.bottom) {\n attributes['data-bottom-scroll'] = true;\n }\n } else {\n if (finalScrollState.left && finalScrollState.right) {\n attributes['data-left-right-scroll'] = true;\n } else if (finalScrollState.left) {\n attributes['data-left-scroll'] = true;\n } else if (finalScrollState.right) {\n attributes['data-right-scroll'] = true;\n }\n }\n\n return attributes;\n }, [orientation, finalScrollState]);\n\n // 计算滚动位置变体\n const scrollPosition = useMemo(() => {\n if (orientation === 'vertical') {\n if (finalScrollState.top && finalScrollState.bottom) return 'top-bottom';\n if (finalScrollState.top) return 'top';\n if (finalScrollState.bottom) return 'bottom';\n } else {\n if (finalScrollState.left && finalScrollState.right) return 'left-right';\n if (finalScrollState.left) return 'left';\n if (finalScrollState.right) return 'right';\n }\n return 'none';\n }, [orientation, finalScrollState]);\n\n return (\n <Flexbox\n ref={mergeRefs<HTMLDivElement>([domRef, ref])}\n className={\n styleProps(\n [\n styles.root,\n styles[orientation],\n hideScrollBar && styles.hideScrollBar,\n scrollPositionStyles[scrollPosition],\n ],\n className,\n ).className\n }\n style={{\n ...cssVariables,\n ...style,\n }}\n {...dataAttributes}\n {...rest}\n >\n {children}\n </Flexbox>\n );\n};\n\nScrollShadow.displayName = 'ScrollShadow';\n\nexport default ScrollShadow;\n"],"mappings":";;;;;;;;;;AAcA,MAAM,uBAAuB;CAC3B,UAAU,OAAO;CACjB,QAAQ,OAAO;CACf,cAAc,OAAO;CACrB,QAAQ;CACR,SAAS,OAAO;CAChB,OAAO,OAAO;CACd,cAAc,OAAO;AACvB;AAEA,MAAM,gBAAuC,EAC3C,WACA,UACA,cAAc,YACd,gBAAgB,OAChB,OAAO,IACP,SAAS,GACT,aAAa,QACb,YAAY,MAC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