@seed-design/lynx-react 0.4.1 → 0.5.1

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.
Files changed (96) hide show
  1. package/lib/components/Accordion/Accordion.d.ts +56 -0
  2. package/lib/components/Accordion/Accordion.d.ts.map +1 -0
  3. package/lib/components/Accordion/Accordion.jsx +210 -0
  4. package/lib/components/Accordion/Accordion.namespace.d.ts +2 -0
  5. package/lib/components/Accordion/Accordion.namespace.d.ts.map +1 -0
  6. package/lib/components/Accordion/Accordion.namespace.js +17 -0
  7. package/lib/components/Accordion/index.d.ts +3 -0
  8. package/lib/components/Accordion/index.d.ts.map +1 -0
  9. package/lib/components/ActionButton/ActionButton.jsx +6 -6
  10. package/lib/components/AppBar/AppBar.jsx +1 -1
  11. package/lib/components/Badge/Badge.jsx +1 -1
  12. package/lib/components/BottomSheet/BottomSheet.d.ts.map +1 -1
  13. package/lib/components/BottomSheet/BottomSheet.jsx +6 -3
  14. package/lib/components/Box/Box.jsx +1 -1
  15. package/lib/components/Callout/Callout.d.ts +32 -0
  16. package/lib/components/Callout/Callout.d.ts.map +1 -0
  17. package/lib/components/Callout/Callout.jsx +113 -0
  18. package/lib/components/Callout/Callout.namespace.d.ts +2 -0
  19. package/lib/components/Callout/Callout.namespace.d.ts.map +1 -0
  20. package/lib/components/Callout/Callout.namespace.js +13 -0
  21. package/lib/components/Callout/index.d.ts +3 -0
  22. package/lib/components/Callout/index.d.ts.map +1 -0
  23. package/lib/components/Checkbox/Checkbox.d.ts.map +1 -1
  24. package/lib/components/Checkbox/Checkbox.jsx +36 -5
  25. package/lib/components/Chip/Chip.d.ts +66 -0
  26. package/lib/components/Chip/Chip.d.ts.map +1 -0
  27. package/lib/components/Chip/Chip.jsx +159 -0
  28. package/lib/components/Chip/Chip.namespace.d.ts +2 -0
  29. package/lib/components/Chip/Chip.namespace.d.ts.map +1 -0
  30. package/lib/components/Chip/Chip.namespace.js +16 -0
  31. package/lib/components/Chip/index.d.ts +3 -0
  32. package/lib/components/Chip/index.d.ts.map +1 -0
  33. package/lib/components/Divider/Divider.d.ts +31 -0
  34. package/lib/components/Divider/Divider.d.ts.map +1 -0
  35. package/lib/components/Divider/Divider.jsx +26 -0
  36. package/lib/components/Divider/index.d.ts +2 -0
  37. package/lib/components/Divider/index.d.ts.map +1 -0
  38. package/lib/components/Field/Field.jsx +1 -1
  39. package/lib/components/Icon/Icon.jsx +2 -2
  40. package/lib/components/ProgressCircle/ProgressCircle.jsx +2 -2
  41. package/lib/components/RadioGroup/RadioGroup.jsx +2 -2
  42. package/lib/components/Stack/Stack.jsx +1 -1
  43. package/lib/components/Switch/Switch.jsx +2 -2
  44. package/lib/components/Tabs/Tabs.d.ts +59 -0
  45. package/lib/components/Tabs/Tabs.d.ts.map +1 -0
  46. package/lib/components/Tabs/Tabs.jsx +419 -0
  47. package/lib/components/Tabs/Tabs.namespace.d.ts +2 -0
  48. package/lib/components/Tabs/Tabs.namespace.d.ts.map +1 -0
  49. package/lib/components/Tabs/Tabs.namespace.js +14 -0
  50. package/lib/components/Tabs/Tabs.utils.d.ts +18 -0
  51. package/lib/components/Tabs/Tabs.utils.d.ts.map +1 -0
  52. package/lib/components/Tabs/Tabs.utils.js +37 -0
  53. package/lib/components/Tabs/index.d.ts +3 -0
  54. package/lib/components/Tabs/index.d.ts.map +1 -0
  55. package/lib/components/TagGroup/TagGroup.jsx +2 -2
  56. package/lib/components/Text/Text.jsx +2 -2
  57. package/lib/components/TextField/TextField.jsx +2 -2
  58. package/lib/components/index.d.ts +5 -0
  59. package/lib/components/index.d.ts.map +1 -1
  60. package/lib/hooks/useIconColor.d.ts +2 -1
  61. package/lib/hooks/useIconColor.d.ts.map +1 -1
  62. package/lib/hooks/useIconColor.js +29 -5
  63. package/lib/hooks/usePressTap.d.ts.map +1 -1
  64. package/lib/hooks/usePressTap.js +1 -0
  65. package/lib/index.js +14 -5
  66. package/lib/utils/create-slot-recipe-context.jsx +1 -1
  67. package/package.json +2 -2
  68. package/src/components/Accordion/Accordion.namespace.ts +22 -0
  69. package/src/components/Accordion/Accordion.test.tsx +129 -0
  70. package/src/components/Accordion/Accordion.tsx +453 -0
  71. package/src/components/Accordion/index.ts +24 -0
  72. package/src/components/BottomSheet/BottomSheet.test.tsx +24 -0
  73. package/src/components/BottomSheet/BottomSheet.tsx +14 -2
  74. package/src/components/Callout/Callout.namespace.ts +14 -0
  75. package/src/components/Callout/Callout.test.tsx +188 -0
  76. package/src/components/Callout/Callout.tsx +272 -0
  77. package/src/components/Callout/index.ts +16 -0
  78. package/src/components/Checkbox/Checkbox.test.tsx +176 -0
  79. package/src/components/Checkbox/Checkbox.tsx +36 -2
  80. package/src/components/Chip/Chip.namespace.ts +20 -0
  81. package/src/components/Chip/Chip.test.tsx +113 -0
  82. package/src/components/Chip/Chip.tsx +373 -0
  83. package/src/components/Chip/index.ts +22 -0
  84. package/src/components/Divider/Divider.test.tsx +73 -0
  85. package/src/components/Divider/Divider.tsx +76 -0
  86. package/src/components/Divider/index.ts +1 -0
  87. package/src/components/Icon/Icon.test.tsx +129 -0
  88. package/src/components/Tabs/Tabs.namespace.ts +16 -0
  89. package/src/components/Tabs/Tabs.test.tsx +221 -0
  90. package/src/components/Tabs/Tabs.tsx +727 -0
  91. package/src/components/Tabs/Tabs.utils.ts +56 -0
  92. package/src/components/Tabs/index.ts +2 -0
  93. package/src/components/index.ts +5 -0
  94. package/src/hooks/useIconColor.ts +43 -5
  95. package/src/hooks/usePressTap.test.ts +13 -0
  96. package/src/hooks/usePressTap.ts +1 -0
