@perses-dev/components 0.35.0 → 0.36.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ContentWithLegend/ContentWithLegend.d.ts +1 -1
- package/dist/ContentWithLegend/ContentWithLegend.d.ts.map +1 -1
- package/dist/ContentWithLegend/ContentWithLegend.js +4 -2
- package/dist/ContentWithLegend/ContentWithLegend.js.map +1 -1
- package/dist/ContentWithLegend/model/content-with-legend-model.d.ts +9 -3
- package/dist/ContentWithLegend/model/content-with-legend-model.d.ts.map +1 -1
- package/dist/ContentWithLegend/model/content-with-legend-model.js +17 -7
- package/dist/ContentWithLegend/model/content-with-legend-model.js.map +1 -1
- package/dist/DateTimeRangePicker/DateTimeRangePicker.d.ts +1 -1
- package/dist/DateTimeRangePicker/DateTimeRangePicker.d.ts.map +1 -1
- package/dist/DateTimeRangePicker/DateTimeRangePicker.js.map +1 -1
- package/dist/DateTimeRangePicker/TimeRangeSelector.d.ts +2 -5
- package/dist/DateTimeRangePicker/TimeRangeSelector.d.ts.map +1 -1
- package/dist/DateTimeRangePicker/TimeRangeSelector.js.map +1 -1
- package/dist/GaugeChart/GaugeChart.d.ts +1 -1
- package/dist/GaugeChart/GaugeChart.d.ts.map +1 -1
- package/dist/GaugeChart/GaugeChart.js +1 -2
- package/dist/GaugeChart/GaugeChart.js.map +1 -1
- package/dist/Legend/CompactLegend.d.ts +3 -1
- package/dist/Legend/CompactLegend.d.ts.map +1 -1
- package/dist/Legend/CompactLegend.js +5 -2
- package/dist/Legend/CompactLegend.js.map +1 -1
- package/dist/Legend/Legend.d.ts +11 -2
- package/dist/Legend/Legend.d.ts.map +1 -1
- package/dist/Legend/Legend.js +4 -2
- package/dist/Legend/Legend.js.map +1 -1
- package/dist/Legend/ListLegend.d.ts +3 -1
- package/dist/Legend/ListLegend.d.ts.map +1 -1
- package/dist/Legend/ListLegend.js +5 -4
- package/dist/Legend/ListLegend.js.map +1 -1
- package/dist/Legend/ListLegendItem.d.ts +15 -2
- package/dist/Legend/ListLegendItem.d.ts.map +1 -1
- package/dist/Legend/ListLegendItem.js +17 -5
- package/dist/Legend/ListLegendItem.js.map +1 -1
- package/dist/Legend/TableLegend.d.ts +4 -2
- package/dist/Legend/TableLegend.d.ts.map +1 -1
- package/dist/Legend/TableLegend.js +8 -2
- package/dist/Legend/TableLegend.js.map +1 -1
- package/dist/LineChart/LineChart.d.ts +17 -3
- package/dist/LineChart/LineChart.d.ts.map +1 -1
- package/dist/LineChart/LineChart.js +33 -7
- package/dist/LineChart/LineChart.js.map +1 -1
- package/dist/LineChart/index.d.ts +1 -1
- package/dist/LineChart/index.d.ts.map +1 -1
- package/dist/LineChart/index.js +1 -0
- package/dist/LineChart/index.js.map +1 -1
- package/dist/LineChart/utils.d.ts +2 -1
- package/dist/LineChart/utils.d.ts.map +1 -1
- package/dist/LineChart/utils.js +14 -1
- package/dist/LineChart/utils.js.map +1 -1
- package/dist/RefreshIntervalPicker/RefreshIntervalPicker.d.ts +12 -0
- package/dist/RefreshIntervalPicker/RefreshIntervalPicker.d.ts.map +1 -0
- package/dist/RefreshIntervalPicker/RefreshIntervalPicker.js +45 -0
- package/dist/RefreshIntervalPicker/RefreshIntervalPicker.js.map +1 -0
- package/dist/RefreshIntervalPicker/index.d.ts +2 -0
- package/dist/RefreshIntervalPicker/index.d.ts.map +1 -0
- package/dist/{model/units → RefreshIntervalPicker}/index.js +1 -3
- package/dist/RefreshIntervalPicker/index.js.map +1 -0
- package/dist/StatChart/StatChart.d.ts +1 -1
- package/dist/StatChart/StatChart.d.ts.map +1 -1
- package/dist/StatChart/StatChart.js +1 -1
- package/dist/StatChart/StatChart.js.map +1 -1
- package/dist/Table/InnerTable.js +2 -2
- package/dist/Table/InnerTable.js.map +1 -1
- package/dist/Table/Table.d.ts +1 -1
- package/dist/Table/Table.d.ts.map +1 -1
- package/dist/Table/Table.js +57 -9
- package/dist/Table/Table.js.map +1 -1
- package/dist/Table/TableCell.d.ts +11 -1
- package/dist/Table/TableCell.d.ts.map +1 -1
- package/dist/Table/TableCell.js +8 -3
- package/dist/Table/TableCell.js.map +1 -1
- package/dist/Table/TableCheckbox.js +1 -1
- package/dist/Table/TableCheckbox.js.map +1 -1
- package/dist/Table/TableHeaderCell.d.ts +23 -0
- package/dist/Table/TableHeaderCell.d.ts.map +1 -0
- package/dist/Table/TableHeaderCell.js +53 -0
- package/dist/Table/TableHeaderCell.js.map +1 -0
- package/dist/Table/VirtualizedTable.d.ts +3 -3
- package/dist/Table/VirtualizedTable.d.ts.map +1 -1
- package/dist/Table/VirtualizedTable.js +43 -8
- package/dist/Table/VirtualizedTable.js.map +1 -1
- package/dist/Table/model/table-model.d.ts +71 -7
- package/dist/Table/model/table-model.d.ts.map +1 -1
- package/dist/Table/model/table-model.js +6 -2
- package/dist/Table/model/table-model.js.map +1 -1
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts +2 -1
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js +2 -1
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js.map +1 -1
- package/dist/TimeSeriesTooltip/nearby-series.d.ts +2 -1
- package/dist/TimeSeriesTooltip/nearby-series.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/nearby-series.js +2 -11
- package/dist/TimeSeriesTooltip/nearby-series.js.map +1 -1
- package/dist/UnitSelector/UnitSelector.d.ts +1 -1
- package/dist/UnitSelector/UnitSelector.d.ts.map +1 -1
- package/dist/UnitSelector/UnitSelector.js +1 -2
- package/dist/UnitSelector/UnitSelector.js.map +1 -1
- package/dist/cjs/ContentWithLegend/ContentWithLegend.js +4 -2
- package/dist/cjs/ContentWithLegend/model/content-with-legend-model.js +17 -7
- package/dist/cjs/GaugeChart/GaugeChart.js +2 -3
- package/dist/cjs/Legend/CompactLegend.js +5 -2
- package/dist/cjs/Legend/Legend.js +4 -2
- package/dist/cjs/Legend/ListLegend.js +5 -4
- package/dist/cjs/Legend/ListLegendItem.js +17 -5
- package/dist/cjs/Legend/TableLegend.js +8 -2
- package/dist/cjs/LineChart/LineChart.js +31 -5
- package/dist/cjs/LineChart/index.js +1 -0
- package/dist/cjs/LineChart/utils.js +14 -3
- package/dist/cjs/RefreshIntervalPicker/RefreshIntervalPicker.js +51 -0
- package/dist/cjs/{model/units → RefreshIntervalPicker}/index.js +1 -3
- package/dist/cjs/StatChart/StatChart.js +4 -4
- package/dist/cjs/Table/InnerTable.js +2 -2
- package/dist/cjs/Table/Table.js +56 -8
- package/dist/cjs/Table/TableCell.js +8 -3
- package/dist/cjs/Table/TableCheckbox.js +1 -1
- package/dist/cjs/Table/TableHeaderCell.js +59 -0
- package/dist/cjs/Table/VirtualizedTable.js +43 -8
- package/dist/cjs/Table/model/table-model.js +6 -2
- package/dist/cjs/TimeSeriesTooltip/TimeSeriesTooltip.js +2 -1
- package/dist/cjs/TimeSeriesTooltip/nearby-series.js +2 -11
- package/dist/cjs/UnitSelector/UnitSelector.js +6 -7
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/model/index.js +1 -1
- package/dist/{model/units/types.js → cjs/model/timeOption.js} +4 -10
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/model/index.d.ts +1 -1
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +1 -1
- package/dist/model/index.js.map +1 -1
- package/dist/model/theme.d.ts +1 -4
- package/dist/model/theme.d.ts.map +1 -1
- package/dist/model/theme.js.map +1 -1
- package/dist/model/timeOption.d.ts +6 -0
- package/dist/model/timeOption.d.ts.map +1 -0
- package/dist/model/{units/constants.js → timeOption.js} +2 -4
- package/dist/model/timeOption.js.map +1 -0
- package/package.json +3 -4
- package/dist/cjs/model/units/bytes.js +0 -84
- package/dist/cjs/model/units/constants.js +0 -23
- package/dist/cjs/model/units/decimal.js +0 -62
- package/dist/cjs/model/units/percent.js +0 -73
- package/dist/cjs/model/units/time.js +0 -105
- package/dist/cjs/model/units/types.js +0 -28
- package/dist/cjs/model/units/units.js +0 -101
- package/dist/cjs/model/units/utils.js +0 -42
- package/dist/model/units/bytes.d.ts +0 -13
- package/dist/model/units/bytes.d.ts.map +0 -1
- package/dist/model/units/bytes.js +0 -66
- package/dist/model/units/bytes.js.map +0 -1
- package/dist/model/units/constants.d.ts +0 -2
- package/dist/model/units/constants.d.ts.map +0 -1
- package/dist/model/units/constants.js.map +0 -1
- package/dist/model/units/decimal.d.ts +0 -13
- package/dist/model/units/decimal.d.ts.map +0 -1
- package/dist/model/units/decimal.js +0 -49
- package/dist/model/units/decimal.js.map +0 -1
- package/dist/model/units/index.d.ts +0 -4
- package/dist/model/units/index.d.ts.map +0 -1
- package/dist/model/units/index.js.map +0 -1
- package/dist/model/units/percent.d.ts +0 -12
- package/dist/model/units/percent.d.ts.map +0 -1
- package/dist/model/units/percent.js +0 -60
- package/dist/model/units/percent.js.map +0 -1
- package/dist/model/units/time.d.ts +0 -22
- package/dist/model/units/time.d.ts.map +0 -1
- package/dist/model/units/time.js +0 -91
- package/dist/model/units/time.js.map +0 -1
- package/dist/model/units/types.d.ts +0 -47
- package/dist/model/units/types.d.ts.map +0 -1
- package/dist/model/units/types.js.map +0 -1
- package/dist/model/units/units.d.ts +0 -40
- package/dist/model/units/units.d.ts.map +0 -1
- package/dist/model/units/units.js +0 -80
- package/dist/model/units/units.js.map +0 -1
- package/dist/model/units/utils.d.ts +0 -4
- package/dist/model/units/utils.d.ts.map +0 -1
- package/dist/model/units/utils.js +0 -32
- package/dist/model/units/utils.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Table/TableCell.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { TableCell as MuiTableCell, styled, TableCellProps as MuiTableCellProps, Box, useTheme } from '@mui/material';\nimport { useEffect, useRef } from 'react';\nimport { TableCellAlignment, TableDensity, getTableCellLayout } from './model/table-model';\n\nconst StyledMuiTableCell = styled(MuiTableCell)(({ theme }) => ({\n padding: 0,\n backgroundColor: 'inherit',\n\n '&.MuiTableCell-head': {\n // Important to avoid scrolling behind the header showing through.\n backgroundColor: theme.palette.background.default,\n },\n '&:focus-visible': {\n outline: `solid 1px ${theme.palette.primary.main}`,\n // Move inward a little to avoid getting cut off when focusing on items\n // at the edge of the table.\n outlineOffset: '-1px',\n borderRadius: 0,\n },\n}));\n\nexport interface TableCellProps extends Omit<MuiTableCellProps, 'tabIndex' | 'align'> {\n density: TableDensity;\n\n // These values are used to adjust the spacing for the first/last columns.\n isLastColumn: boolean;\n isFirstColumn: boolean;\n\n align?: TableCellAlignment;\n\n /**\n * How the cell should behave related to focus.\n * - `trigger-focus`: the cell should be auto-focused when it renders.\n * - `focus-next`: the cell should have tabindex=\"0\", so that it will be\n * focused the next time someone tabs with a keyboard.\n * - `none`: the cell should have tabindex=\"-1\", so it is not focused by\n * keyboard interactions at this time.\n */\n focusState?: 'trigger-focus' | 'focus-next' | 'none';\n onFocusTrigger?: (e: React.MouseEvent<HTMLTableCellElement> | React.KeyboardEvent<HTMLTableCellElement>) => void;\n}\n\nexport function TableCell({\n children,\n density,\n variant,\n width,\n focusState = 'none',\n onFocusTrigger,\n isFirstColumn,\n isLastColumn,\n ...otherProps\n}: TableCellProps) {\n const theme = useTheme();\n\n const elRef = useRef<HTMLTableCellElement>();\n\n const isHeader = variant === 'head';\n\n useEffect(() => {\n if (focusState === 'trigger-focus' && elRef.current) {\n elRef.current.focus();\n }\n }, [focusState]);\n\n const handleFocus: React.FocusEventHandler<HTMLTableCellElement> = (e) => {\n // From https://zellwk.com/blog/keyboard-focusable-elements/\n const nestedFocusTarget = e.currentTarget?.querySelector<HTMLElement>(\n 'a[href], button, input, textarea, select, details'\n );\n if (nestedFocusTarget) {\n // If the cell has a focusable child, focus it instead. Mostly used for\n // checkbox cells, but could have other uses.\n nestedFocusTarget.focus();\n }\n };\n\n const handleInteractionFocusTrigger: TableCellProps['onFocusTrigger'] = (e) => {\n // We use `onClick` and `onKeyUp` events instead of `onFocus` because of\n // some ordering issues with when the browser calls events and how this\n // plays with the triggering of focus with keyboard interactions.\n // These report that a focus event happened, so we can adjust the current\n // tabindex and focuses to the right cell.\n onFocusTrigger?.(e);\n };\n\n return (\n <StyledMuiTableCell\n {...otherProps}\n // Modify the tab index based on the currently focused cell. It's important\n // to avoid having tabindex 0 on everything because it essentially traps\n // a keyboard user in the table until they hit \"tab\" for every single\n // cell.\n tabIndex={focusState !== 'none' ? 0 : -1}\n onFocus={handleFocus}\n onClick={handleInteractionFocusTrigger}\n onKeyUp={handleInteractionFocusTrigger}\n sx={{\n width: width,\n borderBottom: isHeader\n ? (theme) => `solid 1px ${theme.palette.grey[100]}`\n : `solid 1px ${theme.palette.grey[50]}`,\n }}\n ref={elRef}\n >\n <Box\n sx={{\n ...getTableCellLayout(theme, density, { isLastColumn, isFirstColumn }),\n position: 'relative',\n\n // Text truncation. Currently enforced on all cells. We may control\n // this with a prop on column config in the future.\n whiteSpace: 'nowrap',\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n }}\n >\n {children}\n </Box>\n </StyledMuiTableCell>\n );\n}\n"],"names":["TableCell","MuiTableCell","styled","Box","useTheme","useEffect","useRef","getTableCellLayout","StyledMuiTableCell","theme","padding","backgroundColor","palette","background","default","outline","primary","main","outlineOffset","borderRadius","children","density","variant","width","focusState","onFocusTrigger","isFirstColumn","isLastColumn","otherProps","elRef","isHeader","current","focus","handleFocus","e","nestedFocusTarget","currentTarget","querySelector","handleInteractionFocusTrigger","tabIndex","onFocus","onClick","onKeyUp","sx","borderBottom","grey","ref","position","whiteSpace","overflow","textOverflow"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,SAAS,IAAIC,YAAY,EAAEC,MAAM,EAAuCC,GAAG,EAAEC,QAAQ,QAAQ,eAAe,CAAC;AACtH,SAASC,SAAS,EAAEC,MAAM,QAAQ,OAAO,CAAC;AAC1C,SAA2CC,kBAAkB,QAAQ,qBAAqB,CAAC;AAE3F,MAAMC,kBAAkB,GAAGN,MAAM,CAACD,YAAY,CAAC,CAAC,CAAC,EAAEQ,KAAK,CAAA,EAAE,GAAM,CAAA;QAC9DC,OAAO,EAAE,CAAC;QACVC,eAAe,EAAE,SAAS;QAE1B,qBAAqB,EAAE;YACrB,kEAAkE;YAClEA,eAAe,EAAEF,KAAK,CAACG,OAAO,CAACC,UAAU,CAACC,OAAO;SAClD;QACD,iBAAiB,EAAE;YACjBC,OAAO,EAAE,CAAC,UAAU,EAAEN,KAAK,CAACG,OAAO,CAACI,OAAO,CAACC,IAAI,CAAC,CAAC;YAClD,uEAAuE;YACvE,4BAA4B;YAC5BC,aAAa,EAAE,MAAM;YACrBC,YAAY,EAAE,CAAC;SAChB;KACF,CAAA,AAAC,CAAC,AAAC;
|
|
1
|
+
{"version":3,"sources":["../../src/Table/TableCell.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { TableCell as MuiTableCell, styled, TableCellProps as MuiTableCellProps, Box, useTheme } from '@mui/material';\nimport { useEffect, useRef } from 'react';\nimport { TableCellAlignment, TableDensity, getTableCellLayout } from './model/table-model';\n\nconst StyledMuiTableCell = styled(MuiTableCell)(({ theme }) => ({\n padding: 0,\n backgroundColor: 'inherit',\n\n '&.MuiTableCell-head': {\n // Important to avoid scrolling behind the header showing through.\n backgroundColor: theme.palette.background.default,\n },\n '&:focus-visible': {\n outline: `solid 1px ${theme.palette.primary.main}`,\n // Move inward a little to avoid getting cut off when focusing on items\n // at the edge of the table.\n outlineOffset: '-1px',\n borderRadius: 0,\n },\n}));\n\nexport interface TableCellProps extends Omit<MuiTableCellProps, 'tabIndex' | 'align'> {\n density: TableDensity;\n\n // These values are used to adjust the spacing for the first/last columns.\n isLastColumn: boolean;\n isFirstColumn: boolean;\n\n align?: TableCellAlignment;\n\n /**\n * Additional information to be displayed when hovering over the cell. This\n * may be the full cell value (e.g. to enable the user to see the full value\n * if it is ellipsized to fit into the space) or some other descriptive text\n * that is useful for the user.\n *\n * The hover behavior is currently managed with the `title` attribute, but this\n * may be changed to a tooltip in the future.\n */\n description?: string;\n\n /**\n * How the cell should behave related to focus.\n * - `trigger-focus`: the cell should be auto-focused when it renders.\n * - `focus-next`: the cell should have tabindex=\"0\", so that it will be\n * focused the next time someone tabs with a keyboard.\n * - `none`: the cell should have tabindex=\"-1\", so it is not focused by\n * keyboard interactions at this time.\n */\n focusState?: 'trigger-focus' | 'focus-next' | 'none';\n onFocusTrigger?: (e: React.MouseEvent<HTMLTableCellElement> | React.KeyboardEvent<HTMLTableCellElement>) => void;\n}\n\nexport function TableCell({\n children,\n density,\n variant,\n width,\n focusState = 'none',\n onFocusTrigger,\n isFirstColumn,\n isLastColumn,\n description,\n ...otherProps\n}: TableCellProps) {\n const theme = useTheme();\n\n const elRef = useRef<HTMLTableCellElement>();\n\n const isHeader = variant === 'head';\n\n useEffect(() => {\n if (focusState === 'trigger-focus' && elRef.current) {\n elRef.current.focus();\n }\n }, [focusState]);\n\n const handleFocus: React.FocusEventHandler<HTMLTableCellElement> = (e) => {\n // From https://zellwk.com/blog/keyboard-focusable-elements/\n const nestedFocusTarget = e.currentTarget?.querySelector<HTMLElement>(\n 'a[href], button, input, textarea, select, details,[role=\"button\"]'\n );\n if (nestedFocusTarget) {\n // If the cell has a focusable child, focus it instead. Mostly used for\n // checkbox cells, but could have other uses.\n nestedFocusTarget.focus();\n }\n };\n\n const handleInteractionFocusTrigger: TableCellProps['onFocusTrigger'] = (e) => {\n // We use `onClick` and `onKeyUp` events instead of `onFocus` because of\n // some ordering issues with when the browser calls events and how this\n // plays with the triggering of focus with keyboard interactions.\n // These report that a focus event happened, so we can adjust the current\n // tabindex and focuses to the right cell.\n onFocusTrigger?.(e);\n };\n\n return (\n <StyledMuiTableCell\n {...otherProps}\n // Modify the tab index based on the currently focused cell. It's important\n // to avoid having tabindex 0 on everything because it essentially traps\n // a keyboard user in the table until they hit \"tab\" for every single\n // cell.\n tabIndex={focusState !== 'none' ? 0 : -1}\n onFocus={handleFocus}\n onClick={handleInteractionFocusTrigger}\n onKeyUp={handleInteractionFocusTrigger}\n sx={{\n width: width,\n borderBottom: isHeader\n ? (theme) => `solid 1px ${theme.palette.grey[100]}`\n : `solid 1px ${theme.palette.grey[50]}`,\n }}\n ref={elRef}\n >\n <Box\n sx={{\n ...getTableCellLayout(theme, density, { isLastColumn, isFirstColumn }),\n position: 'relative',\n\n // Text truncation. Currently enforced on all cells. We may control\n // this with a prop on column config in the future.\n whiteSpace: 'nowrap',\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n\n // Need to inherit from the MUI cell because this manages some ordering\n // that the `TableSortLabel` uses to determine the location of the icon\n // in headers.\n flexDirection: 'inherit',\n }}\n title={description}\n >\n {children}\n </Box>\n </StyledMuiTableCell>\n );\n}\n"],"names":["TableCell","MuiTableCell","styled","Box","useTheme","useEffect","useRef","getTableCellLayout","StyledMuiTableCell","theme","padding","backgroundColor","palette","background","default","outline","primary","main","outlineOffset","borderRadius","children","density","variant","width","focusState","onFocusTrigger","isFirstColumn","isLastColumn","description","otherProps","elRef","isHeader","current","focus","handleFocus","e","nestedFocusTarget","currentTarget","querySelector","handleInteractionFocusTrigger","tabIndex","onFocus","onClick","onKeyUp","sx","borderBottom","grey","ref","position","whiteSpace","overflow","textOverflow","flexDirection","title"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,SAAS,IAAIC,YAAY,EAAEC,MAAM,EAAuCC,GAAG,EAAEC,QAAQ,QAAQ,eAAe,CAAC;AACtH,SAASC,SAAS,EAAEC,MAAM,QAAQ,OAAO,CAAC;AAC1C,SAA2CC,kBAAkB,QAAQ,qBAAqB,CAAC;AAE3F,MAAMC,kBAAkB,GAAGN,MAAM,CAACD,YAAY,CAAC,CAAC,CAAC,EAAEQ,KAAK,CAAA,EAAE,GAAM,CAAA;QAC9DC,OAAO,EAAE,CAAC;QACVC,eAAe,EAAE,SAAS;QAE1B,qBAAqB,EAAE;YACrB,kEAAkE;YAClEA,eAAe,EAAEF,KAAK,CAACG,OAAO,CAACC,UAAU,CAACC,OAAO;SAClD;QACD,iBAAiB,EAAE;YACjBC,OAAO,EAAE,CAAC,UAAU,EAAEN,KAAK,CAACG,OAAO,CAACI,OAAO,CAACC,IAAI,CAAC,CAAC;YAClD,uEAAuE;YACvE,4BAA4B;YAC5BC,aAAa,EAAE,MAAM;YACrBC,YAAY,EAAE,CAAC;SAChB;KACF,CAAA,AAAC,CAAC,AAAC;AAkCJ,OAAO,SAASnB,SAAS,CAAC,EACxBoB,QAAQ,CAAA,EACRC,OAAO,CAAA,EACPC,OAAO,CAAA,EAC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AAK,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC;QACxCiB,OAAO,EAAEP,WAAW;QACpBQ,OAAO,EAAEH,6BAA6B;QACtCI,OAAO,EAAEJ,6BAA6B;QACtCK,EAAE,EAAE;YACFrB,KAAK,EAAEA,KAAK;YACZsB,YAAY,EAAEd,QAAQ,GAClB,CAACtB,KAAK,GAAK,CAAC,UAAU,EAAEA,KAAK,CAACG,OAAO,CAACkC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GACjD,CAAC,UAAU,EAAErC,KAAK,CAACG,OAAO,CAACkC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;SAC1C;QACDC,GAAG,EAAEjB,KAAK;kBAEV,cAAA,KAAC3B,GAAG;YACFyC,EAAE,EAAE;gBACF,GAAGrC,kBAAkB,CAACE,KAAK,EAAEY,OAAO,EAAE;oBAAEM,YAAY;oBAAED,aAAa;iBAAE,CAAC;gBACtEsB,QAAQ,EAAE,UAAU;gBAEpB,mEAAmE;gBACnE,mDAAmD;gBACnDC,UAAU,EAAE,QAAQ;gBACpBC,QAAQ,EAAE,QAAQ;gBAClBC,YAAY,EAAE,UAAU;gBAExB,uEAAuE;gBACvE,uEAAuE;gBACvE,cAAc;gBACdC,aAAa,EAAE,SAAS;aACzB;YACDC,KAAK,EAAEzB,WAAW;sBAEjBR,QAAQ;UACL;MACa,CACrB;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Table/TableCheckbox.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Checkbox, CheckboxProps, alpha } from '@mui/material';\nimport { TableDensity } from './model/table-model';\n\nexport interface TableCheckboxProps extends Pick<CheckboxProps, 'checked' | 'indeterminate' | 'onChange'> {\n color?: string;\n density: TableDensity;\n}\n\nexport function TableCheckbox({ color, density, ...otherProps }: TableCheckboxProps) {\n const isCompact = density === 'compact';\n\n return (\n <Checkbox\n size={isCompact ? 'small' : 'medium'}\n {...otherProps}\n // Disable ripple and set background color below because of some issues\n // with re-rendering with the keyboard interactions that causes the ripple\n // animation to stutter.\n focusRipple={false}\n // Tab index is handled by the overall keyboard interactions for the table\n // to avoid trapping a keyboard user in a table by requiring them to tab\n // through every single checkbox.\n tabIndex={-1}\n sx={{\n color: color,\n\n padding: (theme) => theme.spacing(isCompact ? 0.25 : 0.5),\n\n // Centering.\n position: 'absolute',\n top: '50%',\n left: '50%',\n transform: 'translate(-50%, -50%)',\n\n '&.Mui-checked': {\n color: color,\n },\n\n '&.Mui-focusVisible': {\n background: color ? alpha(color, 0.5) : undefined,\n },\n\n '& .MuiSvgIcon-root': { fontSize: isCompact ?
|
|
1
|
+
{"version":3,"sources":["../../src/Table/TableCheckbox.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Checkbox, CheckboxProps, alpha } from '@mui/material';\nimport { TableDensity } from './model/table-model';\n\nexport interface TableCheckboxProps extends Pick<CheckboxProps, 'checked' | 'indeterminate' | 'onChange'> {\n color?: string;\n density: TableDensity;\n}\n\nexport function TableCheckbox({ color, density, ...otherProps }: TableCheckboxProps) {\n const isCompact = density === 'compact';\n\n return (\n <Checkbox\n size={isCompact ? 'small' : 'medium'}\n {...otherProps}\n // Disable ripple and set background color below because of some issues\n // with re-rendering with the keyboard interactions that causes the ripple\n // animation to stutter.\n focusRipple={false}\n // Tab index is handled by the overall keyboard interactions for the table\n // to avoid trapping a keyboard user in a table by requiring them to tab\n // through every single checkbox.\n tabIndex={-1}\n sx={{\n color: color,\n\n padding: (theme) => theme.spacing(isCompact ? 0.25 : 0.5),\n\n // Centering.\n position: 'absolute',\n top: '50%',\n left: '50%',\n transform: 'translate(-50%, -50%)',\n\n '&.Mui-checked': {\n color: color,\n },\n\n '&.Mui-focusVisible': {\n background: color ? alpha(color, 0.5) : undefined,\n },\n\n '& .MuiSvgIcon-root': { fontSize: isCompact ? 16 : 18 },\n }}\n />\n );\n}\n"],"names":["Checkbox","alpha","TableCheckbox","color","density","otherProps","isCompact","size","focusRipple","tabIndex","sx","padding","theme","spacing","position","top","left","transform","background","undefined","fontSize"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,QAAQ,EAAiBC,KAAK,QAAQ,eAAe,CAAC;AAQ/D,OAAO,SAASC,aAAa,CAAC,EAAEC,KAAK,CAAA,EAAEC,OAAO,CAAA,EAAE,GAAGC,UAAU,EAAsB,EAAE;IACnF,MAAMC,SAAS,GAAGF,OAAO,KAAK,SAAS,AAAC;IAExC,qBACE,KAACJ,QAAQ;QACPO,IAAI,EAAED,SAAS,GAAG,OAAO,GAAG,QAAQ;QACnC,GAAGD,UAAU;QACd,uEAAuE;QACvE,0EAA0E;QAC1E,wBAAwB;QACxBG,WAAW,EAAE,KAAK;QAClB,0EAA0E;QAC1E,wEAAwE;QACxE,iCAAiC;QACjCC,QAAQ,EAAE,CAAC,CAAC;QACZC,EAAE,EAAE;YACFP,KAAK,EAAEA,KAAK;YAEZQ,OAAO,EAAE,CAACC,KAAK,GAAKA,KAAK,CAACC,OAAO,CAACP,SAAS,GAAG,IAAI,GAAG,GAAG,CAAC;YAEzD,aAAa;YACbQ,QAAQ,EAAE,UAAU;YACpBC,GAAG,EAAE,KAAK;YACVC,IAAI,EAAE,KAAK;YACXC,SAAS,EAAE,uBAAuB;YAElC,eAAe,EAAE;gBACfd,KAAK,EAAEA,KAAK;aACb;YAED,oBAAoB,EAAE;gBACpBe,UAAU,EAAEf,KAAK,GAAGF,KAAK,CAACE,KAAK,EAAE,GAAG,CAAC,GAAGgB,SAAS;aAClD;YAED,oBAAoB,EAAE;gBAAEC,QAAQ,EAAEd,SAAS,GAAG,EAAE,GAAG,EAAE;aAAE;SACxD;MACD,CACF;AACJ,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { SortDirection } from './model/table-model';
|
|
3
|
+
import { TableCellProps } from './TableCell';
|
|
4
|
+
export interface TableHeaderCellProps extends TableCellProps {
|
|
5
|
+
/**
|
|
6
|
+
* Handler called when a sort event is triggered.
|
|
7
|
+
* When specified, the header will include sorting interactions and indicators.
|
|
8
|
+
*/
|
|
9
|
+
onSort?: ((event: unknown) => void) | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* The current direction the header is sorted.
|
|
12
|
+
*/
|
|
13
|
+
sortDirection?: SortDirection;
|
|
14
|
+
/**
|
|
15
|
+
* The next direction the header will be sorted when another sort action
|
|
16
|
+
* is triggered via click/keyboard. This impacts some UI interactions (e.g.
|
|
17
|
+
* the direction of the sort arrow on hover f the column is currently
|
|
18
|
+
* unsorted.)
|
|
19
|
+
*/
|
|
20
|
+
nextSortDirection?: SortDirection;
|
|
21
|
+
}
|
|
22
|
+
export declare function TableHeaderCell({ onSort, sortDirection, nextSortDirection, children, ...cellProps }: TableHeaderCellProps): JSX.Element;
|
|
23
|
+
//# sourceMappingURL=TableHeaderCell.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TableHeaderCell.d.ts","sourceRoot":"","sources":["../../src/Table/TableHeaderCell.tsx"],"names":[],"mappings":";AAcA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAa,cAAc,EAAE,MAAM,aAAa,CAAC;AAExD,MAAM,WAAW,oBAAqB,SAAQ,cAAc;IAC1D;;;OAGG;IACH,MAAM,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IAEhD;;OAEG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC;IAE9B;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,aAAa,CAAC;CACnC;AAED,wBAAgB,eAAe,CAAC,EAC9B,MAAM,EACN,aAAa,EACb,iBAAiB,EACjB,QAAQ,EACR,GAAG,SAAS,EACb,EAAE,oBAAoB,eA4CtB"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
import { TableSortLabel, Typography, tableSortLabelClasses } from '@mui/material';
|
|
15
|
+
import { TableCell } from './TableCell';
|
|
16
|
+
export function TableHeaderCell({ onSort , sortDirection , nextSortDirection , children , ...cellProps }) {
|
|
17
|
+
const showSortLabel = !!onSort;
|
|
18
|
+
const headerText = /*#__PURE__*/ _jsx(Typography, {
|
|
19
|
+
noWrap: true,
|
|
20
|
+
variant: "inherit",
|
|
21
|
+
component: "div",
|
|
22
|
+
color: "inherit",
|
|
23
|
+
children: children
|
|
24
|
+
});
|
|
25
|
+
const isActive = !!sortDirection;
|
|
26
|
+
const direction = isActive ? sortDirection : nextSortDirection;
|
|
27
|
+
return /*#__PURE__*/ _jsx(TableCell, {
|
|
28
|
+
...cellProps,
|
|
29
|
+
children: showSortLabel ? /*#__PURE__*/ _jsx(TableSortLabel, {
|
|
30
|
+
onClick: onSort,
|
|
31
|
+
direction: direction,
|
|
32
|
+
active: isActive,
|
|
33
|
+
sx: {
|
|
34
|
+
// Overrides a default vertical alignment in the CSS that changes
|
|
35
|
+
// the header vertical rhythm in a way that's inconsistent with
|
|
36
|
+
// non-sorting headers.
|
|
37
|
+
verticalAlign: 'unset',
|
|
38
|
+
// Makes it possible to ellipsize the text if it's too long.
|
|
39
|
+
maxWidth: '100%',
|
|
40
|
+
// Make the arrow visible when focused using the keyboard to assist
|
|
41
|
+
// with a11y.
|
|
42
|
+
'&:focus-visible': {
|
|
43
|
+
[`& .${tableSortLabelClasses.icon}`]: {
|
|
44
|
+
opacity: isActive ? 1 : 0.5
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
children: headerText
|
|
49
|
+
}) : headerText
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=TableHeaderCell.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/Table/TableHeaderCell.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { TableSortLabel, Typography, tableSortLabelClasses } from '@mui/material';\nimport { SortDirection } from './model/table-model';\nimport { TableCell, TableCellProps } from './TableCell';\n\nexport interface TableHeaderCellProps extends TableCellProps {\n /**\n * Handler called when a sort event is triggered.\n * When specified, the header will include sorting interactions and indicators.\n */\n onSort?: ((event: unknown) => void) | undefined;\n\n /**\n * The current direction the header is sorted.\n */\n sortDirection?: SortDirection;\n\n /**\n * The next direction the header will be sorted when another sort action\n * is triggered via click/keyboard. This impacts some UI interactions (e.g.\n * the direction of the sort arrow on hover f the column is currently\n * unsorted.)\n */\n nextSortDirection?: SortDirection;\n}\n\nexport function TableHeaderCell({\n onSort,\n sortDirection,\n nextSortDirection,\n children,\n ...cellProps\n}: TableHeaderCellProps) {\n const showSortLabel = !!onSort;\n\n const headerText = (\n <Typography noWrap variant=\"inherit\" component=\"div\" color=\"inherit\">\n {children}\n </Typography>\n );\n\n const isActive = !!sortDirection;\n const direction = isActive ? sortDirection : nextSortDirection;\n\n return (\n <TableCell {...cellProps}>\n {showSortLabel ? (\n <TableSortLabel\n onClick={onSort}\n direction={direction}\n active={isActive}\n sx={{\n // Overrides a default vertical alignment in the CSS that changes\n // the header vertical rhythm in a way that's inconsistent with\n // non-sorting headers.\n verticalAlign: 'unset',\n\n // Makes it possible to ellipsize the text if it's too long.\n maxWidth: '100%',\n\n // Make the arrow visible when focused using the keyboard to assist\n // with a11y.\n '&:focus-visible': {\n [`& .${tableSortLabelClasses.icon}`]: {\n opacity: isActive ? 1 : 0.5,\n },\n },\n }}\n >\n {headerText}\n </TableSortLabel>\n ) : (\n headerText\n )}\n </TableCell>\n );\n}\n"],"names":["TableSortLabel","Typography","tableSortLabelClasses","TableCell","TableHeaderCell","onSort","sortDirection","nextSortDirection","children","cellProps","showSortLabel","headerText","noWrap","variant","component","color","isActive","direction","onClick","active","sx","verticalAlign","maxWidth","icon","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AAG;qBAC5B;iBACF;aACF;sBAEAL,UAAU;UACI,GAEjBA,UAAU,AACX;MACS,CACZ;AACJ,CAAC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { Column, HeaderGroup, Row } from '@tanstack/react-table';
|
|
3
3
|
import { TableProps } from './model/table-model';
|
|
4
|
-
export declare type VirtualizedTableProps<TableData> = Required<Pick<TableProps<TableData>, 'height' | 'width' | 'density'>> & {
|
|
5
|
-
onRowClick: (id: string) => void;
|
|
4
|
+
export declare type VirtualizedTableProps<TableData> = Required<Pick<TableProps<TableData>, 'height' | 'width' | 'density'>> & Pick<TableProps<TableData>, 'onRowMouseOver' | 'onRowMouseOut'> & {
|
|
5
|
+
onRowClick: (e: React.MouseEvent<HTMLDivElement, MouseEvent>, id: string) => void;
|
|
6
6
|
rows: Array<Row<TableData>>;
|
|
7
7
|
columns: Array<Column<TableData, unknown>>;
|
|
8
8
|
headers: Array<HeaderGroup<TableData>>;
|
|
9
9
|
};
|
|
10
|
-
export declare function VirtualizedTable<TableData>({ width, height, density, onRowClick, rows, columns, headers, }: VirtualizedTableProps<TableData>): JSX.Element;
|
|
10
|
+
export declare function VirtualizedTable<TableData>({ width, height, density, onRowClick, onRowMouseOver, onRowMouseOut, rows, columns, headers, }: VirtualizedTableProps<TableData>): JSX.Element;
|
|
11
11
|
//# sourceMappingURL=VirtualizedTable.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VirtualizedTable.d.ts","sourceRoot":"","sources":["../../src/Table/VirtualizedTable.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,EAAc,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"VirtualizedTable.d.ts","sourceRoot":"","sources":["../../src/Table/VirtualizedTable.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,EAAc,MAAM,uBAAuB,CAAC;AAW7E,OAAO,EAAE,UAAU,EAAqB,MAAM,qBAAqB,CAAC;AAQpE,oBAAY,qBAAqB,CAAC,SAAS,IAAI,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,QAAQ,GAAG,OAAO,GAAG,SAAS,CAAC,CAAC,GAClH,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,gBAAgB,GAAG,eAAe,CAAC,GAAG;IAChE,UAAU,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,cAAc,EAAE,UAAU,CAAC,EAAE,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAClF,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;IAC5B,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;IAC3C,OAAO,EAAE,KAAK,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC;CACxC,CAAC;AAKJ,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,EAC1C,KAAK,EACL,MAAM,EACN,OAAO,EACP,UAAU,EACV,cAAc,EACd,aAAa,EACb,IAAI,EACJ,OAAO,EACP,OAAO,GACR,EAAE,qBAAqB,CAAC,SAAS,CAAC,eA4KlC"}
|
|
@@ -19,13 +19,14 @@ import { TableRow } from './TableRow';
|
|
|
19
19
|
import { TableBody } from './TableBody';
|
|
20
20
|
import { InnerTable } from './InnerTable';
|
|
21
21
|
import { TableHead } from './TableHead';
|
|
22
|
+
import { TableHeaderCell } from './TableHeaderCell';
|
|
22
23
|
import { TableCell } from './TableCell';
|
|
23
24
|
import { VirtualizedTableContainer } from './VirtualizedTableContainer';
|
|
24
25
|
import { useVirtualizedTableKeyboardNav } from './hooks/useVirtualizedTableKeyboardNav';
|
|
25
26
|
// Separating out the virtualized table because we may want a paginated table
|
|
26
27
|
// in the future that does not need virtualization, and we'd likely lay them
|
|
27
28
|
// out differently.
|
|
28
|
-
export function VirtualizedTable({ width , height , density , onRowClick , rows , columns , headers }) {
|
|
29
|
+
export function VirtualizedTable({ width , height , density , onRowClick , onRowMouseOver , onRowMouseOut , rows , columns , headers }) {
|
|
29
30
|
const virtuosoRef = useRef(null);
|
|
30
31
|
// Use a ref for these values because they are only needed for keyboard
|
|
31
32
|
// focus interactions and setting them on state will lead to a significant
|
|
@@ -69,10 +70,20 @@ export function VirtualizedTable({ width , height , density , onRowClick , rows
|
|
|
69
70
|
if (!row) {
|
|
70
71
|
return null;
|
|
71
72
|
}
|
|
73
|
+
const rowEventOpts = {
|
|
74
|
+
id: row.id,
|
|
75
|
+
index: row.index
|
|
76
|
+
};
|
|
72
77
|
return /*#__PURE__*/ _jsx(TableRow, {
|
|
73
78
|
...props,
|
|
74
|
-
onClick: ()=>onRowClick(row.id),
|
|
75
|
-
density: density
|
|
79
|
+
onClick: (e)=>onRowClick(e, row.id),
|
|
80
|
+
density: density,
|
|
81
|
+
onMouseOver: (e)=>{
|
|
82
|
+
onRowMouseOver === null || onRowMouseOver === void 0 ? void 0 : onRowMouseOver(e, rowEventOpts);
|
|
83
|
+
},
|
|
84
|
+
onMouseOut: (e)=>{
|
|
85
|
+
onRowMouseOut === null || onRowMouseOut === void 0 ? void 0 : onRowMouseOut(e, rowEventOpts);
|
|
86
|
+
}
|
|
76
87
|
});
|
|
77
88
|
},
|
|
78
89
|
TableBody
|
|
@@ -81,6 +92,8 @@ export function VirtualizedTable({ width , height , density , onRowClick , rows
|
|
|
81
92
|
density,
|
|
82
93
|
keyboardNav.onTableKeyDown,
|
|
83
94
|
onRowClick,
|
|
95
|
+
onRowMouseOut,
|
|
96
|
+
onRowMouseOver,
|
|
84
97
|
rows,
|
|
85
98
|
width
|
|
86
99
|
]);
|
|
@@ -103,17 +116,23 @@ export function VirtualizedTable({ width , height , density , onRowClick , rows
|
|
|
103
116
|
return /*#__PURE__*/ _jsx(TableRow, {
|
|
104
117
|
density: density,
|
|
105
118
|
children: headerGroup.headers.map((header, i, headers)=>{
|
|
106
|
-
var ref;
|
|
119
|
+
var ref, ref1;
|
|
107
120
|
const column = header.column;
|
|
108
121
|
const position = {
|
|
109
122
|
row: 0,
|
|
110
123
|
column: i
|
|
111
124
|
};
|
|
112
|
-
|
|
125
|
+
const isSorted = column.getIsSorted();
|
|
126
|
+
const nextSorting = column.getNextSortingOrder();
|
|
127
|
+
return /*#__PURE__*/ _jsx(TableHeaderCell, {
|
|
128
|
+
onSort: column.getCanSort() ? column.getToggleSortingHandler() : undefined,
|
|
129
|
+
sortDirection: typeof isSorted === 'string' ? isSorted : undefined,
|
|
130
|
+
nextSortDirection: typeof nextSorting === 'string' ? nextSorting : undefined,
|
|
113
131
|
width: column.getSize() || 'auto',
|
|
114
132
|
align: (ref = column.columnDef.meta) === null || ref === void 0 ? void 0 : ref.align,
|
|
115
133
|
variant: "head",
|
|
116
134
|
density: density,
|
|
135
|
+
description: (ref1 = column.columnDef.meta) === null || ref1 === void 0 ? void 0 : ref1.headerDescription,
|
|
117
136
|
focusState: getFocusState(position),
|
|
118
137
|
onFocusTrigger: ()=>keyboardNav.onCellFocus(position),
|
|
119
138
|
isFirstColumn: i === 0,
|
|
@@ -132,21 +151,37 @@ export function VirtualizedTable({ width , height , density , onRowClick , rows
|
|
|
132
151
|
}
|
|
133
152
|
return /*#__PURE__*/ _jsx(_Fragment, {
|
|
134
153
|
children: row.getVisibleCells().map((cell, i, cells)=>{
|
|
135
|
-
var ref;
|
|
154
|
+
var ref, ref1;
|
|
136
155
|
const position = {
|
|
137
156
|
// Add 1 to the row index because the header is row 0
|
|
138
157
|
row: index + 1,
|
|
139
158
|
column: i
|
|
140
159
|
};
|
|
160
|
+
const cellContext = cell.getContext();
|
|
161
|
+
const cellRenderFn = cell.column.columnDef.cell;
|
|
162
|
+
const cellContent = typeof cellRenderFn == 'function' ? cellRenderFn(cellContext) : null;
|
|
163
|
+
const cellDescriptionDef = (ref = cell.column.columnDef.meta) === null || ref === void 0 ? void 0 : ref.cellDescription;
|
|
164
|
+
let description = undefined;
|
|
165
|
+
if (typeof cellDescriptionDef === 'function') {
|
|
166
|
+
// If the cell description is a function, set the value using
|
|
167
|
+
// the function.
|
|
168
|
+
description = cellDescriptionDef(cellContext);
|
|
169
|
+
} else if (cellDescriptionDef && typeof cellContent === 'string') {
|
|
170
|
+
// If the cell description is `true` AND the cell content is
|
|
171
|
+
// a string (and thus viable as a `title` attribute), use the
|
|
172
|
+
// cell content.
|
|
173
|
+
description = cellContent;
|
|
174
|
+
}
|
|
141
175
|
return /*#__PURE__*/ _jsx(TableCell, {
|
|
142
176
|
width: cell.column.getSize() || 'auto',
|
|
143
|
-
align: (
|
|
177
|
+
align: (ref1 = cell.column.columnDef.meta) === null || ref1 === void 0 ? void 0 : ref1.align,
|
|
144
178
|
density: density,
|
|
145
179
|
focusState: getFocusState(position),
|
|
146
180
|
onFocusTrigger: ()=>keyboardNav.onCellFocus(position),
|
|
147
181
|
isFirstColumn: i === 0,
|
|
148
182
|
isLastColumn: i === cells.length - 1,
|
|
149
|
-
|
|
183
|
+
description: description,
|
|
184
|
+
children: cellContent
|
|
150
185
|
}, cell.id);
|
|
151
186
|
})
|
|
152
187
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Table/VirtualizedTable.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Column, HeaderGroup, Row, flexRender } from '@tanstack/react-table';\nimport { Box } from '@mui/material';\nimport { TableVirtuoso, TableComponents, TableVirtuosoHandle, TableVirtuosoProps } from 'react-virtuoso';\nimport { useRef, useMemo } from 'react';\nimport { TableRow } from './TableRow';\nimport { TableBody } from './TableBody';\nimport { InnerTable } from './InnerTable';\nimport { TableHead } from './TableHead';\nimport { TableCell, TableCellProps } from './TableCell';\nimport { VirtualizedTableContainer } from './VirtualizedTableContainer';\nimport { TableProps } from './model/table-model';\nimport { useVirtualizedTableKeyboardNav } from './hooks/useVirtualizedTableKeyboardNav';\n\ntype TableCellPosition = {\n row: number;\n column: number;\n};\n\nexport type VirtualizedTableProps<TableData> = Required<Pick<TableProps<TableData>, 'height' | 'width' | 'density'>> & {\n onRowClick: (id: string) => void;\n rows: Array<Row<TableData>>;\n columns: Array<Column<TableData, unknown>>;\n headers: Array<HeaderGroup<TableData>>;\n};\n\n// Separating out the virtualized table because we may want a paginated table\n// in the future that does not need virtualization, and we'd likely lay them\n// out differently.\nexport function VirtualizedTable<TableData>({\n width,\n height,\n density,\n onRowClick,\n rows,\n columns,\n headers,\n}: VirtualizedTableProps<TableData>) {\n const virtuosoRef = useRef<TableVirtuosoHandle>(null);\n\n // Use a ref for these values because they are only needed for keyboard\n // focus interactions and setting them on state will lead to a significant\n // amount of unnecessary re-renders.\n const visibleRange = useRef({\n startIndex: 0,\n endIndex: 0,\n });\n const setVisibleRange: TableVirtuosoProps<TableData, unknown>['rangeChanged'] = (newVisibleRange) => {\n visibleRange.current = newVisibleRange;\n };\n\n const keyboardNav = useVirtualizedTableKeyboardNav({\n visibleRange: visibleRange,\n virtualTable: virtuosoRef,\n\n // We add 1 here for the header.\n maxRows: rows.length + 1,\n maxColumns: columns.length,\n });\n\n const getFocusState = (cellPosition: TableCellPosition): TableCellProps['focusState'] => {\n if (cellPosition.row === keyboardNav.activeCell.row && cellPosition.column === keyboardNav.activeCell.column) {\n return keyboardNav.isActive ? 'trigger-focus' : 'focus-next';\n }\n\n return 'none';\n };\n\n const VirtuosoTableComponents: TableComponents<TableData> = useMemo(() => {\n return {\n Scroller: VirtualizedTableContainer,\n Table: (props) => {\n return <InnerTable {...props} width={width} density={density} onKeyDown={keyboardNav.onTableKeyDown} />;\n },\n TableHead,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n TableRow: ({ item, ...props }) => {\n const index = props['data-index'];\n const row = rows[index];\n if (!row) {\n return null;\n }\n\n return <TableRow {...props} onClick={() => onRowClick(row.id)} density={density} />;\n },\n TableBody,\n };\n }, [density, keyboardNav.onTableKeyDown, onRowClick, rows, width]);\n\n return (\n <Box sx={{ width, height }}>\n <TableVirtuoso\n ref={virtuosoRef}\n totalCount={rows.length}\n components={VirtuosoTableComponents}\n // Note: this value is impacted by overscan. See this issue if overscan\n // is added.\n // https://github.com/petyosi/react-virtuoso/issues/118#issuecomment-642156138\n rangeChanged={setVisibleRange}\n fixedHeaderContent={() => {\n return (\n <>\n {headers.map((headerGroup) => {\n return (\n <TableRow key={headerGroup.id} density={density}>\n {headerGroup.headers.map((header, i, headers) => {\n const column = header.column;\n const position: TableCellPosition = {\n row: 0,\n column: i,\n };\n\n return (\n <TableCell\n key={header.id}\n width={column.getSize() || 'auto'}\n align={column.columnDef.meta?.align}\n variant=\"head\"\n density={density}\n focusState={getFocusState(position)}\n onFocusTrigger={() => keyboardNav.onCellFocus(position)}\n isFirstColumn={i === 0}\n isLastColumn={i === headers.length - 1}\n >\n {flexRender(column.columnDef.header, header.getContext())}\n </TableCell>\n );\n })}\n </TableRow>\n );\n })}\n </>\n );\n }}\n itemContent={(index) => {\n const row = rows[index];\n if (!row) {\n return null;\n }\n\n return (\n <>\n {row.getVisibleCells().map((cell, i, cells) => {\n const position: TableCellPosition = {\n // Add 1 to the row index because the header is row 0\n row: index + 1,\n column: i,\n };\n\n return (\n <TableCell\n key={cell.id}\n width={cell.column.getSize() || 'auto'}\n align={cell.column.columnDef.meta?.align}\n density={density}\n focusState={getFocusState(position)}\n onFocusTrigger={() => keyboardNav.onCellFocus(position)}\n isFirstColumn={i === 0}\n isLastColumn={i === cells.length - 1}\n >\n {flexRender(cell.column.columnDef.cell, cell.getContext())}\n </TableCell>\n );\n })}\n </>\n );\n }}\n />\n </Box>\n );\n}\n"],"names":["flexRender","Box","TableVirtuoso","useRef","useMemo","TableRow","TableBody","InnerTable","TableHead","TableCell","VirtualizedTableContainer","useVirtualizedTableKeyboardNav","VirtualizedTable","width","height","density","onRowClick","rows","columns","headers","virtuosoRef","visibleRange","startIndex","endIndex","setVisibleRange","newVisibleRange","current","keyboardNav","virtualTable","maxRows","length","maxColumns","getFocusState","cellPosition","row","activeCell","column","isActive","VirtuosoTableComponents","Scroller","Table","props","onKeyDown","onTableKeyDown","item","index","onClick","id","sx","ref","totalCount","components","rangeChanged","fixedHeaderContent","map","headerGroup","header","i","position","getSize","align","columnDef","meta","variant","focusState","onFocusTrigger","onCellFocus","isFirstColumn","isLastColumn","getContext","itemContent","getVisibleCells","cell","cells"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAAmCA,UAAU,QAAQ,uBAAuB,CAAC;AAC7E,SAASC,GAAG,QAAQ,eAAe,CAAC;AACpC,SAASC,aAAa,QAAkE,gBAAgB,CAAC;AACzG,SAASC,MAAM,EAAEC,OAAO,QAAQ,OAAO,CAAC;AACxC,SAASC,QAAQ,QAAQ,YAAY,CAAC;AACtC,SAASC,SAAS,QAAQ,aAAa,CAAC;AACxC,SAASC,UAAU,QAAQ,cAAc,CAAC;AAC1C,SAASC,SAAS,QAAQ,aAAa,CAAC;AACxC,SAASC,SAAS,QAAwB,aAAa,CAAC;AACxD,SAASC,yBAAyB,QAAQ,6BAA6B,CAAC;AAExE,SAASC,8BAA8B,QAAQ,wCAAwC,CAAC;AAcxF,6EAA6E;AAC7E,4EAA4E;AAC5E,mBAAmB;AACnB,OAAO,SAASC,gBAAgB,CAAY,EAC1CC,KAA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AK,GAAG,CAAC;4BACdT,MAAM,EAAEqB,CAAC;yBACV,AAAC;wBAEF,qBACE,KAAChD,SAAS;4BAERI,KAAK,EAAE2D,IAAI,CAACpC,MAAM,CAACuB,OAAO,EAAE,IAAI,MAAM;4BACtCC,KAAK,EAAEY,CAAAA,GAA0B,GAA1BA,IAAI,CAACpC,MAAM,CAACyB,SAAS,CAACC,IAAI,cAA1BU,GAA0B,WAAO,GAAjCA,KAAAA,CAAiC,GAAjCA,GAA0B,CAAEZ,KAAK;4BACxC7C,OAAO,EAAEA,OAAO;4BAChBiD,UAAU,EAAEhC,aAAa,CAAC0B,QAAQ,CAAC;4BACnCO,cAAc,EAAE,IAAMtC,WAAW,CAACuC,WAAW,CAACR,QAAQ,CAAC;4BACvDS,aAAa,EAAEV,CAAC,KAAK,CAAC;4BACtBW,YAAY,EAAEX,CAAC,KAAKgB,KAAK,CAAC3C,MAAM,GAAG,CAAC;sCAEnC9B,UAAU,CAACwE,IAAI,CAACpC,MAAM,CAACyB,SAAS,CAACW,IAAI,EAAEA,IAAI,CAACH,UAAU,EAAE,CAAC;2BATrDG,IAAI,CAACzB,EAAE,CAUF,CACZ;oBACJ,CAAC,CAAC;kBACD,CACH;YACJ,CAAC;UACD;MACE,CACN;AACJ,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/Table/VirtualizedTable.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Column, HeaderGroup, Row, flexRender } from '@tanstack/react-table';\nimport { Box } from '@mui/material';\nimport { TableVirtuoso, TableComponents, TableVirtuosoHandle, TableVirtuosoProps } from 'react-virtuoso';\nimport { useRef, useMemo } from 'react';\nimport { TableRow } from './TableRow';\nimport { TableBody } from './TableBody';\nimport { InnerTable } from './InnerTable';\nimport { TableHead } from './TableHead';\nimport { TableHeaderCell } from './TableHeaderCell';\nimport { TableCell, TableCellProps } from './TableCell';\nimport { VirtualizedTableContainer } from './VirtualizedTableContainer';\nimport { TableProps, TableRowEventOpts } from './model/table-model';\nimport { useVirtualizedTableKeyboardNav } from './hooks/useVirtualizedTableKeyboardNav';\n\ntype TableCellPosition = {\n row: number;\n column: number;\n};\n\nexport type VirtualizedTableProps<TableData> = Required<Pick<TableProps<TableData>, 'height' | 'width' | 'density'>> &\n Pick<TableProps<TableData>, 'onRowMouseOver' | 'onRowMouseOut'> & {\n onRowClick: (e: React.MouseEvent<HTMLDivElement, MouseEvent>, id: string) => void;\n rows: Array<Row<TableData>>;\n columns: Array<Column<TableData, unknown>>;\n headers: Array<HeaderGroup<TableData>>;\n };\n\n// Separating out the virtualized table because we may want a paginated table\n// in the future that does not need virtualization, and we'd likely lay them\n// out differently.\nexport function VirtualizedTable<TableData>({\n width,\n height,\n density,\n onRowClick,\n onRowMouseOver,\n onRowMouseOut,\n rows,\n columns,\n headers,\n}: VirtualizedTableProps<TableData>) {\n const virtuosoRef = useRef<TableVirtuosoHandle>(null);\n\n // Use a ref for these values because they are only needed for keyboard\n // focus interactions and setting them on state will lead to a significant\n // amount of unnecessary re-renders.\n const visibleRange = useRef({\n startIndex: 0,\n endIndex: 0,\n });\n const setVisibleRange: TableVirtuosoProps<TableData, unknown>['rangeChanged'] = (newVisibleRange) => {\n visibleRange.current = newVisibleRange;\n };\n\n const keyboardNav = useVirtualizedTableKeyboardNav({\n visibleRange: visibleRange,\n virtualTable: virtuosoRef,\n\n // We add 1 here for the header.\n maxRows: rows.length + 1,\n maxColumns: columns.length,\n });\n\n const getFocusState = (cellPosition: TableCellPosition): TableCellProps['focusState'] => {\n if (cellPosition.row === keyboardNav.activeCell.row && cellPosition.column === keyboardNav.activeCell.column) {\n return keyboardNav.isActive ? 'trigger-focus' : 'focus-next';\n }\n\n return 'none';\n };\n\n const VirtuosoTableComponents: TableComponents<TableData> = useMemo(() => {\n return {\n Scroller: VirtualizedTableContainer,\n Table: (props) => {\n return <InnerTable {...props} width={width} density={density} onKeyDown={keyboardNav.onTableKeyDown} />;\n },\n TableHead,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n TableRow: ({ item, ...props }) => {\n const index = props['data-index'];\n const row = rows[index];\n if (!row) {\n return null;\n }\n\n const rowEventOpts: TableRowEventOpts = { id: row.id, index: row.index };\n\n return (\n <TableRow\n {...props}\n onClick={(e) => onRowClick(e, row.id)}\n density={density}\n onMouseOver={(e) => {\n onRowMouseOver?.(e, rowEventOpts);\n }}\n onMouseOut={(e) => {\n onRowMouseOut?.(e, rowEventOpts);\n }}\n />\n );\n },\n TableBody,\n };\n }, [density, keyboardNav.onTableKeyDown, onRowClick, onRowMouseOut, onRowMouseOver, rows, width]);\n\n return (\n <Box sx={{ width, height }}>\n <TableVirtuoso\n ref={virtuosoRef}\n totalCount={rows.length}\n components={VirtuosoTableComponents}\n // Note: this value is impacted by overscan. See this issue if overscan\n // is added.\n // https://github.com/petyosi/react-virtuoso/issues/118#issuecomment-642156138\n rangeChanged={setVisibleRange}\n fixedHeaderContent={() => {\n return (\n <>\n {headers.map((headerGroup) => {\n return (\n <TableRow key={headerGroup.id} density={density}>\n {headerGroup.headers.map((header, i, headers) => {\n const column = header.column;\n const position: TableCellPosition = {\n row: 0,\n column: i,\n };\n\n const isSorted = column.getIsSorted();\n const nextSorting = column.getNextSortingOrder();\n\n return (\n <TableHeaderCell\n key={header.id}\n onSort={column.getCanSort() ? column.getToggleSortingHandler() : undefined}\n sortDirection={typeof isSorted === 'string' ? isSorted : undefined}\n nextSortDirection={typeof nextSorting === 'string' ? nextSorting : undefined}\n width={column.getSize() || 'auto'}\n align={column.columnDef.meta?.align}\n variant=\"head\"\n density={density}\n description={column.columnDef.meta?.headerDescription}\n focusState={getFocusState(position)}\n onFocusTrigger={() => keyboardNav.onCellFocus(position)}\n isFirstColumn={i === 0}\n isLastColumn={i === headers.length - 1}\n >\n {flexRender(column.columnDef.header, header.getContext())}\n </TableHeaderCell>\n );\n })}\n </TableRow>\n );\n })}\n </>\n );\n }}\n itemContent={(index) => {\n const row = rows[index];\n if (!row) {\n return null;\n }\n\n return (\n <>\n {row.getVisibleCells().map((cell, i, cells) => {\n const position: TableCellPosition = {\n // Add 1 to the row index because the header is row 0\n row: index + 1,\n column: i,\n };\n\n const cellContext = cell.getContext();\n const cellRenderFn = cell.column.columnDef.cell;\n const cellContent = typeof cellRenderFn == 'function' ? cellRenderFn(cellContext) : null;\n\n const cellDescriptionDef = cell.column.columnDef.meta?.cellDescription;\n let description: string | undefined = undefined;\n if (typeof cellDescriptionDef === 'function') {\n // If the cell description is a function, set the value using\n // the function.\n description = cellDescriptionDef(cellContext);\n } else if (cellDescriptionDef && typeof cellContent === 'string') {\n // If the cell description is `true` AND the cell content is\n // a string (and thus viable as a `title` attribute), use the\n // cell content.\n description = cellContent;\n }\n\n return (\n <TableCell\n key={cell.id}\n width={cell.column.getSize() || 'auto'}\n align={cell.column.columnDef.meta?.align}\n density={density}\n focusState={getFocusState(position)}\n onFocusTrigger={() => keyboardNav.onCellFocus(position)}\n isFirstColumn={i === 0}\n isLastColumn={i === cells.length - 1}\n description={description}\n >\n {cellContent}\n </TableCell>\n );\n })}\n </>\n );\n }}\n />\n </Box>\n );\n}\n"],"names":["flexRender","Box","TableVirtuoso","useRef","useMemo","TableRow","TableBody","InnerTable","TableHead","TableHeaderCell","TableCell","VirtualizedTableContainer","useVirtualizedTableKeyboardNav","VirtualizedTable","width","height","density","onRowClick","onRowMouseOver","onRowMouseOut","rows","columns","headers","virtuosoRef","visibleRange","startIndex","endIndex","setVisibleRange","newVisibleRange","current","keyboardNav","virtualTable","maxRows","length","maxColumns","getFocusState","cellPosition","row","activeCell","column","isActive","VirtuosoTableComponents","Scroller","Table","props","onKeyDown","onTableKeyDown","item","index","rowEventOpts","id","onClick","e","onMouseOver","onMouseOut","sx","ref","totalCount","components","rangeChanged","fixedHeaderContent","map","headerGroup","header","i","position","isSorted","getIsSorted","nextSorting","getNextSortingOrder","onSort","getCanSort","getToggleSortingHandler","undefined","sortDirection","nextSortDirection","getSize","align","columnDef","meta","variant","description","headerDescription","focusState","onFocusTrigger","onCellFocus","isFirstColumn","isLastColumn","getContext","itemContent","getVisibleCells","cell","cells","cellContext","cellRenderFn","cellContent","cellDescriptionDef","cellDescription"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAAmCA,UAAU,QAAQ,uBAAuB,CAAC;AAC7E,SAASC,GAAG,QAAQ,eAAe,CAAC;AACpC,SAASC,aAAa,QAAkE,gBAAgB,CAAC;AACzG,SAASC,MAAM,EAAEC,OAAO,QAAQ,OAAO,CAAC;AACxC,SAASC,QAAQ,QAAQ,YAAY,CAAC;AACtC,SAASC,SAAS,QAAQ,aAAa,CAAC;AACxC,SAASC,UAAU,QAAQ,cAAc,CAAC;AAC1C,SAASC,SAAS,QAAQ,aAAa,CAAC;AACxC,SAASC,eAAe,QAAQ,mBAAmB,CAAC;AACpD,SAASC,SAAS,QAAwB,aAAa,CAAC;AACxD,SAASC,yBAAyB,QAAQ,6BAA6B,CAAC;AAExE,SAASC,8BAA8B,QAAQ,wCAAwC,CAAC;AAexF,6EAA6E;AAC7E,4EAA4E;AAC5E,mBAAmB;AACnB,OAAO,SAASC,gBAAgB,CAAY,EAC1CC,KAAK,CAAA,EACLC,MAAM,CAAA,EACNC,OAAO,CAAA,EACPC,UAAU,CAAA,EACVC,cAAc,CAAA,EACdC,aAAa,CAAA,EACbC,IAAI,CAAA,EACJC,OAA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AACJ,CAAC"}
|
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { Theme } from '@mui/material';
|
|
3
|
-
import { AccessorKeyColumnDef, ColumnDef, CoreOptions, RowData, RowSelectionState } from '@tanstack/react-table';
|
|
3
|
+
import { AccessorKeyColumnDef, CellContext, ColumnDef, CoreOptions, RowData, RowSelectionState, SortingState } from '@tanstack/react-table';
|
|
4
4
|
export declare type TableDensity = 'compact' | 'standard';
|
|
5
|
+
export declare type SortDirection = 'asc' | 'desc' | undefined;
|
|
6
|
+
export declare type TableRowEventOpts = {
|
|
7
|
+
/**
|
|
8
|
+
* Unique identifier for the row.
|
|
9
|
+
*/
|
|
10
|
+
id: string;
|
|
11
|
+
/**
|
|
12
|
+
* Index of the row in the original data.
|
|
13
|
+
*/
|
|
14
|
+
index: number;
|
|
15
|
+
};
|
|
5
16
|
export interface TableProps<TableData> {
|
|
6
17
|
/**
|
|
7
18
|
* Height of the table.
|
|
@@ -31,6 +42,18 @@ export interface TableProps<TableData> {
|
|
|
31
42
|
* When `true`, the first column of the table will include checkboxes.
|
|
32
43
|
*/
|
|
33
44
|
checkboxSelection?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Determines the behavior of row selection.
|
|
47
|
+
*
|
|
48
|
+
* - `standard`: clicking a checkbox will toggle that rows's selected/unselected
|
|
49
|
+
* state and will not impact other rows.
|
|
50
|
+
* - `legend`: clicking a checkbox will "focus" that row by selecting it and
|
|
51
|
+
* unselecting other rows. Clicking a checkbox with a modifier key pressed,
|
|
52
|
+
* will change this behavior to behave like `standard`.
|
|
53
|
+
*
|
|
54
|
+
* @default 'standard'
|
|
55
|
+
*/
|
|
56
|
+
rowSelectionVariant?: 'standard' | 'legend';
|
|
34
57
|
/**
|
|
35
58
|
* State of selected rows in the table when `checkboxSelection` is enabled.
|
|
36
59
|
*
|
|
@@ -38,10 +61,29 @@ export interface TableProps<TableData> {
|
|
|
38
61
|
* combination of this prop and `onRowSelectionChange`.
|
|
39
62
|
*/
|
|
40
63
|
rowSelection?: RowSelectionState;
|
|
64
|
+
/**
|
|
65
|
+
* Callback fired when the mouse is moved over a table row.
|
|
66
|
+
*/
|
|
67
|
+
onRowMouseOver?: (e: React.MouseEvent, opts: TableRowEventOpts) => void;
|
|
68
|
+
/**
|
|
69
|
+
* Callback fired when the mouse is moved out of a table row.
|
|
70
|
+
*/
|
|
71
|
+
onRowMouseOut?: (e: React.MouseEvent, opts: TableRowEventOpts) => void;
|
|
72
|
+
/**
|
|
73
|
+
* State of the column sorting in the table.
|
|
74
|
+
*
|
|
75
|
+
* The column sorting is a controlled value that should be managed using a
|
|
76
|
+
* combination fo this prop and `onSortingChange`.
|
|
77
|
+
*/
|
|
78
|
+
sorting?: SortingState;
|
|
41
79
|
/**
|
|
42
80
|
* Callback fired when the selected rows in the table changes.
|
|
43
81
|
*/
|
|
44
82
|
onRowSelectionChange?: (rowSelection: RowSelectionState) => void;
|
|
83
|
+
/**
|
|
84
|
+
* Callback fired when the table sorting changes.
|
|
85
|
+
*/
|
|
86
|
+
onSortingChange?: (sorting: SortingState) => void;
|
|
45
87
|
/**
|
|
46
88
|
* Function used to determine the unique identifier used for each row. This
|
|
47
89
|
* value is used to key `rowSelection`. If this value is not set, the index
|
|
@@ -69,14 +111,40 @@ export declare function getTableCellLayout(theme: Theme, density: TableDensity,
|
|
|
69
111
|
export declare type TableCellAlignment = 'left' | 'right' | 'center';
|
|
70
112
|
declare module '@tanstack/table-core' {
|
|
71
113
|
interface ColumnMeta<TData extends RowData, TValue> {
|
|
72
|
-
align?:
|
|
114
|
+
align?: TableColumnConfig<TData>['align'];
|
|
115
|
+
headerDescription?: TableColumnConfig<TData>['headerDescription'];
|
|
116
|
+
cellDescription?: TableColumnConfig<TData>['cellDescription'];
|
|
73
117
|
}
|
|
74
118
|
}
|
|
75
|
-
export interface TableColumnConfig<TableData> extends Pick<AccessorKeyColumnDef<TableData, any>, 'accessorKey' | 'cell'> {
|
|
119
|
+
export interface TableColumnConfig<TableData> extends Pick<AccessorKeyColumnDef<TableData, any>, 'accessorKey' | 'cell' | 'sortingFn'> {
|
|
76
120
|
/**
|
|
77
121
|
* Text to display in the header for the column.
|
|
78
122
|
*/
|
|
79
123
|
header: string;
|
|
124
|
+
/**
|
|
125
|
+
* Alignment of the content in the cell.
|
|
126
|
+
*/
|
|
127
|
+
align?: TableCellAlignment;
|
|
128
|
+
/**
|
|
129
|
+
* Text to display when hovering over a cell. This can be useful for
|
|
130
|
+
* providing additional information about the column when the content is
|
|
131
|
+
* ellipsized to fit in the space.
|
|
132
|
+
*
|
|
133
|
+
* If set to `true`, it will use the value generated by the `cell` prop if it
|
|
134
|
+
* can be treated as a string.
|
|
135
|
+
*/
|
|
136
|
+
cellDescription?: ((props: CellContext<TableData, any>) => string) | boolean | undefined;
|
|
137
|
+
/**
|
|
138
|
+
* When `true`, the column will be sortable.
|
|
139
|
+
* @default false
|
|
140
|
+
*/
|
|
141
|
+
enableSorting?: boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Text to display when hovering over the header text. This can be useful for
|
|
144
|
+
* providing additional information about the column when you want to keep the
|
|
145
|
+
* header text relatively short to manage the column width.
|
|
146
|
+
*/
|
|
147
|
+
headerDescription?: string;
|
|
80
148
|
/**
|
|
81
149
|
* Width of the column when rendered in a table. It should be a number in pixels
|
|
82
150
|
* or "auto" to allow the table to automatically adjust the width to fill
|
|
@@ -84,10 +152,6 @@ export interface TableColumnConfig<TableData> extends Pick<AccessorKeyColumnDef<
|
|
|
84
152
|
* @default 'auto'
|
|
85
153
|
*/
|
|
86
154
|
width?: number | 'auto';
|
|
87
|
-
/**
|
|
88
|
-
* Alignment of the content in the cell.
|
|
89
|
-
*/
|
|
90
|
-
align?: TableCellAlignment;
|
|
91
155
|
}
|
|
92
156
|
/**
|
|
93
157
|
* Takes in a perses table column and transforms it into a tanstack column.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table-model.d.ts","sourceRoot":"","sources":["../../../src/Table/model/table-model.ts"],"names":[],"mappings":";AAaA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,
|
|
1
|
+
{"version":3,"file":"table-model.d.ts","sourceRoot":"","sources":["../../../src/Table/model/table-model.ts"],"names":[],"mappings":";AAaA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EACL,oBAAoB,EACpB,WAAW,EACX,SAAS,EACT,WAAW,EACX,OAAO,EACP,iBAAiB,EACjB,YAAY,EACb,MAAM,uBAAuB,CAAC;AAG/B,oBAAY,YAAY,GAAG,SAAS,GAAG,UAAU,CAAC;AAClD,oBAAY,aAAa,GAAG,KAAK,GAAG,MAAM,GAAG,SAAS,CAAC;AAEvD,oBAAY,iBAAiB,GAAG;IAC9B;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,WAAW,UAAU,CAAC,SAAS;IACnC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,IAAI,EAAE,SAAS,EAAE,CAAC;IAElB;;;;OAIG;IACH,OAAO,EAAE,KAAK,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,CAAC;IAE7C;;;OAGG;IACH,OAAO,CAAC,EAAE,YAAY,CAAC;IAEvB;;OAEG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAE5B;;;;;;;;;;OAUG;IACH,mBAAmB,CAAC,EAAE,UAAU,GAAG,QAAQ,CAAC;IAE5C;;;;;OAKG;IACH,YAAY,CAAC,EAAE,iBAAiB,CAAC;IAEjC;;OAEG;IACH,cAAc,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,EAAE,IAAI,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAExE;;OAEG;IACH,aAAa,CAAC,EAAE,CA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AE,iBAAiB,CAAC,KAAK,CAAC,CAAC,iBAAiB,CAAC,CAAC;KAC/D;CACF;AAKD,MAAM,WAAW,iBAAiB,CAAC,SAAS,CAM1C,SAAQ,IAAI,CAAC,oBAAoB,CAAC,SAAS,EAAE,GAAG,CAAC,EAAE,aAAa,GAAG,MAAM,GAAG,WAAW,CAAC;IACxF;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,KAAK,CAAC,EAAE,kBAAkB,CAAC;IAE3B;;;;;;;OAOG;IAGH,eAAe,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,WAAW,CAAC,SAAS,EAAE,GAAG,CAAC,KAAK,MAAM,CAAC,GAAG,OAAO,GAAG,SAAS,CAAC;IAEzF;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAI3B;;;;;OAKG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,wBAAgB,8BAA8B,CAAC,SAAS,EAAE,OAAO,EAAE,KAAK,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,mCA0CrG"}
|
|
@@ -52,7 +52,7 @@ function calculateTableCellHeight(lineHeight, paddingY) {
|
|
|
52
52
|
/**
|
|
53
53
|
* Takes in a perses table column and transforms it into a tanstack column.
|
|
54
54
|
*/ export function persesColumnsToTanstackColumns(columns) {
|
|
55
|
-
const tableCols = columns.map(({ width , align , ...otherProps })=>{
|
|
55
|
+
const tableCols = columns.map(({ width , align , headerDescription , cellDescription , enableSorting , ...otherProps })=>{
|
|
56
56
|
// Tanstack Table does not support an "auto" value to naturally size to fit
|
|
57
57
|
// the space in a table. We translate our custom "auto" setting to 0 size
|
|
58
58
|
// for these columns, so it is easy to fall back to auto when rendering.
|
|
@@ -70,10 +70,14 @@ function calculateTableCellHeight(lineHeight, paddingY) {
|
|
|
70
70
|
const result = {
|
|
71
71
|
...otherProps,
|
|
72
72
|
...sizeProps,
|
|
73
|
+
// Default sorting to false, so it is very explicitly set per column.
|
|
74
|
+
enableSorting: !!enableSorting,
|
|
73
75
|
// Open-ended store for extra metadata in TanStack Table, so you can bake
|
|
74
76
|
// in your own features.
|
|
75
77
|
meta: {
|
|
76
|
-
align
|
|
78
|
+
align,
|
|
79
|
+
headerDescription,
|
|
80
|
+
cellDescription
|
|
77
81
|
}
|
|
78
82
|
};
|
|
79
83
|
return result;
|