@ltht-react/table 2.0.159 → 2.0.160

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/README.md CHANGED
@@ -1,15 +1,15 @@
1
- # Select
2
-
3
- <!-- STORY -->
4
-
5
- ### Import
6
-
7
- ```js
8
- import Select from '@ltht-react/table'
9
- ```
10
-
11
- ### Usage
12
-
13
- ```jsx
14
- <Table />
15
- ```
1
+ # Select
2
+
3
+ <!-- STORY -->
4
+
5
+ ### Import
6
+
7
+ ```js
8
+ import Select from '@ltht-react/table'
9
+ ```
10
+
11
+ ### Usage
12
+
13
+ ```jsx
14
+ <Table />
15
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ltht-react/table",
3
- "version": "2.0.159",
3
+ "version": "2.0.160",
4
4
  "description": "ltht-react Table component.",
5
5
  "author": "LTHT",
6
6
  "homepage": "",
@@ -28,15 +28,15 @@
28
28
  "dependencies": {
29
29
  "@emotion/react": "^11.0.0",
30
30
  "@emotion/styled": "^11.0.0",
31
- "@ltht-react/button": "^2.0.159",
32
- "@ltht-react/icon": "^2.0.159",
33
- "@ltht-react/menu": "^2.0.159",
34
- "@ltht-react/styles": "^2.0.159",
35
- "@ltht-react/types": "^2.0.159",
36
- "@ltht-react/utils": "^2.0.159",
31
+ "@ltht-react/button": "^2.0.160",
32
+ "@ltht-react/icon": "^2.0.160",
33
+ "@ltht-react/menu": "^2.0.160",
34
+ "@ltht-react/styles": "^2.0.160",
35
+ "@ltht-react/types": "^2.0.160",
36
+ "@ltht-react/utils": "^2.0.160",
37
37
  "@tanstack/react-table": "^8.10.7",
38
38
  "react": "^18.2.0",
39
39
  "react-uuid": "^2.0.0"
40
40
  },
41
- "gitHead": "4a697c254ecf73e4c69eaae4116e59d27c1558ff"
41
+ "gitHead": "ae069fdcbcd0bfced3222d0b98a79b1b5097b11b"
42
42
  }
@@ -1,15 +1,15 @@
1
- import { FC } from 'react'
2
- import styled from '@emotion/styled'
3
-
4
- const StyledText = styled.div`
5
- text-decoration: line-through;
6
- color: gray;
7
- `
8
-
9
- const QuestionnaireWithdrawnTableCell: FC<WithdrawnCellProps> = ({ text }) => <StyledText>{text ?? ''}</StyledText>
10
-
11
- export interface WithdrawnCellProps {
12
- text?: string
13
- }
14
-
15
- export default QuestionnaireWithdrawnTableCell
1
+ import { FC } from 'react'
2
+ import styled from '@emotion/styled'
3
+
4
+ const StyledText = styled.div`
5
+ text-decoration: line-through;
6
+ color: gray;
7
+ `
8
+
9
+ const QuestionnaireWithdrawnTableCell: FC<WithdrawnCellProps> = ({ text }) => <StyledText>{text ?? ''}</StyledText>
10
+
11
+ export interface WithdrawnCellProps {
12
+ text?: string
13
+ }
14
+
15
+ export default QuestionnaireWithdrawnTableCell
package/src/index.tsx CHANGED
@@ -1,8 +1,8 @@
1
- import Table, { Header, DataEntity, TableData, CellProps } from './molecules/table'
2
- import GenericTable from './organisms/generic-table'
3
- import QuestionnaireTable from './organisms/questionnaire-table'
4
- import { AdminActionsForQuestionnaire } from './organisms/questionnaire-table-methods'
5
-
6
- export default Table
7
- export { Header, TableData, DataEntity, CellProps, GenericTable, QuestionnaireTable, AdminActionsForQuestionnaire }
8
- export { default as mapQuestionnaireToTableData } from './organisms/questionnaire-table-methods'
1
+ import Table, { Header, DataEntity, TableData, CellProps } from './molecules/table'
2
+ import GenericTable from './organisms/generic-table'
3
+ import QuestionnaireTable from './organisms/questionnaire-table'
4
+ import { AdminActionsForQuestionnaire } from './organisms/questionnaire-table-methods'
5
+
6
+ export default Table
7
+ export { Header, TableData, DataEntity, CellProps, GenericTable, QuestionnaireTable, AdminActionsForQuestionnaire }
8
+ export { default as mapQuestionnaireToTableData } from './organisms/questionnaire-table-methods'
@@ -1,93 +1,93 @@
1
- import { FC } from 'react'
2
- import { Button } from '@ltht-react/button'
3
- import styled from '@emotion/styled'
4
- import Icon, { IconButton, IconProps } from '@ltht-react/icon'
5
- import ActionMenu, { ActionMenuOption } from '@ltht-react/menu'
6
- import { PopUp, getZIndex, BTN_COLOURS } from '@ltht-react/styles'
7
- import { Axis } from '@ltht-react/types'
8
-
9
- const StyledIconText = styled.span`
10
- margin-left: 0.4rem;
11
- `
12
-
13
- // TODO: This component is still a WIP and will be re-factored soon!
14
- // May be best to split it out into different components, the important part is unifying Type used by React-Table so the mapping can be simplified
15
- // It will need to facilitate the Actions list capability Jonny Dyson has requested
16
- // Betters ways of handling the customComponentOverride will be considered too
17
- const TableCell: FC<CellProps> = ({
18
- adminActions,
19
- isButton = false,
20
- text,
21
- iconProps,
22
- headerAxis = 'x',
23
- clickHandler,
24
- customComponentOverride,
25
- }) => {
26
- if (customComponentOverride) {
27
- return customComponentOverride
28
- }
29
-
30
- if (adminActions) {
31
- if (adminActions.length === 0) {
32
- return <></>
33
- }
34
- return (
35
- <ActionMenu
36
- actions={adminActions}
37
- menuButtonOptions={{
38
- type: 'button',
39
- text: '',
40
- buttonProps: {
41
- styling: {
42
- buttonStyle: 'standard',
43
- padding: headerAxis === 'x' ? '0.3rem 0.5rem' : '0.15rem 0.3rem',
44
- },
45
- icon: (
46
- <Icon {...{ type: headerAxis === 'x' ? 'ellipsis-vertical' : 'ellipsis-horizontal', size: 'medium' }} />
47
- ),
48
- iconPlacement: 'center',
49
- color: `${BTN_COLOURS.DANGER.VALUE}`,
50
- },
51
- }}
52
- popupStyle={{ zIndex: getZIndex(PopUp) }}
53
- popupPlacement={headerAxis === 'x' ? 'bottom-start' : 'right-start'}
54
- />
55
- )
56
- }
57
-
58
- if (isButton) {
59
- return <Button value={text} icon={iconProps && <Icon {...iconProps} />} onClick={clickHandler} />
60
- }
61
-
62
- if (clickHandler && iconProps) {
63
- return <IconButton iconProps={iconProps} text={text} onClick={clickHandler} />
64
- }
65
-
66
- if (iconProps) {
67
- return (
68
- <>
69
- <Icon {...iconProps} />
70
- {text && <StyledIconText>{text}</StyledIconText>}
71
- </>
72
- )
73
- }
74
-
75
- if (text) {
76
- return <div>{text ?? ''}</div>
77
- }
78
-
79
- return <></>
80
- }
81
-
82
- export interface CellProps {
83
- adminActions?: ActionMenuOption[]
84
- isButton?: boolean
85
- text?: string
86
- iconProps?: IconProps
87
- clickHandler?: React.MouseEventHandler<HTMLButtonElement>
88
- customComponentOverride?: JSX.Element
89
- parentStyle?: React.CSSProperties
90
- headerAxis?: Axis
91
- }
92
-
93
- export default TableCell
1
+ import { FC } from 'react'
2
+ import { Button } from '@ltht-react/button'
3
+ import styled from '@emotion/styled'
4
+ import Icon, { IconButton, IconProps } from '@ltht-react/icon'
5
+ import ActionMenu, { ActionMenuOption } from '@ltht-react/menu'
6
+ import { PopUp, getZIndex, BTN_COLOURS } from '@ltht-react/styles'
7
+ import { Axis } from '@ltht-react/types'
8
+
9
+ const StyledIconText = styled.span`
10
+ margin-left: 0.4rem;
11
+ `
12
+
13
+ // TODO: This component is still a WIP and will be re-factored soon!
14
+ // May be best to split it out into different components, the important part is unifying Type used by React-Table so the mapping can be simplified
15
+ // It will need to facilitate the Actions list capability Jonny Dyson has requested
16
+ // Betters ways of handling the customComponentOverride will be considered too
17
+ const TableCell: FC<CellProps> = ({
18
+ adminActions,
19
+ isButton = false,
20
+ text,
21
+ iconProps,
22
+ headerAxis = 'x',
23
+ clickHandler,
24
+ customComponentOverride,
25
+ }) => {
26
+ if (customComponentOverride) {
27
+ return customComponentOverride
28
+ }
29
+
30
+ if (adminActions) {
31
+ if (adminActions.length === 0) {
32
+ return <></>
33
+ }
34
+ return (
35
+ <ActionMenu
36
+ actions={adminActions}
37
+ menuButtonOptions={{
38
+ type: 'button',
39
+ text: '',
40
+ buttonProps: {
41
+ styling: {
42
+ buttonStyle: 'standard',
43
+ padding: headerAxis === 'x' ? '0.3rem 0.5rem' : '0.15rem 0.3rem',
44
+ },
45
+ icon: (
46
+ <Icon {...{ type: headerAxis === 'x' ? 'ellipsis-vertical' : 'ellipsis-horizontal', size: 'medium' }} />
47
+ ),
48
+ iconPlacement: 'center',
49
+ color: `${BTN_COLOURS.DANGER.VALUE}`,
50
+ },
51
+ }}
52
+ popupStyle={{ zIndex: getZIndex(PopUp) }}
53
+ popupPlacement={headerAxis === 'x' ? 'bottom-start' : 'right-start'}
54
+ />
55
+ )
56
+ }
57
+
58
+ if (isButton) {
59
+ return <Button value={text} icon={iconProps && <Icon {...iconProps} />} onClick={clickHandler} />
60
+ }
61
+
62
+ if (clickHandler && iconProps) {
63
+ return <IconButton iconProps={iconProps} text={text} onClick={clickHandler} />
64
+ }
65
+
66
+ if (iconProps) {
67
+ return (
68
+ <>
69
+ <Icon {...iconProps} />
70
+ {text && <StyledIconText>{text}</StyledIconText>}
71
+ </>
72
+ )
73
+ }
74
+
75
+ if (text) {
76
+ return <div>{text ?? ''}</div>
77
+ }
78
+
79
+ return <></>
80
+ }
81
+
82
+ export interface CellProps {
83
+ adminActions?: ActionMenuOption[]
84
+ isButton?: boolean
85
+ text?: string
86
+ iconProps?: IconProps
87
+ clickHandler?: React.MouseEventHandler<HTMLButtonElement>
88
+ customComponentOverride?: JSX.Element
89
+ parentStyle?: React.CSSProperties
90
+ headerAxis?: Axis
91
+ }
92
+
93
+ export default TableCell
@@ -1,120 +1,120 @@
1
- import Icon from '@ltht-react/icon'
2
- import { flexRender, Header as ReactTableHeader, Table } from '@tanstack/react-table'
3
- import { HTMLAttributes, useMemo, useRef } from 'react'
4
- import { calculateStaticColumnOffset } from './table-methods'
5
- import {
6
- StyledNextPageButtonContainer,
7
- StyledSpinnerContainer,
8
- StyledTable,
9
- StyledTableRow,
10
- StyledTableData,
11
- StyledTHead,
12
- } from './table-styled-components'
13
- import useDimensionsRef from './useDimensionRef'
14
- import { CellProps } from './table-cell'
15
- import { ITableConfig } from './table'
16
- import TableHeader from './table-header'
17
-
18
- const TableComponent = <T,>({ table, staticColumns = 0, headerAxis, ...rest }: ITableHeadProps<T>): JSX.Element => {
19
- const firstColumn = useRef(null)
20
- const secondColumn = useRef(null)
21
- const tableElement = useRef(null)
22
- const { width: firstColumnWidth } = useDimensionsRef(firstColumn, tableElement)
23
- const { width: secondColumnWidth } = useDimensionsRef(secondColumn, tableElement)
24
-
25
- const usingExpanderColumn = table.getHeaderGroups().some((x) => x.headers.some((h) => h.column.id === 'expander'))
26
- const totalStaticColumns = useMemo(
27
- () => (usingExpanderColumn ? staticColumns + 1 : staticColumns),
28
- [usingExpanderColumn, staticColumns]
29
- )
30
-
31
- const getHeaderColumn = <TData, TValue>(header: ReactTableHeader<TData, TValue>, headerIndex: number) => {
32
- const stickyWidth = calculateStaticColumnOffset(
33
- headerIndex,
34
- totalStaticColumns,
35
- firstColumnWidth,
36
- secondColumnWidth
37
- )
38
- const headerProps = {
39
- header,
40
- stickyWidth,
41
- }
42
- switch (headerIndex) {
43
- case 0:
44
- return <TableHeader key={header.id} ref={firstColumn} {...headerProps} />
45
- case 1:
46
- return <TableHeader key={header.id} ref={secondColumn} {...headerProps} />
47
- default:
48
- return <TableHeader key={header.id} {...headerProps} />
49
- }
50
- }
51
-
52
- return (
53
- <StyledTable ref={tableElement} {...rest}>
54
- <StyledTHead>
55
- {table.getHeaderGroups().map((headerGroup) => (
56
- <tr key={headerGroup.id} role="row">
57
- {headerGroup.headers.map((header, headerIndex) => getHeaderColumn(header, headerIndex))}
58
- </tr>
59
- ))}
60
- </StyledTHead>
61
- <tbody>
62
- {table.getRowModel().rows.map((row) => (
63
- <StyledTableRow tableHeaderAxis={headerAxis} key={row.id} role="row">
64
- {row.getVisibleCells().map((cell, cellIdx) => (
65
- <StyledTableData
66
- tableHeaderAxis={headerAxis}
67
- stickyWidth={calculateStaticColumnOffset(
68
- cellIdx,
69
- totalStaticColumns,
70
- firstColumnWidth,
71
- secondColumnWidth
72
- )}
73
- key={cell.id}
74
- role="cell"
75
- style={(cell.getValue() as CellProps)?.parentStyle}
76
- >
77
- {flexRender(cell.column.columnDef.cell, cell.getContext())}
78
- </StyledTableData>
79
- ))}
80
- </StyledTableRow>
81
- ))}
82
- </tbody>
83
- </StyledTable>
84
- )
85
- }
86
-
87
- const TableNavigationButton = ({ position, hidden, clickHandler }: ITableNavButtonProps) => (
88
- <StyledNextPageButtonContainer
89
- role="button"
90
- elementPosition={position}
91
- onClick={() => clickHandler()}
92
- hidden={hidden}
93
- >
94
- <Icon type="chevron" direction={position === 'bottom' ? 'down' : 'right'} size="medium" />
95
- </StyledNextPageButtonContainer>
96
- )
97
-
98
- const TableSpinner = ({ position, hidden }: ITableSpinnerProps) => (
99
- <StyledSpinnerContainer elementPosition={position} hidden={hidden}>
100
- <Icon type="spinner" size="medium" title="Loading..." />
101
- </StyledSpinnerContainer>
102
- )
103
-
104
- interface ITableNavButtonProps {
105
- position: 'bottom' | 'right'
106
- hidden: boolean
107
- clickHandler: () => void
108
- }
109
-
110
- interface ITableSpinnerProps {
111
- position: 'bottom' | 'right'
112
- hidden: boolean
113
- }
114
-
115
- interface ITableHeadProps<T> extends ITableConfig, HTMLAttributes<HTMLTableElement> {
116
- table: Table<T>
117
- }
118
-
119
- export default TableComponent
120
- export { TableNavigationButton, TableSpinner }
1
+ import Icon from '@ltht-react/icon'
2
+ import { flexRender, Header as ReactTableHeader, Table } from '@tanstack/react-table'
3
+ import { HTMLAttributes, useMemo, useRef } from 'react'
4
+ import { calculateStaticColumnOffset } from './table-methods'
5
+ import {
6
+ StyledNextPageButtonContainer,
7
+ StyledSpinnerContainer,
8
+ StyledTable,
9
+ StyledTableRow,
10
+ StyledTableData,
11
+ StyledTHead,
12
+ } from './table-styled-components'
13
+ import useDimensionsRef from './useDimensionRef'
14
+ import { CellProps } from './table-cell'
15
+ import { ITableConfig } from './table'
16
+ import TableHeader from './table-header'
17
+
18
+ const TableComponent = <T,>({ table, staticColumns = 0, headerAxis, ...rest }: ITableHeadProps<T>): JSX.Element => {
19
+ const firstColumn = useRef(null)
20
+ const secondColumn = useRef(null)
21
+ const tableElement = useRef(null)
22
+ const { width: firstColumnWidth } = useDimensionsRef(firstColumn, tableElement)
23
+ const { width: secondColumnWidth } = useDimensionsRef(secondColumn, tableElement)
24
+
25
+ const usingExpanderColumn = table.getHeaderGroups().some((x) => x.headers.some((h) => h.column.id === 'expander'))
26
+ const totalStaticColumns = useMemo(
27
+ () => (usingExpanderColumn ? staticColumns + 1 : staticColumns),
28
+ [usingExpanderColumn, staticColumns]
29
+ )
30
+
31
+ const getHeaderColumn = <TData, TValue>(header: ReactTableHeader<TData, TValue>, headerIndex: number) => {
32
+ const stickyWidth = calculateStaticColumnOffset(
33
+ headerIndex,
34
+ totalStaticColumns,
35
+ firstColumnWidth,
36
+ secondColumnWidth
37
+ )
38
+ const headerProps = {
39
+ header,
40
+ stickyWidth,
41
+ }
42
+ switch (headerIndex) {
43
+ case 0:
44
+ return <TableHeader key={header.id} ref={firstColumn} {...headerProps} />
45
+ case 1:
46
+ return <TableHeader key={header.id} ref={secondColumn} {...headerProps} />
47
+ default:
48
+ return <TableHeader key={header.id} {...headerProps} />
49
+ }
50
+ }
51
+
52
+ return (
53
+ <StyledTable ref={tableElement} {...rest}>
54
+ <StyledTHead>
55
+ {table.getHeaderGroups().map((headerGroup) => (
56
+ <tr key={headerGroup.id} role="row">
57
+ {headerGroup.headers.map((header, headerIndex) => getHeaderColumn(header, headerIndex))}
58
+ </tr>
59
+ ))}
60
+ </StyledTHead>
61
+ <tbody>
62
+ {table.getRowModel().rows.map((row) => (
63
+ <StyledTableRow tableHeaderAxis={headerAxis} key={row.id} role="row">
64
+ {row.getVisibleCells().map((cell, cellIdx) => (
65
+ <StyledTableData
66
+ tableHeaderAxis={headerAxis}
67
+ stickyWidth={calculateStaticColumnOffset(
68
+ cellIdx,
69
+ totalStaticColumns,
70
+ firstColumnWidth,
71
+ secondColumnWidth
72
+ )}
73
+ key={cell.id}
74
+ role="cell"
75
+ style={(cell.getValue() as CellProps)?.parentStyle}
76
+ >
77
+ {flexRender(cell.column.columnDef.cell, cell.getContext())}
78
+ </StyledTableData>
79
+ ))}
80
+ </StyledTableRow>
81
+ ))}
82
+ </tbody>
83
+ </StyledTable>
84
+ )
85
+ }
86
+
87
+ const TableNavigationButton = ({ position, hidden, clickHandler }: ITableNavButtonProps) => (
88
+ <StyledNextPageButtonContainer
89
+ role="button"
90
+ elementPosition={position}
91
+ onClick={() => clickHandler()}
92
+ hidden={hidden}
93
+ >
94
+ <Icon type="chevron" direction={position === 'bottom' ? 'down' : 'right'} size="medium" />
95
+ </StyledNextPageButtonContainer>
96
+ )
97
+
98
+ const TableSpinner = ({ position, hidden }: ITableSpinnerProps) => (
99
+ <StyledSpinnerContainer elementPosition={position} hidden={hidden}>
100
+ <Icon type="spinner" size="medium" title="Loading..." />
101
+ </StyledSpinnerContainer>
102
+ )
103
+
104
+ interface ITableNavButtonProps {
105
+ position: 'bottom' | 'right'
106
+ hidden: boolean
107
+ clickHandler: () => void
108
+ }
109
+
110
+ interface ITableSpinnerProps {
111
+ position: 'bottom' | 'right'
112
+ hidden: boolean
113
+ }
114
+
115
+ interface ITableHeadProps<T> extends ITableConfig, HTMLAttributes<HTMLTableElement> {
116
+ table: Table<T>
117
+ }
118
+
119
+ export default TableComponent
120
+ export { TableNavigationButton, TableSpinner }
@@ -1,36 +1,36 @@
1
- import { forwardRef, Ref } from 'react'
2
- import { flexRender, Header as ReactTableHeader } from '@tanstack/react-table'
3
- import { StyledTableHeader } from './table-styled-components'
4
-
5
- interface TableHeaderProps<TData, TValue> {
6
- header: ReactTableHeader<TData, TValue>
7
- stickyWidth?: number
8
- }
9
-
10
- export const Wrapper = <TData, TValue>(
11
- { header, stickyWidth }: TableHeaderProps<TData, TValue>,
12
- ref?: Ref<HTMLTableCellElement>
13
- ) => (
14
- <StyledTableHeader
15
- ref={ref}
16
- stickyWidth={stickyWidth}
17
- colSpan={header.colSpan}
18
- role="columnheader"
19
- {...(header.column.id !== 'expander'
20
- ? {
21
- style: {
22
- cursor: header.column.getCanSort() ? 'pointer' : '',
23
- },
24
- onClick: header.column.getToggleSortingHandler(),
25
- }
26
- : {})}
27
- >
28
- {header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())}
29
- </StyledTableHeader>
30
- )
31
-
32
- const TableHeader = forwardRef(Wrapper) as <TData, TValue>(
33
- props: TableHeaderProps<TData, TValue> & { ref?: Ref<HTMLTableCellElement> }
34
- ) => ReturnType<typeof Wrapper>
35
-
36
- export default TableHeader
1
+ import { forwardRef, Ref } from 'react'
2
+ import { flexRender, Header as ReactTableHeader } from '@tanstack/react-table'
3
+ import { StyledTableHeader } from './table-styled-components'
4
+
5
+ interface TableHeaderProps<TData, TValue> {
6
+ header: ReactTableHeader<TData, TValue>
7
+ stickyWidth?: number
8
+ }
9
+
10
+ export const Wrapper = <TData, TValue>(
11
+ { header, stickyWidth }: TableHeaderProps<TData, TValue>,
12
+ ref?: Ref<HTMLTableCellElement>
13
+ ) => (
14
+ <StyledTableHeader
15
+ ref={ref}
16
+ stickyWidth={stickyWidth}
17
+ colSpan={header.colSpan}
18
+ role="columnheader"
19
+ {...(header.column.id !== 'expander'
20
+ ? {
21
+ style: {
22
+ cursor: header.column.getCanSort() ? 'pointer' : '',
23
+ },
24
+ onClick: header.column.getToggleSortingHandler(),
25
+ }
26
+ : {})}
27
+ >
28
+ {header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())}
29
+ </StyledTableHeader>
30
+ )
31
+
32
+ const TableHeader = forwardRef(Wrapper) as <TData, TValue>(
33
+ props: TableHeaderProps<TData, TValue> & { ref?: Ref<HTMLTableCellElement> }
34
+ ) => ReturnType<typeof Wrapper>
35
+
36
+ export default TableHeader