@entur/table 4.3.18 → 4.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/dist/HeaderCell.d.ts +13 -3
- package/dist/TableBody.d.ts +3 -3
- package/dist/TableRow.d.ts +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/styles.css +42 -22
- package/dist/table.cjs.development.js +158 -43
- 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 +130 -17
- package/dist/table.esm.js.map +1 -1
- package/dist/useSortableTable.d.ts +3 -1
- package/dist/useTableKeyboardNavigation.d.ts +14 -0
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table.cjs.development.js","sources":["../src/Table.tsx","../src/TableHead.tsx","../src/TableBody.tsx","../src/TableFooter.tsx","../src/TableRow.tsx","../src/DataCell.tsx","../src/HeaderCell.tsx","../src/useSortableTable.ts","../src/EditableCell.tsx","../src/ExpandableRow.tsx","../src/ExpandRowButton.tsx","../src/index.tsx"],"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 [key: string]: any;\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\ntype 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} & 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';\nimport { DownArrowIcon, UpArrowIcon } from '@entur/icons';\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 [key: string]: any;\n};\n\nexport const HeaderCell = React.forwardRef<\n HTMLTableHeaderCellElement,\n HeaderCellProps\n>(\n (\n {\n className,\n children,\n onClick,\n name,\n sortable = false,\n sortConfig,\n padding = 'default',\n ...rest\n },\n ref,\n ) => {\n const [isCurrentlySorted, setIsCurrentlySorted] =\n React.useState<boolean>(false);\n React.useEffect(() => {\n setIsCurrentlySorted(sortConfig && name === sortConfig.key);\n }, [sortConfig, name]);\n const ariaSort = isCurrentlySorted\n ? sortConfig && sortConfig.order\n : 'none';\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 ? (\n <button\n className=\"eds-table__header-cell-button\"\n type=\"button\"\n onClick={onClick}\n >\n {children}\n {isCurrentlySorted && sortConfig.order === 'ascending' && (\n <UpArrowIcon\n size=\"16px\"\n className=\"eds-table__header-cell-button-icon\"\n />\n )}\n {isCurrentlySorted && sortConfig.order === 'descending' && (\n <DownArrowIcon\n size=\"16px\"\n className=\"eds-table__header-cell-button-icon\"\n />\n )}\n </button>\n ) : (\n children\n )}\n </th>\n );\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 ...props\n }: SortableHeaderProps): SortableHeaderReturnProps {\n return {\n name,\n sortable,\n onClick: () => onSortRequested(name),\n sortConfig: sortConfig,\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 [key: string]: any;\n};\n\nexport type SortableHeaderReturnProps = {\n name: string;\n sortable: boolean;\n onClick: () => void;\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","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 { 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 classNames from 'classnames';\nimport { RightArrowIcon } from '@entur/icons';\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 <button\n className={classNames('eds-expand-row-button', {\n 'eds-expand-row-button--open': open,\n })}\n onClick={onClick}\n {...rest}\n >\n <RightArrowIcon className=\"eds-expand-row-button__icon\" />\n </button>\n );\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';\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","onClick","name","sortConfig","useState","isCurrentlySorted","setIsCurrentlySorted","useEffect","key","ariaSort","order","type","UpArrowIcon","size","DownArrowIcon","useSortableData","rawData","externalSortConfig","setSortConfig","tableCopy","slice","sortedData","useMemo","sort","a","b","get","onSortRequested","getSortableHeaderProps","getSortableTableProps","EditableCell","feedback","variant","outlined","VariantProvider","Tooltip","disableHoverListener","disableFocusListener","placement","content","ExpandableRow","open","colSpan","BaseExpand","ExpandRowButton","RightArrowIcon","warnAboutMissingStyles"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAkBaA,KAAK,gBAAGC,KAAK,CAACC,UAAN,CACnB,gBAQEC,GARF;MAEIC,iBAAAA;wBACAC;MAAAA,gCAAQ;0BACRC;MAAAA,oCAAU;2BACVC;MAAAA,sCAAW;MACRC;;AAIL,SACEP,mBAAA,QAAA;AACEG,IAAAA,SAAS,EAAEK,UAAU,CACnB,WADmB,EAEnB;AAAE,0BAAoBJ;AAAtB,KAFmB,EAGnB;AAAE,2BAAqBC,OAAO,KAAK;AAAnC,KAHmB,EAInB;AAAE,0BAAoBA,OAAO,KAAK;AAAlC,KAJmB,EAKnB;AAAE,6BAAuBC;AAAzB,KALmB,EAMnBH,SANmB;AAQrBD,IAAAA,GAAG,EAAEA;KACDK,KAVN,CADF;AAcD,CAzBkB;;ICLRE,SAAS,gBAAGT,KAAK,CAACC,UAAN,CAGvB,gBAA0BC,GAA1B;AAAA,MAAGC,SAAH,QAAGA,SAA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AxC,eAAAA;MACGhB;;AAEH,SACEP,mBAAA,SAAA;AACEG,IAAAA,SAAS,EAAEK,UAAU,CAAC,uBAAD,EAA0B;AAC7C,qCAA+BuD;AADc,KAA1B;AAGrBxC,IAAAA,OAAO,EAAEA;KACLhB,KALN,EAOEP,mBAAA,CAACmE,oBAAD;AAAgBhE,IAAAA,SAAS,EAAC;GAA1B,CAPF,CADF;AAWD,CAhBM;;ACPPiE,4BAAsB,CAAC,OAAD,CAAtB;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"table.cjs.development.js","sources":["../src/Table.tsx","../src/TableHead.tsx","../src/TableBody.tsx","../src/TableFooter.tsx","../src/TableRow.tsx","../src/DataCell.tsx","../src/HeaderCell.tsx","../src/useSortableTable.ts","../src/EditableCell.tsx","../src/ExpandableRow.tsx","../src/ExpandRowButton.tsx","../src/useTableKeyboardNavigation.tsx","../src/index.tsx"],"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';\nimport { DownArrowIcon, UpArrowIcon } from '@entur/icons';\nimport './HeaderCell.scss';\nimport { ExternalSortConfig } from '.';\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 === 'ascending' && (\n <UpArrowIcon\n size=\"16px\"\n className=\"eds-table__header-cell-button-icon\"\n />\n )}\n {isCurrentlySorted && sortConfig.order === 'descending' && (\n <DownArrowIcon\n size=\"16px\"\n className=\"eds-table__header-cell-button-icon\"\n />\n )}\n </button>\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","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 { 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 classNames from 'classnames';\nimport { RightArrowIcon } from '@entur/icons';\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 <button\n className={classNames('eds-expand-row-button', {\n 'eds-expand-row-button--open': open,\n })}\n onClick={onClick}\n {...rest}\n >\n <RightArrowIcon className=\"eds-expand-row-button__icon\" />\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]);\n\n function getTableBodyNavigationProps(...rest: any): Partial<TableBodyProps> {\n return {\n ref: tableBodyRef,\n ...rest,\n };\n }\n\n function getTableRowNavigationProps(\n row: number,\n ...rest: any\n ): Partial<TableRowProps> {\n React.useEffect(() => {\n row >= maxRow && setMaxRow(row + 1);\n }, []);\n const tableRowRef = React.useRef<HTMLTableRowElement>(null);\n\n let tabIndex = -1;\n row === currentRow ? (tabIndex = 0) : undefined;\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"],"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","UpArrowIcon","size","DownArrowIcon","useSortableData","rawData","externalSortConfig","setSortConfig","tableCopy","slice","sortedData","useMemo","sort","a","b","get","onSortRequested","getSortableHeaderProps","buttonProps","onClick","getSortableTableProps","EditableCell","feedback","variant","outlined","VariantProvider","Tooltip","disableHoverListener","disableFocusListener","placement","content","ExpandableRow","open","colSpan","BaseExpand","ExpandRowButton","RightArrowIcon","onTableKeypress","event","currentRow","maxRow","allowWrap","keyPress","preventDefault","useTableKeyboardNavigation","numberOfRows","setCurrentRow","setMaxRow","tableBodyRef","useRef","tableHasFocus","current","contains","document","activeElement","childNodes","parentElement","focus","getTableBodyNavigationProps","getTableRowNavigationProps","row","tableRowRef","tabIndex","onKeyDown","e","newCell","warnAboutMissingStyles"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAkBaA,KAAK,gBAAGC,cAAK,CAACC,UAAN,CACnB,gBAQEC,GARF;MAEIC,iBAAAA;wBACAC;MAAAA,gCAAQ;0BACRC;MAAAA,oCAAU;2BACVC;MAAAA,sCAAW;MACRC;;AAIL,SACEP,4BAAA,QAAA;AACEG,IAAAA,SAAS,EAAEK,UAAU,CACnB,WADmB,EAEnB;AAAE,0BAAoBJ;AAAtB,KAFmB,EAGnB;AAAE,2BAAqBC,OAAO,KAAK;AAAnC,KAHmB,EAInB;AAAE,0BAAoBA,OAAO,KAAK;AAAlC,KAJmB,EAKnB;AAAE,6BAAuBC;A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IAAAA,cAAK,CAAC6B,SAAN,CAAgB;AACdiE,MAAAA,GAAG,IAAIpB,MAAP,IAAiBO,SAAS,CAACa,GAAG,GAAG,CAAP,CAA1B;AACD,KAFD,EAEG,EAFH;AAGA,QAAMC,WAAW,GAAG/F,cAAK,CAACmF,MAAN,CAAkC,IAAlC,CAApB;AAEA,QAAIa,QAAQ,GAAG,CAAC,CAAhB;AACAF,IAAAA,GAAG,KAAKrB,UAAR,GAAsBuB,QAAQ,GAAG,CAAjC,GAAsC5E,SAAtC;;uCARGb;AAAAA,MAAAA;;;AASH;AACEyF,MAAAA,QAAQ,EAARA,QADF;AAEE9F,MAAAA,GAAG,EAAE6F,WAFP;AAGE1C,MAAAA,OAAO,EAAE;AAAA,eAAM2B,aAAa,CAACc,GAAD,CAAnB;AAAA,OAHX;AAIEG,MAAAA,SAAS,EAAE,mBAACC,CAAD;AACT,YAAMC,OAAO,GAAG5B,eAAe,CAAC2B,CAAD,EAAIzB,UAAJ,EAAgBM,YAAhB,EAA8BJ,SAA9B,CAA/B;AACAK,QAAAA,aAAa,CAACmB,OAAD,CAAb;AACD;AAPH,OAQK5F,IARL;AAUD;;AACD,SAAO;AAAEsF,IAAAA,0BAA0B,EAA1BA,0BAAF;AAA8BD,IAAAA,2BAA2B,EAA3BA;AAA9B,GAAP;AACD,CAjDM;;AC1CPQ,4BAAsB,CAAC,OAAD,CAAtB;;;;;;;;;;;;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var r=require("@entur/utils"),t=require("react"),a=e(t),n=e(require("classnames")),o=require("@entur/icons"),s=e(require("lodash.get")),l=require("@entur/form"),d=require("@entur/tooltip"),c=require("@entur/expand");function i(){return(i=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a])}return e}).apply(this,arguments)}function u(e,r){if(null==e)return{};var t,a,n={},o=Object.keys(e);for(a=0;a<o.length;a++)r.indexOf(t=o[a])>=0||(n[t]=e[t]);return n}var b=a.forwardRef((function(e,r){var t=e.className,o=e.fixed,s=void 0!==o&&o,l=e.spacing,d=void 0===l?"default":l,c=e.sortable,i=void 0!==c&&c,b=u(e,["className","fixed","spacing","sortable"]);return a.createElement("table",Object.assign({className:n("eds-table",{"eds-table--fixed":s},{"eds-table--middle":"middle"===d},{"eds-table--small":"small"===d},{"eds-table--sortable":i},t),ref:r},b))})),f=a.forwardRef((function(e,r){var t=e.className,o=u(e,["className"]);return a.createElement("thead",Object.assign({className:n("eds-table__head",t),ref:r},o))})),v=a.forwardRef((function(e,r){var t=e.className,o=u(e,["className"]);return a.createElement("tbody",Object.assign({className:n("eds-table__body",t),ref:r},o))})),m=a.forwardRef((function(e,r){var t=i({},e);return a.createElement("tfoot",Object.assign({ref:r},t))})),p=a.forwardRef((function(e,r){var t=e.className,o=e.hover,s=void 0!==o&&o,l=e.active,d=void 0!==l&&l,c=e.error,i=void 0!==c&&c,b=u(e,["className","hover","active","error"]);return a.createElement("tr",Object.assign({className:n("eds-table__row",t,{"eds-table__row--hover":s,"eds-table__row--active":d,"eds-table__row--error":i}),ref:r},b))})),g=a.forwardRef((function(e,r){var t,o=e.className,s=e.padding,l=void 0===s?"default":s,d=e.status,c=void 0===d?void 0:d,i=u(e,["className","padding","status"]);return a.createElement("td",Object.assign({ref:r,className:n("eds-table__data-cell",o,(t={},t["eds-table__data-cell--status-"+c]=c,t["eds-table__data-cell--padding-checkbox"]="checkbox"===l,t["eds-table__data-cell--padding-radio"]="radio"===l,t["eds-table__data-cell--padding-overflow-menu"]="overflow-menu"===l,t))},i))})),_=a.forwardRef((function(e,r){var t=e.className,o=e.children,s=e.name,l=e.sortable,d=void 0!==l&&l,c=e.sortConfig,i=e.padding,b=void 0===i?"default":i,f=e.sortableButtonProps,v=u(e,["className","children","name","sortable","sortConfig","padding","sortableButtonProps"]),m=a.useState(!1),p=m[0],g=m[1];a.useEffect((function(){c&&s&&g(c&&s===c.key)}),[c,s]);var _=p?c&&c.order:"none";return a.createElement("th",Object.assign({className:n("eds-table__header-cell",t,{"eds-table__header-cell--sortable":d,"eds-table__header-cell--padding-radio":"radio"===b,"eds-table__header-cell--padding-checkbox":"checkbox"===b,"eds-table__header-cell--padding-overflow-menu":"overflow-menu"===b}),"aria-sort":_,ref:r},v),d&&c&&f?a.createElement(h,{sortableButtonProps:f,sortConfig:c,isCurrentlySorted:p},o):o)})),h=function(e){var r=e.sortConfig,t=e.sortableButtonProps,s=e.isCurrentlySorted,l=e.children,d=t.className,c=u(t,["className"]);return a.createElement("button",Object.assign({className:n("eds-table__header-cell-button",d),type:"button"},c),l,s&&"ascending"===r.order&&a.createElement(o.UpArrowIcon,{size:"16px",className:"eds-table__header-cell-button-icon"}),s&&"descending"===r.order&&a.createElement(o.DownArrowIcon,{size:"16px",className:"eds-table__header-cell-button-icon"}))};function w(e,r,t,a){switch(e.key){case"ArrowUp":return e.preventDefault(),a?0===r?t-1:r-1:r>0?r-1:0;case"ArrowDown":return e.preventDefault(),a?r===t-1?0:r+1:r<t-1?r+1:r;default:return r}}r.warnAboutMissingStyles("table"),exports.DataCell=g,exports.EditableCell=function(e){var r=e.children,t=e.className,o=e.feedback,s=e.variant,c=e.outlined,i=void 0!==c&&c,b=u(e,["children","className","feedback","variant","outlined"]);return a.createElement(l.VariantProvider,{variant:s},a.createElement(g,Object.assign({className:n("eds-editable-cell",{"eds-editable-cell--outlined":i},t)},b),a.createElement(d.Tooltip,{disableHoverListener:!o,disableFocusListener:!o,placement:"bottom",content:o||void 0,variant:o?"error":void 0},r)))},exports.ExpandRowButton=function(e){var r=e.open,t=e.onClick,s=u(e,["open","onClick"]);return a.createElement("button",Object.assign({className:n("eds-expand-row-button",{"eds-expand-row-button--open":r}),onClick:t},s),a.createElement(o.RightArrowIcon,{className:"eds-expand-row-button__icon"}))},exports.ExpandableRow=function(e){var r=e.open;return a.createElement("tr",null,a.createElement("td",{colSpan:e.colSpan},a.createElement(c.BaseExpand,{open:void 0!==r&&r},e.children)))},exports.HeaderCell=_,exports.Table=b,exports.TableBody=v,exports.TableFooter=m,exports.TableHead=f,exports.TableRow=p,exports.useSortableData=function(e,r){void 0===r&&(r={key:"",order:"none"});var t=a.useState(r),n=t[0],o=t[1],l=e.slice();return a.useEffect((function(){o({key:r.key,order:r.order})}),[r.key,r.order]),{sortedData:a.useMemo((function(){return"none"===n.order?l:[].concat(e).sort((function(e,r){return s(e,n.key)<s(r,n.key)?"ascending"===n.order?-1:1:s(e,n.key)>s(r,n.key)?"ascending"===n.order?1:-1:0}))}),[e,l,n]),getSortableHeaderProps:function(e){var r=e.name,t=e.sortable,a=void 0===t||t,s=e.buttonProps,l=u(e,["name","sortable","buttonProps"]);return i({name:r,sortable:a,sortConfig:n,sortableButtonProps:i({onClick:function(){return t="ascending",n.key===(e=r)&&"ascending"===n.order?t="descending":n.key===e&&"descending"===n.order&&(t="none"),void o({key:e,order:t});var e,t}},s)},l)},getSortableTableProps:function(e){var r=e.sortable,t=void 0===r||r,a=u(e,["sortable"]);return i({sortable:t,sortConfig:n},a)}}},exports.useTableKeyboardNavigation=function(e,r){var n;void 0===e&&(e=0),void 0===r&&(r=!0);var o=t.useState(e),s=o[0],l=o[1],d=t.useState(0),c=d[0],u=d[1],b=a.useRef(null),f=null==b||null===(n=b.current)||void 0===n?void 0:n.contains(document.activeElement);return a.useEffect((function(){var e;b&&b.current&&f&&(null===(e=b.current.childNodes[s].childNodes[0].parentElement)||void 0===e||e.focus())}),[s]),{getTableRowNavigationProps:function(t){a.useEffect((function(){t>=c&&u(t+1)}),[]);var n=a.useRef(null),o=-1;t===s&&(o=0);for(var d=arguments.length,b=new Array(d>1?d-1:0),f=1;f<d;f++)b[f-1]=arguments[f];return i({tabIndex:o,ref:n,onClick:function(){return l(t)},onKeyDown:function(t){var a=w(t,s,e,r);l(a)}},b)},getTableBodyNavigationProps:function(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];return i({ref:b},r)}}};
|
|
2
2
|
//# sourceMappingURL=table.cjs.production.min.js.map
|
|
@@ -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/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 [key: string]: any;\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\ntype 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} & 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';\nimport { DownArrowIcon, UpArrowIcon } from '@entur/icons';\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 [key: string]: any;\n};\n\nexport const HeaderCell = React.forwardRef<\n HTMLTableHeaderCellElement,\n HeaderCellProps\n>(\n (\n {\n className,\n children,\n onClick,\n name,\n sortable = false,\n sortConfig,\n padding = 'default',\n ...rest\n },\n ref,\n ) => {\n const [isCurrentlySorted, setIsCurrentlySorted] =\n React.useState<boolean>(false);\n React.useEffect(() => {\n setIsCurrentlySorted(sortConfig && name === sortConfig.key);\n }, [sortConfig, name]);\n const ariaSort = isCurrentlySorted\n ? sortConfig && sortConfig.order\n : 'none';\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 ? (\n <button\n className=\"eds-table__header-cell-button\"\n type=\"button\"\n onClick={onClick}\n >\n {children}\n {isCurrentlySorted && sortConfig.order === 'ascending' && (\n <UpArrowIcon\n size=\"16px\"\n className=\"eds-table__header-cell-button-icon\"\n />\n )}\n {isCurrentlySorted && sortConfig.order === 'descending' && (\n <DownArrowIcon\n size=\"16px\"\n className=\"eds-table__header-cell-button-icon\"\n />\n )}\n </button>\n ) : (\n children\n )}\n </th>\n );\n },\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';\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 { RightArrowIcon } from '@entur/icons';\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 <button\n className={classNames('eds-expand-row-button', {\n 'eds-expand-row-button--open': open,\n })}\n onClick={onClick}\n {...rest}\n >\n <RightArrowIcon className=\"eds-expand-row-button__icon\" />\n </button>\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 ...props\n }: SortableHeaderProps): SortableHeaderReturnProps {\n return {\n name,\n sortable,\n onClick: () => onSortRequested(name),\n sortConfig: sortConfig,\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 [key: string]: any;\n};\n\nexport type SortableHeaderReturnProps = {\n name: string;\n sortable: boolean;\n onClick: () => void;\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","onClick","name","sortConfig","useState","isCurrentlySorted","setIsCurrentlySorted","useEffect","key","ariaSort","order","type","UpArrowIcon","size","DownArrowIcon","warnAboutMissingStyles","feedback","variant","outlined","VariantProvider","Tooltip","disableHoverListener","disableFocusListener","placement","content","open","RightArrowIcon","colSpan","BaseExpand","rawData","externalSortConfig","setSortConfig","tableCopy","slice","sortedData","useMemo","sort","a","b","get","getSortableHeaderProps","getSortableTableProps"],"mappings":"qrBAkBaA,EAAQC,EAAMC,YACzB,WAQEC,OANEC,IAAAA,cACAC,MAAAA,oBACAC,QAAAA,aAAU,gBACVC,SAAAA,gBACGC,yDAKHP,uCACEG,UAAWK,EACT,YACA,oBAAsBJ,GACtB,qBAAmC,WAAZC,GACvB,oBAAkC,UAAZA,GACtB,uBAAyBC,GACzBH,GAEFD,IAAKA,GACDK,OC3BCE,EAAYT,EAAMC,YAG7B,WAA0BC,OAAvBC,IAAAA,UAAcO,4BACjBV,uCACEG,UAAWK,EAAW,kBAAmBL,GACzCD,IAAKA,GACDQ,OCTKC,EAAYX,EAAMC,YAG7B,WAAyBC,OAAtBC,IAAAA,UAAcI,4BACjBP,uCACEG,UAAWK,EAAW,kBAAmBL,GACzCD,IAAKA,GACDK,OCRKK,EAAcZ,EAAMC,YAG/B,WAAeC,OAATQ,iBAAiBV,uCAAOE,IAAKA,GAASQ,OCYjCG,EAAWb,EAAMC,YAC5B,WAEEC,OADEC,IAAAA,cAAWW,MAAAA,oBAAeC,OAAAA,oBAAgBC,MAAAA,gBAAkBT,qDAG9DP,oCACEG,UAAWK,EAAW,iBAAkBL,EAAW,yBACxBW,2BACCC,0BACDC,IAE3Bd,IAAKA,GACDK,OCpBGU,EAAWjB,EAAMC,YAI5B,WAEEC,SADEC,IAAAA,cAAWe,QAAAA,aAAU,gBAAWC,OAAAA,kBAASC,IAAcb,+CAGzDP,oCACEE,IAAKA,EACLC,UAAWK,EAAW,uBAAwBL,0CACXgB,GAAWA,IAC5C,0CAAsD,aAAZ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jD,gBAACkD,cAAWH,sBANlBzB,oKCHA6B,EACAC,YAAAA,IAAAA,EAAyC,CAAEtB,IAAK,GAAIE,MAAO,eAQvBhC,EAAM0B,SAAS0B,GAA5C3B,OAAY4B,OACbC,EAAYH,EAAQI,eAE1BvD,EAAM6B,WAAU,WACdwB,EAAc,CACZvB,IAAKsB,EAAmBtB,IACxBE,MAAOoB,EAAmBpB,UAE3B,CAACoB,EAAmBtB,IAAKsB,EAAmBpB,QAqDxC,CAAEwB,WAnDexD,EAAMyD,SAAQ,iBACX,SAArBhC,EAAWO,MACNsB,EAEF,UAAIH,GAASO,MAAK,SAACC,EAAQC,UAC5BC,EAAIF,EAAGlC,EAAWK,KAAO+B,EAAID,EAAGnC,EAAWK,KACjB,cAArBL,EAAWO,OAAyB,EAAI,EACtC6B,EAAIF,EAAGlC,EAAWK,KAAO+B,EAAID,EAAGnC,EAAWK,KACxB,cAArBL,EAAWO,MAAwB,GAAK,EAExC,OAGV,CAACmB,EAASG,EAAW7B,IAsCHqC,uCAxBnBtC,IAAAA,SACAlB,SAAAA,gBACGI,qCAGDc,KAAAA,EACAlB,SAAAA,EACAiB,QAAS,kBAlBPS,EAA6C,YAC7CP,EAAWK,OAFQA,EAmBUN,IAjBkB,cAArBC,EAAWO,MACvCA,EAAQ,aACCP,EAAWK,MAAQA,GAA4B,eAArBL,EAAWO,QAC9CA,EAAQ,aAGVqB,EAAc,CAAEvB,IAAAA,EAAKE,MAAAA,IARC,IAACF,EACnBE,GAmBFP,WAAYA,GACTf,IAesCqD,0CAV3CzD,SAAAA,gBACGI,8BAGDJ,SAAAA,EACAmB,WAAYA,GACTf"}
|
|
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';\nimport { DownArrowIcon, UpArrowIcon } from '@entur/icons';\nimport './HeaderCell.scss';\nimport { ExternalSortConfig } from '.';\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 === 'ascending' && (\n <UpArrowIcon\n size=\"16px\"\n className=\"eds-table__header-cell-button-icon\"\n />\n )}\n {isCurrentlySorted && sortConfig.order === 'descending' && (\n <DownArrowIcon\n size=\"16px\"\n className=\"eds-table__header-cell-button-icon\"\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]);\n\n function getTableBodyNavigationProps(...rest: any): Partial<TableBodyProps> {\n return {\n ref: tableBodyRef,\n ...rest,\n };\n }\n\n function getTableRowNavigationProps(\n row: number,\n ...rest: any\n ): Partial<TableRowProps> {\n React.useEffect(() => {\n row >= maxRow && setMaxRow(row + 1);\n }, []);\n const tableRowRef = React.useRef<HTMLTableRowElement>(null);\n\n let tabIndex = -1;\n row === currentRow ? (tabIndex = 0) : undefined;\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 { RightArrowIcon } from '@entur/icons';\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 <button\n className={classNames('eds-expand-row-button', {\n 'eds-expand-row-button--open': open,\n })}\n onClick={onClick}\n {...rest}\n >\n <RightArrowIcon className=\"eds-expand-row-button__icon\" />\n </button>\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","UpArrowIcon","size","DownArrowIcon","onTableKeypress","event","currentRow","maxRow","allowWrap","preventDefault","warnAboutMissingStyles","feedback","variant","outlined","VariantProvider","Tooltip","disableHoverListener","disableFocusListener","placement","content","open","onClick","RightArrowIcon","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","getTableRowNavigationProps","row","tableRowRef","tabIndex","onKeyDown","e","newCell","getTableBodyNavigationProps"],"mappings":"yrBAkBaA,EAAQC,EAAMC,YACzB,WAQEC,OANEC,IAAAA,cACAC,MAAAA,oBACAC,QAAAA,aAAU,gBACVC,SAAAA,gBACGC,yDAKHP,uCACEG,UAAWK,EACT,YACA,oBAAsBJ,GACtB,qBAAmC,WAAZC,GACvB,oBAAkC,UAAZA,GACtB,uBAAyBC,GACzBH,GAEFD,IAAKA,GACDK,OC3BCE,EAAYT,EAAMC,YAG7B,WAA0BC,OAAvBC,IAAAA,UAAcO,4BACjBV,uCACEG,UAAWK,EAAW,kBAAmBL,GACzCD,IAAKA,GACDQ,OCNKC,EAAYX,EAAMC,YAG7B,WAAyBC,OAAtBC,IAAAA,UAAcI,4BACjBP,uCACEG,UAAWK,EAAW,kBAAmBL,GACzCD,IAAKA,GACDK,OCXKK,EAAcZ,EAAMC,YAG/B,WAAeC,OAATQ,iBAAiBV,uCAAOE,IAAKA,GAASQ,OCajCG,EAAWb,EAAMC,YAC5B,WAEEC,OADEC,IAAAA,cAAWW,MAAAA,oBAAeC,OAAAA,oBAAgBC,MAAAA,gBAAkBT,qDAG9DP,oCACEG,UAAWK,EAAW,iBAAkBL,EAAW,yBACxBW,2BACCC,0BACDC,IAE3Bd,IAAKA,GACDK,OCrBGU,EAAWjB,EAAMC,YAI5B,WAEEC,SADEC,IAAAA,cAAWe,QAAAA,aAAU,gBAAWC,OAAAA,kBAASC,IAAcb,+CAGzDP,oCACEE,IAAKA,EACLC,UAAWK,EAAW,uBAAwBL,0CACXgB,GAAWA,IAC5C,0CAAsD,aAAZD,IAC1C,uCAAmD,UAAZA,IACvC,+CACc,kBAAZA,OAEAX,OCDGc,E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WM,OAFQA,EAsBYP,IApBgB,cAArBC,EAAWQ,MACvCA,EAAQ,aACCR,EAAWM,MAAQA,GAA4B,eAArBN,EAAWQ,QAC9CA,EAAQ,aAGV6B,EAAc,CAAE/B,IAAAA,EAAKE,MAAAA,IARC,IAACF,EACnBE,IAsBGuC,IAEF7D,IAesC8D,0CAV3ClE,SAAAA,gBACGI,8BAGDJ,SAAAA,EACAkB,WAAYA,GACTd,yCLtCkE,SACzE+D,EACA/B,kBADA+B,IAAAA,EAAe,YACf/B,IAAAA,GAAY,SAEwBhB,WAAS+C,GAAtCjC,OAAYkC,SACShD,WAAS,GAA9Be,OAAQkC,OAETC,EAAe5E,EAAM6E,OAAgC,MACrDC,EAAgBF,MAAAA,aAAAA,EAAcG,4BAAdC,EAAuBC,SAASC,SAASC,sBAE/DnF,EAAM6B,WAAU,iBACd+C,GACEA,EAAaG,SACbD,cACAF,EAAaG,QAAQK,WACnB5C,GACA4C,WAAW,GAAGC,4BAFhBC,EAE+BC,WAChC,CAAC/C,IA+BG,CAAEgD,oCArBPC,GAGAzF,EAAM6B,WAAU,WACd4D,GAAOhD,GAAUkC,EAAUc,EAAM,KAChC,QACGC,EAAc1F,EAAM6E,OAA4B,MAElDc,GAAY,EAChBF,IAAQjD,IAAcmD,EAAW,8BAR9BpF,mCAAAA,8BAUDoF,SAAAA,EACAzF,IAAKwF,EACLnC,QAAS,kBAAMmB,EAAce,IAC7BG,UAAW,SAACC,OACJC,EAAUxD,EAAgBuD,EAAGrD,EAAYiC,EAAc/B,GAC7DgC,EAAcoB,KAEbvF,IAG8BwF,kEA7BGxF,2BAAAA,4BAEpCL,IAAK0E,GACFrE"}
|
package/dist/table.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { warnAboutMissingStyles } from '@entur/utils';
|
|
2
|
-
import React from 'react';
|
|
2
|
+
import React, { useState } from 'react';
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
import { UpArrowIcon, DownArrowIcon, RightArrowIcon } from '@entur/icons';
|
|
5
5
|
import get from 'lodash.get';
|
|
@@ -131,21 +131,21 @@ var DataCell = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
131
131
|
var HeaderCell = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
132
132
|
var className = _ref.className,
|
|
133
133
|
children = _ref.children,
|
|
134
|
-
onClick = _ref.onClick,
|
|
135
134
|
name = _ref.name,
|
|
136
135
|
_ref$sortable = _ref.sortable,
|
|
137
136
|
sortable = _ref$sortable === void 0 ? false : _ref$sortable,
|
|
138
137
|
sortConfig = _ref.sortConfig,
|
|
139
138
|
_ref$padding = _ref.padding,
|
|
140
139
|
padding = _ref$padding === void 0 ? 'default' : _ref$padding,
|
|
141
|
-
|
|
140
|
+
sortableButtonProps = _ref.sortableButtonProps,
|
|
141
|
+
rest = _objectWithoutPropertiesLoose(_ref, ["className", "children", "name", "sortable", "sortConfig", "padding", "sortableButtonProps"]);
|
|
142
142
|
|
|
143
143
|
var _React$useState = React.useState(false),
|
|
144
144
|
isCurrentlySorted = _React$useState[0],
|
|
145
145
|
setIsCurrentlySorted = _React$useState[1];
|
|
146
146
|
|
|
147
147
|
React.useEffect(function () {
|
|
148
|
-
setIsCurrentlySorted(sortConfig && name === sortConfig.key);
|
|
148
|
+
sortConfig && name && setIsCurrentlySorted(sortConfig && name === sortConfig.key);
|
|
149
149
|
}, [sortConfig, name]);
|
|
150
150
|
var ariaSort = isCurrentlySorted ? sortConfig && sortConfig.order : 'none';
|
|
151
151
|
return React.createElement("th", Object.assign({
|
|
@@ -157,18 +157,33 @@ var HeaderCell = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
157
157
|
}),
|
|
158
158
|
"aria-sort": ariaSort,
|
|
159
159
|
ref: ref
|
|
160
|
-
}, rest), sortable ? React.createElement(
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}, children
|
|
160
|
+
}, rest), sortable && sortConfig && sortableButtonProps ? React.createElement(SortableHeaderCellButton, {
|
|
161
|
+
sortableButtonProps: sortableButtonProps,
|
|
162
|
+
sortConfig: sortConfig,
|
|
163
|
+
isCurrentlySorted: isCurrentlySorted
|
|
164
|
+
}, children) : children);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
var SortableHeaderCellButton = function SortableHeaderCellButton(_ref2) {
|
|
168
|
+
var sortConfig = _ref2.sortConfig,
|
|
169
|
+
sortableButtonProps = _ref2.sortableButtonProps,
|
|
170
|
+
isCurrentlySorted = _ref2.isCurrentlySorted,
|
|
171
|
+
children = _ref2.children;
|
|
172
|
+
|
|
173
|
+
var className = sortableButtonProps.className,
|
|
174
|
+
rest = _objectWithoutPropertiesLoose(sortableButtonProps, ["className"]);
|
|
175
|
+
|
|
176
|
+
return React.createElement("button", Object.assign({
|
|
177
|
+
className: classNames('eds-table__header-cell-button', className),
|
|
178
|
+
type: "button"
|
|
179
|
+
}, rest), children, isCurrentlySorted && sortConfig.order === 'ascending' && React.createElement(UpArrowIcon, {
|
|
165
180
|
size: "16px",
|
|
166
181
|
className: "eds-table__header-cell-button-icon"
|
|
167
182
|
}), isCurrentlySorted && sortConfig.order === 'descending' && React.createElement(DownArrowIcon, {
|
|
168
183
|
size: "16px",
|
|
169
184
|
className: "eds-table__header-cell-button-icon"
|
|
170
|
-
}))
|
|
171
|
-
}
|
|
185
|
+
}));
|
|
186
|
+
};
|
|
172
187
|
|
|
173
188
|
function useSortableData(rawData, externalSortConfig) {
|
|
174
189
|
if (externalSortConfig === void 0) {
|
|
@@ -224,15 +239,18 @@ function useSortableData(rawData, externalSortConfig) {
|
|
|
224
239
|
var name = _ref.name,
|
|
225
240
|
_ref$sortable = _ref.sortable,
|
|
226
241
|
sortable = _ref$sortable === void 0 ? true : _ref$sortable,
|
|
227
|
-
|
|
242
|
+
buttonProps = _ref.buttonProps,
|
|
243
|
+
props = _objectWithoutPropertiesLoose(_ref, ["name", "sortable", "buttonProps"]);
|
|
228
244
|
|
|
229
245
|
return _extends({
|
|
230
246
|
name: name,
|
|
231
247
|
sortable: sortable,
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
248
|
+
sortConfig: sortConfig,
|
|
249
|
+
sortableButtonProps: _extends({
|
|
250
|
+
onClick: function onClick() {
|
|
251
|
+
return onSortRequested(name);
|
|
252
|
+
}
|
|
253
|
+
}, buttonProps)
|
|
236
254
|
}, props);
|
|
237
255
|
}
|
|
238
256
|
|
|
@@ -305,7 +323,102 @@ var ExpandRowButton = function ExpandRowButton(_ref) {
|
|
|
305
323
|
}));
|
|
306
324
|
};
|
|
307
325
|
|
|
326
|
+
function onTableKeypress(event, currentRow, maxRow, allowWrap) {
|
|
327
|
+
var keyPress = event.key;
|
|
328
|
+
|
|
329
|
+
switch (keyPress) {
|
|
330
|
+
case 'ArrowUp':
|
|
331
|
+
event.preventDefault();
|
|
332
|
+
|
|
333
|
+
if (allowWrap) {
|
|
334
|
+
return currentRow === 0 ? maxRow - 1 : currentRow - 1;
|
|
335
|
+
} else {
|
|
336
|
+
return currentRow > 0 ? currentRow - 1 : 0;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
case 'ArrowDown':
|
|
340
|
+
event.preventDefault();
|
|
341
|
+
|
|
342
|
+
if (allowWrap) {
|
|
343
|
+
return currentRow === maxRow - 1 ? 0 : currentRow + 1;
|
|
344
|
+
} else {
|
|
345
|
+
return currentRow < maxRow - 1 ? currentRow + 1 : currentRow;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
default:
|
|
349
|
+
return currentRow;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
var useTableKeyboardNavigation = function useTableKeyboardNavigation(numberOfRows, allowWrap) {
|
|
354
|
+
var _tableBodyRef$current;
|
|
355
|
+
|
|
356
|
+
if (numberOfRows === void 0) {
|
|
357
|
+
numberOfRows = 0;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
if (allowWrap === void 0) {
|
|
361
|
+
allowWrap = true;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
var _useState = useState(numberOfRows),
|
|
365
|
+
currentRow = _useState[0],
|
|
366
|
+
setCurrentRow = _useState[1];
|
|
367
|
+
|
|
368
|
+
var _useState2 = useState(0),
|
|
369
|
+
maxRow = _useState2[0],
|
|
370
|
+
setMaxRow = _useState2[1];
|
|
371
|
+
|
|
372
|
+
var tableBodyRef = React.useRef(null);
|
|
373
|
+
var tableHasFocus = tableBodyRef === null || tableBodyRef === void 0 ? void 0 : (_tableBodyRef$current = tableBodyRef.current) === null || _tableBodyRef$current === void 0 ? void 0 : _tableBodyRef$current.contains(document.activeElement);
|
|
374
|
+
React.useEffect(function () {
|
|
375
|
+
var _tableBodyRef$current2;
|
|
376
|
+
|
|
377
|
+
tableBodyRef && tableBodyRef.current && tableHasFocus && ((_tableBodyRef$current2 = tableBodyRef.current.childNodes[currentRow].childNodes[0].parentElement) === null || _tableBodyRef$current2 === void 0 ? void 0 : _tableBodyRef$current2.focus());
|
|
378
|
+
}, [currentRow]);
|
|
379
|
+
|
|
380
|
+
function getTableBodyNavigationProps() {
|
|
381
|
+
for (var _len = arguments.length, rest = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
382
|
+
rest[_key] = arguments[_key];
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
return _extends({
|
|
386
|
+
ref: tableBodyRef
|
|
387
|
+
}, rest);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
function getTableRowNavigationProps(row) {
|
|
391
|
+
React.useEffect(function () {
|
|
392
|
+
row >= maxRow && setMaxRow(row + 1);
|
|
393
|
+
}, []);
|
|
394
|
+
var tableRowRef = React.useRef(null);
|
|
395
|
+
var tabIndex = -1;
|
|
396
|
+
row === currentRow ? tabIndex = 0 : undefined;
|
|
397
|
+
|
|
398
|
+
for (var _len2 = arguments.length, rest = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
399
|
+
rest[_key2 - 1] = arguments[_key2];
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
return _extends({
|
|
403
|
+
tabIndex: tabIndex,
|
|
404
|
+
ref: tableRowRef,
|
|
405
|
+
onClick: function onClick() {
|
|
406
|
+
return setCurrentRow(row);
|
|
407
|
+
},
|
|
408
|
+
onKeyDown: function onKeyDown(e) {
|
|
409
|
+
var newCell = onTableKeypress(e, currentRow, numberOfRows, allowWrap);
|
|
410
|
+
setCurrentRow(newCell);
|
|
411
|
+
}
|
|
412
|
+
}, rest);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
return {
|
|
416
|
+
getTableRowNavigationProps: getTableRowNavigationProps,
|
|
417
|
+
getTableBodyNavigationProps: getTableBodyNavigationProps
|
|
418
|
+
};
|
|
419
|
+
};
|
|
420
|
+
|
|
308
421
|
warnAboutMissingStyles('table');
|
|
309
422
|
|
|
310
|
-
export { DataCell, EditableCell, ExpandRowButton, ExpandableRow, HeaderCell, Table, TableBody, TableFooter, TableHead, TableRow, useSortableData };
|
|
423
|
+
export { DataCell, EditableCell, ExpandRowButton, ExpandableRow, HeaderCell, Table, TableBody, TableFooter, TableHead, TableRow, useSortableData, useTableKeyboardNavigation };
|
|
311
424
|
//# sourceMappingURL=table.esm.js.map
|