@entur/table 4.5.29 → 4.5.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +544 -0
- package/dist/styles.css +7 -7
- package/dist/table.cjs.development.js +113 -65
- package/dist/table.cjs.development.js.map +1 -1
- package/dist/table.cjs.production.min.js +1 -1
- package/dist/table.cjs.production.min.js.map +1 -1
- package/dist/table.esm.js +113 -65
- package/dist/table.esm.js.map +1 -1
- package/package.json +11 -16
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table.cjs.production.min.js","sources":["../src/Table.tsx","../src/TableHead.tsx","../src/TableBody.tsx","../src/TableFooter.tsx","../src/TableRow.tsx","../src/DataCell.tsx","../src/HeaderCell.tsx","../src/useTableKeyboardNavigation.tsx","../src/index.tsx","../src/EditableCell.tsx","../src/ExpandRowButton.tsx","../src/ExpandableRow.tsx","../src/useSortableTable.ts"],"sourcesContent":["import React from 'react';\nimport classNames from 'classnames';\n\nexport type TableProps = {\n /** Ekstra klassenavn */\n className?: string;\n /** Setter tettheten mellom rader og kolonner. Bruk gjerne middle og small for for sider med høy informasjonstetthet\n * @default \"default\"\n */\n spacing?: 'default' | 'middle' | 'small';\n /** Setter kolonne-layout til å være uavhengig av innhold\n * @default false\n */\n fixed?: boolean;\n /** Innholdet i tabellen */\n children: React.ReactNode;\n [key: string]: any;\n};\nexport const Table = React.forwardRef<HTMLTableElement, TableProps>(\n (\n {\n className,\n fixed = false,\n spacing = 'default',\n sortable = false,\n ...rest\n },\n ref,\n ) => {\n return (\n <table\n className={classNames(\n 'eds-table',\n { 'eds-table--fixed': fixed },\n { 'eds-table--middle': spacing === 'middle' },\n { 'eds-table--small': spacing === 'small' },\n { 'eds-table--sortable': sortable },\n className,\n )}\n ref={ref}\n {...rest}\n />\n );\n },\n);\n","import React from 'react';\nimport classNames from 'classnames';\n\nexport type TableHeadProps = {\n /** Kolonneoverskrifter */\n children: React.ReactNode;\n /** Esktra klassenavn */\n className?: string;\n} & React.DetailedHTMLProps<\n React.HTMLAttributes<HTMLTableSectionElement>,\n HTMLTableSectionElement\n>;\n\nexport const TableHead = React.forwardRef<\n HTMLTableSectionElement,\n TableHeadProps\n>(({ className, ...props }, ref) => (\n <thead\n className={classNames('eds-table__head', className)}\n ref={ref}\n {...props}\n />\n));\n","import React from 'react';\nimport classNames from 'classnames';\n\nexport type TableBodyProps = {\n /** Tabellrader */\n children: React.ReactNode;\n /** Ekstra klassenavn */\n className?: string;\n ref?: React.Ref<HTMLTableSectionElement>;\n} & React.DetailedHTMLProps<\n React.HTMLAttributes<HTMLTableSectionElement>,\n HTMLTableSectionElement\n>;\n\nexport const TableBody = React.forwardRef<\n HTMLTableSectionElement,\n TableBodyProps\n>(({ className, ...rest }, ref) => (\n <tbody\n className={classNames('eds-table__body', className)}\n ref={ref}\n {...rest}\n />\n));\n","import React from 'react';\n\nexport type TableFooterProps = {\n /** Tabellrader */\n children: React.ReactNode;\n} & React.DetailedHTMLProps<\n React.HTMLAttributes<HTMLTableSectionElement>,\n HTMLTableSectionElement\n>;\n\nexport const TableFooter = React.forwardRef<\n HTMLTableSectionElement,\n TableFooterProps\n>(({ ...props }, ref) => <tfoot ref={ref} {...props} />);\n","import React from 'react';\nimport classNames from 'classnames';\n\nexport type TableRowProps = {\n /** Tabellceller */\n children: React.ReactNode;\n /** Ekstra klassenavn */\n className?: string;\n /**Hvis satt, så vil tabellraden endre fargen ved hover\n * @default false\n */\n hover?: boolean;\n /** Om raden er klikkbar, så vil raden endre farge, og musepekeren vil symbolisere interaktivitet\n * @default false\n */\n active?: boolean;\n /**Signalisere om at det er en feil i tabellraden\n * @default false\n */\n error?: boolean;\n ref?: React.Ref<HTMLTableRowElement>;\n} & React.DetailedHTMLProps<\n React.HTMLAttributes<HTMLTableRowElement>,\n HTMLTableRowElement\n>;\n\nexport const TableRow = React.forwardRef<HTMLTableRowElement, TableRowProps>(\n (\n { className, hover = false, active = false, error = false, ...rest },\n ref: React.Ref<HTMLTableRowElement>,\n ) => (\n <tr\n className={classNames('eds-table__row', className, {\n 'eds-table__row--hover': hover,\n 'eds-table__row--active': active,\n 'eds-table__row--error': error,\n })}\n ref={ref}\n {...rest}\n />\n ),\n);\n","import React from 'react';\nimport classNames from 'classnames';\n\nexport type DataCellProps = {\n /** Innholdet i tabellcellen */\n children: React.ReactNode;\n /** Ekstra klassenavn */\n className?: string;\n /** Størrelse som settes for DataCell for ulikt innhold av komponenter */\n padding?: 'default' | 'checkbox' | 'radio' | 'overflow-menu';\n /** Viser en status-sirkel for DataCell */\n status?: 'positive' | 'negative' | 'neutral';\n} & React.DetailedHTMLProps<\n React.TdHTMLAttributes<HTMLTableDataCellElement>,\n HTMLTableDataCellElement\n>;\n\nexport const DataCell = React.forwardRef<\n HTMLTableDataCellElement,\n DataCellProps\n>(\n (\n { className, padding = 'default', status = undefined, ...rest },\n ref: React.Ref<HTMLTableDataCellElement>,\n ) => (\n <td\n ref={ref}\n className={classNames('eds-table__data-cell', className, {\n [`eds-table__data-cell--status-${status}`]: status,\n 'eds-table__data-cell--padding-checkbox': padding === 'checkbox',\n 'eds-table__data-cell--padding-radio': padding === 'radio',\n 'eds-table__data-cell--padding-overflow-menu':\n padding === 'overflow-menu',\n })}\n {...rest}\n />\n ),\n);\n","import React from 'react';\nimport classNames from 'classnames';\n\nimport { DownArrowIcon, UpArrowIcon, UnsortedIcon } from '@entur/icons';\n\nimport { ExternalSortConfig } from '.';\n\nimport './HeaderCell.scss';\n\nexport type HeaderCellProps = {\n /** Kolonneoverskrift */\n children: React.ReactNode;\n /** Ekstra klassenavn */\n className?: string;\n /** Størrelse som settes for HeaderCell for ulikt innhold av komponenter */\n padding?: 'default' | 'checkbox' | 'radio' | 'overflow-menu';\n\n /** Ekstra props som kan sendes til sorteringsknappelementet. Benyttes via useSortableTable */\n sortableButtonProps?: React.DetailedHTMLProps<\n React.ButtonHTMLAttributes<HTMLButtonElement>,\n HTMLButtonElement\n >;\n\n /** Om komponenten brukes til sortering. Benytt via useSortableTable\n * @default false\n */\n sortable?: boolean;\n /** Konfigurering og rekkefølgen på sortering. Benyttes via useSortableTable */\n sortConfig?: ExternalSortConfig;\n /** Navnet det skal sorteres på. Benyttes via useSortableTable */\n name?: string;\n} & React.DetailedHTMLProps<\n React.ThHTMLAttributes<HTMLTableCellElement>,\n HTMLTableCellElement\n>;\n\nexport const HeaderCell = React.forwardRef<\n HTMLTableCellElement,\n HeaderCellProps\n>(\n (\n {\n className,\n children,\n name,\n sortable = false,\n sortConfig,\n padding = 'default',\n sortableButtonProps,\n ...rest\n },\n ref,\n ) => {\n const [isCurrentlySorted, setIsCurrentlySorted] =\n React.useState<boolean>(false);\n React.useEffect(() => {\n sortConfig &&\n name &&\n setIsCurrentlySorted(sortConfig && name === sortConfig.key);\n }, [sortConfig, name]);\n const ariaSort = isCurrentlySorted\n ? sortConfig && sortConfig.order\n : 'none';\n\n return (\n <th\n className={classNames('eds-table__header-cell', className, {\n 'eds-table__header-cell--sortable': sortable,\n 'eds-table__header-cell--padding-radio': padding === 'radio',\n 'eds-table__header-cell--padding-checkbox': padding === 'checkbox',\n 'eds-table__header-cell--padding-overflow-menu':\n padding === 'overflow-menu',\n })}\n aria-sort={ariaSort}\n ref={ref}\n {...rest}\n >\n {sortable && sortConfig && sortableButtonProps ? (\n <SortableHeaderCellButton\n sortableButtonProps={sortableButtonProps}\n sortConfig={sortConfig}\n isCurrentlySorted={isCurrentlySorted}\n >\n {children}\n </SortableHeaderCellButton>\n ) : (\n children\n )}\n </th>\n );\n },\n);\n\ntype SortableHeaderCellButtonProps = {\n sortConfig: ExternalSortConfig;\n isCurrentlySorted: boolean;\n sortableButtonProps: React.DetailedHTMLProps<\n React.ButtonHTMLAttributes<HTMLButtonElement>,\n HTMLButtonElement\n >;\n};\n\nconst SortableHeaderCellButton: React.FC<SortableHeaderCellButtonProps> = ({\n sortConfig,\n sortableButtonProps,\n isCurrentlySorted,\n children,\n}) => {\n const { className, ...rest } = sortableButtonProps;\n return (\n <button\n className={classNames('eds-table__header-cell-button', className)}\n type=\"button\"\n {...rest}\n >\n {children}\n {(!isCurrentlySorted || sortConfig.order === 'none') && (\n <UnsortedIcon\n size=\"16px\"\n className=\"eds-table__header-cell-button-icon\"\n aria-label=\"usortert kolonne\"\n />\n )}\n {isCurrentlySorted && sortConfig.order === 'ascending' && (\n <UpArrowIcon\n size=\"16px\"\n className=\"eds-table__header-cell-button-icon\"\n aria-label=\"stigende sortert kolonne\"\n />\n )}\n {isCurrentlySorted && sortConfig.order === 'descending' && (\n <DownArrowIcon\n size=\"16px\"\n className=\"eds-table__header-cell-button-icon\"\n aria-label=\"synkende sortert kolonne\"\n />\n )}\n </button>\n );\n};\n","import React, { useState } from 'react';\nimport { TableBodyProps, TableRowProps } from './index';\n\nfunction onTableKeypress(\n event: React.KeyboardEvent,\n currentRow: number,\n maxRow: number,\n allowWrap?: boolean,\n) {\n const keyPress = event.key;\n switch (keyPress) {\n case 'ArrowUp':\n event.preventDefault();\n if (allowWrap) {\n return currentRow === 0 ? maxRow - 1 : currentRow - 1;\n } else {\n return currentRow > 0 ? currentRow - 1 : 0;\n }\n case 'ArrowDown':\n event.preventDefault();\n if (allowWrap) {\n return currentRow === maxRow - 1 ? 0 : currentRow + 1;\n } else {\n return currentRow < maxRow - 1 ? currentRow + 1 : currentRow;\n }\n default:\n return currentRow;\n }\n}\n\nexport type useTableKeyboardNavigationProps = (\n /** Antall rader i tabellen */\n numberOfRows: number,\n /** Tillate at man kan navigere sirkulært\n * @default false\n */\n allowWrap?: boolean,\n) => {\n getTableRowNavigationProps: (\n /** Raden i tabellen (0-indeksert) */\n row: number,\n ) => Partial<TableRowProps>;\n getTableBodyNavigationProps: () => Partial<TableBodyProps>;\n};\n\nexport const useTableKeyboardNavigation: useTableKeyboardNavigationProps = (\n numberOfRows = 0,\n allowWrap = true,\n) => {\n const [currentRow, setCurrentRow] = useState(numberOfRows);\n const [maxRow, setMaxRow] = useState(0);\n\n const tableBodyRef = React.useRef<HTMLTableSectionElement>(null);\n const tableHasFocus = tableBodyRef?.current?.contains(document.activeElement);\n\n React.useEffect(() => {\n tableBodyRef &&\n tableBodyRef.current &&\n tableHasFocus &&\n tableBodyRef.current.childNodes[\n currentRow\n ].childNodes[0].parentElement?.focus();\n }, [currentRow, tableHasFocus]);\n\n function getTableBodyNavigationProps(...rest: any): Partial<TableBodyProps> {\n return {\n ref: tableBodyRef,\n ...rest,\n };\n }\n\n const tableRowRef = React.useRef<HTMLTableRowElement>(null);\n function getTableRowNavigationProps(\n row: number,\n ...rest: any\n ): Partial<TableRowProps> {\n if (row >= maxRow) {\n setMaxRow(row + 1);\n }\n const tabIndex = currentRow ? 0 : -1;\n return {\n tabIndex,\n ref: tableRowRef,\n onClick: () => setCurrentRow(row),\n onKeyDown: (e: React.KeyboardEvent) => {\n const newCell = onTableKeypress(e, currentRow, numberOfRows, allowWrap);\n setCurrentRow(newCell);\n },\n ...rest,\n };\n }\n return { getTableRowNavigationProps, getTableBodyNavigationProps };\n};\n","import { warnAboutMissingStyles } from '@entur/utils';\nimport './index.scss';\n\nwarnAboutMissingStyles('table');\n\nexport * from './Table';\nexport * from './TableHead';\nexport * from './TableBody';\nexport * from './TableFooter';\nexport * from './TableRow';\nexport * from './DataCell';\nexport * from './HeaderCell';\nexport * from './useSortableTable';\nexport * from './EditableCell';\nexport * from './ExpandableRow';\nexport * from './ExpandRowButton';\nexport * from './useTableKeyboardNavigation';\n","import classNames from 'classnames';\nimport React from 'react';\nimport { DataCell } from './DataCell';\nimport { VariantProvider, VariantType } from '@entur/form';\nimport { Tooltip } from '@entur/tooltip';\nimport './EditableCell.scss';\n\ntype EditableCellProps = {\n /** Ekstra klassenavn */\n className?: string;\n /** Inputelementet som skal være i tabellcellen */\n children: React.ReactElement;\n /** Valideringsvariant for EditableCell */\n variant?: VariantType;\n /** Varselmelding, som vil komme som en Tooltip under EditableCell */\n feedback?: string;\n /** Om cellen skal vise omriss til enhver tid\n * @default false\n */\n outlined?: boolean;\n [key: string]: any;\n};\n\nexport const EditableCell: React.FC<EditableCellProps> = ({\n children,\n className,\n feedback,\n variant,\n outlined = false,\n ...rest\n}) => {\n return (\n <VariantProvider variant={variant}>\n <DataCell\n className={classNames(\n 'eds-editable-cell',\n {\n 'eds-editable-cell--outlined': outlined,\n },\n className,\n )}\n {...rest}\n >\n <Tooltip\n disableHoverListener={!feedback}\n disableFocusListener={!feedback}\n placement=\"bottom\"\n content={feedback || undefined}\n variant={feedback ? 'error' : undefined}\n >\n {children}\n </Tooltip>\n </DataCell>\n </VariantProvider>\n );\n};\n","import React from 'react';\nimport classNames from 'classnames';\nimport { DownArrowIcon } from '@entur/icons';\nimport { IconButton } from '@entur/button';\nimport './ExpandRowButton.scss';\n\nexport type ExpandRowButtonProps = {\n open: boolean;\n onClick: (e: React.MouseEvent) => void;\n} & React.ButtonHTMLAttributes<HTMLButtonElement>;\n\nexport const ExpandRowButton: React.FC<ExpandRowButtonProps> = ({\n open,\n onClick,\n ...rest\n}) => {\n return (\n <IconButton\n className={classNames('eds-expand-row-button', {\n 'eds-expand-row-button--open': open,\n })}\n onClick={onClick}\n aria-label={open ? 'Lukk tabellrad' : 'Utvid tabellrad'}\n {...rest}\n >\n <DownArrowIcon className=\"eds-expand-row-button__icon\" />\n </IconButton>\n );\n};\n","import React from 'react';\nimport { BaseExpand } from '@entur/expand';\n\nexport type ExpandableRowProps = {\n /** Antall kolonner tabellraden er */\n colSpan: number;\n /** Innholdet til ExpandableRow */\n children: React.ReactNode;\n /** Om ExpandableRow er åpen\n * @default false\n */\n open?: boolean;\n};\n\nexport const ExpandableRow: React.FC<ExpandableRowProps> = ({\n open = false,\n children,\n colSpan,\n}) => {\n return (\n <tr>\n <td colSpan={colSpan}>\n <BaseExpand open={open}>{children}</BaseExpand>\n </td>\n </tr>\n );\n};\n","import React from 'react';\nimport get from 'lodash.get';\n\nexport type ExternalSortConfig = {\n /**\n * @default \"\"\n */\n key: string;\n /** @default \"none\" */\n order: 'ascending' | 'descending' | 'none';\n};\n\nexport function useSortableData<T>(\n rawData: T[],\n externalSortConfig: ExternalSortConfig = { key: '', order: 'none' },\n): {\n sortedData: T[];\n getSortableHeaderProps: (\n args: SortableHeaderProps,\n ) => SortableHeaderReturnProps;\n getSortableTableProps: (args: SortableTableProps) => SortableTableReturnProps;\n} {\n const [sortConfig, setSortConfig] = React.useState(externalSortConfig);\n const tableCopy = rawData.slice();\n\n React.useEffect(() => {\n setSortConfig({\n key: externalSortConfig.key,\n order: externalSortConfig.order,\n });\n }, [externalSortConfig.key, externalSortConfig.order]);\n\n const sortedData: T[] = React.useMemo(() => {\n if (sortConfig.order === 'none') {\n return tableCopy;\n }\n return [...rawData].sort((a: any, b: any) => {\n if (get(a, sortConfig.key) < get(b, sortConfig.key)) {\n return sortConfig.order === 'ascending' ? -1 : 1;\n } else if (get(a, sortConfig.key) > get(b, sortConfig.key)) {\n return sortConfig.order === 'ascending' ? 1 : -1;\n } else {\n return 0;\n }\n });\n }, [rawData, tableCopy, sortConfig]);\n\n const onSortRequested = (key: string) => {\n let order: 'ascending' | 'descending' | 'none' = 'ascending';\n if (sortConfig.key === key && sortConfig.order === 'ascending') {\n order = 'descending';\n } else if (sortConfig.key === key && sortConfig.order === 'descending') {\n order = 'none';\n }\n\n setSortConfig({ key, order });\n };\n\n function getSortableHeaderProps({\n name,\n sortable = true,\n buttonProps,\n ...props\n }: SortableHeaderProps): SortableHeaderReturnProps {\n return {\n name,\n sortable,\n sortConfig: sortConfig,\n sortableButtonProps: {\n onClick: () => onSortRequested(name),\n ...buttonProps,\n },\n ...props,\n };\n }\n\n function getSortableTableProps({\n sortable = true,\n ...props\n }: SortableTableProps): SortableTableReturnProps {\n return {\n sortable,\n sortConfig: sortConfig,\n ...props,\n };\n }\n\n return { sortedData, getSortableHeaderProps, getSortableTableProps };\n}\n\nexport type SortableHeaderProps = {\n /** Navnet headeren skal se etter i forhold til sortering av items */\n name: string;\n /** Om headeren skal være sorterbar eller ikke\n * @default true */\n sortable?: boolean;\n /** Props som sendes til knapp-elementet */\n buttonProps?: Omit<\n React.DetailedHTMLProps<\n React.ButtonHTMLAttributes<HTMLButtonElement>,\n HTMLButtonElement\n >,\n 'type' | 'onClick'\n >;\n [key: string]: any;\n};\n\nexport type SortableHeaderReturnProps = {\n name: string;\n sortable: boolean;\n sortConfig: ExternalSortConfig;\n [key: string]: any;\n};\n\nexport type SortableTableProps = {\n /** @default true */\n sortable?: boolean;\n [key: string]: any;\n};\n\nexport type SortableTableReturnProps = {\n /** @default true */\n sortable?: boolean;\n sortConfig: ExternalSortConfig;\n [key: string]: any;\n};\n"],"names":["Table","React","forwardRef","ref","className","_ref$fixed","fixed","_ref$spacing","spacing","_ref$sortable","sortable","rest","classNames","TableHead","props","TableBody","TableFooter","TableRow","_ref$hover","hover","_ref$active","active","_ref$error","error","DataCell","_ref$padding","padding","_ref$status","status","undefined","HeaderCell","children","name","sortConfig","sortableButtonProps","useState","isCurrentlySorted","setIsCurrentlySorted","useEffect","key","ariaSort","order","SortableHeaderCellButton","type","UnsortedIcon","size","UpArrowIcon","DownArrowIcon","onTableKeypress","event","currentRow","maxRow","allowWrap","preventDefault","warnAboutMissingStyles","feedback","variant","_ref$outlined","outlined","VariantProvider","Tooltip","disableHoverListener","disableFocusListener","placement","content","open","onClick","IconButton","colSpan","BaseExpand","rawData","externalSortConfig","setSortConfig","tableCopy","slice","sortedData","useMemo","sort","a","b","get","getSortableHeaderProps","buttonProps","getSortableTableProps","numberOfRows","setCurrentRow","setMaxRow","tableBodyRef","useRef","tableHasFocus","current","_tableBodyRef$current","contains","document","activeElement","childNodes","parentElement","_tableBodyRef$current2","focus","tableRowRef","getTableRowNavigationProps","row","tabIndex","onKeyDown","e","newCell","getTableBodyNavigationProps"],"mappings":"gxBAkBaA,EAAQC,UAAMC,YACzB,WAQEC,OANEC,IAAAA,UAASC,IACTC,MAAAA,gBAAaC,IACbC,QAAAA,aAAU,YAASC,IACnBC,SAAAA,gBACGC,SAIL,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production.min.js","sources":["../src/Table.tsx","../src/TableHead.tsx","../src/TableBody.tsx","../src/TableFooter.tsx","../src/TableRow.tsx","../src/DataCell.tsx","../src/HeaderCell.tsx","../src/useTableKeyboardNavigation.tsx","../src/index.tsx","../src/EditableCell.tsx","../src/ExpandRowButton.tsx","../src/ExpandableRow.tsx","../src/useSortableTable.ts"],"sourcesContent":["import React from 'react';\nimport classNames from 'classnames';\n\nexport type TableProps = {\n /** Ekstra klassenavn */\n className?: string;\n /** Setter tettheten mellom rader og kolonner. Bruk gjerne middle og small for for sider med høy informasjonstetthet\n * @default \"default\"\n */\n spacing?: 'default' | 'middle' | 'small';\n /** Setter kolonne-layout til å være uavhengig av innhold\n * @default false\n */\n fixed?: boolean;\n /** Innholdet i tabellen */\n children: React.ReactNode;\n [key: string]: any;\n};\nexport const Table = React.forwardRef<HTMLTableElement, TableProps>(\n (\n {\n className,\n fixed = false,\n spacing = 'default',\n sortable = false,\n ...rest\n },\n ref,\n ) => {\n return (\n <table\n className={classNames(\n 'eds-table',\n { 'eds-table--fixed': fixed },\n { 'eds-table--middle': spacing === 'middle' },\n { 'eds-table--small': spacing === 'small' },\n { 'eds-table--sortable': sortable },\n className,\n )}\n ref={ref}\n {...rest}\n />\n );\n },\n);\n","import React from 'react';\nimport classNames from 'classnames';\n\nexport type TableHeadProps = {\n /** Kolonneoverskrifter */\n children: React.ReactNode;\n /** Esktra klassenavn */\n className?: string;\n} & React.DetailedHTMLProps<\n React.HTMLAttributes<HTMLTableSectionElement>,\n HTMLTableSectionElement\n>;\n\nexport const TableHead = React.forwardRef<\n HTMLTableSectionElement,\n TableHeadProps\n>(({ className, ...props }, ref) => (\n <thead\n className={classNames('eds-table__head', className)}\n ref={ref}\n {...props}\n />\n));\n","import React from 'react';\nimport classNames from 'classnames';\n\nexport type TableBodyProps = {\n /** Tabellrader */\n children: React.ReactNode;\n /** Ekstra klassenavn */\n className?: string;\n ref?: React.Ref<HTMLTableSectionElement>;\n} & React.DetailedHTMLProps<\n React.HTMLAttributes<HTMLTableSectionElement>,\n HTMLTableSectionElement\n>;\n\nexport const TableBody = React.forwardRef<\n HTMLTableSectionElement,\n TableBodyProps\n>(({ className, ...rest }, ref) => (\n <tbody\n className={classNames('eds-table__body', className)}\n ref={ref}\n {...rest}\n />\n));\n","import React from 'react';\n\nexport type TableFooterProps = {\n /** Tabellrader */\n children: React.ReactNode;\n} & React.DetailedHTMLProps<\n React.HTMLAttributes<HTMLTableSectionElement>,\n HTMLTableSectionElement\n>;\n\nexport const TableFooter = React.forwardRef<\n HTMLTableSectionElement,\n TableFooterProps\n>(({ ...props }, ref) => <tfoot ref={ref} {...props} />);\n","import React from 'react';\nimport classNames from 'classnames';\n\nexport type TableRowProps = {\n /** Tabellceller */\n children: React.ReactNode;\n /** Ekstra klassenavn */\n className?: string;\n /**Hvis satt, så vil tabellraden endre fargen ved hover\n * @default false\n */\n hover?: boolean;\n /** Om raden er klikkbar, så vil raden endre farge, og musepekeren vil symbolisere interaktivitet\n * @default false\n */\n active?: boolean;\n /**Signalisere om at det er en feil i tabellraden\n * @default false\n */\n error?: boolean;\n ref?: React.Ref<HTMLTableRowElement>;\n} & React.DetailedHTMLProps<\n React.HTMLAttributes<HTMLTableRowElement>,\n HTMLTableRowElement\n>;\n\nexport const TableRow = React.forwardRef<HTMLTableRowElement, TableRowProps>(\n (\n { className, hover = false, active = false, error = false, ...rest },\n ref: React.Ref<HTMLTableRowElement>,\n ) => (\n <tr\n className={classNames('eds-table__row', className, {\n 'eds-table__row--hover': hover,\n 'eds-table__row--active': active,\n 'eds-table__row--error': error,\n })}\n ref={ref}\n {...rest}\n />\n ),\n);\n","import React from 'react';\nimport classNames from 'classnames';\n\nexport type DataCellProps = {\n /** Innholdet i tabellcellen */\n children: React.ReactNode;\n /** Ekstra klassenavn */\n className?: string;\n /** Størrelse som settes for DataCell for ulikt innhold av komponenter */\n padding?: 'default' | 'checkbox' | 'radio' | 'overflow-menu';\n /** Viser en status-sirkel for DataCell */\n status?: 'positive' | 'negative' | 'neutral';\n} & React.DetailedHTMLProps<\n React.TdHTMLAttributes<HTMLTableDataCellElement>,\n HTMLTableDataCellElement\n>;\n\nexport const DataCell = React.forwardRef<\n HTMLTableDataCellElement,\n DataCellProps\n>(\n (\n { className, padding = 'default', status = undefined, ...rest },\n ref: React.Ref<HTMLTableDataCellElement>,\n ) => (\n <td\n ref={ref}\n className={classNames('eds-table__data-cell', className, {\n [`eds-table__data-cell--status-${status}`]: status,\n 'eds-table__data-cell--padding-checkbox': padding === 'checkbox',\n 'eds-table__data-cell--padding-radio': padding === 'radio',\n 'eds-table__data-cell--padding-overflow-menu':\n padding === 'overflow-menu',\n })}\n {...rest}\n />\n ),\n);\n","import React from 'react';\nimport classNames from 'classnames';\n\nimport { DownArrowIcon, UpArrowIcon, UnsortedIcon } from '@entur/icons';\n\nimport { ExternalSortConfig } from '.';\n\nimport './HeaderCell.scss';\n\nexport type HeaderCellProps = {\n /** Kolonneoverskrift */\n children: React.ReactNode;\n /** Ekstra klassenavn */\n className?: string;\n /** Størrelse som settes for HeaderCell for ulikt innhold av komponenter */\n padding?: 'default' | 'checkbox' | 'radio' | 'overflow-menu';\n\n /** Ekstra props som kan sendes til sorteringsknappelementet. Benyttes via useSortableTable */\n sortableButtonProps?: React.DetailedHTMLProps<\n React.ButtonHTMLAttributes<HTMLButtonElement>,\n HTMLButtonElement\n >;\n\n /** Om komponenten brukes til sortering. Benytt via useSortableTable\n * @default false\n */\n sortable?: boolean;\n /** Konfigurering og rekkefølgen på sortering. Benyttes via useSortableTable */\n sortConfig?: ExternalSortConfig;\n /** Navnet det skal sorteres på. Benyttes via useSortableTable */\n name?: string;\n} & React.DetailedHTMLProps<\n React.ThHTMLAttributes<HTMLTableCellElement>,\n HTMLTableCellElement\n>;\n\nexport const HeaderCell = React.forwardRef<\n HTMLTableCellElement,\n HeaderCellProps\n>(\n (\n {\n className,\n children,\n name,\n sortable = false,\n sortConfig,\n padding = 'default',\n sortableButtonProps,\n ...rest\n },\n ref,\n ) => {\n const [isCurrentlySorted, setIsCurrentlySorted] =\n React.useState<boolean>(false);\n React.useEffect(() => {\n sortConfig &&\n name &&\n setIsCurrentlySorted(sortConfig && name === sortConfig.key);\n }, [sortConfig, name]);\n const ariaSort = isCurrentlySorted\n ? sortConfig && sortConfig.order\n : 'none';\n\n return (\n <th\n className={classNames('eds-table__header-cell', className, {\n 'eds-table__header-cell--sortable': sortable,\n 'eds-table__header-cell--padding-radio': padding === 'radio',\n 'eds-table__header-cell--padding-checkbox': padding === 'checkbox',\n 'eds-table__header-cell--padding-overflow-menu':\n padding === 'overflow-menu',\n })}\n aria-sort={ariaSort}\n ref={ref}\n {...rest}\n >\n {sortable && sortConfig && sortableButtonProps ? (\n <SortableHeaderCellButton\n sortableButtonProps={sortableButtonProps}\n sortConfig={sortConfig}\n isCurrentlySorted={isCurrentlySorted}\n >\n {children}\n </SortableHeaderCellButton>\n ) : (\n children\n )}\n </th>\n );\n },\n);\n\ntype SortableHeaderCellButtonProps = {\n sortConfig: ExternalSortConfig;\n isCurrentlySorted: boolean;\n sortableButtonProps: React.DetailedHTMLProps<\n React.ButtonHTMLAttributes<HTMLButtonElement>,\n HTMLButtonElement\n >;\n};\n\nconst SortableHeaderCellButton: React.FC<SortableHeaderCellButtonProps> = ({\n sortConfig,\n sortableButtonProps,\n isCurrentlySorted,\n children,\n}) => {\n const { className, ...rest } = sortableButtonProps;\n return (\n <button\n className={classNames('eds-table__header-cell-button', className)}\n type=\"button\"\n {...rest}\n >\n {children}\n {(!isCurrentlySorted || sortConfig.order === 'none') && (\n <UnsortedIcon\n size=\"16px\"\n className=\"eds-table__header-cell-button-icon\"\n aria-label=\"usortert kolonne\"\n />\n )}\n {isCurrentlySorted && sortConfig.order === 'ascending' && (\n <UpArrowIcon\n size=\"16px\"\n className=\"eds-table__header-cell-button-icon\"\n aria-label=\"stigende sortert kolonne\"\n />\n )}\n {isCurrentlySorted && sortConfig.order === 'descending' && (\n <DownArrowIcon\n size=\"16px\"\n className=\"eds-table__header-cell-button-icon\"\n aria-label=\"synkende sortert kolonne\"\n />\n )}\n </button>\n );\n};\n","import React, { useState } from 'react';\nimport { TableBodyProps, TableRowProps } from './index';\n\nfunction onTableKeypress(\n event: React.KeyboardEvent,\n currentRow: number,\n maxRow: number,\n allowWrap?: boolean,\n) {\n const keyPress = event.key;\n switch (keyPress) {\n case 'ArrowUp':\n event.preventDefault();\n if (allowWrap) {\n return currentRow === 0 ? maxRow - 1 : currentRow - 1;\n } else {\n return currentRow > 0 ? currentRow - 1 : 0;\n }\n case 'ArrowDown':\n event.preventDefault();\n if (allowWrap) {\n return currentRow === maxRow - 1 ? 0 : currentRow + 1;\n } else {\n return currentRow < maxRow - 1 ? currentRow + 1 : currentRow;\n }\n default:\n return currentRow;\n }\n}\n\nexport type useTableKeyboardNavigationProps = (\n /** Antall rader i tabellen */\n numberOfRows: number,\n /** Tillate at man kan navigere sirkulært\n * @default false\n */\n allowWrap?: boolean,\n) => {\n getTableRowNavigationProps: (\n /** Raden i tabellen (0-indeksert) */\n row: number,\n ) => Partial<TableRowProps>;\n getTableBodyNavigationProps: () => Partial<TableBodyProps>;\n};\n\nexport const useTableKeyboardNavigation: useTableKeyboardNavigationProps = (\n numberOfRows = 0,\n allowWrap = true,\n) => {\n const [currentRow, setCurrentRow] = useState(numberOfRows);\n const [maxRow, setMaxRow] = useState(0);\n\n const tableBodyRef = React.useRef<HTMLTableSectionElement>(null);\n const tableHasFocus = tableBodyRef?.current?.contains(document.activeElement);\n\n React.useEffect(() => {\n tableBodyRef &&\n tableBodyRef.current &&\n tableHasFocus &&\n tableBodyRef.current.childNodes[\n currentRow\n ].childNodes[0].parentElement?.focus();\n }, [currentRow, tableHasFocus]);\n\n function getTableBodyNavigationProps(...rest: any): Partial<TableBodyProps> {\n return {\n ref: tableBodyRef,\n ...rest,\n };\n }\n\n const tableRowRef = React.useRef<HTMLTableRowElement>(null);\n function getTableRowNavigationProps(\n row: number,\n ...rest: any\n ): Partial<TableRowProps> {\n if (row >= maxRow) {\n setMaxRow(row + 1);\n }\n const tabIndex = currentRow ? 0 : -1;\n return {\n tabIndex,\n ref: tableRowRef,\n onClick: () => setCurrentRow(row),\n onKeyDown: (e: React.KeyboardEvent) => {\n const newCell = onTableKeypress(e, currentRow, numberOfRows, allowWrap);\n setCurrentRow(newCell);\n },\n ...rest,\n };\n }\n return { getTableRowNavigationProps, getTableBodyNavigationProps };\n};\n","import { warnAboutMissingStyles } from '@entur/utils';\nimport './index.scss';\n\nwarnAboutMissingStyles('table');\n\nexport * from './Table';\nexport * from './TableHead';\nexport * from './TableBody';\nexport * from './TableFooter';\nexport * from './TableRow';\nexport * from './DataCell';\nexport * from './HeaderCell';\nexport * from './useSortableTable';\nexport * from './EditableCell';\nexport * from './ExpandableRow';\nexport * from './ExpandRowButton';\nexport * from './useTableKeyboardNavigation';\n","import classNames from 'classnames';\nimport React from 'react';\nimport { DataCell } from './DataCell';\nimport { VariantProvider, VariantType } from '@entur/form';\nimport { Tooltip } from '@entur/tooltip';\nimport './EditableCell.scss';\n\ntype EditableCellProps = {\n /** Ekstra klassenavn */\n className?: string;\n /** Inputelementet som skal være i tabellcellen */\n children: React.ReactElement;\n /** Valideringsvariant for EditableCell */\n variant?: VariantType;\n /** Varselmelding, som vil komme som en Tooltip under EditableCell */\n feedback?: string;\n /** Om cellen skal vise omriss til enhver tid\n * @default false\n */\n outlined?: boolean;\n [key: string]: any;\n};\n\nexport const EditableCell: React.FC<EditableCellProps> = ({\n children,\n className,\n feedback,\n variant,\n outlined = false,\n ...rest\n}) => {\n return (\n <VariantProvider variant={variant}>\n <DataCell\n className={classNames(\n 'eds-editable-cell',\n {\n 'eds-editable-cell--outlined': outlined,\n },\n className,\n )}\n {...rest}\n >\n <Tooltip\n disableHoverListener={!feedback}\n disableFocusListener={!feedback}\n placement=\"bottom\"\n content={feedback || undefined}\n variant={feedback ? 'error' : undefined}\n >\n {children}\n </Tooltip>\n </DataCell>\n </VariantProvider>\n );\n};\n","import React from 'react';\nimport classNames from 'classnames';\nimport { DownArrowIcon } from '@entur/icons';\nimport { IconButton } from '@entur/button';\nimport './ExpandRowButton.scss';\n\nexport type ExpandRowButtonProps = {\n open: boolean;\n onClick: (e: React.MouseEvent) => void;\n} & React.ButtonHTMLAttributes<HTMLButtonElement>;\n\nexport const ExpandRowButton: React.FC<ExpandRowButtonProps> = ({\n open,\n onClick,\n ...rest\n}) => {\n return (\n <IconButton\n className={classNames('eds-expand-row-button', {\n 'eds-expand-row-button--open': open,\n })}\n onClick={onClick}\n aria-label={open ? 'Lukk tabellrad' : 'Utvid tabellrad'}\n {...rest}\n >\n <DownArrowIcon className=\"eds-expand-row-button__icon\" />\n </IconButton>\n );\n};\n","import React from 'react';\nimport { BaseExpand } from '@entur/expand';\n\nexport type ExpandableRowProps = {\n /** Antall kolonner tabellraden er */\n colSpan: number;\n /** Innholdet til ExpandableRow */\n children: React.ReactNode;\n /** Om ExpandableRow er åpen\n * @default false\n */\n open?: boolean;\n};\n\nexport const ExpandableRow: React.FC<ExpandableRowProps> = ({\n open = false,\n children,\n colSpan,\n}) => {\n return (\n <tr>\n <td colSpan={colSpan}>\n <BaseExpand open={open}>{children}</BaseExpand>\n </td>\n </tr>\n );\n};\n","import React from 'react';\nimport get from 'lodash.get';\n\nexport type ExternalSortConfig = {\n /**\n * @default \"\"\n */\n key: string;\n /** @default \"none\" */\n order: 'ascending' | 'descending' | 'none';\n};\n\nexport function useSortableData<T>(\n rawData: T[],\n externalSortConfig: ExternalSortConfig = { key: '', order: 'none' },\n): {\n sortedData: T[];\n getSortableHeaderProps: (\n args: SortableHeaderProps,\n ) => SortableHeaderReturnProps;\n getSortableTableProps: (args: SortableTableProps) => SortableTableReturnProps;\n} {\n const [sortConfig, setSortConfig] = React.useState(externalSortConfig);\n const tableCopy = rawData.slice();\n\n React.useEffect(() => {\n setSortConfig({\n key: externalSortConfig.key,\n order: externalSortConfig.order,\n });\n }, [externalSortConfig.key, externalSortConfig.order]);\n\n const sortedData: T[] = React.useMemo(() => {\n if (sortConfig.order === 'none') {\n return tableCopy;\n }\n return [...rawData].sort((a: any, b: any) => {\n if (get(a, sortConfig.key) < get(b, sortConfig.key)) {\n return sortConfig.order === 'ascending' ? -1 : 1;\n } else if (get(a, sortConfig.key) > get(b, sortConfig.key)) {\n return sortConfig.order === 'ascending' ? 1 : -1;\n } else {\n return 0;\n }\n });\n }, [rawData, tableCopy, sortConfig]);\n\n const onSortRequested = (key: string) => {\n let order: 'ascending' | 'descending' | 'none' = 'ascending';\n if (sortConfig.key === key && sortConfig.order === 'ascending') {\n order = 'descending';\n } else if (sortConfig.key === key && sortConfig.order === 'descending') {\n order = 'none';\n }\n\n setSortConfig({ key, order });\n };\n\n function getSortableHeaderProps({\n name,\n sortable = true,\n buttonProps,\n ...props\n }: SortableHeaderProps): SortableHeaderReturnProps {\n return {\n name,\n sortable,\n sortConfig: sortConfig,\n sortableButtonProps: {\n onClick: () => onSortRequested(name),\n ...buttonProps,\n },\n ...props,\n };\n }\n\n function getSortableTableProps({\n sortable = true,\n ...props\n }: SortableTableProps): SortableTableReturnProps {\n return {\n sortable,\n sortConfig: sortConfig,\n ...props,\n };\n }\n\n return { sortedData, getSortableHeaderProps, getSortableTableProps };\n}\n\nexport type SortableHeaderProps = {\n /** Navnet headeren skal se etter i forhold til sortering av items */\n name: string;\n /** Om headeren skal være sorterbar eller ikke\n * @default true */\n sortable?: boolean;\n /** Props som sendes til knapp-elementet */\n buttonProps?: Omit<\n React.DetailedHTMLProps<\n React.ButtonHTMLAttributes<HTMLButtonElement>,\n HTMLButtonElement\n >,\n 'type' | 'onClick'\n >;\n [key: string]: any;\n};\n\nexport type SortableHeaderReturnProps = {\n name: string;\n sortable: boolean;\n sortConfig: ExternalSortConfig;\n [key: string]: any;\n};\n\nexport type SortableTableProps = {\n /** @default true */\n sortable?: boolean;\n [key: string]: any;\n};\n\nexport type SortableTableReturnProps = {\n /** @default true */\n sortable?: boolean;\n sortConfig: ExternalSortConfig;\n [key: string]: any;\n};\n"],"names":["Table","React","forwardRef","ref","className","fixed","spacing","sortable","rest","classNames","TableHead","props","TableBody","TableFooter","TableRow","hover","active","error","DataCell","padding","status","undefined","HeaderCell","children","name","sortConfig","sortableButtonProps","useState","isCurrentlySorted","setIsCurrentlySorted","useEffect","key","ariaSort","order","SortableHeaderCellButton","type","UnsortedIcon","size","UpArrowIcon","DownArrowIcon","onTableKeypress","event","currentRow","maxRow","allowWrap","preventDefault","warnAboutMissingStyles","feedback","variant","outlined","VariantProvider","Tooltip","disableHoverListener","disableFocusListener","placement","content","open","onClick","IconButton","colSpan","BaseExpand","rawData","externalSortConfig","setSortConfig","tableCopy","slice","sortedData","useMemo","sort","a","b","get","getSortableHeaderProps","buttonProps","getSortableTableProps","numberOfRows","setCurrentRow","setMaxRow","tableBodyRef","useRef","tableHasFocus","current","_tableBodyRef$current","contains","document","activeElement","childNodes","parentElement","_tableBodyRef$current2","focus","tableRowRef","getTableRowNavigationProps","row","tabIndex","onKeyDown","e","newCell","getTableBodyNavigationProps"],"mappings":"gxBAkBaA,EAAQC,UAAMC,YACzB,WAQEC,OANEC,IAAAA,cACAC,MAAAA,oBACAC,QAAAA,aAAU,gBACVC,SAAAA,gBACGC,gBAKHP,mCACEG,UAAWK,UACT,YACA,oBAAsBJ,GACtB,qBAAmC,WAAZC,GACvB,oBAAkC,UAAZA,GACtB,uBAAyBC,GACzBH,GAEFD,IAAKA,GACDK,uBC3BCE,EAAYT,UAAMC,YAG7B,WAA0BC,OAAvBC,IAAAA,UAAcO,gBACjBV,mCACEG,UAAWK,UAAW,kBAAmBL,GACzCD,IAAKA,GACDQ,uBCNKC,EAAYX,UAAMC,YAG7B,WAAyBC,OAAtBC,IAAAA,UAAcI,gBACjBP,mCACEG,UAAWK,UAAW,kBAAmBL,GACzCD,IAAKA,GACDK,OCXKK,EAAcZ,UAAMC,YAG/B,WAAeC,OAATQ,iBAAiBV,mCAAOE,IAAKA,GAASQ,gDCajCG,EAAWb,UAAMC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lBPC,GAGIA,GAAOjD,GACTkC,EAAUe,EAAM,WAEZC,EAAWnD,EAAa,GAAK,qBALhClC,mCAAAA,8BAODqF,SAAAA,EACA1F,IAAKuF,EACLjC,QAAS,kBAAMmB,EAAcgB,IAC7BE,UAAW,SAACC,OACJC,EAAUxD,EAAgBuD,EAAGrD,EAAYiC,EAAc/B,GAC7DgC,EAAcoB,KAEbxF,IAG8ByF,kEA3BGzF,2BAAAA,4BAEpCL,IAAK2E,GACFtE"}
|
package/dist/table.esm.js
CHANGED
|
@@ -12,42 +12,46 @@ function _extends() {
|
|
|
12
12
|
_extends = Object.assign || function (target) {
|
|
13
13
|
for (var i = 1; i < arguments.length; i++) {
|
|
14
14
|
var source = arguments[i];
|
|
15
|
+
|
|
15
16
|
for (var key in source) {
|
|
16
17
|
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
17
18
|
target[key] = source[key];
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
21
|
}
|
|
22
|
+
|
|
21
23
|
return target;
|
|
22
24
|
};
|
|
25
|
+
|
|
23
26
|
return _extends.apply(this, arguments);
|
|
24
27
|
}
|
|
25
|
-
|
|
26
|
-
if (obj == null) throw new TypeError("Cannot destructure undefined");
|
|
27
|
-
}
|
|
28
|
+
|
|
28
29
|
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
29
30
|
if (source == null) return {};
|
|
30
31
|
var target = {};
|
|
31
32
|
var sourceKeys = Object.keys(source);
|
|
32
33
|
var key, i;
|
|
34
|
+
|
|
33
35
|
for (i = 0; i < sourceKeys.length; i++) {
|
|
34
36
|
key = sourceKeys[i];
|
|
35
37
|
if (excluded.indexOf(key) >= 0) continue;
|
|
36
38
|
target[key] = source[key];
|
|
37
39
|
}
|
|
40
|
+
|
|
38
41
|
return target;
|
|
39
42
|
}
|
|
40
43
|
|
|
41
44
|
var _excluded$8 = ["className", "fixed", "spacing", "sortable"];
|
|
42
45
|
var Table = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
43
46
|
var className = _ref.className,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
_ref$fixed = _ref.fixed,
|
|
48
|
+
fixed = _ref$fixed === void 0 ? false : _ref$fixed,
|
|
49
|
+
_ref$spacing = _ref.spacing,
|
|
50
|
+
spacing = _ref$spacing === void 0 ? 'default' : _ref$spacing,
|
|
51
|
+
_ref$sortable = _ref.sortable,
|
|
52
|
+
sortable = _ref$sortable === void 0 ? false : _ref$sortable,
|
|
53
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded$8);
|
|
54
|
+
|
|
51
55
|
return React.createElement("table", _extends({
|
|
52
56
|
className: classNames('eds-table', {
|
|
53
57
|
'eds-table--fixed': fixed
|
|
@@ -65,7 +69,8 @@ var Table = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
65
69
|
var _excluded$7 = ["className"];
|
|
66
70
|
var TableHead = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
67
71
|
var className = _ref.className,
|
|
68
|
-
|
|
72
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded$7);
|
|
73
|
+
|
|
69
74
|
return React.createElement("thead", _extends({
|
|
70
75
|
className: classNames('eds-table__head', className),
|
|
71
76
|
ref: ref
|
|
@@ -75,7 +80,8 @@ var TableHead = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
75
80
|
var _excluded$6 = ["className"];
|
|
76
81
|
var TableBody = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
77
82
|
var className = _ref.className,
|
|
78
|
-
|
|
83
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded$6);
|
|
84
|
+
|
|
79
85
|
return React.createElement("tbody", _extends({
|
|
80
86
|
className: classNames('eds-table__body', className),
|
|
81
87
|
ref: ref
|
|
@@ -83,7 +89,8 @@ var TableBody = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
83
89
|
});
|
|
84
90
|
|
|
85
91
|
var TableFooter = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
86
|
-
var props = _extends({},
|
|
92
|
+
var props = _extends({}, _ref);
|
|
93
|
+
|
|
87
94
|
return React.createElement("tfoot", _extends({
|
|
88
95
|
ref: ref
|
|
89
96
|
}, props));
|
|
@@ -92,13 +99,14 @@ var TableFooter = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
92
99
|
var _excluded$5 = ["className", "hover", "active", "error"];
|
|
93
100
|
var TableRow = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
94
101
|
var className = _ref.className,
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
+
_ref$hover = _ref.hover,
|
|
103
|
+
hover = _ref$hover === void 0 ? false : _ref$hover,
|
|
104
|
+
_ref$active = _ref.active,
|
|
105
|
+
active = _ref$active === void 0 ? false : _ref$active,
|
|
106
|
+
_ref$error = _ref.error,
|
|
107
|
+
error = _ref$error === void 0 ? false : _ref$error,
|
|
108
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded$5);
|
|
109
|
+
|
|
102
110
|
return React.createElement("tr", _extends({
|
|
103
111
|
className: classNames('eds-table__row', className, {
|
|
104
112
|
'eds-table__row--hover': hover,
|
|
@@ -112,12 +120,14 @@ var TableRow = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
112
120
|
var _excluded$4 = ["className", "padding", "status"];
|
|
113
121
|
var DataCell = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
114
122
|
var _classNames;
|
|
123
|
+
|
|
115
124
|
var className = _ref.className,
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
125
|
+
_ref$padding = _ref.padding,
|
|
126
|
+
padding = _ref$padding === void 0 ? 'default' : _ref$padding,
|
|
127
|
+
_ref$status = _ref.status,
|
|
128
|
+
status = _ref$status === void 0 ? undefined : _ref$status,
|
|
129
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded$4);
|
|
130
|
+
|
|
121
131
|
return React.createElement("td", _extends({
|
|
122
132
|
ref: ref,
|
|
123
133
|
className: classNames('eds-table__data-cell', className, (_classNames = {}, _classNames["eds-table__data-cell--status-" + status] = status, _classNames['eds-table__data-cell--padding-checkbox'] = padding === 'checkbox', _classNames['eds-table__data-cell--padding-radio'] = padding === 'radio', _classNames['eds-table__data-cell--padding-overflow-menu'] = padding === 'overflow-menu', _classNames))
|
|
@@ -125,21 +135,23 @@ var DataCell = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
125
135
|
});
|
|
126
136
|
|
|
127
137
|
var _excluded$3 = ["className", "children", "name", "sortable", "sortConfig", "padding", "sortableButtonProps"],
|
|
128
|
-
|
|
138
|
+
_excluded2$1 = ["className"];
|
|
129
139
|
var HeaderCell = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
130
140
|
var className = _ref.className,
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
141
|
+
children = _ref.children,
|
|
142
|
+
name = _ref.name,
|
|
143
|
+
_ref$sortable = _ref.sortable,
|
|
144
|
+
sortable = _ref$sortable === void 0 ? false : _ref$sortable,
|
|
145
|
+
sortConfig = _ref.sortConfig,
|
|
146
|
+
_ref$padding = _ref.padding,
|
|
147
|
+
padding = _ref$padding === void 0 ? 'default' : _ref$padding,
|
|
148
|
+
sortableButtonProps = _ref.sortableButtonProps,
|
|
149
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded$3);
|
|
150
|
+
|
|
140
151
|
var _React$useState = React.useState(false),
|
|
141
|
-
|
|
142
|
-
|
|
152
|
+
isCurrentlySorted = _React$useState[0],
|
|
153
|
+
setIsCurrentlySorted = _React$useState[1];
|
|
154
|
+
|
|
143
155
|
React.useEffect(function () {
|
|
144
156
|
sortConfig && name && setIsCurrentlySorted(sortConfig && name === sortConfig.key);
|
|
145
157
|
}, [sortConfig, name]);
|
|
@@ -159,13 +171,16 @@ var HeaderCell = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
159
171
|
isCurrentlySorted: isCurrentlySorted
|
|
160
172
|
}, children) : children);
|
|
161
173
|
});
|
|
174
|
+
|
|
162
175
|
var SortableHeaderCellButton = function SortableHeaderCellButton(_ref2) {
|
|
163
176
|
var sortConfig = _ref2.sortConfig,
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
177
|
+
sortableButtonProps = _ref2.sortableButtonProps,
|
|
178
|
+
isCurrentlySorted = _ref2.isCurrentlySorted,
|
|
179
|
+
children = _ref2.children;
|
|
180
|
+
|
|
167
181
|
var className = sortableButtonProps.className,
|
|
168
|
-
|
|
182
|
+
rest = _objectWithoutPropertiesLoose(sortableButtonProps, _excluded2$1);
|
|
183
|
+
|
|
169
184
|
return React.createElement("button", _extends({
|
|
170
185
|
className: classNames('eds-table__header-cell-button', className),
|
|
171
186
|
type: "button"
|
|
@@ -185,7 +200,7 @@ var SortableHeaderCellButton = function SortableHeaderCellButton(_ref2) {
|
|
|
185
200
|
};
|
|
186
201
|
|
|
187
202
|
var _excluded$2 = ["name", "sortable", "buttonProps"],
|
|
188
|
-
|
|
203
|
+
_excluded2 = ["sortable"];
|
|
189
204
|
function useSortableData(rawData, externalSortConfig) {
|
|
190
205
|
if (externalSortConfig === void 0) {
|
|
191
206
|
externalSortConfig = {
|
|
@@ -193,9 +208,11 @@ function useSortableData(rawData, externalSortConfig) {
|
|
|
193
208
|
order: 'none'
|
|
194
209
|
};
|
|
195
210
|
}
|
|
211
|
+
|
|
196
212
|
var _React$useState = React.useState(externalSortConfig),
|
|
197
|
-
|
|
198
|
-
|
|
213
|
+
sortConfig = _React$useState[0],
|
|
214
|
+
setSortConfig = _React$useState[1];
|
|
215
|
+
|
|
199
216
|
var tableCopy = rawData.slice();
|
|
200
217
|
React.useEffect(function () {
|
|
201
218
|
setSortConfig({
|
|
@@ -207,6 +224,7 @@ function useSortableData(rawData, externalSortConfig) {
|
|
|
207
224
|
if (sortConfig.order === 'none') {
|
|
208
225
|
return tableCopy;
|
|
209
226
|
}
|
|
227
|
+
|
|
210
228
|
return [].concat(rawData).sort(function (a, b) {
|
|
211
229
|
if (get(a, sortConfig.key) < get(b, sortConfig.key)) {
|
|
212
230
|
return sortConfig.order === 'ascending' ? -1 : 1;
|
|
@@ -217,24 +235,29 @@ function useSortableData(rawData, externalSortConfig) {
|
|
|
217
235
|
}
|
|
218
236
|
});
|
|
219
237
|
}, [rawData, tableCopy, sortConfig]);
|
|
238
|
+
|
|
220
239
|
var onSortRequested = function onSortRequested(key) {
|
|
221
240
|
var order = 'ascending';
|
|
241
|
+
|
|
222
242
|
if (sortConfig.key === key && sortConfig.order === 'ascending') {
|
|
223
243
|
order = 'descending';
|
|
224
244
|
} else if (sortConfig.key === key && sortConfig.order === 'descending') {
|
|
225
245
|
order = 'none';
|
|
226
246
|
}
|
|
247
|
+
|
|
227
248
|
setSortConfig({
|
|
228
249
|
key: key,
|
|
229
250
|
order: order
|
|
230
251
|
});
|
|
231
252
|
};
|
|
253
|
+
|
|
232
254
|
function getSortableHeaderProps(_ref) {
|
|
233
255
|
var name = _ref.name,
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
256
|
+
_ref$sortable = _ref.sortable,
|
|
257
|
+
sortable = _ref$sortable === void 0 ? true : _ref$sortable,
|
|
258
|
+
buttonProps = _ref.buttonProps,
|
|
259
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded$2);
|
|
260
|
+
|
|
238
261
|
return _extends({
|
|
239
262
|
name: name,
|
|
240
263
|
sortable: sortable,
|
|
@@ -246,15 +269,18 @@ function useSortableData(rawData, externalSortConfig) {
|
|
|
246
269
|
}, buttonProps)
|
|
247
270
|
}, props);
|
|
248
271
|
}
|
|
272
|
+
|
|
249
273
|
function getSortableTableProps(_ref2) {
|
|
250
274
|
var _ref2$sortable = _ref2.sortable,
|
|
251
|
-
|
|
252
|
-
|
|
275
|
+
sortable = _ref2$sortable === void 0 ? true : _ref2$sortable,
|
|
276
|
+
props = _objectWithoutPropertiesLoose(_ref2, _excluded2);
|
|
277
|
+
|
|
253
278
|
return _extends({
|
|
254
279
|
sortable: sortable,
|
|
255
280
|
sortConfig: sortConfig
|
|
256
281
|
}, props);
|
|
257
282
|
}
|
|
283
|
+
|
|
258
284
|
return {
|
|
259
285
|
sortedData: sortedData,
|
|
260
286
|
getSortableHeaderProps: getSortableHeaderProps,
|
|
@@ -265,12 +291,13 @@ function useSortableData(rawData, externalSortConfig) {
|
|
|
265
291
|
var _excluded$1 = ["children", "className", "feedback", "variant", "outlined"];
|
|
266
292
|
var EditableCell = function EditableCell(_ref) {
|
|
267
293
|
var children = _ref.children,
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
294
|
+
className = _ref.className,
|
|
295
|
+
feedback = _ref.feedback,
|
|
296
|
+
variant = _ref.variant,
|
|
297
|
+
_ref$outlined = _ref.outlined,
|
|
298
|
+
outlined = _ref$outlined === void 0 ? false : _ref$outlined,
|
|
299
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded$1);
|
|
300
|
+
|
|
274
301
|
return React.createElement(VariantProvider, {
|
|
275
302
|
variant: variant
|
|
276
303
|
}, React.createElement(DataCell, _extends({
|
|
@@ -288,9 +315,9 @@ var EditableCell = function EditableCell(_ref) {
|
|
|
288
315
|
|
|
289
316
|
var ExpandableRow = function ExpandableRow(_ref) {
|
|
290
317
|
var _ref$open = _ref.open,
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
318
|
+
open = _ref$open === void 0 ? false : _ref$open,
|
|
319
|
+
children = _ref.children,
|
|
320
|
+
colSpan = _ref.colSpan;
|
|
294
321
|
return React.createElement("tr", null, React.createElement("td", {
|
|
295
322
|
colSpan: colSpan
|
|
296
323
|
}, React.createElement(BaseExpand, {
|
|
@@ -301,8 +328,9 @@ var ExpandableRow = function ExpandableRow(_ref) {
|
|
|
301
328
|
var _excluded = ["open", "onClick"];
|
|
302
329
|
var ExpandRowButton = function ExpandRowButton(_ref) {
|
|
303
330
|
var open = _ref.open,
|
|
304
|
-
|
|
305
|
-
|
|
331
|
+
onClick = _ref.onClick,
|
|
332
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
333
|
+
|
|
306
334
|
return React.createElement(IconButton, _extends({
|
|
307
335
|
className: classNames('eds-expand-row-button', {
|
|
308
336
|
'eds-expand-row-button--open': open
|
|
@@ -316,62 +344,81 @@ var ExpandRowButton = function ExpandRowButton(_ref) {
|
|
|
316
344
|
|
|
317
345
|
function onTableKeypress(event, currentRow, maxRow, allowWrap) {
|
|
318
346
|
var keyPress = event.key;
|
|
347
|
+
|
|
319
348
|
switch (keyPress) {
|
|
320
349
|
case 'ArrowUp':
|
|
321
350
|
event.preventDefault();
|
|
351
|
+
|
|
322
352
|
if (allowWrap) {
|
|
323
353
|
return currentRow === 0 ? maxRow - 1 : currentRow - 1;
|
|
324
354
|
} else {
|
|
325
355
|
return currentRow > 0 ? currentRow - 1 : 0;
|
|
326
356
|
}
|
|
357
|
+
|
|
327
358
|
case 'ArrowDown':
|
|
328
359
|
event.preventDefault();
|
|
360
|
+
|
|
329
361
|
if (allowWrap) {
|
|
330
362
|
return currentRow === maxRow - 1 ? 0 : currentRow + 1;
|
|
331
363
|
} else {
|
|
332
364
|
return currentRow < maxRow - 1 ? currentRow + 1 : currentRow;
|
|
333
365
|
}
|
|
366
|
+
|
|
334
367
|
default:
|
|
335
368
|
return currentRow;
|
|
336
369
|
}
|
|
337
370
|
}
|
|
371
|
+
|
|
338
372
|
var useTableKeyboardNavigation = function useTableKeyboardNavigation(numberOfRows, allowWrap) {
|
|
339
373
|
var _tableBodyRef$current;
|
|
374
|
+
|
|
340
375
|
if (numberOfRows === void 0) {
|
|
341
376
|
numberOfRows = 0;
|
|
342
377
|
}
|
|
378
|
+
|
|
343
379
|
if (allowWrap === void 0) {
|
|
344
380
|
allowWrap = true;
|
|
345
381
|
}
|
|
382
|
+
|
|
346
383
|
var _useState = useState(numberOfRows),
|
|
347
|
-
|
|
348
|
-
|
|
384
|
+
currentRow = _useState[0],
|
|
385
|
+
setCurrentRow = _useState[1];
|
|
386
|
+
|
|
349
387
|
var _useState2 = useState(0),
|
|
350
|
-
|
|
351
|
-
|
|
388
|
+
maxRow = _useState2[0],
|
|
389
|
+
setMaxRow = _useState2[1];
|
|
390
|
+
|
|
352
391
|
var tableBodyRef = React.useRef(null);
|
|
353
392
|
var tableHasFocus = tableBodyRef == null ? void 0 : (_tableBodyRef$current = tableBodyRef.current) == null ? void 0 : _tableBodyRef$current.contains(document.activeElement);
|
|
354
393
|
React.useEffect(function () {
|
|
355
394
|
var _tableBodyRef$current2;
|
|
395
|
+
|
|
356
396
|
tableBodyRef && tableBodyRef.current && tableHasFocus && ((_tableBodyRef$current2 = tableBodyRef.current.childNodes[currentRow].childNodes[0].parentElement) == null ? void 0 : _tableBodyRef$current2.focus());
|
|
357
397
|
}, [currentRow, tableHasFocus]);
|
|
398
|
+
|
|
358
399
|
function getTableBodyNavigationProps() {
|
|
359
400
|
for (var _len = arguments.length, rest = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
360
401
|
rest[_key] = arguments[_key];
|
|
361
402
|
}
|
|
403
|
+
|
|
362
404
|
return _extends({
|
|
363
405
|
ref: tableBodyRef
|
|
364
406
|
}, rest);
|
|
365
407
|
}
|
|
408
|
+
|
|
366
409
|
var tableRowRef = React.useRef(null);
|
|
410
|
+
|
|
367
411
|
function getTableRowNavigationProps(row) {
|
|
368
412
|
if (row >= maxRow) {
|
|
369
413
|
setMaxRow(row + 1);
|
|
370
414
|
}
|
|
415
|
+
|
|
371
416
|
var tabIndex = currentRow ? 0 : -1;
|
|
417
|
+
|
|
372
418
|
for (var _len2 = arguments.length, rest = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
373
419
|
rest[_key2 - 1] = arguments[_key2];
|
|
374
420
|
}
|
|
421
|
+
|
|
375
422
|
return _extends({
|
|
376
423
|
tabIndex: tabIndex,
|
|
377
424
|
ref: tableRowRef,
|
|
@@ -384,6 +431,7 @@ var useTableKeyboardNavigation = function useTableKeyboardNavigation(numberOfRow
|
|
|
384
431
|
}
|
|
385
432
|
}, rest);
|
|
386
433
|
}
|
|
434
|
+
|
|
387
435
|
return {
|
|
388
436
|
getTableRowNavigationProps: getTableRowNavigationProps,
|
|
389
437
|
getTableBodyNavigationProps: getTableBodyNavigationProps
|