@economic/taco 2.9.2 → 2.10.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/components/Button/Button.d.ts +1 -1
- package/dist/components/IconButton/IconButton.d.ts +2 -2
- package/dist/components/Provider/Localization.d.ts +6 -0
- package/dist/components/Table3/components/columns/header/Header.d.ts +6 -1
- package/dist/components/Table3/components/columns/header/Menu.d.ts +4 -0
- package/dist/components/Table3/hooks/features/useCurrentRow.d.ts +6 -5
- package/dist/components/Table3/hooks/useCssVars.d.ts +2 -1
- package/dist/components/Table3/hooks/useTable.d.ts +1 -0
- package/dist/components/Table3/types.d.ts +7 -0
- package/dist/esm/index.css +92 -16
- package/dist/esm/packages/taco/src/components/Button/util.js +5 -1
- package/dist/esm/packages/taco/src/components/Button/util.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Menu/components/Content.js +1 -1
- package/dist/esm/packages/taco/src/components/Menu/components/Content.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Provider/Localization.js +7 -1
- package/dist/esm/packages/taco/src/components/Provider/Localization.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/Table3.js +13 -6
- package/dist/esm/packages/taco/src/components/Table3/Table3.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/Cell.js +3 -2
- package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/Cell.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/DisplayCell.js +5 -3
- package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/DisplayCell.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/EditingCell.js +5 -3
- package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/EditingCell.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/EditingControl.js +0 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/EditingControl.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/controls/TextareaControl.js +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/controls/TextareaControl.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/header/Header.js +30 -6
- package/dist/esm/packages/taco/src/components/Table3/components/columns/header/Header.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/header/Menu.js +36 -10
- package/dist/esm/packages/taco/src/components/Table3/components/columns/header/Menu.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/internal/Actions.js +3 -3
- package/dist/esm/packages/taco/src/components/Table3/components/columns/internal/Actions.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/internal/Drag.js +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/internal/Drag.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/internal/EditingActions.js +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/internal/EditingActions.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/internal/Expansion.js +2 -2
- package/dist/esm/packages/taco/src/components/Table3/components/columns/internal/Expansion.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/internal/Selection.js +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/internal/Selection.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/rows/Row.js +87 -40
- package/dist/esm/packages/taco/src/components/Table3/components/rows/Row.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/PrintButton/PrintButton.js +10 -0
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/PrintButton/PrintButton.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/features/useCurrentRow.js +28 -2
- package/dist/esm/packages/taco/src/components/Table3/hooks/features/useCurrentRow.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/features/useRowClick.js +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/features/useRowClick.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/features/useRowSelection.js +5 -2
- package/dist/esm/packages/taco/src/components/Table3/hooks/features/useRowSelection.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/listeners/useCurrentRowListener.js +2 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/listeners/useCurrentRowListener.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/listeners/useEditingStateListener.js +8 -4
- package/dist/esm/packages/taco/src/components/Table3/hooks/listeners/useEditingStateListener.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/listeners/useShortcutsListener.js +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/listeners/useShortcutsListener.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/useConvertChildrenToColumns.js +2 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/useConvertChildrenToColumns.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/useCssVars.js +15 -2
- package/dist/esm/packages/taco/src/components/Table3/hooks/useCssVars.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/useTable.js +1 -0
- package/dist/esm/packages/taco/src/components/Table3/hooks/useTable.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/types.js.map +1 -1
- package/dist/index.css +92 -16
- package/dist/taco.cjs.development.js +272 -96
- package/dist/taco.cjs.development.js.map +1 -1
- package/dist/taco.cjs.production.min.js +1 -1
- package/dist/taco.cjs.production.min.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/package.json +2 -2
- package/types.json +5803 -5242
package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/EditingControl.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"EditingControl.js","sources":["../../../../../../../../../../src/components/Table3/components/columns/cell/EditingControl.tsx"],"sourcesContent":["import React from 'react';\nimport cn from 'classnames';\nimport { Cell as RTCell, Column as RTColumn, Table as RTTable, TableMeta } from '@tanstack/react-table';\nimport _ from 'lodash';\n\nimport { deselectInputValue } from '../../../../../utils/input';\nimport { hasChanged } from '../../../util/editing';\nimport { Datepicker } from '../../../../Datepicker/Datepicker';\nimport { Switch } from '../../../../Switch/Switch';\nimport { Input } from '../../../../Input/Input';\nimport { getCellAlignmentClasses, getInputAppearanceClassnames } from '../styles';\nimport { mergeRefs } from '../../../../../utils/mergeRefs';\nimport { Table3ColumnAlignment } from '../../../types';\nimport { TextareaControl } from './controls/TextareaControl';\nimport { shouldTriggerShortcut } from '../../../../../utils/keyboard';\n\nexport type EditingControlProps<TType = unknown> = {\n align?: Table3ColumnAlignment;\n column: RTColumn<TType, unknown>;\n data: TType;\n initialValue: any;\n value: any;\n onBlur: (event: React.FocusEvent) => void;\n onFocus: (event: React.FocusEvent) => void;\n onChange: (value: any) => void;\n ref: React.Ref<HTMLElement>;\n table: RTTable<TType>;\n tableRef: React.RefObject<HTMLDivElement>;\n cell: RTCell<TType, unknown>;\n error?: string;\n tabIndex?: number;\n isCurrentRow?: boolean;\n};\n\nexport const EditingControl = React.forwardRef<HTMLElement, any>(function Control<TType = unknown>(\n props: EditingControlProps<TType>,\n externalRef: React.Ref<HTMLElement>\n) {\n const {\n align,\n column,\n data,\n initialValue,\n onChange: handleChange,\n table,\n tableRef,\n value,\n cell,\n isCurrentRow,\n ...attributes\n } = props;\n\n const tableMeta = table.options.meta as TableMeta<unknown>;\n\n const ref = React.useRef<HTMLElement>();\n const refCallback = mergeRefs([ref, externalRef]);\n\n const columnMeta = column.columnDef.meta;\n const controlRenderer = columnMeta?.control;\n\n const isCellInDetailMode =\n tableMeta.editing.detailModeEditing && (ref as React.RefObject<HTMLElement>)?.current?.contains(document.activeElement);\n\n const handleKeyDown = (event: React.KeyboardEvent) => {\n // For some reason keydown event handler is not propogated to the table when input or other control element is\n // in focus so we need to check for shortcut that toggles the editing.\n if (shouldTriggerShortcut(event, { key: 'e', meta: true, shift: false })) {\n tableMeta.editing.toggleEditing(false);\n return;\n }\n\n const target = event.target as HTMLInputElement;\n\n if (target.readOnly) {\n return;\n }\n\n // Prevent row arrow shortcuts triggering when in detail mode\n if (tableMeta.editing.detailModeEditing && (event.key === 'ArrowUp' || event.key === 'ArrowDown')) {\n event.stopPropagation();\n }\n\n // Revert to initial value if escape was pressed\n if (event.key === 'Escape') {\n event.preventDefault();\n\n if (tableMeta.editing.detailModeEditing) {\n tableMeta.editing.setDetailModeEditing(false);\n\n if (value !== initialValue) {\n // Before reseting to initial value, we need to check if edited row with cell initial value is the same as original row,\n // and in this case we need to completely remove row from editing state to avoid saving the same data as original.\n const changedRow: any = tableMeta.editing.changes ? tableMeta.editing.changes[cell.row.id] : {};\n const rowEdtitingDataWithInitialValue = { ...changedRow, [cell.column.id]: initialValue };\n if (_.isEqual(cell.row.original, rowEdtitingDataWithInitialValue)) {\n tableMeta.editing.resetChange(cell.row.id);\n } else {\n handleChange(initialValue);\n }\n }\n } else {\n tableMeta.editing.toggleEditing(false);\n tableRef.current?.focus();\n }\n\n return;\n }\n\n // Should enable/disable editing mode if Enter was clicked\n if (event.key === 'Enter') {\n event.preventDefault();\n\n if (!tableMeta.editing.detailModeEditing) {\n deselectInputValue(target);\n } else {\n target?.select?.();\n }\n\n // Ketydown \"Enter\" should toggle edititng mode\n tableMeta.editing.setDetailModeEditing(!tableMeta.editing.detailModeEditing);\n\n return;\n }\n };\n\n const isNumber = typeof value === 'number';\n const handleInputKeyDown = (event: React.KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n handleKeyDown(event);\n\n // Switching to editing mode, when key pressed any alphabetical character or number\n if (/^[a-z0-9]$/i.test(event.key)) {\n tableMeta.editing.setDetailModeEditing(true);\n }\n };\n\n const handleDatepickerChange = event => {\n // When datepicker looses focus, it triggers change event, even if date wasn't changed,\n // so adding additional check here to prevent adding change to the edititng state.\n const originalDate = cell.row.original[cell.column.id];\n const changedDate = (event as any).detail;\n if (hasChanged(originalDate, changedDate)) {\n handleChange(changedDate);\n }\n };\n\n if (typeof controlRenderer === 'function') {\n return controlRenderer(\n {\n ...attributes,\n ref: ref,\n setValue: nextValue => {\n if (nextValue !== value) {\n handleChange(nextValue);\n }\n },\n value,\n },\n data\n );\n } else if (controlRenderer === 'datepicker') {\n const handleDatepickerKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {\n handleKeyDown(event);\n\n if (/^[a-z0-9]$/i.test(event.key)) {\n tableMeta.editing.setDetailModeEditing(true);\n return;\n }\n };\n\n return (\n <Datepicker\n {...attributes}\n className={cn({\n '[&_input]:!yt-focus-dark': isCellInDetailMode,\n })}\n onChange={handleDatepickerChange}\n onKeyDown={handleDatepickerKeyDown}\n ref={refCallback}\n value={value as Date}\n />\n );\n } else if (controlRenderer === 'switch') {\n return (\n <Switch {...attributes} className=\"mx-2 mt-1.5\" checked={Boolean(value)} onChange={handleChange} ref={refCallback} />\n );\n } else if (controlRenderer === 'textarea') {\n return (\n <TextareaControl\n {...props}\n isCellInDetailMode={isCellInDetailMode}\n onKeyDown={handleInputKeyDown}\n ref={refCallback}\n fontSize={tableMeta.fontSize.size}\n />\n );\n }\n\n return (\n <Input\n {...attributes}\n className={cn(getInputAppearanceClassnames(), getCellAlignmentClasses(align), {\n '!yt-focus-dark': isCellInDetailMode,\n })}\n onChange={event => {\n handleChange(event.target.value);\n }}\n onKeyDown={handleInputKeyDown}\n ref={refCallback}\n type={isNumber ? 'number' : undefined}\n value={isNumber ? value : String(value ?? '')}\n />\n );\n});\n"],"names":["EditingControl","React","forwardRef","Control","props","externalRef","align","column","data","initialValue","onChange","handleChange","table","tableRef","value","cell","isCurrentRow","attributes","tableMeta","options","meta","ref","useRef","refCallback","mergeRefs","columnMeta","columnDef","controlRenderer","control","isCellInDetailMode","editing","detailModeEditing","_ref$current","current","contains","document","activeElement","handleKeyDown","event","shouldTriggerShortcut","key","shift","toggleEditing","target","readOnly","stopPropagation","preventDefault","setDetailModeEditing","changedRow","changes","row","id","rowEdtitingDataWithInitialValue","_","isEqual","original","resetChange","_tableRef$current","focus","deselectInputValue","_target$select","select","call","isNumber","handleInputKeyDown","test","handleDatepickerChange","originalDate","changedDate","detail","hasChanged","setValue","nextValue","handleDatepickerKeyDown","Datepicker","className","cn","onKeyDown","Switch","checked","Boolean","TextareaControl","fontSize","size","Input","getInputAppearanceClassnames","getCellAlignmentClasses","type","undefined","String"],"mappings":";;;;;;;;;;;;;MAkCaA,cAAc,gBAAGC,cAAK,CAACC,UAAU,CAAmB,SAASC,OAAOA,CAC7EC,KAAiC,EACjCC,WAAmC;;EAEnC,MAAM;IACFC,KAAK;IACLC,MAAM;IACNC,IAAI;IACJC,YAAY;IACZC,QAAQ,EAAEC,YAAY;IACtBC,KAAK;IACLC,QAAQ;IACRC,KAAK;IACLC,IAAI;IACJC,YAAY;IACZ,GAAGC;GACN,GAAGb,KAAK;EAET,MAAMc,SAAS,GAAGN,KAAK,CAACO,OAAO,CAACC,IAA0B;EAE1D,MAAMC,GAAG,GAAGpB,cAAK,CAACqB,MAAM,EAAe;EACvC,MAAMC,WAAW,GAAGC,SAAS,CAAC,CAACH,GAAG,EAAEhB,WAAW,CAAC,CAAC;EAEjD,MAAMoB,UAAU,GAAGlB,MAAM,CAACmB,SAAS,CAACN,IAAI;EACxC,MAAMO,eAAe,GAAGF,UAAU,aAAVA,UAAU,uBAAVA,UAAU,CAAEG,OAAO;EAE3C,MAAMC,kBAAkB,GACpBX,SAAS,CAACY,OAAO,CAACC,iBAAiB,KAAKV,GAAoC,aAApCA,GAAoC,wBAAAW,YAAA,GAApCX,GAAoC,CAAEY,OAAO,cAAAD,YAAA,uBAA7CA,YAAA,CAA+CE,QAAQ,CAACC,QAAQ,CAACC,aAAa,CAAC;EAE3H,MAAMC,aAAa,GAAIC,KAA0B;;;IAG7C,IAAIC,qBAAqB,CAACD,KAAK,EAAE;MAAEE,GAAG,EAAE,GAAG;MAAEpB,IAAI,EAAE,IAAI;MAAEqB,KAAK,EAAE;KAAO,CAAC,EAAE;MACtEvB,SAAS,CAACY,OAAO,CAACY,aAAa,CAAC,KAAK,CAAC;MACtC;;IAGJ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C7B3C,GAAG,EAAEE,WAAW;IAChBgE,IAAI,EAAExB,QAAQ,GAAG,QAAQ,GAAGyB,SAAS;IACrC1E,KAAK,EAAEiD,QAAQ,GAAGjD,KAAK,GAAG2E,MAAM,CAAC3E,KAAK,aAALA,KAAK,cAALA,KAAK,GAAI,EAAE;KAC9C;AAEV,CAAC;;;;"}
|
1
|
+
{"version":3,"file":"EditingControl.js","sources":["../../../../../../../../../../src/components/Table3/components/columns/cell/EditingControl.tsx"],"sourcesContent":["import React from 'react';\nimport cn from 'classnames';\nimport { Cell as RTCell, Column as RTColumn, Table as RTTable, TableMeta } from '@tanstack/react-table';\nimport _ from 'lodash';\n\nimport { deselectInputValue } from '../../../../../utils/input';\nimport { hasChanged } from '../../../util/editing';\nimport { Datepicker } from '../../../../Datepicker/Datepicker';\nimport { Switch } from '../../../../Switch/Switch';\nimport { Input } from '../../../../Input/Input';\nimport { getCellAlignmentClasses, getInputAppearanceClassnames } from '../styles';\nimport { mergeRefs } from '../../../../../utils/mergeRefs';\nimport { Table3ColumnAlignment } from '../../../types';\nimport { TextareaControl } from './controls/TextareaControl';\nimport { shouldTriggerShortcut } from '../../../../../utils/keyboard';\n\nexport type EditingControlProps<TType = unknown> = {\n align?: Table3ColumnAlignment;\n column: RTColumn<TType, unknown>;\n data: TType;\n initialValue: any;\n value: any;\n onBlur: (event: React.FocusEvent) => void;\n onFocus: (event: React.FocusEvent) => void;\n onChange: (value: any) => void;\n ref: React.Ref<HTMLElement>;\n table: RTTable<TType>;\n tableRef: React.RefObject<HTMLDivElement>;\n cell: RTCell<TType, unknown>;\n error?: string;\n tabIndex?: number;\n isCurrentRow?: boolean;\n};\n\nexport const EditingControl = React.forwardRef<HTMLElement, any>(function Control<TType = unknown>(\n props: EditingControlProps<TType>,\n externalRef: React.Ref<HTMLElement>\n) {\n const {\n align,\n column,\n data,\n initialValue,\n onChange: handleChange,\n table,\n tableRef,\n value,\n cell,\n isCurrentRow,\n ...attributes\n } = props;\n\n const tableMeta = table.options.meta as TableMeta<unknown>;\n\n const ref = React.useRef<HTMLElement>();\n const refCallback = mergeRefs([ref, externalRef]);\n\n const columnMeta = column.columnDef.meta;\n const controlRenderer = columnMeta?.control;\n\n const isCellInDetailMode =\n tableMeta.editing.detailModeEditing && (ref as React.RefObject<HTMLElement>)?.current?.contains(document.activeElement);\n\n const handleKeyDown = (event: React.KeyboardEvent) => {\n // For some reason keydown event handler is not propogated to the table when input or other control element is\n // in focus so we need to check for shortcut that toggles the editing.\n if (shouldTriggerShortcut(event, { key: 'e', meta: true, shift: false })) {\n tableMeta.editing.toggleEditing(false);\n return;\n }\n\n const target = event.target as HTMLInputElement;\n\n if (target.readOnly) {\n return;\n }\n\n // Prevent row arrow shortcuts triggering when in detail mode\n if (tableMeta.editing.detailModeEditing && (event.key === 'ArrowUp' || event.key === 'ArrowDown')) {\n event.stopPropagation();\n }\n\n // Revert to initial value if escape was pressed\n if (event.key === 'Escape') {\n event.preventDefault();\n\n if (tableMeta.editing.detailModeEditing) {\n tableMeta.editing.setDetailModeEditing(false);\n\n if (value !== initialValue) {\n // Before reseting to initial value, we need to check if edited row with cell initial value is the same as original row,\n // and in this case we need to completely remove row from editing state to avoid saving the same data as original.\n const changedRow: any = tableMeta.editing.changes ? tableMeta.editing.changes[cell.row.id] : {};\n const rowEdtitingDataWithInitialValue = { ...changedRow, [cell.column.id]: initialValue };\n if (_.isEqual(cell.row.original, rowEdtitingDataWithInitialValue)) {\n tableMeta.editing.resetChange(cell.row.id);\n } else {\n handleChange(initialValue);\n }\n }\n } else {\n tableMeta.editing.toggleEditing(false);\n tableRef.current?.focus();\n }\n\n return;\n }\n\n // Should enable/disable editing mode if Enter was clicked\n if (event.key === 'Enter') {\n event.preventDefault();\n\n if (!tableMeta.editing.detailModeEditing) {\n deselectInputValue(target);\n } else {\n target?.select?.();\n }\n\n // Ketydown \"Enter\" should toggle edititng mode\n tableMeta.editing.setDetailModeEditing(!tableMeta.editing.detailModeEditing);\n\n return;\n }\n };\n\n const isNumber = typeof value === 'number';\n const handleInputKeyDown = (event: React.KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n handleKeyDown(event);\n\n // Switching to editing mode, when key pressed any alphabetical character or number\n if (/^[a-z0-9]$/i.test(event.key)) {\n tableMeta.editing.setDetailModeEditing(true);\n }\n };\n\n const handleDatepickerChange = event => {\n // When datepicker looses focus, it triggers change event, even if date wasn't changed,\n // so adding additional check here to prevent adding change to the edititng state.\n const originalDate = cell.row.original[cell.column.id];\n const changedDate = (event as any).detail;\n if (hasChanged(originalDate, changedDate)) {\n handleChange(changedDate);\n }\n };\n\n if (typeof controlRenderer === 'function') {\n return controlRenderer(\n {\n ...attributes,\n ref: ref,\n setValue: nextValue => {\n if (nextValue !== value) {\n handleChange(nextValue);\n }\n },\n value,\n },\n data\n );\n } else if (controlRenderer === 'datepicker') {\n const handleDatepickerKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {\n handleKeyDown(event);\n\n if (/^[a-z0-9]$/i.test(event.key)) {\n tableMeta.editing.setDetailModeEditing(true);\n return;\n }\n };\n\n return (\n <Datepicker\n {...attributes}\n className={cn({\n '[&_input]:!yt-focus-dark': isCellInDetailMode,\n })}\n onChange={handleDatepickerChange}\n onKeyDown={handleDatepickerKeyDown}\n ref={refCallback}\n value={value as Date}\n />\n );\n } else if (controlRenderer === 'switch') {\n return <Switch {...attributes} checked={Boolean(value)} onChange={handleChange} ref={refCallback} />;\n } else if (controlRenderer === 'textarea') {\n return (\n <TextareaControl\n {...props}\n isCellInDetailMode={isCellInDetailMode}\n onKeyDown={handleInputKeyDown}\n ref={refCallback}\n fontSize={tableMeta.fontSize.size}\n />\n );\n }\n\n return (\n <Input\n {...attributes}\n className={cn(getInputAppearanceClassnames(), getCellAlignmentClasses(align), {\n '!yt-focus-dark': isCellInDetailMode,\n })}\n onChange={event => {\n handleChange(event.target.value);\n }}\n onKeyDown={handleInputKeyDown}\n ref={refCallback}\n type={isNumber ? 'number' : undefined}\n value={isNumber ? value : String(value ?? '')}\n />\n );\n});\n"],"names":["EditingControl","React","forwardRef","Control","props","externalRef","align","column","data","initialValue","onChange","handleChange","table","tableRef","value","cell","isCurrentRow","attributes","tableMeta","options","meta","ref","useRef","refCallback","mergeRefs","columnMeta","columnDef","controlRenderer","control","isCellInDetailMode","editing","detailModeEditing","_ref$current","current","contains","document","activeElement","handleKeyDown","event","shouldTriggerShortcut","key","shift","toggleEditing","target","readOnly","stopPropagation","preventDefault","setDetailModeEditing","changedRow","changes","row","id","rowEdtitingDataWithInitialValue","_","isEqual","original","resetChange","_tableRef$current","focus","deselectInputValue","_target$select","select","call","isNumber","handleInputKeyDown","test","handleDatepickerChange","originalDate","changedDate","detail","hasChanged","setValue","nextValue","handleDatepickerKeyDown","Datepicker","className","cn","onKeyDown","Switch","checked","Boolean","TextareaControl","fontSize","size","Input","getInputAppearanceClassnames","getCellAlignmentClasses","type","undefined","String"],"mappings":";;;;;;;;;;;;;MAkCaA,cAAc,gBAAGC,cAAK,CAACC,UAAU,CAAmB,SAASC,OAAOA,CAC7EC,KAAiC,EACjCC,WAAmC;;EAEnC,MAAM;IACFC,KAAK;IACLC,MAAM;IACNC,IAAI;IACJC,YAAY;IACZC,QAAQ,EAAEC,YAAY;IACtBC,KAAK;IACLC,QAAQ;IACRC,KAAK;IACLC,IAAI;IACJC,YAAY;IACZ,GAAGC;GACN,GAAGb,KAAK;EAET,MAAMc,SAAS,GAAGN,KAAK,CAACO,OAAO,CAACC,IAA0B;EAE1D,MAAMC,GAAG,GAAGpB,cAAK,CAACqB,MAAM,EAAe;EACvC,MAAMC,WAAW,GAAGC,SAAS,CAAC,CAACH,GAAG,EAAEhB,WAAW,CAAC,CAAC;EAEjD,MAAMoB,UAAU,GAAGlB,MAAM,CAACmB,SAAS,CAACN,IAAI;EACxC,MAAMO,eAAe,GAAGF,UAAU,aAAVA,UAAU,uBAAVA,UAAU,CAAEG,OAAO;EAE3C,MAAMC,kBAAkB,GACpBX,SAAS,CAACY,OAA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7B3C,GAAG,EAAEE,WAAW;MAChB2D,QAAQ,EAAEhE,SAAS,CAACgE,QAAQ,CAACC;OAC/B;;EAIV,oBACIlF,6BAACmF,KAAK,oBACEnE,UAAU;IACd0D,SAAS,EAAEC,EAAE,CAACS,4BAA4B,EAAE,EAAEC,uBAAuB,CAAChF,KAAK,CAAC,EAAE;MAC1E,gBAAgB,EAAEuB;KACrB,CAAC;IACFnB,QAAQ,EAAE4B,KAAK;MACX3B,YAAY,CAAC2B,KAAK,CAACK,MAAM,CAAC7B,KAAK,CAAC;KACnC;IACD+D,SAAS,EAAEb,kBAAkB;IAC7B3C,GAAG,EAAEE,WAAW;IAChBgE,IAAI,EAAExB,QAAQ,GAAG,QAAQ,GAAGyB,SAAS;IACrC1E,KAAK,EAAEiD,QAAQ,GAAGjD,KAAK,GAAG2E,MAAM,CAAC3E,KAAK,aAALA,KAAK,cAALA,KAAK,GAAI,EAAE;KAC9C;AAEV,CAAC;;;;"}
|
@@ -79,7 +79,7 @@ const TextareaControl = /*#__PURE__*/React__default.forwardRef(function Textarea
|
|
79
79
|
resizeTextArea(e.target);
|
80
80
|
};
|
81
81
|
const textareaContainerClassName = cn('w-full', {
|
82
|
-
'focus-within:absolute focus-within:left-0 focus-within:top-0 focus-within:z-20 focus-within:px-
|
82
|
+
'focus-within:absolute focus-within:left-0 focus-within:top-0 focus-within:z-20 focus-within:px-[var(--table3-cell-padding-x)] focus-within:pt-[var(--table3-cell-padding-y)]': columnMeta === null || columnMeta === void 0 ? void 0 : columnMeta.enableTruncate
|
83
83
|
});
|
84
84
|
const handleTextareaKeyDown = event => {
|
85
85
|
// By default Shift + Enter in textarea makes a new line, we want to keep this behaviour
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"TextareaControl.js","sources":["../../../../../../../../../../../src/components/Table3/components/columns/cell/controls/TextareaControl.tsx"],"sourcesContent":["import React from 'react';\nimport cn from 'classnames';\nimport { Textarea } from '../../../../../Textarea/Textarea';\nimport { EditingControlProps } from '../EditingControl';\nimport { getCellAlignmentClasses } from '../../styles';\nimport { useMergedRef } from '../../../../../../hooks/useMergedRef';\nimport { Table3FontSize } from '../../../../types';\n\ntype TextareaHeight = {\n min: number;\n max: number;\n};\n// By UX design, textarea should fold to min size when blured and extend to max 5 lines height when edited in enableTruncate mode,\n// for this reason we need to set min/max height limits for each font size value.\nconst heights: Record<Table3FontSize, TextareaHeight> = {\n small: {\n min: 24,\n max: 86,\n },\n medium: {\n min: 34,\n max: 100,\n },\n large: {\n min: 40,\n max: 140,\n },\n};\n\ntype TextareaControlProps<TType = unknown> = EditingControlProps<TType> & {\n onKeyDown: (event: React.KeyboardEvent<HTMLTextAreaElement>) => void;\n fontSize: Table3FontSize;\n isCellInDetailMode?: boolean;\n};\n\nexport const TextareaControl = React.forwardRef<HTMLElement, any>(function TextareaControl<TType = unknown>(\n props: TextareaControlProps<TType>,\n externalRef: React.Ref<HTMLElement>\n) {\n const {\n onKeyDown: handleKeyDown,\n onChange: handleChange,\n column,\n isCellInDetailMode,\n align,\n isCurrentRow,\n value,\n fontSize,\n ...attributes\n } = props;\n\n const minMaxHeight = heights[fontSize];\n\n const columnMeta = column.columnDef.meta;\n\n const ref = useMergedRef<HTMLTextAreaElement>(externalRef);\n\n React.useEffect(() => {\n if (ref?.current) {\n // Need to reset textarea to min height when font size got changed and if column in enable truncate mode.\n if (columnMeta?.enableTruncate) {\n const textareaElement = ref?.current as HTMLTextAreaElement;\n textareaElement.style.height = `${minMaxHeight.min}px`;\n\n // If truncation is not enabled, then textarea should re-calculate it's height to fit with it's own content, when initialized or fonsSize got changed.\n } else {\n const textareaElement = ref?.current as HTMLTextAreaElement;\n resizeTextArea(textareaElement);\n }\n }\n }, [fontSize]);\n\n React.useEffect(() => {\n // If truncation is enabled, then textarea should only adjust to it's own content, when in detail mode.\n // Otherwise it should collapse to minimal height.\n if (ref?.current && columnMeta?.enableTruncate) {\n const textareaElement = ref?.current as HTMLTextAreaElement;\n\n if (isCellInDetailMode) {\n resizeTextArea(textareaElement);\n } else {\n textareaElement.style.height = `${minMaxHeight.min}px`;\n }\n }\n }, [isCellInDetailMode]);\n\n const resizeTextArea = (textareaElement: HTMLTextAreaElement) => {\n // Need to set inherit before calculating height, so that browser sets the scrollHeight properly,\n // depending on text inside.\n const textareaRect = textareaElement.getBoundingClientRect();\n const prevHeight = textareaRect.height;\n if (columnMeta?.enableTruncate) {\n if (prevHeight < minMaxHeight.max) {\n textareaElement.style.height = 'inherit';\n textareaElement.style.height = `${Math.min(textareaElement.scrollHeight, minMaxHeight.max)}px`;\n }\n } else {\n textareaElement.style.height = 'inherit';\n textareaElement.style.height = `${textareaElement.scrollHeight}px`;\n }\n };\n\n const handleTextareaChange = e => {\n resizeTextArea(e.target);\n };\n\n const textareaContainerClassName = cn('w-full', {\n 'focus-within:absolute focus-within:left-0 focus-within:top-0 focus-within:z-20 focus-within:px-
|
1
|
+
{"version":3,"file":"TextareaControl.js","sources":["../../../../../../../../../../../src/components/Table3/components/columns/cell/controls/TextareaControl.tsx"],"sourcesContent":["import React from 'react';\nimport cn from 'classnames';\nimport { Textarea } from '../../../../../Textarea/Textarea';\nimport { EditingControlProps } from '../EditingControl';\nimport { getCellAlignmentClasses } from '../../styles';\nimport { useMergedRef } from '../../../../../../hooks/useMergedRef';\nimport { Table3FontSize } from '../../../../types';\n\ntype TextareaHeight = {\n min: number;\n max: number;\n};\n// By UX design, textarea should fold to min size when blured and extend to max 5 lines height when edited in enableTruncate mode,\n// for this reason we need to set min/max height limits for each font size value.\nconst heights: Record<Table3FontSize, TextareaHeight> = {\n small: {\n min: 24,\n max: 86,\n },\n medium: {\n min: 34,\n max: 100,\n },\n large: {\n min: 40,\n max: 140,\n },\n};\n\ntype TextareaControlProps<TType = unknown> = EditingControlProps<TType> & {\n onKeyDown: (event: React.KeyboardEvent<HTMLTextAreaElement>) => void;\n fontSize: Table3FontSize;\n isCellInDetailMode?: boolean;\n};\n\nexport const TextareaControl = React.forwardRef<HTMLElement, any>(function TextareaControl<TType = unknown>(\n props: TextareaControlProps<TType>,\n externalRef: React.Ref<HTMLElement>\n) {\n const {\n onKeyDown: handleKeyDown,\n onChange: handleChange,\n column,\n isCellInDetailMode,\n align,\n isCurrentRow,\n value,\n fontSize,\n ...attributes\n } = props;\n\n const minMaxHeight = heights[fontSize];\n\n const columnMeta = column.columnDef.meta;\n\n const ref = useMergedRef<HTMLTextAreaElement>(externalRef);\n\n React.useEffect(() => {\n if (ref?.current) {\n // Need to reset textarea to min height when font size got changed and if column in enable truncate mode.\n if (columnMeta?.enableTruncate) {\n const textareaElement = ref?.current as HTMLTextAreaElement;\n textareaElement.style.height = `${minMaxHeight.min}px`;\n\n // If truncation is not enabled, then textarea should re-calculate it's height to fit with it's own content, when initialized or fonsSize got changed.\n } else {\n const textareaElement = ref?.current as HTMLTextAreaElement;\n resizeTextArea(textareaElement);\n }\n }\n }, [fontSize]);\n\n React.useEffect(() => {\n // If truncation is enabled, then textarea should only adjust to it's own content, when in detail mode.\n // Otherwise it should collapse to minimal height.\n if (ref?.current && columnMeta?.enableTruncate) {\n const textareaElement = ref?.current as HTMLTextAreaElement;\n\n if (isCellInDetailMode) {\n resizeTextArea(textareaElement);\n } else {\n textareaElement.style.height = `${minMaxHeight.min}px`;\n }\n }\n }, [isCellInDetailMode]);\n\n const resizeTextArea = (textareaElement: HTMLTextAreaElement) => {\n // Need to set inherit before calculating height, so that browser sets the scrollHeight properly,\n // depending on text inside.\n const textareaRect = textareaElement.getBoundingClientRect();\n const prevHeight = textareaRect.height;\n if (columnMeta?.enableTruncate) {\n if (prevHeight < minMaxHeight.max) {\n textareaElement.style.height = 'inherit';\n textareaElement.style.height = `${Math.min(textareaElement.scrollHeight, minMaxHeight.max)}px`;\n }\n } else {\n textareaElement.style.height = 'inherit';\n textareaElement.style.height = `${textareaElement.scrollHeight}px`;\n }\n };\n\n const handleTextareaChange = e => {\n resizeTextArea(e.target);\n };\n\n const textareaContainerClassName = cn('w-full', {\n 'focus-within:absolute focus-within:left-0 focus-within:top-0 focus-within:z-20 focus-within:px-[var(--table3-cell-padding-x)] focus-within:pt-[var(--table3-cell-padding-y)]':\n columnMeta?.enableTruncate,\n });\n const handleTextareaKeyDown = (event: React.KeyboardEvent<HTMLTextAreaElement>) => {\n // By default Shift + Enter in textarea makes a new line, we want to keep this behaviour\n if (event.shiftKey && event.key === 'Enter') {\n return;\n } else {\n handleKeyDown(event);\n }\n };\n\n return (\n <div className={textareaContainerClassName} data-taco=\"input-container\">\n <Textarea\n {...attributes}\n onChange={event => {\n handleChange(event.target.value);\n handleTextareaChange(event);\n }}\n rows={1}\n onKeyDown={e => {\n handleTextareaKeyDown(e);\n }}\n onBlur={event => {\n // If truncation is enabled, then textarea should shring back to min height, when loosing focus.\n if (columnMeta?.enableTruncate) {\n const textareaElement = event.currentTarget;\n textareaElement.style.height = `${minMaxHeight.min}px`;\n }\n }}\n className={cn(getCellAlignmentClasses(align), `z-20 h-fit resize-none`, {\n [`!min-h-[${minMaxHeight.min}px]`]: columnMeta?.enableTruncate,\n '!yt-focus-dark': isCellInDetailMode,\n [`h-[${minMaxHeight.min}px]`]: !isCellInDetailMode && columnMeta?.enableTruncate,\n // Only allow resizing when focused and truncation enabled\n 'focus:resize-y': isCurrentRow && columnMeta?.enableTruncate,\n })}\n ref={ref}\n value={String(value ?? '')}\n />\n </div>\n );\n});\n"],"names":["heights","small","min","max","medium","large","TextareaControl","React","forwardRef","props","externalRef","onKeyDown","handleKeyDown","onChange","handleChange","column","isCellInDetailMode","align","isCurrentRow","value","fontSize","attributes","minMaxHeight","columnMeta","columnDef","meta","ref","useMergedRef","useEffect","current","enableTruncate","textareaElement","style","height","resizeTextArea","textareaRect","getBoundingClientRect","prevHeight","Math","scrollHeight","handleTextareaChange","e","target","textareaContainerClassName","cn","handleTextareaKeyDown","event","shiftKey","key","className","Textarea","rows","onBlur","currentTarget","getCellAlignmentClasses","String"],"mappings":";;;;;;AAYA;AACA;AACA,MAAMA,OAAO,GAA2C;EACpDC,KAA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IAAK0C,SAAS,EAAEN,0BAA0B;iBAAY;kBAClDpC,6BAAC2C,QAAQ,oBACD7B,UAAU;IACdR,QAAQ,EAAEiC,KAAK;MACXhC,YAAY,CAACgC,KAAK,CAACJ,MAAM,CAACvB,KAAK,CAAC;MAChCqB,oBAAoB,CAACM,KAAK,CAAC;KAC9B;IACDK,IAAI,EAAE,CAAC;IACPxC,SAAS,EAAE8B,CAAC;MACRI,qBAAqB,CAACJ,CAAC,CAAC;KAC3B;IACDW,MAAM,EAAEN,KAAK;;MAET,IAAIvB,UAAU,aAAVA,UAAU,eAAVA,UAAU,CAAEO,cAAc,EAAE;QAC5B,MAAMC,eAAe,GAAGe,KAAK,CAACO,aAAa;QAC3CtB,eAAe,CAACC,KAAK,CAACC,MAAM,MAAMX,YAAY,CAACpB,OAAO;;KAE7D;IACD+C,SAAS,EAAEL,EAAE,CAACU,uBAAuB,CAACrC,KAAK,CAAC,0BAA0B,EAAE;MACpE,YAAYK,YAAY,CAACpB,QAAQ,GAAGqB,UAAU,aAAVA,UAAU,uBAAVA,UAAU,CAAEO,cAAc;MAC9D,gBAAgB,EAAEd,kBAAkB;MACpC,OAAOM,YAAY,CAACpB,QAAQ,GAAG,CAACc,kBAAkB,KAAIO,UAAU,aAAVA,UAAU,uBAAVA,UAAU,CAAEO,cAAc;;MAEhF,gBAAgB,EAAEZ,YAAY,KAAIK,UAAU,aAAVA,UAAU,uBAAVA,UAAU,CAAEO,cAAc;KAC/D,CAAC;IACFJ,GAAG,EAAEA,GAAG;IACRP,KAAK,EAAEoC,MAAM,CAACpC,KAAK,aAALA,KAAK,cAALA,KAAK,GAAI,EAAE;KAC3B,CACA;AAEd,CAAC;;;;"}
|
@@ -6,6 +6,10 @@ import { Resizer } from './Resizer.js';
|
|
6
6
|
import { getSortAttributes, SortIndicator } from './SortIndicator.js';
|
7
7
|
import { isFrozenColumn, isInternalColumn } from '../../../util/columns.js';
|
8
8
|
|
9
|
+
const SORT_DIRECTION = {
|
10
|
+
ASC: 'asc',
|
11
|
+
DESC: 'desc'
|
12
|
+
};
|
9
13
|
function Header(props) {
|
10
14
|
const {
|
11
15
|
children,
|
@@ -17,11 +21,19 @@ function Header(props) {
|
|
17
21
|
const tableMeta = table.options.meta;
|
18
22
|
const columnMeta = React__default.useMemo(() => column.columnDef.meta, []);
|
19
23
|
const canSort = column.getCanSort();
|
24
|
+
const hasGoto = isGotoAvailable(table, header);
|
20
25
|
// passing header or column results in re-renders on scroll, so anything from those objects as memoed props
|
26
|
+
const handleHide = React__default.useMemo(() => header.column.getToggleVisibilityHandler(), []);
|
21
27
|
const handleResize = React__default.useMemo(() => header.getResizeHandler(), []);
|
22
28
|
const handleSort = React__default.useMemo(() => header.column.getToggleSortingHandler(), []);
|
23
|
-
const
|
24
|
-
|
29
|
+
const handleSortToggle = React__default.useCallback(sortDirection => {
|
30
|
+
// When sorting is not applied, sortDirection is false.
|
31
|
+
if (sortDirection === false) {
|
32
|
+
header.column.clearSorting();
|
33
|
+
} else {
|
34
|
+
header.column.toggleSorting(sortDirection === SORT_DIRECTION.DESC);
|
35
|
+
}
|
36
|
+
}, []);
|
25
37
|
const sorting = table.getState().sorting;
|
26
38
|
const filters = table.getState().columnFilters;
|
27
39
|
const search = table.getState().globalFilter;
|
@@ -42,6 +54,7 @@ function Header(props) {
|
|
42
54
|
id: header.id,
|
43
55
|
index: header.index,
|
44
56
|
isFrozen: isFrozenColumn(header, table),
|
57
|
+
isPrinting: tableMeta.isPrinting,
|
45
58
|
isResizing: column.getIsResizing(),
|
46
59
|
length: table.getRowModel().rows.length,
|
47
60
|
meta: columnMeta,
|
@@ -49,6 +62,7 @@ function Header(props) {
|
|
49
62
|
onHide: handleHide,
|
50
63
|
onResize: handleResize,
|
51
64
|
onSort: handleSort,
|
65
|
+
onSortToggle: handleSortToggle,
|
52
66
|
scrollToIndex,
|
53
67
|
sortDirection: column.getIsSorted(),
|
54
68
|
table
|
@@ -68,6 +82,7 @@ const MemoedHeader = /*#__PURE__*/React__default.memo(function MemoedHeader(prop
|
|
68
82
|
id,
|
69
83
|
index,
|
70
84
|
isFrozen,
|
85
|
+
isPrinting,
|
71
86
|
isResizing,
|
72
87
|
length,
|
73
88
|
meta,
|
@@ -75,13 +90,17 @@ const MemoedHeader = /*#__PURE__*/React__default.memo(function MemoedHeader(prop
|
|
75
90
|
onHide: handleHide,
|
76
91
|
onResize: handleResize,
|
77
92
|
onSort: handleSort,
|
93
|
+
onSortToggle: handleSortToggle,
|
78
94
|
scrollToIndex,
|
79
95
|
sortDirection,
|
80
96
|
table
|
81
97
|
} = props;
|
82
|
-
const className = cn('sticky top-0 border-b-2 font-bold
|
98
|
+
const className = cn('sticky top-0 border-b-2 font-bold box-content group/column relative', '[[role="table"][data-resizing="true"]_&]:pointer-events-none', 'px-[var(--table3-cell-padding-x)]', {
|
99
|
+
'h-10 items-center': !isPrinting,
|
100
|
+
'pb-2': isPrinting,
|
83
101
|
'cursor-pointer select-none': canSort,
|
84
102
|
'hover:bg-grey-100': canSort || canResize || hasMenu,
|
103
|
+
'focus-within:bg-grey-100': hasMenu,
|
85
104
|
'!pointer-events-all !bg-grey-100': isResizing,
|
86
105
|
// z-indexes
|
87
106
|
'z-10 hover:z-20': !isFrozen && !isResizing,
|
@@ -115,13 +134,16 @@ const MemoedHeader = /*#__PURE__*/React__default.memo(function MemoedHeader(prop
|
|
115
134
|
title: String((_meta$tooltip = meta === null || meta === void 0 ? void 0 : meta.tooltip) !== null && _meta$tooltip !== void 0 ? _meta$tooltip : children),
|
116
135
|
placement: "top"
|
117
136
|
}, /*#__PURE__*/React__default.createElement("span", {
|
118
|
-
className:
|
137
|
+
className: cn({
|
138
|
+
truncate: !isPrinting
|
139
|
+
})
|
119
140
|
}, children)), canSort ? /*#__PURE__*/React__default.createElement(SortIndicator, {
|
120
141
|
direction: sortDirection
|
121
142
|
}) : null, hasMenu ? /*#__PURE__*/React__default.createElement(Menu, {
|
122
143
|
canFreeze: canFreeze,
|
123
144
|
canHide: canHide,
|
124
|
-
|
145
|
+
canSort: canSort,
|
146
|
+
className: cn({
|
125
147
|
'ml-auto': align !== 'right',
|
126
148
|
'ml-2': align === 'right'
|
127
149
|
}),
|
@@ -129,7 +151,9 @@ const MemoedHeader = /*#__PURE__*/React__default.memo(function MemoedHeader(prop
|
|
129
151
|
menu: meta.menu,
|
130
152
|
onGoto: handleGoto,
|
131
153
|
onHide: handleHide,
|
154
|
+
onSortToggle: handleSortToggle,
|
132
155
|
scrollToIndex: scrollToIndex,
|
156
|
+
sortDirection: sortDirection,
|
133
157
|
table: table
|
134
158
|
}) : null, canResize ? /*#__PURE__*/React__default.createElement(Resizer, {
|
135
159
|
isResizing: isResizing,
|
@@ -137,5 +161,5 @@ const MemoedHeader = /*#__PURE__*/React__default.memo(function MemoedHeader(prop
|
|
137
161
|
}) : null);
|
138
162
|
});
|
139
163
|
|
140
|
-
export { Header };
|
164
|
+
export { Header, SORT_DIRECTION };
|
141
165
|
//# sourceMappingURL=Header.js.map
|
package/dist/esm/packages/taco/src/components/Table3/components/columns/header/Header.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Header.js","sources":["../../../../../../../../../../src/components/Table3/components/columns/header/Header.tsx"],"sourcesContent":["import React from 'react';\nimport cn from 'classnames';\nimport { ColumnMeta, HeaderContext, TableMeta } from '@tanstack/react-table';\nimport { Menu, isMenuAvailable, isGotoAvailable } from './Menu';\nimport { Resizer } from './Resizer';\nimport { Table3ColumnAlignment, Table3SortDirection, TableStrategy } from '../../../types';\nimport { getSortAttributes, SortIndicator } from './SortIndicator';\nimport { isFrozenColumn, isInternalColumn } from '../../../util/columns';\nimport { Tooltip } from '../../../../Tooltip/Tooltip';\n\nexport type HeaderProps<TType = unknown> = HeaderContext<TType, unknown> & {\n children?: string | JSX.Element;\n};\n\nexport function Header<TType = unknown>(props: HeaderProps<TType>) {\n const { children, column, header, scrollToIndex, table } = props;\n const tableMeta = table.options.meta as TableMeta<TType>;\n const columnMeta = React.useMemo(() => column.columnDef.meta, []) as ColumnMeta<TType, unknown>;\n const canSort = column.getCanSort();\n\n // passing header or column results in re-renders on scroll, so anything from those objects as memoed props\n const handleResize = React.useMemo(() => header.getResizeHandler(), []);\n const handleSort = React.useMemo(() => header.column.getToggleSortingHandler(), []);\n const handleHide = React.useMemo(() => header.column.getToggleVisibilityHandler(), []);\n const hasGoto = isGotoAvailable(table, header);\n\n const sorting = table.getState().sorting;\n const filters = table.getState().columnFilters;\n const search = table.getState().globalFilter;\n\n const handleGoto = React.useMemo(() => {\n if (hasGoto) {\n return ((query: string) => tableMeta.rowGoto.handleGoto(header.id, query, sorting, filters, search)) as (\n query: string\n ) => Promise<number>;\n }\n\n return undefined;\n }, [hasGoto, JSON.stringify(sorting), JSON.stringify(filters), search]);\n\n const memoedProps = {\n align: columnMeta.align,\n canFreeze: tableMeta.columnFreezing.isEnabled,\n canHide: column.getCanHide(),\n canResize: column.getCanResize(),\n canSort,\n children: children ?? columnMeta.header,\n hasMenu: isMenuAvailable<TType>(table, header),\n id: header.id,\n index: header.index,\n isFrozen: isFrozenColumn(header, table),\n isResizing: column.getIsResizing(),\n length: table.getRowModel().rows.length,\n meta: columnMeta,\n onGoto: handleGoto,\n onHide: handleHide,\n onResize: handleResize,\n onSort: handleSort as (event: unknown) => void,\n scrollToIndex,\n sortDirection: column.getIsSorted(),\n table,\n };\n\n return <MemoedHeader<TType> {...memoedProps} />;\n}\n\n// Memoization\nexport type MemoedHeaderProps<TType = unknown> = Omit<HeaderProps<TType>, 'column' | 'header'> & {\n align?: Table3ColumnAlignment;\n canFreeze: boolean;\n canHide: boolean;\n canResize: boolean;\n canSort: boolean;\n hasMenu: boolean;\n id: string;\n index: number;\n isFrozen: boolean;\n isResizing: boolean;\n length: number;\n meta: ColumnMeta<TType, unknown>;\n onGoto?: (query: string) => Promise<number>;\n onHide: (event: unknown) => void;\n onResize: (event: unknown) => void;\n onSort: (event: unknown) => void;\n scrollToIndex: TableStrategy['scrollToIndex'];\n sortDirection: false | Table3SortDirection;\n};\n\nconst MemoedHeader = React.memo(function MemoedHeader<TType = unknown>(props: MemoedHeaderProps<TType>) {\n const {\n align,\n children,\n canFreeze,\n canHide,\n canResize,\n canSort,\n hasMenu,\n id,\n index,\n isFrozen,\n isResizing,\n length,\n meta,\n onGoto: handleGoto,\n onHide: handleHide,\n onResize: handleResize,\n onSort: handleSort,\n scrollToIndex,\n sortDirection,\n table,\n } = props;\n\n const className = cn(\n 'sticky top-0 border-b-2 font-bold h-10 box-content items-center group/column relative',\n '[[role=\"table\"][data-resizing=\"true\"]_&]:pointer-events-none',\n {\n 'cursor-pointer select-none': canSort,\n 'hover:bg-grey-100': canSort || canResize || hasMenu,\n '!pointer-events-all !bg-grey-100': isResizing,\n // z-indexes\n 'z-10 hover:z-20': !isFrozen && !isResizing,\n 'z-20': !isFrozen && isResizing,\n '!z-30': isFrozen,\n '!z-40': isFrozen && isResizing,\n },\n meta.headerClassName\n );\n\n const [internalRef, setInternalRef] = React.useState<HTMLDivElement | null>(null);\n\n React.useLayoutEffect(() => {\n if (internalRef && length) {\n // the actions column size gets set by the column itself\n if (isInternalColumn(id)) {\n return;\n }\n\n table.setColumnSizing(sizes => ({\n ...sizes,\n [id]: internalRef.getBoundingClientRect().width,\n }));\n }\n }, [internalRef, length]);\n\n if (table.options.debugAll) {\n console.log('header render', id);\n }\n\n return (\n <div\n {...(canSort ? getSortAttributes(handleSort, sortDirection) : undefined)}\n className={className}\n data-align={align}\n data-column-index={index}\n role=\"columnheader\"\n ref={setInternalRef}>\n {isInternalColumn(id) ? (\n children\n ) : (\n <Tooltip title={String(meta?.tooltip ?? children)} placement=\"top\">\n <span className=\"truncate\">{children}</span>\n </Tooltip>\n )}\n {canSort ? <SortIndicator direction={sortDirection} /> : null}\n {hasMenu ? (\n <Menu\n canFreeze={canFreeze}\n canHide={canHide}\n className={cn('hidden group-hover/column:flex aria-expanded:!flex', {\n 'ml-auto': align !== 'right',\n 'ml-2': align === 'right',\n })}\n index={index}\n menu={meta.menu}\n onGoto={handleGoto}\n onHide={handleHide}\n scrollToIndex={scrollToIndex}\n table={table}\n />\n ) : null}\n {canResize ? <Resizer isResizing={isResizing} onResize={handleResize} /> : null}\n </div>\n );\n}) as <TType = unknown>(props: MemoedHeaderProps<TType>) => JSX.Element;\n"],"names":["Header","props","children","column","header","scrollToIndex","table","tableMeta","options","meta","columnMeta","React","useMemo","columnDef","canSort","getCanSort","handleResize","getResizeHandler","handleSort","getToggleSortingHandler","handleHide","getToggleVisibilityHandler","hasGoto","isGotoAvailable","sorting","getState","filters","columnFilters","search","globalFilter","handleGoto","query","rowGoto","id","undefined","JSON","stringify","memoedProps","align","canFreeze","columnFreezing","isEnabled","canHide","getCanHide","canResize","getCanResize","hasMenu","isMenuAvailable","index","isFrozen","isFrozenColumn","isResizing","getIsResizing","length","getRowModel","rows","onGoto","onHide","onResize","onSort","sortDirection","getIsSorted","MemoedHeader","memo","className","cn","headerClassName","internalRef","setInternalRef","useState","useLayoutEffect","isInternalColumn","setColumnSizing","sizes","getBoundingClientRect","width","debugAll","console","log","getSortAttributes","role","ref","Tooltip","title","String","_meta$tooltip","tooltip","placement","SortIndicator","direction","Menu","menu","Resizer"],"mappings":";;;;;;;;SAcgBA,MAAMA,CAAkBC,KAAyB;EAC7D,MAAM;IAAEC,QAAQ;IAAEC,MAAM;IAAEC,MAAM;IAAEC,aAAa;IAAEC;GAAO,GAAGL,KAAK;EAChE,MAAMM,SAAS,GAAGD,KAAK,CAACE,OAAO,CAACC,IAAwB;EACxD,MAAMC,UAAU,GAAGC,cAAK,CAACC,OAAO,CAAC,MAAMT,MAAM,CAACU,SAAS,CAACJ,IAAI,EAAE,EAAE,CAA+B;EAC/F,MAAMK,OAAO,GAAGX,MAAM,CAACY,UAAU,EAAE;;EAGnC,MAAMC,YAAY,GAAGL,cAAK,CAACC,OAAO,CAAC,MAAMR,MAAM,CAACa,gBAAgB,EAAE,EAAE,EAAE,CAAC;EACvE,MAAMC,UAAU,GAAGP,cAAK,C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nC,6BAAC+E,IAAI;IACDnD,SAAS,EAAEA,SAAS;IACpBG,OAAO,EAAEA,OAAO;IAChBsB,SAAS,EAAEC,EAAE,CAAC,oDAAoD,EAAE;MAChE,SAAS,EAAE3B,KAAK,KAAK,OAAO;MAC5B,MAAM,EAAEA,KAAK,KAAK;KACrB,CAAC;IACFU,KAAK,EAAEA,KAAK;IACZ2C,IAAI,EAAElF,IAAI,CAACkF,IAAI;IACfnC,MAAM,EAAE1B,UAAU;IAClB2B,MAAM,EAAErC,UAAU;IAClBf,aAAa,EAAEA,aAAa;IAC5BC,KAAK,EAAEA;IACT,GACF,IAAI,EACPsC,SAAS,gBAAGjC,6BAACiF,OAAO;IAACzC,UAAU,EAAEA,UAAU;IAAEO,QAAQ,EAAE1C;IAAgB,GAAG,IAAI,CAC7E;AAEd,CAAC,CAAsE;;;;"}
|
1
|
+
{"version":3,"file":"Header.js","sources":["../../../../../../../../../../src/components/Table3/components/columns/header/Header.tsx"],"sourcesContent":["import React from 'react';\nimport cn from 'classnames';\nimport { ColumnMeta, HeaderContext, TableMeta } from '@tanstack/react-table';\nimport { Menu, isMenuAvailable, isGotoAvailable } from './Menu';\nimport { Resizer } from './Resizer';\nimport { Table3ColumnAlignment, Table3SortDirection, TableStrategy } from '../../../types';\nimport { getSortAttributes, SortIndicator } from './SortIndicator';\nimport { isFrozenColumn, isInternalColumn } from '../../../util/columns';\nimport { Tooltip } from '../../../../Tooltip/Tooltip';\n\nexport const SORT_DIRECTION: Record<string, Table3SortDirection> = {\n ASC: 'asc',\n DESC: 'desc',\n};\n\nexport type HeaderSortDirection = Table3SortDirection | false;\nexport type SortToggleHandler = (sortDirection: HeaderSortDirection) => void;\n\nexport type HeaderProps<TType = unknown> = HeaderContext<TType, unknown> & {\n children?: string | JSX.Element;\n};\n\nexport function Header<TType = unknown>(props: HeaderProps<TType>) {\n const { children, column, header, scrollToIndex, table } = props;\n const tableMeta = table.options.meta as TableMeta<TType>;\n const columnMeta = React.useMemo(() => column.columnDef.meta, []) as ColumnMeta<TType, unknown>;\n const canSort = column.getCanSort();\n const hasGoto = isGotoAvailable(table, header);\n\n // passing header or column results in re-renders on scroll, so anything from those objects as memoed props\n const handleHide = React.useMemo(() => header.column.getToggleVisibilityHandler(), []);\n const handleResize = React.useMemo(() => header.getResizeHandler(), []);\n const handleSort = React.useMemo(() => header.column.getToggleSortingHandler(), []);\n const handleSortToggle = React.useCallback((sortDirection: HeaderSortDirection) => {\n // When sorting is not applied, sortDirection is false.\n if (sortDirection === false) {\n header.column.clearSorting();\n } else {\n header.column.toggleSorting(sortDirection === SORT_DIRECTION.DESC);\n }\n }, []);\n\n const sorting = table.getState().sorting;\n const filters = table.getState().columnFilters;\n const search = table.getState().globalFilter;\n\n const handleGoto = React.useMemo(() => {\n if (hasGoto) {\n return ((query: string) => tableMeta.rowGoto.handleGoto(header.id, query, sorting, filters, search)) as (\n query: string\n ) => Promise<number>;\n }\n\n return undefined;\n }, [hasGoto, JSON.stringify(sorting), JSON.stringify(filters), search]);\n\n const memoedProps = {\n align: columnMeta.align,\n canFreeze: tableMeta.columnFreezing.isEnabled,\n canHide: column.getCanHide(),\n canResize: column.getCanResize(),\n canSort,\n children: children ?? columnMeta.header,\n hasMenu: isMenuAvailable<TType>(table, header),\n id: header.id,\n index: header.index,\n isFrozen: isFrozenColumn(header, table),\n isPrinting: tableMeta.isPrinting,\n isResizing: column.getIsResizing(),\n length: table.getRowModel().rows.length,\n meta: columnMeta,\n onGoto: handleGoto,\n onHide: handleHide,\n onResize: handleResize,\n onSort: handleSort as (event: unknown) => void,\n onSortToggle: handleSortToggle,\n scrollToIndex,\n sortDirection: column.getIsSorted(),\n table,\n };\n\n return <MemoedHeader<TType> {...memoedProps} />;\n}\n\n// Memoization\nexport type MemoedHeaderProps<TType = unknown> = Omit<HeaderProps<TType>, 'column' | 'header'> & {\n align?: Table3ColumnAlignment;\n canFreeze: boolean;\n canHide: boolean;\n canResize: boolean;\n canSort: boolean;\n hasMenu: boolean;\n id: string;\n index: number;\n isFrozen: boolean;\n isPrinting: boolean;\n isResizing: boolean;\n length: number;\n meta: ColumnMeta<TType, unknown>;\n onGoto?: (query: string) => Promise<number>;\n onHide: (event: unknown) => void;\n onResize: (event: unknown) => void;\n onSort: (event: unknown) => void;\n onSortToggle: SortToggleHandler;\n scrollToIndex: TableStrategy['scrollToIndex'];\n sortDirection: HeaderSortDirection;\n};\n\nconst MemoedHeader = React.memo(function MemoedHeader<TType = unknown>(props: MemoedHeaderProps<TType>) {\n const {\n align,\n children,\n canFreeze,\n canHide,\n canResize,\n canSort,\n hasMenu,\n id,\n index,\n isFrozen,\n isPrinting,\n isResizing,\n length,\n meta,\n onGoto: handleGoto,\n onHide: handleHide,\n onResize: handleResize,\n onSort: handleSort,\n onSortToggle: handleSortToggle,\n scrollToIndex,\n sortDirection,\n table,\n } = props;\n\n const className = cn(\n 'sticky top-0 border-b-2 font-bold box-content group/column relative',\n '[[role=\"table\"][data-resizing=\"true\"]_&]:pointer-events-none',\n 'px-[var(--table3-cell-padding-x)]',\n {\n 'h-10 items-center': !isPrinting,\n 'pb-2': isPrinting,\n 'cursor-pointer select-none': canSort,\n 'hover:bg-grey-100': canSort || canResize || hasMenu,\n 'focus-within:bg-grey-100': hasMenu,\n '!pointer-events-all !bg-grey-100': isResizing,\n // z-indexes\n 'z-10 hover:z-20': !isFrozen && !isResizing,\n 'z-20': !isFrozen && isResizing,\n '!z-30': isFrozen,\n '!z-40': isFrozen && isResizing,\n },\n meta.headerClassName\n );\n\n const [internalRef, setInternalRef] = React.useState<HTMLDivElement | null>(null);\n\n React.useLayoutEffect(() => {\n if (internalRef && length) {\n // the actions column size gets set by the column itself\n if (isInternalColumn(id)) {\n return;\n }\n\n table.setColumnSizing(sizes => ({\n ...sizes,\n [id]: internalRef.getBoundingClientRect().width,\n }));\n }\n }, [internalRef, length]);\n\n if (table.options.debugAll) {\n console.log('header render', id);\n }\n\n return (\n <div\n {...(canSort ? getSortAttributes(handleSort, sortDirection) : undefined)}\n className={className}\n data-align={align}\n data-column-index={index}\n role=\"columnheader\"\n ref={setInternalRef}>\n {isInternalColumn(id) ? (\n children\n ) : (\n <Tooltip title={String(meta?.tooltip ?? children)} placement=\"top\">\n <span className={cn({ truncate: !isPrinting })}>{children}</span>\n </Tooltip>\n )}\n {canSort ? <SortIndicator direction={sortDirection} /> : null}\n {hasMenu ? (\n <Menu\n canFreeze={canFreeze}\n canHide={canHide}\n canSort={canSort}\n className={cn({\n 'ml-auto': align !== 'right',\n 'ml-2': align === 'right',\n })}\n index={index}\n menu={meta.menu}\n onGoto={handleGoto}\n onHide={handleHide}\n onSortToggle={handleSortToggle}\n scrollToIndex={scrollToIndex}\n sortDirection={sortDirection}\n table={table}\n />\n ) : null}\n {canResize ? <Resizer isResizing={isResizing} onResize={handleResize} /> : null}\n </div>\n );\n}) as <TType = unknown>(props: MemoedHeaderProps<TType>) => JSX.Element;\n"],"names":["SORT_DIRECTION","ASC","DESC","Header","props","children","column","header","scrollToIndex","table","tableMeta","options","meta","columnMeta","React","useMemo","columnDef","canSort","getCanSort","hasGoto","isGotoAvailable","handleHide","getToggleVisibilityHandler","handleResize","getResizeHandler","handleSort","getToggleSortingHandler","handleSortToggle","useCallback","sortDirection","clearSorting","toggleSorting","sorting","getState","filters","columnFilters","search","globalFilter","handleGoto","query","rowGoto","id","undefined","JSON","stringify","memoedProps","align","canFreeze","columnFreezing","isEnabled","canHide","getCanHide","canResize","getCanResize","hasMenu","isMenuAvailable","index","isFrozen","isFrozenColumn","isPrinting","isResizing","getIsResizing","length","getRowModel","rows","onGoto","onHide","onResize","onSort","onSortToggle","getIsSorted","MemoedHeader","memo","className","cn","headerClassName","internalRef","setInternalRef","useState","useLayoutEffect","isInternalColumn","setColumnSizing","sizes","getBoundingClientRect","width","debugAll","console","log","getSortAttributes","role","ref","Tooltip","title","String","_meta$tooltip","tooltip","placement","truncate","SortIndicator","direction","Menu","menu","Resizer"],"mappings":";;;;;;;;MAUaA,cAAc,GAAwC;EA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AAEA,KAAK,KAAK;KACrB,CAAC;IACFU,KAAK,EAAEA,KAAK;IACZ6C,IAAI,EAAEzF,IAAI,CAACyF,IAAI;IACfpC,MAAM,EAAE3B,UAAU;IAClB4B,MAAM,EAAE7C,UAAU;IAClBgD,YAAY,EAAE1C,gBAAgB;IAC9BnB,aAAa,EAAEA,aAAa;IAC5BqB,aAAa,EAAEA,aAAa;IAC5BpB,KAAK,EAAEA;IACT,GACF,IAAI,EACP2C,SAAS,gBAAGtC,6BAACwF,OAAO;IAAC1C,UAAU,EAAEA,UAAU;IAAEO,QAAQ,EAAE5C;IAAgB,GAAG,IAAI,CAC7E;AAEd,CAAC,CAAsE;;;;"}
|
@@ -5,6 +5,7 @@ import { useLocalization } from '../../../../Provider/Localization.js';
|
|
5
5
|
import { Menu as Menu$1 } from '../../../../Menu/Menu.js';
|
6
6
|
import { _finallyRethrows, _catch } from '../../../../../../../../node_modules/babel-plugin-transform-async-to-promises/helpers.mjs.js';
|
7
7
|
import { GotoPopover } from './Goto.js';
|
8
|
+
import { SORT_DIRECTION } from './Header.js';
|
8
9
|
import { isInternalColumn } from '../../../util/columns.js';
|
9
10
|
|
10
11
|
function isGotoAvailable(table, header) {
|
@@ -26,11 +27,14 @@ function Menu(props) {
|
|
26
27
|
const {
|
27
28
|
canFreeze,
|
28
29
|
canHide,
|
30
|
+
canSort,
|
29
31
|
index,
|
30
32
|
menu,
|
31
33
|
onGoto: handleGoto,
|
32
34
|
onHide: handleHide,
|
35
|
+
onSortToggle: handleSortToggle,
|
33
36
|
scrollToIndex,
|
37
|
+
sortDirection,
|
34
38
|
table
|
35
39
|
} = props;
|
36
40
|
const tableMeta = table.options.meta;
|
@@ -38,6 +42,11 @@ function Menu(props) {
|
|
38
42
|
texts
|
39
43
|
} = useLocalization();
|
40
44
|
const [popover, setPopover] = React__default.useState(undefined);
|
45
|
+
const [sortDirectionState, setSortDirectionState] = React__default.useState(sortDirection);
|
46
|
+
const handleSortMenuRadioGroupChange = newSortDirection => {
|
47
|
+
setSortDirectionState(newSortDirection);
|
48
|
+
handleSortToggle(newSortDirection);
|
49
|
+
};
|
41
50
|
let popoverElement;
|
42
51
|
if (popover) {
|
43
52
|
const handleClosePopover = () => setPopover(undefined);
|
@@ -75,18 +84,11 @@ function Menu(props) {
|
|
75
84
|
}
|
76
85
|
}
|
77
86
|
}
|
78
|
-
const className = cn('-my-0.5 -mr-1 -ml-0.5 !h-6 !min-h-[theme(spacing.6)] !w-
|
79
|
-
'!
|
87
|
+
const className = cn('-my-0.5 -mr-1 -ml-0.5 !h-6 !min-h-[theme(spacing.6)] flex-shrink-0 justify-end !w-0 !min-w-0 !overflow-hidden', 'aria-expanded:!min-w-[theme(spacing.6)] aria-expanded:!w-6 aria-expanded:!overflow-auto', 'focus:!min-w-[theme(spacing.6)] focus:!w-6 focus:!overflow-auto', 'group-hover/column:!min-w-[theme(spacing.6)] group-hover/column:!w-6 group-hover/column:!overflow-auto', {
|
88
|
+
'!w-6 !min-w-[theme(spacing.6)] !overflow-auto': !!popoverElement
|
80
89
|
}, props.className);
|
81
90
|
const memoedMenuItems = React__default.useMemo(() => {
|
82
91
|
const menuItems = [];
|
83
|
-
if (handleGoto) {
|
84
|
-
menuItems.push( /*#__PURE__*/React__default.createElement(Menu$1.Item, {
|
85
|
-
icon: "move",
|
86
|
-
onClick: () => setPopover('goto'),
|
87
|
-
shortcut: "g"
|
88
|
-
}, texts.table3.columns.menu.gotoRow, "..."));
|
89
|
-
}
|
90
92
|
if (canHide) {
|
91
93
|
// we do this in the next tick, otherwise the menu closes and react throws a "state update on unmounted component" error
|
92
94
|
const handleClick = event => setTimeout(() => handleHide(event), 1);
|
@@ -95,6 +97,30 @@ function Menu(props) {
|
|
95
97
|
onClick: handleClick
|
96
98
|
}, texts.table3.columns.menu.hideColumn));
|
97
99
|
}
|
100
|
+
// We rely on canSort value instead of onSort function's value because some columns might have sorting disabled,
|
101
|
+
// so even though onSort is truthy, we don't want to show sorting menu.
|
102
|
+
if (canSort) {
|
103
|
+
menuItems.push( /*#__PURE__*/React__default.createElement(Menu$1.Item, {
|
104
|
+
icon: "sort-by",
|
105
|
+
subMenu: () => /*#__PURE__*/React__default.createElement(Menu$1.SubMenu, null, /*#__PURE__*/React__default.createElement(Menu$1.RadioGroup, {
|
106
|
+
onChange: handleSortMenuRadioGroupChange,
|
107
|
+
value: sortDirectionState
|
108
|
+
}, /*#__PURE__*/React__default.createElement(Menu$1.RadioGroup.Item, {
|
109
|
+
value: SORT_DIRECTION.ASC
|
110
|
+
}, texts.table3.columns.menu.sortingOrder.ascending), /*#__PURE__*/React__default.createElement(Menu$1.RadioGroup.Item, {
|
111
|
+
value: SORT_DIRECTION.DESC
|
112
|
+
}, texts.table3.columns.menu.sortingOrder.descending), /*#__PURE__*/React__default.createElement(Menu$1.RadioGroup.Item, {
|
113
|
+
value: false
|
114
|
+
}, texts.table3.columns.menu.sortingOrder.unsorted)))
|
115
|
+
}, texts.table3.columns.menu.sorting));
|
116
|
+
}
|
117
|
+
if (handleGoto) {
|
118
|
+
menuItems.push( /*#__PURE__*/React__default.createElement(Menu$1.Item, {
|
119
|
+
icon: "move",
|
120
|
+
onClick: () => setPopover('goto'),
|
121
|
+
shortcut: "g"
|
122
|
+
}, texts.table3.columns.menu.gotoRow, "..."));
|
123
|
+
}
|
98
124
|
if (canFreeze) {
|
99
125
|
const frozenIndex = index - tableMeta.columnFreezing.frozenInternalColumnCount;
|
100
126
|
const handleClick = () => tableMeta.columnFreezing.setFrozenColumnIndex(frozenIndex);
|
@@ -127,7 +153,7 @@ function Menu(props) {
|
|
127
153
|
return menuItems.map((item, key) => /*#__PURE__*/React__default.cloneElement(item, {
|
128
154
|
key
|
129
155
|
}));
|
130
|
-
}, [menu, index, canFreeze, canHide, handleGoto, tableMeta.columnFreezing.frozenColumnIndex]);
|
156
|
+
}, [menu, index, canFreeze, canHide, canSort, handleGoto, handleSortToggle, sortDirection, tableMeta.columnFreezing.frozenColumnIndex]);
|
131
157
|
return /*#__PURE__*/React__default.createElement(IconButton, {
|
132
158
|
className: className,
|
133
159
|
icon: "more",
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Menu.js","sources":["../../../../../../../../../../src/components/Table3/components/columns/header/Menu.tsx"],"sourcesContent":["import React from 'react';\nimport cn from 'classnames';\nimport { Header as RTHeader, Table as RTable, TableMeta } from '@tanstack/react-table';\nimport { IconButton } from '../../../../IconButton/IconButton';\nimport { Menu as MenuPrimitive } from '../../../../Menu/Menu';\nimport { isInternalColumn } from '../../../util/columns';\nimport { useLocalization } from '../../../../Provider/Localization';\nimport { Table3ColumnHeaderMenu, TableStrategy } from '../../../types';\nimport { GotoPopover } from './Goto';\n\nexport function isGotoAvailable<TType = unknown>(table: RTable<TType>, header: RTHeader<TType, unknown>) {\n if (isInternalColumn(header.id)) {\n return false;\n }\n\n const tableMeta = table.options.meta as TableMeta<TType>;\n\n return !!(tableMeta.rowGoto.isEnabled && header.column.getCanSort() && header.column.getIsSorted());\n}\n\nexport function isMenuAvailable<TType = unknown>(table: RTable<TType>, header: RTHeader<TType, unknown>): boolean {\n if (isInternalColumn(header.id)) {\n return false;\n }\n\n const tableMeta = table.options.meta as TableMeta<TType>;\n\n return (\n !!header.column.columnDef.meta?.menu ||\n !!tableMeta.columnFreezing.isEnabled ||\n (!!table.options.enableHiding && !!header.column.getCanHide()) ||\n isGotoAvailable(table, header)\n );\n}\n\nexport type MenuProps<TType = unknown> = React.ButtonHTMLAttributes<HTMLButtonElement> & {\n canFreeze: boolean;\n canHide: boolean;\n index: number;\n menu?: Table3ColumnHeaderMenu;\n onGoto?: (query: string) => Promise<number>;\n onHide: (event: unknown) => void;\n scrollToIndex: TableStrategy['scrollToIndex'];\n table: RTable<TType>;\n};\n\nexport function Menu<TType = unknown>(props: MenuProps<TType>) {\n const { canFreeze, canHide, index, menu, onGoto: handleGoto, onHide: handleHide, scrollToIndex, table } = props;\n const tableMeta = table.options.meta as TableMeta<TType>;\n const { texts } = useLocalization();\n const [popover, setPopover] = React.useState<string | undefined>(undefined);\n\n let popoverElement;\n\n if (popover) {\n const handleClosePopover = () => setPopover(undefined);\n\n switch (popover) {\n case 'goto': {\n if (handleGoto) {\n const goto = async (query: string) => {\n try {\n const index = await handleGoto(query);\n tableMeta.currentRow.setCurrentRowIndex(index);\n scrollToIndex(index + 2, { align: 'center' });\n } catch {\n //\n } finally {\n handleClosePopover();\n }\n };\n popoverElement = props => <GotoPopover {...props} open onChange={handleClosePopover} onGoto={goto} />;\n }\n }\n }\n }\n\n const className = cn(\n '-my-0.5 -mr-1 -ml-0.5 !h-6 !min-h-[theme(spacing.6)] !w-6 !min-w-[theme(spacing.6)] flex-shrink-0 justify-end',\n {\n '!flex': !!popoverElement,\n },\n props.className\n );\n\n const memoedMenuItems = React.useMemo(() => {\n const menuItems: JSX.Element[] = [];\n\n if (handleGoto) {\n menuItems.push(\n <MenuPrimitive.Item icon=\"move\" onClick={() => setPopover('goto')} shortcut=\"g\">\n {texts.table3.columns.menu.gotoRow}...\n </MenuPrimitive.Item>\n );\n }\n\n if (canHide) {\n // we do this in the next tick, otherwise the menu closes and react throws a \"state update on unmounted component\" error\n const handleClick = event => setTimeout(() => handleHide(event), 1);\n\n menuItems.push(\n <MenuPrimitive.Item icon=\"unreconciled\" onClick={handleClick}>\n {texts.table3.columns.menu.hideColumn}\n </MenuPrimitive.Item>\n );\n }\n\n if (canFreeze) {\n const frozenIndex = index - tableMeta.columnFreezing.frozenInternalColumnCount;\n const handleClick = () => tableMeta.columnFreezing.setFrozenColumnIndex(frozenIndex);\n\n menuItems.push(\n <MenuPrimitive.Item icon=\"column-freeze\" onClick={handleClick}>\n {frozenIndex === 0\n ? texts.table3.columns.menu.freezeFirstColumn\n : texts.table3.columns.menu.freezeUptoColumn.replace('[TOTAL]', String(frozenIndex + 1))}\n </MenuPrimitive.Item>\n );\n\n if (tableMeta.columnFreezing.frozenColumnIndex !== undefined) {\n const handleClick = () => {\n tableMeta.columnFreezing.setFrozenColumnIndex(undefined);\n };\n\n menuItems.push(\n <MenuPrimitive.Item icon=\"column-unfreeze\" onClick={handleClick}>\n {texts.table3.columns.menu.unfreezeColumns}\n </MenuPrimitive.Item>\n );\n }\n }\n\n if (menu) {\n const customMenu = menu({ trigger: undefined });\n const customItems = React.Children.toArray(customMenu.props.children.props.children) as JSX.Element[];\n\n if (customItems.length) {\n if (menuItems.length) {\n menuItems.push(<MenuPrimitive.Separator />);\n }\n\n menuItems.push(...customItems);\n }\n }\n\n return menuItems.map((item, key) => React.cloneElement(item, { key }));\n }, [menu, index, canFreeze, canHide, handleGoto, tableMeta.columnFreezing.frozenColumnIndex]);\n\n return (\n <IconButton\n className={className}\n icon=\"more\"\n menu={\n popoverElement\n ? undefined\n : menuProps => (\n <MenuPrimitive {...menuProps}>\n <MenuPrimitive.Content>{memoedMenuItems}</MenuPrimitive.Content>\n </MenuPrimitive>\n )\n }\n popover={popoverElement}\n onClickCapture={event => event.preventDefault()}\n />\n );\n}\n"],"names":["isGotoAvailable","table","header","isInternalColumn","id","tableMeta","options","meta","rowGoto","isEnabled","column","getCanSort","getIsSorted","isMenuAvailable","_header$column$column","columnDef","menu","columnFreezing","enableHiding","getCanHide","Menu","props","canFreeze","canHide","index","onGoto","handleGoto","onHide","handleHide","scrollToIndex","texts","useLocalization","popover","setPopover","React","useState","undefined","popoverElement","handleClosePopover","goto","query","Promise","resolve","then","currentRow","setCurrentRowIndex","align","_wasThrown","_result","_temp","e","reject","GotoPopover","open","onChange","className","cn","memoedMenuItems","useMemo","menuItems","push","MenuPrimitive","Item","icon","onClick","shortcut","table3","columns","gotoRow","handleClick","event","setTimeout","hideColumn","frozenIndex","frozenInternalColumnCount","setFrozenColumnIndex","freezeFirstColumn","freezeUptoColumn","replace","String","frozenColumnIndex","unfreezeColumns","customMenu","trigger","customItems","Children","toArray","children","length","Separator","map","item","key","cloneElement","IconButton","menuProps","Content","onClickCapture","preventDefault"],"mappings":";;;;;;;;;SAUgBA,eAAeA,CAAkBC,KAAoB,EAAE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,EAAEK;WAC/CvC,KAAK,CAACoC,MAAM,CAACC,OAAO,CAACnD,IAAI,CAACiE,eAAe,CACzB,CACxB;;;IAIT,IAAIjE,IAAI,EAAE;MACN,MAAMkE,UAAU,GAAGlE,IAAI,CAAC;QAAEmE,OAAO,EAAE/C;OAAW,CAAC;MAC/C,MAAMgD,WAAW,GAAGlD,cAAK,CAACmD,QAAQ,CAACC,OAAO,CAACJ,UAAU,CAAC7D,KAAK,CAACkE,QAAQ,CAAClE,KAAK,CAACkE,QAAQ,CAAkB;MAErG,IAAIH,WAAW,CAACI,MAAM,EAAE;QACpB,IAAI7B,SAAS,CAAC6B,MAAM,EAAE;UAClB7B,SAAS,CAACC,IAAI,eAAC1B,6BAAC2B,MAAa,CAAC4B,SAAS,OAAG,CAAC;;QAG/C9B,SAAS,CAACC,IAAI,CAAC,GAAGwB,WAAW,CAAC;;;IAItC,OAAOzB,SAAS,CAAC+B,GAAG,CAAC,CAACC,IAAI,EAAEC,GAAG,kBAAK1D,cAAK,CAAC2D,YAAY,CAACF,IAAI,EAAE;MAAEC;KAAK,CAAC,CAAC;GACzE,EAAE,CAAC5E,IAAI,EAAEQ,KAAK,EAAEF,SAAS,EAAEC,OAAO,EAAEG,UAAU,EAAErB,SAAS,CAACY,cAAc,CAAC+D,iBAAiB,CAAC,CAAC;EAE7F,oBACI9C,6BAAC4D,UAAU;IACPvC,SAAS,EAAEA,SAAS;IACpBQ,IAAI,EAAC,MAAM;IACX/C,IAAI,EACAqB,cAAc,GACRD,SAAS,GACT2D,SAAS,iBACL7D,6BAAC2B,MAAa,oBAAKkC,SAAS,gBACxB7D,6BAAC2B,MAAa,CAACmC,OAAO,QAAEvC,eAAe,CAAyB,CAEvE;IAEXzB,OAAO,EAAEK,cAAc;IACvB4D,cAAc,EAAE3B,KAAK,IAAIA,KAAK,CAAC4B,cAAc;IAC/C;AAEV;;;;"}
|
1
|
+
{"version":3,"file":"Menu.js","sources":["../../../../../../../../../../src/components/Table3/components/columns/header/Menu.tsx"],"sourcesContent":["import React from 'react';\nimport cn from 'classnames';\nimport { Header as RTHeader, Table as RTable, TableMeta } from '@tanstack/react-table';\nimport { IconButton } from '../../../../IconButton/IconButton';\nimport { Menu as MenuPrimitive } from '../../../../Menu/Menu';\nimport { isInternalColumn } from '../../../util/columns';\nimport { useLocalization } from '../../../../Provider/Localization';\nimport { Table3ColumnHeaderMenu, TableStrategy } from '../../../types';\nimport { GotoPopover } from './Goto';\nimport { HeaderSortDirection, SORT_DIRECTION, SortToggleHandler } from './Header';\nimport { RadioGroupItemValue } from '../../../../RadioGroup/RadioGroup';\n\nexport function isGotoAvailable<TType = unknown>(table: RTable<TType>, header: RTHeader<TType, unknown>) {\n if (isInternalColumn(header.id)) {\n return false;\n }\n\n const tableMeta = table.options.meta as TableMeta<TType>;\n\n return !!(tableMeta.rowGoto.isEnabled && header.column.getCanSort() && header.column.getIsSorted());\n}\n\nexport function isMenuAvailable<TType = unknown>(table: RTable<TType>, header: RTHeader<TType, unknown>): boolean {\n if (isInternalColumn(header.id)) {\n return false;\n }\n\n const tableMeta = table.options.meta as TableMeta<TType>;\n\n return (\n !!header.column.columnDef.meta?.menu ||\n !!tableMeta.columnFreezing.isEnabled ||\n (!!table.options.enableHiding && !!header.column.getCanHide()) ||\n isGotoAvailable(table, header)\n );\n}\n\nexport type MenuProps<TType = unknown> = React.ButtonHTMLAttributes<HTMLButtonElement> & {\n canFreeze: boolean;\n canHide: boolean;\n canSort: boolean;\n index: number;\n menu?: Table3ColumnHeaderMenu;\n onGoto?: (query: string) => Promise<number>;\n onHide: (event: unknown) => void;\n onSortToggle: SortToggleHandler;\n scrollToIndex: TableStrategy['scrollToIndex'];\n sortDirection: HeaderSortDirection;\n table: RTable<TType>;\n};\n\nexport function Menu<TType = unknown>(props: MenuProps<TType>) {\n const {\n canFreeze,\n canHide,\n canSort,\n index,\n menu,\n onGoto: handleGoto,\n onHide: handleHide,\n onSortToggle: handleSortToggle,\n scrollToIndex,\n sortDirection,\n table,\n } = props;\n const tableMeta = table.options.meta as TableMeta<TType>;\n const { texts } = useLocalization();\n const [popover, setPopover] = React.useState<string | undefined>(undefined);\n const [sortDirectionState, setSortDirectionState] = React.useState<HeaderSortDirection>(sortDirection);\n\n const handleSortMenuRadioGroupChange = (newSortDirection: RadioGroupItemValue) => {\n setSortDirectionState(newSortDirection as HeaderSortDirection);\n handleSortToggle(newSortDirection as HeaderSortDirection);\n };\n\n let popoverElement;\n\n if (popover) {\n const handleClosePopover = () => setPopover(undefined);\n\n switch (popover) {\n case 'goto': {\n if (handleGoto) {\n const goto = async (query: string) => {\n try {\n const index = await handleGoto(query);\n tableMeta.currentRow.setCurrentRowIndex(index);\n scrollToIndex(index + 2, { align: 'center' });\n } catch {\n //\n } finally {\n handleClosePopover();\n }\n };\n popoverElement = props => <GotoPopover {...props} open onChange={handleClosePopover} onGoto={goto} />;\n }\n }\n }\n }\n\n const className = cn(\n '-my-0.5 -mr-1 -ml-0.5 !h-6 !min-h-[theme(spacing.6)] flex-shrink-0 justify-end !w-0 !min-w-0 !overflow-hidden',\n 'aria-expanded:!min-w-[theme(spacing.6)] aria-expanded:!w-6 aria-expanded:!overflow-auto',\n 'focus:!min-w-[theme(spacing.6)] focus:!w-6 focus:!overflow-auto',\n 'group-hover/column:!min-w-[theme(spacing.6)] group-hover/column:!w-6 group-hover/column:!overflow-auto',\n {\n '!w-6 !min-w-[theme(spacing.6)] !overflow-auto': !!popoverElement,\n },\n props.className\n );\n\n const memoedMenuItems = React.useMemo(() => {\n const menuItems: JSX.Element[] = [];\n\n if (canHide) {\n // we do this in the next tick, otherwise the menu closes and react throws a \"state update on unmounted component\" error\n const handleClick = event => setTimeout(() => handleHide(event), 1);\n\n menuItems.push(\n <MenuPrimitive.Item icon=\"unreconciled\" onClick={handleClick}>\n {texts.table3.columns.menu.hideColumn}\n </MenuPrimitive.Item>\n );\n }\n\n // We rely on canSort value instead of onSort function's value because some columns might have sorting disabled,\n // so even though onSort is truthy, we don't want to show sorting menu.\n if (canSort) {\n menuItems.push(\n <MenuPrimitive.Item\n icon=\"sort-by\"\n subMenu={() => (\n <MenuPrimitive.SubMenu>\n <MenuPrimitive.RadioGroup onChange={handleSortMenuRadioGroupChange} value={sortDirectionState}>\n <MenuPrimitive.RadioGroup.Item value={SORT_DIRECTION.ASC}>\n {texts.table3.columns.menu.sortingOrder.ascending}\n </MenuPrimitive.RadioGroup.Item>\n <MenuPrimitive.RadioGroup.Item value={SORT_DIRECTION.DESC}>\n {texts.table3.columns.menu.sortingOrder.descending}\n </MenuPrimitive.RadioGroup.Item>\n <MenuPrimitive.RadioGroup.Item value={false}>\n {texts.table3.columns.menu.sortingOrder.unsorted}\n </MenuPrimitive.RadioGroup.Item>\n </MenuPrimitive.RadioGroup>\n </MenuPrimitive.SubMenu>\n )}>\n {texts.table3.columns.menu.sorting}\n </MenuPrimitive.Item>\n );\n }\n\n if (handleGoto) {\n menuItems.push(\n <MenuPrimitive.Item icon=\"move\" onClick={() => setPopover('goto')} shortcut=\"g\">\n {texts.table3.columns.menu.gotoRow}...\n </MenuPrimitive.Item>\n );\n }\n\n if (canFreeze) {\n const frozenIndex = index - tableMeta.columnFreezing.frozenInternalColumnCount;\n const handleClick = () => tableMeta.columnFreezing.setFrozenColumnIndex(frozenIndex);\n\n menuItems.push(\n <MenuPrimitive.Item icon=\"column-freeze\" onClick={handleClick}>\n {frozenIndex === 0\n ? texts.table3.columns.menu.freezeFirstColumn\n : texts.table3.columns.menu.freezeUptoColumn.replace('[TOTAL]', String(frozenIndex + 1))}\n </MenuPrimitive.Item>\n );\n\n if (tableMeta.columnFreezing.frozenColumnIndex !== undefined) {\n const handleClick = () => {\n tableMeta.columnFreezing.setFrozenColumnIndex(undefined);\n };\n\n menuItems.push(\n <MenuPrimitive.Item icon=\"column-unfreeze\" onClick={handleClick}>\n {texts.table3.columns.menu.unfreezeColumns}\n </MenuPrimitive.Item>\n );\n }\n }\n\n if (menu) {\n const customMenu = menu({ trigger: undefined });\n const customItems = React.Children.toArray(customMenu.props.children.props.children) as JSX.Element[];\n\n if (customItems.length) {\n if (menuItems.length) {\n menuItems.push(<MenuPrimitive.Separator />);\n }\n\n menuItems.push(...customItems);\n }\n }\n\n return menuItems.map((item, key) => React.cloneElement(item, { key }));\n }, [\n menu,\n index,\n canFreeze,\n canHide,\n canSort,\n handleGoto,\n handleSortToggle,\n sortDirection,\n tableMeta.columnFreezing.frozenColumnIndex,\n ]);\n\n return (\n <IconButton\n className={className}\n icon=\"more\"\n menu={\n popoverElement\n ? undefined\n : menuProps => (\n <MenuPrimitive {...menuProps}>\n <MenuPrimitive.Content>{memoedMenuItems}</MenuPrimitive.Content>\n </MenuPrimitive>\n )\n }\n popover={popoverElement}\n onClickCapture={event => event.preventDefault()}\n />\n );\n}\n"],"names":["isGotoAvailable","table","header","isInternalColumn","id","tableMeta","options","meta","rowGoto","isEnabled","column","getCanSort","getIsSorted","isMenuAvailable","_header$column$column","columnDef","menu","columnFreezing","enableHiding","getCanHide","Menu","props","canFreeze","canHide","canSort","index","onGoto","handleGoto","onHide","handleHide","onSortToggle","handleSortToggle","scrollToIndex","sortDirection","texts","useLocalization","popover","setPopover","React","useState","undefined","sortDirectionState","setSortDirectionState","handleSortMenuRadioGroupChange","newSortDirection","popoverElement","handleClosePopover","goto","query","Promise","resolve","then","currentRow","setCurrentRowIndex","align","_wasThrown","_result","_temp","e","reject","GotoPopover","open","onChange","className","cn","memoedMenuItems","useMemo","menuItems","handleClick","event","setTimeout","push","MenuPrimitive","Item","icon","onClick","table3","columns","hideColumn","subMenu","SubMenu","RadioGroup","value","SORT_DIRECTION","ASC","sortingOrder","ascending","DESC","descending","unsorted","sorting","shortcut","gotoRow","frozenIndex","frozenInternalColumnCount","setFrozenColumnIndex","freezeFirstColumn","freezeUptoColumn","replace","String","frozenColumnIndex","unfreezeColumns","customMenu","trigger","customItems","Children","toArray","children","length","Separator","map","item","key","cloneElement","IconButton","menuProps","Content","onClickCapture","preventDefault"],"mappings":";;;;;;;;;;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OAAO,CAAC7D,IAAI,CAACqF,eAAe,CACzB,CACxB;;;IAIT,IAAIrF,IAAI,EAAE;MACN,MAAMsF,UAAU,GAAGtF,IAAI,CAAC;QAAEuF,OAAO,EAAE/D;OAAW,CAAC;MAC/C,MAAMgE,WAAW,GAAGlE,cAAK,CAACmE,QAAQ,CAACC,OAAO,CAACJ,UAAU,CAACjF,KAAK,CAACsF,QAAQ,CAACtF,KAAK,CAACsF,QAAQ,CAAkB;MAErG,IAAIH,WAAW,CAACI,MAAM,EAAE;QACpB,IAAIzC,SAAS,CAACyC,MAAM,EAAE;UAClBzC,SAAS,CAACI,IAAI,eAACjC,6BAACkC,MAAa,CAACqC,SAAS,OAAG,CAAC;;QAG/C1C,SAAS,CAACI,IAAI,CAAC,GAAGiC,WAAW,CAAC;;;IAItC,OAAOrC,SAAS,CAAC2C,GAAG,CAAC,CAACC,IAAI,EAAEC,GAAG,kBAAK1E,cAAK,CAAC2E,YAAY,CAACF,IAAI,EAAE;MAAEC;KAAK,CAAC,CAAC;GACzE,EAAE,CACChG,IAAI,EACJS,KAAK,EACLH,SAAS,EACTC,OAAO,EACPC,OAAO,EACPG,UAAU,EACVI,gBAAgB,EAChBE,aAAa,EACb5B,SAAS,CAACY,cAAc,CAACmF,iBAAiB,CAC7C,CAAC;EAEF,oBACI9D,6BAAC4E,UAAU;IACPnD,SAAS,EAAEA,SAAS;IACpBW,IAAI,EAAC,MAAM;IACX1D,IAAI,EACA6B,cAAc,GACRL,SAAS,GACT2E,SAAS,iBACL7E,6BAACkC,MAAa,oBAAK2C,SAAS,gBACxB7E,6BAACkC,MAAa,CAAC4C,OAAO,QAAEnD,eAAe,CAAyB,CAEvE;IAEX7B,OAAO,EAAES,cAAc;IACvBwE,cAAc,EAAEhD,KAAK,IAAIA,KAAK,CAACiD,cAAc;IAC/C;AAEV;;;;"}
|
@@ -61,7 +61,7 @@ const MemoedCell = /*#__PURE__*/React__default.memo(function MemoedCell(props) {
|
|
61
61
|
var _ref, _button$props$tooltip;
|
62
62
|
const tooltip = String((_ref = (_button$props$tooltip = button.props.tooltip) !== null && _button$props$tooltip !== void 0 ? _button$props$tooltip : button.props['aria-label']) !== null && _ref !== void 0 ? _ref : '');
|
63
63
|
return /*#__PURE__*/React__default.cloneElement(button, {
|
64
|
-
appearance: '
|
64
|
+
appearance: 'transparent',
|
65
65
|
key: index,
|
66
66
|
tabIndex: isCurrentRow ? 0 : -1,
|
67
67
|
tooltip: button.props.shortcut ? /*#__PURE__*/React__default.createElement(React__default.Fragment, null, tooltip, /*#__PURE__*/React__default.createElement(Shortcut, {
|
@@ -70,7 +70,7 @@ const MemoedCell = /*#__PURE__*/React__default.memo(function MemoedCell(props) {
|
|
70
70
|
})) : tooltip
|
71
71
|
});
|
72
72
|
}), actionsInMenu.length ? /*#__PURE__*/React__default.createElement(IconButton, {
|
73
|
-
appearance: "
|
73
|
+
appearance: "transparent",
|
74
74
|
"aria-label": texts.table3.columns.actions.tooltip,
|
75
75
|
icon: "more",
|
76
76
|
tabIndex: isCurrentRow ? 0 : -1,
|
@@ -106,7 +106,7 @@ function createRowActionsColumn() {
|
|
106
106
|
footer: Footer,
|
107
107
|
meta: {
|
108
108
|
align: 'right',
|
109
|
-
className: cn('!pt-[var(--table3-
|
109
|
+
className: cn('!pt-[var(--table3-cell-padding-y)] print:opacity-0 [[role="table"][data-editing="false"]_&]:group-[[data-current="true"]]/row:sticky [[role="table"][data-pause-hover="false"][data-editing="false"]_&]:group-hover/row:sticky right-0 !pl-1 !pr-1', 'shadow-[-6px_0px_6px_var(--table3-row-actions-shadow)]', 'group-[[data-current="true"][data-selected="false"]]/row:text-grey-200', 'group-[[data-selected="true"]]/row:text-blue-100', 'group-[[data-selected="false"]:hover]/row:text-grey-100'),
|
110
110
|
enableOrdering: false,
|
111
111
|
enableSearch: false,
|
112
112
|
enableTruncate: false,
|
package/dist/esm/packages/taco/src/components/Table3/components/columns/internal/Actions.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Actions.js","sources":["../../../../../../../../../../src/components/Table3/components/columns/internal/Actions.tsx"],"sourcesContent":["import React from 'react';\nimport { CellContext, DisplayColumnDef, TableMeta } from '@tanstack/react-table';\nimport cn from 'classnames';\nimport { Header as ColumnHeader } from '../header/Header';\nimport { DisplayCell } from '../cell/DisplayCell';\nimport { Table3FontSize, Table3RowActionRenderer } from '../../../types';\nimport { RowContext } from '../../rows/RowContext';\nimport { IconButton } from '../../../../IconButton/IconButton';\nimport { useLocalization } from '../../../../Provider/Localization';\nimport { Menu } from '../../../../Menu/Menu';\nimport { Shortcut } from '../../../../Shortcut/Shortcut';\nimport { Footer } from '../footer/Footer';\n\nexport const COLUMN_ID = '__actions';\n\ntype MemoedCellProps<TType = unknown> = CellContext<TType, unknown> & {\n actions?: Table3RowActionRenderer<TType>[];\n actionsLength: number;\n fontSize: Table3FontSize;\n isCurrentRow: boolean;\n isEditing: boolean;\n isResizingColumn: boolean;\n isHoverStatePaused: boolean;\n};\n\nconst MemoedCell = React.memo(function MemoedCell<TType = unknown>(props: MemoedCellProps<TType>) {\n const { actions, actionsLength, fontSize, isCurrentRow, isEditing, isResizingColumn, isHoverStatePaused, row } = props;\n const { isHovered } = React.useContext(RowContext);\n const { texts } = useLocalization();\n const ref = React.useRef<HTMLSpanElement | null>(null);\n /*\n const size = table.getState().columnSizing[COLUMN_ID];\n\n // the actions column needs to set its size based on its content, not the actual column\n // so we do this here instead of in the header\n React.useLayoutEffect(() => {\n if (ref.current && !size) {\n const width = ref.current.getBoundingClientRect().width;\n\n table.setColumnSizing(sizes => ({\n ...sizes,\n [COLUMN_ID]: width,\n }));\n }\n }, [ref.current]);\n */\n\n let content;\n\n // We don't want to show actions in edit mode, since we have editing actions,\n // which is shown in edit mode instead.\n if (actions?.length && !isEditing && (isCurrentRow || (isHovered && !isHoverStatePaused && !isResizingColumn))) {\n const visibleActions = actions.map(action => action(row.original)).filter(action => !!action) as JSX.Element[];\n\n const actionsOnRow =\n visibleActions.length === actionsLength ? visibleActions : visibleActions.slice(0, actionsLength - 1);\n const actionsInMenu = visibleActions.slice(visibleActions.length === actionsLength ? actionsLength : actionsLength - 1);\n\n const className = cn('-mb-2 flex justify-end pl-2 text-right', {\n // Adjust negative margin on row actions cell to ensure that the cell aligns vertically.\n '-mt-2': fontSize === 'small',\n '-mt-1.5': fontSize !== 'small',\n });\n\n content = (\n <span className={className} ref={ref}>\n {actionsOnRow.map((button, index) => {\n const tooltip = String(button.props.tooltip ?? button.props['aria-label'] ?? '');\n\n return React.cloneElement(button, {\n appearance: 'discrete',\n key: index,\n tabIndex: isCurrentRow ? 0 : -1,\n tooltip: button.props.shortcut ? (\n <>\n {tooltip}\n <Shortcut className=\"ml-2\" keys={button.props.shortcut} />\n </>\n ) : (\n tooltip\n ),\n });\n })}\n {actionsInMenu.length ? (\n <IconButton\n appearance=\"discrete\"\n aria-label={texts.table3.columns.actions.tooltip}\n icon=\"more\"\n tabIndex={isCurrentRow ? 0 : -1}\n menu={menuProps => (\n <Menu {...menuProps}>\n <Menu.Content>\n {actionsInMenu.map((action, i) => (\n <Menu.Item key={i} {...action.props} shortcut={action.props.shortcut}>\n {action.props['aria-label']}\n </Menu.Item>\n ))}\n </Menu.Content>\n </Menu>\n )}\n />\n ) : null}\n </span>\n );\n }\n\n return <DisplayCell {...props}>{content}</DisplayCell>;\n}) as <TType = unknown>(props: MemoedCellProps<TType>) => JSX.Element;\n\ntype CellProps<TType = unknown> = CellContext<TType, unknown>;\n\nfunction Cell<TType = unknown>(context: CellProps<TType>) {\n const { rowIndex } = React.useContext(RowContext);\n const tableMeta = context.table.options.meta as TableMeta<TType>;\n\n return (\n <MemoedCell\n {...context}\n actions={tableMeta.rowActions.actionsForRow}\n actionsLength={tableMeta.rowActions.actionsForRowLength}\n fontSize={tableMeta.fontSize.size}\n isCurrentRow={tableMeta.currentRow.currentRowIndex === rowIndex}\n isEditing={tableMeta.editing.isEditing}\n isResizingColumn={!!context.table.getState().columnSizingInfo.isResizingColumn}\n isHoverStatePaused={!!tableMeta.hoverState.isPaused}\n />\n );\n}\n\nexport function createRowActionsColumn<TType = unknown>(): DisplayColumnDef<TType, unknown> {\n return {\n id: COLUMN_ID,\n header: ColumnHeader,\n cell: Cell,\n footer: Footer,\n meta: {\n align: 'right',\n className: cn(\n '!pt-[var(--table3-row-padding)] print:opacity-0 [[role=\"table\"][data-editing=\"false\"]_&]:group-[[data-current=\"true\"]]/row:sticky [[role=\"table\"][data-pause-hover=\"false\"][data-editing=\"false\"]_&]:group-hover/row:sticky right-0 !pl-1 !pr-1',\n 'shadow-[-6px_0px_6px_var(--table3-row-actions-shadow)]',\n 'group-[[data-current=\"true\"][data-selected=\"false\"]]/row:text-grey-200',\n 'group-[[data-selected=\"true\"]]/row:text-blue-100',\n 'group-[[data-selected=\"false\"]:hover]/row:text-grey-100'\n ),\n enableOrdering: false,\n enableSearch: false,\n enableTruncate: false,\n header: '',\n headerClassName: 'items-center !p-0',\n },\n // options\n enableResizing: false,\n };\n}\n"],"names":["COLUMN_ID","MemoedCell","React","memo","props","actions","actionsLength","fontSize","isCurrentRow","isEditing","isResizingColumn","isHoverStatePaused","row","isHovered","useContext","RowContext","texts","useLocalization","ref","useRef","content","length","visibleActions","map","action","original","filter","actionsOnRow","slice","actionsInMenu","className","cn","button","index","tooltip","String","_ref","_button$props$tooltip","cloneElement","appearance","key","tabIndex","shortcut","Shortcut","keys","IconButton","table3","columns","icon","menu","menuProps","Menu","Content","i","Item","DisplayCell","Cell","context","rowIndex","tableMeta","table","options","meta","rowActions","actionsForRow","actionsForRowLength","size","currentRow","currentRowIndex","editing","getState","columnSizingInfo","hoverState","isPaused","createRowActionsColumn","id","header","ColumnHeader","cell","footer","Footer","align","enableOrdering","enableSearch","enableTruncate","headerClassName","enableResizing"],"mappings":";;;;;;;;;;;MAaaA,SAAS,GAAG;AAYzB,MAAMC,UAAU,gBAAGC,cAAK,CAACC,IAAI,CAAC,SAASF,UAAUA,CAAkBG,KAA6B;EAC5F,MAAM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../../../../../../src/components/Table3/components/columns/internal/Actions.tsx"],"sourcesContent":["import React from 'react';\nimport { CellContext, DisplayColumnDef, TableMeta } from '@tanstack/react-table';\nimport cn from 'classnames';\nimport { Header as ColumnHeader } from '../header/Header';\nimport { DisplayCell } from '../cell/DisplayCell';\nimport { Table3FontSize, Table3RowActionRenderer } from '../../../types';\nimport { RowContext } from '../../rows/RowContext';\nimport { IconButton } from '../../../../IconButton/IconButton';\nimport { useLocalization } from '../../../../Provider/Localization';\nimport { Menu } from '../../../../Menu/Menu';\nimport { Shortcut } from '../../../../Shortcut/Shortcut';\nimport { Footer } from '../footer/Footer';\n\nexport const COLUMN_ID = '__actions';\n\ntype MemoedCellProps<TType = unknown> = CellContext<TType, unknown> & {\n actions?: Table3RowActionRenderer<TType>[];\n actionsLength: number;\n fontSize: Table3FontSize;\n isCurrentRow: boolean;\n isEditing: boolean;\n isResizingColumn: boolean;\n isHoverStatePaused: boolean;\n};\n\nconst MemoedCell = React.memo(function MemoedCell<TType = unknown>(props: MemoedCellProps<TType>) {\n const { actions, actionsLength, fontSize, isCurrentRow, isEditing, isResizingColumn, isHoverStatePaused, row } = props;\n const { isHovered } = React.useContext(RowContext);\n const { texts } = useLocalization();\n const ref = React.useRef<HTMLSpanElement | null>(null);\n /*\n const size = table.getState().columnSizing[COLUMN_ID];\n\n // the actions column needs to set its size based on its content, not the actual column\n // so we do this here instead of in the header\n React.useLayoutEffect(() => {\n if (ref.current && !size) {\n const width = ref.current.getBoundingClientRect().width;\n\n table.setColumnSizing(sizes => ({\n ...sizes,\n [COLUMN_ID]: width,\n }));\n }\n }, [ref.current]);\n */\n\n let content;\n\n // We don't want to show actions in edit mode, since we have editing actions,\n // which is shown in edit mode instead.\n if (actions?.length && !isEditing && (isCurrentRow || (isHovered && !isHoverStatePaused && !isResizingColumn))) {\n const visibleActions = actions.map(action => action(row.original)).filter(action => !!action) as JSX.Element[];\n\n const actionsOnRow =\n visibleActions.length === actionsLength ? visibleActions : visibleActions.slice(0, actionsLength - 1);\n const actionsInMenu = visibleActions.slice(visibleActions.length === actionsLength ? actionsLength : actionsLength - 1);\n\n const className = cn('-mb-2 flex justify-end pl-2 text-right', {\n // Adjust negative margin on row actions cell to ensure that the cell aligns vertically.\n '-mt-2': fontSize === 'small',\n '-mt-1.5': fontSize !== 'small',\n });\n\n content = (\n <span className={className} ref={ref}>\n {actionsOnRow.map((button, index) => {\n const tooltip = String(button.props.tooltip ?? button.props['aria-label'] ?? '');\n\n return React.cloneElement(button, {\n appearance: 'transparent',\n key: index,\n tabIndex: isCurrentRow ? 0 : -1,\n tooltip: button.props.shortcut ? (\n <>\n {tooltip}\n <Shortcut className=\"ml-2\" keys={button.props.shortcut} />\n </>\n ) : (\n tooltip\n ),\n });\n })}\n {actionsInMenu.length ? (\n <IconButton\n appearance=\"transparent\"\n aria-label={texts.table3.columns.actions.tooltip}\n icon=\"more\"\n tabIndex={isCurrentRow ? 0 : -1}\n menu={menuProps => (\n <Menu {...menuProps}>\n <Menu.Content>\n {actionsInMenu.map((action, i) => (\n <Menu.Item key={i} {...action.props} shortcut={action.props.shortcut}>\n {action.props['aria-label']}\n </Menu.Item>\n ))}\n </Menu.Content>\n </Menu>\n )}\n />\n ) : null}\n </span>\n );\n }\n\n return <DisplayCell {...props}>{content}</DisplayCell>;\n}) as <TType = unknown>(props: MemoedCellProps<TType>) => JSX.Element;\n\ntype CellProps<TType = unknown> = CellContext<TType, unknown>;\n\nfunction Cell<TType = unknown>(context: CellProps<TType>) {\n const { rowIndex } = React.useContext(RowContext);\n const tableMeta = context.table.options.meta as TableMeta<TType>;\n\n return (\n <MemoedCell\n {...context}\n actions={tableMeta.rowActions.actionsForRow}\n actionsLength={tableMeta.rowActions.actionsForRowLength}\n fontSize={tableMeta.fontSize.size}\n isCurrentRow={tableMeta.currentRow.currentRowIndex === rowIndex}\n isEditing={tableMeta.editing.isEditing}\n isResizingColumn={!!context.table.getState().columnSizingInfo.isResizingColumn}\n isHoverStatePaused={!!tableMeta.hoverState.isPaused}\n />\n );\n}\n\nexport function createRowActionsColumn<TType = unknown>(): DisplayColumnDef<TType, unknown> {\n return {\n id: COLUMN_ID,\n header: ColumnHeader,\n cell: Cell,\n footer: Footer,\n meta: {\n align: 'right',\n className: cn(\n '!pt-[var(--table3-cell-padding-y)] print:opacity-0 [[role=\"table\"][data-editing=\"false\"]_&]:group-[[data-current=\"true\"]]/row:sticky [[role=\"table\"][data-pause-hover=\"false\"][data-editing=\"false\"]_&]:group-hover/row:sticky right-0 !pl-1 !pr-1',\n 'shadow-[-6px_0px_6px_var(--table3-row-actions-shadow)]',\n 'group-[[data-current=\"true\"][data-selected=\"false\"]]/row:text-grey-200',\n 'group-[[data-selected=\"true\"]]/row:text-blue-100',\n 'group-[[data-selected=\"false\"]:hover]/row:text-grey-100'\n ),\n enableOrdering: false,\n enableSearch: false,\n enableTruncate: false,\n header: '',\n headerClassName: 'items-center !p-0',\n },\n // options\n enableResizing: false,\n };\n}\n"],"names":["COLUMN_ID","MemoedCell","React","memo","props","actions","actionsLength","fontSize","isCurrentRow","isEditing","isResizingColumn","isHoverStatePaused","row","isHovered","useContext","RowContext","texts","useLocalization","ref","useRef","content","length","visibleActions","map","action","original","filter","actionsOnRow","slice","actionsInMenu","className","cn","button","index","tooltip","String","_ref","_button$props$tooltip","cloneElement","appearance","key","tabIndex","shortcut","Shortcut","keys","IconButton","table3","columns","icon","menu","menuProps","Menu","Content","i","Item","DisplayCell","Cell","context","rowIndex","tableMeta","table","options","meta","rowActions","actionsForRow","actionsForRowLength","size","currentRow","currentRowIndex","editing","getState","columnSizingInfo","hoverState","isPaused","createRowActionsColumn","id","header","ColumnHeader","cell","footer","Footer","align","enableOrdering","enableSearch","enableTruncate","headerClassName","enableResizing"],"mappings":";;;;;;;;;;;MAaaA,SAAS,GAAG;AAYzB,MAAMC,UAAU,gBAAGC,cAAK,CAACC,IAAI,CAAC,SAASF,UAAUA,CAAkBG,KAA6B;EAC5F,MAAM;IAAEC,OAAO;IAAEC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: Footer,
|
69
69
|
meta: {
|
70
70
|
align: 'center',
|
71
|
-
className: '!p-0 !pt-[var(--table3-
|
71
|
+
className: '!p-0 !pt-[var(--table3-cell-padding-y)]',
|
72
72
|
enableOrdering: false,
|
73
73
|
enableSearch: false,
|
74
74
|
enableTruncate: false,
|