@@ -0,0 +1,419 @@
1
+ import { useControllableState } from "../../hooks/useControllableState.js";
2
+ import { usePressTap } from "../../hooks/usePressTap.js";
3
+ import { createSlotRecipeContext } from "../../utils/create-slot-recipe-context.jsx";
4
+ import { getTabsLayoutWidth, getTabsOrderedItems, getTabsTriggerRects } from "./Tabs.utils.js";
5
+ import * as React from "@lynx-js/react";
6
+ import clsx from "clsx";
7
+ import { tabs } from "@seed-design/lynx-css/recipes/tabs";
8
+ //#region src/components/Tabs/Tabs.tsx
9
+ var { ClassNamesProvider, useClassNames } = createSlotRecipeContext(tabs);
10
+ function invokeSelectTab(pager, index, smooth) {
11
+ "background only";
12
+ if (!pager || index < 0) return;
13
+ try {
14
+ pager.invoke({
15
+ method: "selectTab",
16
+ params: {
17
+ index,
18
+ smooth
19
+ }
20
+ }).exec();
21
+ } catch {}
22
+ }
23
+ function invokeScrollToOffset(list, offset) {
24
+ "background only";
25
+ if (!list || offset < 0) return;
26
+ try {
27
+ list.invoke({
28
+ method: "scrollTo",
29
+ params: {
30
+ offset,
31
+ smooth: true
32
+ }
33
+ }).exec();
34
+ } catch {}
35
+ }
36
+ var TabsContext = React.createContext(null);
37
+ function useTabsContext(consumer) {
38
+ const context = React.useContext(TabsContext);
39
+ if (!context) throw new Error(`<${consumer}/> must be rendered inside <TabsRoot/>.`);
40
+ return context;
41
+ }
42
+ var TabsCarouselContext = React.createContext(null);
43
+ var TabsCarouselCameraContext = React.createContext(null);
44
+ function useTabsCarouselCameraContext() {
45
+ return React.useContext(TabsCarouselCameraContext) ?? false;
46
+ }
47
+ function useTabsCarouselContext(consumer) {
48
+ const context = React.useContext(TabsCarouselContext);
49
+ if (!context) throw new Error(`<${consumer}/> must be rendered inside <TabsCarousel/>.`);
50
+ return context;
51
+ }
52
+ var TabsRoot = React.forwardRef((props, ref) => {
53
+ const [variantProps, otherProps] = tabs.splitVariantProps(props);
54
+ const { children, className, style, value: valueProp, defaultValue, onValueChange, ...nativeProps } = otherProps;
55
+ const classNames = tabs(variantProps);
56
+ const [value, setValueInternal] = useControllableState({
57
+ value: valueProp,
58
+ defaultValue,
59
+ onChange(nextValue) {
60
+ "background only";
61
+ if (nextValue !== void 0) onValueChange?.(nextValue);
62
+ }
63
+ });
64
+ const [items, setItems] = React.useState([]);
65
+ const [contentValues, setContentValues] = React.useState([]);
66
+ const [indicatorValue, setIndicatorValue] = React.useState();
67
+ const [triggerWidths, setTriggerWidths] = React.useState({});
68
+ const listRef = React.useRef(null);
69
+ const pagerRef = React.useRef(null);
70
+ const indicatorRef = React.useMainThreadRef(null);
71
+ const pagerValues = React.useMemo(() => contentValues.filter((contentValue) => !items.find((item) => item.value === contentValue)?.disabled), [contentValues, items]);
72
+ const triggerRects = React.useMemo(() => getTabsTriggerRects(items.map((item) => item.value), triggerWidths), [items, triggerWidths]);
73
+ const visualValue = indicatorValue ?? value;
74
+ const indicatorIndex = items.findIndex((item) => item.value === visualValue);
75
+ const selectedPagerIndex = value === void 0 ? -1 : pagerValues.indexOf(value);
76
+ const selectedOffset = (value === void 0 ? void 0 : triggerRects[value])?.left ?? null;
77
+ const setListNode = React.useCallback((node) => {
78
+ listRef.current = node;
79
+ if (node && selectedOffset !== null) invokeScrollToOffset(node, selectedOffset);
80
+ }, [selectedOffset]);
81
+ const setPagerNode = React.useCallback((node) => {
82
+ pagerRef.current = node;
83
+ if (node && selectedPagerIndex >= 0) invokeSelectTab(node, selectedPagerIndex, false);
84
+ }, [selectedPagerIndex]);
85
+ const registerTrigger = React.useCallback((triggerValue, disabled) => {
86
+ setItems((current) => {
87
+ if (current.some((item) => item.value === triggerValue)) return current;
88
+ return [...current, {
89
+ value: triggerValue,
90
+ disabled
91
+ }];
92
+ });
93
+ return () => {
94
+ "background only";
95
+ setItems((current) => current.filter((item) => item.value !== triggerValue));
96
+ setTriggerWidths((current) => {
97
+ const next = { ...current };
98
+ delete next[triggerValue];
99
+ return next;
100
+ });
101
+ };
102
+ }, []);
103
+ const registerContent = React.useCallback((contentValue) => {
104
+ setContentValues((current) => current.includes(contentValue) ? current : [...current, contentValue]);
105
+ return () => {
106
+ "background only";
107
+ setContentValues((current) => current.filter((value) => value !== contentValue));
108
+ };
109
+ }, []);
110
+ const updateTriggerDisabled = React.useCallback((triggerValue, disabled) => {
111
+ setItems((current) => current.map((item) => item.value === triggerValue && item.disabled !== disabled ? {
112
+ ...item,
113
+ disabled
114
+ } : item));
115
+ }, []);
116
+ const syncTriggerOrder = React.useCallback((triggerValues) => {
117
+ setItems((current) => {
118
+ const ordered = getTabsOrderedItems(current, triggerValues);
119
+ return ordered.every((item, index) => item === current[index]) ? current : ordered;
120
+ });
121
+ }, []);
122
+ const updateTriggerWidth = React.useCallback((triggerValue, width) => {
123
+ setTriggerWidths((current) => current[triggerValue] === width ? current : {
124
+ ...current,
125
+ [triggerValue]: width
126
+ });
127
+ }, []);
128
+ const selectValue = React.useCallback((nextValue) => {
129
+ setIndicatorValue(void 0);
130
+ setValueInternal(nextValue);
131
+ }, [setValueInternal]);
132
+ const handlePagerWillChange = React.useCallback((targetIndex) => {
133
+ setIndicatorValue(pagerValues[targetIndex]);
134
+ }, [pagerValues]);
135
+ const handlePagerChange = React.useCallback((targetIndex) => {
136
+ const nextValue = pagerValues[targetIndex];
137
+ if (nextValue === void 0) return;
138
+ setIndicatorValue(void 0);
139
+ setValueInternal(nextValue);
140
+ }, [pagerValues, setValueInternal]);
141
+ React.useEffect(() => {
142
+ "background only";
143
+ if (selectedPagerIndex >= 0) invokeSelectTab(pagerRef.current, selectedPagerIndex, false);
144
+ if (selectedOffset !== null) invokeScrollToOffset(listRef.current, selectedOffset);
145
+ }, [selectedPagerIndex, selectedOffset]);
146
+ const contextValue = React.useMemo(() => ({
147
+ value,
148
+ visualValue,
149
+ variantProps,
150
+ items,
151
+ pagerValues,
152
+ indicatorIndex,
153
+ selectedPagerIndex,
154
+ indicatorRef,
155
+ triggerRects,
156
+ registerTrigger,
157
+ registerContent,
158
+ updateTriggerDisabled,
159
+ syncTriggerOrder,
160
+ updateTriggerWidth,
161
+ setListRef: setListNode,
162
+ setPagerRef: setPagerNode,
163
+ selectValue,
164
+ handlePagerWillChange,
165
+ handlePagerChange
166
+ }), [
167
+ value,
168
+ visualValue,
169
+ variantProps,
170
+ items,
171
+ pagerValues,
172
+ indicatorIndex,
173
+ selectedPagerIndex,
174
+ indicatorRef,
175
+ triggerRects,
176
+ registerTrigger,
177
+ registerContent,
178
+ updateTriggerDisabled,
179
+ syncTriggerOrder,
180
+ updateTriggerWidth,
181
+ setListNode,
182
+ setPagerNode,
183
+ selectValue,
184
+ handlePagerWillChange,
185
+ handlePagerChange
186
+ ]);
187
+ return <TabsContext.Provider value={contextValue}>
188
+ <ClassNamesProvider value={classNames}>
189
+ <view {...ref ? { ref } : {}} {...nativeProps} className={clsx(classNames.root, className)} style={style}>
190
+ {children}
191
+ </view>
192
+ </ClassNamesProvider>
193
+ </TabsContext.Provider>;
194
+ });
195
+ TabsRoot.displayName = "TabsRoot";
196
+ function getTabsTriggerValues(children) {
197
+ const values = [];
198
+ function visit(node) {
199
+ if (Array.isArray(node)) {
200
+ node.forEach(visit);
201
+ return;
202
+ }
203
+ if (!React.isValidElement(node)) return;
204
+ if (node.type === TabsTrigger) {
205
+ values.push(node.props.value);
206
+ return;
207
+ }
208
+ if (node.type === React.Fragment) visit(node.props.children);
209
+ }
210
+ visit(children);
211
+ return values;
212
+ }
213
+ var TabsList = React.forwardRef((props, ref) => {
214
+ const { children, className, style, ...nativeProps } = props;
215
+ const classNames = useClassNames();
216
+ const { items, setListRef, syncTriggerOrder } = useTabsContext("TabsList");
217
+ const triggerOrder = React.useMemo(() => getTabsTriggerValues(children), [children]);
218
+ React.useEffect(() => {
219
+ "background only";
220
+ syncTriggerOrder(triggerOrder);
221
+ }, [
222
+ items,
223
+ syncTriggerOrder,
224
+ triggerOrder
225
+ ]);
226
+ const mergedRef = React.useCallback((node) => {
227
+ setListRef(node);
228
+ if (typeof ref === "function") ref(node);
229
+ else if (ref) ref.current = node;
230
+ }, [ref, setListRef]);
231
+ return <scroll-view ref={mergedRef} {...nativeProps} scroll-orientation="horizontal" scroll-bar-enable={false} accessibility-element={false} accessibility-traits="tabbar" className={clsx(classNames.list, className)} style={style}>
232
+ <view className={classNames.listContent}>{children}</view>
233
+ </scroll-view>;
234
+ });
235
+ TabsList.displayName = "TabsList";
236
+ var TabsTrigger = React.forwardRef((props, ref) => {
237
+ const { children, className, style, value: triggerValue, disabled = false, "accessibility-label": accessibilityLabel, ...nativeProps } = props;
238
+ const context = useTabsContext("TabsTrigger");
239
+ const selected = context.value === triggerValue;
240
+ const visuallySelected = context.visualValue === triggerValue;
241
+ React.useEffect(() => {
242
+ "background only";
243
+ return context.registerTrigger(triggerValue, disabled);
244
+ }, [context.registerTrigger, triggerValue]);
245
+ React.useEffect(() => {
246
+ "background only";
247
+ context.updateTriggerDisabled(triggerValue, disabled);
248
+ }, [
249
+ context.updateTriggerDisabled,
250
+ triggerValue,
251
+ disabled
252
+ ]);
253
+ const { pressed: _pressed, ...pressHandlers } = usePressTap({
254
+ disabled,
255
+ onTap: React.useCallback(() => {
256
+ "background only";
257
+ context.selectValue(triggerValue);
258
+ }, [context.selectValue, triggerValue])
259
+ });
260
+ const handleLayoutChange = React.useCallback((...args) => {
261
+ "background only";
262
+ const width = getTabsLayoutWidth(args[0]);
263
+ if (width !== null) context.updateTriggerWidth(triggerValue, width);
264
+ }, [context.updateTriggerWidth, triggerValue]);
265
+ const triggerClasses = tabs({
266
+ ...context.variantProps,
267
+ selected: visuallySelected,
268
+ disabled
269
+ });
270
+ const label = typeof children === "string" || typeof children === "number" ? String(children) : void 0;
271
+ return <view {...ref ? { ref } : {}} {...nativeProps} {...pressHandlers} flatten={false} bindlayoutchange={handleLayoutChange} accessibility-element={true} accessibility-role-description="tab" accessibility-label={accessibilityLabel ?? label} accessibility-value={selected ? "selected" : "not selected"} accessibility-traits={disabled ? "disabled" : selected ? "selected" : "button"} className={clsx(triggerClasses.trigger, className)} style={style}>
272
+ <text className={triggerClasses.triggerLabel}>{children}</text>
273
+ </view>;
274
+ });
275
+ TabsTrigger.displayName = "TabsTrigger";
276
+ var TabsIndicator = React.forwardRef((props, ref) => {
277
+ const { className, style, ...nativeProps } = props;
278
+ const classNames = useClassNames();
279
+ const { indicatorRef, items, indicatorIndex, triggerRects } = useTabsContext("TabsIndicator");
280
+ const position = indicatorIndex;
281
+ const lowerIndex = Math.max(0, Math.floor(position));
282
+ const upperIndex = Math.min(items.length - 1, Math.ceil(position));
283
+ const progress = Math.max(0, Math.min(1, position - lowerIndex));
284
+ const lowerRect = triggerRects[items[lowerIndex]?.value ?? ""];
285
+ const upperRect = triggerRects[items[upperIndex]?.value ?? ""] ?? lowerRect;
286
+ const x = lowerRect ? lowerRect.left + ((upperRect?.left ?? lowerRect.left) - lowerRect.left) * progress : 0;
287
+ const width = lowerRect ? lowerRect.width + ((upperRect?.width ?? lowerRect.width) - lowerRect.width) * progress : 0;
288
+ return <view {...ref ? { ref } : {}} main-thread:ref={indicatorRef} {...nativeProps} accessibility-elements-hidden={true} className={clsx(classNames.indicator, className)} style={{
289
+ "--tabs-indicator-x": `${x}px`,
290
+ "--tabs-indicator-width": `${width}px`,
291
+ ...style
292
+ }} />;
293
+ });
294
+ TabsIndicator.displayName = "TabsIndicator";
295
+ var TabsContent = React.forwardRef((props, ref) => {
296
+ const { children, className, style, value: contentValue, ...nativeProps } = props;
297
+ const tabsContext = useTabsContext("TabsContent");
298
+ const inCarousel = useTabsCarouselCameraContext();
299
+ const selected = tabsContext.value === contentValue;
300
+ const disabled = tabsContext.items.find((item) => item.value === contentValue)?.disabled ?? false;
301
+ const contentClasses = tabs({
302
+ ...tabsContext.variantProps,
303
+ selected,
304
+ inCarousel
305
+ });
306
+ React.useEffect(() => {
307
+ "background only";
308
+ if (inCarousel) return tabsContext.registerContent(contentValue);
309
+ }, [
310
+ inCarousel,
311
+ tabsContext.registerContent,
312
+ contentValue
313
+ ]);
314
+ const content = <view {...ref ? { ref } : {}} {...nativeProps} accessibility-elements-hidden={!selected} accessibility-role-description="tabpanel" accessibility-value={selected ? "selected" : "not selected"} className={clsx(contentClasses.content, className)} style={style}>
315
+ {children}
316
+ </view>;
317
+ if (inCarousel) {
318
+ if (disabled) return null;
319
+ return <viewpager-item>{content}</viewpager-item>;
320
+ }
321
+ return content;
322
+ });
323
+ TabsContent.displayName = "TabsContent";
324
+ var TabsCarousel = React.forwardRef((props, ref) => {
325
+ const { children, className, style, swipeable = false, iosBackGestureEdgeWidth = 32, onSettle, onSwipeStart, onSwipeEnd, ...nativeProps } = props;
326
+ const classNames = useClassNames();
327
+ const contextValue = React.useMemo(() => ({
328
+ swipeable,
329
+ iosBackGestureEdgeWidth,
330
+ onSettle,
331
+ onSwipeStart,
332
+ onSwipeEnd
333
+ }), [
334
+ swipeable,
335
+ iosBackGestureEdgeWidth,
336
+ onSettle,
337
+ onSwipeStart,
338
+ onSwipeEnd
339
+ ]);
340
+ return <TabsCarouselContext.Provider value={contextValue}>
341
+ <view {...ref ? { ref } : {}} {...nativeProps} className={clsx(classNames.carousel, className)} style={style}>
342
+ {children}
343
+ </view>
344
+ </TabsCarouselContext.Provider>;
345
+ });
346
+ TabsCarousel.displayName = "TabsCarousel";
347
+ var TabsCarouselCamera = React.forwardRef((props, ref) => {
348
+ const { children, className, style, bindchange, bindwillchange, bindoffsetchange, ...nativeProps } = props;
349
+ const classNames = useClassNames();
350
+ const tabsContext = useTabsContext("TabsCarouselCamera");
351
+ const carouselContext = useTabsCarouselContext("TabsCarouselCamera");
352
+ const swipingRef = React.useRef(false);
353
+ const { indicatorRef, pagerValues, triggerRects } = tabsContext;
354
+ const indicatorRects = pagerValues.map((value) => triggerRects[value] ?? null);
355
+ const mergedRef = React.useCallback((node) => {
356
+ tabsContext.setPagerRef(node);
357
+ if (typeof ref === "function") ref(node);
358
+ else if (ref) ref.current = node;
359
+ }, [ref, tabsContext.setPagerRef]);
360
+ const handleWillChange = React.useCallback((event) => {
361
+ "background only";
362
+ bindwillchange?.(event);
363
+ if (event.detail.isDragged) {
364
+ tabsContext.handlePagerWillChange(event.detail.index);
365
+ if (!swipingRef.current) {
366
+ swipingRef.current = true;
367
+ carouselContext.onSwipeStart?.();
368
+ }
369
+ }
370
+ }, [
371
+ bindwillchange,
372
+ carouselContext.onSwipeStart,
373
+ tabsContext.handlePagerWillChange
374
+ ]);
375
+ const handleChange = React.useCallback((event) => {
376
+ "background only";
377
+ bindchange?.(event);
378
+ tabsContext.handlePagerChange(event.detail.index);
379
+ carouselContext.onSettle?.();
380
+ if (swipingRef.current || event.detail.isDragged) {
381
+ swipingRef.current = false;
382
+ carouselContext.onSwipeEnd?.();
383
+ }
384
+ }, [
385
+ bindchange,
386
+ carouselContext.onSettle,
387
+ carouselContext.onSwipeEnd,
388
+ tabsContext.handlePagerChange
389
+ ]);
390
+ const handleOffsetChange = React.useCallback((event) => {
391
+ "background only";
392
+ bindoffsetchange?.(event);
393
+ }, [bindoffsetchange]);
394
+ function handleIndicatorOffsetChange(event) {
395
+ "main thread";
396
+ const position = Number(event.detail.offset);
397
+ if (!Number.isFinite(position)) return;
398
+ const lowerIndex = Math.max(0, Math.floor(position));
399
+ const upperIndex = Math.min(indicatorRects.length - 1, Math.ceil(position));
400
+ const progress = Math.max(0, Math.min(1, position - lowerIndex));
401
+ const lowerRect = indicatorRects[lowerIndex];
402
+ const upperRect = indicatorRects[upperIndex] ?? lowerRect;
403
+ if (!lowerRect) return;
404
+ const x = lowerRect.left + ((upperRect?.left ?? lowerRect.left) - lowerRect.left) * progress;
405
+ const width = lowerRect.width + ((upperRect?.width ?? lowerRect.width) - lowerRect.width) * progress;
406
+ indicatorRef.current?.setStyleProperties({
407
+ "--tabs-indicator-x": `${x}px`,
408
+ "--tabs-indicator-width": `${width}px`
409
+ });
410
+ }
411
+ return <viewpager ref={mergedRef} {...nativeProps} initial-select-index={Math.max(0, tabsContext.selectedPagerIndex)} enable-scroll={carouselContext.swipeable} ios-gesture-offset={carouselContext.iosBackGestureEdgeWidth} bindwillchange={handleWillChange} bindchange={handleChange} bindoffsetchange={handleOffsetChange} main-thread:bindoffsetchange={handleIndicatorOffsetChange} className={clsx(classNames.carouselCamera, className)} style={style}>
412
+ <TabsCarouselCameraContext.Provider value={true}>
413
+ {children}
414
+ </TabsCarouselCameraContext.Provider>
415
+ </viewpager>;
416
+ });
417
+ TabsCarouselCamera.displayName = "TabsCarouselCamera";
418
+ //#endregion
419
+ export { TabsCarousel, TabsCarouselCamera, TabsContent, TabsIndicator, TabsList, TabsRoot, TabsTrigger };
@@ -0,0 +1,2 @@
1
+ export { TabsCarousel as Carousel, TabsCarouselCamera as CarouselCamera, TabsContent as Content, TabsIndicator as Indicator, TabsList as List, TabsRoot as Root, TabsTrigger as Trigger, type TabsCarouselCameraProps as CarouselCameraProps, type TabsCarouselProps as CarouselProps, type TabsContentProps as ContentProps, type TabsIndicatorProps as IndicatorProps, type TabsListProps as ListProps, type TabsRootProps as RootProps, type TabsTriggerProps as TriggerProps, } from './Tabs';
2
+ //# sourceMappingURL=Tabs.namespace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Tabs.namespace.d.ts","sourceRoot":"","sources":["../../../src/components/Tabs/Tabs.namespace.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,IAAI,QAAQ,EACxB,kBAAkB,IAAI,cAAc,EACpC,WAAW,IAAI,OAAO,EACtB,aAAa,IAAI,SAAS,EAC1B,QAAQ,IAAI,IAAI,EAChB,QAAQ,IAAI,IAAI,EAChB,WAAW,IAAI,OAAO,EACtB,KAAK,uBAAuB,IAAI,mBAAmB,EACnD,KAAK,iBAAiB,IAAI,aAAa,EACvC,KAAK,gBAAgB,IAAI,YAAY,EACrC,KAAK,kBAAkB,IAAI,cAAc,EACzC,KAAK,aAAa,IAAI,SAAS,EAC/B,KAAK,aAAa,IAAI,SAAS,EAC/B,KAAK,gBAAgB,IAAI,YAAY,GACtC,MAAM,QAAQ,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { __exportAll } from "../../_virtual/_rolldown/runtime.js";
2
+ import { TabsCarousel, TabsCarouselCamera, TabsContent, TabsIndicator, TabsList, TabsRoot, TabsTrigger } from "./Tabs.jsx";
3
+ //#region src/components/Tabs/Tabs.namespace.ts
4
+ var Tabs_namespace_exports = /* @__PURE__ */ __exportAll({
5
+ Carousel: () => TabsCarousel,
6
+ CarouselCamera: () => TabsCarouselCamera,
7
+ Content: () => TabsContent,
8
+ Indicator: () => TabsIndicator,
9
+ List: () => TabsList,
10
+ Root: () => TabsRoot,
11
+ Trigger: () => TabsTrigger
12
+ });
13
+ //#endregion
14
+ export { Tabs_namespace_exports };
@@ -0,0 +1,18 @@
1
+ export interface TabsLayoutChangeEvent {
2
+ detail?: {
3
+ width?: number;
4
+ };
5
+ params?: {
6
+ width?: number;
7
+ };
8
+ }
9
+ export interface TabsLayoutRect {
10
+ left: number;
11
+ width: number;
12
+ }
13
+ export declare function getTabsLayoutWidth(event: TabsLayoutChangeEvent): number | null;
14
+ export declare function getTabsOrderedItems<T extends {
15
+ value: string;
16
+ }>(items: T[], values: string[]): T[];
17
+ export declare function getTabsTriggerRects(values: string[], widths: Record<string, number>): Record<string, TabsLayoutRect>;
18
+ //# sourceMappingURL=Tabs.utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Tabs.utils.d.ts","sourceRoot":"","sources":["../../../src/components/Tabs/Tabs.utils.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,qBAAqB;IACpC,MAAM,CAAC,EAAE;QACP,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,MAAM,CAAC,EAAE;QACP,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;CACH;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,qBAAqB,GAAG,MAAM,GAAG,IAAI,CAI9E;AAED,wBAAgB,mBAAmB,CAAC,CAAC,SAAS;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,EAC7D,KAAK,EAAE,CAAC,EAAE,EACV,MAAM,EAAE,MAAM,EAAE,GACf,CAAC,EAAE,CAUL;AAED,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,EAAE,EAChB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC7B,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAiBhC"}
@@ -0,0 +1,37 @@
1
+ //#region src/components/Tabs/Tabs.utils.ts
2
+ function getTabsLayoutWidth(event) {
3
+ const width = event.detail?.width ?? event.params?.width;
4
+ if (typeof width !== "number" || !Number.isFinite(width)) return null;
5
+ return Math.max(0, width);
6
+ }
7
+ function getTabsOrderedItems(items, values) {
8
+ const itemsByValue = new Map(items.map((item) => [item.value, item]));
9
+ const ordered = values.flatMap((value) => {
10
+ const item = itemsByValue.get(value);
11
+ if (!item) return [];
12
+ itemsByValue.delete(value);
13
+ return [item];
14
+ });
15
+ ordered.push(...itemsByValue.values());
16
+ return ordered;
17
+ }
18
+ function getTabsTriggerRects(values, widths) {
19
+ const rects = Object.create(null);
20
+ let left = 0;
21
+ let hasCompletePrefix = true;
22
+ for (const value of values) {
23
+ const width = Object.prototype.hasOwnProperty.call(widths, value) ? widths[value] : void 0;
24
+ if (width === void 0) {
25
+ hasCompletePrefix = false;
26
+ continue;
27
+ }
28
+ if (hasCompletePrefix) rects[value] = {
29
+ left,
30
+ width
31
+ };
32
+ left += width;
33
+ }
34
+ return rects;
35
+ }
36
+ //#endregion
37
+ export { getTabsLayoutWidth, getTabsOrderedItems, getTabsTriggerRects };
@@ -0,0 +1,3 @@
1
+ export * from './Tabs';
2
+ export * as Tabs from './Tabs.namespace';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Tabs/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,OAAO,KAAK,IAAI,MAAM,kBAAkB,CAAC"}
@@ -1,9 +1,9 @@
1
- import { createSlotRecipeContext } from "../../utils/create-slot-recipe-context.jsx";
2
1
  import { toArray } from "../../utils/children.js";
