@wonderflow/react-components 7.0.0 → 8.2.0
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.
- package/dist/components/autocomplete/autocomplete-option.d.ts +0 -10
- package/dist/components/autocomplete/autocomplete-option.d.ts.map +1 -1
- package/dist/components/autocomplete/autocomplete-option.js +1 -1
- package/dist/components/autocomplete/autocomplete.d.ts +5 -3
- package/dist/components/autocomplete/autocomplete.d.ts.map +1 -1
- package/dist/components/autocomplete/autocomplete.js +10 -11
- package/dist/components/container/container.d.ts +1 -1
- package/dist/components/container/container.d.ts.map +1 -1
- package/dist/components/container/container.module.css +1 -1
- package/dist/components/disclosure/disclosure.d.ts.map +1 -1
- package/dist/components/disclosure/disclosure.js +2 -2
- package/dist/components/drawer/drawer.d.ts.map +1 -1
- package/dist/components/drawer/drawer.js +2 -2
- package/dist/components/icon/icon.d.ts +1 -1
- package/dist/components/menu/menu-item/menu-item.d.ts +5 -1
- package/dist/components/menu/menu-item/menu-item.d.ts.map +1 -1
- package/dist/components/menu/menu-item/menu-item.js +3 -3
- package/dist/components/menu/menu.d.ts +4 -0
- package/dist/components/menu/menu.d.ts.map +1 -1
- package/dist/components/menu/menu.js +5 -2
- package/dist/components/menu/menu.module.css +1 -1
- package/dist/components/modal/modal.d.ts.map +1 -1
- package/dist/components/modal/modal.js +2 -2
- package/dist/components/overlay-container/overlay-container.d.ts.map +1 -1
- package/dist/components/overlay-container/overlay-container.js +2 -2
- package/dist/components/popover/popover.d.ts.map +1 -1
- package/dist/components/popover/popover.js +6 -6
- package/dist/components/slider/slider.module.css +1 -1
- package/dist/components/spinner/spinner.d.ts.map +1 -1
- package/dist/components/spinner/spinner.js +6 -6
- package/dist/components/tab/tab.d.ts +27 -26
- package/dist/components/tab/tab.d.ts.map +1 -1
- package/dist/components/tab/tab.js +15 -32
- package/dist/components/tab/tab.module.css +1 -1
- package/dist/components/tab/tabs-panel.d.ts +10 -0
- package/dist/components/tab/tabs-panel.d.ts.map +1 -0
- package/dist/components/tab/tabs-panel.js +5 -0
- package/dist/components/table/table-controls/toggle-columns.d.ts.map +1 -1
- package/dist/components/table/table-controls/toggle-columns.js +2 -2
- package/dist/components/table/table.d.ts +41 -51
- package/dist/components/table/table.d.ts.map +1 -1
- package/dist/components/table/table.js +64 -64
- package/dist/components/table/types.d.ts +2 -2
- package/dist/components/table/types.d.ts.map +1 -1
- package/dist/components/textfield/base-field/base-field.module.css +1 -1
- package/dist/components/toggle-button/toggle-button.d.ts.map +1 -1
- package/dist/components/toggle-button/toggle-button.js +4 -4
- package/package.json +15 -14
- package/dist/components/tab/primitive-tab.d.ts +0 -12
- package/dist/components/tab/primitive-tab.d.ts.map +0 -1
- package/dist/components/tab/primitive-tab.js +0 -51
- package/dist/components/tab/tab-item.d.ts +0 -23
- package/dist/components/tab/tab-item.d.ts.map +0 -1
- package/dist/components/tab/tab-item.js +0 -24
- package/dist/components/tab/tab-list.d.ts +0 -8
- package/dist/components/tab/tab-list.d.ts.map +0 -1
- package/dist/components/tab/tab-list.js +0 -11
- package/dist/components/tab/tab-panel.d.ts +0 -35
- package/dist/components/tab/tab-panel.d.ts.map +0 -1
- package/dist/components/tab/tab-panel.js +0 -16
- package/dist/components/tab/use-constant.d.ts +0 -2
- package/dist/components/tab/use-constant.d.ts.map +0 -1
- package/dist/components/tab/use-constant.js +0 -8
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tabs-panel.d.ts","sourceRoot":"","sources":["../../../src/components/tab/tabs-panel.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,aAAa,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAGxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAA;AAGzC,oBAAY,aAAa,GAAG,iBAAiB,CAAC,cAAc,CAAC,GAAG;IAC9D,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC;IAC3B,KAAK,EAAE,aAAa,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;CAChD,CAAC;AAEF,eAAO,MAAM,QAAQ,kDAKlB,aAAa,gBAQf,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import * as TabsPrimitive from '@radix-ui/react-tabs';
|
|
3
|
+
import styles from './tab.module.css';
|
|
4
|
+
import clsx from 'clsx';
|
|
5
|
+
export const TabPanel = ({ className, children, label, ...otherProps }) => (_jsx(TabsPrimitive.Content, { className: clsx(styles.Panel, className), "data-tabs-label": label, ...otherProps, children: children }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toggle-columns.d.ts","sourceRoot":"","sources":["../../../../src/components/table/table-controls/toggle-columns.tsx"],"names":[],"mappings":";AAIA,OAAO,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAA;AAEnD,aAAK,yBAAyB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;IAClE,OAAO,EAAE,KAAK,CAAC,wBAAwB,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5C,cAAc,EAAE,KAAK,CAAC,wBAAwB,CAAC,CAAC,CAAC,CAAC,CAAC;CACpD,CAAA;AAED,eAAO,MAAM,oBAAoB,+
|
|
1
|
+
{"version":3,"file":"toggle-columns.d.ts","sourceRoot":"","sources":["../../../../src/components/table/table-controls/toggle-columns.tsx"],"names":[],"mappings":";AAIA,OAAO,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAA;AAEnD,aAAK,yBAAyB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;IAClE,OAAO,EAAE,KAAK,CAAC,wBAAwB,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5C,cAAc,EAAE,KAAK,CAAC,wBAAwB,CAAC,CAAC,CAAC,CAAC,CAAC;CACpD,CAAA;AAED,eAAO,MAAM,oBAAoB,+GAwDhC,CAAA"}
|
|
@@ -3,7 +3,7 @@ import { useCallback, useMemo } from 'react';
|
|
|
3
3
|
import { Button, Menu, Popover } from '../../..';
|
|
4
4
|
export const ToggleColumnsControl = ({ columns, visibleColumns }) => {
|
|
5
5
|
const someVisibleColums = useMemo(() => visibleColumns.length !== 0, [visibleColumns]);
|
|
6
|
-
const filteredColumns = useMemo(() => columns.filter(col => !col.
|
|
6
|
+
const filteredColumns = useMemo(() => columns.filter(col => !col.isToggable), [columns]);
|
|
7
7
|
const handleToggleAll = useCallback(() => {
|
|
8
8
|
/**
|
|
9
9
|
* If there are visible columns (excluding artificial ones),
|
|
@@ -19,5 +19,5 @@ export const ToggleColumnsControl = ({ columns, visibleColumns }) => {
|
|
|
19
19
|
*/
|
|
20
20
|
filteredColumns.forEach(col => col.toggleHidden(false));
|
|
21
21
|
}, [someVisibleColums, filteredColumns, visibleColumns]);
|
|
22
|
-
return (_jsx(Popover, { placement: "bottom-start", trigger: _jsx(Button, { kind: "secondary", children: "Toggle columns" }), children: _jsxs(Menu, { children: [_jsx(Menu.ItemCheckbox, { onClick: () => handleToggleAll(), checked: true, icon: visibleColumns.length === 0 ? 'check' : 'minus', children: "Toggle All" }), columns.filter(col => !col.
|
|
22
|
+
return (_jsx(Popover, { placement: "bottom-start", trigger: _jsx(Button, { kind: "secondary", children: "Toggle columns" }), matchTriggerWidth: true, children: _jsxs(Menu, { maxHeight: "350px", children: [_jsx(Menu.ItemCheckbox, { value: "toggle-all", onClick: () => handleToggleAll(), checked: true, icon: visibleColumns.length === 0 ? 'check' : 'minus', children: "Toggle All" }), columns.filter(col => !col.isToggable).map((column, i) => (_jsx(Menu.ItemCheckbox, { value: column.id, autoFocus: i === 0, checked: column.isVisible, icon: column.isVisible ? 'check' : undefined, onClick: () => column.toggleHidden(), children: column.render('Header') }, column.id)))] }) }));
|
|
23
23
|
};
|
|
@@ -2,7 +2,7 @@ import { ComponentType, ReactNode } from 'react';
|
|
|
2
2
|
import { IdType, Row, SortingRule } from 'react-table';
|
|
3
3
|
import { TableHeaderProps } from './table-header';
|
|
4
4
|
import { TablePaginationProps } from './table-pagination';
|
|
5
|
-
import { CustomColumnsType,
|
|
5
|
+
import { CustomColumnsType, OptionalDataTypes, CustomSortingRule, PaginationPageType } from './types';
|
|
6
6
|
export declare type TableProps<T extends Record<string, unknown>> = PropsWithClass & {
|
|
7
7
|
/**
|
|
8
8
|
* Define the columns and headers of the table.
|
|
@@ -16,51 +16,11 @@ export declare type TableProps<T extends Record<string, unknown>> = PropsWithCla
|
|
|
16
16
|
* Define the default visibility of the columns. This is an array of columns `id`,
|
|
17
17
|
*/
|
|
18
18
|
defaultHiddenColumns?: Array<IdType<T>>;
|
|
19
|
-
/**
|
|
20
|
-
* Show pagination below the table. This is recommended only for tables with a lot of rows.
|
|
21
|
-
*/
|
|
22
|
-
showPagination?: boolean;
|
|
23
|
-
/**
|
|
24
|
-
* The amount of entries to show for each page.
|
|
25
|
-
*/
|
|
26
|
-
itemsPerPage?: number;
|
|
27
|
-
/**
|
|
28
|
-
* The index of the page that should be set as active when the table is rendered.
|
|
29
|
-
*/
|
|
30
|
-
activePageIndex?: number;
|
|
31
|
-
/**
|
|
32
|
-
* The callback that is called when the active page index and page size change.
|
|
33
|
-
* Passing this property along side `showPagination` will enable manual pagination,
|
|
34
|
-
* disabling the automatic one.
|
|
35
|
-
*/
|
|
36
|
-
onDataUpdate?: ({ pageIndex, pageSize }: PaginationType) => Promise<void> | void;
|
|
37
|
-
/**
|
|
38
|
-
* Set the number of pages to show in the pagination. Used only when doing manual pagination.
|
|
39
|
-
*/
|
|
40
|
-
totalRows?: number;
|
|
41
|
-
/**
|
|
42
|
-
* Set clusters of items to show in a single page. These values are used to
|
|
43
|
-
* compute the select options for the page size select.
|
|
44
|
-
*/
|
|
45
|
-
pageClusters?: TablePaginationProps['clusters'];
|
|
46
19
|
/**
|
|
47
20
|
* Enable row selection. This property will render an additiona column
|
|
48
21
|
* at the start of the table, containing a checkbox.
|
|
49
22
|
*/
|
|
50
23
|
selectableRows?: boolean;
|
|
51
|
-
/**
|
|
52
|
-
* Callback run when the selected rows change
|
|
53
|
-
*/
|
|
54
|
-
onSelectionChange?: (selectedRows?: Array<Row<T>>, selectedRowIds?: Record<IdType<T>, boolean>) => void;
|
|
55
|
-
/**
|
|
56
|
-
* If true, disable the automatic column sorting of the table. Turn this on if you want to
|
|
57
|
-
* to control the sorting yourself.
|
|
58
|
-
*/
|
|
59
|
-
isManualSorted?: boolean;
|
|
60
|
-
/**
|
|
61
|
-
* Callback run when a column is sorted
|
|
62
|
-
*/
|
|
63
|
-
onSortChange?: (sorting: Array<CustomSortingRule<T>>) => void;
|
|
64
24
|
/**
|
|
65
25
|
* Add an alternate style to the table rows
|
|
66
26
|
*/
|
|
@@ -97,11 +57,11 @@ export declare type TableProps<T extends Record<string, unknown>> = PropsWithCla
|
|
|
97
57
|
/**
|
|
98
58
|
* Set the label for selected items in the table. Default to "Selected items"
|
|
99
59
|
*/
|
|
100
|
-
selectedLabel?: (
|
|
60
|
+
selectedLabel?: (selectedRowIds: Array<Row<T>>) => ReactNode;
|
|
101
61
|
/**
|
|
102
62
|
* Pass custom components to show when rows are selected.
|
|
103
63
|
*/
|
|
104
|
-
selectedActions?: ReactNode;
|
|
64
|
+
selectedActions?: (selectedRows: Array<Row<T>>) => ReactNode;
|
|
105
65
|
/**
|
|
106
66
|
* Set the table height after which the table will scroll.
|
|
107
67
|
*/
|
|
@@ -118,21 +78,51 @@ export declare type TableProps<T extends Record<string, unknown>> = PropsWithCla
|
|
|
118
78
|
* a component.
|
|
119
79
|
*/
|
|
120
80
|
expandableRowComponent?: ComponentType<T>;
|
|
121
|
-
/**
|
|
122
|
-
* A react component that add custom actions to rows. If fuction is passed,
|
|
123
|
-
* the function will be called with the row data and the function must return
|
|
124
|
-
* a component.
|
|
125
|
-
*/
|
|
126
|
-
actionsRowComponent?: ComponentType<Row<T>>;
|
|
127
81
|
/**
|
|
128
82
|
* Custom component/empty state to show when the table has no data or
|
|
129
83
|
* all columns have been toggled off.
|
|
130
84
|
*/
|
|
131
85
|
emptyComponent?: ReactNode;
|
|
132
86
|
/**
|
|
133
|
-
*
|
|
87
|
+
* Show pagination below the table. This is recommended only for tables with a lot of rows.
|
|
88
|
+
*/
|
|
89
|
+
showPagination?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* The index of the page that should be set as active when the table is rendered.
|
|
92
|
+
*/
|
|
93
|
+
initialPageIndex?: number;
|
|
94
|
+
/**
|
|
95
|
+
* The amount of entries to show for each page.
|
|
96
|
+
*/
|
|
97
|
+
itemsPerPage?: number;
|
|
98
|
+
/**
|
|
99
|
+
* Set the number of pages to show in the pagination. Used only when doing manual pagination.
|
|
134
100
|
*/
|
|
101
|
+
totalRows?: number;
|
|
102
|
+
/**
|
|
103
|
+
* Set clusters of items to show in a single page. These values are used to
|
|
104
|
+
* compute the select options for the page size select.
|
|
105
|
+
*/
|
|
106
|
+
pageClusters?: TablePaginationProps['clusters'];
|
|
107
|
+
/**
|
|
108
|
+
* The callback that is called when the active page index and page size change.
|
|
109
|
+
* Passing this property will enable manual pagination,
|
|
110
|
+
* disabling the automatic one.
|
|
111
|
+
*/
|
|
112
|
+
onPaginationChange?: ({ pageIndex, pageSize }: PaginationPageType) => Promise<void> | void;
|
|
113
|
+
/**
|
|
114
|
+
* If true, disable the automatic column sorting of the table. Turn this on if you want to
|
|
115
|
+
* to control the sorting yourself.
|
|
116
|
+
*/
|
|
117
|
+
isManualSorted?: boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Set the initial sorted column and order by passing column id and order.
|
|
120
|
+
*/
|
|
135
121
|
initialSortBy?: Array<SortingRule<T>>;
|
|
122
|
+
/**
|
|
123
|
+
* Callback run when a column is sorted
|
|
124
|
+
*/
|
|
125
|
+
onSortChange?: (sorting: Array<CustomSortingRule<T>>) => void;
|
|
136
126
|
};
|
|
137
|
-
export declare const Table: <T extends Record<string, unknown>>({ className, style, columns, data, selectableRows,
|
|
127
|
+
export declare const Table: <T extends Record<string, unknown>>({ className, style, columns, data, selectableRows, stripes, showSeparators, title, actions, selectedActions, selectedLabel, showHeader, showTableHead, columnsControl, defaultHiddenColumns, height, loading, background, expandableRowComponent, emptyComponent, showPagination, isManualSorted, itemsPerPage, totalRows, initialPageIndex, onPaginationChange, onSortChange, pageClusters, initialSortBy, ...otherProps }: TableProps<T>) => JSX.Element;
|
|
138
128
|
//# sourceMappingURL=table.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../../src/components/table/table.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,aAAa,EAA2B,SAAS,EAClD,MAAM,OAAO,CAAA;AACd,OAAO,EACE,MAAM,EAAE,GAAG,
|
|
1
|
+
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../../src/components/table/table.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,aAAa,EAA2B,SAAS,EAClD,MAAM,OAAO,CAAA;AACd,OAAO,EACE,MAAM,EAAE,GAAG,EAEiB,WAAW,EAC/C,MAAM,aAAa,CAAA;AAcpB,OAAO,EAAe,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAC9D,OAAO,EAAmB,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AAE1E,OAAO,EAC+B,iBAAiB,EACpC,iBAAiB,EAAE,iBAAiB,EAAE,kBAAkB,EAC1E,MAAM,SAAS,CAAA;AAEhB,oBAAY,UAAU,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,cAAc,GAAG;IAC3E;;OAEG;IACH,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAC9B;;OAEG;IACH,IAAI,EAAE,KAAK,CAAC,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC;IACtC;;OAEG;IACH,oBAAoB,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IACxC;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;OAEG;IACH,KAAK,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAClC;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;OAEG;IACH,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB;;OAEG;IACH,aAAa,CAAC,EAAE,CAAC,cAAc,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC;IAC5D;;MAEE;IACH,eAAe,CAAC,EAAE,CAAC,YAAY,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC;IAC7D;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;;OAKG;IACH,sBAAsB,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;IAC1C;;;OAGG;IACH,cAAc,CAAC,EAAE,SAAS,CAAC;IAC3B;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IACzB;;OAEG;IACJ,YAAY,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACJ,SAAS,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACJ,YAAY,CAAC,EAAE,oBAAoB,CAAC,UAAU,CAAC,CAAC;IAC/C;;;;OAIG;IACJ,kBAAkB,CAAC,EAAE,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,kBAAkB,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC3F;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACxB;;MAEE;IACH,aAAa,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IACrC;;OAEG;IACJ,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;CAC/D,CAAA;AAED,eAAO,MAAM,KAAK,geA6VjB,CAAA"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import clsx from 'clsx';
|
|
3
|
-
import {
|
|
4
|
-
import { Fragment, useEffect, useMemo } from 'react';
|
|
3
|
+
import { domMax, LazyMotion, m, AnimatePresence } from 'framer-motion';
|
|
4
|
+
import { Fragment, useCallback, useEffect, useMemo } from 'react';
|
|
5
5
|
import { useExpanded, usePagination, useRowSelect, useSortBy, useTable } from 'react-table';
|
|
6
6
|
import { useUIDSeed } from 'react-uid';
|
|
7
|
+
import { useUpdateEffect } from 'ahooks';
|
|
7
8
|
import { Skeleton, Stack, Text, ToggleButton } from '../..';
|
|
8
9
|
import styles from './table.module.css';
|
|
9
10
|
import { TableCell } from './table-cell';
|
|
@@ -13,21 +14,32 @@ import { TableExpand } from './table-expand';
|
|
|
13
14
|
import { TableHeader } from './table-header';
|
|
14
15
|
import { TablePagination } from './table-pagination';
|
|
15
16
|
import { TableRow } from './table-row';
|
|
16
|
-
export const Table = ({ className, style, columns, data = [], selectableRows,
|
|
17
|
+
export const Table = ({ className, style, columns, data = [], selectableRows, stripes, showSeparators = true, title, actions, selectedActions, selectedLabel = selectedRows => `Selected items: ${selectedRows.length}`, showHeader = false, showTableHead = true, columnsControl = false, defaultHiddenColumns, height, loading, background, expandableRowComponent, emptyComponent, showPagination, isManualSorted, itemsPerPage = 10, totalRows, initialPageIndex = 0, onPaginationChange, onSortChange, pageClusters, initialSortBy = [], ...otherProps }) => {
|
|
17
18
|
const uid = useUIDSeed();
|
|
18
19
|
const hasSomeExpandableRows = useMemo(() => data.some(d => d.subRows), [data]);
|
|
19
|
-
const isManualPaginated = useMemo(() => Boolean(
|
|
20
|
-
const
|
|
20
|
+
const isManualPaginated = useMemo(() => Boolean(showPagination && onPaginationChange && totalRows), [showPagination, totalRows, onPaginationChange]);
|
|
21
|
+
const manualPaginationPageCount = useMemo(() => (isManualPaginated && totalRows) ? Math.ceil(totalRows / itemsPerPage) : -1, [isManualPaginated, totalRows, itemsPerPage]);
|
|
22
|
+
const getHiddenColumns = useCallback(() => {
|
|
23
|
+
const hiddenColumns = defaultHiddenColumns ? [...defaultHiddenColumns] : [];
|
|
24
|
+
if (!selectableRows)
|
|
25
|
+
hiddenColumns.push('selection');
|
|
26
|
+
if (!hasSomeExpandableRows)
|
|
27
|
+
hiddenColumns.push('expander');
|
|
28
|
+
return hiddenColumns;
|
|
29
|
+
}, [defaultHiddenColumns, selectableRows, hasSomeExpandableRows]);
|
|
30
|
+
const getRowId = useCallback((originalRow, relativeIndex, parent) => originalRow?._id || (parent && [parent.id, relativeIndex].join('.')) || relativeIndex.toString(), []);
|
|
31
|
+
const { getTableProps, getTableBodyProps, headerGroups, rows, page, pageCount, gotoPage, allColumns, prepareRow, visibleColumns, setPageSize, setHiddenColumns, selectedFlatRows, state: { pageSize, pageIndex, sortBy } } = useTable({
|
|
21
32
|
columns,
|
|
22
33
|
data,
|
|
34
|
+
getRowId,
|
|
35
|
+
expandSubRows: Boolean(!expandableRowComponent),
|
|
36
|
+
manualPagination: isManualPaginated,
|
|
37
|
+
pageCount: manualPaginationPageCount,
|
|
23
38
|
manualSortBy: isManualSorted,
|
|
24
39
|
disableMultiSort: true,
|
|
25
|
-
expandSubRows: Boolean(!expandableRowComponent),
|
|
26
40
|
autoResetHiddenColumns: false,
|
|
27
41
|
autoResetPage: false,
|
|
28
|
-
|
|
29
|
-
autoResetSelectedRows: false,
|
|
30
|
-
pageCount: (isManualPaginated && totalRows) ? Math.ceil(totalRows / itemsPerPage) : 10,
|
|
42
|
+
autoResetSortBy: false,
|
|
31
43
|
/**
|
|
32
44
|
* This `paginateExpandedRows` prop prevent expanded rows to
|
|
33
45
|
* be placed in the next page. But it breaks row selection
|
|
@@ -35,101 +47,89 @@ export const Table = ({ className, style, columns, data = [], selectableRows, on
|
|
|
35
47
|
*/
|
|
36
48
|
initialState: {
|
|
37
49
|
sortBy: initialSortBy,
|
|
38
|
-
pageIndex:
|
|
39
|
-
pageSize: showPagination ? itemsPerPage :
|
|
40
|
-
hiddenColumns:
|
|
50
|
+
pageIndex: initialPageIndex,
|
|
51
|
+
pageSize: showPagination ? itemsPerPage : data.length,
|
|
52
|
+
hiddenColumns: getHiddenColumns()
|
|
41
53
|
}
|
|
42
54
|
}, useSortBy, useExpanded, usePagination, useRowSelect, (hooks) => {
|
|
43
55
|
const checkboxColumn = [{
|
|
44
56
|
id: 'selection',
|
|
45
57
|
isCollapsed: true,
|
|
46
|
-
|
|
47
|
-
Header: ({
|
|
58
|
+
isToggable: true,
|
|
59
|
+
Header: ({ getToggleAllPageRowsSelectedProps }) => (!loading ? _jsx(TableCheckbox, { ...getToggleAllPageRowsSelectedProps() }) : null),
|
|
48
60
|
Cell: ({ row }) => _jsx(TableCheckbox, { ...row.getToggleRowSelectedProps() })
|
|
49
61
|
}];
|
|
50
62
|
const expanderColumn = [{
|
|
51
63
|
id: 'expander',
|
|
52
|
-
|
|
64
|
+
isToggable: true,
|
|
53
65
|
expander: true,
|
|
54
66
|
minWidth: 40,
|
|
55
67
|
align: 'center',
|
|
56
68
|
Cell: ({ row }) => (row.canExpand
|
|
57
|
-
? (_jsx(ToggleButton, { kind: "
|
|
69
|
+
? (_jsx(ToggleButton, { kind: "flat", dimension: "small", restingIcon: "chevron-right", pressedIcon: "chevron-down", ...row.getToggleRowExpandedProps(), onClick: () => {
|
|
58
70
|
const subRowsExpanded = row.subRows.filter(r => r.isExpanded);
|
|
59
71
|
subRowsExpanded.forEach(r => r.toggleRowExpanded(!r.isExpanded));
|
|
60
72
|
row.toggleRowExpanded(!row.isExpanded);
|
|
61
73
|
} }))
|
|
62
74
|
: null)
|
|
63
75
|
}];
|
|
64
|
-
const actionsColumn = [{
|
|
65
|
-
id: 'actions',
|
|
66
|
-
isCollapsed: true,
|
|
67
|
-
hideFromList: true,
|
|
68
|
-
Cell: ({ row }) => (ActionsRowComponent ? _jsx(ActionsRowComponent, { ...row }) : null)
|
|
69
|
-
}];
|
|
70
76
|
hooks.visibleColumns.push(columns => [
|
|
71
77
|
...checkboxColumn,
|
|
72
78
|
...expanderColumn,
|
|
73
|
-
...actionsColumn,
|
|
74
79
|
...columns
|
|
75
80
|
]);
|
|
76
81
|
});
|
|
77
|
-
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
artificialColumns.push('selection');
|
|
81
|
-
if (!hasSomeExpandableRows)
|
|
82
|
-
artificialColumns.push('expander');
|
|
83
|
-
if (!ActionsRowComponent)
|
|
84
|
-
artificialColumns.push('actions');
|
|
85
|
-
setHiddenColumns(artificialColumns);
|
|
82
|
+
useUpdateEffect(() => {
|
|
83
|
+
const hiddenColumns = getHiddenColumns();
|
|
84
|
+
setHiddenColumns(hiddenColumns);
|
|
86
85
|
}, [
|
|
87
|
-
selectableRows,
|
|
88
86
|
setHiddenColumns,
|
|
89
|
-
|
|
90
|
-
hasSomeExpandableRows,
|
|
91
|
-
ActionsRowComponent
|
|
87
|
+
getHiddenColumns
|
|
92
88
|
]);
|
|
93
|
-
|
|
94
|
-
onSelectionChange?.(selectedFlatRows, selectedRowIds);
|
|
95
|
-
}, [onSelectionChange, selectedFlatRows, selectedRowIds]);
|
|
96
|
-
useEffect(() => {
|
|
89
|
+
useUpdateEffect(() => {
|
|
97
90
|
onSortChange?.(sortBy);
|
|
98
91
|
}, [onSortChange, sortBy]);
|
|
92
|
+
useUpdateEffect(() => {
|
|
93
|
+
onPaginationChange?.({ pageIndex, pageSize });
|
|
94
|
+
}, [onPaginationChange, pageIndex, pageSize]);
|
|
99
95
|
useEffect(() => {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
96
|
+
if (pageIndex >= pageCount) {
|
|
97
|
+
gotoPage(0);
|
|
98
|
+
}
|
|
99
|
+
}, [pageCount, pageIndex, gotoPage]);
|
|
100
|
+
const rowEntries = useMemo(() => {
|
|
101
|
+
return (showPagination ? page : rows);
|
|
102
|
+
}, [page, rows, showPagination]);
|
|
103
|
+
const filteredVisibleColumns = useMemo(() => (visibleColumns.filter((col) => !col.isToggable)), [visibleColumns]);
|
|
104
104
|
const expandedRows = useMemo(() => rows.filter(row => row.canExpand && row.isExpanded).map(r => r.id), [rows]);
|
|
105
105
|
const dynamicStyle = {
|
|
106
106
|
'--table-height': height,
|
|
107
107
|
'--table-background': background
|
|
108
108
|
};
|
|
109
|
-
return (_jsxs("div", { className: clsx(styles.Table, className), style: { ...dynamicStyle, ...style }, children: [
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
109
|
+
return (_jsxs("div", { className: clsx(styles.Table, className), style: { ...dynamicStyle, ...style }, children: [_jsx(AnimatePresence, { children: _jsxs(LazyMotion, { features: domMax, children: [!!selectedFlatRows.length && selectableRows && (_jsxs(Stack, { as: m.div, className: styles.Toast, direction: "row", hAlign: "space-between", vAlign: "center", hPadding: 16, vPadding: 8, fill: false, columnGap: 16, initial: { y: '-16px', opacity: 0 }, animate: {
|
|
110
|
+
y: 0,
|
|
111
|
+
opacity: 1,
|
|
112
|
+
transition: {
|
|
113
|
+
type: 'spring',
|
|
114
|
+
stiffness: 700,
|
|
115
|
+
damping: 30
|
|
116
|
+
}
|
|
117
|
+
}, exit: { y: '-16px', opacity: 0 }, children: [_jsx(Text, { as: "span", size: 14, weight: "bold", children: selectedLabel(selectedFlatRows) }), selectedActions?.(selectedFlatRows)] })), (showHeader || selectableRows) && (_jsx(m.div, { animate: {
|
|
118
|
+
y: selectedFlatRows.length ? 20 : 0,
|
|
119
|
+
opacity: selectedFlatRows.length ? 0 : 1,
|
|
120
|
+
transition: {
|
|
121
|
+
type: 'spring',
|
|
122
|
+
stiffness: 700,
|
|
123
|
+
damping: 30
|
|
124
|
+
}
|
|
125
|
+
}, children: _jsxs(TableHeader, { title: title, children: [(columnsControl && data.length)
|
|
126
|
+
? (_jsx(ToggleColumnsControl, { columns: allColumns, visibleColumns: filteredVisibleColumns }))
|
|
127
|
+
: null, actions] }) }))] }) }), ((data.length || loading) && filteredVisibleColumns.length)
|
|
128
128
|
? (_jsx("div", { className: styles.TableWrapper, "data-table-scrolling": Boolean(height), children: _jsxs("table", { className: styles.TableElement, "data-table-stripes": stripes, "data-table-separators": showSeparators, "data-table-loading": loading, "aria-labelledby": uid('table-title'), ...getTableProps(), ...otherProps, children: [showTableHead && (_jsx("thead", { role: "rowgroup", className: styles.THead, children: headerGroups.map(headerGroup => (_jsx(TableRow, { ...headerGroup.getHeaderGroupProps(), children: headerGroup.headers.map((column) => (_jsx(TableCell, { as: "th", width: column.minWidth === 0 ? undefined : column.minWidth, collapsed: column.isCollapsed, isSorted: column.isSorted, isSortedDesc: column.isSorted && column.isSortedDesc, align: column.align, ...column.getHeaderProps(column.getSortByToggleProps()), children: column.render('Header') }))) }))) })), _jsx("tbody", { role: "rowgroup", className: styles.TBody, ...getTableBodyProps(), children: loading
|
|
129
129
|
? (_jsx(TableRow, { children: _jsx(TableCell, { colSpan: 100, children: _jsx(Skeleton, { gap: 16, height: 24, count: 10 }) }) }))
|
|
130
130
|
: rowEntries.map((row) => {
|
|
131
131
|
prepareRow(row);
|
|
132
132
|
return (_jsxs(Fragment, { children: [_jsx(TableRow, { ...row.getRowProps(), expanded: (row.isExpanded && !row.subRows.some(subrow => subrow.isExpanded && subrow.canExpand)), rowData: row, expandedRows: expandedRows, children: row.cells.map((cell) => (_jsx(TableCell, { collapsed: cell.column.isCollapsed, width: cell.column.minWidth === 0 ? undefined : cell.column.minWidth, align: cell.column.align, ...cell.getCellProps(), children: cell.render('Cell') }))) }), (row.subRows && row.isExpanded && expandableRowComponent) && row.subRows.map(subRow => (_jsx(TableRow, { "data-table-row-expander": true, children: _jsx(TableCell, { padding: false, colSpan: 100, children: _jsx(TableExpand, { data: subRow.original, component: expandableRowComponent }) }) }, subRow.id)))] }, row.id));
|
|
133
133
|
}) })] }) }))
|
|
134
|
-
: (_jsx(Stack, { vAlign: "center", hAlign: "center", children: emptyComponent ?? 'No data' })), (showPagination && filteredVisibleColumns.length > 0 && !!rows.length) && (_jsx(TablePagination, { clusters: pageClusters, pageSize: pageSize, totalItems: totalRows ?? rows.length, currentPage: pageIndex, totalPages: pageCount, isManual: Boolean(isManualPaginated && totalRows), onPageSizeChange:
|
|
134
|
+
: (_jsx(Stack, { vAlign: "center", hAlign: "center", children: emptyComponent ?? 'No data' })), (showPagination && filteredVisibleColumns.length > 0 && !!rows.length) && (_jsx(TablePagination, { clusters: pageClusters, pageSize: pageSize, totalItems: totalRows ?? rows.length, currentPage: pageIndex, totalPages: pageCount, isManual: Boolean(isManualPaginated && totalRows), onPageSizeChange: setPageSize, onPageClick: selected => gotoPage(selected) }))] }));
|
|
135
135
|
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import { Column, ColumnInstance, CustomCell, CustomHeaderGroup } from 'react-table';
|
|
3
|
-
export declare type
|
|
3
|
+
export declare type PaginationPageType = {
|
|
4
4
|
pageIndex: number;
|
|
5
5
|
pageSize: number;
|
|
6
6
|
};
|
|
7
7
|
export declare type OptionalColumnTypes = {
|
|
8
8
|
isCollapsed?: boolean;
|
|
9
9
|
align?: 'start' | 'center' | 'end';
|
|
10
|
-
|
|
10
|
+
isToggable?: boolean;
|
|
11
11
|
expander?: boolean;
|
|
12
12
|
};
|
|
13
13
|
export declare type OptionalDataTypes<T> = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/components/table/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EACL,MAAM,EAAE,cAAc,EACtB,UAAU,EACV,iBAAiB,EAClB,MAAM,aAAa,CAAA;AAEpB,oBAAY,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/components/table/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EACL,MAAM,EAAE,cAAc,EACtB,UAAU,EACV,iBAAiB,EAClB,MAAM,aAAa,CAAA;AAEpB,oBAAY,kBAAkB,GAAG;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAA;AAED,oBAAY,mBAAmB,GAAG;IAChC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,KAAK,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,KAAK,CAAC;IACnC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAA;AAED,oBAAY,iBAAiB,CAAC,CAAC,IAAI;IACjC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC;IACd,OAAO,CAAC,EAAE,SAAS,GAAG,SAAS,EAAE,CAAC;CACnC,CAAA;AAED,oBAAY,eAAe,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,iBAAiB,CAAC,CAAC,EAAE,mBAAmB,CAAC,CAAA;AAC1G,oBAAY,QAAQ,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,UAAU,CAAC,CAAC,EAAE,mBAAmB,CAAC,CAAA;AAC5F,oBAAY,iBAAiB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,mBAAmB,CAAC,CAAA;AACzG,oBAAY,wBAAwB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,cAAc,CAAC,CAAC,CAAC,GAAG,mBAAmB,CAAA;AACjH,oBAAY,iBAAiB,CAAC,CAAC,IAAI;IACjC,EAAE,EAAE,MAAM,CAAC,CAAC;IACZ,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
.BaseField{-webkit-appearance:none;appearance:none;background-color:var(--global-background);block-size:var(--field-height);border:1px solid var(--dimmed-2);border-radius:.22rem;box-sizing:border-box;caret-color:var(--cta-default);color:inherit;display:flex;font-family:inherit;font-size:var(--font-size);inline-size:100%;line-height:1;margin:0;outline-offset:2px;overflow:hidden;padding:0 var(--field-padding);text-overflow:ellipsis}[data-textfield-has-icon=true] .BaseField::-webkit-calendar-picker-indicator{opacity:0;position:absolute;right:calc(var(--field-padding)/2)}.BaseField:-moz-ui-invalid{box-shadow:none}.BaseField::placeholder{color:var(--dimmed-5)}.BaseField:focus-visible{border-color:var(--dimmed-5)}.BaseField:disabled{background:linear-gradient(to bottom,var(--global-disabled-background),var(--global-disabled-background));border-color:transparent;color:var(--global-disabled-foreground);cursor:not-allowed}.BaseField:disabled::placeholder{color:var(--dimmed-6)}.BaseField[readonly]{border-style:dashed;box-shadow:none;cursor:default}.BaseField:-webkit-autofill,.BaseField:-webkit-autofill:active,.BaseField:-webkit-autofill:focus,.BaseField:-webkit-autofill:hover{-webkit-text-fill-color:var(--global-vibrancy-foreground);border:1px solid var(--dimmed-2);box-shadow:0 0 0 100px var(--global-background) inset}:is(.BaseField:-webkit-autofill,.BaseField:-webkit-autofill:hover,.BaseField:-webkit-autofill:focus,.BaseField:-webkit-autofill:active)::selection{-webkit-text-fill-color:var(--dimmed-0)}.BaseField:is(:invalid,[data-basefield-invalid=true],:out-of-range),.BaseField:is(:invalid,[data-basefield-invalid=true],:out-of-range):focus-visible{border-color:var(--highlight-red-foreground)}.BaseField[type=number]{-webkit-appearance:textfield;appearance:textfield}.BaseField[type=number]::-webkit-inner-spin-button,.BaseField[type=number]::-webkit-outer-spin-button{display:none}.BaseField[type=search]{-webkit-appearance:none;appearance:none}.BaseField[type=search]::-webkit-search-cancel-button,.BaseField[type=search]::-webkit-search-decoration{-webkit-appearance:none;appearance:none}textarea.BaseField{block-size:auto;line-height:1.5;min-block-size:1.78rem;padding:calc(var(--field-padding)/2) calc(var(--field-padding) + .89rem) calc(var(--field-padding)/2) var(--field-padding);resize:vertical}textarea.BaseField::-webkit-datetime-edit-text{opacity:.3}textarea.BaseField::-webkit-calendar-picker-indicator{color:var(--global-foreground)}textarea.BaseField:-moz-ui-invalid{box-shadow:none}textarea.BaseField::-webkit-calendar-picker-indicator
|
|
1
|
+
.BaseField{-webkit-appearance:none;appearance:none;background-color:var(--global-background);block-size:var(--field-height);border:1px solid var(--dimmed-2);border-radius:.22rem;box-sizing:border-box;caret-color:var(--cta-default);color:inherit;display:flex;font-family:inherit;font-size:var(--font-size);inline-size:100%;line-height:1;margin:0;outline-offset:2px;overflow:hidden;padding:0 var(--field-padding);text-overflow:ellipsis}[data-textfield-has-icon=true] .BaseField::-webkit-calendar-picker-indicator{opacity:0;position:absolute;right:calc(var(--field-padding)/2)}.BaseField:-moz-ui-invalid{box-shadow:none}.BaseField::placeholder{color:var(--dimmed-5)}.BaseField:focus-visible{border-color:var(--dimmed-5)}.BaseField:disabled{background:linear-gradient(to bottom,var(--global-disabled-background),var(--global-disabled-background));border-color:transparent;color:var(--global-disabled-foreground);cursor:not-allowed}.BaseField:disabled::placeholder{color:var(--dimmed-6)}.BaseField[readonly]{border-style:dashed;box-shadow:none;cursor:default}.BaseField:-webkit-autofill,.BaseField:-webkit-autofill:active,.BaseField:-webkit-autofill:focus,.BaseField:-webkit-autofill:hover{-webkit-text-fill-color:var(--global-vibrancy-foreground);border:1px solid var(--dimmed-2);box-shadow:0 0 0 100px var(--global-background) inset}:is(.BaseField:-webkit-autofill,.BaseField:-webkit-autofill:hover,.BaseField:-webkit-autofill:focus,.BaseField:-webkit-autofill:active)::selection{-webkit-text-fill-color:var(--dimmed-0)}.BaseField:is(:invalid,[data-basefield-invalid=true],:out-of-range),.BaseField:is(:invalid,[data-basefield-invalid=true],:out-of-range):focus-visible{border-color:var(--highlight-red-foreground)}.BaseField[type=number]{-webkit-appearance:textfield;appearance:textfield}.BaseField[type=number]::-webkit-inner-spin-button,.BaseField[type=number]::-webkit-outer-spin-button{display:none}.BaseField[type=search]{-webkit-appearance:none;appearance:none}.BaseField[type=search]::-webkit-search-cancel-button,.BaseField[type=search]::-webkit-search-decoration{-webkit-appearance:none;appearance:none}textarea.BaseField{block-size:auto;line-height:1.5;min-block-size:1.78rem;padding:calc(var(--field-padding)/2) calc(var(--field-padding) + .89rem) calc(var(--field-padding)/2) var(--field-padding);resize:vertical}textarea.BaseField::-webkit-datetime-edit-text{opacity:.3}textarea.BaseField::-webkit-calendar-picker-indicator{color:var(--global-foreground)}textarea.BaseField:-moz-ui-invalid{box-shadow:none}textarea.BaseField:hover::-webkit-calendar-picker-indicator{background-color:transparent}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toggle-button.d.ts","sourceRoot":"","sources":["../../../src/components/toggle-button/toggle-button.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,WAAW,EAAmB,MAAM,cAAc,CAAA;AAExF,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAGlC,oBAAY,iBAAiB,GAAG,MAAM,CAAC,eAAe,EAAE,MAAM,CAAC,GAAG;IAChE;;OAEG;IACH,WAAW,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;IACrC;;OAEG;IACH,WAAW,CAAC,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;IACtC;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAA;AAED,aAAK,uBAAuB,GAAG,WAAW,CAAC,mBAAmB,CAC5D,WAAW,CAAC,gBAAgB,CAAC,OAAO,UAAU,CAAC,EAC/C,WAAW,CAAC,QAAQ,CAAC,OAAO,UAAU,CAAC,GAAG,iBAAiB,CAC5D,CAAC;AAqBF,eAAO,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"toggle-button.d.ts","sourceRoot":"","sources":["../../../src/components/toggle-button/toggle-button.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,WAAW,EAAmB,MAAM,cAAc,CAAA;AAExF,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAGlC,oBAAY,iBAAiB,GAAG,MAAM,CAAC,eAAe,EAAE,MAAM,CAAC,GAAG;IAChE;;OAEG;IACH,WAAW,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;IACrC;;OAEG;IACH,WAAW,CAAC,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;IACtC;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAA;AAED,aAAK,uBAAuB,GAAG,WAAW,CAAC,mBAAmB,CAC5D,WAAW,CAAC,gBAAgB,CAAC,OAAO,UAAU,CAAC,EAC/C,WAAW,CAAC,QAAQ,CAAC,OAAO,UAAU,CAAC,GAAG,iBAAiB,CAC5D,CAAC;AAqBF,eAAO,MAAM,YAAY,yBA8EI,CAAA"}
|
|
@@ -3,7 +3,7 @@ import { forwardRef, useCallback, useEffect, useState } from 'react';
|
|
|
3
3
|
import styles from './toggle-button.module.css';
|
|
4
4
|
import { IconButton, Icon } from '../..';
|
|
5
5
|
import clsx from 'clsx';
|
|
6
|
-
import {
|
|
6
|
+
import { domMax, LazyMotion, m } from 'framer-motion';
|
|
7
7
|
const scaleAnimation = {
|
|
8
8
|
scaleIn: {
|
|
9
9
|
scale: 1,
|
|
@@ -40,7 +40,7 @@ export const ToggleButton = forwardRef(({ className, restingIcon, pressedIcon, d
|
|
|
40
40
|
};
|
|
41
41
|
return (_jsx(Icon, { source: icon, dimension: iconSize[dimension] }));
|
|
42
42
|
}, []);
|
|
43
|
-
return (_jsx(IconButton, { as: "button", ref: forwardedRef, dimension: dimension, "aria-pressed": isPressed, kind: kind, disabled: disabled, onClick: handleClick, className: clsx(styles.ToggleButton, className), ...otherProps, children: isPressed && pressedIcon
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
return (_jsx(IconButton, { as: "button", ref: forwardedRef, dimension: dimension, "aria-pressed": isPressed, kind: kind, disabled: disabled, onClick: handleClick, className: clsx(styles.ToggleButton, className), ...otherProps, children: _jsx(LazyMotion, { features: domMax, strict: true, children: isPressed && pressedIcon
|
|
44
|
+
? (_jsx(m.span, { variants: scaleAnimation, initial: firstRender && isPressed ? false : 'scaleOut', animate: "scaleIn", children: renderIcon(pressedIcon, dimension) }, "pressedIcon"))
|
|
45
|
+
: restingIcon && (_jsx(m.span, { variants: scaleAnimation, initial: firstRender && !isPressed ? false : 'scaleOut', animate: "scaleIn", children: renderIcon(restingIcon, dimension) }, "restingIcon")) }) }));
|
|
46
46
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wonderflow/react-components",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.2.0",
|
|
4
4
|
"description": "UI components from Wonderflow's Wanda design system",
|
|
5
5
|
"author": "Wonderflow",
|
|
6
6
|
"license": "MIT",
|
|
@@ -56,24 +56,24 @@
|
|
|
56
56
|
"react-dom": "^17.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@babel/core": "7.17.
|
|
59
|
+
"@babel/core": "7.17.9",
|
|
60
60
|
"@babel/preset-typescript": "7.16.7",
|
|
61
|
-
"@storybook/addon-actions": "6.4.
|
|
62
|
-
"@storybook/addon-essentials": "6.4.
|
|
63
|
-
"@storybook/addon-links": "6.4.
|
|
61
|
+
"@storybook/addon-actions": "6.4.22",
|
|
62
|
+
"@storybook/addon-essentials": "6.4.22",
|
|
63
|
+
"@storybook/addon-links": "6.4.22",
|
|
64
64
|
"@storybook/addon-postcss": "2.0.0",
|
|
65
65
|
"@storybook/addons": "6.5.0-alpha.21",
|
|
66
66
|
"@storybook/builder-webpack5": "6.5.0-alpha.21",
|
|
67
67
|
"@storybook/manager-webpack5": "6.5.0-alpha.21",
|
|
68
|
-
"@storybook/react": "6.4.
|
|
68
|
+
"@storybook/react": "6.4.22",
|
|
69
69
|
"@storybook/theming": "6.5.0-alpha.21",
|
|
70
70
|
"@types/react": "17.0.43",
|
|
71
71
|
"@types/react-dom": "17.0.14",
|
|
72
|
-
"@types/react-table": "7.7.
|
|
72
|
+
"@types/react-table": "7.7.11",
|
|
73
73
|
"@wonderflow/config": "*",
|
|
74
74
|
"@wonderflow/stylelint-config": "1.1.4",
|
|
75
75
|
"@wonderflow/tokens": "*",
|
|
76
|
-
"babel-loader": "8.2.
|
|
76
|
+
"babel-loader": "8.2.5",
|
|
77
77
|
"cpy-cli": "3.1.1",
|
|
78
78
|
"postcss": "8.4.12",
|
|
79
79
|
"postcss-cli": "9.1.0",
|
|
@@ -86,16 +86,17 @@
|
|
|
86
86
|
"typescript-plugin-css-modules": "3.4.0"
|
|
87
87
|
},
|
|
88
88
|
"dependencies": {
|
|
89
|
-
"
|
|
89
|
+
"@radix-ui/react-tabs": "0.1.5",
|
|
90
|
+
"ahooks": "3.3.10",
|
|
90
91
|
"clsx": "1.1.1",
|
|
91
|
-
"framer-motion": "6.2
|
|
92
|
+
"framer-motion": "6.3.2",
|
|
92
93
|
"react-focus-on": "3.5.4",
|
|
93
94
|
"react-masonry-css": "1.0.16",
|
|
94
|
-
"react-paginate": "8.1.
|
|
95
|
+
"react-paginate": "8.1.3",
|
|
95
96
|
"react-popper-tooltip": "4.3.1",
|
|
96
|
-
"react-roving-tabindex": "3.
|
|
97
|
+
"react-roving-tabindex": "3.2.0",
|
|
97
98
|
"react-table": "7.7.0",
|
|
98
|
-
"react-uid": "2.3.
|
|
99
|
-
"type-fest": "2.12.
|
|
99
|
+
"react-uid": "2.3.2",
|
|
100
|
+
"type-fest": "2.12.2"
|
|
100
101
|
}
|
|
101
102
|
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { FC } from 'react';
|
|
2
|
-
interface TabsProps {
|
|
3
|
-
state: [number, React.Dispatch<React.SetStateAction<number>>];
|
|
4
|
-
}
|
|
5
|
-
export declare const Tabs: FC<TabsProps>;
|
|
6
|
-
export declare const useTabState: (children: React.ReactNode) => {
|
|
7
|
-
isActive: boolean;
|
|
8
|
-
onClick: () => void;
|
|
9
|
-
};
|
|
10
|
-
export declare const usePanelState: (children: React.ReactNode) => boolean;
|
|
11
|
-
export {};
|
|
12
|
-
//# sourceMappingURL=primitive-tab.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"primitive-tab.d.ts","sourceRoot":"","sources":["../../../src/components/tab/primitive-tab.tsx"],"names":[],"mappings":"AAAA,OAAO,EAKL,EAAE,EACH,MAAM,OAAO,CAAA;AAed,UAAU,SAAS;IACjB,KAAK,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;CAC9D;AAED,eAAO,MAAM,IAAI,EAAE,EAAE,CAAC,SAAS,CAU9B,CAAA;AAED,eAAO,MAAM,WAAW,aAAc,MAAM,SAAS;;;CA+BpD,CAAA;AAED,eAAO,MAAM,aAAa,aAAc,MAAM,SAAS,YAiBtD,CAAA"}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { createContext, useState, useMemo, useContext } from 'react';
|
|
3
|
-
import useConstant from './use-constant';
|
|
4
|
-
const TabsState = createContext([]);
|
|
5
|
-
const Elements = createContext({
|
|
6
|
-
tabs: [],
|
|
7
|
-
panels: []
|
|
8
|
-
});
|
|
9
|
-
export const Tabs = ({ state: outerState, children }) => {
|
|
10
|
-
const innerState = useState(0);
|
|
11
|
-
const elements = useConstant(() => ({ tabs: [], panels: [] }));
|
|
12
|
-
const state = outerState || innerState;
|
|
13
|
-
return (_jsx(Elements.Provider, { value: elements, children: _jsx(TabsState.Provider, { value: state, children: children }) }));
|
|
14
|
-
};
|
|
15
|
-
export const useTabState = (children) => {
|
|
16
|
-
const [activeIndex, setActive] = useContext(TabsState);
|
|
17
|
-
const elements = useContext(Elements);
|
|
18
|
-
const tabIndex = useConstant(() => {
|
|
19
|
-
const currentIndex = elements.tabs.length;
|
|
20
|
-
const childrenIndex = elements.tabs.indexOf(children);
|
|
21
|
-
const isChildrenUnique = !elements.tabs.includes(children);
|
|
22
|
-
if (isChildrenUnique) {
|
|
23
|
-
elements.tabs.push(children);
|
|
24
|
-
}
|
|
25
|
-
return isChildrenUnique ? currentIndex : childrenIndex;
|
|
26
|
-
});
|
|
27
|
-
const onClick = useConstant(() => () => {
|
|
28
|
-
if (setActive) {
|
|
29
|
-
setActive(tabIndex);
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
const state = useMemo(() => ({
|
|
33
|
-
isActive: activeIndex === tabIndex,
|
|
34
|
-
onClick
|
|
35
|
-
}), [activeIndex, onClick, tabIndex]);
|
|
36
|
-
return state;
|
|
37
|
-
};
|
|
38
|
-
export const usePanelState = (children) => {
|
|
39
|
-
const [activeIndex] = useContext(TabsState);
|
|
40
|
-
const elements = useContext(Elements);
|
|
41
|
-
const panelIndex = useConstant(() => {
|
|
42
|
-
const currentIndex = elements.panels.length;
|
|
43
|
-
const childrenIndex = elements.panels.indexOf(children);
|
|
44
|
-
const isChildrenUnique = !elements.panels.includes(children);
|
|
45
|
-
if (isChildrenUnique) {
|
|
46
|
-
elements.panels.push(children);
|
|
47
|
-
}
|
|
48
|
-
return isChildrenUnique ? currentIndex : childrenIndex;
|
|
49
|
-
});
|
|
50
|
-
return panelIndex === activeIndex;
|
|
51
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { ButtonHTMLAttributes } from 'react';
|
|
2
|
-
import { IconProps } from '../..';
|
|
3
|
-
/**
|
|
4
|
-
* Tab.Item
|
|
5
|
-
* Public api
|
|
6
|
-
*/
|
|
7
|
-
export declare type TabItemProps = ButtonHTMLAttributes<HTMLButtonElement> & {
|
|
8
|
-
/**
|
|
9
|
-
* An optional icon to show beside the tab label.
|
|
10
|
-
*/
|
|
11
|
-
icon?: IconProps['source'];
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* Tab.Item
|
|
15
|
-
* Component
|
|
16
|
-
*/
|
|
17
|
-
export declare const TabItem: import("react").ForwardRefExoticComponent<ButtonHTMLAttributes<HTMLButtonElement> & {
|
|
18
|
-
/**
|
|
19
|
-
* An optional icon to show beside the tab label.
|
|
20
|
-
*/
|
|
21
|
-
icon?: import("packages/icons/dist").IconNames | import("react").ReactElement<HTMLOrSVGElement, string | import("react").JSXElementConstructor<any>> | undefined;
|
|
22
|
-
} & import("react").RefAttributes<HTMLButtonElement>>;
|
|
23
|
-
//# sourceMappingURL=tab-item.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tab-item.d.ts","sourceRoot":"","sources":["../../../src/components/tab/tab-item.tsx"],"names":[],"mappings":"AAAA,OAAO,EAGL,oBAAoB,EAErB,MAAM,OAAO,CAAA;AAId,OAAO,EAAe,SAAS,EAAE,MAAM,cAAc,CAAA;AAKrD;;;GAGG;AACH,oBAAY,YAAY,GAAG,oBAAoB,CAAC,iBAAiB,CAAC,GAAG;IACnE;;OAEG;IACH,IAAI,CAAC,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC;CAC5B,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,OAAO;IAVlB;;OAEG;;qDA8DH,CAAA"}
|