@fluentui/react-table 9.0.0-alpha.1 → 9.0.0-alpha.3
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/CHANGELOG.json +168 -4
- package/CHANGELOG.md +43 -5
- package/dist/index.d.ts +318 -21
- package/lib/TableCellActions.js +2 -0
- package/lib/TableCellActions.js.map +1 -0
- package/lib/TableCellLayout.js +2 -0
- package/lib/TableCellLayout.js.map +1 -0
- package/lib/TableCellPrimaryLayout.js +2 -0
- package/lib/TableCellPrimaryLayout.js.map +1 -0
- package/lib/TableSelectionCell.js +2 -0
- package/lib/TableSelectionCell.js.map +1 -0
- package/lib/components/Table/Table.types.js.map +1 -1
- package/lib/components/Table/useTableContextValues.js +7 -5
- package/lib/components/Table/useTableContextValues.js.map +1 -1
- package/lib/components/Table/useTableStyles.js +7 -2
- package/lib/components/Table/useTableStyles.js.map +1 -1
- package/lib/components/TableBody/useTableBody.js +3 -1
- package/lib/components/TableBody/useTableBody.js.map +1 -1
- package/lib/components/TableBody/useTableBodyStyles.js +12 -2
- package/lib/components/TableBody/useTableBodyStyles.js.map +1 -1
- package/lib/components/TableCell/TableCell.types.js.map +1 -1
- package/lib/components/TableCell/renderTableCell.js +2 -4
- package/lib/components/TableCell/renderTableCell.js.map +1 -1
- package/lib/components/TableCell/useTableCell.js +5 -5
- package/lib/components/TableCell/useTableCell.js.map +1 -1
- package/lib/components/TableCell/useTableCellStyles.js +6 -20
- package/lib/components/TableCell/useTableCellStyles.js.map +1 -1
- package/lib/components/TableCellActions/TableCellActions.js +15 -0
- package/lib/components/TableCellActions/TableCellActions.js.map +1 -0
- package/lib/components/TableCellActions/TableCellActions.types.js +2 -0
- package/lib/components/TableCellActions/TableCellActions.types.js.map +1 -0
- package/lib/components/TableCellActions/index.js +6 -0
- package/lib/components/TableCellActions/index.js.map +1 -0
- package/lib/components/TableCellActions/renderTableCellActions.js +16 -0
- package/lib/components/TableCellActions/renderTableCellActions.js.map +1 -0
- package/lib/components/TableCellActions/useTableCellActions.js +27 -0
- package/lib/components/TableCellActions/useTableCellActions.js.map +1 -0
- package/lib/components/TableCellActions/useTableCellActionsStyles.js +40 -0
- package/lib/components/TableCellActions/useTableCellActionsStyles.js.map +1 -0
- package/lib/components/TableCellLayout/TableCellLayout.js +15 -0
- package/lib/components/TableCellLayout/TableCellLayout.js.map +1 -0
- package/lib/components/TableCellLayout/TableCellLayout.types.js +2 -0
- package/lib/components/TableCellLayout/TableCellLayout.types.js.map +1 -0
- package/lib/components/TableCellLayout/index.js +6 -0
- package/lib/components/TableCellLayout/index.js.map +1 -0
- package/lib/components/TableCellLayout/renderTableCellLayout.js +19 -0
- package/lib/components/TableCellLayout/renderTableCellLayout.js.map +1 -0
- package/lib/components/TableCellLayout/useTableCellLayout.js +36 -0
- package/lib/components/TableCellLayout/useTableCellLayout.js.map +1 -0
- package/lib/components/TableCellLayout/useTableCellLayoutStyles.js +74 -0
- package/lib/components/TableCellLayout/useTableCellLayoutStyles.js.map +1 -0
- package/lib/components/TableHeader/useTableHeader.js +4 -2
- package/lib/components/TableHeader/useTableHeader.js.map +1 -1
- package/lib/components/TableHeader/useTableHeaderStyles.js +12 -2
- package/lib/components/TableHeader/useTableHeaderStyles.js.map +1 -1
- package/lib/components/TableHeaderCell/useTableHeaderCell.js +4 -2
- package/lib/components/TableHeaderCell/useTableHeaderCell.js.map +1 -1
- package/lib/components/TableHeaderCell/useTableHeaderCellStyles.js +11 -9
- package/lib/components/TableHeaderCell/useTableHeaderCellStyles.js.map +1 -1
- package/lib/components/TableRow/useTableRow.js +4 -2
- package/lib/components/TableRow/useTableRow.js.map +1 -1
- package/lib/components/TableRow/useTableRowStyles.js +11 -7
- package/lib/components/TableRow/useTableRowStyles.js.map +1 -1
- package/lib/components/TableSelectionCell/TableSelectionCell.js +15 -0
- package/lib/components/TableSelectionCell/TableSelectionCell.js.map +1 -0
- package/lib/components/TableSelectionCell/TableSelectionCell.types.js +2 -0
- package/lib/components/TableSelectionCell/TableSelectionCell.types.js.map +1 -0
- package/lib/components/TableSelectionCell/index.js +6 -0
- package/lib/components/TableSelectionCell/index.js.map +1 -0
- package/lib/components/TableSelectionCell/renderTableSelectionCell.js +17 -0
- package/lib/components/TableSelectionCell/renderTableSelectionCell.js.map +1 -0
- package/lib/components/TableSelectionCell/useTableSelectionCell.js +42 -0
- package/lib/components/TableSelectionCell/useTableSelectionCell.js.map +1 -0
- package/lib/components/TableSelectionCell/useTableSelectionCellStyles.js +55 -0
- package/lib/components/TableSelectionCell/useTableSelectionCellStyles.js.map +1 -0
- package/lib/contexts/tableContext.js +7 -3
- package/lib/contexts/tableContext.js.map +1 -1
- package/lib/hooks/index.js +3 -0
- package/lib/hooks/index.js.map +1 -0
- package/lib/hooks/selectionManager.js +89 -0
- package/lib/hooks/selectionManager.js.map +1 -0
- package/lib/hooks/types.js +2 -0
- package/lib/hooks/types.js.map +1 -0
- package/lib/hooks/useSelection.js +47 -0
- package/lib/hooks/useSelection.js.map +1 -0
- package/lib/hooks/useSort.js +72 -0
- package/lib/hooks/useSort.js.map +1 -0
- package/lib/hooks/useTable.js +87 -0
- package/lib/hooks/useTable.js.map +1 -0
- package/lib/index.js +4 -0
- package/lib/index.js.map +1 -1
- package/lib/navigationModes/cell.js +250 -0
- package/lib/navigationModes/cell.js.map +1 -0
- package/lib/navigationModes/composite.js +208 -0
- package/lib/navigationModes/composite.js.map +1 -0
- package/lib/navigationModes/index.js +3 -0
- package/lib/navigationModes/index.js.map +1 -0
- package/lib/navigationModes/useNavigationMode.js +42 -0
- package/lib/navigationModes/useNavigationMode.js.map +1 -0
- package/lib-commonjs/TableCellActions.js +10 -0
- package/lib-commonjs/TableCellActions.js.map +1 -0
- package/lib-commonjs/TableCellLayout.js +10 -0
- package/lib-commonjs/TableCellLayout.js.map +1 -0
- package/lib-commonjs/TableCellPrimaryLayout.js +10 -0
- package/lib-commonjs/TableCellPrimaryLayout.js.map +1 -0
- package/lib-commonjs/TableSelectionCell.js +10 -0
- package/lib-commonjs/TableSelectionCell.js.map +1 -0
- package/lib-commonjs/components/Table/useTableContextValues.js +8 -5
- package/lib-commonjs/components/Table/useTableContextValues.js.map +1 -1
- package/lib-commonjs/components/Table/useTableStyles.js +8 -2
- package/lib-commonjs/components/Table/useTableStyles.js.map +1 -1
- package/lib-commonjs/components/TableBody/useTableBody.js +3 -1
- package/lib-commonjs/components/TableBody/useTableBody.js.map +1 -1
- package/lib-commonjs/components/TableBody/useTableBodyStyles.js +10 -1
- package/lib-commonjs/components/TableBody/useTableBodyStyles.js.map +1 -1
- package/lib-commonjs/components/TableCell/renderTableCell.js +2 -4
- package/lib-commonjs/components/TableCell/renderTableCell.js.map +1 -1
- package/lib-commonjs/components/TableCell/useTableCell.js +4 -4
- package/lib-commonjs/components/TableCell/useTableCell.js.map +1 -1
- package/lib-commonjs/components/TableCell/useTableCellStyles.js +6 -20
- package/lib-commonjs/components/TableCell/useTableCellStyles.js.map +1 -1
- package/lib-commonjs/components/TableCellActions/TableCellActions.js +26 -0
- package/lib-commonjs/components/TableCellActions/TableCellActions.js.map +1 -0
- package/lib-commonjs/components/TableCellActions/TableCellActions.types.js +6 -0
- package/lib-commonjs/components/TableCellActions/TableCellActions.types.js.map +1 -0
- package/lib-commonjs/components/TableCellActions/index.js +18 -0
- package/lib-commonjs/components/TableCellActions/index.js.map +1 -0
- package/lib-commonjs/components/TableCellActions/renderTableCellActions.js +27 -0
- package/lib-commonjs/components/TableCellActions/renderTableCellActions.js.map +1 -0
- package/lib-commonjs/components/TableCellActions/useTableCellActions.js +38 -0
- package/lib-commonjs/components/TableCellActions/useTableCellActions.js.map +1 -0
- package/lib-commonjs/components/TableCellActions/useTableCellActionsStyles.js +51 -0
- package/lib-commonjs/components/TableCellActions/useTableCellActionsStyles.js.map +1 -0
- package/lib-commonjs/components/TableCellLayout/TableCellLayout.js +26 -0
- package/lib-commonjs/components/TableCellLayout/TableCellLayout.js.map +1 -0
- package/lib-commonjs/components/TableCellLayout/TableCellLayout.types.js +6 -0
- package/lib-commonjs/components/TableCellLayout/TableCellLayout.types.js.map +1 -0
- package/lib-commonjs/components/TableCellLayout/index.js +18 -0
- package/lib-commonjs/components/TableCellLayout/index.js.map +1 -0
- package/lib-commonjs/components/TableCellLayout/renderTableCellLayout.js +30 -0
- package/lib-commonjs/components/TableCellLayout/renderTableCellLayout.js.map +1 -0
- package/lib-commonjs/components/TableCellLayout/useTableCellLayout.js +46 -0
- package/lib-commonjs/components/TableCellLayout/useTableCellLayout.js.map +1 -0
- package/lib-commonjs/components/TableCellLayout/useTableCellLayoutStyles.js +85 -0
- package/lib-commonjs/components/TableCellLayout/useTableCellLayoutStyles.js.map +1 -0
- package/lib-commonjs/components/TableHeader/useTableHeader.js +4 -2
- package/lib-commonjs/components/TableHeader/useTableHeader.js.map +1 -1
- package/lib-commonjs/components/TableHeader/useTableHeaderStyles.js +11 -1
- package/lib-commonjs/components/TableHeader/useTableHeaderStyles.js.map +1 -1
- package/lib-commonjs/components/TableHeaderCell/useTableHeaderCell.js +4 -2
- package/lib-commonjs/components/TableHeaderCell/useTableHeaderCell.js.map +1 -1
- package/lib-commonjs/components/TableHeaderCell/useTableHeaderCellStyles.js +11 -9
- package/lib-commonjs/components/TableHeaderCell/useTableHeaderCellStyles.js.map +1 -1
- package/lib-commonjs/components/TableRow/useTableRow.js +4 -2
- package/lib-commonjs/components/TableRow/useTableRow.js.map +1 -1
- package/lib-commonjs/components/TableRow/useTableRowStyles.js +12 -7
- package/lib-commonjs/components/TableRow/useTableRowStyles.js.map +1 -1
- package/lib-commonjs/components/TableSelectionCell/TableSelectionCell.js +26 -0
- package/lib-commonjs/components/TableSelectionCell/TableSelectionCell.js.map +1 -0
- package/lib-commonjs/components/TableSelectionCell/TableSelectionCell.types.js +6 -0
- package/lib-commonjs/components/TableSelectionCell/TableSelectionCell.types.js.map +1 -0
- package/lib-commonjs/components/TableSelectionCell/index.js +18 -0
- package/lib-commonjs/components/TableSelectionCell/index.js.map +1 -0
- package/lib-commonjs/components/TableSelectionCell/renderTableSelectionCell.js +28 -0
- package/lib-commonjs/components/TableSelectionCell/renderTableSelectionCell.js.map +1 -0
- package/lib-commonjs/components/TableSelectionCell/useTableSelectionCell.js +56 -0
- package/lib-commonjs/components/TableSelectionCell/useTableSelectionCell.js.map +1 -0
- package/lib-commonjs/components/TableSelectionCell/useTableSelectionCellStyles.js +65 -0
- package/lib-commonjs/components/TableSelectionCell/useTableSelectionCellStyles.js.map +1 -0
- package/lib-commonjs/contexts/tableContext.js +7 -3
- package/lib-commonjs/contexts/tableContext.js.map +1 -1
- package/lib-commonjs/hooks/index.js +12 -0
- package/lib-commonjs/hooks/index.js.map +1 -0
- package/lib-commonjs/hooks/selectionManager.js +98 -0
- package/lib-commonjs/hooks/selectionManager.js.map +1 -0
- package/lib-commonjs/hooks/types.js +6 -0
- package/lib-commonjs/hooks/types.js.map +1 -0
- package/lib-commonjs/hooks/useSelection.js +59 -0
- package/lib-commonjs/hooks/useSelection.js.map +1 -0
- package/lib-commonjs/hooks/useSort.js +82 -0
- package/lib-commonjs/hooks/useSort.js.map +1 -0
- package/lib-commonjs/hooks/useTable.js +99 -0
- package/lib-commonjs/hooks/useTable.js.map +1 -0
- package/lib-commonjs/index.js +110 -1
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/navigationModes/cell.js +259 -0
- package/lib-commonjs/navigationModes/cell.js.map +1 -0
- package/lib-commonjs/navigationModes/composite.js +217 -0
- package/lib-commonjs/navigationModes/composite.js.map +1 -0
- package/lib-commonjs/navigationModes/index.js +16 -0
- package/lib-commonjs/navigationModes/index.js.map +1 -0
- package/lib-commonjs/navigationModes/useNavigationMode.js +55 -0
- package/lib-commonjs/navigationModes/useNavigationMode.js.map +1 -0
- package/package.json +9 -9
- package/dist/tsdoc-metadata.json +0 -11
|
@@ -13,8 +13,10 @@ import { useTableContext } from '../../contexts/tableContext';
|
|
|
13
13
|
export const useTableRow_unstable = (props, ref) => {
|
|
14
14
|
var _a;
|
|
15
15
|
|
|
16
|
-
const
|
|
17
|
-
|
|
16
|
+
const {
|
|
17
|
+
noNativeElements,
|
|
18
|
+
size
|
|
19
|
+
} = useTableContext();
|
|
18
20
|
const rootComponent = ((_a = props.as) !== null && _a !== void 0 ? _a : noNativeElements) ? 'div' : 'tr';
|
|
19
21
|
return {
|
|
20
22
|
components: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["components/TableRow/useTableRow.ts"],"names":[],"mappings":"AACA,SAAS,qBAAT,QAAsC,2BAAtC;AAEA,SAAS,eAAT,QAAgC,6BAAhC;AAEA;;;;;;;;AAQG;;AACH,OAAO,MAAM,oBAAoB,GAAG,CAAC,KAAD,EAAuB,GAAvB,KAAqE;;;EACvG,MAAM,
|
|
1
|
+
{"version":3,"sources":["components/TableRow/useTableRow.ts"],"names":[],"mappings":"AACA,SAAS,qBAAT,QAAsC,2BAAtC;AAEA,SAAS,eAAT,QAAgC,6BAAhC;AAEA;;;;;;;;AAQG;;AACH,OAAO,MAAM,oBAAoB,GAAG,CAAC,KAAD,EAAuB,GAAvB,KAAqE;;;EACvG,MAAM;IAAE,gBAAF;IAAoB;EAApB,IAA6B,eAAe,EAAlD;EACA,MAAM,aAAa,GAAG,CAAA,CAAA,EAAA,GAAA,KAAK,CAAC,EAAN,MAAQ,IAAR,IAAQ,EAAA,KAAA,KAAA,CAAR,GAAQ,EAAR,GAAY,gBAAZ,IAA+B,KAA/B,GAAuC,IAA7D;EAEA,OAAO;IACL,UAAU,EAAE;MACV,IAAI,EAAE;IADI,CADP;IAIL,IAAI,EAAE,qBAAqB,CAAC,aAAD,EAAgB;MACzC,GADyC;MAEzC,IAAI,EAAE,aAAa,KAAK,KAAlB,GAA0B,KAA1B,GAAkC,SAFC;MAGzC,GAAG;IAHsC,CAAhB,CAJtB;IASL;EATK,CAAP;AAWD,CAfM","sourcesContent":["import * as React from 'react';\nimport { getNativeElementProps } from '@fluentui/react-utilities';\nimport type { TableRowProps, TableRowState } from './TableRow.types';\nimport { useTableContext } from '../../contexts/tableContext';\n\n/**\n * Create the state required to render TableRow.\n *\n * The returned state can be modified with hooks such as useTableRowStyles_unstable,\n * before being passed to renderTableRow_unstable.\n *\n * @param props - props from this instance of TableRow\n * @param ref - reference to root HTMLElement of TableRow\n */\nexport const useTableRow_unstable = (props: TableRowProps, ref: React.Ref<HTMLElement>): TableRowState => {\n const { noNativeElements, size } = useTableContext();\n const rootComponent = props.as ?? noNativeElements ? 'div' : 'tr';\n\n return {\n components: {\n root: rootComponent,\n },\n root: getNativeElementProps(rootComponent, {\n ref,\n role: rootComponent === 'div' ? 'row' : undefined,\n ...props,\n }),\n size,\n };\n};\n"],"sourceRoot":"../src/"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { __styles, mergeClasses, shorthands } from '@griffel/react';
|
|
2
2
|
import { tokens } from '@fluentui/react-theme';
|
|
3
|
+
import { tableCellActionsClassNames } from '../TableCellActions/useTableCellActionsStyles';
|
|
3
4
|
export const tableRowClassName = 'fui-TableRow';
|
|
4
5
|
export const tableRowClassNames = {
|
|
5
6
|
root: tableRowClassName
|
|
@@ -10,29 +11,32 @@ export const tableRowClassNames = {
|
|
|
10
11
|
|
|
11
12
|
const useStyles = /*#__PURE__*/__styles({
|
|
12
13
|
"root": {
|
|
13
|
-
"mc9l5x": "
|
|
14
|
+
"mc9l5x": "f1u0rzck",
|
|
14
15
|
"sj55zd": "f19n0e5",
|
|
15
|
-
"Jwef8y": "f1knas48"
|
|
16
|
+
"Jwef8y": "f1knas48",
|
|
17
|
+
"Bi91k9c": "feu1g3u",
|
|
18
|
+
"Bi7d7a3": "f1boln4s",
|
|
19
|
+
"Bpt6rm4": "f1uorfem"
|
|
16
20
|
},
|
|
17
21
|
"medium": {
|
|
18
|
-
"
|
|
22
|
+
"Bqenvij": "f1ft4266",
|
|
19
23
|
"Bn0qgzm": "f1vxd6vx",
|
|
20
24
|
"oivjwe": "fg706s2",
|
|
21
25
|
"B9xav0g": "frpde29"
|
|
22
26
|
},
|
|
23
27
|
"small": {
|
|
24
|
-
"
|
|
28
|
+
"Bqenvij": "fbsu25e",
|
|
25
29
|
"Bn0qgzm": "f1vxd6vx",
|
|
26
30
|
"oivjwe": "fg706s2",
|
|
27
31
|
"B9xav0g": "frpde29"
|
|
28
32
|
},
|
|
29
33
|
"smaller": {
|
|
30
|
-
"
|
|
34
|
+
"Bqenvij": "frvgh55",
|
|
31
35
|
"Be2twd7": "fy9rknc"
|
|
32
36
|
}
|
|
33
37
|
}, {
|
|
34
|
-
"d": [".
|
|
35
|
-
"h": [".f1knas48:hover{background-color:var(--colorNeutralBackground1Hover);}"]
|
|
38
|
+
"d": [".f1u0rzck{display:table-row;}", ".f19n0e5{color:var(--colorNeutralForeground1);}", ".f1ft4266{height:44px;}", ".f1vxd6vx{border-bottom-width:var(--strokeWidthThin);}", ".fg706s2{border-bottom-style:solid;}", ".frpde29{border-bottom-color:var(--colorNeutralStroke2);}", ".fbsu25e{height:34px;}", ".frvgh55{height:24px;}", ".fy9rknc{font-size:var(--fontSizeBase200);}"],
|
|
39
|
+
"h": [".f1knas48:hover{background-color:var(--colorNeutralBackground1Hover);}", ".feu1g3u:hover{color:var(--colorNeutralForeground1Hover);}", ".f1boln4s:hover .fui-TableCellActions{background-color:var(--colorNeutralBackground1Hover);}", ".f1uorfem:hover .fui-TableCellActions{opacity:1;}"]
|
|
36
40
|
});
|
|
37
41
|
/**
|
|
38
42
|
* Apply styling to the TableRow slots based on the state
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["components/TableRow/useTableRowStyles.ts"],"names":[],"mappings":"AAAA,mBAAqB,YAArB,EAAmC,UAAnC,QAAqD,gBAArD;AACA,SAAS,MAAT,QAAuB,uBAAvB;
|
|
1
|
+
{"version":3,"sources":["components/TableRow/useTableRowStyles.ts"],"names":[],"mappings":"AAAA,mBAAqB,YAArB,EAAmC,UAAnC,QAAqD,gBAArD;AACA,SAAS,MAAT,QAAuB,uBAAvB;AAGA,SAAS,0BAAT,QAA2C,+CAA3C;AAEA,OAAO,MAAM,iBAAiB,GAAG,cAA1B;AACP,OAAO,MAAM,kBAAkB,GAAkC;EAC/D,IAAI,EAAE;AADyD,CAA1D;AAIP;;AAEG;;AACH,MAAM,SAAS,gBAAG;EAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;EAAA;IAAA;IAAA;IAAA;IAAA;EAAA;EAAA;IAAA;IAAA;IAAA;IAAA;EAAA;EAAA;IAAA;IAAA;EAAA;AAAA;EAAA;EAAA;AAAA,EAAlB;AA8BA;;AAEG;;;AACH,OAAO,MAAM,0BAA0B,GAAI,KAAD,IAAwC;EAChF,MAAM,MAAM,GAAG,SAAS,EAAxB;EACA,KAAK,CAAC,IAAN,CAAW,SAAX,GAAuB,YAAY,CAAC,kBAAkB,CAAC,IAApB,EAA0B,MAAM,CAAC,IAAjC,EAAuC,MAAM,CAAC,KAAK,CAAC,IAAP,CAA7C,EAA2D,KAAK,CAAC,IAAN,CAAW,SAAtE,CAAnC;EAEA,OAAO,KAAP;AACD,CALM","sourcesContent":["import { makeStyles, mergeClasses, shorthands } from '@griffel/react';\nimport { tokens } from '@fluentui/react-theme';\nimport type { TableRowSlots, TableRowState } from './TableRow.types';\nimport type { SlotClassNames } from '@fluentui/react-utilities';\nimport { tableCellActionsClassNames } from '../TableCellActions/useTableCellActionsStyles';\n\nexport const tableRowClassName = 'fui-TableRow';\nexport const tableRowClassNames: SlotClassNames<TableRowSlots> = {\n root: tableRowClassName,\n};\n\n/**\n * Styles for the root slot\n */\nconst useStyles = makeStyles({\n root: {\n display: 'table-row',\n color: tokens.colorNeutralForeground1,\n ':hover': {\n backgroundColor: tokens.colorNeutralBackground1Hover,\n color: tokens.colorNeutralForeground1Hover,\n [`& .${tableCellActionsClassNames.root}`]: {\n backgroundColor: tokens.colorNeutralBackground1Hover,\n opacity: 1,\n },\n },\n },\n\n medium: {\n height: '44px',\n ...shorthands.borderBottom(tokens.strokeWidthThin, 'solid', tokens.colorNeutralStroke2),\n },\n\n small: {\n height: '34px',\n ...shorthands.borderBottom(tokens.strokeWidthThin, 'solid', tokens.colorNeutralStroke2),\n },\n\n smaller: {\n height: '24px',\n fontSize: tokens.fontSizeBase200,\n },\n});\n\n/**\n * Apply styling to the TableRow slots based on the state\n */\nexport const useTableRowStyles_unstable = (state: TableRowState): TableRowState => {\n const styles = useStyles();\n state.root.className = mergeClasses(tableRowClassNames.root, styles.root, styles[state.size], state.root.className);\n\n return state;\n};\n"],"sourceRoot":"../src/"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useTableSelectionCell_unstable } from './useTableSelectionCell';
|
|
3
|
+
import { renderTableSelectionCell_unstable } from './renderTableSelectionCell';
|
|
4
|
+
import { useTableSelectionCellStyles_unstable } from './useTableSelectionCellStyles';
|
|
5
|
+
/**
|
|
6
|
+
* TableSelectionCell component - TODO: add more docs
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export const TableSelectionCell = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
10
|
+
const state = useTableSelectionCell_unstable(props, ref);
|
|
11
|
+
useTableSelectionCellStyles_unstable(state);
|
|
12
|
+
return renderTableSelectionCell_unstable(state);
|
|
13
|
+
});
|
|
14
|
+
TableSelectionCell.displayName = 'TableSelectionCell';
|
|
15
|
+
//# sourceMappingURL=TableSelectionCell.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["components/TableSelectionCell/TableSelectionCell.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,8BAAT,QAA+C,yBAA/C;AACA,SAAS,iCAAT,QAAkD,4BAAlD;AACA,SAAS,oCAAT,QAAqD,+BAArD;AAIA;;AAEG;;AACH,OAAO,MAAM,kBAAkB,gBAAiD,KAAK,CAAC,UAAN,CAAiB,CAAC,KAAD,EAAQ,GAAR,KAAe;EAC9G,MAAM,KAAK,GAAG,8BAA8B,CAAC,KAAD,EAAQ,GAAR,CAA5C;EAEA,oCAAoC,CAAC,KAAD,CAApC;EACA,OAAO,iCAAiC,CAAC,KAAD,CAAxC;AACD,CAL+E,CAAzE;AAOP,kBAAkB,CAAC,WAAnB,GAAiC,oBAAjC","sourcesContent":["import * as React from 'react';\nimport { useTableSelectionCell_unstable } from './useTableSelectionCell';\nimport { renderTableSelectionCell_unstable } from './renderTableSelectionCell';\nimport { useTableSelectionCellStyles_unstable } from './useTableSelectionCellStyles';\nimport type { TableSelectionCellProps } from './TableSelectionCell.types';\nimport type { ForwardRefComponent } from '@fluentui/react-utilities';\n\n/**\n * TableSelectionCell component - TODO: add more docs\n */\nexport const TableSelectionCell: ForwardRefComponent<TableSelectionCellProps> = React.forwardRef((props, ref) => {\n const state = useTableSelectionCell_unstable(props, ref);\n\n useTableSelectionCellStyles_unstable(state);\n return renderTableSelectionCell_unstable(state);\n});\n\nTableSelectionCell.displayName = 'TableSelectionCell';\n"],"sourceRoot":"../src/"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TableSelectionCell.types.js","sourceRoot":"../src/","sources":["components/TableSelectionCell/TableSelectionCell.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\nimport type { Checkbox, CheckboxProps } from '@fluentui/react-checkbox';\nimport { TableCellSlots } from '../TableCell/TableCell.types';\n\nexport type TableSelectionCellSlots = {\n /**\n * Selection indicator if selection type is checkbox\n */\n checkboxIndicator: Slot<typeof Checkbox>;\n /**\n * Selection indicator if selection type is radio\n */\n radioIndicator: Slot<'span'>;\n} & Pick<TableCellSlots, 'root'>;\n\n/**\n * TableSelectionCell Props\n */\nexport type TableSelectionCellProps = ComponentProps<Partial<Omit<TableSelectionCellSlots, 'media'>>> & {\n /**\n * A table can have two kinds of selection modes\n */\n type?: 'checkbox' | 'radio';\n checked?: CheckboxProps['checked'];\n};\n\n/**\n * State used in rendering TableSelectionCell\n */\nexport type TableSelectionCellState = ComponentState<TableSelectionCellSlots> &\n Pick<Required<TableSelectionCellProps>, 'type' | 'checked'>;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["components/TableSelectionCell/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,+BAA+B,CAAC","sourcesContent":["export * from './TableSelectionCell';\nexport * from './TableSelectionCell.types';\nexport * from './renderTableSelectionCell';\nexport * from './useTableSelectionCell';\nexport * from './useTableSelectionCellStyles';\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { getSlots } from '@fluentui/react-utilities';
|
|
3
|
+
/**
|
|
4
|
+
* Render the final JSX of TableSelectionCell
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export const renderTableSelectionCell_unstable = state => {
|
|
8
|
+
const {
|
|
9
|
+
slots,
|
|
10
|
+
slotProps
|
|
11
|
+
} = getSlots(state);
|
|
12
|
+
return /*#__PURE__*/React.createElement(slots.root, { ...slotProps.root
|
|
13
|
+
}, state.type === 'checkbox' && slots.checkboxIndicator && /*#__PURE__*/React.createElement(slots.checkboxIndicator, { ...slotProps.checkboxIndicator
|
|
14
|
+
}), state.type === 'radio' && slots.radioIndicator && /*#__PURE__*/React.createElement(slots.radioIndicator, { ...slotProps.radioIndicator
|
|
15
|
+
}));
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=renderTableSelectionCell.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["components/TableSelectionCell/renderTableSelectionCell.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,QAAT,QAAyB,2BAAzB;AAGA;;AAEG;;AACH,OAAO,MAAM,iCAAiC,GAAI,KAAD,IAAmC;EAClF,MAAM;IAAE,KAAF;IAAS;EAAT,IAAuB,QAAQ,CAA0B,KAA1B,CAArC;EAEA,oBACE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,IAAP,EAAW,EAAA,GAAK,SAAS,CAAC;EAAf,CAAX,EACG,KAAK,CAAC,IAAN,KAAe,UAAf,IAA6B,KAAK,CAAC,iBAAnC,iBACC,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,iBAAP,EAAwB,EAAA,GAAK,SAAS,CAAC;EAAf,CAAxB,CAFJ,EAIG,KAAK,CAAC,IAAN,KAAe,OAAf,IAA0B,KAAK,CAAC,cAAhC,iBAAkD,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,cAAP,EAAqB,EAAA,GAAK,SAAS,CAAC;EAAf,CAArB,CAJrD,CADF;AAQD,CAXM","sourcesContent":["import * as React from 'react';\nimport { getSlots } from '@fluentui/react-utilities';\nimport type { TableSelectionCellState, TableSelectionCellSlots } from './TableSelectionCell.types';\n\n/**\n * Render the final JSX of TableSelectionCell\n */\nexport const renderTableSelectionCell_unstable = (state: TableSelectionCellState) => {\n const { slots, slotProps } = getSlots<TableSelectionCellSlots>(state);\n\n return (\n <slots.root {...slotProps.root}>\n {state.type === 'checkbox' && slots.checkboxIndicator && (\n <slots.checkboxIndicator {...slotProps.checkboxIndicator} />\n )}\n {state.type === 'radio' && slots.radioIndicator && <slots.radioIndicator {...slotProps.radioIndicator} />}\n </slots.root>\n );\n};\n"],"sourceRoot":"../src/"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { resolveShorthand } from '@fluentui/react-utilities';
|
|
3
|
+
import { Checkbox } from '@fluentui/react-checkbox';
|
|
4
|
+
import { CheckmarkFilled } from '@fluentui/react-icons';
|
|
5
|
+
import { useTableCell_unstable } from '../TableCell/useTableCell';
|
|
6
|
+
/**
|
|
7
|
+
* Create the state required to render TableSelectionCell.
|
|
8
|
+
*
|
|
9
|
+
* The returned state can be modified with hooks such as useTableSelectionCellStyles_unstable,
|
|
10
|
+
* before being passed to renderTableSelectionCell_unstable.
|
|
11
|
+
*
|
|
12
|
+
* @param props - props from this instance of TableSelectionCell
|
|
13
|
+
* @param ref - reference to root HTMLElement of TableSelectionCell
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export const useTableSelectionCell_unstable = (props, ref) => {
|
|
17
|
+
var _a, _b;
|
|
18
|
+
|
|
19
|
+
const tableCellState = useTableCell_unstable(props, ref);
|
|
20
|
+
const type = (_a = props.type) !== null && _a !== void 0 ? _a : 'checkbox';
|
|
21
|
+
return { ...tableCellState,
|
|
22
|
+
components: { ...tableCellState.components,
|
|
23
|
+
checkboxIndicator: Checkbox,
|
|
24
|
+
radioIndicator: 'span'
|
|
25
|
+
},
|
|
26
|
+
checkboxIndicator: resolveShorthand(props.checkboxIndicator, {
|
|
27
|
+
required: type === 'checkbox',
|
|
28
|
+
defaultProps: {
|
|
29
|
+
checked: props.checked
|
|
30
|
+
}
|
|
31
|
+
}),
|
|
32
|
+
radioIndicator: resolveShorthand(props.radioIndicator, {
|
|
33
|
+
required: type === 'radio',
|
|
34
|
+
defaultProps: {
|
|
35
|
+
children: /*#__PURE__*/React.createElement(CheckmarkFilled, null)
|
|
36
|
+
}
|
|
37
|
+
}),
|
|
38
|
+
type,
|
|
39
|
+
checked: (_b = props.checked) !== null && _b !== void 0 ? _b : false
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=useTableSelectionCell.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["components/TableSelectionCell/useTableSelectionCell.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,gBAAT,QAAiC,2BAAjC;AACA,SAAS,QAAT,QAAyB,0BAAzB;AACA,SAAS,eAAT,QAAgC,uBAAhC;AAEA,SAAS,qBAAT,QAAsC,2BAAtC;AAEA;;;;;;;;AAQG;;AACH,OAAO,MAAM,8BAA8B,GAAG,CAC5C,KAD4C,EAE5C,GAF4C,KAGjB;;;EAC3B,MAAM,cAAc,GAAG,qBAAqB,CAAC,KAAD,EAAQ,GAAR,CAA5C;EACA,MAAM,IAAI,GAAG,CAAA,EAAA,GAAA,KAAK,CAAC,IAAN,MAAU,IAAV,IAAU,EAAA,KAAA,KAAA,CAAV,GAAU,EAAV,GAAc,UAA3B;EAEA,OAAO,EACL,GAAG,cADE;IAEL,UAAU,EAAE,EACV,GAAG,cAAc,CAAC,UADR;MAEV,iBAAiB,EAAE,QAFT;MAGV,cAAc,EAAE;IAHN,CAFP;IAOL,iBAAiB,EAAE,gBAAgB,CAAC,KAAK,CAAC,iBAAP,EAA0B;MAC3D,QAAQ,EAAE,IAAI,KAAK,UADwC;MAE3D,YAAY,EAAE;QAAE,OAAO,EAAE,KAAK,CAAC;MAAjB;IAF6C,CAA1B,CAP9B;IAWL,cAAc,EAAE,gBAAgB,CAAC,KAAK,CAAC,cAAP,EAAuB;MACrD,QAAQ,EAAE,IAAI,KAAK,OADkC;MAErD,YAAY,EAAE;QAAE,QAAQ,eAAE,KAAA,CAAA,aAAA,CAAC,eAAD,EAAgB,IAAhB;MAAZ;IAFuC,CAAvB,CAX3B;IAeL,IAfK;IAgBL,OAAO,EAAE,CAAA,EAAA,GAAA,KAAK,CAAC,OAAN,MAAa,IAAb,IAAa,EAAA,KAAA,KAAA,CAAb,GAAa,EAAb,GAAiB;EAhBrB,CAAP;AAkBD,CAzBM","sourcesContent":["import * as React from 'react';\nimport { resolveShorthand } from '@fluentui/react-utilities';\nimport { Checkbox } from '@fluentui/react-checkbox';\nimport { CheckmarkFilled } from '@fluentui/react-icons';\nimport type { TableSelectionCellProps, TableSelectionCellState } from './TableSelectionCell.types';\nimport { useTableCell_unstable } from '../TableCell/useTableCell';\n\n/**\n * Create the state required to render TableSelectionCell.\n *\n * The returned state can be modified with hooks such as useTableSelectionCellStyles_unstable,\n * before being passed to renderTableSelectionCell_unstable.\n *\n * @param props - props from this instance of TableSelectionCell\n * @param ref - reference to root HTMLElement of TableSelectionCell\n */\nexport const useTableSelectionCell_unstable = (\n props: TableSelectionCellProps,\n ref: React.Ref<HTMLElement>,\n): TableSelectionCellState => {\n const tableCellState = useTableCell_unstable(props, ref);\n const type = props.type ?? 'checkbox';\n\n return {\n ...tableCellState,\n components: {\n ...tableCellState.components,\n checkboxIndicator: Checkbox,\n radioIndicator: 'span',\n },\n checkboxIndicator: resolveShorthand(props.checkboxIndicator, {\n required: type === 'checkbox',\n defaultProps: { checked: props.checked },\n }),\n radioIndicator: resolveShorthand(props.radioIndicator, {\n required: type === 'radio',\n defaultProps: { children: <CheckmarkFilled /> },\n }),\n type,\n checked: props.checked ?? false,\n };\n};\n"],"sourceRoot":"../src/"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { __styles, mergeClasses, shorthands } from '@griffel/react';
|
|
2
|
+
export const tableSelectionCellClassNames = {
|
|
3
|
+
root: 'fui-TableSelectionCell',
|
|
4
|
+
checkboxIndicator: 'fui-TableSelectionCell__checkboxIndicator',
|
|
5
|
+
radioIndicator: 'fui-TableSelectionCell__radioIndicator'
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Styles for the root slot
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const useStyles = /*#__PURE__*/__styles({
|
|
12
|
+
"root": {
|
|
13
|
+
"a9b677": "fksc0bp",
|
|
14
|
+
"fsow6f": "f17mccla",
|
|
15
|
+
"Huce71": "fz5stix",
|
|
16
|
+
"z8tnut": "f1g0x7ka",
|
|
17
|
+
"z189sj": ["fhxju0i", "f1cnd47f"],
|
|
18
|
+
"Byoj8tv": "f1qch9an",
|
|
19
|
+
"uwmqm3": ["f1cnd47f", "fhxju0i"],
|
|
20
|
+
"mc9l5x": "f15pt5es"
|
|
21
|
+
},
|
|
22
|
+
"radioIndicator": {
|
|
23
|
+
"mc9l5x": "f22iagw",
|
|
24
|
+
"Bh6795r": "fqerorx",
|
|
25
|
+
"Bt984gj": "f122n59",
|
|
26
|
+
"Brf1p80": "f4d9j23",
|
|
27
|
+
"B5pe6w7": "f1cqkysu",
|
|
28
|
+
"p4uzdd": "f1sgf1mg"
|
|
29
|
+
},
|
|
30
|
+
"hidden": {
|
|
31
|
+
"Bcdw1i0": "fd7fpy0"
|
|
32
|
+
}
|
|
33
|
+
}, {
|
|
34
|
+
"d": [".fksc0bp{width:44px;}", ".f17mccla{text-align:center;}", ".fz5stix{white-space:nowrap;}", ".f1g0x7ka{padding-top:0;}", ".fhxju0i{padding-right:0;}", ".f1cnd47f{padding-left:0;}", ".f1qch9an{padding-bottom:0;}", ".f15pt5es{display:table-cell;}", ".f22iagw{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;}", ".fqerorx{-webkit-box-flex:1;-webkit-flex-grow:1;-ms-flex-positive:1;flex-grow:1;}", ".f122n59{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;}", ".f4d9j23{-webkit-box-pack:center;-ms-flex-pack:center;-webkit-justify-content:center;justify-content:center;}", ".f1cqkysu svg{width:16px;}", ".f1sgf1mg svg{height:16px;}", ".fd7fpy0{visibility:hidden;}"]
|
|
35
|
+
});
|
|
36
|
+
/**
|
|
37
|
+
* Apply styling to the TableSelectionCell slots based on the state
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
export const useTableSelectionCellStyles_unstable = state => {
|
|
42
|
+
const styles = useStyles();
|
|
43
|
+
state.root.className = mergeClasses(tableSelectionCellClassNames.root, styles.root, state.root.className);
|
|
44
|
+
|
|
45
|
+
if (state.checkboxIndicator) {
|
|
46
|
+
state.checkboxIndicator.className = mergeClasses(tableSelectionCellClassNames.checkboxIndicator, state.checkboxIndicator.className);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (state.radioIndicator) {
|
|
50
|
+
state.radioIndicator.className = mergeClasses(tableSelectionCellClassNames.radioIndicator, styles.radioIndicator, state.checked === false && styles.hidden, state.radioIndicator.className);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return state;
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=useTableSelectionCellStyles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["components/TableSelectionCell/useTableSelectionCellStyles.ts"],"names":[],"mappings":"AAAA,mBAAqB,YAArB,EAAmC,UAAnC,QAAqD,gBAArD;AAIA,OAAO,MAAM,4BAA4B,GAA4C;EACnF,IAAI,EAAE,wBAD6E;EAEnF,iBAAiB,EAAE,2CAFgE;EAGnF,cAAc,EAAE;AAHmE,CAA9E;AAMP;;AAEG;;AACH,MAAM,SAAS,gBAAG;EAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;EAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;EAAA;IAAA;EAAA;AAAA;EAAA;AAAA,EAAlB;AAyBA;;AAEG;;;AACH,OAAO,MAAM,oCAAoC,GAAI,KAAD,IAA4D;EAC9G,MAAM,MAAM,GAAG,SAAS,EAAxB;EACA,KAAK,CAAC,IAAN,CAAW,SAAX,GAAuB,YAAY,CAAC,4BAA4B,CAAC,IAA9B,EAAoC,MAAM,CAAC,IAA3C,EAAiD,KAAK,CAAC,IAAN,CAAW,SAA5D,CAAnC;;EACA,IAAI,KAAK,CAAC,iBAAV,EAA6B;IAC3B,KAAK,CAAC,iBAAN,CAAwB,SAAxB,GAAoC,YAAY,CAC9C,4BAA4B,CAAC,iBADiB,EAE9C,KAAK,CAAC,iBAAN,CAAwB,SAFsB,CAAhD;EAID;;EAED,IAAI,KAAK,CAAC,cAAV,EAA0B;IACxB,KAAK,CAAC,cAAN,CAAqB,SAArB,GAAiC,YAAY,CAC3C,4BAA4B,CAAC,cADc,EAE3C,MAAM,CAAC,cAFoC,EAG3C,KAAK,CAAC,OAAN,KAAkB,KAAlB,IAA2B,MAAM,CAAC,MAHS,EAI3C,KAAK,CAAC,cAAN,CAAqB,SAJsB,CAA7C;EAMD;;EAED,OAAO,KAAP;AACD,CApBM","sourcesContent":["import { makeStyles, mergeClasses, shorthands } from '@griffel/react';\nimport type { TableSelectionCellSlots, TableSelectionCellState } from './TableSelectionCell.types';\nimport type { SlotClassNames } from '@fluentui/react-utilities';\n\nexport const tableSelectionCellClassNames: SlotClassNames<TableSelectionCellSlots> = {\n root: 'fui-TableSelectionCell',\n checkboxIndicator: 'fui-TableSelectionCell__checkboxIndicator',\n radioIndicator: 'fui-TableSelectionCell__radioIndicator',\n};\n\n/**\n * Styles for the root slot\n */\nconst useStyles = makeStyles({\n root: {\n width: '44px',\n textAlign: 'center',\n whiteSpace: 'nowrap',\n ...shorthands.padding(0),\n display: 'table-cell',\n },\n\n radioIndicator: {\n display: 'flex',\n flexGrow: 1,\n alignItems: 'center',\n justifyContent: 'center',\n '& svg': {\n width: '16px',\n height: '16px',\n },\n },\n\n hidden: {\n visibility: 'hidden',\n },\n});\n\n/**\n * Apply styling to the TableSelectionCell slots based on the state\n */\nexport const useTableSelectionCellStyles_unstable = (state: TableSelectionCellState): TableSelectionCellState => {\n const styles = useStyles();\n state.root.className = mergeClasses(tableSelectionCellClassNames.root, styles.root, state.root.className);\n if (state.checkboxIndicator) {\n state.checkboxIndicator.className = mergeClasses(\n tableSelectionCellClassNames.checkboxIndicator,\n state.checkboxIndicator.className,\n );\n }\n\n if (state.radioIndicator) {\n state.radioIndicator.className = mergeClasses(\n tableSelectionCellClassNames.radioIndicator,\n styles.radioIndicator,\n state.checked === false && styles.hidden,\n state.radioIndicator.className,\n );\n }\n\n return state;\n};\n"],"sourceRoot":"../src/"}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
const tableContext = /*#__PURE__*/createContext(undefined);
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
const tableContext = /*#__PURE__*/React.createContext(undefined);
|
|
3
3
|
export const tableContextDefaultValue = {
|
|
4
4
|
size: 'medium',
|
|
5
5
|
noNativeElements: false,
|
|
6
6
|
sortable: false
|
|
7
7
|
};
|
|
8
8
|
export const TableContextProvider = tableContext.Provider;
|
|
9
|
-
export const useTableContext =
|
|
9
|
+
export const useTableContext = () => {
|
|
10
|
+
var _a;
|
|
11
|
+
|
|
12
|
+
return (_a = React.useContext(tableContext)) !== null && _a !== void 0 ? _a : tableContextDefaultValue;
|
|
13
|
+
};
|
|
10
14
|
//# sourceMappingURL=tableContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["contexts/tableContext.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"sources":["contexts/tableContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAGA,MAAM,YAAY,gBAAG,KAAK,CAAC,aAAN,CAAmD,SAAnD,CAArB;AAEA,OAAO,MAAM,wBAAwB,GAAsB;EACzD,IAAI,EAAE,QADmD;EAEzD,gBAAgB,EAAE,KAFuC;EAGzD,QAAQ,EAAE;AAH+C,CAApD;AAMP,OAAO,MAAM,oBAAoB,GAAG,YAAY,CAAC,QAA1C;AACP,OAAO,MAAM,eAAe,GAAG,MAAK;EAAA,IAAA,EAAA;;EAAC,OAAA,CAAA,EAAA,GAAA,KAAK,CAAC,UAAN,CAAiB,YAAjB,CAAA,MAA8B,IAA9B,IAA8B,EAAA,KAAA,KAAA,CAA9B,GAA8B,EAA9B,GAAkC,wBAAlC;AAA0D,CAAxF","sourcesContent":["import * as React from 'react';\nimport { TableContextValue } from '../components/Table/Table.types';\n\nconst tableContext = React.createContext<TableContextValue | undefined>(undefined);\n\nexport const tableContextDefaultValue: TableContextValue = {\n size: 'medium',\n noNativeElements: false,\n sortable: false,\n};\n\nexport const TableContextProvider = tableContext.Provider;\nexport const useTableContext = () => React.useContext(tableContext) ?? tableContextDefaultValue;\n"],"sourceRoot":"../src/"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC","sourcesContent":["export * from './types';\nexport * from './useTable';\n"]}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
export function createSelectionManager(mode, onSelectionChange = () => undefined) {
|
|
2
|
+
const managerFactory = mode === 'multiselect' ? createMultipleSelectionManager : createSingleSelectionManager;
|
|
3
|
+
return managerFactory(onSelectionChange);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
function createMultipleSelectionManager(onSelectionChange) {
|
|
7
|
+
const toggleAllItems = (itemIds, selectedItems) => {
|
|
8
|
+
const allItemsSelected = itemIds.every(itemId => selectedItems.has(itemId));
|
|
9
|
+
|
|
10
|
+
if (allItemsSelected) {
|
|
11
|
+
selectedItems.clear();
|
|
12
|
+
} else {
|
|
13
|
+
itemIds.forEach(itemId => selectedItems.add(itemId));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
onSelectionChange(new Set(selectedItems));
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const toggleItem = (itemId, selectedItems) => {
|
|
20
|
+
if (selectedItems.has(itemId)) {
|
|
21
|
+
selectedItems.delete(itemId);
|
|
22
|
+
} else {
|
|
23
|
+
selectedItems.add(itemId);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
onSelectionChange(new Set(selectedItems));
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const selectItem = (itemId, selectedItems) => {
|
|
30
|
+
selectedItems.add(itemId);
|
|
31
|
+
onSelectionChange(new Set(selectedItems));
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const deselectItem = (itemId, selectedItems) => {
|
|
35
|
+
selectedItems.delete(itemId);
|
|
36
|
+
onSelectionChange(new Set(selectedItems));
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const clearItems = () => {
|
|
40
|
+
onSelectionChange(new Set());
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const isSelected = (itemId, selectedItems) => {
|
|
44
|
+
return selectedItems.has(itemId);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
toggleItem,
|
|
49
|
+
selectItem,
|
|
50
|
+
deselectItem,
|
|
51
|
+
clearItems,
|
|
52
|
+
isSelected,
|
|
53
|
+
toggleAllItems
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function createSingleSelectionManager(onSelectionChange) {
|
|
58
|
+
const toggleItem = itemId => {
|
|
59
|
+
onSelectionChange(new Set([itemId]));
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const clearItems = () => {
|
|
63
|
+
onSelectionChange(new Set());
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const isSelected = (itemId, selectedItems) => {
|
|
67
|
+
return selectedItems.has(itemId);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const selectItem = itemId => {
|
|
71
|
+
onSelectionChange(new Set([itemId]));
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
deselectItem: clearItems,
|
|
76
|
+
selectItem,
|
|
77
|
+
toggleAllItems: () => {
|
|
78
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
79
|
+
throw new Error('[react-table]: `toggleAllItems` should not be used in single selection mode');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return undefined;
|
|
83
|
+
},
|
|
84
|
+
toggleItem,
|
|
85
|
+
clearItems,
|
|
86
|
+
isSelected
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=selectionManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["hooks/selectionManager.ts"],"names":[],"mappings":"AAeA,OAAM,SAAU,sBAAV,CACJ,IADI,EAEJ,iBAAA,GAA+C,MAAM,SAFjD,EAE0D;EAE9D,MAAM,cAAc,GAAG,IAAI,KAAK,aAAT,GAAyB,8BAAzB,GAA0D,4BAAjF;EAEA,OAAO,cAAc,CAAC,iBAAD,CAArB;AACD;;AAED,SAAS,8BAAT,CAAwC,iBAAxC,EAAoF;EAClF,MAAM,cAAc,GAAG,CAAC,OAAD,EAA6B,aAA7B,KAAoE;IACzF,MAAM,gBAAgB,GAAG,OAAO,CAAC,KAAR,CAAc,MAAM,IAAI,aAAa,CAAC,GAAd,CAAkB,MAAlB,CAAxB,CAAzB;;IAEA,IAAI,gBAAJ,EAAsB;MACpB,aAAa,CAAC,KAAd;IACD,CAFD,MAEO;MACL,OAAO,CAAC,OAAR,CAAgB,MAAM,IAAI,aAAa,CAAC,GAAd,CAAkB,MAAlB,CAA1B;IACD;;IAED,iBAAiB,CAAC,IAAI,GAAJ,CAAQ,aAAR,CAAD,CAAjB;EACD,CAVD;;EAYA,MAAM,UAAU,GAAG,CAAC,MAAD,EAA0B,aAA1B,KAAiE;IAClF,IAAI,aAAa,CAAC,GAAd,CAAkB,MAAlB,CAAJ,EAA+B;MAC7B,aAAa,CAAC,MAAd,CAAqB,MAArB;IACD,CAFD,MAEO;MACL,aAAa,CAAC,GAAd,CAAkB,MAAlB;IACD;;IAED,iBAAiB,CAAC,IAAI,GAAJ,CAAQ,aAAR,CAAD,CAAjB;EACD,CARD;;EAUA,MAAM,UAAU,GAAG,CAAC,MAAD,EAA0B,aAA1B,KAAiE;IAClF,aAAa,CAAC,GAAd,CAAkB,MAAlB;IACA,iBAAiB,CAAC,IAAI,GAAJ,CAAQ,aAAR,CAAD,CAAjB;EACD,CAHD;;EAKA,MAAM,YAAY,GAAG,CAAC,MAAD,EAA0B,aAA1B,KAAiE;IACpF,aAAa,CAAC,MAAd,CAAqB,MAArB;IACA,iBAAiB,CAAC,IAAI,GAAJ,CAAQ,aAAR,CAAD,CAAjB;EACD,CAHD;;EAKA,MAAM,UAAU,GAAG,MAAK;IACtB,iBAAiB,CAAC,IAAI,GAAJ,EAAD,CAAjB;EACD,CAFD;;EAIA,MAAM,UAAU,GAAG,CAAC,MAAD,EAA0B,aAA1B,KAAiE;IAClF,OAAO,aAAa,CAAC,GAAd,CAAkB,MAAlB,CAAP;EACD,CAFD;;EAIA,OAAO;IACL,UADK;IAEL,UAFK;IAGL,YAHK;IAIL,UAJK;IAKL,UALK;IAML;EANK,CAAP;AAQD;;AAED,SAAS,4BAAT,CAAsC,iBAAtC,EAAkF;EAChF,MAAM,UAAU,GAAI,MAAD,IAA4B;IAC7C,iBAAiB,CAAC,IAAI,GAAJ,CAAQ,CAAC,MAAD,CAAR,CAAD,CAAjB;EACD,CAFD;;EAIA,MAAM,UAAU,GAAG,MAAK;IACtB,iBAAiB,CAAC,IAAI,GAAJ,EAAD,CAAjB;EACD,CAFD;;EAIA,MAAM,UAAU,GAAG,CAAC,MAAD,EAA0B,aAA1B,KAAiE;IAClF,OAAO,aAAa,CAAC,GAAd,CAAkB,MAAlB,CAAP;EACD,CAFD;;EAIA,MAAM,UAAU,GAAI,MAAD,IAA4B;IAC7C,iBAAiB,CAAC,IAAI,GAAJ,CAAQ,CAAC,MAAD,CAAR,CAAD,CAAjB;EACD,CAFD;;EAIA,OAAO;IACL,YAAY,EAAE,UADT;IAEL,UAFK;IAGL,cAAc,EAAE,MAAK;MACnB,IAAI,OAAO,CAAC,GAAR,CAAY,QAAZ,KAAyB,YAA7B,EAA2C;QACzC,MAAM,IAAI,KAAJ,CAAU,6EAAV,CAAN;MACD;;MAED,OAAO,SAAP;IACD,CATI;IAUL,UAVK;IAWL,UAXK;IAYL;EAZK,CAAP;AAcD","sourcesContent":["import { SelectionMode } from './types';\n\ntype OnSelectionChangeCallback = (selectedItems: Set<SelectionItemId>) => void;\n\nexport interface SelectionManager {\n toggleItem(id: SelectionItemId, selectedItems: Set<SelectionItemId>): void;\n selectItem(id: SelectionItemId, selectedItems: Set<SelectionItemId>): void;\n deselectItem(id: SelectionItemId, selectedItems: Set<SelectionItemId>): void;\n clearItems(): void;\n isSelected(id: SelectionItemId, selectedItems: Set<SelectionItemId>): boolean;\n toggleAllItems(itemIds: SelectionItemId[], selectedItems: Set<SelectionItemId>): void;\n}\n\nexport type SelectionItemId = string | number;\n\nexport function createSelectionManager(\n mode: SelectionMode,\n onSelectionChange: OnSelectionChangeCallback = () => undefined,\n): SelectionManager {\n const managerFactory = mode === 'multiselect' ? createMultipleSelectionManager : createSingleSelectionManager;\n\n return managerFactory(onSelectionChange);\n}\n\nfunction createMultipleSelectionManager(onSelectionChange: OnSelectionChangeCallback): SelectionManager {\n const toggleAllItems = (itemIds: SelectionItemId[], selectedItems: Set<SelectionItemId>) => {\n const allItemsSelected = itemIds.every(itemId => selectedItems.has(itemId));\n\n if (allItemsSelected) {\n selectedItems.clear();\n } else {\n itemIds.forEach(itemId => selectedItems.add(itemId));\n }\n\n onSelectionChange(new Set(selectedItems));\n };\n\n const toggleItem = (itemId: SelectionItemId, selectedItems: Set<SelectionItemId>) => {\n if (selectedItems.has(itemId)) {\n selectedItems.delete(itemId);\n } else {\n selectedItems.add(itemId);\n }\n\n onSelectionChange(new Set(selectedItems));\n };\n\n const selectItem = (itemId: SelectionItemId, selectedItems: Set<SelectionItemId>) => {\n selectedItems.add(itemId);\n onSelectionChange(new Set(selectedItems));\n };\n\n const deselectItem = (itemId: SelectionItemId, selectedItems: Set<SelectionItemId>) => {\n selectedItems.delete(itemId);\n onSelectionChange(new Set(selectedItems));\n };\n\n const clearItems = () => {\n onSelectionChange(new Set());\n };\n\n const isSelected = (itemId: SelectionItemId, selectedItems: Set<SelectionItemId>) => {\n return selectedItems.has(itemId);\n };\n\n return {\n toggleItem,\n selectItem,\n deselectItem,\n clearItems,\n isSelected,\n toggleAllItems,\n };\n}\n\nfunction createSingleSelectionManager(onSelectionChange: OnSelectionChangeCallback): SelectionManager {\n const toggleItem = (itemId: SelectionItemId) => {\n onSelectionChange(new Set([itemId]));\n };\n\n const clearItems = () => {\n onSelectionChange(new Set<SelectionItemId>());\n };\n\n const isSelected = (itemId: SelectionItemId, selectedItems: Set<SelectionItemId>) => {\n return selectedItems.has(itemId);\n };\n\n const selectItem = (itemId: SelectionItemId) => {\n onSelectionChange(new Set([itemId]));\n };\n\n return {\n deselectItem: clearItems,\n selectItem,\n toggleAllItems: () => {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('[react-table]: `toggleAllItems` should not be used in single selection mode');\n }\n\n return undefined;\n },\n toggleItem,\n clearItems,\n isSelected,\n };\n}\n"],"sourceRoot":"../src/"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"../src/","sources":["hooks/types.ts"],"names":[],"mappings":"","sourcesContent":["import { SortDirection } from '../components/Table/Table.types';\n\nexport type RowId = string | number;\nexport type ColumnId = string | number;\nexport type GetRowIdInternal<TItem> = (rowId: TItem, index: number) => RowId;\nexport type SelectionMode = 'single' | 'multiselect';\nexport type OnSelectionChangeCallback = (selectedItems: Set<RowId>) => void;\nexport type OnSortChangeCallback = (state: { sortColumn: ColumnId | undefined; sortDirection: SortDirection }) => void;\n\nexport interface SortState {\n sortColumn: ColumnId | undefined;\n sortDirection: SortDirection;\n}\n\nexport interface ColumnDefinition<TItem> {\n columnId: ColumnId;\n compare?: (a: TItem, b: TItem) => number;\n}\n\nexport type RowEnhancer<TItem, TRowState extends RowState<TItem> = RowState<TItem>> = (\n row: RowState<TItem>,\n state: { selection: TableSelectionState; sort: TableSortState },\n) => TRowState;\n\nexport interface TableSortStateInternal<TItem> {\n sortDirection: SortDirection;\n sortColumn: ColumnId | undefined;\n setColumnSort: (columnId: ColumnId, sortDirection: SortDirection) => void;\n toggleColumnSort: (columnId: ColumnId) => void;\n getSortDirection: (columnId: ColumnId) => SortDirection | undefined;\n /**\n * Returns a sorted **shallow** copy of original items\n */\n sort: (items: TItem[]) => TItem[];\n}\n\nexport interface UseTableOptions<TItem, TRowState extends RowState<TItem> = RowState<TItem>> {\n columns: ColumnDefinition<TItem>[];\n items: TItem[];\n selectionMode?: SelectionMode;\n /**\n * Used in uncontrolled mode to set initial selected rows on mount\n */\n defaultSelectedRows?: Set<RowId>;\n /**\n * Used to control row selection\n */\n selectedRows?: Set<RowId>;\n /**\n * Called when selection changes\n */\n onSelectionChange?: OnSelectionChangeCallback;\n /**\n * Used to control sorting\n */\n sortState?: SortState;\n /**\n * Used in uncontrolled mode to set initial sort column and direction on mount\n */\n defaultSortState?: SortState;\n /**\n * Called when sort changes\n */\n onSortChange?: OnSortChangeCallback;\n getRowId?: (item: TItem) => RowId;\n rowEnhancer?: RowEnhancer<TItem, TRowState>;\n}\n\nexport interface TableSelectionStateInternal {\n clearRows: () => void;\n deselectRow: (rowId: RowId) => void;\n selectRow: (rowId: RowId) => void;\n toggleAllRows: () => void;\n toggleRow: (rowId: RowId) => void;\n isRowSelected: (rowId: RowId) => boolean;\n selectedRows: Set<RowId>;\n allRowsSelected: boolean;\n someRowsSelected: boolean;\n}\n\nexport interface TableSortState {\n /**\n * Current sort direction\n */\n sortDirection: SortDirection;\n /**\n * Column id of the currently sorted column\n */\n sortColumn: ColumnId | undefined;\n /**\n * Set the sort direction for the specified column\n */\n setColumnSort: (columnId: ColumnId, sortDirection: SortDirection) => void;\n /**\n * Toggles the sort direction for specified column\n */\n toggleColumnSort: (columnId: ColumnId) => void;\n /**\n * Returns the sort direction if a column is sorted,\n * returns undefined if the column is not sorted\n */\n getSortDirection: (columnId: ColumnId) => SortDirection | undefined;\n}\n\nexport interface TableSelectionState {\n /**\n * Clears all selected rows\n */\n clearRows: () => void;\n /**\n * Selects single row\n */\n selectRow: (rowId: RowId) => void;\n /**\n * De-selects single row\n */\n deselectRow: (rowId: RowId) => void;\n /**\n * Toggle selection of all rows\n */\n toggleAllRows: () => void;\n /**\n * Toggle selection of single row\n */\n toggleRow: (rowId: RowId) => void;\n /**\n * Collection of row ids corresponding to selected rows\n */\n selectedRows: RowId[];\n /**\n * Whether all rows are selected\n */\n allRowsSelected: boolean;\n /**\n * Whether some rows are selected\n */\n someRowsSelected: boolean;\n\n /**\n * Checks if a given rowId is selected\n */\n isRowSelected: (rowId: RowId) => boolean;\n}\n\nexport interface RowState<TItem> {\n /**\n * User provided data\n */\n item: TItem;\n /**\n * The row id, defaults to index position in the collection\n */\n rowId: RowId;\n}\n\nexport interface TableState<TItem, TRowState extends RowState<TItem> = RowState<TItem>> {\n /**\n * The row data for rendering\n */\n rows: TRowState[];\n /**\n * State and actions to manage row selection\n */\n selection: TableSelectionState;\n /**\n * State and actions to manage row sorting\n */\n sort: TableSortState;\n}\n"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useControllableState, useEventCallback } from '@fluentui/react-utilities';
|
|
3
|
+
import { createSelectionManager } from './selectionManager';
|
|
4
|
+
export function useSelection(options) {
|
|
5
|
+
const {
|
|
6
|
+
selectionMode,
|
|
7
|
+
items,
|
|
8
|
+
getRowId,
|
|
9
|
+
defaultSelectedItems,
|
|
10
|
+
selectedItems,
|
|
11
|
+
onSelectionChange
|
|
12
|
+
} = options;
|
|
13
|
+
const [selected, setSelected] = useControllableState({
|
|
14
|
+
initialState: new Set(),
|
|
15
|
+
defaultState: defaultSelectedItems,
|
|
16
|
+
state: selectedItems
|
|
17
|
+
});
|
|
18
|
+
const selectionManager = React.useMemo(() => {
|
|
19
|
+
return createSelectionManager(selectionMode, newSelectedItems => {
|
|
20
|
+
setSelected(() => {
|
|
21
|
+
onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange(newSelectedItems);
|
|
22
|
+
return newSelectedItems;
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
}, [onSelectionChange, selectionMode, setSelected]);
|
|
26
|
+
const toggleAllRows = useEventCallback(() => {
|
|
27
|
+
selectionManager.toggleAllItems(items.map((item, i) => getRowId(item, i)), selected);
|
|
28
|
+
});
|
|
29
|
+
const toggleRow = useEventCallback(rowId => selectionManager.toggleItem(rowId, selected));
|
|
30
|
+
const deselectRow = useEventCallback(rowId => selectionManager.deselectItem(rowId, selected));
|
|
31
|
+
const selectRow = useEventCallback(rowId => selectionManager.selectItem(rowId, selected));
|
|
32
|
+
|
|
33
|
+
const isRowSelected = rowId => selectionManager.isSelected(rowId, selected);
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
someRowsSelected: selected.size > 0,
|
|
37
|
+
allRowsSelected: selectionMode === 'single' ? selected.size > 0 : selected.size === items.length,
|
|
38
|
+
selectedRows: selected,
|
|
39
|
+
toggleRow,
|
|
40
|
+
toggleAllRows,
|
|
41
|
+
clearRows: selectionManager.clearItems,
|
|
42
|
+
deselectRow,
|
|
43
|
+
selectRow,
|
|
44
|
+
isRowSelected
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=useSelection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["hooks/useSelection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,oBAAT,EAA+B,gBAA/B,QAAuD,2BAAvD;AACA,SAAS,sBAAT,QAAuC,oBAAvC;AAkBA,OAAM,SAAU,YAAV,CAA8B,OAA9B,EAAiE;EACrE,MAAM;IAAE,aAAF;IAAiB,KAAjB;IAAwB,QAAxB;IAAkC,oBAAlC;IAAwD,aAAxD;IAAuE;EAAvE,IAA6F,OAAnG;EAEA,MAAM,CAAC,QAAD,EAAW,WAAX,IAA0B,oBAAoB,CAAC;IACnD,YAAY,EAAE,IAAI,GAAJ,EADqC;IAEnD,YAAY,EAAE,oBAFqC;IAGnD,KAAK,EAAE;EAH4C,CAAD,CAApD;EAMA,MAAM,gBAAgB,GAAG,KAAK,CAAC,OAAN,CAAc,MAAK;IAC1C,OAAO,sBAAsB,CAAC,aAAD,EAAgB,gBAAgB,IAAG;MAC9D,WAAW,CAAC,MAAK;QACf,iBAAiB,KAAA,IAAjB,IAAA,iBAAiB,KAAA,KAAA,CAAjB,GAAiB,KAAA,CAAjB,GAAA,iBAAiB,CAAG,gBAAH,CAAjB;QACA,OAAO,gBAAP;MACD,CAHU,CAAX;IAID,CAL4B,CAA7B;EAMD,CAPwB,EAOtB,CAAC,iBAAD,EAAoB,aAApB,EAAmC,WAAnC,CAPsB,CAAzB;EASA,MAAM,aAAa,GAAiD,gBAAgB,CAAC,MAAK;IACxF,gBAAgB,CAAC,cAAjB,CACE,KAAK,CAAC,GAAN,CAAU,CAAC,IAAD,EAAO,CAAP,KAAa,QAAQ,CAAC,IAAD,EAAO,CAAP,CAA/B,CADF,EAEE,QAFF;EAID,CALmF,CAApF;EAOA,MAAM,SAAS,GAA6C,gBAAgB,CAAE,KAAD,IAC3E,gBAAgB,CAAC,UAAjB,CAA4B,KAA5B,EAAmC,QAAnC,CAD0E,CAA5E;EAIA,MAAM,WAAW,GAA+C,gBAAgB,CAAE,KAAD,IAC/E,gBAAgB,CAAC,YAAjB,CAA8B,KAA9B,EAAqC,QAArC,CAD8E,CAAhF;EAIA,MAAM,SAAS,GAA6C,gBAAgB,CAAE,KAAD,IAC3E,gBAAgB,CAAC,UAAjB,CAA4B,KAA5B,EAAmC,QAAnC,CAD0E,CAA5E;;EAIA,MAAM,aAAa,GAAkD,KAAD,IAClE,gBAAgB,CAAC,UAAjB,CAA4B,KAA5B,EAAmC,QAAnC,CADF;;EAGA,OAAO;IACL,gBAAgB,EAAE,QAAQ,CAAC,IAAT,GAAgB,CAD7B;IAEL,eAAe,EAAE,aAAa,KAAK,QAAlB,GAA6B,QAAQ,CAAC,IAAT,GAAgB,CAA7C,GAAiD,QAAQ,CAAC,IAAT,KAAkB,KAAK,CAAC,MAFrF;IAGL,YAAY,EAAE,QAHT;IAIL,SAJK;IAKL,aALK;IAML,SAAS,EAAE,gBAAgB,CAAC,UANvB;IAOL,WAPK;IAQL,SARK;IASL;EATK,CAAP;AAWD","sourcesContent":["import * as React from 'react';\nimport { useControllableState, useEventCallback } from '@fluentui/react-utilities';\nimport { createSelectionManager } from './selectionManager';\nimport type {\n GetRowIdInternal,\n OnSelectionChangeCallback,\n RowId,\n SelectionMode,\n TableSelectionStateInternal,\n} from './types';\n\ninterface UseSelectionOptions<TItem> {\n selectionMode: SelectionMode;\n items: TItem[];\n getRowId: GetRowIdInternal<TItem>;\n defaultSelectedItems?: Set<RowId>;\n selectedItems?: Set<RowId>;\n onSelectionChange?: OnSelectionChangeCallback;\n}\n\nexport function useSelection<TItem>(options: UseSelectionOptions<TItem>): TableSelectionStateInternal {\n const { selectionMode, items, getRowId, defaultSelectedItems, selectedItems, onSelectionChange } = options;\n\n const [selected, setSelected] = useControllableState({\n initialState: new Set<RowId>(),\n defaultState: defaultSelectedItems,\n state: selectedItems,\n });\n\n const selectionManager = React.useMemo(() => {\n return createSelectionManager(selectionMode, newSelectedItems => {\n setSelected(() => {\n onSelectionChange?.(newSelectedItems);\n return newSelectedItems;\n });\n });\n }, [onSelectionChange, selectionMode, setSelected]);\n\n const toggleAllRows: TableSelectionStateInternal['toggleAllRows'] = useEventCallback(() => {\n selectionManager.toggleAllItems(\n items.map((item, i) => getRowId(item, i)),\n selected,\n );\n });\n\n const toggleRow: TableSelectionStateInternal['toggleRow'] = useEventCallback((rowId: RowId) =>\n selectionManager.toggleItem(rowId, selected),\n );\n\n const deselectRow: TableSelectionStateInternal['deselectRow'] = useEventCallback((rowId: RowId) =>\n selectionManager.deselectItem(rowId, selected),\n );\n\n const selectRow: TableSelectionStateInternal['selectRow'] = useEventCallback((rowId: RowId) =>\n selectionManager.selectItem(rowId, selected),\n );\n\n const isRowSelected: TableSelectionStateInternal['isRowSelected'] = (rowId: RowId) =>\n selectionManager.isSelected(rowId, selected);\n\n return {\n someRowsSelected: selected.size > 0,\n allRowsSelected: selectionMode === 'single' ? selected.size > 0 : selected.size === items.length,\n selectedRows: selected,\n toggleRow,\n toggleAllRows,\n clearRows: selectionManager.clearItems,\n deselectRow,\n selectRow,\n isRowSelected,\n };\n}\n"],"sourceRoot":"../src/"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { useControllableState } from '@fluentui/react-utilities';
|
|
2
|
+
export function useSort(options) {
|
|
3
|
+
const {
|
|
4
|
+
columns,
|
|
5
|
+
sortState,
|
|
6
|
+
defaultSortState,
|
|
7
|
+
onSortChange
|
|
8
|
+
} = options;
|
|
9
|
+
const [sorted, setSorted] = useControllableState({
|
|
10
|
+
initialState: {
|
|
11
|
+
sortDirection: 'ascending',
|
|
12
|
+
sortColumn: undefined
|
|
13
|
+
},
|
|
14
|
+
defaultState: defaultSortState,
|
|
15
|
+
state: sortState
|
|
16
|
+
});
|
|
17
|
+
const {
|
|
18
|
+
sortColumn,
|
|
19
|
+
sortDirection
|
|
20
|
+
} = sorted;
|
|
21
|
+
|
|
22
|
+
const toggleColumnSort = columnId => {
|
|
23
|
+
setSorted(s => {
|
|
24
|
+
const newState = { ...s,
|
|
25
|
+
sortColumn: columnId
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
if (s.sortColumn === columnId) {
|
|
29
|
+
newState.sortDirection = s.sortDirection === 'ascending' ? 'descending' : 'ascending';
|
|
30
|
+
} else {
|
|
31
|
+
newState.sortDirection = 'ascending';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
onSortChange === null || onSortChange === void 0 ? void 0 : onSortChange(newState);
|
|
35
|
+
return newState;
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const setColumnSort = (nextSortColumn, nextSortDirection) => {
|
|
40
|
+
const newState = {
|
|
41
|
+
sortColumn: nextSortColumn,
|
|
42
|
+
sortDirection: nextSortDirection
|
|
43
|
+
};
|
|
44
|
+
onSortChange === null || onSortChange === void 0 ? void 0 : onSortChange(newState);
|
|
45
|
+
setSorted(newState);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const sort = items => items.slice().sort((a, b) => {
|
|
49
|
+
const sortColumnDef = columns.find(column => column.columnId === sortColumn);
|
|
50
|
+
|
|
51
|
+
if (!(sortColumnDef === null || sortColumnDef === void 0 ? void 0 : sortColumnDef.compare)) {
|
|
52
|
+
return 0;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const mod = sortDirection === 'ascending' ? 1 : -1;
|
|
56
|
+
return sortColumnDef.compare(a, b) * mod;
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const getSortDirection = columnId => {
|
|
60
|
+
return sortColumn === columnId ? sortDirection : undefined;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
sortColumn,
|
|
65
|
+
sortDirection,
|
|
66
|
+
sort,
|
|
67
|
+
setColumnSort,
|
|
68
|
+
toggleColumnSort,
|
|
69
|
+
getSortDirection
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=useSort.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["hooks/useSort.ts"],"names":[],"mappings":"AAAA,SAAS,oBAAT,QAAqC,2BAArC;AAUA,OAAM,SAAU,OAAV,CAAyB,OAAzB,EAAuD;EAC3D,MAAM;IAAE,OAAF;IAAW,SAAX;IAAsB,gBAAtB;IAAwC;EAAxC,IAAyD,OAA/D;EAEA,MAAM,CAAC,MAAD,EAAS,SAAT,IAAsB,oBAAoB,CAAY;IAC1D,YAAY,EAAE;MACZ,aAAa,EAAE,WADH;MAEZ,UAAU,EAAE;IAFA,CAD4C;IAK1D,YAAY,EAAE,gBAL4C;IAM1D,KAAK,EAAE;EANmD,CAAZ,CAAhD;EASA,MAAM;IAAE,UAAF;IAAc;EAAd,IAAgC,MAAtC;;EAEA,MAAM,gBAAgB,GAAI,QAAD,IAAmC;IAC1D,SAAS,CAAC,CAAC,IAAG;MACZ,MAAM,QAAQ,GAAG,EAAE,GAAG,CAAL;QAAQ,UAAU,EAAE;MAApB,CAAjB;;MACA,IAAI,CAAC,CAAC,UAAF,KAAiB,QAArB,EAA+B;QAC7B,QAAQ,CAAC,aAAT,GAAyB,CAAC,CAAC,aAAF,KAAoB,WAApB,GAAkC,YAAlC,GAAiD,WAA1E;MACD,CAFD,MAEO;QACL,QAAQ,CAAC,aAAT,GAAyB,WAAzB;MACD;;MAED,YAAY,KAAA,IAAZ,IAAA,YAAY,KAAA,KAAA,CAAZ,GAAY,KAAA,CAAZ,GAAA,YAAY,CAAG,QAAH,CAAZ;MACA,OAAO,QAAP;IACD,CAVQ,CAAT;EAWD,CAZD;;EAcA,MAAM,aAAa,GAAmD,CAAC,cAAD,EAAiB,iBAAjB,KAAsC;IAC1G,MAAM,QAAQ,GAAG;MAAE,UAAU,EAAE,cAAd;MAA8B,aAAa,EAAE;IAA7C,CAAjB;IACA,YAAY,KAAA,IAAZ,IAAA,YAAY,KAAA,KAAA,CAAZ,GAAY,KAAA,CAAZ,GAAA,YAAY,CAAG,QAAH,CAAZ;IACA,SAAS,CAAC,QAAD,CAAT;EACD,CAJD;;EAMA,MAAM,IAAI,GAAI,KAAD,IACX,KAAK,CAAC,KAAN,GAAc,IAAd,CAAmB,CAAC,CAAD,EAAI,CAAJ,KAAS;IAC1B,MAAM,aAAa,GAAG,OAAO,CAAC,IAAR,CAAa,MAAM,IAAI,MAAM,CAAC,QAAP,KAAoB,UAA3C,CAAtB;;IACA,IAAI,EAAC,aAAa,KAAA,IAAb,IAAA,aAAa,KAAA,KAAA,CAAb,GAAa,KAAA,CAAb,GAAA,aAAa,CAAE,OAAhB,CAAJ,EAA6B;MAC3B,OAAO,CAAP;IACD;;IAED,MAAM,GAAG,GAAG,aAAa,KAAK,WAAlB,GAAgC,CAAhC,GAAoC,CAAC,CAAjD;IACA,OAAO,aAAa,CAAC,OAAd,CAAsB,CAAtB,EAAyB,CAAzB,IAA8B,GAArC;EACD,CARD,CADF;;EAWA,MAAM,gBAAgB,GAAuD,QAAD,IAAuB;IACjG,OAAO,UAAU,KAAK,QAAf,GAA0B,aAA1B,GAA0C,SAAjD;EACD,CAFD;;EAIA,OAAO;IACL,UADK;IAEL,aAFK;IAGL,IAHK;IAIL,aAJK;IAKL,gBALK;IAML;EANK,CAAP;AAQD","sourcesContent":["import { useControllableState } from '@fluentui/react-utilities';\nimport type { ColumnDefinition, ColumnId, OnSortChangeCallback, SortState, TableSortStateInternal } from './types';\n\ninterface UseSortOptions<TItem> {\n columns: ColumnDefinition<TItem>[];\n sortState?: SortState;\n defaultSortState?: SortState;\n onSortChange?: OnSortChangeCallback;\n}\n\nexport function useSort<TItem>(options: UseSortOptions<TItem>): TableSortStateInternal<TItem> {\n const { columns, sortState, defaultSortState, onSortChange } = options;\n\n const [sorted, setSorted] = useControllableState<SortState>({\n initialState: {\n sortDirection: 'ascending' as const,\n sortColumn: undefined,\n },\n defaultState: defaultSortState,\n state: sortState,\n });\n\n const { sortColumn, sortDirection } = sorted;\n\n const toggleColumnSort = (columnId: ColumnId | undefined) => {\n setSorted(s => {\n const newState = { ...s, sortColumn: columnId };\n if (s.sortColumn === columnId) {\n newState.sortDirection = s.sortDirection === 'ascending' ? 'descending' : 'ascending';\n } else {\n newState.sortDirection = 'ascending';\n }\n\n onSortChange?.(newState);\n return newState;\n });\n };\n\n const setColumnSort: TableSortStateInternal<TItem>['setColumnSort'] = (nextSortColumn, nextSortDirection) => {\n const newState = { sortColumn: nextSortColumn, sortDirection: nextSortDirection };\n onSortChange?.(newState);\n setSorted(newState);\n };\n\n const sort = (items: TItem[]) =>\n items.slice().sort((a, b) => {\n const sortColumnDef = columns.find(column => column.columnId === sortColumn);\n if (!sortColumnDef?.compare) {\n return 0;\n }\n\n const mod = sortDirection === 'ascending' ? 1 : -1;\n return sortColumnDef.compare(a, b) * mod;\n });\n\n const getSortDirection: TableSortStateInternal<TItem>['getSortDirection'] = (columnId: ColumnId) => {\n return sortColumn === columnId ? sortDirection : undefined;\n };\n\n return {\n sortColumn,\n sortDirection,\n sort,\n setColumnSort,\n toggleColumnSort,\n getSortDirection,\n };\n}\n"],"sourceRoot":"../src/"}
|