@perses-dev/components 0.48.0 → 0.49.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/ColorPicker/ColorPicker.d.ts +2 -1
  2. package/dist/ColorPicker/ColorPicker.d.ts.map +1 -1
  3. package/dist/ColorPicker/ColorPicker.js +24 -9
  4. package/dist/ColorPicker/ColorPicker.js.map +1 -1
  5. package/dist/ColorPicker/OptionsColorPicker.d.ts +2 -1
  6. package/dist/ColorPicker/OptionsColorPicker.d.ts.map +1 -1
  7. package/dist/ColorPicker/OptionsColorPicker.js +10 -7
  8. package/dist/ColorPicker/OptionsColorPicker.js.map +1 -1
  9. package/dist/Table/Table.d.ts +1 -1
  10. package/dist/Table/Table.d.ts.map +1 -1
  11. package/dist/Table/Table.js +3 -2
  12. package/dist/Table/Table.js.map +1 -1
  13. package/dist/Table/TableCell.d.ts +3 -1
  14. package/dist/Table/TableCell.d.ts.map +1 -1
  15. package/dist/Table/TableCell.js +5 -1
  16. package/dist/Table/TableCell.js.map +1 -1
  17. package/dist/Table/VirtualizedTable.d.ts +3 -2
  18. package/dist/Table/VirtualizedTable.d.ts.map +1 -1
  19. package/dist/Table/VirtualizedTable.js +8 -2
  20. package/dist/Table/VirtualizedTable.js.map +1 -1
  21. package/dist/Table/model/table-model.d.ts +14 -0
  22. package/dist/Table/model/table-model.d.ts.map +1 -1
  23. package/dist/Table/model/table-model.js.map +1 -1
  24. package/dist/TransformsEditor/TransformEditor.d.ts +8 -0
  25. package/dist/TransformsEditor/TransformEditor.d.ts.map +1 -0
  26. package/dist/TransformsEditor/TransformEditor.js +291 -0
  27. package/dist/TransformsEditor/TransformEditor.js.map +1 -0
  28. package/dist/TransformsEditor/TransformEditorContainer.d.ts +9 -0
  29. package/dist/TransformsEditor/TransformEditorContainer.d.ts.map +1 -0
  30. package/dist/TransformsEditor/TransformEditorContainer.js +120 -0
  31. package/dist/TransformsEditor/TransformEditorContainer.js.map +1 -0
  32. package/dist/TransformsEditor/TransformsEditor.d.ts +8 -0
  33. package/dist/TransformsEditor/TransformsEditor.d.ts.map +1 -0
  34. package/dist/TransformsEditor/TransformsEditor.js +93 -0
  35. package/dist/TransformsEditor/TransformsEditor.js.map +1 -0
  36. package/dist/TransformsEditor/index.d.ts +2 -0
  37. package/dist/TransformsEditor/index.d.ts.map +1 -0
  38. package/dist/TransformsEditor/index.js +15 -0
  39. package/dist/TransformsEditor/index.js.map +1 -0
  40. package/dist/cjs/ColorPicker/ColorPicker.js +24 -9
  41. package/dist/cjs/ColorPicker/OptionsColorPicker.js +11 -8
  42. package/dist/cjs/Table/Table.js +3 -2
  43. package/dist/cjs/Table/TableCell.js +5 -1
  44. package/dist/cjs/Table/VirtualizedTable.js +8 -2
  45. package/dist/cjs/TransformsEditor/TransformEditor.js +299 -0
  46. package/dist/cjs/TransformsEditor/TransformEditorContainer.js +133 -0
  47. package/dist/cjs/TransformsEditor/TransformsEditor.js +106 -0
  48. package/dist/cjs/TransformsEditor/index.js +30 -0
  49. package/dist/cjs/index.js +1 -0
  50. package/dist/cjs/theme/palette/background.js +2 -0
  51. package/dist/index.d.ts +1 -0
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/index.js +1 -0
  54. package/dist/index.js.map +1 -1
  55. package/dist/theme/index.d.ts +1 -0
  56. package/dist/theme/index.d.ts.map +1 -1
  57. package/dist/theme/index.js.map +1 -1
  58. package/dist/theme/palette/background.d.ts.map +1 -1
  59. package/dist/theme/palette/background.js +2 -0
  60. package/dist/theme/palette/background.js.map +1 -1
  61. package/package.json +3 -3
@@ -1,11 +1,12 @@
1
1
  interface ColorPickerProps {
2
2
  color: string;
3
3
  onChange?: (color: string) => void;
4
+ onClear?: () => void;
4
5
  /**
5
6
  * Preset color palette
6
7
  */
7
8
  palette?: string[];
8
9
  }
9
- export declare const ColorPicker: ({ color, onChange, palette }: ColorPickerProps) => import("react/jsx-runtime").JSX.Element;
10
+ export declare const ColorPicker: ({ color, onChange, onClear, palette }: ColorPickerProps) => import("react/jsx-runtime").JSX.Element;
10
11
  export {};
11
12
  //# sourceMappingURL=ColorPicker.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ColorPicker.d.ts","sourceRoot":"","sources":["../../src/ColorPicker/ColorPicker.tsx"],"names":[],"mappings":"AAkBA,UAAU,gBAAgB;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,eAAO,MAAM,WAAW,iCAAkC,gBAAgB,4CA4CzE,CAAC"}
1
+ {"version":3,"file":"ColorPicker.d.ts","sourceRoot":"","sources":["../../src/ColorPicker/ColorPicker.tsx"],"names":[],"mappings":"AAmBA,UAAU,gBAAgB;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,eAAO,MAAM,WAAW,0CAA2C,gBAAgB,4CAmDlF,CAAC"}
@@ -15,7 +15,8 @@ import { IconButton, Stack, TextField } from '@mui/material';
15
15
  import React, { useState } from 'react';
16
16
  import { HexColorPicker } from 'react-colorful';
17
17
  import CircleIcon from 'mdi-material-ui/Circle';
