musae 1.0.27-beta.2 → 1.0.27-beta.21

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 (77) hide show
  1. package/dist/components/calendar/calendar.cjs +2 -2
  2. package/dist/components/calendar/calendar.mjs +2 -2
  3. package/dist/components/calendar/hooks.cjs +17 -17
  4. package/dist/components/calendar/hooks.d.ts +2 -2
  5. package/dist/components/calendar/hooks.mjs +17 -17
  6. package/dist/components/checkbox/checkbox.cjs +5 -26
  7. package/dist/components/checkbox/checkbox.mjs +3 -24
  8. package/dist/components/icon/icons/action/calendar-today.cjs +22 -0
  9. package/dist/components/icon/icons/action/calendar-today.d.ts +3 -0
  10. package/dist/components/icon/icons/action/calendar-today.mjs +18 -0
  11. package/dist/components/icon/icons/action/index.cjs +2 -0
  12. package/dist/components/icon/icons/action/index.d.ts +2 -1
  13. package/dist/components/icon/icons/action/index.mjs +1 -0
  14. package/dist/components/icon/icons/communication/index.d.ts +2 -0
  15. package/dist/components/icon/icons/communication/location-on.cjs +25 -0
  16. package/dist/components/icon/icons/communication/location-on.d.ts +3 -0
  17. package/dist/components/icon/icons/communication/location-on.mjs +21 -0
  18. package/dist/components/icon/icons/content/add.cjs +22 -0
  19. package/dist/components/icon/icons/content/add.d.ts +3 -0
  20. package/dist/components/icon/icons/content/add.mjs +18 -0
  21. package/dist/components/icon/icons/content/clear.cjs +2 -2
  22. package/dist/components/icon/icons/content/clear.d.ts +2 -2
  23. package/dist/components/icon/icons/content/clear.mjs +2 -2
  24. package/dist/components/icon/icons/content/index.cjs +4 -0
  25. package/dist/components/icon/icons/content/index.d.ts +3 -1
  26. package/dist/components/icon/icons/content/index.mjs +2 -0
  27. package/dist/components/icon/icons/content/remove.cjs +22 -0
  28. package/dist/components/icon/icons/content/remove.d.ts +3 -0
  29. package/dist/components/icon/icons/content/remove.mjs +18 -0
  30. package/dist/components/icon/icons/index.cjs +10 -0
  31. package/dist/components/icon/icons/index.d.ts +2 -0
  32. package/dist/components/icon/icons/index.mjs +5 -0
  33. package/dist/components/icon/icons/social/index.d.ts +2 -0
  34. package/dist/components/icon/icons/social/share.cjs +22 -0
  35. package/dist/components/icon/icons/social/share.d.ts +3 -0
  36. package/dist/components/icon/icons/social/share.mjs +18 -0
  37. package/dist/components/progress/linear.cjs +2 -2
  38. package/dist/components/progress/linear.mjs +2 -2
  39. package/dist/components/rich-text-editor/plugins/controlled-state/index.cjs +12 -26
  40. package/dist/components/rich-text-editor/plugins/controlled-state/index.mjs +13 -27
  41. package/dist/components/rich-text-editor/rich-text-editor.cjs +3 -11
  42. package/dist/components/rich-text-editor/rich-text-editor.mjs +3 -11
  43. package/dist/components/tabs/context.cjs +1 -4
  44. package/dist/components/tabs/context.d.ts +2 -2
  45. package/dist/components/tabs/context.mjs +1 -4
  46. package/dist/components/tabs/hooks/use-navigation.cjs +87 -0
  47. package/dist/components/tabs/hooks/use-navigation.d.ts +12 -0
  48. package/dist/components/tabs/hooks/use-navigation.mjs +85 -0
  49. package/dist/components/tabs/hooks/use-tabs-context.cjs +18 -0
  50. package/dist/components/tabs/hooks/use-tabs-context.d.ts +7 -0
  51. package/dist/components/tabs/hooks/use-tabs-context.mjs +16 -0
  52. package/dist/components/tabs/hooks/use-tabs.cjs +46 -0
  53. package/dist/components/tabs/hooks/use-tabs.d.ts +17 -0
  54. package/dist/components/tabs/hooks/use-tabs.mjs +44 -0
  55. package/dist/components/tabs/navigation.cjs +48 -18
  56. package/dist/components/tabs/navigation.mjs +47 -17
  57. package/dist/components/tabs/panels.cjs +56 -39
  58. package/dist/components/tabs/panels.mjs +56 -39
  59. package/dist/components/tabs/tab.cjs +6 -4
  60. package/dist/components/tabs/tab.mjs +5 -3
  61. package/dist/components/tabs/tabs.cjs +11 -6
  62. package/dist/components/tabs/tabs.d.ts +1 -1
  63. package/dist/components/tabs/tabs.mjs +10 -5
  64. package/dist/components/tag/tag.cjs +51 -28
  65. package/dist/components/tag/tag.d.ts +1 -1
  66. package/dist/components/tag/tag.mjs +51 -28
  67. package/dist/components/theme/tokens.stylex.d.ts +2 -0
  68. package/dist/hooks/use-theme-color-vars.cjs +7 -9
  69. package/dist/hooks/use-theme-color-vars.d.ts +2 -1
  70. package/dist/hooks/use-theme-color-vars.mjs +6 -8
  71. package/dist/styles.css +37 -21
  72. package/dist/types/tabs.d.ts +18 -2
  73. package/dist/types/tag.d.ts +7 -0
  74. package/package.json +6 -6
  75. package/dist/components/tabs/hooks.cjs +0 -145
  76. package/dist/components/tabs/hooks.d.ts +0 -43
  77. package/dist/components/tabs/hooks.mjs +0 -140
