@oslokommune/punkt-react 11.12.4 → 11.13.0
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 +34 -0
- package/dist/components/icon/DefaultIconFetcher.d.ts +1 -1
- package/dist/components/index.d.ts +4 -1
- package/dist/components/table/Table.d.ts +8 -8
- package/dist/components/table/Table.test.d.ts +1 -1
- package/dist/components/table/TableBody.d.ts +7 -0
- package/dist/components/table/TableDataCell.d.ts +8 -0
- package/dist/components/table/TableHeader.d.ts +4 -3
- package/dist/components/table/TableHeaderCell.d.ts +7 -0
- package/dist/components/table/TableRow.d.ts +7 -0
- package/dist/punkt-react.es.js +621 -605
- package/dist/punkt-react.umd.js +13 -13
- package/package.json +3 -3
- package/src/components/index.ts +4 -1
- package/src/components/table/Table.test.tsx +48 -89
- package/src/components/table/Table.tsx +24 -24
- package/src/components/table/TableBody.tsx +13 -0
- package/src/components/table/TableDataCell.tsx +19 -0
- package/src/components/table/TableHeader.tsx +9 -3
- package/src/components/table/TableHeaderCell.tsx +13 -0
- package/src/components/table/TableRow.tsx +13 -0
- package/src/components/table/__snapshots__/Table.test.tsx.snap +0 -137
|
@@ -1,105 +1,64 @@
|
|
|
1
|
-
import { render } from '@testing-library/react'
|
|
2
1
|
import * as React from 'react'
|
|
2
|
+
import { axe, toHaveNoViolations } from 'jest-axe'
|
|
3
|
+
import { render, screen } from '@testing-library/react'
|
|
4
|
+
import '@testing-library/jest-dom'
|
|
3
5
|
|
|
4
6
|
import { PktTable } from './Table'
|
|
5
7
|
import { PktTableHeader } from './TableHeader'
|
|
8
|
+
import { PktTableRow } from './TableRow'
|
|
9
|
+
import { PktTableBody } from './TableBody'
|
|
10
|
+
import { PktTableHeaderCell } from './TableHeaderCell'
|
|
11
|
+
import { PktTableDataCell } from './TableDataCell'
|
|
6
12
|
|
|
7
|
-
|
|
8
|
-
it('renders correctly without modifiers', () => {
|
|
9
|
-
const { asFragment } = render(
|
|
10
|
-
<PktTable>
|
|
11
|
-
<thead>
|
|
12
|
-
<tr>
|
|
13
|
-
<PktTableHeader>Header 1</PktTableHeader>
|
|
14
|
-
<PktTableHeader>Header 2</PktTableHeader>
|
|
15
|
-
</tr>
|
|
16
|
-
</thead>
|
|
17
|
-
<tbody>
|
|
18
|
-
<tr>
|
|
19
|
-
<td>Table data</td>
|
|
20
|
-
<td>Table data</td>
|
|
21
|
-
</tr>
|
|
22
|
-
</tbody>
|
|
23
|
-
</PktTable>,
|
|
24
|
-
)
|
|
13
|
+
expect.extend(toHaveNoViolations)
|
|
25
14
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
<PktTableHeader>Header 2</PktTableHeader>
|
|
43
|
-
</tr>
|
|
44
|
-
</thead>
|
|
45
|
-
<tbody>
|
|
46
|
-
<tr>
|
|
47
|
-
<td>Table data</td>
|
|
48
|
-
<td>Table data</td>
|
|
49
|
-
</tr>
|
|
50
|
-
</tbody>
|
|
51
|
-
</PktTable>,
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
expect(asFragment()).toMatchSnapshot()
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
it('renders correctly with modifier values false', () => {
|
|
58
|
-
const { asFragment } = render(
|
|
59
|
-
<PktTable
|
|
60
|
-
modifiers={{
|
|
61
|
-
info: false,
|
|
62
|
-
success: false,
|
|
63
|
-
strong: false,
|
|
64
|
-
shadow: false,
|
|
65
|
-
}}
|
|
66
|
-
>
|
|
67
|
-
<thead>
|
|
68
|
-
<tr>
|
|
69
|
-
<PktTableHeader>Header 1</PktTableHeader>
|
|
70
|
-
<PktTableHeader>Header 2</PktTableHeader>
|
|
71
|
-
</tr>
|
|
72
|
-
</thead>
|
|
73
|
-
<tbody>
|
|
74
|
-
<tr>
|
|
75
|
-
<td>Table data</td>
|
|
76
|
-
<td>Table data</td>
|
|
77
|
-
</tr>
|
|
78
|
-
</tbody>
|
|
15
|
+
describe('<PktTable />', () => {
|
|
16
|
+
test('renders correctly with defaultprops', () => {
|
|
17
|
+
render(
|
|
18
|
+
<PktTable>
|
|
19
|
+
<PktTableHeader>
|
|
20
|
+
<PktTableRow>
|
|
21
|
+
<PktTableHeaderCell>Header 1</PktTableHeaderCell>
|
|
22
|
+
<PktTableHeaderCell>Header 2</PktTableHeaderCell>
|
|
23
|
+
</PktTableRow>
|
|
24
|
+
</PktTableHeader>
|
|
25
|
+
<PktTableBody>
|
|
26
|
+
<PktTableRow>
|
|
27
|
+
<PktTableDataCell>Table data 1</PktTableDataCell>
|
|
28
|
+
<PktTableDataCell>Table data 2</PktTableDataCell>
|
|
29
|
+
</PktTableRow>
|
|
30
|
+
</PktTableBody>
|
|
79
31
|
</PktTable>,
|
|
80
32
|
)
|
|
81
33
|
|
|
82
|
-
|
|
34
|
+
// Assert that the component renders its children correctly
|
|
35
|
+
expect(screen.getByTestId('pkt-table')).toHaveClass('pkt-table--basic')
|
|
36
|
+
expect(screen.getByText('Header 1')).toBeInTheDocument()
|
|
37
|
+
expect(screen.getByText('Header 2')).toBeInTheDocument()
|
|
38
|
+
expect(screen.getByText('Table data 1')).toBeInTheDocument()
|
|
39
|
+
expect(screen.getByText('Table data 2')).toBeInTheDocument()
|
|
83
40
|
})
|
|
84
41
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
<PktTable
|
|
88
|
-
<
|
|
89
|
-
<
|
|
90
|
-
<
|
|
91
|
-
<
|
|
92
|
-
</
|
|
93
|
-
</
|
|
94
|
-
<
|
|
95
|
-
<
|
|
96
|
-
<
|
|
97
|
-
<
|
|
98
|
-
</
|
|
99
|
-
</
|
|
42
|
+
test('renders correctly with skin "zebra-blue" and compact set to true', () => {
|
|
43
|
+
render(
|
|
44
|
+
<PktTable skin="zebra-blue" compact>
|
|
45
|
+
<PktTableHeader>
|
|
46
|
+
<PktTableRow>
|
|
47
|
+
<PktTableHeaderCell>Header 1</PktTableHeaderCell>
|
|
48
|
+
<PktTableHeaderCell>Header 2</PktTableHeaderCell>
|
|
49
|
+
</PktTableRow>
|
|
50
|
+
</PktTableHeader>
|
|
51
|
+
<PktTableBody>
|
|
52
|
+
<PktTableRow>
|
|
53
|
+
<PktTableDataCell dataLabel="Header 1">Table data</PktTableDataCell>
|
|
54
|
+
<PktTableDataCell dataLabel="Header 2">Table data</PktTableDataCell>
|
|
55
|
+
</PktTableRow>
|
|
56
|
+
</PktTableBody>
|
|
100
57
|
</PktTable>,
|
|
101
58
|
)
|
|
102
59
|
|
|
103
|
-
|
|
60
|
+
// Assert that the component applies the props correctly
|
|
61
|
+
expect(screen.getByTestId('pkt-table')).toHaveClass('pkt-table--compact')
|
|
62
|
+
expect(screen.getByTestId('pkt-table')).toHaveClass('pkt-table--zebra-blue')
|
|
104
63
|
})
|
|
105
64
|
})
|
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
import classNames from 'classnames'
|
|
2
2
|
import * as React from 'react'
|
|
3
3
|
|
|
4
|
-
export type
|
|
4
|
+
export type TTableSkin = 'basic' | 'zebra-blue'
|
|
5
5
|
|
|
6
|
-
interface
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const ResponsiveWrapper = ({ isResponsive, children }: TableProps) => {
|
|
13
|
-
return isResponsive ? <div className="pkt-table-container">{children}</div> : <>{children}</>
|
|
6
|
+
interface ITableProps {
|
|
7
|
+
compact?: boolean
|
|
8
|
+
skin?: 'basic' | 'zebra-blue'
|
|
9
|
+
responsiveView?: boolean
|
|
10
|
+
className?: string
|
|
11
|
+
children: React.ReactNode
|
|
14
12
|
}
|
|
15
13
|
|
|
16
14
|
export const PktTable = ({
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
className,
|
|
16
|
+
compact = false,
|
|
17
|
+
skin = 'basic',
|
|
18
|
+
responsiveView = true,
|
|
19
19
|
children,
|
|
20
|
-
}:
|
|
20
|
+
}: ITableProps) => {
|
|
21
21
|
return (
|
|
22
|
-
<
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
</
|
|
22
|
+
<table
|
|
23
|
+
data-testid="pkt-table"
|
|
24
|
+
className={classNames(className, 'pkt-table', {
|
|
25
|
+
'pkt-table--responsive': responsiveView,
|
|
26
|
+
'pkt-table--compact': compact,
|
|
27
|
+
'pkt-table--basic': skin === 'basic',
|
|
28
|
+
'pkt-table--zebra-blue': skin === 'zebra-blue',
|
|
29
|
+
})}
|
|
30
|
+
role="table"
|
|
31
|
+
>
|
|
32
|
+
{children}
|
|
33
|
+
</table>
|
|
34
34
|
)
|
|
35
35
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import classNames from 'classnames'
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
|
|
4
|
+
interface ITableBodyProps {
|
|
5
|
+
className?: string
|
|
6
|
+
children: React.ReactNode
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const PktTableBody = ({ children, className }: ITableBodyProps) => (
|
|
10
|
+
<tbody className={classNames(className, 'pkt-table__body', {})} role="rowgroup">
|
|
11
|
+
{children}
|
|
12
|
+
</tbody>
|
|
13
|
+
)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import classNames from 'classnames'
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
|
|
4
|
+
interface ITableDataCellProps {
|
|
5
|
+
className?: string
|
|
6
|
+
children: React.ReactNode
|
|
7
|
+
dataLabel?: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const PktTableDataCell = ({ children, className, dataLabel }: ITableDataCellProps) => (
|
|
11
|
+
<td
|
|
12
|
+
className={classNames(className, 'pkt-table__data-cell', {})}
|
|
13
|
+
data-label={dataLabel}
|
|
14
|
+
role="cell"
|
|
15
|
+
data-testid="pkt-table__data-cell"
|
|
16
|
+
>
|
|
17
|
+
{children}
|
|
18
|
+
</td>
|
|
19
|
+
)
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
import classNames from 'classnames'
|
|
1
2
|
import * as React from 'react'
|
|
2
3
|
|
|
3
|
-
interface
|
|
4
|
-
|
|
4
|
+
interface ITableHeaderProps {
|
|
5
|
+
className?: string
|
|
6
|
+
children: React.ReactNode
|
|
5
7
|
}
|
|
6
8
|
|
|
7
|
-
export const PktTableHeader = ({ children }:
|
|
9
|
+
export const PktTableHeader = ({ className, children }: ITableHeaderProps) => (
|
|
10
|
+
<thead className={classNames(className, 'pkt-table__header', {})} role="rowgroup">
|
|
11
|
+
{children}
|
|
12
|
+
</thead>
|
|
13
|
+
)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import classNames from 'classnames'
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
|
|
4
|
+
interface ITableHeaderCellProps {
|
|
5
|
+
className?: string
|
|
6
|
+
children: React.ReactNode
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const PktTableHeaderCell = ({ className, children }: ITableHeaderCellProps) => (
|
|
10
|
+
<th className={classNames(className, 'pkt-table__header-cell', {})} role="columnheader">
|
|
11
|
+
{children}
|
|
12
|
+
</th>
|
|
13
|
+
)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import classNames from 'classnames'
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
|
|
4
|
+
interface ITableRowProps {
|
|
5
|
+
className?: string
|
|
6
|
+
children: React.ReactNode
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const PktTableRow = ({ className, children }: ITableRowProps) => (
|
|
10
|
+
<tr className={classNames(className, 'pkt-table__row', {})} role="row">
|
|
11
|
+
{children}
|
|
12
|
+
</tr>
|
|
13
|
+
)
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`<Table /> renders correctly with modifier values false 1`] = `
|
|
4
|
-
<DocumentFragment>
|
|
5
|
-
<table
|
|
6
|
-
class="pkt-table"
|
|
7
|
-
>
|
|
8
|
-
<thead>
|
|
9
|
-
<tr>
|
|
10
|
-
<th
|
|
11
|
-
class="pkt-table__th"
|
|
12
|
-
>
|
|
13
|
-
Header 1
|
|
14
|
-
</th>
|
|
15
|
-
<th
|
|
16
|
-
class="pkt-table__th"
|
|
17
|
-
>
|
|
18
|
-
Header 2
|
|
19
|
-
</th>
|
|
20
|
-
</tr>
|
|
21
|
-
</thead>
|
|
22
|
-
<tbody>
|
|
23
|
-
<tr>
|
|
24
|
-
<td>
|
|
25
|
-
Table data
|
|
26
|
-
</td>
|
|
27
|
-
<td>
|
|
28
|
-
Table data
|
|
29
|
-
</td>
|
|
30
|
-
</tr>
|
|
31
|
-
</tbody>
|
|
32
|
-
</table>
|
|
33
|
-
</DocumentFragment>
|
|
34
|
-
`;
|
|
35
|
-
|
|
36
|
-
exports[`<Table /> renders correctly with modifier values true 1`] = `
|
|
37
|
-
<DocumentFragment>
|
|
38
|
-
<table
|
|
39
|
-
class="pkt-table pkt-table--info pkt-table--success pkt-table--strong pkt-table--shadow"
|
|
40
|
-
>
|
|
41
|
-
<thead>
|
|
42
|
-
<tr>
|
|
43
|
-
<th
|
|
44
|
-
class="pkt-table__th"
|
|
45
|
-
>
|
|
46
|
-
Header 1
|
|
47
|
-
</th>
|
|
48
|
-
<th
|
|
49
|
-
class="pkt-table__th"
|
|
50
|
-
>
|
|
51
|
-
Header 2
|
|
52
|
-
</th>
|
|
53
|
-
</tr>
|
|
54
|
-
</thead>
|
|
55
|
-
<tbody>
|
|
56
|
-
<tr>
|
|
57
|
-
<td>
|
|
58
|
-
Table data
|
|
59
|
-
</td>
|
|
60
|
-
<td>
|
|
61
|
-
Table data
|
|
62
|
-
</td>
|
|
63
|
-
</tr>
|
|
64
|
-
</tbody>
|
|
65
|
-
</table>
|
|
66
|
-
</DocumentFragment>
|
|
67
|
-
`;
|
|
68
|
-
|
|
69
|
-
exports[`<Table /> renders correctly without modifiers 1`] = `
|
|
70
|
-
<DocumentFragment>
|
|
71
|
-
<table
|
|
72
|
-
class="pkt-table"
|
|
73
|
-
>
|
|
74
|
-
<thead>
|
|
75
|
-
<tr>
|
|
76
|
-
<th
|
|
77
|
-
class="pkt-table__th"
|
|
78
|
-
>
|
|
79
|
-
Header 1
|
|
80
|
-
</th>
|
|
81
|
-
<th
|
|
82
|
-
class="pkt-table__th"
|
|
83
|
-
>
|
|
84
|
-
Header 2
|
|
85
|
-
</th>
|
|
86
|
-
</tr>
|
|
87
|
-
</thead>
|
|
88
|
-
<tbody>
|
|
89
|
-
<tr>
|
|
90
|
-
<td>
|
|
91
|
-
Table data
|
|
92
|
-
</td>
|
|
93
|
-
<td>
|
|
94
|
-
Table data
|
|
95
|
-
</td>
|
|
96
|
-
</tr>
|
|
97
|
-
</tbody>
|
|
98
|
-
</table>
|
|
99
|
-
</DocumentFragment>
|
|
100
|
-
`;
|
|
101
|
-
|
|
102
|
-
exports[`<Table /> renders with responsive container 1`] = `
|
|
103
|
-
<DocumentFragment>
|
|
104
|
-
<div
|
|
105
|
-
class="pkt-table-container"
|
|
106
|
-
>
|
|
107
|
-
<table
|
|
108
|
-
class="pkt-table"
|
|
109
|
-
>
|
|
110
|
-
<thead>
|
|
111
|
-
<tr>
|
|
112
|
-
<th
|
|
113
|
-
class="pkt-table__th"
|
|
114
|
-
>
|
|
115
|
-
Header 1
|
|
116
|
-
</th>
|
|
117
|
-
<th
|
|
118
|
-
class="pkt-table__th"
|
|
119
|
-
>
|
|
120
|
-
Header 2
|
|
121
|
-
</th>
|
|
122
|
-
</tr>
|
|
123
|
-
</thead>
|
|
124
|
-
<tbody>
|
|
125
|
-
<tr>
|
|
126
|
-
<td>
|
|
127
|
-
Table data
|
|
128
|
-
</td>
|
|
129
|
-
<td>
|
|
130
|
-
Table data
|
|
131
|
-
</td>
|
|
132
|
-
</tr>
|
|
133
|
-
</tbody>
|
|
134
|
-
</table>
|
|
135
|
-
</div>
|
|
136
|
-
</DocumentFragment>
|
|
137
|
-
`;
|