18
- export const ColorPicker = ({ color, onChange, palette })=>{
18
+ import DeleteIcon from 'mdi-material-ui/Delete';
19
+ export const ColorPicker = ({ color, onChange, onClear, palette })=>{
19
20
  // value is the visible value for the controlled text input
20
21
  const [value, setValue] = useState(color);
21
22
  const handleColorChange = (color)=>{
@@ -36,7 +37,10 @@ export const ColorPicker = ({ color, onChange, palette })=>{
36
37
  children: [
37
38
  /*#__PURE__*/ _jsx(HexColorPicker, {
38
39
  color: color,
39
- onChange: handleColorChange
40
+ onChange: handleColorChange,
41
+ style: {
42
+ width: '100%'
43
+ }
40
44
  }),
41
45
  /*#__PURE__*/ _jsx(Stack, {
42
46
  direction: "row",
@@ -53,13 +57,24 @@ export const ColorPicker = ({ color, onChange, palette })=>{
53
57
  children: /*#__PURE__*/ _jsx(CircleIcon, {})
54
58
  }, i))
55
59
  }),
56
- /*#__PURE__*/ _jsx(TextField, {
57
- inputProps: {
58
- 'aria-label': 'enter hex color'
59
- },
60
- fullWidth: true,
61
- value: value,
62
- onChange: handleInputChange
60
+ /*#__PURE__*/ _jsxs(Stack, {
61
+ direction: "row",
62
+ gap: 1,
63
+ alignItems: "center",
64
+ children: [
65
+ /*#__PURE__*/ _jsx(TextField, {
66
+ inputProps: {
67
+ 'aria-label': 'enter hex color'
68
+ },
69
+ fullWidth: true,
70
+ value: value,
71
+ onChange: handleInputChange
72
+ }),
73
+ onClear && /*#__PURE__*/ _jsx(IconButton, {
74
+ onClick: onClear,
75
+ children: /*#__PURE__*/ _jsx(DeleteIcon, {})
76
+ })
77
+ ]
63
78
  })
64
79
  ]
65
80
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/ColorPicker/ColorPicker.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 { IconButton, Stack, TextField } from '@mui/material';\nimport React, { useState } from 'react';\nimport { HexColorPicker } from 'react-colorful';\nimport CircleIcon from 'mdi-material-ui/Circle';\n\ninterface ColorPickerProps {\n color: string;\n onChange?: (color: string) => void;\n /**\n * Preset color palette\n */\n palette?: string[];\n}\n\nexport const ColorPicker = ({ color, onChange, palette }: ColorPickerProps) => {\n // value is the visible value for the controlled text input\n const [value, setValue] = useState(color);\n\n const handleColorChange = (color: string) => {\n setValue(color);\n onChange && onChange(color);\n };\n\n // we should update this if https://github.com/omgovich/react-colorful/issues/157 is resolved\n const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n const inputValue = e.target.value.replace(/([^0-9A-F]+)/gi, '').substring(0, 8);\n setValue(`#${inputValue}`); // always prefix input value with # to indicate hex format\n // only set color if input value is a valid hex color\n if (isValidHex(e.target.value)) {\n onChange && onChange(e.target.value);\n }\n };\n\n return (\n <Stack spacing={1}>\n <HexColorPicker color={color} onChange={handleColorChange} />\n <Stack direction=\"row\" flexWrap=\"wrap\" justifyContent=\"space-evenly\" width=\"200px\">\n {palette &&\n palette.map((color, i) => (\n <IconButton\n key={i}\n size=\"small\"\n aria-label={`change color to ${color}`}\n sx={{ color }}\n onClick={() => handleColorChange(color)}\n >\n <CircleIcon />\n </IconButton>\n ))}\n </Stack>\n <TextField\n inputProps={{ 'aria-label': 'enter hex color' }}\n fullWidth\n value={value}\n onChange={handleInputChange}\n />\n </Stack>\n );\n};\n\nconst isValidHex = (value: string, alpha?: boolean): boolean => {\n const matcher = /^#?([0-9A-F]{3,8})$/i;\n const match = matcher.exec(value);\n const length = match && match[1] ? match[1].length : 0;\n return (\n length === 3 || // '#rgb' format\n length === 6 || // '#rrggbb' format\n (!!alpha && length === 4) || // '#rgba' format\n (!!alpha && length === 8) // '#rrggbbaa' format\n );\n};\n"],"names":["IconButton","Stack","TextField","React","useState","HexColorPicker","CircleIcon","ColorPicker","color","onChange","palette","value","setValue","handleColorChange","handleInputChange","e","inputValue","target","replace","substring","isValidHex","spacing","direction","flexWrap","justifyContent","width","map","i","size","aria-label","sx","onClick","inputProps","fullWidth","alpha","matcher","match","exec","length"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6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;gBACTtB,OAAOA;gBACPF,UAAUK;;;;AAIlB,EAAE;AAEF,MAAMM,aAAa,CAACT,OAAeuB;IACjC,MAAMC,UAAU;IAChB,MAAMC,QAAQD,QAAQE,IAAI,CAAC1B;IAC3B,MAAM2B,SAASF,SAASA,KAAK,CAAC,EAAE,GAAGA,KAAK,CAAC,EAAE,CAACE,MAAM,GAAG;IACrD,OACEA,WAAW,KAAK,gBAAgB;IAChCA,WAAW,KAAK,mBAAmB;IAClC,CAAC,CAACJ,SAASI,WAAW,KAAM,iBAAiB;IAC7C,CAAC,CAACJ,SAASI,WAAW,EAAG,qBAAqB;;AAEnD"}
1
+ {"version":3,"sources":["../../src/ColorPicker/ColorPicker.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 { IconButton, Stack, TextField } from '@mui/material';\nimport React, { useState } from 'react';\nimport { HexColorPicker } from 'react-colorful';\nimport CircleIcon from 'mdi-material-ui/Circle';\nimport DeleteIcon from 'mdi-material-ui/Delete';\n\ninterface ColorPickerProps {\n color: string;\n onChange?: (color: string) => void;\n onClear?: () => void;\n /**\n * Preset color palette\n */\n palette?: string[];\n}\n\nexport const ColorPicker = ({ color, onChange, onClear, palette }: ColorPickerProps) => {\n // value is the visible value for the controlled text input\n const [value, setValue] = useState(color);\n\n const handleColorChange = (color: string) => {\n setValue(color);\n onChange && onChange(color);\n };\n\n // we should update this if https://github.com/omgovich/react-colorful/issues/157 is resolved\n const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n const inputValue = e.target.value.replace(/([^0-9A-F]+)/gi, '').substring(0, 8);\n setValue(`#${inputValue}`); // always prefix input value with # to indicate hex format\n // only set color if input value is a valid hex color\n if (isValidHex(e.target.value)) {\n onChange && onChange(e.target.value);\n }\n };\n\n return (\n <Stack spacing={1}>\n <HexColorPicker color={color} onChange={handleColorChange} style={{ width: '100%' }} />\n <Stack direction=\"row\" flexWrap=\"wrap\" justifyContent=\"space-evenly\" width=\"200px\">\n {palette &&\n palette.map((color, i) => (\n <IconButton\n key={i}\n size=\"small\"\n aria-label={`change color to ${color}`}\n sx={{ color }}\n onClick={() => handleColorChange(color)}\n >\n <CircleIcon />\n </IconButton>\n ))}\n </Stack>\n <Stack direction=\"row\" gap={1} alignItems=\"center\">\n <TextField\n inputProps={{ 'aria-label': 'enter hex color' }}\n fullWidth\n value={value}\n onChange={handleInputChange}\n />\n {onClear && (\n <IconButton onClick={onClear}>\n <DeleteIcon />\n </IconButton>\n )}\n </Stack>\n </Stack>\n );\n};\n\nconst isValidHex = (value: string, alpha?: boolean): boolean => {\n const matcher = /^#?([0-9A-F]{3,8})$/i;\n const match = matcher.exec(value);\n const length = match && match[1] ? match[1].length : 0;\n return (\n length === 3 || // '#rgb' format\n length === 6 || // '#rrggbb' format\n (!!alpha && length === 4) || // '#rgba' format\n (!!alpha && length === 8) // '#rrggbbaa' format\n );\n};\n"],"names":["IconButton","Stack","TextField","React","useState","HexColorPicker","CircleIcon","DeleteIcon","ColorPicker","color","onChange","onClear","palette","value","setValue","handleColorChange","handleInputChange","e","inputValue","target","replace","substring","isValidHex","spacing","style","width","direction","flexWrap","justifyContent","map","i","size","aria-label","sx","onClick","gap","alignItems","inputProps","fullWidth","alpha","matcher","match","exec","length"],"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,SAASA,UAAU,EAAEC,KAAK,EA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kB;wBAC9CC,SAAS;wBACTzB,OAAOA;wBACPH,UAAUM;;oBAEXL,yBACC,KAACX;wBAAWkC,SAASvB;kCACnB,cAAA,KAACJ;;;;;;AAMb,EAAE;AAEF,MAAMe,aAAa,CAACT,OAAe0B;IACjC,MAAMC,UAAU;IAChB,MAAMC,QAAQD,QAAQE,IAAI,CAAC7B;IAC3B,MAAM8B,SAASF,SAASA,KAAK,CAAC,EAAE,GAAGA,KAAK,CAAC,EAAE,CAACE,MAAM,GAAG;IACrD,OACEA,WAAW,KAAK,gBAAgB;IAChCA,WAAW,KAAK,mBAAmB;IAClC,CAAC,CAACJ,SAASI,WAAW,KAAM,iBAAiB;IAC7C,CAAC,CAACJ,SAASI,WAAW,EAAG,qBAAqB;;AAEnD"}
@@ -2,6 +2,7 @@ export interface OptionsColorPickerProps {
2
2
  label: string;
3
3
  color: string;
4
4
  onColorChange: (color: string) => void;
5
+ onClear?: () => void;
5
6
  }
6
- export declare function OptionsColorPicker({ color, onColorChange, label }: OptionsColorPickerProps): import("react/jsx-runtime").JSX.Element;
7
+ export declare function OptionsColorPicker({ label, color, onColorChange, onClear }: OptionsColorPickerProps): import("react/jsx-runtime").JSX.Element;
7
8
  //# sourceMappingURL=OptionsColorPicker.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"OptionsColorPicker.d.ts","sourceRoot":"","sources":["../../src/ColorPicker/OptionsColorPicker.tsx"],"names":[],"mappings":"AAmBA,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACxC;AAED,wBAAgB,kBAAkB,CAAC,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,EAAE,uBAAuB,2CA8C1F"}
1
+ {"version":3,"file":"OptionsColorPicker.d.ts","sourceRoot":"","sources":["../../src/ColorPicker/OptionsColorPicker.tsx"],"names":[],"mappings":"AAmBA,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,wBAAgB,kBAAkB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,EAAE,uBAAuB,2CA8CnG"}
@@ -14,9 +14,9 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
14
14
  import React from 'react';
15
15
  import { styled, IconButton, Popover } from '@mui/material';
16
16
  import CircleIcon from 'mdi-material-ui/Circle';
17
- import { useChartsTheme } from '../context/ChartsProvider';
17
+ import { useChartsTheme } from '../context';
18
18
  import { ColorPicker } from './ColorPicker';
19
- export function OptionsColorPicker({ color, onColorChange, label }) {
19
+ export function OptionsColorPicker({ label, color, onColorChange, onClear }) {
20
20
  const [anchorEl, setAnchorEl] = React.useState(null);
21
21
  const isOpen = Boolean(anchorEl);
22
22
  const openColorPicker = (event)=>{
@@ -41,9 +41,11 @@ export function OptionsColorPicker({ color, onColorChange, label }) {
41
41
  open: isOpen,
42
42
  anchorEl: anchorEl,
43
43
  onClose: closeColorPicker,
44
- PaperProps: {
45
- sx: {
46
- padding: (theme)=>theme.spacing(2)
44
+ slotProps: {
45
+ paper: {
46
+ sx: {
47
+ padding: (theme)=>theme.spacing(2)
48
+ }
47
49
  }
48
50
  },
49
51
  anchorOrigin: {
@@ -56,11 +58,12 @@ export function OptionsColorPicker({ color, onColorChange, label }) {
56
58
  },
57
59
  children: /*#__PURE__*/ _jsx(ColorPicker, {
58
60
  color: color,
59
- onChange: onColorChange,
60
61
  palette: [
61
62
  defaultColor,
62
63
  ...palette
63
- ]
64
+ ],
65
+ onChange: onColorChange,
66
+ onClear: onClear
64
67
  })
65
68
  })
66
69
  ]
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/ColorPicker/OptionsColorPicker.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 React from 'react';\nimport { styled, IconButton, Popover } from '@mui/material';\nimport CircleIcon from 'mdi-material-ui/Circle';\nimport { useChartsTheme } from '../context/ChartsProvider';\nimport { ColorPicker } from './ColorPicker';\n\nexport interface OptionsColorPickerProps {\n label: string;\n color: string;\n onColorChange: (color: string) => void;\n}\n\nexport function OptionsColorPicker({ color, onColorChange, label }: OptionsColorPickerProps) {\n const [anchorEl, setAnchorEl] = React.useState<HTMLButtonElement | null>(null);\n const isOpen = Boolean(anchorEl);\n\n const openColorPicker = (event: React.MouseEvent<HTMLButtonElement>) => {\n setAnchorEl(event.currentTarget);\n };\n\n const closeColorPicker = () => {\n setAnchorEl(null);\n };\n\n const {\n thresholds: { defaultColor, palette },\n } = useChartsTheme();\n\n return (\n <>\n <ColorIconButton\n size=\"small\"\n aria-label={`change ${label} color`}\n isSelected={isOpen}\n iconColor={color}\n onClick={openColorPicker}\n >\n <CircleIcon />\n </ColorIconButton>\n <Popover\n data-testid=\"options color picker\"\n open={isOpen}\n anchorEl={anchorEl}\n onClose={closeColorPicker}\n PaperProps={{ sx: { padding: (theme) => theme.spacing(2) } }}\n anchorOrigin={{\n vertical: 'top',\n horizontal: 'left',\n }}\n transformOrigin={{\n vertical: 'top',\n horizontal: 'right',\n }}\n >\n <ColorPicker color={color} onChange={onColorChange} palette={[defaultColor, ...palette]} />\n </Popover>\n </>\n );\n}\n\nconst ColorIconButton = styled(IconButton, {\n shouldForwardProp: (props) => props !== 'isSelected' && props !== 'iconColor',\n})<{\n iconColor?: string;\n isSelected?: boolean;\n}>(({ iconColor, isSelected }) => ({\n backgroundColor: isSelected && iconColor ? `${iconColor}3F` : 'undefined', // 3F represents 25% opacity\n color: iconColor,\n}));\n"],"names":["React","styled","IconButton","Popover","CircleIcon","useChartsTheme","ColorPicker","OptionsColorPicker","color","onColorChange","label","anchorEl","setAnchorEl","useState","isOpen","Boolean","openColorPicker","event","currentTarget","closeColorPicker","thresholds","defaultColor","palette","ColorIconButton","size","aria-label","isSelected","iconColor","onClick","data-testid","open","onClose","PaperProps","sx","padding","theme","spacing","anchorOrigin","vertical","horizontal","transformOrigin","onChange","shouldForwardProp","props","backgroundColor"],"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,OAAOA,WAAW,QAAQ;AAC1B,SAASC,MAAM,EAAEC,UAAU,EAAEC,OAAO,QAAQ,gBAAgB;AAC5D,OAAOC,gBAAgB,yBAAyB;AAChD,SAASC,cAAc,QAAQ,4BAA4B;AAC3D,SAASC,WAAW,QAAQ,gBAAgB;AAQ5C,OAAO,SAASC,mBAAmB,EAAEC,KAAK,EAAEC,aAAa,EAAEC,KAAK,EAA2B;IACzF,MAAM,CAACC,UAAUC,YAAY,GAAGZ,MAAMa,QAAQ,CAA2B;IACzE,MAAMC,SAASC,QAAQJ;IAEvB,MAAMK,kBAAkB,CAACC;QACvBL,YAAYK,MAAMC,aAAa;IACjC;IAEA,MAAMC,mBAAmB;QACvBP,YAAY;IACd;IAEA,MAAM,EACJQ,YAAY,EAAEC,YAAY,EAAEC,OAAO,EAAE,EACtC,GAAGjB;IAEJ,qBACE;;0BACE,KAACkB;gBACCC,MAAK;gBACLC,cAAY,CAAC,OAAO,EAAEf,MAAM,MAAM,CAAC;gBACnCgB,YAAYZ;gBACZa,WAAWnB;gBACXoB,SAASZ;0BAET,cAAA,KAACZ;;0BAEH,KAACD;gBACC0B,eAAY;gBACZC,MAAMhB;gBACNH,UAAUA;gBACVoB,SAASZ;gBACTa,YAAY;oBAAEC,IAAI;wBAAEC,SAAS,CAACC,QAAUA,MAAMC,OAAO,CAAC;oBAAG;gBAAE;gBAC3DC,cAAc;oBACZC,UAAU;oBACVC,YAAY;gBACd;gBACAC,iBAAiB;oBACfF,UAAU;oBACVC,YAAY;gBACd;0BAEA,cAAA,KAACjC;oBAAYE,OAAOA;oBAAOiC,UAAUhC;oBAAea,SAAS;wBAACD;2BAAiBC;qBAAQ;;;;;AAI/F;AAEA,MAAMC,kBAAkBtB,OAAOC,YAAY;IACzCwC,mBAAmB,CAACC,QAAUA,UAAU,gBAAgBA,UAAU;AACpE,GAGG,CAAC,EAAEhB,SAAS,EAAED,UAAU,EAAE,GAAM,CAAA;QACjCkB,iBAAiBlB,cAAcC,YAAY,CAAC,EAAEA,UAAU,EAAE,CAAC,GAAG;QAC9DnB,OAAOmB;IACT,CAAA"}
1
+ {"version":3,"sources":["../../src/ColorPicker/OptionsColorPicker.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 React from 'react';\nimport { styled, IconButton, Popover } from '@mui/material';\nimport CircleIcon from 'mdi-material-ui/Circle';\nimport { useChartsTheme } from '../context';\nimport { ColorPicker } from './ColorPicker';\n\nexport interface OptionsColorPickerProps {\n label: string;\n color: string;\n onColorChange: (color: string) => void;\n onClear?: () => void;\n}\n\nexport function OptionsColorPicker({ label, color, onColorChange, onClear }: OptionsColorPickerProps) {\n const [anchorEl, setAnchorEl] = React.useState<HTMLButtonElement | null>(null);\n const isOpen = Boolean(anchorEl);\n\n const openColorPicker = (event: React.MouseEvent<HTMLButtonElement>) => {\n setAnchorEl(event.currentTarget);\n };\n\n const closeColorPicker = () => {\n setAnchorEl(null);\n };\n\n const {\n thresholds: { defaultColor, palette },\n } = useChartsTheme();\n\n return (\n <>\n <ColorIconButton\n size=\"small\"\n aria-label={`change ${label} color`}\n isSelected={isOpen}\n iconColor={color}\n onClick={openColorPicker}\n >\n <CircleIcon />\n </ColorIconButton>\n <Popover\n data-testid=\"options color picker\"\n open={isOpen}\n anchorEl={anchorEl}\n onClose={closeColorPicker}\n slotProps={{ paper: { sx: { padding: (theme) => theme.spacing(2) } } }}\n anchorOrigin={{\n vertical: 'top',\n horizontal: 'left',\n }}\n transformOrigin={{\n vertical: 'top',\n horizontal: 'right',\n }}\n >\n <ColorPicker color={color} palette={[defaultColor, ...palette]} onChange={onColorChange} onClear={onClear} />\n </Popover>\n </>\n );\n}\n\nconst ColorIconButton = styled(IconButton, {\n shouldForwardProp: (props) => props !== 'isSelected' && props !== 'iconColor',\n})<{\n iconColor?: string;\n isSelected?: boolean;\n}>(({ iconColor, isSelected }) => ({\n backgroundColor: isSelected && iconColor ? `${iconColor}3F` : 'undefined', // 3F represents 25% opacity\n color: iconColor,\n}));\n"],"names":["React","styled","IconButton","Popover","CircleIcon","useChartsTheme","ColorPicker","OptionsColorPicker","label","color","onColorChange","onClear","anchorEl","setAnchorEl","useState","isOpen","Boolean","openColorPicker","event","currentTarget","closeColorPicker","thresholds","defaultColor","palette","ColorIconButton","size","aria-label","isSelected","iconColor","onClick","data-testid","open","onClose","slotProps","paper","sx","padding","theme","spacing","anchorOrigin","vertical","horizontal","transformOrigin","onChange","shouldForwardProp","props","backgroundColor"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6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0C,mBAAmB,CAACC,QAAUA,UAAU,gBAAgBA,UAAU;AACpE,GAGG,CAAC,EAAEjB,SAAS,EAAED,UAAU,EAAE,GAAM,CAAA;QACjCmB,iBAAiBnB,cAAcC,YAAY,CAAC,EAAEA,UAAU,EAAE,CAAC,GAAG;QAC9DnB,OAAOmB;IACT,CAAA"}
@@ -5,5 +5,5 @@ import { TableProps } from './model/table-model';
5
5
  *
6
6
  * **Note: This component is currently experimental and is likely to have significant breaking changes in the near future. Use with caution outside of the core Perses codebase.**
7
7
  */
8
- export declare function Table<TableData>({ data, columns, density, checkboxSelection, onRowSelectionChange, onSortingChange, getCheckboxColor, getRowId, rowSelection, sorting, rowSelectionVariant, ...otherProps }: TableProps<TableData>): import("react/jsx-runtime").JSX.Element;
8
+ export declare function Table<TableData>({ data, columns, cellConfigs, density, checkboxSelection, onRowSelectionChange, onSortingChange, getCheckboxColor, getRowId, rowSelection, sorting, rowSelectionVariant, ...otherProps }: TableProps<TableData>): import("react/jsx-runtime").JSX.Element;
9
9
  //# sourceMappingURL=Table.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Table.d.ts","sourceRoot":"","sources":["../../src/Table/Table.tsx"],"names":[],"mappings":"AA4BA,OAAO,EAAE,UAAU,EAAkC,MAAM,qBAAqB,CAAC;AAYjF;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,SAAS,EAAE,EAC/B,IAAI,EACJ,OAAO,EACP,OAAoB,EACpB,iBAAiB,EACjB,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,QAA6B,EAC7B,YAAoC,EACpC,OAAyB,EACzB,mBAAgC,EAChC,GAAG,UAAU,EACd,EAAE,UAAU,CAAC,SAAS,CAAC,2CA+HvB"}
1
+ {"version":3,"file":"Table.d.ts","sourceRoot":"","sources":["../../src/Table/Table.tsx"],"names":[],"mappings":"AA4BA,OAAO,EAAE,UAAU,EAAkC,MAAM,qBAAqB,CAAC;AAYjF;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,SAAS,EAAE,EAC/B,IAAI,EACJ,OAAO,EACP,WAAW,EACX,OAAoB,EACpB,iBAAiB,EACjB,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,QAA6B,EAC7B,YAAoC,EACpC,OAAyB,EACzB,mBAAgC,EAChC,GAAG,UAAU,EACd,EAAE,UAAU,CAAC,SAAS,CAAC,2CAgIvB"}
@@ -30,7 +30,7 @@ const DEFAULT_SORTING = [];
30
30
  * **not** intended to be a general use data table for use cases unrelated to Perses.
31
31
  *
32
32
  * **Note: This component is currently experimental and is likely to have significant breaking changes in the near future. Use with caution outside of the core Perses codebase.**
33
- */ export function Table({ data, columns, density = 'standard', checkboxSelection, onRowSelectionChange, onSortingChange, getCheckboxColor, getRowId = DEFAULT_GET_ROW_ID, rowSelection = DEFAULT_ROW_SELECTION, sorting = DEFAULT_SORTING, rowSelectionVariant = 'standard', ...otherProps }) {
33
+ */ export function Table({ data, columns, cellConfigs, density = 'standard', checkboxSelection, onRowSelectionChange, onSortingChange, getCheckboxColor, getRowId = DEFAULT_GET_ROW_ID, rowSelection = DEFAULT_ROW_SELECTION, sorting = DEFAULT_SORTING, rowSelectionVariant = 'standard', ...otherProps }) {
34
34
  const theme = useTheme();
35
35
  const handleRowSelectionChange = (rowSelectionUpdater)=>{
36
36
  const newRowSelection = typeof rowSelectionUpdater === 'function' ? rowSelectionUpdater(rowSelection) : rowSelectionUpdater;
@@ -142,7 +142,8 @@ const DEFAULT_SORTING = [];
142
142
  onRowClick: handleRowClick,
143
143
  rows: table.getRowModel().rows,
144
144
  columns: table.getAllFlatColumns(),
145
- headers: table.getHeaderGroups()
145
+ headers: table.getHeaderGroups(),
146
+ cellConfigs: cellConfigs
146
147
  });
147
148
  }
148
149
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/Table/Table.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 {\n useReactTable,\n getCoreRowModel,\n ColumnDef,\n RowSelectionState,\n OnChangeFn,\n Row,\n Table as TanstackTable,\n SortingState,\n getSortedRowModel,\n} from '@tanstack/react-table';\nimport { useTheme } from '@mui/material';\nimport { useCallback, useMemo } from 'react';\nimport { VirtualizedTable } from './VirtualizedTable';\nimport { TableCheckbox } from './TableCheckbox';\nimport { TableProps, persesColumnsToTanstackColumns } from './model/table-model';\n\nconst DEFAULT_GET_ROW_ID = (data: unknown, index: number) => {\n return `${index}`;\n};\n\n// Setting these defaults one enables them to be consistent across renders instead\n// of being recreated every time, which can be important for perf because react\n// does not do deep equality checking for objects and arrays.\nconst DEFAULT_ROW_SELECTION: NonNullable<TableProps<unknown>['rowSelection']> = {};\nconst DEFAULT_SORTING: NonNullable<TableProps<unknown>['sorting']> = [];\n\n/**\n * Component used to render tabular data in Perses use cases. This component is\n * **not** intended to be a general use data table for use cases unrelated to Perses.\n *\n * **Note: This component is currently experimental and is likely to have significant breaking changes in the near future. Use with caution outside of the core Perses codebase.**\n */\nexport function Table<TableData>({\n data,\n columns,\n density = 'standard',\n checkboxSelection,\n onRowSelectionChange,\n onSortingChange,\n getCheckboxColor,\n getRowId = DEFAULT_GET_ROW_ID,\n rowSelection = DEFAULT_ROW_SELECTION,\n sorting = DEFAULT_SORTING,\n rowSelectionVariant = 'standard',\n ...otherProps\n}: TableProps<TableData>) {\n const theme = useTheme();\n\n const handleRowSelectionChange: OnChangeFn<RowSelectionState> = (rowSelectionUpdater) => {\n const newRowSelection =\n typeof rowSelectionUpdater === 'function' ? rowSelectionUpdater(rowSelection) : rowSelectionUpdater;\n onRowSelectionChange?.(newRowSelection);\n };\n\n const handleRowSelectionEvent = useCallback(\n (table: TanstackTable<TableData>, row: Row<TableData>, isModified: boolean) => {\n if (rowSelectionVariant === 'standard' || isModified) {\n row.toggleSelected();\n } else {\n // Legend variant (when action not modified with shift/meta key).\n // Note that this behavior needs to be kept in sync with behavior in\n // the Legend component for list-based legends.\n if (row.getIsSelected() && !table.getIsAllRowsSelected()) {\n // Row was already selected. Revert to select all.\n table.toggleAllRowsSelected();\n } else {\n // Focus the selected row.\n onRowSelectionChange?.({\n [row.id]: true,\n });\n }\n }\n },\n [onRowSelectionChange, rowSelectionVariant]\n );\n\n const handleCheckboxChange = useCallback(\n (e: React.ChangeEvent<HTMLInputElement>, table: TanstackTable<TableData>, row: Row<TableData>) => {\n const nativePointerEvent =\n e.nativeEvent && (e.nativeEvent instanceof MouseEvent || e.nativeEvent instanceof KeyboardEvent)\n ? (e.nativeEvent as PointerEvent)\n : undefined;\n const isModifed = !!nativePointerEvent?.metaKey || !!nativePointerEvent?.shiftKey;\n handleRowSelectionEvent(table, row, isModifed);\n },\n [handleRowSelectionEvent]\n );\n\n const handleSortingChange: OnChangeFn<SortingState> = (sortingUpdater) => {\n const newSorting = typeof sortingUpdater === 'function' ? sortingUpdater(sorting) : sortingUpdater;\n onSortingChange?.(newSorting);\n };\n\n const checkboxColumn: ColumnDef<TableData> = useMemo(() => {\n return {\n id: 'checkboxRowSelect',\n size: 28,\n header: ({ table }) => {\n return (\n <TableCheckbox\n checked={table.getIsAllRowsSelected()}\n indeterminate={table.getIsSomeRowsSelected()}\n onChange={table.getToggleAllRowsSelectedHandler()}\n color={theme.palette.text.primary}\n density={density}\n />\n );\n },\n cell: ({ row, table }) => {\n return (\n <TableCheckbox\n checked={row.getIsSelected()}\n indeterminate={row.getIsSomeSelected()}\n onChange={(e) => {\n handleCheckboxChange(e, table, row);\n }}\n color={getCheckboxColor?.(row.original)}\n density={density}\n />\n );\n },\n enableSorting: false,\n };\n }, [theme.palette.text.primary, density, getCheckboxColor, handleCheckboxChange]);\n\n const tableColumns: Array<ColumnDef<TableData>> = useMemo(() => {\n const initTableColumns = persesColumnsToTanstackColumns(columns);\n\n if (checkboxSelection) {\n initTableColumns.unshift(checkboxColumn);\n }\n\n return initTableColumns;\n }, [checkboxColumn, checkboxSelection, columns]);\n\n const table = useReactTable({\n data,\n columns: tableColumns,\n getRowId,\n getCoreRowModel: getCoreRowModel(),\n getSortedRowModel: getSortedRowModel(),\n enableRowSelection: !!checkboxSelection,\n onRowSelectionChange: handleRowSelectionChange,\n onSortingChange: handleSortingChange,\n // For now, defaulting to sort by descending first. We can expose the ability\n // to customize it if/when we have use cases for it.\n sortDescFirst: true,\n state: {\n rowSelection,\n sorting,\n },\n });\n\n const handleRowClick = useCallback(\n (e: React.MouseEvent<HTMLDivElement, MouseEvent>, rowId: string) => {\n const row = table.getRow(rowId);\n const isModifiedClick = e.metaKey || e.shiftKey;\n handleRowSelectionEvent(table, row, isModifiedClick);\n },\n [handleRowSelectionEvent, table]\n );\n\n return (\n <VirtualizedTable\n {...otherProps}\n density={density}\n onRowClick={handleRowClick}\n rows={table.getRowModel().rows}\n columns={table.getAllFlatColumns()}\n headers={table.getHeaderGroups()}\n />\n );\n}\n"],"names":["useReactTable","getCoreRowModel","getSortedRowModel","useTheme","useCallback","useMemo","VirtualizedTable","TableCheckbox","persesColumnsToTanstackColumns","DEFAULT_GET_ROW_ID","data","index","DEFAULT_ROW_SELECTION","DEFAULT_SORTING","Table","columns","density","checkboxSelection","onRowSelectionChange","onSortingChange","getCheckboxColor","getRowId","rowSelection","sorting","rowSelectionVariant","otherProps","theme","handleRowSelectionChange","rowSelectionUpdater","newRowSelection","handleRowSelectionEvent","table","row","isModified","toggleSelected","getIsSelected","getIsAllRowsSelected","toggleAllRowsSelected","id","handleCheckboxChange","e","nativePointerEvent","nativeEvent","MouseEvent","KeyboardEvent","undefined","isModifed","metaKey","shiftKey","handleSortingChange","sortingUpdater","newSorting","checkboxColumn","size","header","checked","indeterminate","getIsSomeRowsSelected","onChange","getToggleAllRowsSelectedHandler","color","palette","text","primary","cell","getIsSomeSelected","original","enableSorting","tableColumns","initTableColumns","unshift","enableRowSelection","sortDescFirst","state","handleRowClick","rowId","getRow","isModifiedClick","onRowClick","rows","getRowModel","getAllFlatColumns","headers","getHeaderGroups"],"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,SACEA,aAAa,EACbC,eAAe,EAOfC,iBAAiB,QACZ,wBAAwB;AAC/B,SAASC,QAAQ,QAAQ,gBAAgB;AACzC,SAASC,WAAW,EAAEC,OAAO,QAAQ,QAAQ;AAC7C,SAASC,gBAAgB,QAAQ,qBAAqB;AACtD,SAASC,aAAa,QAAQ,kBAAkB;AAChD,SAAqBC,8BAA8B,QAAQ,sBAAsB;AAEjF,MAAMC,qBAAqB,CAACC,MAAeC;IACzC,OAAO,CAAC,EAAEA,MAAM,CAAC;AACnB;AAEA,kFAAkF;AAClF,+EAA+E;AAC/E,6DAA6D;AAC7D,MAAMC,wBAA0E,CAAC;AACjF,MAAMC,kBAA+D,EAAE;AAEvE;;;;;CAKC,GACD,OAAO,SAASC,MAAiB,EAC/BJ,IAAI,EACJK,OAAO,EACPC,UAAU,UAAU,EACpBC,iBAAiB,EACjBC,oBAAoB,EACpBC,eAAe,EACfC,gBAAgB,EAChBC,WAAWZ,kBAAkB,EAC7Ba,eAAeV,qBAAqB,EACpCW,UAAUV,eAAe,EACzBW,sBAAsB,UAAU,EAChC,GAAGC,YACmB;IACtB,MAAMC,QAAQvB;IAEd,MAAMwB,2BAA0D,CAACC;QAC/D,MAAMC,kBACJ,OAAOD,wBAAwB,aAAaA,oBAAoBN,gBAAgBM;QAClFV,iCAAAA,2CAAAA,qBAAuBW;IACzB;IAEA,MAAMC,0BAA0B1B,YAC9B,CAAC2B,OAAiC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BACE,KAACxB;oBACCgD,SAASvB,IAAIG,aAAa;oBAC1BqB,eAAexB,IAAIiC,iBAAiB;oBACpCP,UAAU,CAAClB;wBACTD,qBAAqBC,GAAGT,OAAOC;oBACjC;oBACA4B,KAAK,EAAExC,6BAAAA,uCAAAA,iBAAmBY,IAAIkC,QAAQ;oBACtClD,SAASA;;YAGf;YACAmD,eAAe;QACjB;IACF,GAAG;QAACzC,MAAMmC,OAAO,CAACC,IAAI,CAACC,OAAO;QAAE/C;QAASI;QAAkBmB;KAAqB;IAEhF,MAAM6B,eAA4C/D,QAAQ;QACxD,MAAMgE,mBAAmB7D,+BAA+BO;QAExD,IAAIE,mBAAmB;YACrBoD,iBAAiBC,OAAO,CAAClB;QAC3B;QAEA,OAAOiB;IACT,GAAG;QAACjB;QAAgBnC;QAAmBF;KAAQ;IAE/C,MAAMgB,QAAQ/B,cAAc;QAC1BU;QACAK,SAASqD;QACT/C;QACApB,iBAAiBA;QACjBC,mBAAmBA;QACnBqE,oBAAoB,CAAC,CAACtD;QACtBC,sBAAsBS;QACtBR,iBAAiB8B;QACjB,6EAA6E;QAC7E,oDAAoD;QACpDuB,eAAe;QACfC,OAAO;YACLnD;YACAC;QACF;IACF;IAEA,MAAMmD,iBAAiBtE,YACrB,CAACoC,GAAiDmC;QAChD,MAAM3C,MAAMD,MAAM6C,MAAM,CAACD;QACzB,MAAME,kBAAkBrC,EAAEO,OAAO,IAAIP,EAAEQ,QAAQ;QAC/ClB,wBAAwBC,OAAOC,KAAK6C;IACtC,GACA;QAAC/C;QAAyBC;KAAM;IAGlC,qBACE,KAACzB;QACE,GAAGmB,UAAU;QACdT,SAASA;QACT8D,YAAYJ;QACZK,MAAMhD,MAAMiD,WAAW,GAAGD,IAAI;QAC9BhE,SAASgB,MAAMkD,iBAAiB;QAChCC,SAASnD,MAAMoD,eAAe;;AAGpC"}
1
+ {"version":3,"sources":["../../src/Table/Table.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 {\n useReactTable,\n getCoreRowModel,\n ColumnDef,\n RowSelectionState,\n OnChangeFn,\n Row,\n Table as TanstackTable,\n SortingState,\n getSortedRowModel,\n} from '@tanstack/react-table';\nimport { useTheme } from '@mui/material';\nimport { useCallback, useMemo } from 'react';\nimport { VirtualizedTable } from './VirtualizedTable';\nimport { TableCheckbox } from './TableCheckbox';\nimport { TableProps, persesColumnsToTanstackColumns } from './model/table-model';\n\nconst DEFAULT_GET_ROW_ID = (data: unknown, index: number) => {\n return `${index}`;\n};\n\n// Setting these defaults one enables them to be consistent across renders instead\n// of being recreated every time, which can be important for perf because react\n// does not do deep equality checking for objects and arrays.\nconst DEFAULT_ROW_SELECTION: NonNullable<TableProps<unknown>['rowSelection']> = {};\nconst DEFAULT_SORTING: NonNullable<TableProps<unknown>['sorting']> = [];\n\n/**\n * Component used to render tabular data in Perses use cases. This component is\n * **not** intended to be a general use data table for use cases unrelated to Perses.\n *\n * **Note: This component is currently experimental and is likely to have significant breaking changes in the near future. Use with caution outside of the core Perses codebase.**\n */\nexport function Table<TableData>({\n data,\n columns,\n cellConfigs,\n density = 'standard',\n checkboxSelection,\n onRowSelectionChange,\n onSortingChange,\n getCheckboxColor,\n getRowId = DEFAULT_GET_ROW_ID,\n rowSelection = DEFAULT_ROW_SELECTION,\n sorting = DEFAULT_SORTING,\n rowSelectionVariant = 'standard',\n ...otherProps\n}: TableProps<TableData>) {\n const theme = useTheme();\n\n const handleRowSelectionChange: OnChangeFn<RowSelectionState> = (rowSelectionUpdater) => {\n const newRowSelection =\n typeof rowSelectionUpdater === 'function' ? rowSelectionUpdater(rowSelection) : rowSelectionUpdater;\n onRowSelectionChange?.(newRowSelection);\n };\n\n const handleRowSelectionEvent = useCallback(\n (table: TanstackTable<TableData>, row: Row<TableData>, isModified: boolean) => {\n if (rowSelectionVariant === 'standard' || isModified) {\n row.toggleSelected();\n } else {\n // Legend variant (when action not modified with shift/meta key).\n // Note that this behavior needs to be kept in sync with behavior in\n // the Legend component for list-based legends.\n if (row.getIsSelected() && !table.getIsAllRowsSelected()) {\n // Row was already selected. Revert to select all.\n table.toggleAllRowsSelected();\n } else {\n // Focus the selected row.\n onRowSelectionChange?.({\n [row.id]: true,\n });\n }\n }\n },\n [onRowSelectionChange, rowSelectionVariant]\n );\n\n const handleCheckboxChange = useCallback(\n (e: React.ChangeEvent<HTMLInputElement>, table: TanstackTable<TableData>, row: Row<TableData>) => {\n const nativePointerEvent =\n e.nativeEvent && (e.nativeEvent instanceof MouseEvent || e.nativeEvent instanceof KeyboardEvent)\n ? (e.nativeEvent as PointerEvent)\n : undefined;\n const isModifed = !!nativePointerEvent?.metaKey || !!nativePointerEvent?.shiftKey;\n handleRowSelectionEvent(table, row, isModifed);\n },\n [handleRowSelectionEvent]\n );\n\n const handleSortingChange: OnChangeFn<SortingState> = (sortingUpdater) => {\n const newSorting = typeof sortingUpdater === 'function' ? sortingUpdater(sorting) : sortingUpdater;\n onSortingChange?.(newSorting);\n };\n\n const checkboxColumn: ColumnDef<TableData> = useMemo(() => {\n return {\n id: 'checkboxRowSelect',\n size: 28,\n header: ({ table }) => {\n return (\n <TableCheckbox\n checked={table.getIsAllRowsSelected()}\n indeterminate={table.getIsSomeRowsSelected()}\n onChange={table.getToggleAllRowsSelectedHandler()}\n color={theme.palette.text.primary}\n density={density}\n />\n );\n },\n cell: ({ row, table }) => {\n return (\n <TableCheckbox\n checked={row.getIsSelected()}\n indeterminate={row.getIsSomeSelected()}\n onChange={(e) => {\n handleCheckboxChange(e, table, row);\n }}\n color={getCheckboxColor?.(row.original)}\n density={density}\n />\n );\n },\n enableSorting: false,\n };\n }, [theme.palette.text.primary, density, getCheckboxColor, handleCheckboxChange]);\n\n const tableColumns: Array<ColumnDef<TableData>> = useMemo(() => {\n const initTableColumns = persesColumnsToTanstackColumns(columns);\n\n if (checkboxSelection) {\n initTableColumns.unshift(checkboxColumn);\n }\n\n return initTableColumns;\n }, [checkboxColumn, checkboxSelection, columns]);\n\n const table = useReactTable({\n data,\n columns: tableColumns,\n getRowId,\n getCoreRowModel: getCoreRowModel(),\n getSortedRowModel: getSortedRowModel(),\n enableRowSelection: !!checkboxSelection,\n onRowSelectionChange: handleRowSelectionChange,\n onSortingChange: handleSortingChange,\n // For now, defaulting to sort by descending first. We can expose the ability\n // to customize it if/when we have use cases for it.\n sortDescFirst: true,\n state: {\n rowSelection,\n sorting,\n },\n });\n\n const handleRowClick = useCallback(\n (e: React.MouseEvent<HTMLDivElement, MouseEvent>, rowId: string) => {\n const row = table.getRow(rowId);\n const isModifiedClick = e.metaKey || e.shiftKey;\n handleRowSelectionEvent(table, row, isModifiedClick);\n },\n [handleRowSelectionEvent, table]\n );\n\n return (\n <VirtualizedTable\n {...otherProps}\n density={density}\n onRowClick={handleRowClick}\n rows={table.getRowModel().rows}\n columns={table.getAllFlatColumns()}\n headers={table.getHeaderGroups()}\n cellConfigs={cellConfigs}\n />\n );\n}\n"],"names":["useReactTable","getCoreRowModel","getSortedRowModel","useTheme","useCallback","useMemo","VirtualizedTable","TableCheckbox","persesColumnsToTanstackColumns","DEFAULT_GET_ROW_ID","data","index","DEFAULT_ROW_SELECTION","DEFAULT_SORTING","Table","columns","cellConfigs","density","checkboxSelection","onRowSelectionChange","onSortingChange","getCheckboxColor","getRowId","rowSelection","sorting","rowSelectionVariant","otherProps","theme","handleRowSelectionChange","rowSelectionUpdater","newRowSelection","handleRowSelectionEvent","table","row","isModified","toggleSelected","getIsSelected","getIsAllRowsSelected","toggleAllRowsSelected","id","handleCheckboxChange","e","nativePointerEvent","nativeEvent","MouseEvent","KeyboardEvent","undefined","isModifed","metaKey","shiftKey","handleSortingChange","sortingUpdater","newSorting","checkboxColumn","size","header","checked","indeterminate","getIsSomeRowsSelected","onChange","getToggleAllRowsSelectedHandler","color","palette","text","primary","cell","getIsSomeSelected","original","enableSorting","tableColumns","initTableColumns","unshift","enableRowSelection","sortDescFirst","state","handleRowClick","rowId","getRow","isModifiedClick","onRowClick","rows","getRowModel","getAllFlatColumns","headers","getHeaderGroups"],"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,SACEA,aAAa,EACbC,eAAe,EAOfC,iBAAiB,QACZ,wBAAwB;AAC/B,SAASC,QAAQ,QAAQ,gBAAgB;AACzC,SAASC,WAAW,EAAEC,OAAO,QAAQ,QAAQ;AAC7C,SAASC,gBAAgB,QAAQ,qBAAqB;AACtD,SAASC,aAAa,QAAQ,kBAAkB;AAChD,SAAqBC,8BAA8B,QAAQ,sBAAsB;AAEjF,MAAMC,qBAAqB,CAACC,MAAeC;IACzC,OAAO,CAAC,EAAEA,MAAM,CAAC;AACnB;AAEA,kFAAkF;AAClF,+EAA+E;AAC/E,6DAA6D;AAC7D,MAAMC,wBAA0E,CAAC;AACjF,MAAMC,kBAA+D,EAAE;AAEvE;;;;;CAKC,GACD,OAAO,SAASC,MAAiB,EAC/BJ,IAAI,EACJK,OAAO,EACPC,WAAW,EACXC,UAAU,UAAU,EACpBC,iBAAiB,EACjBC,oBAAoB,EACpBC,eAAe,EACfC,gBAAgB,EAChBC,WAAWb,kBAAkB,EAC7Bc,eAAeX,qBAAqB,EACpCY,UAAUX,eAAe,EACzBY,sBAAsB,UAAU,EAChC,GAAGC,YACmB;IACtB,MAAMC,QAAQxB;IAEd,MAAMyB,2BAA0D,CAACC;QAC/D,MAAMC,kBACJ,OAAOD,wBAAwB,aAAaA,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AMoD,eAAe;QAC9BpE,aAAaA;;AAGnB"}
@@ -26,6 +26,8 @@ export interface TableCellProps extends Omit<MuiTableCellProps, 'tabIndex' | 'al
26
26
  */
27
27
  focusState?: 'trigger-focus' | 'focus-next' | 'none';
28
28
  onFocusTrigger?: (e: React.MouseEvent<HTMLTableCellElement> | React.KeyboardEvent<HTMLTableCellElement>) => void;
29
+ color?: string;
30
+ backgroundColor?: string;
29
31
  }
30
- export declare function TableCell({ children, density, variant, width, focusState, onFocusTrigger, isFirstColumn, isLastColumn, description, align, ...otherProps }: TableCellProps): import("react/jsx-runtime").JSX.Element;
32
+ export declare function TableCell({ children, density, variant, width, focusState, onFocusTrigger, isFirstColumn, isLastColumn, description, align, color, backgroundColor, ...otherProps }: TableCellProps): import("react/jsx-runtime").JSX.Element;
31
33
  //# sourceMappingURL=TableCell.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TableCell.d.ts","sourceRoot":"","sources":["../../src/Table/TableCell.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAqC,cAAc,IAAI,iBAAiB,EAAiB,MAAM,eAAe,CAAC;AAEtH,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAsB,MAAM,qBAAqB,CAAC;AAmB3F,MAAM,WAAW,cAAe,SAAQ,IAAI,CAAC,iBAAiB,EAAE,UAAU,GAAG,OAAO,CAAC;IACnF,OAAO,EAAE,YAAY,CAAC;IAGtB,YAAY,EAAE,OAAO,CAAC;IACtB,aAAa,EAAE,OAAO,CAAC;IAEvB,KAAK,CAAC,EAAE,kBAAkB,CAAC;IAE3B;;;;;;;;OAQG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;;;;;OAOG;IACH,UAAU,CAAC,EAAE,eAAe,GAAG,YAAY,GAAG,MAAM,CAAC;IACrD,cAAc,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,oBAAoB,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC,oBAAoB,CAAC,KAAK,IAAI,CAAC;CAClH;AAED,wBAAgB,SAAS,CAAC,EACxB,QAAQ,EACR,OAAO,EACP,OAAO,EACP,KAAK,EACL,UAAmB,EACnB,cAAc,EACd,aAAa,EACb,YAAY,EACZ,WAAW,EACX,KAAK,EACL,GAAG,UAAU,EACd,EAAE,cAAc,2CA6EhB"}
1
+ {"version":3,"file":"TableCell.d.ts","sourceRoot":"","sources":["../../src/Table/TableCell.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAqC,cAAc,IAAI,iBAAiB,EAAiB,MAAM,eAAe,CAAC;AAEtH,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAsB,MAAM,qBAAqB,CAAC;AAmB3F,MAAM,WAAW,cAAe,SAAQ,IAAI,CAAC,iBAAiB,EAAE,UAAU,GAAG,OAAO,CAAC;IACnF,OAAO,EAAE,YAAY,CAAC;IAGtB,YAAY,EAAE,OAAO,CAAC;IACtB,aAAa,EAAE,OAAO,CAAC;IAEvB,KAAK,CAAC,EAAE,kBAAkB,CAAC;IAE3B;;;;;;;;OAQG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;;;;;OAOG;IACH,UAAU,CAAC,EAAE,eAAe,GAAG,YAAY,GAAG,MAAM,CAAC;IACrD,cAAc,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,oBAAoB,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC,oBAAoB,CAAC,KAAK,IAAI,CAAC;IACjH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAgB,SAAS,CAAC,EACxB,QAAQ,EACR,OAAO,EACP,OAAO,EACP,KAAK,EACL,UAAmB,EACnB,cAAc,EACd,aAAa,EACb,YAAY,EACZ,WAAW,EACX,KAAK,EACL,KAAK,EACL,eAAe,EACf,GAAG,UAAU,EACd,EAAE,cAAc,2CAiFhB"}
@@ -29,7 +29,7 @@ const StyledMuiTableCell = styled(MuiTableCell)(({ theme })=>({
29
29
  borderRadius: 0
30
30
  }
31
31
  }));
32
- export function TableCell({ children, density, variant, width, focusState = 'none', onFocusTrigger, isFirstColumn, isLastColumn, description, align, ...otherProps }) {
32
+ export function TableCell({ children, density, variant, width, focusState = 'none', onFocusTrigger, isFirstColumn, isLastColumn, description, align, color, backgroundColor, ...otherProps }) {
33
33
  const theme = useTheme();
34
34
  const elRef = useRef();
35
35
  const isHeader = variant === 'head';
@@ -90,6 +90,10 @@ export function TableCell({ children, density, variant, width, focusState = 'non
90
90
  // in headers.
91
91
  flexDirection: 'inherit'
92
92
  },
93
+ style: {
94
+ backgroundColor: backgroundColor !== null && backgroundColor !== void 0 ? backgroundColor : 'inherit',
95
+ color: color !== null && color !== void 0 ? color : 'inherit'
96
+ },
93
97
  title: description,
94
98
  "aria-label": description,
95
99
  textAlign: align,
@@ -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 * 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 align,\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 aria-label={description}\n textAlign={align}\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","align","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","aria-label","textAlign"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF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E,CAACJ;QACvE,wEAAwE;QACxE,uEAAuE;QACvE,iEAAiE;QACjE,yEAAyE;QACzE,0CAA0C;QAC1CX,2BAAAA,qCAAAA,eAAiBW;IACnB;IAEA,qBACE,KAAC5B;QACE,GAAGsB,UAAU;QACd,2EAA2E;QAC3E,wEAAwE;QACxE,qEAAqE;QACrE,QAAQ;QACRW,UAAUjB,eAAe,SAAS,IAAI,CAAC;QACvCkB,SAASP;QACTQ,SAASH;QACTI,SAASJ;QACTK,IAAI;YACFtB,OAAOA;YACPuB,cAAcd,WACV,CAACvB,QAAU,CAAC,UAAU,EAAEA,MAAMG,OAAO,CAACmC,IAAI,CAAC,IAAI,CAAC,CAAC,GACjD,CAAC,UAAU,EAAEtC,MAAMG,OAAO,CAACmC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC3C;QACAC,KAAKjB;kBAEL,cAAA,KAAC5B;YACC0C,IAAI;gBACF,GAAGtC,mBAAmBE,OAAOY,SAAS;oBAAEM;oBAAcD;gBAAc,EAAE;gBACtEuB,UAAU;gBAEV,mEAAmE;gBACnE,mDAAmD;gBACnDC,YAAY;gBACZC,UAAU;gBACVC,cAAc;gBAEd,uEAAuE;gBACvE,uEAAuE;gBACvE,cAAc;gBACdC,eAAe;YACjB;YACAC,OAAO1B;YACP2B,cAAY3B;YACZ4B,WAAW3B;sBAEVT;;;AAIT"}
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 color?: string;\n backgroundColor?: string;\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 align,\n color,\n backgroundColor,\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 style={{\n backgroundColor: backgroundColor ?? 'inherit',\n color: color ?? 'inherit',\n }}\n title={description}\n aria-label={description}\n textAlign={align}\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","align","color","otherProps","elRef","isHeader","current","focus","handleFocus","e","nestedFocusTarget","currentTarget","querySelector","handleInteractionFocusTrigger","tabIndex","onFocus","onClick","onKeyUp","sx","borderBottom","grey","ref","position","whiteSpace","overflow","textOverflow","flexDirection","style","title","aria-label","textAlign"],"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,SAASA,aAAaC,YAAY,EAAEC,MAAM,EAAuCC,GAAG,EAAEC,QAAQ,QAAQ,gBAAgB;AACtH,SAASC,SAAS,EAAEC,MAAM,QAAQ,QAAQ;AAC1C,SAA2CC,kBAAkB,QAAQ,sBAAsB;AAE3F,MAAMC,qBAAqBN,OAAOD,cAAc,CAAC,EAAEQ,KAAK,EAAE,GAAM,CAAA;QAC9DC,SAAS;QACTC,iBAAiB;QAEjB,uBAAuB;YACrB,kEAAkE;YAClEA,iBAAiBF,MAAMG,OAAO,CAACC,UAAU,CAACC,OAAO;QACnD;QACA,mBAAmB;YACjBC,SAAS,CAAC,UAAU,EAAEN,MAAMG,OAAO,CAACI,OAAO,CAACC,IAAI,CAAC,CAAC;YAClD,uEAAuE;YACvE,4BAA4B;YAC5BC,eAAe;YACfC,cAAc;QAChB;IACF,CAAA;AAoCA,OAAO,SAASnB,UAAU,EACxBoB,QAAQ,EACRC,OAAO,EACPC,OAAO,EACPC,KAAK,EACLC,aAAa,MAAM,EACnBC,cAAc,EACdC,aAAa,EACbC,YAAY,EACZC,WAAW,EACXC,KAAK,EACLC,KAAK,EACLnB,eAAe,EACf,GAAGoB,YACY;IACf,MA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A,4BAAAA,6BAAAA,kBAAmB;gBACpCmB,OAAOA,kBAAAA,mBAAAA,QAAS;YAClB;YACA0B,OAAO5B;YACP6B,cAAY7B;YACZ8B,WAAW7B;sBAEVT;;;AAIT"}
@@ -1,11 +1,12 @@
1
1
  /// <reference types="react" />
2
2
  import { Column, HeaderGroup, Row } from '@tanstack/react-table';
3
- import { TableProps } from './model/table-model';
3
+ import { TableCellConfigs, TableProps } from './model/table-model';
4
4
  export type VirtualizedTableProps<TableData> = Required<Pick<TableProps<TableData>, 'height' | 'width' | 'density'>> & Pick<TableProps<TableData>, 'onRowMouseOver' | 'onRowMouseOut'> & {
5
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
+ cellConfigs?: TableCellConfigs;
9
10
  };
10
- export declare function VirtualizedTable<TableData>({ width, height, density, onRowClick, onRowMouseOver, onRowMouseOut, rows, columns, headers, }: VirtualizedTableProps<TableData>): import("react/jsx-runtime").JSX.Element;
11
+ export declare function VirtualizedTable<TableData>({ width, height, density, onRowClick, onRowMouseOver, onRowMouseOut, rows, columns, headers, cellConfigs, }: VirtualizedTableProps<TableData>): import("react/jsx-runtime").JSX.Element;
11
12
  //# 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;AAW7E,OAAO,EAAE,UAAU,EAAqB,MAAM,qBAAqB,CAAC;AAQpE,MAAM,MAAM,qBAAqB,CAAC,SAAS,IAAI,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,QAAQ,GAAG,OAAO,GAAG,SAAS,CAAC,CAA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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;IACvC,WAAW,CAAC,EAAE,gBAAgB,CAAC;CAChC,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,EACP,WAAW,GACZ,EAAE,qBAAqB,CAAC,SAAS,CAAC,2CAkLlC"}
@@ -26,7 +26,7 @@ import { useVirtualizedTableKeyboardNav } from './hooks/useVirtualizedTableKeybo
26
26
  // Separating out the virtualized table because we may want a paginated table
27
27
  // in the future that does not need virtualization, and we'd likely lay them
28
28
  // out differently.
29
- export function VirtualizedTable({ width, height, density, onRowClick, onRowMouseOver, onRowMouseOut, rows, columns, headers }) {
29
+ export function VirtualizedTable({ width, height, density, onRowClick, onRowMouseOver, onRowMouseOut, rows, columns, headers, cellConfigs }) {
30
30
  const virtuosoRef = useRef(null);
31
31
  // Use a ref for these values because they are only needed for keyboard
32
32
  // focus interactions and setting them on state will lead to a significant
@@ -158,6 +158,7 @@ export function VirtualizedTable({ width, height, density, onRowClick, onRowMous
158
158
  column: i
159
159
  };
160
160
  const cellContext = cell.getContext();
161
+ const cellConfig = cellConfigs === null || cellConfigs === void 0 ? void 0 : cellConfigs[cellContext.cell.id];
161
162
  const cellRenderFn = cell.column.columnDef.cell;
162
163
  const cellContent = typeof cellRenderFn === 'function' ? cellRenderFn(cellContext) : null;
163
164
  const cellDescriptionDef = (_cell_column_columnDef_meta = cell.column.columnDef.meta) === null || _cell_column_columnDef_meta === void 0 ? void 0 : _cell_column_columnDef_meta.cellDescription;
@@ -172,7 +173,10 @@ export function VirtualizedTable({ width, height, density, onRowClick, onRowMous
172
173
  // cell content.
173
174
  description = cellContent;
174
175
  }
176
+ var _cellConfig_textColor, _cellConfig_backgroundColor;
175
177
  return /*#__PURE__*/ _jsx(TableCell, {
178
+ "data-testid": cell.id,
179
+ title: description || (cellConfig === null || cellConfig === void 0 ? void 0 : cellConfig.text) || cellContent,
176
180
  width: cell.column.getSize() || 'auto',
177
181
  align: (_cell_column_columnDef_meta1 = cell.column.columnDef.meta) === null || _cell_column_columnDef_meta1 === void 0 ? void 0 : _cell_column_columnDef_meta1.align,
178
182
  density: density,
@@ -181,7 +185,9 @@ export function VirtualizedTable({ width, height, density, onRowClick, onRowMous
181
185
  isFirstColumn: i === 0,
182
186
  isLastColumn: i === cells.length - 1,
183
187
  description: description,
184
- children: cellContent
188
+ color: (_cellConfig_textColor = cellConfig === null || cellConfig === void 0 ? void 0 : cellConfig.textColor) !== null && _cellConfig_textColor !== void 0 ? _cellConfig_textColor : undefined,
189
+ backgroundColor: (_cellConfig_backgroundColor = cellConfig === null || cellConfig === void 0 ? void 0 : cellConfig.backgroundColor) !== null && _cellConfig_backgroundColor !== void 0 ? _cellConfig_backgroundColor : undefined,
190
+ children: (cellConfig === null || cellConfig === void 0 ? void 0 : cellConfig.text) || cellContent
185
191
  }, cell.id);
186
192
  })
187
193
  });
@@ -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 { 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,SAAmCA,UAAU,QAAQ,wBAAwB;AAC7E,SAASC,GAAG,QAAQ,gBAAgB;AACpC,SAASC,aAAa,QAAkE,iBAAiB;AACzG,SAASC,MAAM,EAAEC,OAAO,QAAQ,QAAQ;AACxC,SAASC,QAAQ,QAAQ,aAAa;AACtC,SAASC,SAAS,QAAQ,cAAc;AACxC,SAASC,UAAU,QAAQ,eAAe;AAC1C,SAASC,SAAS,QAAQ,cAAc;AACxC,SAASC,eAAe,QAAQ,oBAAoB;AACpD,SAASC,SAAS,QAAwB,cAAc;AACxD,SAASC,yBAAyB,QAAQ,8BAA8B;AAExE,SAASC,8BAA8B,QAAQ,yCAAyC;AAexF,6EAA6E;AAC7E,4EAA4E;AAC5E,mBAAmB;AACnB,OAAO,SAASC,iBAA4B,EAC1CC,KAAK,EACLC,MAAM,EACNC,OAAO,EACPC,UAAU,EACVC,cAAc,EACdC,aAAa,EACbC,IAAI,EACJC,OAAO,EACPC,OAAO,EAC0B;IACjC,MAAMC,cAAcpB,OAA4B;IAEhD,uEAAuE;IACvE,0EAA0E;IAC1E,oCAAoC;IACpC,MAAMqB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BACnCgD,aAAaA;sCAEZc;2BAVIJ,KAAKzC,EAAE;oBAalB;;YAGN;;;AAIR"}
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 { TableCellConfigs, 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 cellConfigs?: TableCellConfigs;\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 cellConfigs,\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 cellConfig = cellConfigs?.[cellContext.cell.id];\n\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 data-testid={cell.id}\n title={description || cellConfig?.text || cellContent}\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 color={cellConfig?.textColor ?? undefined}\n backgroundColor={cellConfig?.backgroundColor ?? undefined}\n >\n {cellConfig?.text || 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","cellConfigs","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","cellConfig","cellRenderFn","cellContent","cellDescriptionDef","cellDescription","data-testid","title","text","color","textColor","backgroundColor"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2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AGN;;;AAIR"}
@@ -33,6 +33,12 @@ export interface TableProps<TableData> {
33
33
  * table rows.
34
34
  */
35
35
  columns: Array<TableColumnConfig<TableData>>;
36
+ /**
37
+ * Custom render cell configurations. Each entry of the object should be an
38
+ * id for cell `${rowIndex}_${columnIndex}`, can apply custom text, text color
39
+ * and background color.
40
+ */
41
+ cellConfigs?: TableCellConfigs;
36
42
  /**
37
43
  * The density of the table layout. This impacts the size and space taken up
38
44
  * by content in the table (e.g. font size, padding).
@@ -109,6 +115,14 @@ type GetTableCellLayoutOpts = {
109
115
  */
110
116
  export declare function getTableCellLayout(theme: Theme, density: TableDensity, { isLastColumn, isFirstColumn }?: GetTableCellLayoutOpts): TableCellLayout;
111
117
  export type TableCellAlignment = 'left' | 'right' | 'center';
118
+ export interface TableCellConfigs {
119
+ [id: string]: TableCellConfig;
120
+ }
121
+ export interface TableCellConfig {
122
+ text?: string;
123
+ textColor?: string;
124
+ backgroundColor?: string;
125
+ }
112
126
  declare module '@tanstack/table-core' {
113
127
  interface ColumnMeta<TData extends RowData, TValue> {
114
128
  align?: TableColumnConfig<TData>['align'];
@@ -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,EACL,oBAAoB,EACpB,WAAW,EACX,SAAS,EACT,WAAW,EACX,OAAO,EACP,iBAAiB,EACjB,YAAY,EACb,MAAM,uBAAuB,CAAC;AAG/B,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,UAAU,GAAG,aAAa,CAAC;AAClE,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,MAAM,GAAG,SAAS,CAAC;AAEvD,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,WAAW,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