package/dist/styles.css CHANGED
@@ -420,6 +420,10 @@
420
420
  padding-block: var(--musaex-mk8wyj);
421
421
  }
422
422
 
423
+ .musaex-13bwjiu {
424
+ padding-inline: calc(var(--padding-inline) - var(--musaex-6ewyph));
425
+ }
426
+
423
427
  .musaex-1v4gb6w {
424
428
  padding-inline: var(--musaex-14eq97i);
425
429
  }
@@ -464,6 +468,10 @@
464
468
  padding-inline: var(--musaex-mk8wyj);
465
469
  }
466
470
 
471
+ .musaex-1ioy7le {
472
+ padding-inline: var(--padding-inline);
473
+ }
474
+
467
475
  .musaex-mqliwb {
468
476
  text-decoration: line-through;
469
477
  }
@@ -472,6 +480,10 @@
472
480
  text-decoration: none;
473
481
  }
474
482
 
483
+ .musaex-bngzmg {
484
+ transition: transform .3s ease-in-out;
485
+ }
486
+
475
487
  .musaex-1yssd5k {
476
488
  transition: transform .3s;
477
489
  }
@@ -1450,12 +1462,12 @@
1450
1462
  transform: translateX(50%)translateY(50%);
1451
1463
  }
1452
1464
 
1453
- .musaex-14dcsj8 {
1454
- transform: translateX(var(--movement-x)) translateY(var(--movement-y));
1465
+ .musaex-12eyqs9 {
1466
+ transform: translateX(calc(var(--offset) * -1));
1455
1467
  }
1456
1468
 
1457
- .musaex-o9m17b {
1458
- transform: translateX(var(--offset));
1469
+ .musaex-14dcsj8 {
1470
+ transform: translateX(var(--movement-x)) translateY(var(--movement-y));
1459
1471
  }
1460
1472
 
1461
1473
  .musaex-1cb1t30 {
@@ -1599,10 +1611,6 @@
1599
1611
  z-index: var(--musaex-15xdox1);
1600
1612
  }
1601
1613
 
1602
- .musaex-1nnj97i {
1603
- z-index: var(--musaex-1cifd33);
1604
- }
1605
-
1606
1614
  .musaex-qgk00j {
1607
1615
  z-index: var(--musaex-1ktvdf5);
1608
1616
  }
@@ -1917,10 +1925,6 @@
1917
1925
  height: var(--musaex-9xrpwn);
1918
1926
  }
1919
1927
 
1920
- .musaex-1r6gm7t {
1921
- height: var(--musaex-eliz3k);
1922
- }
1923
-
1924
1928
  .musaex-1svyby3 {
1925
1929
  height: var(--musaex-hio464);
1926
1930
  }
@@ -2253,10 +2257,6 @@
2253
2257
  width: var(--check-size);
2254
2258
  }
