@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,7 +0,0 @@
1
- import { TableColumnBase, TableDataSource, TableRecord } from '@mezzanine-ui/core/table';
2
- import { NativeElementPropsWithoutKeyAndRef } from '../../utils/jsx-types';
3
- export interface EditableBodyCellProps extends NativeElementPropsWithoutKeyAndRef<'div'>, TableColumnBase<TableRecord<unknown>> {
4
- rowData: TableDataSource;
5
- }
6
- declare function TableEditRenderWrapper({ children, dataIndex, editable, rowData, setCellProps, ...rest }: EditableBodyCellProps): import("react/jsx-runtime").JSX.Element;
7
- export default TableEditRenderWrapper;
@@ -1,16 +0,0 @@
1
- 'use client';
2
- import { jsx, Fragment } from 'react/jsx-runtime';
3
- import { useContext } from 'react';
4
- import { TableComponentContext } from '../TableContext.js';
5
-
6
- function TableEditRenderWrapper({ children, dataIndex, editable, rowData, setCellProps, ...rest }) {
7
- var _a;
8
- const { bodyCell: BodyCell } = useContext(TableComponentContext) || {};
9
- const customProps = (_a = setCellProps === null || setCellProps === void 0 ? void 0 : setCellProps(rowData)) !== null && _a !== void 0 ? _a : {};
10
- if (typeof BodyCell === 'function') {
11
- return (jsx(BodyCell, { ...customProps, ...rest, dataIndex: dataIndex, editable: editable, rowData: rowData, children: children }));
12
- }
13
- return jsx(Fragment, { children: children });
14
- }
15
-
16
- export { TableEditRenderWrapper as default };
@@ -1,27 +0,0 @@
1
- import { NativeElementPropsWithoutKeyAndRef } from '../../utils/jsx-types';
2
- export interface TableExpandableProps extends NativeElementPropsWithoutKeyAndRef<'div'> {
3
- /**
4
- * whether is expandable or not
5
- * @default true
6
- */
7
- expandable?: boolean;
8
- /**
9
- * whether is expanded or not
10
- */
11
- expanded?: boolean;
12
- /**
13
- * Invoked by expanded status changed.
14
- */
15
- onExpand?(status: boolean): void;
16
- /**
17
- * toggle expanded
18
- */
19
- setExpanded?(e: boolean): void;
20
- /**
21
- * show icon or not
22
- * @default true
23
- */
24
- showIcon?: boolean;
25
- }
26
- declare const TableExpandable: import("react").ForwardRefExoticComponent<TableExpandableProps & import("react").RefAttributes<HTMLDivElement>>;
27
- export default TableExpandable;
@@ -1,24 +0,0 @@
1
- import { jsx } from 'react/jsx-runtime';
2
- import { forwardRef } from 'react';
3
- import { tableClasses } from '@mezzanine-ui/core/table';
4
- import { ChevronDownIcon } from '@mezzanine-ui/icons';
5
- import Icon from '../../Icon/Icon.js';
6
- import cx from 'clsx';
7
-
8
- const TableExpandable = forwardRef(function TableExpandable(props, ref) {
9
- const { className, expandable = true, expanded, onExpand, setExpanded, showIcon = true, ...rest } = props;
10
- const onClick = () => {
11
- if (expandable) {
12
- const nextStatus = !expanded;
13
- setExpanded === null || setExpanded === void 0 ? void 0 : setExpanded(nextStatus);
14
- if (onExpand) {
15
- onExpand(nextStatus);
16
- }
17
- }
18
- };
19
- return (jsx("div", { ...rest, ref: ref, className: cx(tableClasses.collapseAction, className), children: jsx("div", { className: tableClasses.icon, children: showIcon ? (jsx(Icon, { className: cx(tableClasses.icon, {
20
- [tableClasses.iconClickable]: expandable,
21
- }), color: expandable ? 'brand' : 'neutral-faint', icon: ChevronDownIcon, onClick: onClick, style: { transform: `rotate(${expanded ? '180deg' : '0'})` } })) : null }) }));
22
- });
23
-
24
- export { TableExpandable as default };
@@ -1,10 +0,0 @@
1
- import { RefObject } from 'react';
2
- import { NativeElementPropsWithoutKeyAndRef } from '../../utils/jsx-types';
3
- export interface TablePaginationProps extends NativeElementPropsWithoutKeyAndRef<'div'> {
4
- /**
5
- * body scroll ref
6
- */
7
- bodyRef: RefObject<HTMLDivElement | null>;
8
- }
9
- declare const TablePagination: import("react").ForwardRefExoticComponent<TablePaginationProps & import("react").RefAttributes<HTMLDivElement>>;
10
- export default TablePagination;
@@ -1,26 +0,0 @@
1
- 'use client';
2
- import { jsxs, jsx } from 'react/jsx-runtime';
3
- import { forwardRef, useContext } from 'react';
4
- import { tableClasses } from '@mezzanine-ui/core/table';
5
- import { TableContext } from '../TableContext.js';
6
- import { useTablePagination } from './useTablePagination.js';
7
- import Pagination from '../../Pagination/Pagination.js';
8
- import cx from 'clsx';
9
-
10
- const TablePagination = forwardRef(function TablePagination(props, ref) {
11
- var _a;
12
- const { className, bodyRef, ...rest } = props;
13
- const { pagination } = useContext(TableContext) || {};
14
- const { current: currentPageProp, onChange: onChangePageProp, total, options: paginationOptions = {}, } = pagination || {};
15
- const [currentPage, setCurrentPage] = useTablePagination({
16
- bodyRef,
17
- current: currentPageProp,
18
- onChange: onChangePageProp,
19
- });
20
- const { boundaryCount, className: paginationClassName, disabled, hideNextButton, hidePreviousButton, jumperButtonText, jumperHintText, jumperInputPlaceholder, onChangePageSize, pageSize: pageSizeProp, pageSizeLabel, pageSizeOptions, pageSizeUnit, renderPageSizeOptionName, renderPaginationSummary, showJumper, showPageSizeOptions, siblingCount, } = paginationOptions;
21
- const currentStartCount = pageSizeProp * (currentPage - 1) + 1;
22
- const currentEndCount = Math.min(pageSizeProp * currentPage, total);
23
- return (jsxs("div", { ...rest, ref: ref, className: cx(tableClasses.pagination, className), children: [jsx("span", { className: tableClasses.paginationIndicator, children: (_a = renderPaginationSummary === null || renderPaginationSummary === void 0 ? void 0 : renderPaginationSummary(currentStartCount, currentEndCount)) !== null && _a !== void 0 ? _a : `目前顯示 ${currentStartCount} - ${currentEndCount} 筆,共 ${total} 筆資料` }), jsx("div", { className: tableClasses.paginationActions, children: jsx(Pagination, { boundaryCount: boundaryCount, buttonText: jumperButtonText, className: paginationClassName, current: currentPage, disabled: disabled, hideNextButton: hideNextButton, hidePreviousButton: hidePreviousButton, hintText: jumperHintText, inputPlaceholder: jumperInputPlaceholder, onChange: setCurrentPage, onChangePageSize: onChangePageSize, pageSize: pageSizeProp, pageSizeLabel: pageSizeLabel, pageSizeOptions: pageSizeOptions, pageSizeUnit: pageSizeUnit, renderPageSizeOptionName: renderPageSizeOptionName, showJumper: showJumper, showPageSizeOptions: showPageSizeOptions, siblingCount: siblingCount, total: total }) })] }));
24
- });
25
-
26
- export { TablePagination as default };
@@ -1,8 +0,0 @@
1
- import { RefObject } from 'react';
2
- import { TablePagination } from '@mezzanine-ui/core/table';
3
- export interface UseTablePagination {
4
- bodyRef: RefObject<HTMLDivElement | null>;
5
- current?: TablePagination['current'];
6
- onChange?: TablePagination['onChange'];
7
- }
8
- export declare function useTablePagination(props: UseTablePagination): readonly [number, (c: number) => void];
@@ -1,30 +0,0 @@
1
- 'use client';
2
- import { useContext } from 'react';
3
- import { useControlValueState } from '../../Form/useControlValueState.js';
4
- import { useLastCallback } from '../../hooks/useLastCallback.js';
5
- import { TableContext } from '../TableContext.js';
6
-
7
- const equalityFn = (a, b) => a === b;
8
- function useTablePagination(props) {
9
- const { bodyRef, current: currentProp, onChange: onChangeProp } = props;
10
- const { sorting } = useContext(TableContext) || {};
11
- const [current, setCurrent] = useControlValueState({
12
- defaultValue: 1,
13
- equalityFn,
14
- value: currentProp,
15
- });
16
- const onChange = useLastCallback((newCurrent) => {
17
- var _a, _b;
18
- if (!equalityFn(current, newCurrent)) {
19
- setCurrent(newCurrent);
20
- /** reset body scroll position when page changed */
21
- (_a = bodyRef.current) === null || _a === void 0 ? void 0 : _a.scrollTo(0, 0);
22
- /** reset sorting status */
23
- (_b = sorting === null || sorting === void 0 ? void 0 : sorting.onResetAll) === null || _b === void 0 ? void 0 : _b.call(sorting);
24
- }
25
- onChangeProp === null || onChangeProp === void 0 ? void 0 : onChangeProp(newCurrent);
26
- });
27
- return [current, onChange];
28
- }
29
-
30
- export { useTablePagination };
@@ -1,10 +0,0 @@
1
- import { MouseEvent } from 'react';
2
- import { NativeElementPropsWithoutKeyAndRef } from '../../utils/jsx-types';
3
- export interface TableRefreshProps extends Omit<NativeElementPropsWithoutKeyAndRef<'div'>, 'onClick'> {
4
- /**
5
- * callback when button is clicked
6
- */
7
- onClick?(e: MouseEvent): void;
8
- }
9
- declare const TableRefresh: import("react").ForwardRefExoticComponent<TableRefreshProps & import("react").RefAttributes<HTMLDivElement>>;
10
- export default TableRefresh;
@@ -1,22 +0,0 @@
1
- 'use client';
2
- import { jsx } from 'react/jsx-runtime';
3
- import { forwardRef, useContext, useCallback } from 'react';
4
- import cx from 'clsx';
5
- import { tableClasses } from '@mezzanine-ui/core/table';
6
- import { ResetIcon } from '@mezzanine-ui/icons';
7
- import { TableContext } from '../TableContext.js';
8
- import Button from '../../Button/Button.js';
9
- import Icon from '../../Icon/Icon.js';
10
-
11
- const TableRefresh = forwardRef(function TableRefresh(props, ref) {
12
- const { className, children, onClick, ...rest } = props;
13
- const { setLoading } = useContext(TableContext) || {};
14
- const onRefreshClicked = useCallback((e) => {
15
- e.stopPropagation();
16
- setLoading === null || setLoading === void 0 ? void 0 : setLoading(true);
17
- onClick === null || onClick === void 0 ? void 0 : onClick(e);
18
- }, [onClick, setLoading]);
19
- return (jsx("div", { ref: ref, className: cx(tableClasses.refresh, className), ...rest, children: jsx(Button, { onClick: onRefreshClicked, prefix: jsx(Icon, { icon: ResetIcon }), children: children || '重新整理' }) }));
20
- });
21
-
22
- export { TableRefresh as default };
@@ -1,18 +0,0 @@
1
- import { NativeElementPropsWithoutKeyAndRef } from '../../utils/jsx-types';
2
- export interface TableRowSelectionProps extends NativeElementPropsWithoutKeyAndRef<'div'> {
3
- /**
4
- * row key to control checkbox
5
- */
6
- rowKey: string;
7
- /**
8
- * show dropdown icon or not
9
- * @default false
10
- */
11
- showDropdownIcon?: boolean;
12
- /**
13
- * function to get check status
14
- */
15
- setChecked?(c: boolean): void;
16
- }
17
- declare const TableRowSelection: import("react").ForwardRefExoticComponent<TableRowSelectionProps & import("react").RefAttributes<HTMLDivElement>>;
18
- export default TableRowSelection;
@@ -1,93 +0,0 @@
1
- 'use client';
2
- import { jsx, jsxs } from 'react/jsx-runtime';
3
- import { forwardRef, useContext, useCallback, useMemo, useEffect, useState } from 'react';
4
- import { tableClasses } from '@mezzanine-ui/core/table';
5
- import xor from 'lodash/xor';
6
- import { MoreVerticalIcon } from '@mezzanine-ui/icons';
7
- import { TableContext, TableDataContext } from '../TableContext.js';
8
- import { SELECTED_ALL_KEY } from './useTableRowSelection.js';
9
- import Checkbox from '../../Checkbox/Checkbox.js';
10
- import Menu from '../../Menu/Menu.js';
11
- import MenuItem from '../../Menu/MenuItem.js';
12
- import Dropdown from '../../Dropdown/Dropdown.js';
13
- import Icon from '../../Icon/Icon.js';
14
- import cx from 'clsx';
15
-
16
- const TableRowSelection = forwardRef(function TableRowSelection(props, ref) {
17
- var _a, _b, _c;
18
- const { rowKey, setChecked, showDropdownIcon, ...rest } = props;
19
- const { rowSelection, expanding } = useContext(TableContext) || {};
20
- const { dataSource = [] } = useContext(TableDataContext) || {};
21
- /** checkbox methods/state */
22
- const onSelected = useCallback(() => {
23
- rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.onChange(rowKey);
24
- }, [rowSelection, rowKey]);
25
- const checkboxStatus = useMemo(() => {
26
- var _a, _b;
27
- const selectedRowKeys = (_a = rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.selectedRowKeys) !== null && _a !== void 0 ? _a : [];
28
- if (!selectedRowKeys.length)
29
- return 'none';
30
- const validDataSource = xor((_b = rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.disabledRowKeys) !== null && _b !== void 0 ? _b : [], dataSource.map((d) => (d.id || d.key)));
31
- if (selectedRowKeys.length === validDataSource.length)
32
- return 'all';
33
- return 'indeterminate';
34
- }, [
35
- rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.selectedRowKeys,
36
- rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.disabledRowKeys,
37
- dataSource,
38
- ]);
39
- const selfChecked = useMemo(() => { var _a; return ((_a = rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.selectedRowKeys) !== null && _a !== void 0 ? _a : []).some((key) => key === rowKey); }, [rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.selectedRowKeys, rowKey]);
40
- /** checkbox props */
41
- const isHeaderCheckbox = rowKey === SELECTED_ALL_KEY;
42
- const checked = isHeaderCheckbox ? checkboxStatus === 'all' : selfChecked;
43
- const indeterminate = isHeaderCheckbox
44
- ? checkboxStatus === 'indeterminate'
45
- : false;
46
- const name = isHeaderCheckbox ? '選擇全部' : '選擇';
47
- /** parent callbacks */
48
- useEffect(() => {
49
- setChecked === null || setChecked === void 0 ? void 0 : setChecked(checked);
50
- }, [checked, setChecked]);
51
- /** If expandable icon existed, it will affect row selection styling (only when dropdown icon is hidden) */
52
- const hiddenIconWithExpandableStyle = useMemo(() => {
53
- if (!expanding || showDropdownIcon)
54
- return {};
55
- return {
56
- host: {
57
- paddingRight: 0,
58
- },
59
- icon: {
60
- width: 0,
61
- },
62
- };
63
- }, [showDropdownIcon, expanding]);
64
- /** menu */
65
- const [open, toggleOpen] = useState(false);
66
- const isMenuAllowOpen = checked || indeterminate;
67
- const onIconClicked = useCallback((evt) => {
68
- evt.stopPropagation();
69
- if (isMenuAllowOpen)
70
- toggleOpen((prev) => !prev);
71
- }, [isMenuAllowOpen]);
72
- const onMenuItemClicked = (evt, action) => {
73
- var _a;
74
- evt.stopPropagation();
75
- (_a = action.onClick) === null || _a === void 0 ? void 0 : _a.call(action, rowSelection.selectedRowKeys);
76
- toggleOpen(false);
77
- };
78
- const actionMenu = (jsx(Menu, { size: "medium", children: ((_a = rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.actions) !== null && _a !== void 0 ? _a : []).map((action) => (jsx(MenuItem, { className: action.className, onClick: (evt) => onMenuItemClicked(evt, action), children: action.text }, action.key))) }));
79
- return (jsxs("div", { ref: ref, ...rest, className: tableClasses.selections, style: hiddenIconWithExpandableStyle.host, children: [jsx(Checkbox, { checked: checked, disabled: ((_b = rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.disabledRowKeys) === null || _b === void 0 ? void 0 : _b.length)
80
- ? rowSelection.disabledRowKeys.includes(rowKey)
81
- : false, indeterminate: indeterminate, inputProps: {
82
- name,
83
- }, onChange: onSelected, size: "medium" }), ((_c = rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.actions) === null || _c === void 0 ? void 0 : _c.length) ? (jsx("div", { className: tableClasses.icon, style: hiddenIconWithExpandableStyle.icon, children: showDropdownIcon ? (jsx(Dropdown, { menu: actionMenu, onClose: () => toggleOpen(false), popperProps: {
84
- open,
85
- options: {
86
- placement: 'bottom-start',
87
- },
88
- }, children: (dropdownRef) => (jsx(Icon, { ref: dropdownRef, className: cx(tableClasses.icon, {
89
- [tableClasses.iconClickable]: isMenuAllowOpen,
90
- }), color: isMenuAllowOpen ? 'brand' : 'neutral-faint', icon: MoreVerticalIcon, onClick: onIconClicked })) })) : null })) : null] }));
91
- });
92
-
93
- export { TableRowSelection as default };
@@ -1,6 +0,0 @@
1
- import { TableRowSelection, TableDataSource } from '@mezzanine-ui/core/table';
2
- export declare const SELECTED_ALL_KEY = "MZN-TABLE-ROW-SELECTION-ALL";
3
- export interface UseTableRowSelection extends Omit<TableRowSelection, 'actions'> {
4
- dataSource: TableDataSource[];
5
- }
6
- export declare function useTableRowSelection(props: UseTableRowSelection): readonly [string[], (v: string) => void];
@@ -1,53 +0,0 @@
1
- import xor from 'lodash/xor';
2
- import { useControlValueState } from '../../Form/useControlValueState.js';
3
- import { useLastCallback } from '../../hooks/useLastCallback.js';
4
-
5
- const equalityFn = (a, b) => {
6
- const sortedA = a.sort();
7
- const sortedB = b.sort();
8
- return (sortedA.length === sortedB.length &&
9
- sortedA.every((v, idx) => v === sortedB[idx]));
10
- };
11
- const SELECTED_ALL_KEY = 'MZN-TABLE-ROW-SELECTION-ALL';
12
- function useTableRowSelection(props) {
13
- const { selectedRowKey: selectedRowKeyProp, onChange: onChangeProp, disabledRowKeys = [], dataSource, } = props;
14
- const [selectedRowKey, setSelectedRowKey] = useControlValueState({
15
- defaultValue: [],
16
- equalityFn,
17
- value: selectedRowKeyProp,
18
- });
19
- const onChange = useLastCallback((rowKey) => {
20
- if (!dataSource.length)
21
- return;
22
- const allSourceKeys = dataSource.map((source) => (source.key || source.id));
23
- const validSourceKeys = xor(disabledRowKeys, allSourceKeys);
24
- let nextSelectedRowKey = selectedRowKey;
25
- if (rowKey === SELECTED_ALL_KEY) {
26
- if (equalityFn(selectedRowKey, validSourceKeys)) {
27
- nextSelectedRowKey = [];
28
- }
29
- else {
30
- nextSelectedRowKey = validSourceKeys;
31
- }
32
- }
33
- else {
34
- const existedRowKeyIdx = selectedRowKey.findIndex((key) => key === rowKey);
35
- if (~existedRowKeyIdx) {
36
- nextSelectedRowKey = [
37
- ...selectedRowKey.slice(0, existedRowKeyIdx),
38
- ...selectedRowKey.slice(existedRowKeyIdx + 1),
39
- ];
40
- }
41
- else {
42
- nextSelectedRowKey = [...selectedRowKey, rowKey];
43
- }
44
- }
45
- setSelectedRowKey(nextSelectedRowKey);
46
- if (onChangeProp) {
47
- onChangeProp(nextSelectedRowKey);
48
- }
49
- });
50
- return [selectedRowKey, onChange];
51
- }
52
-
53
- export { SELECTED_ALL_KEY, useTableRowSelection };
@@ -1,10 +0,0 @@
1
- import { TableColumn, TableRecord } from '@mezzanine-ui/core/table';
2
- import { NativeElementPropsWithoutKeyAndRef } from '../../utils/jsx-types';
3
- export interface TableSortingIconProps extends NativeElementPropsWithoutKeyAndRef<'i'> {
4
- /**
5
- * current table column
6
- */
7
- column: TableColumn<TableRecord<unknown>>;
8
- }
9
- declare const TableSortingIcon: import("react").ForwardRefExoticComponent<TableSortingIconProps & import("react").RefAttributes<HTMLElement>>;
10
- export default TableSortingIcon;
@@ -1,33 +0,0 @@
1
- 'use client';
2
- import { jsx } from 'react/jsx-runtime';
3
- import { forwardRef, useMemo, useContext } from 'react';
4
- import { tableClasses } from '@mezzanine-ui/core/table';
5
- import { ArrowRightIcon } from '@mezzanine-ui/icons';
6
- import { TableContext } from '../TableContext.js';
7
- import Icon from '../../Icon/Icon.js';
8
- import cx from 'clsx';
9
-
10
- const TableSortingIcon = forwardRef(function TableSortingIcon(props, ref) {
11
- const { className, column, ...rest } = props;
12
- const uniqueId = useMemo(() => `${crypto.getRandomValues(new Uint32Array(5))[0]}`, []);
13
- const { sorting } = useContext(TableContext) || {};
14
- const { key = uniqueId } = column;
15
- /** styling */
16
- const currentType = (key === (sorting === null || sorting === void 0 ? void 0 : sorting.sortedOn) ? sorting.sortedType : 'none');
17
- const currentIconStyle = useMemo(() => ({
18
- color: currentType === 'none' ? 'neutral' : 'neutral-strong',
19
- style: {
20
- transform: `rotate(${90 * (currentType === 'asc' ? -1 : 1)}deg)`,
21
- },
22
- }), [currentType]);
23
- return (jsx(Icon, { ...rest, ref: ref, className: cx(tableClasses.icon, tableClasses.iconClickable, className), color: currentIconStyle.color, icon: ArrowRightIcon, onClick: (evt) => {
24
- var _a;
25
- evt.stopPropagation();
26
- (_a = sorting === null || sorting === void 0 ? void 0 : sorting.onSort) === null || _a === void 0 ? void 0 : _a.call(sorting, {
27
- ...column,
28
- key,
29
- });
30
- }, style: currentIconStyle.style }));
31
- });
32
-
33
- export { TableSortingIcon as default };
@@ -1,11 +0,0 @@
1
- import { TableDataSource, TableColumn, TableRecord } from '@mezzanine-ui/core/table';
2
- export interface UseTableSorting {
3
- dataSource: TableDataSource[];
4
- }
5
- export type SortedType = 'desc' | 'asc' | 'none';
6
- export declare function useTableSorting(props: UseTableSorting): readonly [TableDataSource[], (v: Pick<TableColumn<TableRecord<unknown>>, "key" | "dataIndex" | "sorter" | "onSorted">) => void, {
7
- readonly sortedOn: string;
8
- readonly sortedType: SortedType;
9
- readonly onResetAll: () => void;
10
- readonly setDataSource: import("react").Dispatch<import("react").SetStateAction<TableDataSource[]>>;
11
- }];
@@ -1,121 +0,0 @@
1
- import { useState, useEffect, useCallback } from 'react';
2
- import isEqual from 'lodash/isEqual';
3
- import get from 'lodash/get';
4
- import { useControlValueState } from '../../Form/useControlValueState.js';
5
- import { useLastCallback } from '../../hooks/useLastCallback.js';
6
- import { usePreviousValue } from '../../hooks/usePreviousValue.js';
7
-
8
- const sortSource = (prev, cur) => {
9
- const prevKey = (prev.key || prev.id);
10
- const curKey = (cur.key || cur.id);
11
- if (prevKey < curKey)
12
- return -1;
13
- if (prevKey > curKey)
14
- return 1;
15
- return 0;
16
- };
17
- /**
18
- * @NOTE deepCompare = true 時,會深度比較 dataSource 順序是否有不同
19
- * @NOTE deepCompare = false(預設),則是為了內部排序可以讓 useControlValueState 認為是一樣的 dataSource
20
- * useControlValueState 會強制把 return value 和傳入的 value 做同步,當有不一樣時就會自動 sync
21
- * 所以無論如何用 setDataSource 都不會有改變
22
- */
23
- const equalityFn = (a, b, deepCompare = false) => {
24
- const aTemp = a.slice(0);
25
- const bTemp = b.slice(0);
26
- const sortedA = deepCompare ? aTemp : aTemp.sort(sortSource);
27
- const sortedB = deepCompare ? bTemp : bTemp.sort(sortSource);
28
- const mappedAKeys = sortedA.map((s) => (s.key || s.id));
29
- const mappedBKeys = sortedB.map((s) => (s.key || s.id));
30
- const isShallowEqual = mappedAKeys.length === mappedBKeys.length &&
31
- mappedAKeys.every((v, idx) => v === mappedBKeys[idx]);
32
- if (isShallowEqual) {
33
- // we need to do deep compare to sync dataSources
34
- return sortedA.every((v, idx) => isEqual(v, sortedB[idx]));
35
- }
36
- // since shallow equal checked that array is different, so we don't need do deep compare
37
- return false;
38
- };
39
- function useTableSorting(props) {
40
- const { dataSource: dataSourceProp } = props;
41
- const [sortedOn, setSortedOn] = useState('');
42
- const [sortedType, setSortedType] = useState('none');
43
- const [dataSource, setDataSource] = useControlValueState({
44
- defaultValue: [],
45
- equalityFn,
46
- /** @NOTE 只有當 dataSource 傳入時,並且使用了 table 提供的 sorting,才需要完全同步 dataSource */
47
- value: dataSourceProp.length && sortedOn ? dataSourceProp : undefined,
48
- });
49
- const prevDataSourceProps = usePreviousValue(dataSourceProp);
50
- useEffect(() => {
51
- /**
52
- * @NOTE 條件1: 如果一開始就有傳入值,則直接同步 dataSource
53
- * @NOTE 條件2: 深度比較舊 dataSourceProp 跟新的是否有不同,如果有則同步
54
- */
55
- if (!dataSource.length ||
56
- !equalityFn(prevDataSourceProps, dataSourceProp, true)) {
57
- setDataSource(dataSourceProp);
58
- }
59
- // eslint-disable-next-line react-hooks/exhaustive-deps
60
- }, [prevDataSourceProps, dataSourceProp]);
61
- const getNextSortedType = useCallback((currentType) => {
62
- // none -> desc -> asc -> none
63
- if (currentType === 'none')
64
- return 'desc';
65
- if (currentType === 'desc')
66
- return 'asc';
67
- return 'none';
68
- }, []);
69
- const onReset = useCallback(() => setSortedOn(''), []);
70
- const onResetAll = useCallback(() => {
71
- setSortedOn('');
72
- setSortedType('none');
73
- }, []);
74
- const onChange = useLastCallback((opts) => {
75
- const { key = '', dataIndex, sorter, onSorted } = opts;
76
- const isChosenFromOneToAnother = sortedOn && key !== sortedOn;
77
- const nextSortedType = getNextSortedType(isChosenFromOneToAnother ? 'none' : sortedType);
78
- const onMappingSources = (sources) => {
79
- setDataSource(sources);
80
- onSorted === null || onSorted === void 0 ? void 0 : onSorted(key, nextSortedType);
81
- };
82
- // only apply changes when column sorter is given
83
- if (typeof sorter === 'function' || typeof onSorted === 'function') {
84
- // should update next sorted type first
85
- setSortedType(nextSortedType);
86
- switch (nextSortedType) {
87
- case 'desc':
88
- case 'asc': {
89
- // update current working key
90
- setSortedOn(key);
91
- // getting new source instance (when switch between sorter, should use origin dataSource)
92
- let newSource = (isChosenFromOneToAnother ? dataSourceProp : dataSource).slice(0);
93
- if (typeof sorter === 'function') {
94
- console.warn('When using a `sorter` function, please provide the `dataIndex` to make sure it worked as expected.');
95
- // sort by given sorter
96
- newSource = newSource.sort((a, b) =>
97
- // reverse result when sorted type is ascending
98
- sorter(get(a, dataIndex || ''), get(b, dataIndex || '')) *
99
- (nextSortedType === 'asc' ? -1 : 1));
100
- }
101
- // map back the data source
102
- onMappingSources(newSource);
103
- break;
104
- }
105
- case 'none':
106
- default: {
107
- onReset();
108
- onMappingSources(dataSourceProp);
109
- break;
110
- }
111
- }
112
- }
113
- });
114
- return [
115
- dataSource,
116
- onChange,
117
- { sortedOn, sortedType, onResetAll, setDataSource },
118
- ];
119
- }
120
-
121
- export { useTableSorting };
@@ -1,10 +0,0 @@
1
- import { TableFetchMore, TableDataSource } from '@mezzanine-ui/core/table';
2
- export interface UseTableFetchMore extends TableFetchMore {
3
- dataSource: TableDataSource[];
4
- disabled?: boolean;
5
- }
6
- export declare function useTableFetchMore(props: UseTableFetchMore): {
7
- readonly fetchMore: (() => void) | undefined;
8
- readonly isFetching: boolean;
9
- readonly isReachEnd: boolean;
10
- };
@@ -1,50 +0,0 @@
1
- import { useMemo, useEffect } from 'react';
2
- import { useControlValueState } from '../Form/useControlValueState.js';
3
- import { useLastCallback } from '../hooks/useLastCallback.js';
4
- import { usePreviousValue } from '../hooks/usePreviousValue.js';
5
-
6
- const equalityFn = (a, b) => a === b;
7
- function useTableFetchMore(props) {
8
- const { callback: callbackProp, dataSource, disabled = false, isReachEnd: isReachEndProp, isFetching: isFetchingProp, } = props;
9
- /** reach end indicator */
10
- const [isReachEnd] = useControlValueState({
11
- defaultValue: false,
12
- equalityFn,
13
- value: isReachEndProp,
14
- });
15
- /** fetching indicator */
16
- const [isFetching, setFetching] = useControlValueState({
17
- defaultValue: false,
18
- equalityFn,
19
- value: isFetchingProp,
20
- });
21
- const onFetching = useLastCallback((newState) => {
22
- if (!equalityFn(isFetching, newState))
23
- setFetching(newState);
24
- });
25
- /** fetchMore called */
26
- const onFetchMore = useLastCallback(() => {
27
- if (!isFetching && !isReachEnd) {
28
- callbackProp();
29
- onFetching(true);
30
- }
31
- if (isReachEnd)
32
- onFetching(false);
33
- });
34
- const fetchMore = callbackProp && !disabled ? onFetchMore : undefined;
35
- /** check source length and reset states */
36
- const prevSourceLength = usePreviousValue(dataSource.length);
37
- const currentSourceLength = useMemo(() => dataSource.length, [dataSource.length]);
38
- useEffect(() => {
39
- if (prevSourceLength !== currentSourceLength) {
40
- onFetching(false);
41
- }
42
- }, [prevSourceLength, currentSourceLength, onFetching]);
43
- return {
44
- fetchMore,
45
- isFetching,
46
- isReachEnd,
47
- };
48
- }
49
-
50
- export { useTableFetchMore };
@@ -1,5 +0,0 @@
1
- export declare const SELECTED_ALL_KEY = "MZN-TABLE-ROW-SELECTION-ALL";
2
- export interface UseTableLoading {
3
- loading?: boolean;
4
- }
5
- export declare function useTableLoading(props: UseTableLoading): readonly [boolean, (l: boolean) => void];
@@ -1,19 +0,0 @@
1
- import { useControlValueState } from '../Form/useControlValueState.js';
2
- import { useLastCallback } from '../hooks/useLastCallback.js';
3
-
4
- const equalityFn = (a, b) => a === b;
5
- function useTableLoading(props) {
6
- const { loading: loadingProp } = props;
7
- const [loading, setLoading] = useControlValueState({
8
- defaultValue: false,
9
- equalityFn,
10
- value: loadingProp,
11
- });
12
- const onChange = useLastCallback((isLoading) => {
13
- if (!equalityFn(loading, isLoading))
14
- setLoading(isLoading);
15
- });
16
- return [loading, onChange];
17
- }
18
-
19
- export { useTableLoading };