@lobehub/ui 6.0.0-beta.4 → 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/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/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,6 +2,8 @@
|
|
|
2
2
|
import { styleProps } from "../styles/stylex/props.mjs";
|
|
3
3
|
import Icon from "../Icon/Icon.mjs";
|
|
4
4
|
import Hotkey from "../Hotkey/Hotkey.mjs";
|
|
5
|
+
import { useEventCallback } from "../hooks/useEventCallback.mjs";
|
|
6
|
+
import { useControlledState } from "../hooks/useControlledState.mjs";
|
|
5
7
|
import Input_default from "../Input/Input.mjs";
|
|
6
8
|
import Spotlight from "../awesome/Spotlight/Spotlight.mjs";
|
|
7
9
|
import { styles } from "./style.mjs";
|
|
@@ -9,7 +11,6 @@ import { memo, useMemo, useRef, useState } from "react";
|
|
|
9
11
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
12
|
import * as stylex from "@stylexjs/stylex";
|
|
11
13
|
import { LucideLoader2, Search } from "lucide-react";
|
|
12
|
-
import useControlledState from "use-merge-value";
|
|
13
14
|
import { useHotkeys } from "react-hotkeys-hook";
|
|
14
15
|
//#region src/SearchBar/SearchBar.tsx
|
|
15
16
|
const SearchBar = memo(({ defaultValue = "", spotlight, className, value, onInputChange, placeholder, enableShortKey, shortKey = "mod+k", onSearch, loading, style, onChange, onBlur, onPressEnter, onFocus, styles: { input: inputStyle, shortKey: shortKeyStyle } = {}, classNames: { input: inputClassName, shortKey: shortKeyClassName } = {}, ...rest }) => {
|
|
@@ -21,6 +22,30 @@ const SearchBar = memo(({ defaultValue = "", spotlight, className, value, onInpu
|
|
|
21
22
|
const [showTag, setShowTag] = useState(true);
|
|
22
23
|
const inputReference = useRef(null);
|
|
23
24
|
const hotkey = useMemo(() => shortKey.includes("+") ? shortKey : `mod+${shortKey}`, [shortKey]);
|
|
25
|
+
const prefix = useMemo(() => /* @__PURE__ */ jsx(Icon, {
|
|
26
|
+
...stylex.props(styles.icon),
|
|
27
|
+
icon: loading ? LucideLoader2 : Search,
|
|
28
|
+
size: "small",
|
|
29
|
+
spin: loading,
|
|
30
|
+
style: { marginRight: 4 }
|
|
31
|
+
}), [loading]);
|
|
32
|
+
const handleBlur = useEventCallback((e) => {
|
|
33
|
+
onBlur?.(e);
|
|
34
|
+
setInputValue(e.target.value);
|
|
35
|
+
setShowTag(true);
|
|
36
|
+
});
|
|
37
|
+
const handleChange = useEventCallback((e) => {
|
|
38
|
+
setInputValue(e.target.value);
|
|
39
|
+
onChange?.(e);
|
|
40
|
+
});
|
|
41
|
+
const handleFocus = useEventCallback((e) => {
|
|
42
|
+
onFocus?.(e);
|
|
43
|
+
setShowTag(false);
|
|
44
|
+
});
|
|
45
|
+
const handlePressEnter = useEventCallback((e) => {
|
|
46
|
+
onPressEnter?.(e);
|
|
47
|
+
onSearch?.(inputValue);
|
|
48
|
+
});
|
|
24
49
|
useHotkeys(hotkey, () => {
|
|
25
50
|
if (!enableShortKey) return;
|
|
26
51
|
inputReference.current?.focus();
|
|
@@ -37,33 +62,14 @@ const SearchBar = memo(({ defaultValue = "", spotlight, className, value, onInpu
|
|
|
37
62
|
allowClear: true,
|
|
38
63
|
className: inputClassName,
|
|
39
64
|
placeholder: placeholder ?? "Type keywords...",
|
|
65
|
+
prefix,
|
|
40
66
|
ref: inputReference,
|
|
41
67
|
style: inputStyle,
|
|
42
68
|
value: inputValue,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
spin: loading,
|
|
48
|
-
style: { marginRight: 4 }
|
|
49
|
-
}),
|
|
50
|
-
onBlur: (e) => {
|
|
51
|
-
onBlur?.(e);
|
|
52
|
-
setInputValue(e.target.value);
|
|
53
|
-
setShowTag(true);
|
|
54
|
-
},
|
|
55
|
-
onChange: (e) => {
|
|
56
|
-
setInputValue(e.target.value);
|
|
57
|
-
onChange?.(e);
|
|
58
|
-
},
|
|
59
|
-
onFocus: (e) => {
|
|
60
|
-
onFocus?.(e);
|
|
61
|
-
setShowTag(false);
|
|
62
|
-
},
|
|
63
|
-
onPressEnter: (e) => {
|
|
64
|
-
onPressEnter?.(e);
|
|
65
|
-
onSearch?.(inputValue);
|
|
66
|
-
},
|
|
69
|
+
onBlur: handleBlur,
|
|
70
|
+
onChange: handleChange,
|
|
71
|
+
onFocus: handleFocus,
|
|
72
|
+
onPressEnter: handlePressEnter,
|
|
67
73
|
...rest
|
|
68
74
|
}),
|
|
69
75
|
enableShortKey && showTag && !inputValue && /* @__PURE__ */ jsx(Hotkey, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SearchBar.mjs","names":["Input"],"sources":["../../src/SearchBar/SearchBar.tsx"],"sourcesContent":["'use client';\n\nimport * as stylex from '@stylexjs/stylex';\nimport { LucideLoader2, Search } from 'lucide-react';\nimport { memo, useMemo, useRef, useState } from 'react';\nimport { useHotkeys } from 'react-hotkeys-hook';\nimport useControlledState from '
|
|
1
|
+
{"version":3,"file":"SearchBar.mjs","names":["Input"],"sources":["../../src/SearchBar/SearchBar.tsx"],"sourcesContent":["'use client';\n\nimport * as stylex from '@stylexjs/stylex';\nimport { LucideLoader2, Search } from 'lucide-react';\nimport { memo, useMemo, useRef, useState } from 'react';\nimport { useHotkeys } from 'react-hotkeys-hook';\n\nimport Spotlight from '@/awesome/Spotlight';\nimport { useControlledState } from '@/hooks/useControlledState';\nimport { useEventCallback } from '@/hooks/useEventCallback';\nimport Hotkey from '@/Hotkey';\nimport Icon from '@/Icon';\nimport { Input } from '@/Input';\nimport { styleProps } from '@/styles/stylex/props';\n\nimport { styles } from './style';\nimport { type SearchBarProps } from './type';\n\ntype HandlerEvent<K extends 'onBlur' | 'onChange' | 'onFocus' | 'onPressEnter'> = Parameters<\n NonNullable<SearchBarProps[K]>\n>[0];\n\nconst SearchBar = memo<SearchBarProps>(\n ({\n defaultValue = '',\n spotlight,\n className,\n value,\n onInputChange,\n placeholder,\n enableShortKey,\n shortKey = 'mod+k',\n onSearch,\n loading,\n style,\n onChange,\n onBlur,\n onPressEnter,\n onFocus,\n styles: { input: inputStyle, shortKey: shortKeyStyle } = {},\n classNames: { input: inputClassName, shortKey: shortKeyClassName } = {},\n ...rest\n }) => {\n const [inputValue, setInputValue] = useControlledState(defaultValue, {\n defaultValue,\n onChange: onInputChange,\n value,\n });\n\n const [showTag, setShowTag] = useState<boolean>(true);\n const inputReference: any = useRef<HTMLInputElement>(null);\n const hotkey = useMemo(\n () => (shortKey.includes('+') ? shortKey : `mod+${shortKey}`),\n [shortKey],\n );\n\n const prefix = useMemo(\n () => (\n <Icon\n {...stylex.props(styles.icon)}\n icon={loading ? LucideLoader2 : Search}\n size=\"small\"\n spin={loading}\n style={{ marginRight: 4 }}\n />\n ),\n [loading],\n );\n\n const handleBlur = useEventCallback((e: HandlerEvent<'onBlur'>) => {\n onBlur?.(e);\n setInputValue(e.target.value);\n setShowTag(true);\n });\n\n const handleChange = useEventCallback((e: HandlerEvent<'onChange'>) => {\n setInputValue(e.target.value);\n onChange?.(e);\n });\n\n const handleFocus = useEventCallback((e: HandlerEvent<'onFocus'>) => {\n onFocus?.(e);\n setShowTag(false);\n });\n\n const handlePressEnter = useEventCallback((e: HandlerEvent<'onPressEnter'>) => {\n onPressEnter?.(e);\n onSearch?.(inputValue);\n });\n\n useHotkeys(\n hotkey,\n () => {\n if (!enableShortKey) return;\n inputReference.current?.focus();\n },\n {\n enableOnFormTags: true,\n enabled: !!enableShortKey && !!shortKey,\n preventDefault: true,\n },\n );\n\n return (\n <div {...styleProps(styles.search, className, style)}>\n {spotlight && <Spotlight />}\n <Input\n allowClear\n className={inputClassName}\n placeholder={placeholder ?? 'Type keywords...'}\n prefix={prefix}\n ref={inputReference}\n style={inputStyle}\n value={inputValue}\n onBlur={handleBlur}\n onChange={handleChange}\n onFocus={handleFocus}\n onPressEnter={handlePressEnter}\n {...rest}\n />\n {enableShortKey && showTag && !inputValue && (\n <Hotkey\n compact\n keys={hotkey}\n styles={{ kbdStyle: { color: 'inherit' } }}\n {...styleProps(styles.tag, shortKeyClassName, shortKeyStyle)}\n />\n )}\n </div>\n );\n },\n);\n\nSearchBar.displayName = 'SearchBar';\n\nexport default SearchBar;\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,MAAM,YAAY,MAAsB,EAC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,UAAA;GACA,aAAa,oBAAC,WAAD,CAAY,CAAA;GAC1B,oBAACA,eAAD;IAAO,YAAA;IAAW,WAAW;IAAgB,aAAa,eAAe;IAA4B;IAAQ,KAAK;IAAgB,OAAO;IAAY,OAAO;IAAY,QAAQ;IAAY,UAAU;IAAc,SAAS;IAAa,cAAc;IAAkB,GAAI;GAAO,CAAA;GACpR,kBAAkB,WAAW,CAAC,cAAc,oBAAC,QAAD;IAAQ,SAAA;IAAQ,MAAM;IAAQ,QAAQ,EACrF,UAAU,EACR,OAAO,UACT,EACF;IAAG,GAAI,WAAW,OAAO,KAAK,mBAAmB,aAAa;GAAI,CAAA;EAC3D;;AACX,CAAC;AACD,UAAU,cAAc"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { useControlledState } from "../hooks/useControlledState.mjs";
|
|
2
3
|
import { SegmentedIndicator, SegmentedItem, SegmentedItemIcon, SegmentedItemLabel, SegmentedRoot } from "./atoms.mjs";
|
|
3
4
|
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef } from "react";
|
|
4
5
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
6
|
import clsx from "clsx";
|
|
6
|
-
import useControlledState from "use-merge-value";
|
|
7
7
|
//#region src/Segmented/Segmented.tsx
|
|
8
8
|
const normalizeOption = (option) => typeof option === "string" ? {
|
|
9
9
|
label: option,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Segmented.mjs","names":[],"sources":["../../src/Segmented/Segmented.tsx"],"sourcesContent":["'use client';\n\nimport clsx from 'clsx';\nimport {\n type CSSProperties,\n useCallback,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n} from 'react';\nimport useControlledState from '
|
|
1
|
+
{"version":3,"file":"Segmented.mjs","names":[],"sources":["../../src/Segmented/Segmented.tsx"],"sourcesContent":["'use client';\n\nimport clsx from 'clsx';\nimport {\n type CSSProperties,\n useCallback,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n} from 'react';\n\nimport { useControlledState } from '@/hooks/useControlledState';\n\nimport {\n SegmentedIndicator,\n SegmentedItem,\n SegmentedItemIcon,\n SegmentedItemLabel,\n SegmentedRoot,\n} from './atoms';\nimport type { SegmentedOption, SegmentedProps } from './type';\n\nconst normalizeOption = <Value extends string>(\n option: SegmentedOption<Value> | Value,\n): SegmentedOption<Value> =>\n typeof option === 'string' ? { label: option, value: option } : option;\n\nconst Segmented = <Value extends string = string>({\n block = false,\n className,\n classNames,\n defaultValue,\n disabled = false,\n glass = false,\n id,\n name,\n onChange,\n options,\n ref,\n shadow = false,\n size = 'middle',\n style,\n styles: customStyles,\n value,\n variant = 'filled',\n vertical = false,\n}: SegmentedProps<Value>) => {\n const [innerValue, setInnerValue] = useControlledState<Value | undefined>(defaultValue, {\n defaultValue,\n onChange: (next) => {\n if (next != null) onChange?.(next);\n },\n value,\n });\n\n const listRef = useRef<HTMLDivElement | null>(null);\n\n const mergedRef = useCallback(\n (node: HTMLDivElement | null) => {\n listRef.current = node;\n if (typeof ref === 'function') ref(node);\n else if (ref) (ref as React.RefObject<HTMLDivElement | null>).current = node;\n },\n [ref],\n );\n\n const normalizedOptions = useMemo(\n () => (options ?? []).map((o) => normalizeOption<Value>(o)),\n [options],\n );\n\n const updateIndicator = useCallback(() => {\n const list = listRef.current;\n if (!list) return;\n const active = list.querySelector<HTMLElement>('[data-segmented-item][data-pressed]');\n if (!active) {\n list.style.setProperty('--active-item-left', '0px');\n list.style.setProperty('--active-item-top', '0px');\n list.style.setProperty('--active-item-right', '0px');\n list.style.setProperty('--active-item-width', '0px');\n list.style.setProperty('--active-item-height', '0px');\n return;\n }\n list.style.setProperty('--active-item-left', `${active.offsetLeft}px`);\n list.style.setProperty('--active-item-top', `${active.offsetTop}px`);\n list.style.setProperty(\n '--active-item-right',\n `${list.clientWidth - active.offsetLeft - active.offsetWidth}px`,\n );\n list.style.setProperty('--active-item-width', `${active.offsetWidth}px`);\n list.style.setProperty('--active-item-height', `${active.offsetHeight}px`);\n }, []);\n\n useLayoutEffect(() => {\n updateIndicator();\n }, [innerValue, normalizedOptions, vertical, size, block, updateIndicator]);\n\n useEffect(() => {\n const list = listRef.current;\n if (!list || typeof ResizeObserver === 'undefined') return;\n const ro = new ResizeObserver(() => updateIndicator());\n ro.observe(list);\n return () => ro.disconnect();\n }, [updateIndicator]);\n\n const groupValue = useMemo<Value[]>(() => (innerValue != null ? [innerValue] : []), [innerValue]);\n\n const rootStyle: CSSProperties = { ...style, ...customStyles?.root };\n\n return (\n <SegmentedRoot<Value>\n block={block}\n className={clsx(classNames?.root, className)}\n disabled={disabled}\n glass={glass}\n id={id}\n orientation={vertical ? 'vertical' : 'horizontal'}\n ref={mergedRef}\n shadow={shadow}\n style={rootStyle}\n value={groupValue}\n variant={variant}\n onValueChange={(next) => {\n const picked = next[0];\n if (picked != null) setInnerValue(picked);\n }}\n >\n <SegmentedIndicator className={classNames?.indicator} style={customStyles?.indicator} />\n {normalizedOptions.map((opt) => (\n <SegmentedItem<Value>\n aria-label={typeof opt.label === 'string' ? opt.label : undefined}\n block={block}\n className={clsx(classNames?.item, opt.className)}\n data-segmented-item=\"\"\n disabled={disabled || opt.disabled}\n key={opt.value}\n name={name}\n size={size}\n style={customStyles?.item}\n title={opt.title}\n value={opt.value}\n >\n {opt.icon != null && (\n <SegmentedItemIcon className={classNames?.itemIcon} style={customStyles?.itemIcon}>\n {opt.icon}\n </SegmentedItemIcon>\n )}\n {opt.label != null && (\n <SegmentedItemLabel className={classNames?.itemLabel} style={customStyles?.itemLabel}>\n {opt.label}\n </SegmentedItemLabel>\n )}\n </SegmentedItem>\n ))}\n </SegmentedRoot>\n );\n};\n\nSegmented.displayName = 'Segmented';\n\nexport default Segmented;\n"],"mappings":";;;;;;;AAuBA,MAAM,mBACJ,WAEA,OAAO,WAAW,WAAW;CAAE,OAAO;CAAQ,OAAO;AAAO,IAAI;AAElE,MAAM,aAA4C,EAChD,QAAQ,OACR,WACA,YACA,cACA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BI,CAChB,CACY;;AAEnB;AAEA,UAAU,cAAc"}
|
package/es/Select/atoms.mjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { useAppElement } from "../ConfigProvider/AppElementContext.mjs";
|
|
3
3
|
import { styleProps } from "../styles/stylex/props.mjs";
|
|
4
4
|
import { useNativeButton } from "../hooks/useNativeButton.mjs";
|
|
5
|
+
import { mergeRefs, useMergeRefs } from "../utils/mergeRefs.mjs";
|
|
5
6
|
import { getFloatingCollisionPadding } from "../internal/floating/collisionPadding.mjs";
|
|
6
7
|
import { useThemeMode } from "../styles/theme/scope.mjs";
|
|
7
8
|
import { useLayerZIndex } from "../internal/zIndex/useLayerZIndex.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 { Select } from "@base-ui/react/select";
|
|
17
17
|
//#region src/Select/atoms.tsx
|
|
18
18
|
const mergeStateClassName = (base, className, extra) => {
|
package/es/Select/atoms.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atoms.mjs","names":[],"sources":["../../src/Select/atoms.tsx"],"sourcesContent":["'use client';\n\nimport { mergeProps } from '@base-ui/react/merge-props';\nimport { Select } from '@base-ui/react/select';\nimport * as stylex from '@stylexjs/stylex';\nimport clsx from 'clsx';\nimport {\n cloneElement,\n type ComponentProps,\n type ComponentPropsWithRef,\n isValidElement,\n} from 'react';\nimport { mergeRefs, useMergeRefs } from 'react-merge-refs';\n\nimport { useAppElement } from '@/ConfigProvider/AppElementContext';\nimport { menuClassNames, menuStyles } from '@/DropdownMenu/sharedStyle';\nimport { useNativeButton } from '@/hooks/useNativeButton';\nimport { getFloatingCollisionPadding } from '@/internal/floating';\nimport { styleProps } from '@/styles/stylex/props';\nimport { useThemeMode } from '@/styles/theme/scope';\n\nimport { useLayerZIndex } from '../internal/zIndex';\nimport { styles, triggerStyles } from './style';\nimport { type SelectSize, type SelectVariant } from './type';\n\nconst mergeStateClassName = <TState,>(\n base: Parameters<typeof styleProps>[0],\n className: string | ((state: TState) => string | undefined) | undefined,\n extra?: string,\n) => {\n const baseClassName = styleProps(base, extra).className;\n if (typeof className === 'function')\n return (state: TState) => clsx(baseClassName, className(state));\n return clsx(baseClassName, className);\n};\n\nexport const SelectRoot = Select.Root;\nexport const SelectBackdrop = Select.Backdrop;\nexport const SelectSeparator = Select.Separator;\n\nexport type SelectTriggerProps = Omit<\n ComponentPropsWithRef<typeof Select.Trigger>,\n 'children' | 'render'\n> & {\n children: ComponentProps<typeof Select.Trigger>['children'];\n shadow?: boolean;\n size?: SelectSize;\n variant?: SelectVariant;\n};\n\nexport const SelectTrigger = ({\n children,\n className,\n nativeButton,\n shadow,\n size = 'middle',\n variant,\n ref: refProp,\n ...rest\n}: SelectTriggerProps) => {\n const { isDarkMode } = useThemeMode();\n const resolvedVariant = variant ?? (isDarkMode ? 'filled' : 'outlined');\n const triggerStyle = triggerStyles({ shadow, size, variant: resolvedVariant });\n const baseClassName = stylex.props(triggerStyle).className;\n\n const { isNativeButtonTriggerElement, resolvedNativeButton } = useNativeButton({\n children,\n nativeButton,\n });\n\n if (isValidElement(children)) {\n return (\n <Select.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 childClassName =\n typeof (mergedProps as any).className === 'function'\n ? (mergedProps as any).className(state)\n : (mergedProps as any).className;\n const extraClassName = typeof className === 'function' ? className(state) : className;\n\n return cloneElement(children as any, {\n ...mergedProps,\n className: clsx(baseClassName, childClassName, extraClassName),\n ref: mergeRefs([(children as any).ref, (props as any).ref, refProp]),\n });\n }}\n />\n );\n }\n\n return (\n <Select.Trigger\n {...rest}\n className={mergeStateClassName([triggerStyle], className) as any}\n nativeButton={resolvedNativeButton}\n ref={refProp as any}\n >\n {children}\n </Select.Trigger>\n );\n};\n\nSelectTrigger.displayName = 'SelectTrigger';\n\nexport type SelectIconProps = ComponentProps<typeof Select.Icon>;\n\nexport const SelectIcon = ({ className, ...rest }: SelectIconProps) => {\n return <Select.Icon className={mergeStateClassName([styles.icon], className) as any} {...rest} />;\n};\n\nSelectIcon.displayName = 'SelectIcon';\n\nexport type SelectValueProps = ComponentProps<typeof Select.Value>;\n\nexport const SelectValue = ({ className, ...rest }: SelectValueProps) => {\n return (\n <Select.Value className={mergeStateClassName([styles.value], className) as any} {...rest} />\n );\n};\n\nSelectValue.displayName = 'SelectValue';\n\nexport type SelectPortalProps = ComponentProps<typeof Select.Portal> & {\n /**\n * When `container` is not provided, it uses a shared container created by `usePortalContainer`.\n */\n container?: HTMLElement | null;\n};\n\nexport const SelectPortal = ({ container, ...rest }: SelectPortalProps) => {\n const appElement = useAppElement();\n return <Select.Portal container={container ?? appElement ?? undefined} {...rest} />;\n};\n\nSelectPortal.displayName = 'SelectPortal';\n\nexport type SelectPositionerProps = ComponentProps<typeof Select.Positioner>;\n\nexport const SelectPositioner = ({\n align,\n alignItemWithTrigger,\n className,\n collisionPadding,\n side,\n sideOffset,\n style,\n ref: forwardedRef,\n ...rest\n}: SelectPositionerProps) => {\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([forwardedRef, zRef]);\n\n const resolvedStyle =\n typeof style === 'function'\n ? (state: any) => ({ zIndex, ...style(state) })\n : { zIndex, ...style };\n\n return (\n <Select.Positioner\n align={align ?? 'start'}\n alignItemWithTrigger={alignItemWithTrigger ?? false}\n className={mergeStateClassName([styles.positioner], className) as any}\n collisionPadding={collisionPadding ?? getFloatingCollisionPadding()}\n ref={composedRef as any}\n side={side ?? 'bottom'}\n sideOffset={sideOffset ?? 6}\n style={resolvedStyle}\n {...rest}\n />\n );\n};\n\nSelectPositioner.displayName = 'SelectPositioner';\n\nexport type SelectPopupProps = ComponentProps<typeof Select.Popup>;\n\nexport const SelectPopup = ({ className, ...rest }: SelectPopupProps) => {\n return (\n <Select.Popup\n className={\n mergeStateClassName(\n [menuStyles.popup, styles.popup],\n className,\n menuClassNames.popup,\n ) as any\n }\n {...rest}\n />\n );\n};\n\nSelectPopup.displayName = 'SelectPopup';\n\nexport type SelectListProps = ComponentProps<typeof Select.List>;\n\nexport const SelectList = ({ className, ...rest }: SelectListProps) => {\n return <Select.List className={mergeStateClassName([styles.list], className) as any} {...rest} />;\n};\n\nSelectList.displayName = 'SelectList';\n\nexport type SelectItemProps = ComponentProps<typeof Select.Item>;\n\nexport const SelectItem = ({ className, ...rest }: SelectItemProps) => {\n return (\n <Select.Item className={mergeStateClassName([menuStyles.item], className) as any} {...rest} />\n );\n};\n\nSelectItem.displayName = 'SelectItem';\n\nexport type SelectItemTextProps = ComponentProps<typeof Select.ItemText>;\n\nexport const SelectItemText = ({ className, ...rest }: SelectItemTextProps) => {\n return (\n <Select.ItemText\n className={mergeStateClassName([menuStyles.label], className, menuClassNames.label) as any}\n {...rest}\n />\n );\n};\n\nSelectItemText.displayName = 'SelectItemText';\n\nexport type SelectItemIndicatorProps = ComponentProps<typeof Select.ItemIndicator>;\n\nexport const SelectItemIndicator = ({ className, ...rest }: SelectItemIndicatorProps) => {\n return (\n <Select.ItemIndicator\n className={mergeStateClassName([styles.itemIndicator], className) as any}\n {...rest}\n />\n );\n};\n\nSelectItemIndicator.displayName = 'SelectItemIndicator';\n\nexport type SelectGroupProps = ComponentProps<typeof Select.Group>;\n\nexport const SelectGroup = ({ className, ...rest }: SelectGroupProps) => {\n return <Select.Group className={className} {...rest} />;\n};\n\nSelectGroup.displayName = 'SelectGroup';\n\nexport type SelectGroupLabelProps = ComponentProps<typeof Select.GroupLabel>;\n\nexport const SelectGroupLabel = ({ className, ...rest }: SelectGroupLabelProps) => {\n return (\n <Select.GroupLabel\n className={mergeStateClassName([menuStyles.groupLabel], className) as any}\n {...rest}\n />\n );\n};\n\nSelectGroupLabel.displayName = 'SelectGroupLabel';\n\nexport type SelectScrollUpArrowProps = ComponentProps<typeof Select.ScrollUpArrow>;\n\nexport const SelectScrollUpArrow = ({ className, ...rest }: SelectScrollUpArrowProps) => {\n return (\n <Select.ScrollUpArrow\n className={mergeStateClassName([styles.scrollArrow], className) as any}\n {...rest}\n />\n );\n};\n\nSelectScrollUpArrow.displayName = 'SelectScrollUpArrow';\n\nexport type SelectScrollDownArrowProps = ComponentProps<typeof Select.ScrollDownArrow>;\n\nexport const SelectScrollDownArrow = ({ className, ...rest }: SelectScrollDownArrowProps) => {\n return (\n <Select.ScrollDownArrow\n className={mergeStateClassName([styles.scrollArrow], className) as any}\n {...rest}\n />\n );\n};\n\nSelectScrollDownArrow.displayName = 'SelectScrollDownArrow';\n\nexport type SelectArrowProps = ComponentProps<typeof Select.Arrow>;\n\nexport const SelectArrow = ({ className, ...rest }: SelectArrowProps) => {\n return (\n <Select.Arrow\n className={mergeStateClassName([styles.arrow], className, 'lobe-select-arrow') as any}\n {...rest}\n />\n );\n};\n\nSelectArrow.displayName = 'SelectArrow';\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,MAAM,uBAAgC,MAAwC,WAAyE,UAAmB;CACxK,MAAM,gBAAgB,WAAW,MAAM,KAAK,CAAC,CAAC;CAC9C,IAAI,OAAO,cAAc,YAAY,QAAQ,UAAkB,KAAK,eAAe,UAAU,KAAK,CAAC;CACnG,OAAO,KAAK,eAAe,SAAS;AACtC;AACA,MAAa,aAAa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C,WACA,GAAG,WAC6B;CAChC,OAAO,oBAAC,OAAO,iBAAR;EAAwB,WAAW,oBAAoB,CAAC,OAAO,WAAW,GAAG,SAAS;EAAU,GAAI;CAAO,CAAA;AACpH;AACA,sBAAsB,cAAc;AAEpC,MAAa,eAAe,EAC1B,WACA,GAAG,WACmB;CACtB,OAAO,oBAAC,OAAO,OAAR;EAAc,WAAW,oBAAoB,CAAC,OAAO,KAAK,GAAG,WAAW,mBAAmB;EAAU,GAAI;CAAO,CAAA;AACzH;AACA,YAAY,cAAc"}
|
|
1
|
+
{"version":3,"file":"atoms.mjs","names":[],"sources":["../../src/Select/atoms.tsx"],"sourcesContent":["'use client';\n\nimport { mergeProps } from '@base-ui/react/merge-props';\nimport { Select } from '@base-ui/react/select';\nimport * as stylex from '@stylexjs/stylex';\nimport clsx from 'clsx';\nimport {\n cloneElement,\n type ComponentProps,\n type ComponentPropsWithRef,\n isValidElement,\n} from 'react';\n\nimport { useAppElement } from '@/ConfigProvider/AppElementContext';\nimport { menuClassNames, menuStyles } from '@/DropdownMenu/sharedStyle';\nimport { useNativeButton } from '@/hooks/useNativeButton';\nimport { getFloatingCollisionPadding } from '@/internal/floating';\nimport { styleProps } from '@/styles/stylex/props';\nimport { useThemeMode } from '@/styles/theme/scope';\nimport { mergeRefs, useMergeRefs } from '@/utils/mergeRefs';\n\nimport { useLayerZIndex } from '../internal/zIndex';\nimport { styles, triggerStyles } from './style';\nimport { type SelectSize, type SelectVariant } from './type';\n\nconst mergeStateClassName = <TState,>(\n base: Parameters<typeof styleProps>[0],\n className: string | ((state: TState) => string | undefined) | undefined,\n extra?: string,\n) => {\n const baseClassName = styleProps(base, extra).className;\n if (typeof className === 'function')\n return (state: TState) => clsx(baseClassName, className(state));\n return clsx(baseClassName, className);\n};\n\nexport const SelectRoot = Select.Root;\nexport const SelectBackdrop = Select.Backdrop;\nexport const SelectSeparator = Select.Separator;\n\nexport type SelectTriggerProps = Omit<\n ComponentPropsWithRef<typeof Select.Trigger>,\n 'children' | 'render'\n> & {\n children: ComponentProps<typeof Select.Trigger>['children'];\n shadow?: boolean;\n size?: SelectSize;\n variant?: SelectVariant;\n};\n\nexport const SelectTrigger = ({\n children,\n className,\n nativeButton,\n shadow,\n size = 'middle',\n variant,\n ref: refProp,\n ...rest\n}: SelectTriggerProps) => {\n const { isDarkMode } = useThemeMode();\n const resolvedVariant = variant ?? (isDarkMode ? 'filled' : 'outlined');\n const triggerStyle = triggerStyles({ shadow, size, variant: resolvedVariant });\n const baseClassName = stylex.props(triggerStyle).className;\n\n const { isNativeButtonTriggerElement, resolvedNativeButton } = useNativeButton({\n children,\n nativeButton,\n });\n\n if (isValidElement(children)) {\n return (\n <Select.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 childClassName =\n typeof (mergedProps as any).className === 'function'\n ? (mergedProps as any).className(state)\n : (mergedProps as any).className;\n const extraClassName = typeof className === 'function' ? className(state) : className;\n\n return cloneElement(children as any, {\n ...mergedProps,\n className: clsx(baseClassName, childClassName, extraClassName),\n ref: mergeRefs([(children as any).ref, (props as any).ref, refProp]),\n });\n }}\n />\n );\n }\n\n return (\n <Select.Trigger\n {...rest}\n className={mergeStateClassName([triggerStyle], className) as any}\n nativeButton={resolvedNativeButton}\n ref={refProp as any}\n >\n {children}\n </Select.Trigger>\n );\n};\n\nSelectTrigger.displayName = 'SelectTrigger';\n\nexport type SelectIconProps = ComponentProps<typeof Select.Icon>;\n\nexport const SelectIcon = ({ className, ...rest }: SelectIconProps) => {\n return <Select.Icon className={mergeStateClassName([styles.icon], className) as any} {...rest} />;\n};\n\nSelectIcon.displayName = 'SelectIcon';\n\nexport type SelectValueProps = ComponentProps<typeof Select.Value>;\n\nexport const SelectValue = ({ className, ...rest }: SelectValueProps) => {\n return (\n <Select.Value className={mergeStateClassName([styles.value], className) as any} {...rest} />\n );\n};\n\nSelectValue.displayName = 'SelectValue';\n\nexport type SelectPortalProps = ComponentProps<typeof Select.Portal> & {\n /**\n * When `container` is not provided, it uses a shared container created by `usePortalContainer`.\n */\n container?: HTMLElement | null;\n};\n\nexport const SelectPortal = ({ container, ...rest }: SelectPortalProps) => {\n const appElement = useAppElement();\n return <Select.Portal container={container ?? appElement ?? undefined} {...rest} />;\n};\n\nSelectPortal.displayName = 'SelectPortal';\n\nexport type SelectPositionerProps = ComponentProps<typeof Select.Positioner>;\n\nexport const SelectPositioner = ({\n align,\n alignItemWithTrigger,\n className,\n collisionPadding,\n side,\n sideOffset,\n style,\n ref: forwardedRef,\n ...rest\n}: SelectPositionerProps) => {\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([forwardedRef, zRef]);\n\n const resolvedStyle =\n typeof style === 'function'\n ? (state: any) => ({ zIndex, ...style(state) })\n : { zIndex, ...style };\n\n return (\n <Select.Positioner\n align={align ?? 'start'}\n alignItemWithTrigger={alignItemWithTrigger ?? false}\n className={mergeStateClassName([styles.positioner], className) as any}\n collisionPadding={collisionPadding ?? getFloatingCollisionPadding()}\n ref={composedRef as any}\n side={side ?? 'bottom'}\n sideOffset={sideOffset ?? 6}\n style={resolvedStyle}\n {...rest}\n />\n );\n};\n\nSelectPositioner.displayName = 'SelectPositioner';\n\nexport type SelectPopupProps = ComponentProps<typeof Select.Popup>;\n\nexport const SelectPopup = ({ className, ...rest }: SelectPopupProps) => {\n return (\n <Select.Popup\n className={\n mergeStateClassName(\n [menuStyles.popup, styles.popup],\n className,\n menuClassNames.popup,\n ) as any\n }\n {...rest}\n />\n );\n};\n\nSelectPopup.displayName = 'SelectPopup';\n\nexport type SelectListProps = ComponentProps<typeof Select.List>;\n\nexport const SelectList = ({ className, ...rest }: SelectListProps) => {\n return <Select.List className={mergeStateClassName([styles.list], className) as any} {...rest} />;\n};\n\nSelectList.displayName = 'SelectList';\n\nexport type SelectItemProps = ComponentProps<typeof Select.Item>;\n\nexport const SelectItem = ({ className, ...rest }: SelectItemProps) => {\n return (\n <Select.Item className={mergeStateClassName([menuStyles.item], className) as any} {...rest} />\n );\n};\n\nSelectItem.displayName = 'SelectItem';\n\nexport type SelectItemTextProps = ComponentProps<typeof Select.ItemText>;\n\nexport const SelectItemText = ({ className, ...rest }: SelectItemTextProps) => {\n return (\n <Select.ItemText\n className={mergeStateClassName([menuStyles.label], className, menuClassNames.label) as any}\n {...rest}\n />\n );\n};\n\nSelectItemText.displayName = 'SelectItemText';\n\nexport type SelectItemIndicatorProps = ComponentProps<typeof Select.ItemIndicator>;\n\nexport const SelectItemIndicator = ({ className, ...rest }: SelectItemIndicatorProps) => {\n return (\n <Select.ItemIndicator\n className={mergeStateClassName([styles.itemIndicator], className) as any}\n {...rest}\n />\n );\n};\n\nSelectItemIndicator.displayName = 'SelectItemIndicator';\n\nexport type SelectGroupProps = ComponentProps<typeof Select.Group>;\n\nexport const SelectGroup = ({ className, ...rest }: SelectGroupProps) => {\n return <Select.Group className={className} {...rest} />;\n};\n\nSelectGroup.displayName = 'SelectGroup';\n\nexport type SelectGroupLabelProps = ComponentProps<typeof Select.GroupLabel>;\n\nexport const SelectGroupLabel = ({ className, ...rest }: SelectGroupLabelProps) => {\n return (\n <Select.GroupLabel\n className={mergeStateClassName([menuStyles.groupLabel], className) as any}\n {...rest}\n />\n );\n};\n\nSelectGroupLabel.displayName = 'SelectGroupLabel';\n\nexport type SelectScrollUpArrowProps = ComponentProps<typeof Select.ScrollUpArrow>;\n\nexport const SelectScrollUpArrow = ({ className, ...rest }: SelectScrollUpArrowProps) => {\n return (\n <Select.ScrollUpArrow\n className={mergeStateClassName([styles.scrollArrow], className) as any}\n {...rest}\n />\n );\n};\n\nSelectScrollUpArrow.displayName = 'SelectScrollUpArrow';\n\nexport type SelectScrollDownArrowProps = ComponentProps<typeof Select.ScrollDownArrow>;\n\nexport const SelectScrollDownArrow = ({ className, ...rest }: SelectScrollDownArrowProps) => {\n return (\n <Select.ScrollDownArrow\n className={mergeStateClassName([styles.scrollArrow], className) as any}\n {...rest}\n />\n );\n};\n\nSelectScrollDownArrow.displayName = 'SelectScrollDownArrow';\n\nexport type SelectArrowProps = ComponentProps<typeof Select.Arrow>;\n\nexport const SelectArrow = ({ className, ...rest }: SelectArrowProps) => {\n return (\n <Select.Arrow\n className={mergeStateClassName([styles.arrow], className, 'lobe-select-arrow') as any}\n {...rest}\n />\n );\n};\n\nSelectArrow.displayName = 'SelectArrow';\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,MAAM,uBAAgC,MAAwC,WAAyE,UAAmB;CACxK,MAAM,gBAAgB,WAAW,MAAM,KAAK,CAAC,CAAC;CAC9C,IAAI,OAAO,cAAc,YAAY,QAAQ,UAAkB,KAAK,eAAe,UAAU,KAAK,CAAC;CACnG,OAAO,KAAK,eAAe,SAAS;AACtC;AACA,MAAa,aAAa,OAAO;AACjC,MAAa,iBAAiB,OAAO;AACrC,MAAa,kBAAkB,OAAO;AAOtC,MAAa,iBAAiB,EAC5B,UACA,WACA,cACA,QACA,OAAO,UACP,SACA,KAAK,SACL,GAAG,WACqB;CACxB,MAAM,EACJ,eACE,aAAa;CAEjB,MAAM,eAAe,cAAc;EACjC;EACA;EACA,SAJsB,YAAY,aAAa,WAAW;CAK5D,CAAC;CACD,MAAM,gBAAgB,OAAO,MAAM,YAAY,CAAC,CAAC;CACjD,MAAM,EACJ,8BACA,yBACE,gBAAgB;EAClB;EACA;CACF,CAAC;CACD,IAAI,eAAe,QAAQ,GACzB,OAAO,oBAAC,OAAO,SAAR;EAAgB,GAAI;EAAM,cAAc;EA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
|
|
3
3
|
import { focusRing } from "../styles/stylex/focusRing.mjs";
|
|
4
|
+
import { useControlledState } from "../hooks/useControlledState.mjs";
|
|
4
5
|
import { switchMarker } from "./marker.stylex.mjs";
|
|
5
6
|
import { styles } from "./style.mjs";
|
|
6
7
|
import { createContext, use, useEffect, useMemo, useRef, useState } from "react";
|
|
@@ -9,7 +10,6 @@ import clsx from "clsx";
|
|
|
9
10
|
import * as stylex from "@stylexjs/stylex";
|
|
10
11
|
import { Switch } from "@base-ui/react/switch";
|
|
11
12
|
import { animate, motionValue } from "motion";
|
|
12
|
-
import useControlledState from "use-merge-value";
|
|
13
13
|
//#region src/Switch/atoms.tsx
|
|
14
14
|
const THUMB_METRICS = {
|
|
15
15
|
default: {
|
package/es/Switch/atoms.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atoms.mjs","names":[],"sources":["../../src/Switch/atoms.tsx"],"sourcesContent":["'use client';\n\nimport './style.css';\n\nimport { Switch } from '@base-ui/react/switch';\nimport * as stylex from '@stylexjs/stylex';\nimport clsx from 'clsx';\nimport { animate, motionValue } from 'motion';\nimport type { CSSProperties, KeyboardEvent, MouseEvent, PointerEvent } from 'react';\nimport { createContext, use, useEffect, useMemo, useRef, useState } from 'react';\nimport useControlledState from 'use-merge-value';\n\nimport { focusRing } from '@/styles/stylex/focusRing';\nimport { styleProps } from '@/styles/stylex/props';\n\nimport { switchMarker } from './marker.stylex';\nimport { styles } from './style';\nimport type {\n SwitchChangeEventHandler,\n SwitchContextType,\n SwitchIconPosition,\n SwitchIconProps,\n SwitchRootProps,\n SwitchSize,\n SwitchThumbProps,\n} from './type';\n\nconst THUMB_METRICS: Record<\n SwitchSize,\n { checkedX: number; pressedCheckedX: number; pressedWidth: number; width: number }\n> = {\n default: { checkedX: 14, pressedCheckedX: 10, pressedWidth: 22, width: 18 },\n small: { checkedX: 12, pressedCheckedX: 8, pressedWidth: 16, width: 12 },\n};\n\nconst rootSizeStyles = { default: styles.rootDefault, small: styles.rootSmall };\nconst thumbSizeStyles = { default: styles.thumbDefault, small: styles.thumbSmall };\n\nconst THUMB_SPRING = { damping: 24, stiffness: 360, type: 'spring' as const };\n\nconst SwitchContext = createContext<SwitchContextType | null>(null);\n\nexport const useSwitchContext = () => {\n const context = use(SwitchContext);\n if (!context) {\n throw new Error('useSwitchContext must be used within a SwitchRoot');\n }\n return context;\n};\n\ntype SwitchRootInternalProps = Omit<SwitchRootProps, 'onCheckedChange' | 'onClick'> & {\n onCheckedChange?: SwitchChangeEventHandler;\n onClick?: SwitchChangeEventHandler;\n};\n\nexport const SwitchRoot = ({\n checked,\n className,\n defaultChecked,\n onCheckedChange,\n onClick,\n onKeyDown,\n onKeyUp,\n onPointerCancel,\n onPointerDown,\n onPointerLeave,\n onPointerUp,\n size = 'default',\n children,\n disabled,\n readOnly,\n required,\n inputRef,\n id,\n name,\n style,\n ...rest\n}: SwitchRootInternalProps) => {\n const [isPressed, setIsPressed] = useState(false);\n const lastEventRef = useRef<MouseEvent<HTMLButtonElement> | KeyboardEvent<HTMLButtonElement>>(\n null,\n );\n\n const [isChecked, setIsChecked] = useControlledState(defaultChecked ?? false, {\n defaultValue: defaultChecked,\n onChange: (value: boolean) => {\n if (lastEventRef.current) {\n onCheckedChange?.(value, lastEventRef.current);\n }\n },\n value: checked,\n });\n\n const contextValue = useMemo(\n () => ({\n isChecked: Boolean(isChecked),\n isPressed,\n setIsChecked: (value: boolean) => setIsChecked(value),\n setIsPressed,\n }),\n [isChecked, isPressed, setIsChecked],\n );\n\n const handleClick = (event: MouseEvent<HTMLButtonElement>) => {\n lastEventRef.current = event;\n onClick?.(!isChecked, event);\n };\n\n const isInteractive = !disabled && !readOnly;\n\n const handleKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {\n if (event.key === 'Enter' || event.key === ' ') {\n lastEventRef.current = event;\n }\n if (event.key === ' ' && isInteractive) {\n setIsPressed(true);\n }\n onKeyDown?.(event);\n };\n\n const handleKeyUp = (event: KeyboardEvent<HTMLButtonElement>) => {\n if (event.key === ' ') {\n setIsPressed(false);\n }\n onKeyUp?.(event);\n };\n\n const handlePointerDown = (event: PointerEvent<HTMLButtonElement>) => {\n if (isInteractive) {\n setIsPressed(true);\n }\n onPointerDown?.(event);\n };\n\n const handlePointerUp = (event: PointerEvent<HTMLButtonElement>) => {\n setIsPressed(false);\n onPointerUp?.(event);\n };\n\n const handlePointerCancel = (event: PointerEvent<HTMLButtonElement>) => {\n setIsPressed(false);\n onPointerCancel?.(event);\n };\n\n const handlePointerLeave = (event: PointerEvent<HTMLButtonElement>) => {\n setIsPressed(false);\n onPointerLeave?.(event);\n };\n\n return (\n <SwitchContext value={contextValue}>\n <Switch.Root\n nativeButton\n checked={isChecked}\n defaultChecked={defaultChecked}\n disabled={disabled}\n id={id}\n inputRef={inputRef}\n name={name}\n readOnly={readOnly}\n required={required}\n render={\n <button\n {...rest}\n {...styleProps(\n [switchMarker, focusRing.info, styles.root, rootSizeStyles[size]],\n clsx('lobe-switch', className),\n style,\n )}\n onClick={handleClick}\n onKeyDown={handleKeyDown}\n onKeyUp={handleKeyUp}\n onPointerCancel={handlePointerCancel}\n onPointerDown={handlePointerDown}\n onPointerLeave={handlePointerLeave}\n onPointerUp={handlePointerUp}\n />\n }\n onCheckedChange={setIsChecked}\n >\n {children}\n </Switch.Root>\n </SwitchContext>\n );\n};\n\nSwitchRoot.displayName = 'SwitchRoot';\n\nexport const SwitchThumb = ({\n className,\n size = 'default',\n style,\n children,\n ...rest\n}: SwitchThumbProps) => {\n const { isChecked, isPressed } = useSwitchContext();\n const ref = useRef<HTMLSpanElement>(null);\n\n const metrics = THUMB_METRICS[size];\n const targetX = isChecked ? (isPressed ? metrics.pressedCheckedX : metrics.checkedX) : 0;\n const targetWidth = isPressed ? metrics.pressedWidth : metrics.width;\n\n const [values] = useState(() => ({\n width: motionValue(targetWidth),\n x: motionValue(targetX),\n }));\n\n // animated keys stay referentially stable so React never rewrites mid-flight inline values\n const [initialStyle] = useState<CSSProperties>(\n () => ({ '--switch-x': `${targetX}px`, 'width': targetWidth }) as CSSProperties,\n );\n\n useEffect(() => {\n const el = ref.current;\n if (!el) return;\n const unsubscribeX = values.x.on('change', (x) => {\n el.style.setProperty('--switch-x', `${x}px`);\n });\n const unsubscribeWidth = values.width.on('change', (width) => {\n el.style.setProperty('width', `${width}px`);\n });\n return () => {\n unsubscribeX();\n unsubscribeWidth();\n };\n }, [values]);\n\n useEffect(() => {\n const reduceMotion = window.matchMedia?.('(prefers-reduced-motion: reduce)').matches ?? false;\n const transition = reduceMotion ? { duration: 0 } : THUMB_SPRING;\n const animations = [\n animate(values.x, targetX, transition),\n animate(values.width, targetWidth, transition),\n ];\n return () => {\n for (const animation of animations) animation.stop();\n };\n }, [values, targetX, targetWidth]);\n\n return (\n <Switch.Thumb\n render={\n <span\n {...rest}\n ref={ref}\n {...styleProps([styles.thumb, thumbSizeStyles[size]], className, {\n ...initialStyle,\n ...style,\n })}\n >\n {children}\n </span>\n }\n />\n );\n};\n\nSwitchThumb.displayName = 'SwitchThumb';\n\nconst iconPositionStyles: Record<SwitchIconPosition, stylex.StyleXStyles> = {\n left: styles.iconLeft,\n right: styles.iconRight,\n thumb: styles.iconThumb,\n};\n\nexport const SwitchIcon = ({\n children,\n className,\n position,\n size: _size,\n style,\n ...rest\n}: SwitchIconProps) => {\n return (\n <span {...styleProps([styles.icon, iconPositionStyles[position]], className, style)} {...rest}>\n {children}\n </span>\n );\n};\n\nSwitchIcon.displayName = 'SwitchIcon';\n\nconst switchClassNames = Object.fromEntries(\n Object.entries(styles).map(([key, value]) => [key, stylex.props(value).className ?? '']),\n) as Record<keyof typeof styles, string>;\n\nexport const switchStyles = {\n ...switchClassNames,\n iconLeftSmall: switchClassNames.iconLeft,\n iconRightSmall: switchClassNames.iconRight,\n};\n"],"mappings":";;;;;;;;;;;;;AAeA,MAAM,gBAKD;CACH,SAAS;EACP,UAAU;EACV,iBAAiB;EACjB,cAAc;EACd,OAAO;CACT;C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CAAC,CAAC,KAAK,CAAC,KAAK,WAAW,CAAC,KAAK,OAAO,MAAM,KAAK,CAAC,CAAC,aAAa,EAAE,CAAC,CAAC;AACpI,MAAa,eAAe;CAC1B,GAAG;CACH,eAAe,iBAAiB;CAChC,gBAAgB,iBAAiB;AACnC"}
|
|
1
|
+
{"version":3,"file":"atoms.mjs","names":[],"sources":["../../src/Switch/atoms.tsx"],"sourcesContent":["'use client';\n\nimport './style.css';\n\nimport { Switch } from '@base-ui/react/switch';\nimport * as stylex from '@stylexjs/stylex';\nimport clsx from 'clsx';\nimport { animate, motionValue } from 'motion';\nimport type { CSSProperties, KeyboardEvent, MouseEvent, PointerEvent } from 'react';\nimport { createContext, use, useEffect, useMemo, useRef, useState } from 'react';\n\nimport { useControlledState } from '@/hooks/useControlledState';\nimport { focusRing } from '@/styles/stylex/focusRing';\nimport { styleProps } from '@/styles/stylex/props';\n\nimport { switchMarker } from './marker.stylex';\nimport { styles } from './style';\nimport type {\n SwitchChangeEventHandler,\n SwitchContextType,\n SwitchIconPosition,\n SwitchIconProps,\n SwitchRootProps,\n SwitchSize,\n SwitchThumbProps,\n} from './type';\n\nconst THUMB_METRICS: Record<\n SwitchSize,\n { checkedX: number; pressedCheckedX: number; pressedWidth: number; width: number }\n> = {\n default: { checkedX: 14, pressedCheckedX: 10, pressedWidth: 22, width: 18 },\n small: { checkedX: 12, pressedCheckedX: 8, pressedWidth: 16, width: 12 },\n};\n\nconst rootSizeStyles = { default: styles.rootDefault, small: styles.rootSmall };\nconst thumbSizeStyles = { default: styles.thumbDefault, small: styles.thumbSmall };\n\nconst THUMB_SPRING = { damping: 24, stiffness: 360, type: 'spring' as const };\n\nconst SwitchContext = createContext<SwitchContextType | null>(null);\n\nexport const useSwitchContext = () => {\n const context = use(SwitchContext);\n if (!context) {\n throw new Error('useSwitchContext must be used within a SwitchRoot');\n }\n return context;\n};\n\ntype SwitchRootInternalProps = Omit<SwitchRootProps, 'onCheckedChange' | 'onClick'> & {\n onCheckedChange?: SwitchChangeEventHandler;\n onClick?: SwitchChangeEventHandler;\n};\n\nexport const SwitchRoot = ({\n checked,\n className,\n defaultChecked,\n onCheckedChange,\n onClick,\n onKeyDown,\n onKeyUp,\n onPointerCancel,\n onPointerDown,\n onPointerLeave,\n onPointerUp,\n size = 'default',\n children,\n disabled,\n readOnly,\n required,\n inputRef,\n id,\n name,\n style,\n ...rest\n}: SwitchRootInternalProps) => {\n const [isPressed, setIsPressed] = useState(false);\n const lastEventRef = useRef<MouseEvent<HTMLButtonElement> | KeyboardEvent<HTMLButtonElement>>(\n null,\n );\n\n const [isChecked, setIsChecked] = useControlledState(defaultChecked ?? false, {\n defaultValue: defaultChecked,\n onChange: (value: boolean) => {\n if (lastEventRef.current) {\n onCheckedChange?.(value, lastEventRef.current);\n }\n },\n value: checked,\n });\n\n const contextValue = useMemo(\n () => ({\n isChecked: Boolean(isChecked),\n isPressed,\n setIsChecked: (value: boolean) => setIsChecked(value),\n setIsPressed,\n }),\n [isChecked, isPressed, setIsChecked],\n );\n\n const handleClick = (event: MouseEvent<HTMLButtonElement>) => {\n lastEventRef.current = event;\n onClick?.(!isChecked, event);\n };\n\n const isInteractive = !disabled && !readOnly;\n\n const handleKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {\n if (event.key === 'Enter' || event.key === ' ') {\n lastEventRef.current = event;\n }\n if (event.key === ' ' && isInteractive) {\n setIsPressed(true);\n }\n onKeyDown?.(event);\n };\n\n const handleKeyUp = (event: KeyboardEvent<HTMLButtonElement>) => {\n if (event.key === ' ') {\n setIsPressed(false);\n }\n onKeyUp?.(event);\n };\n\n const handlePointerDown = (event: PointerEvent<HTMLButtonElement>) => {\n if (isInteractive) {\n setIsPressed(true);\n }\n onPointerDown?.(event);\n };\n\n const handlePointerUp = (event: PointerEvent<HTMLButtonElement>) => {\n setIsPressed(false);\n onPointerUp?.(event);\n };\n\n const handlePointerCancel = (event: PointerEvent<HTMLButtonElement>) => {\n setIsPressed(false);\n onPointerCancel?.(event);\n };\n\n const handlePointerLeave = (event: PointerEvent<HTMLButtonElement>) => {\n setIsPressed(false);\n onPointerLeave?.(event);\n };\n\n return (\n <SwitchContext value={contextValue}>\n <Switch.Root\n nativeButton\n checked={isChecked}\n defaultChecked={defaultChecked}\n disabled={disabled}\n id={id}\n inputRef={inputRef}\n name={name}\n readOnly={readOnly}\n required={required}\n render={\n <button\n {...rest}\n {...styleProps(\n [switchMarker, focusRing.info, styles.root, rootSizeStyles[size]],\n clsx('lobe-switch', className),\n style,\n )}\n onClick={handleClick}\n onKeyDown={handleKeyDown}\n onKeyUp={handleKeyUp}\n onPointerCancel={handlePointerCancel}\n onPointerDown={handlePointerDown}\n onPointerLeave={handlePointerLeave}\n onPointerUp={handlePointerUp}\n />\n }\n onCheckedChange={setIsChecked}\n >\n {children}\n </Switch.Root>\n </SwitchContext>\n );\n};\n\nSwitchRoot.displayName = 'SwitchRoot';\n\nexport const SwitchThumb = ({\n className,\n size = 'default',\n style,\n children,\n ...rest\n}: SwitchThumbProps) => {\n const { isChecked, isPressed } = useSwitchContext();\n const ref = useRef<HTMLSpanElement>(null);\n\n const metrics = THUMB_METRICS[size];\n const targetX = isChecked ? (isPressed ? metrics.pressedCheckedX : metrics.checkedX) : 0;\n const targetWidth = isPressed ? metrics.pressedWidth : metrics.width;\n\n const [values] = useState(() => ({\n width: motionValue(targetWidth),\n x: motionValue(targetX),\n }));\n\n // animated keys stay referentially stable so React never rewrites mid-flight inline values\n const [initialStyle] = useState<CSSProperties>(\n () => ({ '--switch-x': `${targetX}px`, 'width': targetWidth }) as CSSProperties,\n );\n\n useEffect(() => {\n const el = ref.current;\n if (!el) return;\n const unsubscribeX = values.x.on('change', (x) => {\n el.style.setProperty('--switch-x', `${x}px`);\n });\n const unsubscribeWidth = values.width.on('change', (width) => {\n el.style.setProperty('width', `${width}px`);\n });\n return () => {\n unsubscribeX();\n unsubscribeWidth();\n };\n }, [values]);\n\n useEffect(() => {\n const reduceMotion = window.matchMedia?.('(prefers-reduced-motion: reduce)').matches ?? false;\n const transition = reduceMotion ? { duration: 0 } : THUMB_SPRING;\n const animations = [\n animate(values.x, targetX, transition),\n animate(values.width, targetWidth, transition),\n ];\n return () => {\n for (const animation of animations) animation.stop();\n };\n }, [values, targetX, targetWidth]);\n\n return (\n <Switch.Thumb\n render={\n <span\n {...rest}\n ref={ref}\n {...styleProps([styles.thumb, thumbSizeStyles[size]], className, {\n ...initialStyle,\n ...style,\n })}\n >\n {children}\n </span>\n }\n />\n );\n};\n\nSwitchThumb.displayName = 'SwitchThumb';\n\nconst iconPositionStyles: Record<SwitchIconPosition, stylex.StyleXStyles> = {\n left: styles.iconLeft,\n right: styles.iconRight,\n thumb: styles.iconThumb,\n};\n\nexport const SwitchIcon = ({\n children,\n className,\n position,\n size: _size,\n style,\n ...rest\n}: SwitchIconProps) => {\n return (\n <span {...styleProps([styles.icon, iconPositionStyles[position]], className, style)} {...rest}>\n {children}\n </span>\n );\n};\n\nSwitchIcon.displayName = 'SwitchIcon';\n\nconst switchClassNames = Object.fromEntries(\n Object.entries(styles).map(([key, value]) => [key, stylex.props(value).className ?? '']),\n) as Record<keyof typeof styles, string>;\n\nexport const switchStyles = {\n ...switchClassNames,\n iconLeftSmall: switchClassNames.iconLeft,\n iconRightSmall: switchClassNames.iconRight,\n};\n"],"mappings":";;;;;;;;;;;;;AAeA,MAAM,gBAKD;CACH,SAAS;EACP,UAAU;EACV,iBAAiB;EACjB,cAAc;EACd,OAAO;CACT;CACA,OAAO;EACL,UAAU;EACV,iBAAiB;EACjB,cAAc;EACd,OAAO;CACT;AACF;AACA,MAAM,iBAAiB;CACrB,SAAS,OAAO;CAChB,OAAO,OAAO;AAChB;AACA,MAAM,kBAAkB;CACtB,SAAS,OAAO;CAChB,OAAO,OAAO;AAChB;AACA,MAAM,eAAe;CACnB,SAAS;CACT,WAAW;CACX,MAAM;AACR;AACA,MAAM,gBAAgB,cAAwC,IAAI;AAClE,MAAa,yBAAyB;CACpC,MAAM,UAAU,IA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State } from "../hooks/useControlledState.mjs";
|
|
3
4
|
import { styles } from "./style.mjs";
|
|
4
5
|
import { TabsIndicator, TabsList, TabsPanel, TabsRoot, TabsTab } from "./atoms.mjs";
|
|
6
|
+
import { useMemo } from "react";
|
|
5
7
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
8
|
import clsx from "clsx";
|
|
7
|
-
import useControlledState from "use-merge-value";
|
|
8
9
|
//#region src/Tabs/Tabs.tsx
|
|
9
10
|
const Tabs = ({ activeKey, className, classNames, defaultActiveKey, items, onChange, orientation = "horizontal", ref, size = "middle", style, styles: customStyles, variant = "rounded" }) => {
|
|
10
11
|
const initialActiveKey = defaultActiveKey ?? items?.find((item) => !item.disabled)?.key ?? null;
|
|
@@ -15,7 +16,38 @@ const Tabs = ({ activeKey, className, classNames, defaultActiveKey, items, onCha
|
|
|
15
16
|
},
|
|
16
17
|
value: activeKey
|
|
17
18
|
});
|
|
18
|
-
const
|
|
19
|
+
const list = useMemo(() => /* @__PURE__ */ jsxs(TabsList, {
|
|
20
|
+
className: classNames?.list,
|
|
21
|
+
style: customStyles?.list,
|
|
22
|
+
children: [/* @__PURE__ */ jsx(TabsIndicator, {
|
|
23
|
+
className: classNames?.indicator,
|
|
24
|
+
style: customStyles?.indicator
|
|
25
|
+
}), items?.map((item) => /* @__PURE__ */ jsxs(TabsTab, {
|
|
26
|
+
className: classNames?.tab,
|
|
27
|
+
disabled: item.disabled,
|
|
28
|
+
style: customStyles?.tab,
|
|
29
|
+
value: item.key,
|
|
30
|
+
children: [item.icon, item.label]
|
|
31
|
+
}, item.key))]
|
|
32
|
+
}), [
|
|
33
|
+
classNames?.indicator,
|
|
34
|
+
classNames?.list,
|
|
35
|
+
classNames?.tab,
|
|
36
|
+
customStyles?.indicator,
|
|
37
|
+
customStyles?.list,
|
|
38
|
+
customStyles?.tab,
|
|
39
|
+
items
|
|
40
|
+
]);
|
|
41
|
+
const panels = useMemo(() => items?.some((item) => item.children != null) ? items.map((item) => /* @__PURE__ */ jsx(TabsPanel, {
|
|
42
|
+
className: classNames?.panel,
|
|
43
|
+
style: customStyles?.panel,
|
|
44
|
+
value: item.key,
|
|
45
|
+
children: item.children
|
|
46
|
+
}, item.key)) : null, [
|
|
47
|
+
classNames?.panel,
|
|
48
|
+
customStyles?.panel,
|
|
49
|
+
items
|
|
50
|
+
]);
|
|
19
51
|
return /* @__PURE__ */ jsxs(TabsRoot, {
|
|
20
52
|
...styleProps(styles.root, clsx(classNames?.root, className), {
|
|
21
53
|
...style,
|
|
@@ -27,25 +59,7 @@ const Tabs = ({ activeKey, className, classNames, defaultActiveKey, items, onCha
|
|
|
27
59
|
value,
|
|
28
60
|
variant,
|
|
29
61
|
onValueChange: (next) => setValue(next ?? null),
|
|
30
|
-
children: [
|
|
31
|
-
className: classNames?.list,
|
|
32
|
-
style: customStyles?.list,
|
|
33
|
-
children: [/* @__PURE__ */ jsx(TabsIndicator, {
|
|
34
|
-
className: classNames?.indicator,
|
|
35
|
-
style: customStyles?.indicator
|
|
36
|
-
}), items?.map((item) => /* @__PURE__ */ jsxs(TabsTab, {
|
|
37
|
-
className: classNames?.tab,
|
|
38
|
-
disabled: item.disabled,
|
|
39
|
-
style: customStyles?.tab,
|
|
40
|
-
value: item.key,
|
|
41
|
-
children: [item.icon, item.label]
|
|
42
|
-
}, item.key))]
|
|
43
|
-
}), hasPanels && items?.map((item) => /* @__PURE__ */ jsx(TabsPanel, {
|
|
44
|
-
className: classNames?.panel,
|
|
45
|
-
style: customStyles?.panel,
|
|
46
|
-
value: item.key,
|
|
47
|
-
children: item.children
|
|
48
|
-
}, item.key))]
|
|
62
|
+
children: [list, panels]
|
|
49
63
|
});
|
|
50
64
|
};
|
|
51
65
|
Tabs.displayName = "Tabs";
|
package/es/Tabs/Tabs.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tabs.mjs","names":[],"sources":["../../src/Tabs/Tabs.tsx"],"sourcesContent":["'use client';\n\nimport clsx from 'clsx';\nimport { type FC } from 'react';\nimport useControlledState from '
|
|
1
|
+
{"version":3,"file":"Tabs.mjs","names":[],"sources":["../../src/Tabs/Tabs.tsx"],"sourcesContent":["'use client';\n\nimport clsx from 'clsx';\nimport { type FC, useMemo } from 'react';\n\nimport { useControlledState } from '@/hooks/useControlledState';\nimport { styleProps } from '@/styles/stylex/props';\n\nimport { TabsIndicator, TabsList, TabsPanel, TabsRoot, TabsTab } from './atoms';\nimport { styles } from './style';\nimport type { TabsProps } from './type';\n\nconst Tabs: FC<TabsProps> = ({\n activeKey,\n className,\n classNames,\n defaultActiveKey,\n items,\n onChange,\n orientation = 'horizontal',\n ref,\n size = 'middle',\n style,\n styles: customStyles,\n variant = 'rounded',\n}) => {\n const initialActiveKey = defaultActiveKey ?? items?.find((item) => !item.disabled)?.key ?? null;\n const [value, setValue] = useControlledState<string | null>(initialActiveKey, {\n defaultValue: initialActiveKey,\n onChange: (next) => {\n if (next != null) onChange?.(next);\n },\n value: activeKey,\n });\n\n const list = useMemo(\n () => (\n <TabsList className={classNames?.list} style={customStyles?.list}>\n <TabsIndicator className={classNames?.indicator} style={customStyles?.indicator} />\n {items?.map((item) => (\n <TabsTab\n className={classNames?.tab}\n disabled={item.disabled}\n key={item.key}\n style={customStyles?.tab}\n value={item.key}\n >\n {item.icon}\n {item.label}\n </TabsTab>\n ))}\n </TabsList>\n ),\n [\n classNames?.indicator,\n classNames?.list,\n classNames?.tab,\n customStyles?.indicator,\n customStyles?.list,\n customStyles?.tab,\n items,\n ],\n );\n\n const panels = useMemo(\n () =>\n items?.some((item) => item.children != null)\n ? items.map((item) => (\n <TabsPanel\n className={classNames?.panel}\n key={item.key}\n style={customStyles?.panel}\n value={item.key}\n >\n {item.children}\n </TabsPanel>\n ))\n : null,\n [classNames?.panel, customStyles?.panel, items],\n );\n\n return (\n <TabsRoot\n {...styleProps(styles.root, clsx(classNames?.root, className), {\n ...style,\n ...customStyles?.root,\n })}\n orientation={orientation}\n ref={ref}\n size={size}\n value={value}\n variant={variant}\n onValueChange={(next) => setValue(next ?? null)}\n >\n {list}\n {panels}\n </TabsRoot>\n );\n};\n\nTabs.displayName = 'Tabs';\n\nexport default Tabs;\n"],"mappings":";;;;;;;;;AAYA,MAAM,QAAuB,EAC3B,WACA,WACA,YACA,kBACA,OACA,UACA,cAAc,cACd,KACA,OAAO,UACP,OACA,QAAQ,cACR,UAAU,gBACN;CACJ,MAAM,mBAAmB,oBAAoB,OAAO,MAAM,SAAS,CAAC,KAAK,QAAQ,CAAC,EAAE,OAAO;CAC3F,MAAM,CAAC,OAAO,YAAY,mBAAkC,kBAAkB;EAC5E,cAAc;EACd,WAAW,SAAS;GAClB,IAAI,QAAQ,MAAM,WAAW,IAAI;EACnC;EACA,OAAO;CACT,CAAC;CAED,MAAM,OAAO,cAET,qBAAC,UAAD;EAAU,WAAW,YAAY;EAAM,OAAO,cAAc;EAA5D,UAAA,CACE,oBAAC,eAAD;GAAe,WAAW,YAAY;GAAW,OAAO,cAAc;EAAY,CAAA,GACjF,OAAO,KAAK,SACX,qBAAC,SAAD;GACE,WAAW,YAAY;GACvB,UAAU,KAAK;GAEf,OAAO,cAAc;GACrB,OAAO,KAAK;GALd,UAAA,CAOG,KAAK,MACL,KAAK,KACC;EANF,GAAA,KAAK,GAMH,CACV,CACO;CAEZ,CAAA,GAAA;EACE,YAAY;EACZ,YAAY;EACZ,YAAY;EACZ,cAAc;EACd,cAAc;EACd,cAAc;EACd;CACF,CACF;CAEA,MAAM,SAAS,cAEX,OAAO,MAAM,SAAS,KAAK,YAAY,IAAI,IACvC,MAAM,KAAK,SACT,oBAAC,WAAD;EACE,WAAW,YAAY;EAEvB,OAAO,cAAc;EACrB,OAAO,KAAK;EAEX,UAAA,KAAK;CACG,GALJ,KAAK,GAKD,CACZ,IACD,MACN;EAAC,YAAY;EAAO,cAAc;EAAO;CAAK,CAChD;CAEA,OACE,qBAAC,UAAD;EACE,GAAI,WAAW,OAAO,MAAM,KAAK,YAAY,MAAM,SAAS,GAAG;GAC7D,GAAG;GACH,GAAG,cAAc;EACnB,CAAC;EACY;EACR;EACC;EACC;EACE;EACT,gBAAgB,SAAS,SAAS,QAAQ,IAAI;EAVhD,UAAA,CAYG,MACA,MACO;;AAEd;AAEA,KAAK,cAAc"}
|
package/es/Text/style.d.mts
CHANGED
|
@@ -14,13 +14,13 @@ export declare const textStyles: {
|
|
|
14
14
|
text: string;
|
|
15
15
|
disabled: string;
|
|
16
16
|
danger: string;
|
|
17
|
-
success: string;
|
|
18
|
-
info: string;
|
|
19
|
-
warning: string;
|
|
20
17
|
delete: string;
|
|
21
18
|
ellipsis: string;
|
|
22
19
|
italic: string;
|
|
23
20
|
underline: string;
|
|
21
|
+
success: string;
|
|
22
|
+
warning: string;
|
|
23
|
+
info: string;
|
|
24
24
|
ellipsisMulti: string;
|
|
25
25
|
secondary: string;
|
|
26
26
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { useControlledState } from "../hooks/useControlledState.mjs";
|
|
2
3
|
import { ToggleGroupItem, ToggleGroupItemIcon, ToggleGroupItemLabel, ToggleGroupRoot } from "./atoms.mjs";
|
|
3
4
|
import { useMemo } from "react";
|
|
4
5
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
6
|
import clsx from "clsx";
|
|
6
|
-
import useControlledState from "use-merge-value";
|
|
7
7
|
//#region src/ToggleGroup/ToggleGroup.tsx
|
|
8
8
|
const normalizeOption = (option) => typeof option === "string" ? { value: option } : option;
|
|
9
9
|
const ToggleGroup = ({ className, classNames, defaultValue, disabled = false, onChange, options, ref, size = "middle", style, styles: customStyles, value, variant = "outlined" }) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ToggleGroup.mjs","names":[],"sources":["../../src/ToggleGroup/ToggleGroup.tsx"],"sourcesContent":["'use client';\n\nimport clsx from 'clsx';\nimport { useMemo } from 'react';\nimport useControlledState from '
|
|
1
|
+
{"version":3,"file":"ToggleGroup.mjs","names":[],"sources":["../../src/ToggleGroup/ToggleGroup.tsx"],"sourcesContent":["'use client';\n\nimport clsx from 'clsx';\nimport { useMemo } from 'react';\n\nimport { useControlledState } from '@/hooks/useControlledState';\n\nimport {\n ToggleGroupItem,\n ToggleGroupItemIcon,\n ToggleGroupItemLabel,\n ToggleGroupRoot,\n} from './atoms';\nimport type { ToggleGroupOption, ToggleGroupProps } from './type';\n\nconst normalizeOption = <Value extends string>(\n option: ToggleGroupOption<Value> | Value,\n): ToggleGroupOption<Value> => (typeof option === 'string' ? { value: option } : option);\n\nconst ToggleGroup = <Value extends string = string>({\n className,\n classNames,\n defaultValue,\n disabled = false,\n onChange,\n options,\n ref,\n size = 'middle',\n style,\n styles: customStyles,\n value,\n variant = 'outlined',\n}: ToggleGroupProps<Value>) => {\n const [innerValue, setInnerValue] = useControlledState<Value | undefined>(defaultValue, {\n defaultValue,\n onChange: (next) => {\n if (next != null) onChange?.(next);\n },\n value,\n });\n\n const normalizedOptions = useMemo(\n () => (options ?? []).map((o) => normalizeOption<Value>(o)),\n [options],\n );\n\n const groupValue = useMemo<Value[]>(() => (innerValue != null ? [innerValue] : []), [innerValue]);\n\n return (\n <ToggleGroupRoot<Value>\n className={clsx(classNames?.root, className)}\n disabled={disabled}\n ref={ref}\n style={{ ...style, ...customStyles?.root }}\n value={groupValue}\n variant={variant}\n onValueChange={(next) => {\n const picked = next[0];\n if (picked != null) setInnerValue(picked);\n }}\n >\n {normalizedOptions.map((opt) => (\n <ToggleGroupItem<Value>\n aria-label={typeof opt.label === 'string' ? opt.label : opt.title}\n className={clsx(classNames?.item, opt.className)}\n disabled={disabled || opt.disabled}\n key={opt.value}\n size={size}\n style={customStyles?.item}\n title={opt.title}\n value={opt.value}\n variant={variant}\n >\n {opt.icon != null && (\n <ToggleGroupItemIcon className={classNames?.itemIcon} style={customStyles?.itemIcon}>\n {opt.icon}\n </ToggleGroupItemIcon>\n )}\n {opt.label != null && (\n <ToggleGroupItemLabel className={classNames?.itemLabel} style={customStyles?.itemLabel}>\n {opt.label}\n </ToggleGroupItemLabel>\n )}\n </ToggleGroupItem>\n ))}\n </ToggleGroupRoot>\n );\n};\n\nToggleGroup.displayName = 'ToggleGroup';\n\nexport default ToggleGroup;\n"],"mappings":";;;;;;;AAeA,MAAM,mBACJ,WAC8B,OAAO,WAAW,WAAW,EAAE,OAAO,OAAO,IAAI;AAEjF,MAAM,eAA8C,EAClD,WACA,YACA,cACA,WAAW,OACX,UACA,SACA,KACA,OAAO,UACP,OACA,QAAQ,cACR,OACA,UAAU,iBACmB;CAC7B,MAAM,CAAC,YAAY,iBAAiB,mBAAsC,cAAc;EACtF;EACA,WAAW,SAAS;GAClB,IAAI,QAAQ,MAAM,WAAW,IAAI;EACnC;EACA;CACF,CAAC;CAED,MAAM,oBAAoB,eACjB,WAAW,CAAC,EAAA,CAAG,KAAK,MAAM,gBAAuB,CAAC,CAAC,GAC1D,CAAC,OAAO,CACV;CAEA,MAAM,aAAa,cAAwB,cAAc,OAAO,CAAC,UAAU,IAAI,CAAC,GAAI,CAAC,UAAU,CAAC;CAEhG,OACE,oBAAC,iBAAD;EACE,WAAW,KAAK,YAAY,MAAM,SAAS;EACjC;EACL;EACL,OAAO;GAAE,GAAG;GAAO,GAAG,cAAc;EAAK;EACzC,OAAO;EACE;EACT,gBAAgB,SAAS;GACvB,MAAM,SAAS,KAAK;GACpB,IAAI,UAAU,MAAM,cAAc,MAAM;EAC1C;EAEC,UAAA,kBAAkB,KAAK,QACtB,qBAAC,iBAAD;GACE,cAAY,OAAO,IAAI,UAAU,WAAW,IAAI,QAAQ,IAAI;GAC5D,WAAW,KAAK,YAAY,MAAM,IAAI,SAAS;GAC/C,UAAU,YAAY,IAAI;GAEpB;GACN,OAAO,cAAc;GACrB,OAAO,IAAI;GACX,OAAO,IAAI;GACF;GATX,UAAA,CAWG,IAAI,QAAQ,QACX,oBAAC,qBAAD;IAAqB,WAAW,YAAY;IAAU,OAAO,cAAc;IACxE,UAAA,IAAI;GACc,CAAA,GAEtB,IAAI,SAAS,QACZ,oBAAC,sBAAD;IAAsB,WAAW,YAAY;IAAW,OAAO,cAAc;IAC1E,UAAA,IAAI;GACe,CAAA,CAET;EAjBV,GAAA,IAAI,KAiBM,CAClB;CACc,CAAA;AAErB;AAEA,YAAY,cAAc"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { TooltipGroupHandleContext } from "./groupContext.mjs";
|
|
3
3
|
import { useNativeButton } from "../hooks/useNativeButton.mjs";
|
|
4
|
+
import { mergeRefs } from "../utils/mergeRefs.mjs";
|
|
4
5
|
import { useMergedTooltipProps } from "./useMergedTooltipProps.mjs";
|
|
5
6
|
import { cloneElement, isValidElement, use, useCallback, useMemo } from "react";
|
|
6
7
|
import { jsx } from "react/jsx-runtime";
|
|
7
8
|
import { mergeProps } from "@base-ui/react/merge-props";
|
|
8
9
|
import { Tooltip } from "@base-ui/react/tooltip";
|
|
9
|
-
import { mergeRefs } from "react-merge-refs";
|
|
10
10
|
//#region src/Tooltip/TooltipInGroup.tsx
|
|
11
11
|
const DEFAULT_OPEN_DELAY = 400;
|
|
12
12
|
const DEFAULT_CLOSE_DELAY = 100;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TooltipInGroup.mjs","names":["BaseTooltip"],"sources":["../../src/Tooltip/TooltipInGroup.tsx"],"sourcesContent":["'use client';\n\nimport { mergeProps } from '@base-ui/react/merge-props';\nimport { Tooltip as BaseTooltip } from '@base-ui/react/tooltip';\nimport { cloneElement, type FC, isValidElement, use, useCallback, useMemo } from 'react';\nimport {
|
|
1
|
+
{"version":3,"file":"TooltipInGroup.mjs","names":["BaseTooltip"],"sources":["../../src/Tooltip/TooltipInGroup.tsx"],"sourcesContent":["'use client';\n\nimport { mergeProps } from '@base-ui/react/merge-props';\nimport { Tooltip as BaseTooltip } from '@base-ui/react/tooltip';\nimport { cloneElement, type FC, isValidElement, use, useCallback, useMemo } from 'react';\n\nimport { useNativeButton } from '@/hooks/useNativeButton';\nimport { mergeRefs } from '@/utils/mergeRefs';\n\nimport { TooltipGroupHandleContext } from './groupContext';\nimport { type TooltipProps } from './type';\nimport { useMergedTooltipProps } from './useMergedTooltipProps';\n\nconst DEFAULT_OPEN_DELAY = 400;\nconst DEFAULT_CLOSE_DELAY = 100;\n\nexport const TooltipInGroup: FC<TooltipProps> = ({\n children,\n ref: refProp,\n arrow,\n className,\n classNames,\n closeDelay,\n defaultOpen,\n disabled: disabledProp,\n getPopupContainer,\n hotkey,\n hotkeyProps,\n mouseEnterDelay,\n mouseLeaveDelay,\n onOpenChange,\n open,\n openDelay,\n placement,\n popupContainer,\n popupProps,\n portalProps,\n positionerProps,\n standalone: _standalone,\n styles,\n title,\n triggerProps: triggerPropsProp,\n zIndex,\n ...restProps\n}) => {\n const tooltipProps = useMemo(\n () => ({\n arrow,\n className,\n classNames,\n closeDelay,\n defaultOpen,\n disabled: disabledProp,\n getPopupContainer,\n hotkey,\n hotkeyProps,\n mouseEnterDelay,\n mouseLeaveDelay,\n onOpenChange,\n open,\n openDelay,\n placement,\n popupContainer,\n popupProps,\n portalProps,\n positionerProps,\n styles,\n title,\n triggerProps: triggerPropsProp,\n zIndex,\n }),\n [\n arrow,\n className,\n classNames,\n closeDelay,\n defaultOpen,\n disabledProp,\n getPopupContainer,\n hotkey,\n hotkeyProps,\n mouseEnterDelay,\n mouseLeaveDelay,\n onOpenChange,\n open,\n openDelay,\n placement,\n popupContainer,\n popupProps,\n portalProps,\n positionerProps,\n styles,\n title,\n triggerPropsProp,\n zIndex,\n ],\n );\n\n const group = use(TooltipGroupHandleContext);\n const item = useMergedTooltipProps(tooltipProps);\n\n const resolvedOpenDelay = useMemo(() => {\n if (item.openDelay !== undefined) return item.openDelay;\n if (item.mouseEnterDelay !== undefined) return item.mouseEnterDelay * 1000;\n return DEFAULT_OPEN_DELAY;\n }, [item.mouseEnterDelay, item.openDelay]);\n\n const resolvedCloseDelay = useMemo(() => {\n if (item.closeDelay !== undefined) return item.closeDelay;\n if (item.mouseLeaveDelay !== undefined) return item.mouseLeaveDelay * 1000;\n return DEFAULT_CLOSE_DELAY;\n }, [item.closeDelay, item.mouseLeaveDelay]);\n\n const disabled = Boolean(item.disabled);\n\n const { isNativeButtonTriggerElement } = useNativeButton({\n children,\n });\n\n const childElement = isValidElement(children) ? children : null;\n const popupTriggerId =\n childElement &&\n (childElement as any).props['aria-haspopup'] !== undefined &&\n (childElement as any).props.id !== undefined\n ? (childElement as any).props.id\n : undefined;\n\n const renderTrigger = useCallback(\n (renderProps: unknown) => {\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, ...triggerRest } = renderProps as any;\n return triggerRest;\n })();\n\n const childProps = (childElement as any).props;\n const mergedProps = mergeProps(restProps, childProps, resolvedProps);\n const shouldPreservePopupTriggerId =\n childProps['aria-haspopup'] !== undefined && childProps.id !== undefined;\n\n return cloneElement(childElement as any, {\n ...mergedProps,\n id: shouldPreservePopupTriggerId ? childProps.id : mergedProps.id,\n ref: mergeRefs([(childElement as any).ref, (renderProps as any).ref, refProp]),\n });\n },\n [childElement, isNativeButtonTriggerElement, refProp, restProps],\n );\n\n // Don't render trigger behavior if no content\n\n if (item.title == null && !item.hotkey) {\n return children as any;\n }\n\n const triggerProps = {\n closeDelay: resolvedCloseDelay,\n delay: resolvedOpenDelay,\n disabled,\n ...item.triggerProps,\n id: popupTriggerId ?? item.triggerProps?.id,\n payload: item,\n };\n\n if (childElement) {\n return (\n <BaseTooltip.Trigger handle={group ?? undefined} {...triggerProps} render={renderTrigger} />\n );\n }\n\n return (\n <BaseTooltip.Trigger handle={group ?? undefined} {...triggerProps} ref={refProp}>\n {children}\n </BaseTooltip.Trigger>\n );\n};\n\nTooltipInGroup.displayName = 'TooltipInGroup';\n"],"mappings":";;;;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KAAA;CAEN,MAAM,gBAAgB,aACnB,gBAAyB;EAGxB,MAAM,uBAAuB;GAC3B,IAAI,8BAA8B,OAAO;GAEzC,MAAM,EAAE,MAAM,KAAK,YAAY,GAAG,gBAAgB;GAClD,OAAO;EACT,EAAA,CAAG;EAEH,MAAM,aAAc,aAAqB;EACzC,MAAM,cAAc,WAAW,WAAW,YAAY,aAAa;EACnE,MAAM,+BACJ,WAAW,qBAAqB,KAAA,KAAa,WAAW,OAAO,KAAA;EAEjE,OAAO,aAAa,cAAqB;GACvC,GAAG;GACH,IAAI,+BAA+B,WAAW,KAAK,YAAY;GAC/D,KAAK,UAAU;IAAE,aAAqB;IAAM,YAAoB;IAAK;GAAO,CAAC;EAC/E,CAAC;CACH,GACA;EAAC;EAAc;EAA8B;EAAS;CAAS,CACjE;CAIA,IAAI,KAAK,SAAS,QAAQ,CAAC,KAAK,QAC9B,OAAO;CAGT,MAAM,eAAe;EACnB,YAAY;EACZ,OAAO;EACP;EACA,GAAG,KAAK;EACR,IAAI,kBAAkB,KAAK,cAAc;EACzC,SAAS;CACX;CAEA,IAAI,cACF,OACE,oBAACA,QAAY,SAAb;EAAqB,QAAQ,SAAS,KAAA;EAAW,GAAI;EAAc,QAAQ;CAAgB,CAAA;CAI/F,OACE,oBAACA,QAAY,SAAb;EAAqB,QAAQ,SAAS,KAAA;EAAW,GAAI;EAAc,KAAK;EACrE;CACkB,CAAA;AAEzB;AAEA,eAAe,cAAc"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { useAppElement } from "../ConfigProvider/AppElementContext.mjs";
|
|
3
3
|
import { styleProps } from "../styles/stylex/props.mjs";
|
|
4
4
|
import { useNativeButton } from "../hooks/useNativeButton.mjs";
|
|
5
|
+
import { mergeRefs } from "../utils/mergeRefs.mjs";
|
|
5
6
|
import { useFloatingLayer } from "../hooks/useFloatingLayer.mjs";
|
|
6
7
|
import { useIsClient } from "../hooks/useIsClient.mjs";
|
|
7
8
|
import { getFloatingCollisionPadding } from "../internal/floating/collisionPadding.mjs";
|
|
@@ -14,7 +15,6 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
14
15
|
import clsx from "clsx";
|
|
15
16
|
import { mergeProps } from "@base-ui/react/merge-props";
|
|
16
17
|
import { Tooltip } from "@base-ui/react/tooltip";
|
|
17
|
-
import { mergeRefs } from "react-merge-refs";
|
|
18
18
|
//#region src/Tooltip/TooltipStandalone.tsx
|
|
19
19
|
const DEFAULT_OPEN_DELAY = 400;
|
|
20
20
|
const DEFAULT_CLOSE_DELAY = 100;
|