2255
2259
 
2256
- .musaex-k64pxh {
2257
- width: var(--flex);
2258
- }
2259
-
2260
2260
  .musaex-1po6ib {
2261
2261
  width: var(--musaex-10wwlfh);
2262
2262
  }
@@ -2533,7 +2533,7 @@
2533
2533
  display: none;
2534
2534
  }
2535
2535
 
2536
- .musaex-1unh1gc:after, .musaex-typ5od:before {
2536
+ .musaex-1unh1gc:after {
2537
2537
  inset-inline-end: 0;
2538
2538
  }
2539
2539
 
@@ -2541,6 +2541,10 @@
2541
2541
  inset-inline-end: 50%;
2542
2542
  }
2543
2543
 
2544
+ .musaex-vgnsxj:before {
2545
+ inset-inline-end: calc(var(--musaex-joam4e) * -1);
2546
+ }
2547
+
2544
2548
  .musaex-1682cnc:before {
2545
2549
  inset-inline-start: 0;
2546
2550
  }
@@ -2553,6 +2557,10 @@
2553
2557
  inset-inline-start: calc((100% - var(--musaex-1xf102v)) / 2);
2554
2558
  }
2555
2559
 
2560
+ .musaex-1d34y9o:before {
2561
+ inset-inline-start: calc(var(--musaex-joam4e) * -1);
2562
+ }
2563
+
2556
2564
  .musaex-1stqopg:after, .musaex-bres09:before {
2557
2565
  inset-inline-start: var(--musaex-12cvltn);
2558
2566
  }
@@ -2616,10 +2624,6 @@
2616
2624
  .musaex-1jszi47::view-transition-old(root), .musaex-ltipp6::view-transition-new(root) {
2617
2625
  z-index: 9999;
2618
2626
  }
2619
-
2620
- .musaex-rt65ts:before {
2621
- z-index: var(--musaex-1ktvdf5);
2622
- }
2623
2627
  }
2624
2628
 
2625
2629
  @layer priority8 {
@@ -3125,6 +3129,18 @@
3125
3129
  --check-size: var(--musaex-qe7ci9);
3126
3130
  }
3127
3131
 
3132
+ .musaex-58z396 {
3133
+ --padding-inline: var(--musaex-14eq97i);
3134
+ }
3135
+
3136
+ .musaex-1ur110t {
3137
+ --padding-inline: var(--musaex-1vpnstl);
3138
+ }
3139
+
3140
+ .musaex-1rb5leg {
3141
+ --padding-inline: var(--musaex-jo49ah);
3142
+ }
3143
+
3128
3144
  .musaex-1me236a {
3129
3145
  --size: var(--musaex-5c864h);
3130
3146
  }
@@ -1,5 +1,6 @@
1
1
  import type { Key, ReactNode } from "react";
2
2
  import type { ComponentProps } from "./element";
3
+ export type TabsSize = "small" | "medium" | "large";
3
4
  export interface TabsProps extends ComponentProps {
4
5
  /**
5
6
  * @description
@@ -31,6 +32,17 @@ export interface TabsProps extends ComponentProps {
31
32
  * @default false
32
33
  */
33
34
  destroyable?: boolean;
35
+ /**
36
+ * @description
37
+ * size of tabs
38
+ * @default "medium"
39
+ */
40
+ size?: TabsSize;
41
+ /**
42
+ * @zh 修改`activeKey`时触发的回调函数
43
+ * @en Callback function triggered when `activeKey` changes
44
+ */
45
+ onChange?: (key: Key) => void;
34
46
  }
35
47
  export interface TabItemProps {
36
48
  /**
@@ -44,7 +56,7 @@ export interface TabItemProps {
44
56
  * label
45
57
  * @requires
46
58
  */
47
- label: string;
59
+ label: ReactNode;
48
60
  /**
49
61
  * @description
50
62
  * on tab item click
@@ -64,7 +76,7 @@ export type TabItem = {
64
76
  * label
65
77
  * @requires
66
78
  */
67
- label: string;
79
+ label: ReactNode;
68
80
  /**
69
81
  * @description
70
82
  * children
@@ -83,6 +95,10 @@ export interface ContextValue {
83
95
  * items
84
96
  */
85
97
  items: TabItem[];
98
+ /**
99
+ * size of tabs
100
+ */
101
+ size: TabsSize;
86
102
  }
