@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
package/Radio/Radio.js CHANGED
@@ -1,23 +1,22 @@
1
1
  'use client';
2
- import { jsx } from 'react/jsx-runtime';
3
- import { forwardRef, useContext } from 'react';
2
+ import { jsxs, jsx } from 'react/jsx-runtime';
3
+ import { forwardRef, useContext, useState } from 'react';
4
4
  import { radioClasses } from '@mezzanine-ui/core/radio';
5
5
  import InputCheck from '../_internal/InputCheck/InputCheck.js';
6
6
  import { useRadioControlValue } from '../Form/useRadioControlValue.js';
7
7
  import { RadioGroupContext } from './RadioGroupContext.js';
8
- import { MezzanineConfig } from '../Provider/context.js';
9
- import { FormControlContext } from '../Form/FormControlContext.js';
8
+ import Icon from '../Icon/Icon.js';
9
+ import Input from '../Input/Input.js';
10
10
  import cx from 'clsx';
11
11
 
12
12
  /**
13
13
  * The react component for `mezzanine` radio.
14
14
  */
15
15
  const Radio = forwardRef(function Radio(props, ref) {
16
- const { size: globalSize } = useContext(MezzanineConfig);
17
- const { disabled: disabledFromFormControl, severity } = useContext(FormControlContext) || {};
16
+ var _a, _b;
18
17
  const radioGroup = useContext(RadioGroupContext);
19
- const { disabled: disabledFromGroup, name: nameFromGroup, size: sizeFromGroup, } = radioGroup || {};
20
- const { checked: checkedProp, children, defaultChecked, disabled = (disabledFromGroup !== null && disabledFromGroup !== void 0 ? disabledFromGroup : disabledFromFormControl) || false, error = severity === 'error' || false, inputProps, onChange: onChangeProp, size = sizeFromGroup || globalSize, value, ...rest } = props;
18
+ const { disabled: disabledFromGroup, name: nameFromGroup, size: sizeFromGroup, type: typeFromGroup, } = radioGroup || {};
19
+ const { checked: checkedProp, className, children, defaultChecked, disabled = disabledFromGroup || false, error = false, icon, hint, inputProps, onChange: onChangeProp, size = sizeFromGroup || 'main', type = typeFromGroup || 'radio', value, withInputConfig, ...rest } = props;
21
20
  const { id: inputId, name = nameFromGroup, ...restInputProps } = inputProps || {};
22
21
  const [checked, onChange] = useRadioControlValue({
23
22
  checked: checkedProp,
@@ -26,9 +25,20 @@ const Radio = forwardRef(function Radio(props, ref) {
26
25
  radioGroup,
27
26
  value,
28
27
  });
29
- return (jsx(InputCheck, { ...rest, ref: ref, control: jsx("span", { className: cx(radioClasses.host, {
30
- [radioClasses.checked]: checked,
31
- }), children: jsx("input", { ...restInputProps, "aria-checked": checked, "aria-disabled": disabled, checked: checked, disabled: disabled, id: inputId, onChange: onChange, name: name, type: "radio", value: value }) }), disabled: disabled, error: error, htmlFor: inputId, size: size, children: children }));
28
+ const [focused, setFocused] = useState(false);
29
+ return (jsxs("div", { ref: ref, className: cx(radioClasses.wrapper, className), children: [jsx(InputCheck, { ...rest, control: jsxs("span", { className: cx(radioClasses.host, radioClasses.size(size), {
30
+ [radioClasses.segmented]: type === 'segment',
31
+ [radioClasses.checked]: checked,
32
+ [radioClasses.focused]: focused,
33
+ [radioClasses.error]: error,
34
+ }), children: [type === 'segment' && (jsxs("span", { className: cx(radioClasses.segmentedContainer, {
35
+ [radioClasses.segmentedContainerHaveMinWidth]: !!children,
36
+ [radioClasses.segmentedContainerWithIconText]: !!children && !!icon,
37
+ }), children: [icon && jsx(Icon, { icon: icon, size: 16 }), children] })), jsx("input", { ...restInputProps, "aria-checked": checked, "aria-disabled": disabled, checked: checked, disabled: disabled, id: inputId, onChange: onChange, onFocus: () => {
38
+ setFocused(true);
39
+ }, onBlur: () => {
40
+ setFocused(false);
41
+ }, name: name, type: "radio", value: value })] }), disabled: disabled, error: error, focused: focused, hint: hint, htmlFor: inputId, segmentedStyle: type === 'segment', size: size, children: type === 'radio' && children }), type === 'radio' && withInputConfig && (jsx("div", { style: { width: (_a = withInputConfig.width) !== null && _a !== void 0 ? _a : 120 }, children: jsx(Input, { ...withInputConfig, variant: "base", placeholder: (_b = withInputConfig.placeholder) !== null && _b !== void 0 ? _b : 'Placeholder' }) }))] }));
32
42
  });
33
43
 
34
44
  export { Radio as default };
@@ -1,7 +1,16 @@
1
- import { RadioGroupOption, RadioSize } from '@mezzanine-ui/core/radio';
1
+ import { RadioSize } from '@mezzanine-ui/core/radio';
2
2
  import { ChangeEventHandler, ReactNode } from 'react';
3
3
  import { InputCheckGroupProps } from '../_internal/InputCheck/InputCheckGroup';
4
- export interface RadioGroupProps extends Omit<InputCheckGroupProps, 'onChange'> {
4
+ import { RadioNormalProps, RadioSegmentProps } from './Radio';
5
+ export interface RadioGroupNormalOption extends Pick<RadioNormalProps, 'disabled' | 'error' | 'icon' | 'hint' | 'withInputConfig'> {
6
+ id: string;
7
+ name: string | number;
8
+ }
9
+ export interface RadioGroupSegmentOption extends Pick<RadioSegmentProps, 'disabled' | 'error' | 'icon' | 'hint' | 'withInputConfig'> {
10
+ id: string;
11
+ name: string | number;
12
+ }
13
+ export interface RadioGroupBaseProps extends Omit<InputCheckGroupProps, 'onChange' | 'type'> {
5
14
  /**
6
15
  * The radios in radio group.
7
16
  */
@@ -25,11 +34,6 @@ export interface RadioGroupProps extends Omit<InputCheckGroupProps, 'onChange'>
25
34
  * Will be passed to each radios but composing both instead of overriding.
26
35
  */
27
36
  onChange?: ChangeEventHandler<HTMLInputElement>;
28
- /**
29
- * The options of radio group.
30
- * Will be ignored if children passed.
31
- */
32
- options?: RadioGroupOption[];
33
37
  /**
34
38
  * The size of radio group.
35
39
  * Control the size of radios in group if size not passed to radio.
@@ -40,6 +44,31 @@ export interface RadioGroupProps extends Omit<InputCheckGroupProps, 'onChange'>
40
44
  */
41
45
  value?: string;
42
46
  }
47
+ export interface RadioGroupNormalProps extends RadioGroupBaseProps {
48
+ /**
49
+ * The options of radio group.
50
+ * Will be ignored if children passed.
51
+ */
52
+ options?: RadioGroupNormalOption[];
53
+ /**
54
+ * The type of radio group.
55
+ * Control the type of radios in group if type not passed to radio.
56
+ */
57
+ type?: 'radio';
58
+ }
59
+ export interface RadioGroupSegmentProps extends RadioGroupBaseProps {
60
+ /**
61
+ * The options of radio group.
62
+ * Will be ignored if children passed.
63
+ */
64
+ options?: RadioGroupSegmentOption[];
65
+ /**
66
+ * The type of radio group.
67
+ * Control the type of radios in group if type not passed to radio.
68
+ */
69
+ type: 'segment';
70
+ }
71
+ export type RadioGroupProps = RadioGroupNormalProps | RadioGroupSegmentProps;
43
72
  /**
44
73
  * The react component for `mezzanine` radio group.
45
74
  */
@@ -9,7 +9,7 @@ import Radio from './Radio.js';
9
9
  * The react component for `mezzanine` radio group.
10
10
  */
11
11
  const RadioGroup = forwardRef(function RadioGroup(props, ref) {
12
- const { children: childrenProp, defaultValue, disabled, name, options = [], onChange: onChangeProp, size, value: valueProp, ...rest } = props;
12
+ const { children: childrenProp, defaultValue, disabled, name, options = [], onChange: onChangeProp, size, type, value: valueProp, ...rest } = props;
13
13
  const [value, onChange] = useInputControlValue({
14
14
  defaultValue,
15
15
  onChange: onChangeProp,
@@ -20,11 +20,12 @@ const RadioGroup = forwardRef(function RadioGroup(props, ref) {
20
20
  name,
21
21
  onChange,
22
22
  size,
23
+ type,
23
24
  value,
24
- }), [disabled, name, onChange, size, value]);
25
+ }), [disabled, name, onChange, size, type, value]);
25
26
  const children = childrenProp ||
26
- options.map((option) => (jsx(Radio, { disabled: option.disabled, value: option.value, children: option.label }, option.value)));
27
- return (jsx(RadioGroupContext.Provider, { value: context, children: jsx(InputCheckGroup, { ...rest, ref: ref, role: "radiogroup", children: children }) }));
27
+ options.map((option) => (jsx(Radio, { disabled: option.disabled, error: option.error, hint: option.hint, value: option.id, withInputConfig: option.withInputConfig, children: option.name }, option.id)));
28
+ return (jsx(RadioGroupContext.Provider, { value: context, children: jsx(InputCheckGroup, { ...rest, ref: ref, role: "radiogroup", segmentedStyle: type === 'segment', size: size, children: children }) }));
28
29
  });
29
30
 
30
31
  export { RadioGroup as default };
@@ -1,8 +1,9 @@
1
- import { RadioSize } from '@mezzanine-ui/core/radio';
1
+ import { RadioSize, RadioType } from '@mezzanine-ui/core/radio';
2
2
  import { RadioGroupControlContextValue } from '../Form/useRadioControlValue';
3
3
  export interface RadioGroupContextValue extends RadioGroupControlContextValue {
4
4
  disabled?: boolean;
5
5
  name?: string;
6
6
  size?: RadioSize;
7
+ type?: RadioType;
7
8
  }
8
9
  export declare const RadioGroupContext: import("react").Context<RadioGroupContextValue | undefined>;
package/Radio/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export type { RadioSize, RadioGroupOption, RadioGroupOrientation, } from '@mezzanine-ui/core/radio';
2
- export type { RadioProps } from './Radio';
1
+ export type { RadioSize, RadioGroupOrientation, } from '@mezzanine-ui/core/radio';
2
+ export type { RadioNormalProps, RadioSegmentProps, RadioProps } from './Radio';
3
3
  export { default } from './Radio';
4
- export type { RadioGroupProps } from './RadioGroup';
4
+ export type { RadioGroupNormalOption, RadioGroupSegmentOption, RadioGroupProps, } from './RadioGroup';
5
5
  export { default as RadioGroup } from './RadioGroup';
@@ -1,4 +1,4 @@
1
- import { isRangeSlider, fixRangeSliderValue, fixSingleSliderValue, toSliderCssVars, getPercentage, findClosetValueIndex, sortSliderValue, getSliderRect, getValueFromClientX, roundToStep } from '@mezzanine-ui/core/slider';
1
+ import { isRangeSlider, fixRangeSliderValue, fixSingleSliderValue, toSliderCssVars, getPercentage, sortSliderValue, findClosetValueIndex, getSliderRect, getValueFromClientX, roundToStep } from '@mezzanine-ui/core/slider';
2
2
  import { useRef, useState } from 'react';
3
3
  import { useDocumentEvents } from '../hooks/useDocumentEvents.js';
4
4
 
package/Tab/Tab.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ import { Key, ReactElement } from 'react';
2
+ import { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
3
+ import { TabItemProps } from './TabItem';
4
+ export type TabsChild = ReactElement<TabItemProps>;
5
+ export interface TabProps extends Omit<NativeElementPropsWithoutKeyAndRef<'div'>, 'onChange' | 'children'> {
6
+ /**
7
+ * Current TabItem's index
8
+ */
9
+ activeKey?: Key;
10
+ /**
11
+ * The TabItems in tab
12
+ */
13
+ children: TabsChild | TabsChild[];
14
+ /**
15
+ * Initial active TabItem's key, if activeKey is not set.
16
+ */
17
+ defaultActiveKey?: Key;
18
+ /**
19
+ * The direction of tab
20
+ * @default 'horizontal'
21
+ */
22
+ direction?: 'horizontal' | 'vertical';
23
+ /**
24
+ * The change event handler of Tab
25
+ */
26
+ onChange?: (activeKey: Key, index: number) => void;
27
+ }
28
+ /**
29
+ * The react component for `mezzanine` tab.
30
+ */
31
+ declare const Tab: import("react").ForwardRefExoticComponent<TabProps & import("react").RefAttributes<HTMLDivElement>>;
32
+ export default Tab;
package/Tab/Tab.js ADDED
@@ -0,0 +1,57 @@
1
+ import { jsxs, jsx } from 'react/jsx-runtime';
2
+ import { forwardRef, useState, useRef, Children, cloneElement, useLayoutEffect } from 'react';
3
+ import { tabClasses } from '@mezzanine-ui/core/tab';
4
+ import TabItem from './TabItem.js';
5
+ import cx from 'clsx';
6
+
7
+ /**
8
+ * The react component for `mezzanine` tab.
9
+ */
10
+ const Tab = forwardRef(function Tab(props, ref) {
11
+ const { activeKey: activeKeyProp, children, className, defaultActiveKey = 0, onChange, direction = 'horizontal', ...rest } = props;
12
+ const [activeKeyInternal, setActiveKey] = useState(defaultActiveKey);
13
+ const activeKey = activeKeyProp !== null && activeKeyProp !== void 0 ? activeKeyProp : activeKeyInternal;
14
+ const activeTabItemRef = useRef(null);
15
+ const tabItems = Children.map(children, (tabItem, index) => {
16
+ var _a;
17
+ if (!tabItem || tabItem.type !== TabItem) {
18
+ return null;
19
+ }
20
+ const key = (_a = tabItem.key) !== null && _a !== void 0 ? _a : index;
21
+ const active = activeKey === key;
22
+ return cloneElement(tabItem, {
23
+ key,
24
+ active,
25
+ ref: active ? activeTabItemRef : undefined,
26
+ onClick: (event) => {
27
+ var _a, _b;
28
+ if (!active) {
29
+ setActiveKey(key);
30
+ onChange === null || onChange === void 0 ? void 0 : onChange(key, index);
31
+ }
32
+ (_b = (_a = tabItem.props).onClick) === null || _b === void 0 ? void 0 : _b.call(_a, event);
33
+ },
34
+ });
35
+ });
36
+ // get active TabItem left and width for activeBar position
37
+ const [activeBarStyle, setActiveBarStyle] = useState({
38
+ '--active-bar-length': '0px',
39
+ '--active-bar-shift': '0px',
40
+ });
41
+ useLayoutEffect(() => {
42
+ const activeTabElement = activeTabItemRef.current;
43
+ if (activeTabElement) {
44
+ const { offsetLeft, offsetWidth, offsetTop, offsetHeight } = activeTabElement;
45
+ setActiveBarStyle({
46
+ '--active-bar-length': direction === 'horizontal' ? `${offsetWidth}px` : `${offsetHeight}px`,
47
+ '--active-bar-shift': direction === 'horizontal' ? `${offsetLeft}px` : `${offsetTop}px`,
48
+ });
49
+ }
50
+ }, [activeKey, direction]);
51
+ return (jsxs("div", { ...rest, ref: ref, className: cx(tabClasses.host, {
52
+ [tabClasses.tabHorizontal]: direction === 'horizontal',
53
+ [tabClasses.tabVertical]: direction === 'vertical',
54
+ }, className), children: [tabItems, jsx("div", { className: tabClasses.tabActiveBar, style: activeBarStyle })] }));
55
+ });
56
+
57
+ export { Tab as default };
@@ -0,0 +1,27 @@
1
+ import { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
2
+ import { IconDefinition } from '@mezzanine-ui/icons';
3
+ export interface TabItemProps extends NativeElementPropsWithoutKeyAndRef<'button'> {
4
+ /**
5
+ * Whether the tab item is active.
6
+ * Controlled by `<Tab />`.
7
+ */
8
+ active?: boolean;
9
+ /**
10
+ * The badge count to display on the tab item.
11
+ */
12
+ badgeCount?: number;
13
+ /**
14
+ * Whether the tab item is disabled.
15
+ * @default false
16
+ */
17
+ disabled?: boolean;
18
+ /**
19
+ * The icon to display on the tab item.
20
+ */
21
+ icon?: IconDefinition;
22
+ }
23
+ /**
24
+ * The react component for `mezzanine` tab.
25
+ */
26
+ declare const TabItem: import("react").ForwardRefExoticComponent<TabItemProps & import("react").RefAttributes<HTMLButtonElement>>;
27
+ export default TabItem;
package/Tab/TabItem.js ADDED
@@ -0,0 +1,18 @@
1
+ import { jsxs, jsx } from 'react/jsx-runtime';
2
+ import { forwardRef } from 'react';
3
+ import { tabClasses } from '@mezzanine-ui/core/tab';
4
+ import Icon from '../Icon/Icon.js';
5
+ import Badge from '../Badge/Badge.js';
6
+ import cx from 'clsx';
7
+
8
+ /**
9
+ * The react component for `mezzanine` tab.
10
+ */
11
+ const TabItem = forwardRef(function TabItem(props, ref) {
12
+ const { active, badgeCount, children, className, disabled = false, icon, ...rest } = props;
13
+ return (jsxs("button", { ...rest, "aria-disabled": disabled, className: cx(tabClasses.tabItem, {
14
+ [tabClasses.tabItemActive]: active,
15
+ }, className), disabled: disabled, ref: ref, type: "button", children: [icon && jsx(Icon, { className: tabClasses.tabItemIcon, icon: icon, size: 16 }), children, badgeCount !== undefined && (jsx(Badge, { className: tabClasses.tabItemBadge, count: badgeCount, variant: active ? 'count-brand' : 'count-inactive' }))] }));
16
+ });
17
+
18
+ export { TabItem as default };
package/Tab/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export type { TabItemProps } from './TabItem';
2
+ export { default as TabItem } from './TabItem';
3
+ export type { TabsChild, TabProps } from './Tab';
4
+ export { default } from './Tab';
package/Tab/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { default as TabItem } from './TabItem.js';
2
+ export { default } from './Tab.js';
package/Table/Table.d.ts CHANGED
@@ -1,110 +1,91 @@
1
- import { ReactNode } from 'react';
2
- import { TableColumn, TableComponents, TableDataSource, TableRowSelection, TableExpandable, TableFetchMore, TablePagination as TablePaginationType, TableRefresh as TableRefreshType, ExpandRowBySources, TableScrolling, TableDraggable } from '@mezzanine-ui/core/table';
3
- import { EmptyProps } from '../Empty';
4
- import { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
5
- export interface TableBaseProps<T> extends Omit<NativeElementPropsWithoutKeyAndRef<'div'>, 'role' | 'draggable'> {
6
- /**
7
- * customized body className
8
- */
9
- bodyClassName?: string;
10
- /**
11
- * customized body row className
12
- */
13
- bodyRowClassName?: string | ((source: T) => string);
14
- /**
15
- * Columns of table <br />
16
- * `column.render` allowed customizing the column body cell rendering. <br />
17
- * `column.renderTitle` allowed customizing the column header cell rendering. <br />
18
- * `column.sorter` is the sorting method that you want to apply to your column. <br />
19
- * `column.onSorted` is the callback triggered whenever sort icon clicked.
20
- */
1
+ import { TableSize, type HighlightMode, type TableColumn, type TableDataSource, type TableDraggable, type TableExpandable, type TableRowSelection, type TableScroll } from '@mezzanine-ui/core/table';
2
+ import type { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
3
+ import { type TableTransitionState } from './TableContext';
4
+ import { TablePaginationProps } from './components/TablePagination';
5
+ import type { EmptyProps } from '../Empty';
6
+ export interface TableBaseProps<T extends TableDataSource = TableDataSource> extends Omit<NativeElementPropsWithoutKeyAndRef<'table'>, 'children' | 'draggable' | 'summary' | 'onChange'> {
7
+ /** Column configuration */
21
8
  columns: TableColumn<T>[];
22
- /**
23
- * Custom table components <br />
24
- */
25
- components?: TableComponents;
26
- /**
27
- * Data record array to be displayed. <br />
28
- * Notice that each source should contain `key` or `id` prop as data primary key.
29
- */
30
- dataSource: TableDataSource[];
31
- /**
32
- * Draggable table row. This feature allows sort items by mouse dragging. Not supported when `fetchMore` is enabled and also buggy when use finger touch (mobile device).
33
- * When `draggable.enabled` is true, draggable will be enabled.
34
- * `draggable.onDragEnd` return new dataSource for you
35
- */
36
- draggable?: TableDraggable;
37
- /**
38
- * props exported from `<Empty />` component.
39
- */
9
+ /** Data source */
10
+ dataSource: T[];
11
+ /** Props for Empty component when no data */
40
12
  emptyProps?: EmptyProps;
41
- /**
42
- * When `expandable.rowExpandable` is given, it will control whether row data is expandable or not
43
- * `expandable.expandedRowRender` is a callback to helps you decides what data should be rendered.
44
- */
45
- expandable?: Omit<TableExpandable<T>, 'expandedRowRender'> & {
46
- expandedRowRender(record: T): ReactNode | ExpandRowBySources;
47
- };
48
- /**
49
- * customized header className
50
- */
51
- headerClassName?: string;
52
- /**
53
- * Whether table is loading or not
13
+ /** Expandable row configuration */
14
+ expandable?: TableExpandable<T>;
15
+ /** Highlight mode for hover effects
16
+ * @default 'row'
54
17
  */
18
+ highlight?: HighlightMode;
19
+ /** Loading state */
55
20
  loading?: boolean;
21
+ /** Number of rows to display when loading */
22
+ loadingRowsCount?: number;
56
23
  /**
57
- * When loading is true, show specific loadingTip
58
- * @default '資料載入中...'
24
+ * Whether the table is nested inside an expanded row content area
59
25
  */
60
- loadingTip?: string;
26
+ nested?: boolean;
27
+ /** Pagination configuration */
28
+ pagination?: TablePaginationProps;
61
29
  /**
62
- * `refresh.show` is true, refresh button will display at the top-start of table. <br />
63
- * `refresh.onClick` is the callback of the refresh button.
30
+ * Whether columns are resizable by user interaction
31
+ * @default false
64
32
  */
65
- refresh?: TableRefreshType;
33
+ resizable?: boolean;
66
34
  /**
67
- * Enable row selection feature <br />
68
- * `rowSelection.selectedRowKey` is the dataSource keys that are currently selected. <br />
69
- * `rowSelection.onChange` is the callback when selection changed. <br />
70
- * `rowSelection.actions` are the actions that you want to do for selected data.
35
+ * Row height preset token.
71
36
  */
72
- rowSelection?: TableRowSelection;
73
- /**
74
- * Enable table scroll feature <br />
75
- * `scroll.x` set horizontal scrolling, can also be used to specify the width of the scroll area <br />
76
- * `scroll.y` Set vertical scrolling, can also be used to specify the height of the scroll area <br />
77
- * `scroll.fixedFirstColumn` set first column fixed when horizontal scrolling.
37
+ rowHeightPreset?: 'base' | 'condensed' | 'detailed' | 'roomy';
38
+ /** Row selection configuration */
39
+ rowSelection?: TableRowSelection<T>;
40
+ /** Show header row */
41
+ showHeader?: boolean;
42
+ /** Custom size variant
43
+ * @default 'main'
78
44
  */
79
- scroll?: TableScrolling;
80
- /**
81
- * customize scroll container className
45
+ size?: TableSize;
46
+ /** Whether to enable sticky header
47
+ * @default true
82
48
  */
83
- scrollContainerClassName?: string;
49
+ sticky?: boolean;
50
+ /** Transition state for row add/remove animations (from useTableDataSource hook) */
51
+ transitionState?: TableTransitionState;
84
52
  }
85
- export interface TableWithFetchMore<T> extends TableBaseProps<T> {
86
- /**
87
- * If `fetchMore.callback` is given, table will automatically trigger it when scrolling position reach end. <br />
88
- * If `fetchMore.isReachEnd` is true, table will stop triggering callback. <br />
89
- * If `fetchMore.isFetching` is true, a loading spinner will display at the end of table and stop triggering callback.
90
- * <br />
91
- * Notice that when `fetchMore.isFetching` is `undefined`, table will take control of it when source length changed.
92
- */
93
- fetchMore?: TableFetchMore;
94
- pagination?: undefined;
53
+ /**
54
+ * Props when virtualized scrolling is enabled.
55
+ * Draggable is not allowed in this mode.
56
+ */
57
+ export interface TableVirtualizedProps<T extends TableDataSource = TableDataSource> extends TableBaseProps<T> {
58
+ /** Draggable row configuration - not available when virtualized is enabled */
59
+ draggable?: never;
60
+ /** Scroll configuration with virtualized enabled */
61
+ scroll: TableScroll & {
62
+ virtualized: true;
63
+ y: number | string;
64
+ };
95
65
  }
96
- export interface TableWithPagination<T> extends TableBaseProps<T> {
97
- /**
98
- * `pagination.current` is the current page number. (required) <br />
99
- * `pagination.onChange` is the callback when page number changed. (required) <br />
100
- * `pagination.disableAutoSlicing` set this to true if you don't want auto data slicing. <br />
101
- * `pagination.total` is the total amount of your data. (default will be dataSource length) <br />
102
- * `pagination.options` is the 'Pagination' component props. <br />
103
- * Notice that if `pagination` object is given, table will disable fetchMore and use pagination instead.
104
- */
105
- pagination?: TablePaginationType;
106
- fetchMore?: undefined;
66
+ /**
67
+ * Props when virtualized scrolling is disabled or not specified.
68
+ * Draggable is allowed in this mode.
69
+ */
70
+ export interface TableNonVirtualizedProps<T extends TableDataSource = TableDataSource> extends TableBaseProps<T> {
71
+ /** Draggable row configuration */
72
+ draggable?: TableDraggable<T>;
73
+ /** Scroll configuration for scrolling (virtualized defaults to false) */
74
+ scroll?: TableScroll & {
75
+ virtualized?: false;
76
+ };
107
77
  }
108
- export type TableProps<T> = TableWithFetchMore<T> | TableWithPagination<T>;
109
- declare const Table: import("react").ForwardRefExoticComponent<TableProps<Record<string, unknown>> & import("react").RefAttributes<HTMLTableElement>>;
78
+ /**
79
+ * TableProps - discriminated union to ensure draggable and virtualized
80
+ * scrolling are mutually exclusive at the type level.
81
+ */
82
+ export type TableProps<T extends TableDataSource = TableDataSource> = TableVirtualizedProps<T> | TableNonVirtualizedProps<T>;
83
+ /**
84
+ * Table is a high-performance data table component with support for
85
+ * virtual scrolling, column resizing, fixed columns, row selection,
86
+ * sorting, expandable rows, and drag-and-drop row reordering.
87
+ */
88
+ export declare const Table: <T extends TableDataSource = TableDataSource>(props: TableProps<T> & {
89
+ ref?: React.ForwardedRef<HTMLDivElement>;
90
+ }) => React.ReactElement;
110
91
  export default Table;