@mezzanine-ui/react 1.0.0-alpha.0 → 1.0.0-beta.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 (180) hide show
  1. package/Breadcrumb/Breadcrumb.js +40 -12
  2. package/Breadcrumb/typings.d.ts +8 -3
  3. package/Drawer/Drawer.d.ts +47 -6
  4. package/Drawer/Drawer.js +36 -11
  5. package/Dropdown/Dropdown.d.ts +116 -15
  6. package/Dropdown/Dropdown.js +235 -32
  7. package/Dropdown/DropdownAction.d.ts +50 -0
  8. package/Dropdown/DropdownAction.js +26 -0
  9. package/Dropdown/DropdownItem.d.ts +60 -0
  10. package/Dropdown/DropdownItem.js +318 -0
  11. package/Dropdown/DropdownItemCard.d.ts +96 -0
  12. package/Dropdown/DropdownItemCard.js +115 -0
  13. package/Dropdown/DropdownStatus.d.ts +22 -0
  14. package/Dropdown/dropdownKeydownHandler.d.ts +15 -0
  15. package/Dropdown/highlightText.d.ts +9 -0
  16. package/Dropdown/highlightText.js +32 -0
  17. package/Dropdown/index.d.ts +1 -1
  18. package/Empty/Empty.js +26 -3
  19. package/Empty/typings.d.ts +16 -7
  20. package/Navigation/Navigation.d.ts +11 -17
  21. package/Navigation/Navigation.js +58 -41
  22. package/Navigation/NavigationFooter.d.ts +10 -0
  23. package/Navigation/NavigationFooter.js +26 -0
  24. package/Navigation/NavigationHeader.d.ts +8 -0
  25. package/Navigation/NavigationHeader.js +13 -0
  26. package/Navigation/NavigationIconButton.d.ts +15 -0
  27. package/Navigation/NavigationIconButton.js +12 -0
  28. package/Navigation/NavigationOption.d.ts +35 -0
  29. package/Navigation/NavigationOption.js +60 -0
  30. package/Navigation/NavigationOptionCategory.d.ts +6 -0
  31. package/Navigation/NavigationOptionCategory.js +12 -0
  32. package/Navigation/NavigationUserMenu.d.ts +8 -0
  33. package/Navigation/NavigationUserMenu.js +18 -0
  34. package/Navigation/context.d.ts +13 -0
  35. package/Navigation/context.js +7 -0
  36. package/Navigation/index.d.ts +12 -6
  37. package/Navigation/index.js +6 -3
  38. package/Navigation/useCurrentPathname.d.ts +1 -0
  39. package/Navigation/useCurrentPathname.js +14 -0
  40. package/PageHeader/PageHeader.d.ts +5 -1
  41. package/PageHeader/PageHeader.js +8 -3
  42. package/PageToolbar/PageToolbar.d.ts +73 -26
  43. package/PageToolbar/PageToolbar.js +10 -101
  44. package/PageToolbar/utils.d.ts +23 -0
  45. package/PageToolbar/utils.js +165 -0
  46. package/Pagination/PaginationItem.js +1 -3
  47. package/Pagination/usePagination.js +0 -18
  48. package/Radio/Radio.d.ts +36 -3
  49. package/Radio/Radio.js +21 -11
  50. package/Radio/RadioGroup.d.ts +36 -7
  51. package/Radio/RadioGroup.js +5 -4
  52. package/Radio/RadioGroupContext.d.ts +2 -1
  53. package/Radio/index.d.ts +3 -3
  54. package/Slider/useSlider.js +1 -1
  55. package/Tab/Tab.d.ts +32 -0
  56. package/Tab/Tab.js +57 -0
  57. package/Tab/TabItem.d.ts +27 -0
  58. package/Tab/TabItem.js +18 -0
  59. package/Tab/index.d.ts +4 -0
  60. package/Tab/index.js +2 -0
  61. package/Table/Table.d.ts +75 -94
  62. package/Table/Table.js +216 -161
  63. package/Table/TableContext.d.ts +114 -51
  64. package/Table/TableContext.js +21 -3
  65. package/Table/components/TableBody.d.ts +5 -0
  66. package/Table/components/TableBody.js +102 -0
  67. package/Table/components/TableCell.d.ts +17 -0
  68. package/Table/components/TableCell.js +74 -0
  69. package/Table/components/TableColGroup.d.ts +4 -0
  70. package/Table/components/TableColGroup.js +206 -0
  71. package/Table/components/TableDragHandleCell.d.ts +9 -0
  72. package/Table/components/TableDragHandleCell.js +37 -0
  73. package/Table/components/TableExpandCell.d.ts +11 -0
  74. package/Table/components/TableExpandCell.js +44 -0
  75. package/Table/components/TableExpandedRow.d.ts +9 -0
  76. package/Table/components/TableExpandedRow.js +46 -0
  77. package/Table/components/TableHeader.d.ts +4 -0
  78. package/Table/components/TableHeader.js +125 -0
  79. package/Table/components/TablePagination.d.ts +3 -0
  80. package/Table/components/TablePagination.js +11 -0
  81. package/Table/components/TableResizeHandle.d.ts +13 -0
  82. package/Table/components/TableResizeHandle.js +115 -0
  83. package/Table/components/TableRow.d.ts +12 -0
  84. package/Table/components/TableRow.js +126 -0
  85. package/Table/components/TableSelectionCell.d.ts +13 -0
  86. package/Table/components/TableSelectionCell.js +35 -0
  87. package/Table/components/index.d.ts +10 -0
  88. package/Table/components/index.js +10 -0
  89. package/Table/hooks/index.d.ts +9 -0
  90. package/Table/hooks/index.js +8 -0
  91. package/Table/hooks/typings.d.ts +14 -0
  92. package/Table/hooks/useTableColumns.d.ts +8 -0
  93. package/Table/hooks/useTableColumns.js +91 -0
  94. package/Table/hooks/useTableDataSource.d.ts +57 -0
  95. package/Table/hooks/useTableDataSource.js +183 -0
  96. package/Table/hooks/useTableExpansion.d.ts +7 -0
  97. package/Table/hooks/useTableExpansion.js +52 -0
  98. package/Table/hooks/useTableFixedOffsets.d.ts +29 -0
  99. package/Table/hooks/useTableFixedOffsets.js +241 -0
  100. package/Table/hooks/useTableScroll.d.ts +12 -0
  101. package/Table/hooks/useTableScroll.js +58 -0
  102. package/Table/hooks/useTableSelection.d.ts +7 -0
  103. package/Table/hooks/useTableSelection.js +94 -0
  104. package/Table/hooks/useTableSorting.d.ts +6 -0
  105. package/Table/hooks/useTableSorting.js +32 -0
  106. package/Table/hooks/useTableVirtualization.d.ts +22 -0
  107. package/Table/hooks/useTableVirtualization.js +115 -0
  108. package/Table/index.d.ts +7 -10
  109. package/Table/index.js +22 -6
  110. package/Table/utils/index.d.ts +2 -0
  111. package/Table/utils/index.js +1 -0
  112. package/Table/utils/useTableRowSelection.d.ts +18 -0
  113. package/Table/utils/useTableRowSelection.js +63 -0
  114. package/_internal/InputCheck/InputCheck.d.ts +15 -1
  115. package/_internal/InputCheck/InputCheck.js +6 -2
  116. package/_internal/InputCheck/InputCheckGroup.d.ts +11 -1
  117. package/_internal/InputCheck/InputCheckGroup.js +4 -2
  118. package/_internal/SlideFadeOverlay/SlideFadeOverlay.d.ts +1 -1
  119. package/_internal/SlideFadeOverlay/SlideFadeOverlay.js +1 -1
  120. package/hooks/useElementHeight.d.ts +8 -0
  121. package/hooks/useElementHeight.js +41 -0
  122. package/index.d.ts +9 -7
  123. package/index.js +6 -11
  124. package/package.json +6 -4
  125. package/utils/flatten-children.d.ts +12 -0
  126. package/utils/flatten-children.js +37 -0
  127. package/utils/get-css-variable-value.d.ts +1 -0
  128. package/utils/get-css-variable-value.js +4 -1
  129. package/Navigation/NavigationContext.d.ts +0 -5
  130. package/Navigation/NavigationContext.js +0 -8
  131. package/Navigation/NavigationItem.d.ts +0 -31
  132. package/Navigation/NavigationItem.js +0 -23
  133. package/Navigation/NavigationSubMenu.d.ts +0 -22
  134. package/Navigation/NavigationSubMenu.js +0 -50
  135. package/Table/TableBody.d.ts +0 -10
  136. package/Table/TableBody.js +0 -31
  137. package/Table/TableBodyRow.d.ts +0 -11
  138. package/Table/TableBodyRow.js +0 -65
  139. package/Table/TableCell.d.ts +0 -19
  140. package/Table/TableCell.js +0 -24
  141. package/Table/TableExpandedTable.d.ts +0 -11
  142. package/Table/TableExpandedTable.js +0 -29
  143. package/Table/TableHeader.d.ts +0 -3
  144. package/Table/TableHeader.js +0 -36
  145. package/Table/draggable/useTableDraggable.d.ts +0 -14
  146. package/Table/draggable/useTableDraggable.js +0 -64
  147. package/Table/editable/TableEditRenderWrapper.d.ts +0 -7
  148. package/Table/editable/TableEditRenderWrapper.js +0 -16
  149. package/Table/expandable/TableExpandable.d.ts +0 -27
  150. package/Table/expandable/TableExpandable.js +0 -24
  151. package/Table/pagination/TablePagination.d.ts +0 -10
  152. package/Table/pagination/TablePagination.js +0 -26
  153. package/Table/pagination/useTablePagination.d.ts +0 -8
  154. package/Table/pagination/useTablePagination.js +0 -30
  155. package/Table/refresh/TableRefresh.d.ts +0 -10
  156. package/Table/refresh/TableRefresh.js +0 -22
  157. package/Table/rowSelection/TableRowSelection.d.ts +0 -18
  158. package/Table/rowSelection/TableRowSelection.js +0 -93
  159. package/Table/rowSelection/useTableRowSelection.d.ts +0 -6
  160. package/Table/rowSelection/useTableRowSelection.js +0 -53
  161. package/Table/sorting/TableSortingIcon.d.ts +0 -10
  162. package/Table/sorting/TableSortingIcon.js +0 -33
  163. package/Table/sorting/useTableSorting.d.ts +0 -11
  164. package/Table/sorting/useTableSorting.js +0 -121
  165. package/Table/useTableFetchMore.d.ts +0 -10
  166. package/Table/useTableFetchMore.js +0 -50
  167. package/Table/useTableLoading.d.ts +0 -5
  168. package/Table/useTableLoading.js +0 -19
  169. package/Table/useTableScroll.d.ts +0 -592
  170. package/Table/useTableScroll.js +0 -296
  171. package/Tabs/Tab.d.ts +0 -18
  172. package/Tabs/Tab.js +0 -16
  173. package/Tabs/TabPane.d.ts +0 -14
  174. package/Tabs/TabPane.js +0 -19
  175. package/Tabs/Tabs.d.ts +0 -39
  176. package/Tabs/Tabs.js +0 -52
  177. package/Tabs/index.d.ts +0 -6
  178. package/Tabs/index.js +0 -3
  179. package/Tabs/useTabsOverflow.d.ts +0 -8
  180. package/Tabs/useTabsOverflow.js +0 -62