87
103
  /**
88
104
  * @description
@@ -1,11 +1,18 @@
1
1
  import type { MouseEvent, ReactNode } from "react";
2
2
  import type { ComponentProps } from "./element";
3
3
  type Size = "small" | "medium" | "large";
4
+ type Variant = "filled" | "outlined";
4
5
  /**
5
6
  * @description
6
7
  * tag props
7
8
  */
8
9
  export type TagProps = ComponentProps & {
10
+ /**
11
+ * @description
12
+ * variant
13
+ * @default "filled"
14
+ */
15
+ variant?: Variant;
9
16
  /**
10
17
  * @description
11
18
  * children
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "musae",
3
- "version": "1.0.27-beta.2",
3
+ "version": "1.0.27-beta.21",
4
4
  "description": "musae-ui",
5
5
  "author": "tutu@fantufantu.com",
6
6
  "license": "MIT",
@@ -82,9 +82,9 @@
82
82
  "@rollup/plugin-commonjs": "^29.0.0",
83
83
  "@rollup/plugin-node-resolve": "^16.0.3",
84
84
  "@rollup/plugin-typescript": "^12.3.0",
85
- "@storybook/addon-docs": "^10.2.17",
86
- "@storybook/addon-onboarding": "^10.2.17",
87
- "@storybook/react-vite": "^10.2.17",
85
+ "@storybook/addon-docs": "^10.3.3",
86
+ "@storybook/addon-onboarding": "^10.3.3",
87
+ "@storybook/react-vite": "^10.3.3",
88
88
  "@stylexjs/babel-plugin": "^0.17.5",
89
89
  "@stylexjs/rollup-plugin": "^0.17.5",
90
90
  "@stylexjs/stylex": "^0.17.5",
@@ -99,13 +99,13 @@
99
99
  "eslint": "^10.0.0",
100
100
  "eslint-plugin-react": "^7.37.5",
101
101
  "eslint-plugin-react-hooks": "^7.0.1",
102
- "eslint-plugin-storybook": "^10.2.17",
102
+ "eslint-plugin-storybook": "^10.3.3",
103
103
  "jest": "^30.2.0",
104
104
  "jest-environment-jsdom": "^30.2.0",
105
105
  "react": "^19.2.4",
106
106
  "react-dom": "^19.2.4",
107
107
  "rollup": "^4.57.1",
108
- "storybook": "^10.2.17",
108
+ "storybook": "^10.3.3",
109
109
  "typescript": "^5.9.3",
110
110
  "typescript-eslint": "^8.55.0",
111
111
  "zx": "^8.8.5"
@@ -1,145 +0,0 @@
1
- 'use strict';
2
-
3
- var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
4
- var relax = require('@aiszlab/relax');
5
- var React = require('react');
6
- var context = require('./context.cjs');
7
-
8
- /**
9
- * @description
10
- * use tab context
11
- */
12
- var useTabsContext = function useTabsContext() {
13
- var _useContext;
14
- return (_useContext = React.useContext(context.Context)) !== null && _useContext !== void 0 ? _useContext : {
15
- items: [],
16
- activeKey: void 0
17
- };
18
- };
19
- /**
20
- * @description
21
- * tabs
22
- */
23
- var useTabs = function useTabs(_ref) {
24
- var _items$at;
25
- var _activeKey = _ref.activeKey,
26
- items = _ref.items,
27
- defaultActiveKey = _ref.defaultActiveKey;
28
- var _useControlledState = relax.useControlledState(_activeKey, {
29
- defaultState: defaultActiveKey !== null && defaultActiveKey !== void 0 ? defaultActiveKey : (_items$at = items.at(0)) === null || _items$at === void 0 ? void 0 : _items$at.key
30
- }),
31
- _useControlledState2 = _slicedToArray(_useControlledState, 2),
32
- activeKey = _useControlledState2[0],
33
- setActiveKey = _useControlledState2[1];
34
- var _useState = React.useState(function () {
35
- return new Set(relax.isUndefined(activeKey) ? [] : [activeKey]);
36
- }),
37
- _useState2 = _slicedToArray(_useState, 2),
38
- activatedKeys = _useState2[0],
39
- setActivatedKeys = _useState2[1];
40
- var changeActiveKey = relax.useEvent(function (key) {
41
- setActiveKey(key);
42
- setActivatedKeys(function (prev) {
43
- return new Set(prev).add(key);
44
- });
45
- });
46
- return {
47
- activeKey: activeKey,
48
- activatedKeys: activatedKeys,
49
- changeActiveKey: changeActiveKey
50
- };
51
- };
52
- /**
53
- * @description
54
- * count dom ele size
55
- */
56
- var useNavigation = function useNavigation() {
57
- var navigatorRef = React.useRef(null);
58
- var tabsRef = React.useRef(null);
59
- var _useState3 = React.useState(0),
60
- _useState4 = _slicedToArray(_useState3, 2),
61
- offset = _useState4[0],
62
- setOffset = _useState4[1];
63
- // navigator size
64
- var _useState5 = React.useState(0),
65
- _useState6 = _slicedToArray(_useState5, 2),
66
- navigatorSize = _useState6[0],
67
- setNavigatorSize = _useState6[1];
68
- // tabs size
69
- var _useState7 = React.useState(0),
70
- _useState8 = _slicedToArray(_useState7, 2),
71
- tabsSize = _useState8[0],
72
- setTabsSize = _useState8[1];
73
- var _useMemo = React.useMemo(function () {
74
- return {
75
- maxOffset: Math.max(0, tabsSize - navigatorSize),
76
- minOffset: 0
77
- };
78
- }, [navigatorSize, tabsSize]),
79
- maxOffset = _useMemo.maxOffset,
80
- minOffset = _useMemo.minOffset;
81
- // handle scroll
82
- var scroll = relax.useEvent(function (delta) {
83
- setOffset(function (prev) {
84
- return relax.clamp(prev + delta, minOffset, maxOffset);
85
- });
86
- });
87
- var resize = relax.useEvent(function () {
88
- var _navigatorRef$current, _navigatorRef$current2, _tabsRef$current$getB, _tabsRef$current;
89
- var _navigatorSize = (_navigatorRef$current = (_navigatorRef$current2 = navigatorRef.current) === null || _navigatorRef$current2 === void 0 ? void 0 : _navigatorRef$current2.getBoundingClientRect().width) !== null && _navigatorRef$current !== void 0 ? _navigatorRef$current : 0;
90
- var _tabsSize = (_tabsRef$current$getB = (_tabsRef$current = tabsRef.current) === null || _tabsRef$current === void 0 ? void 0 : _tabsRef$current.getBoundingClientRect().width) !== null && _tabsRef$current$getB !== void 0 ? _tabsRef$current$getB : 0;
91
- setNavigatorSize(_navigatorSize);
92
- setTabsSize(_tabsSize);
93
- scroll(0);
94
- });
95
- var _useMemo2 = React.useMemo(function () {
96
- return {
97
- isLeadingOverflow: offset > minOffset,
98
- isTrailingOverflow: offset < maxOffset
99
- };
100
- }, [minOffset, maxOffset, offset]),
101
- isLeadingOverflow = _useMemo2.isLeadingOverflow,
102
- isTrailingOverflow = _useMemo2.isTrailingOverflow;
103
- // if window resize
104
- // re-calculate offsets range
105
- relax.useResize(resize);
106
- // calculate size once at mounting step
107
- relax.useMount(function () {
108
- resize();
109
- });
110
- return {
111
- navigatorRef: navigatorRef,
112
- tabsRef: tabsRef,
113
- scroll: scroll,
114
- offset: offset,
115
- isLeadingOverflow: isLeadingOverflow,
116
- isTrailingOverflow: isTrailingOverflow
117
- };
118
- };
119
- /**
120
- * @description
121
- * use navigator scroll
122
- */
123
- var useNavigatorScroll = function useNavigatorScroll(_ref2) {
124
- var navigatorRef = _ref2.navigatorRef,
125
- scroll = _ref2.scroll;
126
- // mouse wheel
127
- var onWheel = relax.useEvent(function (event) {
128
- event.preventDefault();
129
- var deltaY = event.deltaY;
130
- scroll(deltaY);
131
- });
132
- React.useEffect(function () {
133
- var navigator = navigatorRef.current;
134
- navigator === null || navigator === void 0 || navigator.addEventListener("wheel", onWheel);
135
- return function () {
136
- navigator === null || navigator === void 0 || navigator.removeEventListener("wheel", onWheel);
137
- };
138
- // eslint-disable-next-line react-hooks/exhaustive-deps
139
- }, []);
140
- };
141
-
142
- exports.useNavigation = useNavigation;
143
- exports.useNavigatorScroll = useNavigatorScroll;
144
- exports.useTabs = useTabs;
145
- exports.useTabsContext = useTabsContext;
@@ -1,43 +0,0 @@
1
- import { type Key, type RefObject } from "react";
2
- import type { TabItem } from "../../types/tabs";
3
- import type { Nullable, Partialable } from "@aiszlab/relax/types";
4
- /**
5
- * @description
6
- * use tab context
7
- */
8
- export declare const useTabsContext: () => import("../../types/tabs").ContextValue & {
9
- classNames: typeof import("./context").CLASS_NAMES;
10
- };
11
- /**
12
- * @description
13
- * tabs
14
- */
15
- export declare const useTabs: ({ activeKey: _activeKey, items, defaultActiveKey, }: {
16
- activeKey?: Key;
17
- items: TabItem[];
18
- defaultActiveKey?: Key;
19
- }) => {
20
- activeKey: Partialable<Key>;
21
- activatedKeys: Set<Key>;
22
- changeActiveKey: (key: Key) => void;
23
- };
24
- /**
25
- * @description
26
- * count dom ele size
27
- */
28
- export declare const useNavigation: () => {
29
- navigatorRef: RefObject<HTMLDivElement | null>;
30
- tabsRef: RefObject<HTMLDivElement | null>;
31
- scroll: (delta: number) => void;
32
- offset: number;
33
- isLeadingOverflow: boolean;
34
- isTrailingOverflow: boolean;
35
- };
36
- /**
37
- * @description
38
- * use navigator scroll
39
- */
40
- export declare const useNavigatorScroll: ({ navigatorRef, scroll, }: {
41
- navigatorRef: RefObject<Nullable<HTMLDivElement>>;
42
- scroll: (delta: number) => void;
43
- }) => void;
@@ -1,140 +0,0 @@
1
- import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
2
- import { useControlledState, isUndefined, useEvent, clamp, useResize, useMount } from '@aiszlab/relax';
3
- import { useState, useContext, useRef, useMemo, useEffect } from 'react';
4
- import { Context } from './context.mjs';
5
-
6
- /**
7
- * @description
8
- * use tab context
9
- */
10
- var useTabsContext = function useTabsContext() {
11
- var _useContext;
12
- return (_useContext = useContext(Context)) !== null && _useContext !== void 0 ? _useContext : {
13
- items: [],
14
- activeKey: void 0
15
- };
16
- };
17
- /**
18
- * @description
19
- * tabs
20
- */
21
- var useTabs = function useTabs(_ref) {
22
- var _items$at;
23
- var _activeKey = _ref.activeKey,
24
- items = _ref.items,
25
- defaultActiveKey = _ref.defaultActiveKey;
26
- var _useControlledState = useControlledState(_activeKey, {
27
- defaultState: defaultActiveKey !== null && defaultActiveKey !== void 0 ? defaultActiveKey : (_items$at = items.at(0)) === null || _items$at === void 0 ? void 0 : _items$at.key
28
- }),
29
- _useControlledState2 = _slicedToArray(_useControlledState, 2),
30
- activeKey = _useControlledState2[0],
31
- setActiveKey = _useControlledState2[1];
32
- var _useState = useState(function () {
33
- return new Set(isUndefined(activeKey) ? [] : [activeKey]);
34
- }),
35
- _useState2 = _slicedToArray(_useState, 2),
36
- activatedKeys = _useState2[0],
37
- setActivatedKeys = _useState2[1];
38
- var changeActiveKey = useEvent(function (key) {
39
- setActiveKey(key);
40
- setActivatedKeys(function (prev) {
41
- return new Set(prev).add(key);
42
- });
43
- });
44
- return {
45
- activeKey: activeKey,
46
- activatedKeys: activatedKeys,
47
- changeActiveKey: changeActiveKey
48
- };
49
- };
50
- /**
51
- * @description
52
- * count dom ele size
53
- */
54
- var useNavigation = function useNavigation() {
55
- var navigatorRef = useRef(null);
56
- var tabsRef = useRef(null);
57
- var _useState3 = useState(0),
58
- _useState4 = _slicedToArray(_useState3, 2),
59
- offset = _useState4[0],
60
- setOffset = _useState4[1];
61
- // navigator size
62
- var _useState5 = useState(0),
63
- _useState6 = _slicedToArray(_useState5, 2),
64
- navigatorSize = _useState6[0],
65
- setNavigatorSize = _useState6[1];
66
- // tabs size
67
- var _useState7 = useState(0),
68
- _useState8 = _slicedToArray(_useState7, 2),
69
- tabsSize = _useState8[0],
70
- setTabsSize = _useState8[1];
71
- var _useMemo = useMemo(function () {
72
- return {
73
- maxOffset: Math.max(0, tabsSize - navigatorSize),
74
- minOffset: 0
75
- };
76
- }, [navigatorSize, tabsSize]),
77
- maxOffset = _useMemo.maxOffset,
78
- minOffset = _useMemo.minOffset;
79
- // handle scroll
80
- var scroll = useEvent(function (delta) {
81
- setOffset(function (prev) {
82
- return clamp(prev + delta, minOffset, maxOffset);
83
- });
84
- });
85
- var resize = useEvent(function () {
86
- var _navigatorRef$current, _navigatorRef$current2, _tabsRef$current$getB, _tabsRef$current;
87
- var _navigatorSize = (_navigatorRef$current = (_navigatorRef$current2 = navigatorRef.current) === null || _navigatorRef$current2 === void 0 ? void 0 : _navigatorRef$current2.getBoundingClientRect().width) !== null && _navigatorRef$current !== void 0 ? _navigatorRef$current : 0;
88
- var _tabsSize = (_tabsRef$current$getB = (_tabsRef$current = tabsRef.current) === null || _tabsRef$current === void 0 ? void 0 : _tabsRef$current.getBoundingClientRect().width) !== null && _tabsRef$current$getB !== void 0 ? _tabsRef$current$getB : 0;
89
- setNavigatorSize(_navigatorSize);
90
- setTabsSize(_tabsSize);
91
- scroll(0);
92
- });
93
- var _useMemo2 = useMemo(function () {
94
- return {
95
- isLeadingOverflow: offset > minOffset,
96
- isTrailingOverflow: offset < maxOffset
97
- };
98
- }, [minOffset, maxOffset, offset]),
99
- isLeadingOverflow = _useMemo2.isLeadingOverflow,
100
- isTrailingOverflow = _useMemo2.isTrailingOverflow;
101
- // if window resize
102
- // re-calculate offsets range
103
- useResize(resize);
104
- // calculate size once at mounting step
105
- useMount(function () {
106
- resize();
107
- });
108
- return {
109
- navigatorRef: navigatorRef,
110
- tabsRef: tabsRef,
111
- scroll: scroll,
112
- offset: offset,
113
- isLeadingOverflow: isLeadingOverflow,
114
- isTrailingOverflow: isTrailingOverflow
115
- };
116
- };
117
- /**
118
- * @description
119
- * use navigator scroll
120
- */
121
- var useNavigatorScroll = function useNavigatorScroll(_ref2) {
122
- var navigatorRef = _ref2.navigatorRef,
123
- scroll = _ref2.scroll;
124
- // mouse wheel
125
- var onWheel = useEvent(function (event) {
126
- event.preventDefault();
127
- var deltaY = event.deltaY;
128
- scroll(deltaY);
129
- });
130
- useEffect(function () {
131
- var navigator = navigatorRef.current;
132
- navigator === null || navigator === void 0 || navigator.addEventListener("wheel", onWheel);
133
- return function () {
134
- navigator === null || navigator === void 0 || navigator.removeEventListener("wheel", onWheel);
135
- };
136
- // eslint-disable-next-line react-hooks/exhaustive-deps
137
- }, []);
138
- };
139
-
140
- export { useNavigation, useNavigatorScroll, useTabs, useTabsContext };