2
+ import { createSlotRecipeContext } from "../../utils/create-slot-recipe-context.jsx";
3
3
  import { useStyleProps } from "../../utils/styled.js";
4
4
  import { splitMultipleVariantsProps } from "../../utils/split-multiple-variants-props.js";
5
- import clsx from "clsx";
6
5
  import * as React from "@lynx-js/react";
6
+ import clsx from "clsx";
7
7
  import { tagGroup } from "@seed-design/lynx-css/recipes/tag-group";
8
8
  import { tagGroupItem } from "@seed-design/lynx-css/recipes/tag-group-item";
9
9
  //#region src/components/TagGroup/TagGroup.tsx
@@ -1,7 +1,7 @@
1
1
  import { handleColor, handleFontSize, handleFontWeight, handleLineHeight } from "../../utils/styled.js";
2
- import { typography } from "@seed-design/lynx-css/vars/component";
3
- import clsx from "clsx";
4
2
  import * as React from "@lynx-js/react";
3
+ import clsx from "clsx";
4
+ import { typography } from "@seed-design/lynx-css/vars/component";
5
5
  //#region src/components/Text/Text.tsx
6
6
  function capitalize(value) {
7
7
  return value.charAt(0).toUpperCase() + value.slice(1);
@@ -3,9 +3,9 @@ import { InternalIcon } from "../Icon/Icon.jsx";
3
3
  import { useFieldContext } from "../Field/context.js";
4
4
  import { useKeyboardAvoidanceActions } from "../KeyboardAvoidingScrollView/context.js";
5
5
  import { NATIVE_TEXT_MAX_LENGTH_UNLIMITED, TextFieldContext } from "./context.js";
6
- import { textInput } from "@seed-design/lynx-css/vars/component";
7
- import clsx from "clsx";
8
6
  import * as React from "@lynx-js/react";
7
+ import clsx from "clsx";
8
+ import { textInput } from "@seed-design/lynx-css/vars/component";
9
9
  import { textInput as textInput$1 } from "@seed-design/lynx-css/recipes/text-input";
10
10
  //#region src/components/TextField/TextField.tsx
11
11
  var ANDROID_TEXTAREA_DEFAULT_LINE_SPACING = "3.2px";
@@ -1,9 +1,13 @@
1
+ export * from './Accordion';
1
2
  export * from './ActionButton';
2
3
  export * from './AppBar';
3
4
  export * from './Badge';
4
5
  export * from './Box';
5
6
  export * from './BottomSheet';
7
+ export * from './Callout';
6
8
  export * from './Checkbox';
9
+ export * from './Chip';
10
+ export * from './Divider';
7
11
  export * from './Field';
8
12
  export * from './Icon';
9
13
  export * from './KeyboardAvoidingScrollView';
@@ -11,6 +15,7 @@ export * from './ProgressCircle';
11
15
  export * from './RadioGroup';
12
16
  export * from './Stack';
13
17
  export * from './Switch';
18
+ export * from './Tabs';
14
19
  export * from './TagGroup';
15
20
  export * from './Text';
16
21
  export * from './TextField';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,8BAA8B,CAAC;AAC7C,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,8BAA8B,CAAC;AAC7C,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC"}
@@ -5,7 +5,8 @@ export interface UseIconColorOptions {
5
5
  }
6
6
  /**
7
7
  * Lynx `<image>` 의 tint color 를 recipe 의 CSS `color` 로부터 main-thread 에서 읽어
8
- * `tint-color` attribute 로 mirror. `deps` 가 바뀌면 재동기화.
8
+ * `tint-color` attribute 로 mirror. `deps` 가 바뀌면 native class patch가 반영된
9
+ * 다음 frame에 재동기화하고, UI 표시 이벤트에서는 즉시 동기화.
9
10
  *
10
11
  * ```tsx
11
12
  * const iconColorProps = useIconColor([variant, disabled, loading]);
@@ -1 +1 @@
1
- {"version":3,"file":"useIconColor.d.ts","sourceRoot":"","sources":["../../src/hooks/useIconColor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAOhE,MAAM,WAAW,mBAAmB;IAClC,SAAS,CAAC,EAAE,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;CAC3C;AAyBD;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,cAAc,EACpB,OAAO,CAAC,EAAE,mBAAmB,GAC5B;IACD,GAAG,EAAE,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IACnC,0BAA0B,EAAE,MAAM,IAAI,CAAC;CACxC,CAeA"}
1
+ {"version":3,"file":"useIconColor.d.ts","sourceRoot":"","sources":["../../src/hooks/useIconColor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAOhE,MAAM,WAAW,mBAAmB;IAClC,SAAS,CAAC,EAAE,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;CAC3C;AA0DD;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,cAAc,EACpB,OAAO,CAAC,EAAE,mBAAmB,GAC5B;IACD,GAAG,EAAE,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IACnC,0BAA0B,EAAE,MAAM,IAAI,CAAC;CACxC,CAmBA"}
@@ -1,6 +1,6 @@
1
1
  import { runOnMainThread, useEffect, useMainThreadRef } from "@lynx-js/react";
2
2
  //#region src/hooks/useIconColor.ts
3
- function syncTintColor(targetRef, sourceRef) {
3
+ function syncTintColorOnce(targetRef, sourceRef) {
4
4
  "main thread";
5
5
  const target = targetRef.current;
6
6
  if (!target) return;
@@ -8,11 +8,31 @@ function syncTintColor(targetRef, sourceRef) {
8
8
  let color;
9
9
  if (typeof source.getComputedStyleProperty === "function") color = source.getComputedStyleProperty("color");
10
10
  else if (typeof source.getComputedCssProperty === "function") color = source.getComputedCssProperty("color");
11
- if (color) target.setAttribute("tint-color", color);
11
+ if (color && target.getAttribute("tint-color") !== color) target.setAttribute("tint-color", color);
12
+ }
13
+ function scheduleTintColorSync(targetRef, sourceRef, frameRef) {
14
+ "main thread";
15
+ if (frameRef.current && typeof cancelAnimationFrame === "function") {
16
+ cancelAnimationFrame(frameRef.current);
17
+ frameRef.current = 0;
18
+ }
19
+ if (typeof requestAnimationFrame === "function") frameRef.current = requestAnimationFrame(() => {
20
+ frameRef.current = 0;
21
+ syncTintColorOnce(targetRef, sourceRef);
22
+ });
23
+ else syncTintColorOnce(targetRef, sourceRef);
24
+ }
25
+ function cancelTintColorSync(frameRef) {
26
+ "main thread";
27
+ if (frameRef.current && typeof cancelAnimationFrame === "function") {
28
+ cancelAnimationFrame(frameRef.current);
29
+ frameRef.current = 0;
30
+ }
12
31
  }
13
32
  /**
14
33
  * Lynx `<image>` 의 tint color 를 recipe 의 CSS `color` 로부터 main-thread 에서 읽어
15
- * `tint-color` attribute 로 mirror. `deps` 가 바뀌면 재동기화.
34
+ * `tint-color` attribute 로 mirror. `deps` 가 바뀌면 native class patch가 반영된
35
+ * 다음 frame에 재동기화하고, UI 표시 이벤트에서는 즉시 동기화.
16
36
  *
17
37
  * ```tsx
18
38
  * const iconColorProps = useIconColor([variant, disabled, loading]);
@@ -22,12 +42,16 @@ function syncTintColor(targetRef, sourceRef) {
22
42
  function useIconColor(deps, options) {
23
43
  const ref = useMainThreadRef(null);
24
44
  const sourceRef = options?.sourceRef;
45
+ const frameRef = useMainThreadRef(0);
25
46
  function syncOnUiAppear() {
26
47
  "main thread";
27
- syncTintColor(ref, sourceRef);
48
+ syncTintColorOnce(ref, sourceRef);
28
49
  }
29
50
  useEffect(() => {
30
- runOnMainThread(syncTintColor)(ref, sourceRef);
51
+ runOnMainThread(scheduleTintColorSync)(ref, sourceRef, frameRef);
52
+ return () => {
53
+ runOnMainThread(cancelTintColorSync)(frameRef);
54
+ };
31
55
  }, deps);
32
56
  return {
33
57
  ref,
@@ -1 +1 @@
1
- {"version":3,"file":"usePressTap.d.ts","sourceRoot":"","sources":["../../src/hooks/usePressTap.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAE3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,KAAK,YAAY,GAAG,YAAY,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;AAEzD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,eAAe,CAAC,EAAE,cAAc,CAAC,qBAAqB,CAAC,CAAC;CACzD;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,YAAY,CAAC;IACtB,cAAc,EAAE,YAAY,CAAC;IAC7B,YAAY,EAAE,YAAY,CAAC;IAC3B,eAAe,EAAE,YAAY,CAAC;IAC9B,qBAAqB,CAAC,EAAE,cAAc,CAAC,qBAAqB,CAAC,CAAC;CAC/D;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,OAAO,GAAE,kBAAuB,GAAG,iBAAiB,CA0B/E"}
1
+ {"version":3,"file":"usePressTap.d.ts","sourceRoot":"","sources":["../../src/hooks/usePressTap.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAE3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,KAAK,YAAY,GAAG,YAAY,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;AAEzD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,eAAe,CAAC,EAAE,cAAc,CAAC,qBAAqB,CAAC,CAAC;CACzD;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,YAAY,CAAC;IACtB,cAAc,EAAE,YAAY,CAAC;IAC7B,YAAY,EAAE,YAAY,CAAC;IAC3B,eAAe,EAAE,YAAY,CAAC;IAC9B,qBAAqB,CAAC,EAAE,cAAc,CAAC,qBAAqB,CAAC,CAAC;CAC/D;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,OAAO,GAAE,kBAAuB,GAAG,iBAAiB,CA2B/E"}
@@ -23,6 +23,7 @@ function usePressTap(options = {}) {
23
23
  pressed,
24
24
  bindtap: useMemoizedFn((...args) => {
25
25
  if (disabled) return;
26
+ setPressed(false);
26
27
  onTap?.(...args);
27
28
  }),
28
29
  bindtouchstart: press,