@@ -1,296 +0,0 @@
1
- import { useRef, useState, useCallback, useEffect, useMemo } from 'react';
2
-
3
- const HEADER_DEFAULT_HEIGHT = 40; // px
4
- const SCROLL_BAR_MIN_START_AT = 4; // px
5
- const SCROLL_BAR_MAX_END_SPACING = 16; // px
6
- const FETCH_MORE_TRIGGER_AT_BOTTOM = 46; // px
7
- const SCROLL_BAR_DISPLAY_TIMES = 1500; // ms
8
- const defaultScrollBarTrackStyle = {
9
- position: 'absolute',
10
- right: 0,
11
- top: `${HEADER_DEFAULT_HEIGHT}px`,
12
- width: 12,
13
- height: 0,
14
- opacity: '0',
15
- transition: '0.1s opacity ease-in',
16
- backgroundColor: '#F2F2F2',
17
- };
18
- const defaultScrollBarStyle = {
19
- display: 'flex',
20
- justifyContent: 'center',
21
- alignItems: 'flex-start',
22
- position: 'absolute',
23
- right: 0,
24
- top: `${SCROLL_BAR_MIN_START_AT}px`,
25
- width: 10,
26
- height: 0,
27
- borderRadius: 10,
28
- transform: 'translate3d(0, 0, 0)',
29
- outline: 'none',
30
- opacity: '0',
31
- transition: '0.1s opacity ease-in',
32
- backgroundColor: 'transparent',
33
- };
34
- function useTableScroll(props) {
35
- const { onFetchMore, loading, scrollBarSize = 4 } = props;
36
- const scrollRef = useRef(null);
37
- const tableRef = useRef(null);
38
- const scrollBarTrackRef = useRef(null);
39
- const scrollBarRef = useRef(null);
40
- const scrollBarDisplayTimer = useRef(undefined);
41
- const [scrollBarHeight, setScrollBarHeight] = useState(0);
42
- const [pointerOffset, setPointerOffset] = useState(0);
43
- const [isHorizontalScrolling, toggleIsHorizontalScrolling] = useState(false);
44
- /** set scroll bar callback */
45
- const onSetScrollBarHeight = useCallback(() => {
46
- /** @NOTE Scroll bar 高度為可視區域的百分比 */
47
- if (!scrollRef.current)
48
- return;
49
- const { scrollHeight, clientHeight: tableHeight } = scrollRef.current;
50
- const bodyHeight = scrollHeight - HEADER_DEFAULT_HEIGHT;
51
- const viewAreaHeight = tableHeight - HEADER_DEFAULT_HEIGHT;
52
- const nextHeight = Math.max((viewAreaHeight - SCROLL_BAR_MAX_END_SPACING * 2) *
53
- (viewAreaHeight / bodyHeight), tableHeight / 10);
54
- setScrollBarHeight(nextHeight);
55
- }, []);
56
- /** display/hide scroll bar */
57
- const onHideScrollBar = useCallback(() => {
58
- if (!scrollBarRef.current)
59
- return;
60
- if (scrollBarDisplayTimer.current) {
61
- window.clearTimeout(scrollBarDisplayTimer.current);
62
- }
63
- scrollBarDisplayTimer.current = window.setTimeout(() => {
64
- if (scrollBarRef.current) {
65
- scrollBarRef.current.style.opacity = '0';
66
- scrollBarRef.current.style.pointerEvents = 'none';
67
- }
68
- if (scrollBarTrackRef.current) {
69
- scrollBarTrackRef.current.style.opacity = '0';
70
- scrollBarTrackRef.current.style.pointerEvents = 'none';
71
- }
72
- }, SCROLL_BAR_DISPLAY_TIMES);
73
- }, []);
74
- const onDisplayScrollBar = useCallback(() => {
75
- if (!scrollBarRef.current ||
76
- !scrollRef.current ||
77
- !scrollBarTrackRef.current)
78
- return;
79
- /** 觸控螢幕不需要 scroll bar */
80
- const isTouchEnabled = navigator.maxTouchPoints > 0;
81
- /** firefox 的滾軸只能同時顯示 or 取消,所以乾脆就用原生的(除非能單獨關掉直向的滾軸,只顯示橫向的才行) */
82
- const isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
83
- if (isTouchEnabled || isFirefox)
84
- return;
85
- scrollBarRef.current.style.opacity = '1';
86
- scrollBarRef.current.style.pointerEvents = 'auto';
87
- scrollBarTrackRef.current.style.opacity = '1';
88
- scrollBarTrackRef.current.style.pointerEvents = 'auto';
89
- if (scrollBarDisplayTimer.current) {
90
- window.clearTimeout(scrollBarDisplayTimer.current);
91
- }
92
- }, []);
93
- const resetPointerOffset = useCallback(() => setPointerOffset(0), []);
94
- /** scroll bar style reset when mouse leave */
95
- const onScrollBarLeave = useCallback(() => {
96
- if (scrollBarRef.current) {
97
- scrollBarRef.current.childNodes[0].style.width =
98
- `${scrollBarSize}px`;
99
- }
100
- resetPointerOffset();
101
- }, [resetPointerOffset, scrollBarSize]);
102
- /** when use mouse to drag scroll bar, get cursor position */
103
- const onScrollBarMouseDown = useCallback(({ clientY }) => {
104
- const { current: scrollBar } = scrollBarRef;
105
- if (!scrollBar)
106
- return;
107
- const { top: initScrollBarTop } = scrollBar.getBoundingClientRect();
108
- setPointerOffset(clientY - initScrollBarTop);
109
- }, []);
110
- const onScrollBarMouseUp = useCallback(() => resetPointerOffset(), [resetPointerOffset]);
111
- /** 偵測 table 高度是否發生變化,有的話就要重新計算 scroll bar 長度 */
112
- useEffect(() => {
113
- const { current: table } = tableRef;
114
- function resizing() {
115
- window.requestAnimationFrame(onSetScrollBarHeight);
116
- }
117
- if (table) {
118
- const observer = new ResizeObserver(resizing);
119
- observer.observe(table);
120
- return () => {
121
- observer.disconnect();
122
- };
123
- }
124
- return () => { };
125
- }, [onSetScrollBarHeight]);
126
- useEffect(() => {
127
- const { current: body } = scrollRef;
128
- const { current: scrollBar } = scrollBarRef;
129
- const { current: scrollBarTrack } = scrollBarTrackRef;
130
- if (!body || !scrollBar || !scrollBarTrack)
131
- return;
132
- /** 游標在滾軸上長按並移動 */
133
- function onMouseMove({ clientY }) {
134
- const { scrollHeight, clientHeight: tableHeight } = body;
135
- if (!pointerOffset)
136
- return;
137
- // keep scroll bar display when moving
138
- window.requestAnimationFrame(onDisplayScrollBar);
139
- const { top: tableTop } = body.getBoundingClientRect();
140
- /** Table 最大滾動距離 */
141
- const maxScrollDistance = scrollHeight - tableHeight;
142
- /** 游標在 scroll bar 上的位置 */
143
- const scrollBarCurrentPosition = clientY - (tableTop + HEADER_DEFAULT_HEIGHT) - pointerOffset;
144
- /** 可視區域高度 */
145
- const viewAreaHeight = tableHeight - HEADER_DEFAULT_HEIGHT;
146
- /** 最大滑動距離 */
147
- const maxScrollBarDistance = viewAreaHeight - scrollBarHeight - SCROLL_BAR_MAX_END_SPACING;
148
- /** 計算出來的距離 */
149
- const clampScrollBarTop = Math.min(Math.max(scrollBarCurrentPosition, 0), // min boundary
150
- maxScrollBarDistance);
151
- scrollBar.style.setProperty('transform', `translate3d(0, ${clampScrollBarTop}px, 0)`);
152
- body.scrollTop =
153
- (clampScrollBarTop * maxScrollDistance) / maxScrollBarDistance;
154
- }
155
- /** 在滾軸滑軌上點擊,直接滾動到指定位置上 */
156
- function onMouseClick({ clientY }) {
157
- if (!scrollBar)
158
- return;
159
- const { scrollHeight, clientHeight: tableHeight } = body;
160
- // keep scroll bar display when moving
161
- window.requestAnimationFrame(onDisplayScrollBar);
162
- const { top: tableTop } = body.getBoundingClientRect();
163
- /** Table 最大滾動距離 */
164
- const maxScrollDistance = scrollHeight - tableHeight;
165
- /** 游標在 Track 上的位置 */
166
- const scrollBarCurrentPosition = clientY - (tableTop + HEADER_DEFAULT_HEIGHT) - scrollBarHeight / 2;
167
- /** 可視區域高度 */
168
- const viewAreaHeight = tableHeight - HEADER_DEFAULT_HEIGHT;
169
- /** 最大滑動距離 */
170
- const maxScrollBarDistance = viewAreaHeight - scrollBarHeight - SCROLL_BAR_MAX_END_SPACING;
171
- /** 計算出來的距離 */
172
- const clampScrollBarTop = Math.min(Math.max(scrollBarCurrentPosition, 0), // min boundary
173
- maxScrollBarDistance);
174
- scrollBar.style.setProperty('transform', `translate3d(0, ${clampScrollBarTop}px, 0)`);
175
- body.scrollTop =
176
- (clampScrollBarTop * maxScrollDistance) / maxScrollBarDistance;
177
- }
178
- /** 游標移動到滾軸/滑軌上方時 */
179
- function onMouseOver() {
180
- scrollBar.style.setProperty('transition', '0s');
181
- onDisplayScrollBar();
182
- }
183
- /** 游標移開滾軸/滑軌上方時 */
184
- function onMouseLeave() {
185
- scrollBar.style.setProperty('transition', '0.1s');
186
- onHideScrollBar();
187
- }
188
- scrollBar.addEventListener('mousemove', onMouseMove, false);
189
- scrollBar.addEventListener('mouseover', onMouseOver, false);
190
- scrollBar.addEventListener('mouseleave', onMouseLeave, false);
191
- scrollBarTrack.addEventListener('mousemove', onMouseMove, false);
192
- scrollBarTrack.addEventListener('mouseover', onMouseOver, false);
193
- scrollBarTrack.addEventListener('mouseleave', onMouseLeave, false);
194
- scrollBarTrack.addEventListener('click', onMouseClick, false);
195
- return () => {
196
- scrollBar.removeEventListener('mousemove', onMouseMove, false);
197
- scrollBar.removeEventListener('mouseover', onMouseOver, false);
198
- scrollBar.removeEventListener('mouseleave', onMouseLeave, false);
199
- scrollBarTrack.removeEventListener('mousemove', onMouseMove, false);
200
- scrollBarTrack.removeEventListener('mouseover', onMouseOver, false);
201
- scrollBarTrack.removeEventListener('mouseleave', onMouseLeave, false);
202
- scrollBarTrack.removeEventListener('click', onMouseClick, false);
203
- };
204
- }, [scrollBarHeight, pointerOffset, onDisplayScrollBar, onHideScrollBar]);
205
- /** scroll bar fatter when mouse enter */
206
- const onScrollBarEnter = useCallback(() => {
207
- if (scrollBarRef.current) {
208
- scrollBarRef.current.childNodes[0].style.width =
209
- `${scrollBarSize + 6}px`;
210
- }
211
- }, [scrollBarSize]);
212
- /** scroll table directly */
213
- const setScrollBarTop = useCallback(() => {
214
- if (scrollRef.current) {
215
- const { clientHeight: tableHeight, scrollTop, scrollHeight, } = scrollRef.current;
216
- /** @NOTE don't apply scroll change when use pointer dragging */
217
- if (scrollBarRef.current && !pointerOffset) {
218
- const bodyHeight = scrollHeight - HEADER_DEFAULT_HEIGHT;
219
- const viewAreaHeight = tableHeight - HEADER_DEFAULT_HEIGHT;
220
- const distance = Math.max(viewAreaHeight * Math.max(scrollTop / bodyHeight, 0), 0);
221
- scrollBarRef.current.style.transform = `translate3d(0, ${distance}px, 0)`;
222
- }
223
- if (scrollBarTrackRef.current) {
224
- scrollBarTrackRef.current.style.height = `${tableHeight - HEADER_DEFAULT_HEIGHT}px`;
225
- }
226
- }
227
- }, [pointerOffset]);
228
- const onScroll = useCallback((scrollTarget) => {
229
- /** 使用者開始橫向滾動 */
230
- if (scrollTarget.target.scrollLeft) {
231
- toggleIsHorizontalScrolling(true);
232
- }
233
- else {
234
- toggleIsHorizontalScrolling(false);
235
- }
236
- if (loading)
237
- return;
238
- if (scrollRef.current) {
239
- const { clientHeight, scrollTop, scrollHeight } = scrollRef.current;
240
- /** 如果不需要滾動,則不需要觸發 */
241
- if (clientHeight >= scrollHeight)
242
- return;
243
- window.requestAnimationFrame(onDisplayScrollBar);
244
- /** @Note safari specific bug fix for scroll bouncing */
245
- const belowBottom = scrollTop > scrollHeight - clientHeight;
246
- if (belowBottom)
247
- return;
248
- window.requestAnimationFrame(setScrollBarTop);
249
- /** trigger fetchMore when scrolling */
250
- if (scrollHeight - (scrollTop + clientHeight) <
251
- FETCH_MORE_TRIGGER_AT_BOTTOM) {
252
- onFetchMore === null || onFetchMore === void 0 ? void 0 : onFetchMore();
253
- }
254
- }
255
- window.requestAnimationFrame(onHideScrollBar);
256
- }, [
257
- loading,
258
- setScrollBarTop,
259
- onDisplayScrollBar,
260
- onFetchMore,
261
- onHideScrollBar,
262
- ]);
263
- const scrollBarStyle = useMemo(() => ({
264
- ...defaultScrollBarStyle,
265
- height: `${scrollBarHeight}px`,
266
- }), [scrollBarHeight]);
267
- const scrollBarTrackStyle = useMemo(() => {
268
- var _a, _b;
269
- return ({
270
- ...defaultScrollBarTrackStyle,
271
- height: `${(_b = (_a = scrollRef.current) === null || _a === void 0 ? void 0 : _a.scrollHeight) !== null && _b !== void 0 ? _b : 0}px`,
272
- });
273
- },
274
- // eslint-disable-next-line react-hooks/exhaustive-deps
275
- [scrollBarHeight]);
276
- /** composing result */
277
- const tableScrollContainer = {
278
- ref: scrollRef,
279
- target: tableRef,
280
- onScroll,
281
- };
282
- const scrollElement = {
283
- ref: scrollBarRef,
284
- trackRef: scrollBarTrackRef,
285
- scrollBarSize,
286
- onMouseDown: onScrollBarMouseDown,
287
- onMouseUp: onScrollBarMouseUp,
288
- onMouseEnter: onScrollBarEnter,
289
- onMouseLeave: onScrollBarLeave,
290
- style: scrollBarStyle,
291
- trackStyle: scrollBarTrackStyle,
292
- };
293
- return [tableScrollContainer, scrollElement, isHorizontalScrolling];
294
- }
295
-
296
- export { useTableScroll as default };
package/Tabs/Tab.d.ts DELETED
@@ -1,18 +0,0 @@
1
- import { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
2
- export interface TabProps extends NativeElementPropsWithoutKeyAndRef<'button'> {
3
- /**
4
- * Whether the tab is active.
5
- * Controlled by tabs.
6
- */
7
- active?: boolean;
8
- /**
9
- * Whether the tab is disabled
10
- * @default false
11
- */
12
- disabled?: boolean;
13
- }
14
- /**
15
- * The react component for `mezzanine` tab.
16
- */
17
- declare const Tab: import("react").ForwardRefExoticComponent<TabProps & import("react").RefAttributes<HTMLButtonElement>>;
18
- export default Tab;
package/Tabs/Tab.js DELETED
@@ -1,16 +0,0 @@
1
- import { jsx } from 'react/jsx-runtime';
2
- import { forwardRef } from 'react';
3
- import { tabsClasses } from '@mezzanine-ui/core/tabs';
4
- import cx from 'clsx';
5
-
6
- /**
7
- * The react component for `mezzanine` tab.
8
- */
9
- const Tab = forwardRef(function Tab(props, ref) {
10
- const { active, children, className, disabled, ...rest } = props;
11
- return (jsx("button", { ...rest, ref: ref, type: "button", "aria-disabled": disabled, className: cx(tabsClasses.tab, {
12
- [tabsClasses.tabActive]: active,
13
- }, className), disabled: disabled, children: children }));
14
- });
15
-
16
- export { Tab as default };
package/Tabs/TabPane.d.ts DELETED
@@ -1,14 +0,0 @@
1
- import { ReactElement } from 'react';
2
- import { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
3
- import { TabProps } from './Tab';
4
- export interface TabPaneProps extends NativeElementPropsWithoutKeyAndRef<'div'> {
5
- /**
6
- * Only for tabs to control the tab pane.
7
- */
8
- tab: ReactElement<TabProps>;
9
- }
10
- /**
11
- * The react component for `mezzanine` tab pane.
12
- */
13
- declare const TabPane: import("react").ForwardRefExoticComponent<TabPaneProps & import("react").RefAttributes<HTMLDivElement>>;
14
- export default TabPane;
package/Tabs/TabPane.js DELETED
@@ -1,19 +0,0 @@
1
- import { jsx } from 'react/jsx-runtime';
2
- import { forwardRef } from 'react';
3
- import { tabsClasses } from '@mezzanine-ui/core/tabs';
4
- import cx from 'clsx';
5
-
6
- /**
7
- * The react component for `mezzanine` tab pane.
8
- */
9
- const TabPane = forwardRef(function TabPane(props, ref) {
10
- const { children, className,
11
- /**
12
- * Ignore it
13
- */
14
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
15
- tab, ...rest } = props;
16
- return (jsx("div", { ...rest, ref: ref, className: cx(tabsClasses.pane, className), children: children }));
17
- });
18
-
19
- export { TabPane as default };
package/Tabs/Tabs.d.ts DELETED
@@ -1,39 +0,0 @@
1
- import { Key, MouseEvent, ReactElement, ReactNode } from 'react';
2
- import { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
3
- import { TabPaneProps } from './TabPane';
4
- export type TabsChild = ReactElement<TabPaneProps>;
5
- export interface TabsProps extends Omit<NativeElementPropsWithoutKeyAndRef<'div'>, 'onChange' | 'children'> {
6
- /**
7
- * Current TabPane's index
8
- */
9
- activeKey?: Key;
10
- /**
11
- * Actions on the right side of tabBar
12
- */
13
- actions?: ReactNode;
14
- /**
15
- * The tab panes in tabs
16
- */
17
- children: TabsChild | TabsChild[];
18
- /**
19
- * Initial active TabPane's key, if activeKey is not set.
20
- */
21
- defaultActiveKey?: Key;
22
- /**
23
- * The change event handler of Tabs
24
- */
25
- onChange?: (activeKey: Key) => void;
26
- /**
27
- * Callback executed when tab is clicked
28
- */
29
- onTabClick?: (key: Key, event: MouseEvent) => void;
30
- /**
31
- * The className of tabBar
32
- */
33
- tabBarClassName?: string;
34
- }
35
- /**
36
- * The react component for `mezzanine` tabs.
37
- */
38
- declare const Tabs: import("react").ForwardRefExoticComponent<TabsProps & import("react").RefAttributes<HTMLDivElement>>;
39
- export default Tabs;
package/Tabs/Tabs.js DELETED
@@ -1,52 +0,0 @@
1
- import { jsxs, jsx } from 'react/jsx-runtime';
2
- import { forwardRef, useRef, Children, cloneElement } from 'react';
3
- import { tabsClasses } from '@mezzanine-ui/core/tabs';
4
- import { ChevronLeftIcon, ChevronRightIcon } from '@mezzanine-ui/icons';
5
- import { useCustomControlValue } from '../Form/useCustomControlValue.js';
6
- import useTabsOverflow from './useTabsOverflow.js';
7
- import Icon from '../Icon/Icon.js';
8
- import cx from 'clsx';
9
-
10
- /**
11
- * The react component for `mezzanine` tabs.
12
- */
13
- const Tabs = forwardRef(function Tabs(props, ref) {
14
- const { activeKey: activeKeyProp, actions, children, className, defaultActiveKey = 0, onChange, onTabClick, tabBarClassName, ...rest } = props;
15
- const tabsRef = useRef(null);
16
- const [activeKey, setActiveKey] = useCustomControlValue({
17
- defaultValue: defaultActiveKey,
18
- onChange,
19
- value: activeKeyProp,
20
- });
21
- const tabs = Children.map(children, (tabPane, index) => {
22
- var _a;
23
- const key = (_a = tabPane.key) !== null && _a !== void 0 ? _a : index;
24
- const { tab } = tabPane.props;
25
- const active = activeKey.toString() === key.toString();
26
- return cloneElement(tab, {
27
- key,
28
- active,
29
- onClick: (event) => {
30
- if (!active) {
31
- setActiveKey(key);
32
- }
33
- if (onTabClick) {
34
- onTabClick(key, event);
35
- }
36
- },
37
- });
38
- });
39
- let pane;
40
- Children.forEach(children, (tabPane, index) => {
41
- var _a;
42
- const child = tabPane;
43
- const key = (_a = child.key) !== null && _a !== void 0 ? _a : index;
44
- if (activeKey.toString() === key.toString()) {
45
- pane = child;
46
- }
47
- });
48
- const { isOverflowing, isScrollToBegin, isScrollToEnd, scrollToLeft, scrollToRight, } = useTabsOverflow(tabsRef);
49
- return (jsxs("div", { ...rest, ref: ref, className: cx(tabsClasses.host, className), children: [jsxs("div", { className: cx(tabsClasses.tabBar, tabBarClassName), children: [jsxs("div", { className: tabsClasses.overflow, children: [isOverflowing && !isScrollToBegin && (jsx("button", { "aria-label": "scrollToLeft", className: tabsClasses.scrollBtn, onClick: () => scrollToLeft(), type: "button", children: jsx(Icon, { icon: ChevronLeftIcon }) })), jsx("div", { ref: tabsRef, className: tabsClasses.tabs, children: tabs }), isOverflowing && !isScrollToEnd && (jsx("button", { "aria-label": "scrollToRight", className: tabsClasses.scrollBtn, onClick: () => scrollToRight(), type: "button", children: jsx(Icon, { icon: ChevronRightIcon }) }))] }), actions] }), pane] }));
50
- });
51
-
52
- export { Tabs as default };
package/Tabs/index.d.ts DELETED
@@ -1,6 +0,0 @@
1
- export type { TabProps } from './Tab';
2
- export { default as Tab } from './Tab';
3
- export type { TabPaneProps } from './TabPane';
4
- export { default as TabPane } from './TabPane';
5
- export type { TabsChild, TabsProps } from './Tabs';
6
- export { default } from './Tabs';
package/Tabs/index.js DELETED
@@ -1,3 +0,0 @@
1
- export { default as Tab } from './Tab.js';
2
- export { default as TabPane } from './TabPane.js';
3
- export { default } from './Tabs.js';
@@ -1,8 +0,0 @@
1
- import { RefObject } from 'react';
2
- export default function useTabsOverflow(tabsRef: RefObject<HTMLElement | null>): {
3
- isOverflowing: boolean;
4
- isScrollToBegin: boolean;
5
- isScrollToEnd: boolean;
6
- scrollToLeft: () => void;
7
- scrollToRight: () => void;
8
- };
@@ -1,62 +0,0 @@
1
- import { useState, useEffect } from 'react';
2
-
3
- function useTabsOverflow(tabsRef) {
4
- const [isOverflowing, setIsOverflowing] = useState(false);
5
- const [scrollState, setScrollState] = useState('begin');
6
- const isScrollToBegin = scrollState === 'begin';
7
- const isScrollToEnd = scrollState === 'end';
8
- function scrollToLeft() {
9
- if (tabsRef.current) {
10
- tabsRef.current.scrollTo(0, 0);
11
- }
12
- }
13
- function scrollToRight() {
14
- if (tabsRef.current) {
15
- const offsetRight = tabsRef.current.scrollWidth - tabsRef.current.clientWidth;
16
- tabsRef.current.scrollTo(offsetRight, 0);
17
- }
18
- }
19
- useEffect(() => {
20
- if (tabsRef.current) {
21
- const handleOverflowingState = () => {
22
- if (tabsRef.current) {
23
- setIsOverflowing(tabsRef.current.scrollWidth > tabsRef.current.clientWidth);
24
- }
25
- };
26
- const handleScrollState = () => {
27
- if (tabsRef.current) {
28
- const offsetRight = tabsRef.current.scrollWidth - tabsRef.current.clientWidth;
29
- if (tabsRef.current.scrollLeft === 0) {
30
- setScrollState('begin');
31
- }
32
- else if (tabsRef.current.scrollLeft >= offsetRight) {
33
- setScrollState('end');
34
- }
35
- else {
36
- setScrollState('middle');
37
- }
38
- }
39
- };
40
- // init isOverflowing when mounting
41
- handleOverflowingState();
42
- window.addEventListener('resize', handleOverflowingState);
43
- tabsRef.current.addEventListener('scroll', handleScrollState);
44
- return () => {
45
- const { current: tabsEl } = tabsRef;
46
- if (tabsEl) {
47
- window.removeEventListener('resize', handleOverflowingState);
48
- tabsEl.removeEventListener('scroll', handleScrollState);
49
- }
50
- };
51
- }
52
- }, [tabsRef]);
53
- return {
54
- isOverflowing,
55
- isScrollToBegin,
56
- isScrollToEnd,
57
- scrollToLeft,
58
- scrollToRight,
59
- };
60
- }
61
-
62
- export { useTabsOverflow as default };