@navikt/ds-react 0.14.0-beta.1 → 0.14.3
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/LICENCE +31 -0
- package/cjs/form/Switch.js +58 -0
- package/cjs/form/index.js +3 -1
- package/cjs/table/DataCell.js +5 -2
- package/cjs/table/HeaderCell.js +4 -2
- package/cjs/table/Row.js +4 -2
- package/cjs/table/Table.js +7 -2
- package/esm/form/Switch.d.ts +18 -0
- package/esm/form/Switch.js +35 -0
- package/esm/form/Switch.js.map +1 -0
- package/esm/form/index.d.ts +1 -0
- package/esm/form/index.js +1 -0
- package/esm/form/index.js.map +1 -1
- package/esm/table/DataCell.js +6 -3
- package/esm/table/DataCell.js.map +1 -1
- package/esm/table/HeaderCell.d.ts +1 -0
- package/esm/table/HeaderCell.js +5 -3
- package/esm/table/HeaderCell.js.map +1 -1
- package/esm/table/Row.d.ts +5 -0
- package/esm/table/Row.js +4 -2
- package/esm/table/Row.js.map +1 -1
- package/esm/table/Table.d.ts +9 -0
- package/esm/table/Table.js +7 -3
- package/esm/table/Table.js.map +1 -1
- package/package.json +5 -7
- package/src/form/Switch.tsx +81 -0
- package/src/form/index.ts +1 -0
- package/src/form/stories/switch.stories.mdx +104 -0
- package/src/form/stories/switch.stories.tsx +70 -0
- package/src/table/DataCell.tsx +20 -4
- package/src/table/HeaderCell.tsx +22 -5
- package/src/table/Row.tsx +18 -4
- package/src/table/Table.tsx +25 -8
- package/src/table/stories/table.stories.tsx +157 -74
- package/dist/complete.js +0 -15978
- package/dist/partial.js +0 -4039
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Meta, Canvas } from "@storybook/addon-docs";
|
|
2
|
+
import { Switch } from "../index";
|
|
3
|
+
|
|
4
|
+
<Meta title="ds-react/form/switch/intro" />
|
|
5
|
+
|
|
6
|
+
# Hvordan ta i bruk Switch
|
|
7
|
+
|
|
8
|
+
```jsx
|
|
9
|
+
<Switch>Slå på feature</Switch>
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
<Canvas>
|
|
13
|
+
<Switch>Slå på feature</Switch>
|
|
14
|
+
</Canvas>
|
|
15
|
+
|
|
16
|
+
## Description
|
|
17
|
+
|
|
18
|
+
```jsx
|
|
19
|
+
<Switch description="Dette vil gjøre x og y">Slå på feature</Switch>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
<Canvas>
|
|
23
|
+
<Switch description="Dette vil gjøre x og y">Slå på feature</Switch>
|
|
24
|
+
</Canvas>
|
|
25
|
+
|
|
26
|
+
## Sizing
|
|
27
|
+
|
|
28
|
+
Switch har default 48px høy klikkflate. Med size="small" blir klikkflaten 32px
|
|
29
|
+
|
|
30
|
+
```jsx
|
|
31
|
+
<Switch size="small" >Slå på feature</Switch>
|
|
32
|
+
<Switch size="small" description="Dette vil gjøre x og y">Slå på feature</Switch>
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
<Canvas>
|
|
36
|
+
<div>
|
|
37
|
+
<Switch size="small">Slå på feature</Switch>
|
|
38
|
+
<Switch size="small" description="Dette vil gjøre x og y">
|
|
39
|
+
Slå på feature
|
|
40
|
+
</Switch>
|
|
41
|
+
</div>
|
|
42
|
+
</Canvas>
|
|
43
|
+
|
|
44
|
+
## defaultChecked
|
|
45
|
+
|
|
46
|
+
Switch er en stylet checkbox, så både `checked` og `defaultChecked` fungerer
|
|
47
|
+
|
|
48
|
+
```jsx
|
|
49
|
+
<Switch defaultChecked>Slå på feature</Switch>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
<Canvas>
|
|
53
|
+
<Switch defaultChecked>Slå på feature</Switch>
|
|
54
|
+
</Canvas>
|
|
55
|
+
|
|
56
|
+
## hideLabel
|
|
57
|
+
|
|
58
|
+
Ved bruk av `hideLegend` på Switch kan man gjøre slik at legend/description bare vises for skjermlesere
|
|
59
|
+
|
|
60
|
+
```jsx
|
|
61
|
+
<Switch hideLabel>Slå på feature</Switch>
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
<Canvas>
|
|
65
|
+
<Switch hideLabel>Slå på feature</Switch>
|
|
66
|
+
</Canvas>
|
|
67
|
+
|
|
68
|
+
## Disabled
|
|
69
|
+
|
|
70
|
+
Ved bruk av `disabled` kan man både disabled enkelte checkboxer eller checkboxgruppen.
|
|
71
|
+
|
|
72
|
+
NOTE: Husk at disabled bør unngås!
|
|
73
|
+
|
|
74
|
+
```jsx
|
|
75
|
+
<Switch disabled>Slå på feature</Switch>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
<Canvas>
|
|
79
|
+
<div>
|
|
80
|
+
<Switch disabled>Slå på feature</Switch>
|
|
81
|
+
<Switch disabled defaultChecked>
|
|
82
|
+
Slå på feature
|
|
83
|
+
</Switch>
|
|
84
|
+
</div>
|
|
85
|
+
</Canvas>
|
|
86
|
+
|
|
87
|
+
## Loading
|
|
88
|
+
|
|
89
|
+
Om systemet bruker tid på å utføre handlingen vises en loading-indikator på switch’en.
|
|
90
|
+
Om ventetiden er mer enn noen sekunder bør en forklarende tekst også vises.
|
|
91
|
+
Teksten må forklare kort og godt hvorfor brukeren må vente.
|
|
92
|
+
|
|
93
|
+
```jsx
|
|
94
|
+
<Switch loading>Slå på feature</Switch>
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
<Canvas>
|
|
98
|
+
<div>
|
|
99
|
+
<Switch loading>Slå på feature</Switch>
|
|
100
|
+
<Switch loading defaultChecked>
|
|
101
|
+
Slå på feature
|
|
102
|
+
</Switch>
|
|
103
|
+
</div>
|
|
104
|
+
</Canvas>
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import { Switch } from "../index";
|
|
3
|
+
import { Meta } from "@storybook/react/types-6-0";
|
|
4
|
+
import { Fieldset } from "../..";
|
|
5
|
+
export default {
|
|
6
|
+
title: "ds-react/form/switch",
|
|
7
|
+
component: Switch,
|
|
8
|
+
} as Meta;
|
|
9
|
+
|
|
10
|
+
export const All = () => {
|
|
11
|
+
const [checked, setChecked] = useState(false);
|
|
12
|
+
return (
|
|
13
|
+
<div>
|
|
14
|
+
<h1>Switch</h1>
|
|
15
|
+
<Switch>Label text</Switch>
|
|
16
|
+
|
|
17
|
+
<h2>Switch w/Description</h2>
|
|
18
|
+
<Switch>Label text</Switch>
|
|
19
|
+
<Switch description="Switch description">Label text</Switch>
|
|
20
|
+
<Switch>Label text</Switch>
|
|
21
|
+
|
|
22
|
+
<h2>hidelabel</h2>
|
|
23
|
+
<Switch description="Switch description" hideLabel>
|
|
24
|
+
Label text
|
|
25
|
+
</Switch>
|
|
26
|
+
<Switch description="Switch description" hideLabel>
|
|
27
|
+
Label text
|
|
28
|
+
</Switch>
|
|
29
|
+
<Switch hideLabel size="small">
|
|
30
|
+
Label text small
|
|
31
|
+
</Switch>
|
|
32
|
+
|
|
33
|
+
<h2>Switch small</h2>
|
|
34
|
+
<Switch size="small">Label text</Switch>
|
|
35
|
+
<Switch description="Switch description" size="small">
|
|
36
|
+
Label text
|
|
37
|
+
</Switch>
|
|
38
|
+
<Switch size="small">Label text</Switch>
|
|
39
|
+
|
|
40
|
+
<h2>Controlled</h2>
|
|
41
|
+
<Switch checked={checked} onChange={() => setChecked(!checked)}>
|
|
42
|
+
Label text
|
|
43
|
+
</Switch>
|
|
44
|
+
|
|
45
|
+
<h2>Defaultchecked</h2>
|
|
46
|
+
<Switch defaultChecked>Label text</Switch>
|
|
47
|
+
|
|
48
|
+
<h2>Disabled</h2>
|
|
49
|
+
<Switch disabled>Label text</Switch>
|
|
50
|
+
<Switch disabled defaultChecked>
|
|
51
|
+
Label text
|
|
52
|
+
</Switch>
|
|
53
|
+
|
|
54
|
+
<h2>With fieldset error</h2>
|
|
55
|
+
<Fieldset legend="Fieldset legend" error="Errormsg">
|
|
56
|
+
<Switch defaultChecked>Label text</Switch>
|
|
57
|
+
<Switch>Label text</Switch>
|
|
58
|
+
</Fieldset>
|
|
59
|
+
|
|
60
|
+
<h2>loading prop</h2>
|
|
61
|
+
<Switch loading>Label text</Switch>
|
|
62
|
+
<Switch size="small" loading>
|
|
63
|
+
Label text
|
|
64
|
+
</Switch>
|
|
65
|
+
<Switch disabled loading>
|
|
66
|
+
Label text
|
|
67
|
+
</Switch>
|
|
68
|
+
</div>
|
|
69
|
+
);
|
|
70
|
+
};
|
package/src/table/DataCell.tsx
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import React, { forwardRef } from "react";
|
|
1
|
+
import React, { forwardRef, useContext } from "react";
|
|
2
2
|
import cl from "classnames";
|
|
3
|
+
import { BodyShort } from "..";
|
|
4
|
+
import { TableContext } from ".";
|
|
3
5
|
|
|
4
6
|
interface DataCellProps extends React.HTMLAttributes<HTMLTableCellElement> {}
|
|
5
7
|
|
|
@@ -8,8 +10,22 @@ export interface DataCellType
|
|
|
8
10
|
DataCellProps & React.RefAttributes<HTMLTableCellElement>
|
|
9
11
|
> {}
|
|
10
12
|
|
|
11
|
-
const DataCell: DataCellType = forwardRef(
|
|
12
|
-
|
|
13
|
-
)
|
|
13
|
+
const DataCell: DataCellType = forwardRef(
|
|
14
|
+
({ className, children = "", ...rest }, ref) => {
|
|
15
|
+
const context = useContext(TableContext);
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<BodyShort
|
|
19
|
+
as="td"
|
|
20
|
+
ref={ref}
|
|
21
|
+
className={cl("navds-table__data-cell", className)}
|
|
22
|
+
size={context?.size}
|
|
23
|
+
{...rest}
|
|
24
|
+
>
|
|
25
|
+
{children}
|
|
26
|
+
</BodyShort>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
);
|
|
14
30
|
|
|
15
31
|
export default DataCell;
|
package/src/table/HeaderCell.tsx
CHANGED
|
@@ -1,15 +1,32 @@
|
|
|
1
|
-
import React, { forwardRef } from "react";
|
|
1
|
+
import React, { forwardRef, useContext } from "react";
|
|
2
2
|
import cl from "classnames";
|
|
3
|
+
import { Label, TableContext } from "..";
|
|
3
4
|
|
|
4
|
-
interface HeaderCellProps extends React.HTMLAttributes<HTMLTableCellElement> {
|
|
5
|
+
interface HeaderCellProps extends React.HTMLAttributes<HTMLTableCellElement> {
|
|
6
|
+
scope?: string;
|
|
7
|
+
}
|
|
5
8
|
|
|
6
9
|
export interface HeaderCellType
|
|
7
10
|
extends React.ForwardRefExoticComponent<
|
|
8
11
|
HeaderCellProps & React.RefAttributes<HTMLTableCellElement>
|
|
9
12
|
> {}
|
|
10
13
|
|
|
11
|
-
const HeaderCell: HeaderCellType = forwardRef(
|
|
12
|
-
|
|
13
|
-
)
|
|
14
|
+
const HeaderCell: HeaderCellType = forwardRef(
|
|
15
|
+
({ className, children, ...rest }, ref) => {
|
|
16
|
+
const context = useContext(TableContext);
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<Label
|
|
20
|
+
as="th"
|
|
21
|
+
ref={ref}
|
|
22
|
+
className={cl("navds-table__header-cell", className)}
|
|
23
|
+
size={context?.size}
|
|
24
|
+
{...rest}
|
|
25
|
+
>
|
|
26
|
+
{children}
|
|
27
|
+
</Label>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
);
|
|
14
31
|
|
|
15
32
|
export default HeaderCell;
|
package/src/table/Row.tsx
CHANGED
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
import React, { forwardRef } from "react";
|
|
2
2
|
import cl from "classnames";
|
|
3
3
|
|
|
4
|
-
interface RowProps extends React.HTMLAttributes<HTMLTableRowElement> {
|
|
4
|
+
interface RowProps extends React.HTMLAttributes<HTMLTableRowElement> {
|
|
5
|
+
/**
|
|
6
|
+
* Row is selected
|
|
7
|
+
* @default false
|
|
8
|
+
*/
|
|
9
|
+
selected?: boolean;
|
|
10
|
+
}
|
|
5
11
|
|
|
6
12
|
export interface RowType
|
|
7
13
|
extends React.ForwardRefExoticComponent<
|
|
8
14
|
RowProps & React.RefAttributes<HTMLTableRowElement>
|
|
9
15
|
> {}
|
|
10
16
|
|
|
11
|
-
const Row: RowType = forwardRef(
|
|
12
|
-
|
|
13
|
-
|
|
17
|
+
const Row: RowType = forwardRef(
|
|
18
|
+
({ className, selected = false, ...rest }, ref) => (
|
|
19
|
+
<tr
|
|
20
|
+
{...rest}
|
|
21
|
+
ref={ref}
|
|
22
|
+
className={cl("navds-table__row", className, {
|
|
23
|
+
"navds-table__row--selected": selected,
|
|
24
|
+
})}
|
|
25
|
+
/>
|
|
26
|
+
)
|
|
27
|
+
);
|
|
14
28
|
|
|
15
29
|
export default Row;
|
package/src/table/Table.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { forwardRef } from "react";
|
|
1
|
+
import React, { createContext, forwardRef } from "react";
|
|
2
2
|
import cl from "classnames";
|
|
3
3
|
import Header, { HeaderType } from "./Header";
|
|
4
4
|
import Body, { BodyType } from "./Body";
|
|
@@ -12,6 +12,11 @@ export interface TableProps extends React.HTMLAttributes<HTMLTableElement> {
|
|
|
12
12
|
* @default "medium"
|
|
13
13
|
*/
|
|
14
14
|
size?: "medium" | "small";
|
|
15
|
+
/**
|
|
16
|
+
* Zebra striped table
|
|
17
|
+
* @default false
|
|
18
|
+
*/
|
|
19
|
+
zebraStripes?: boolean;
|
|
15
20
|
}
|
|
16
21
|
|
|
17
22
|
export interface TableType
|
|
@@ -25,13 +30,25 @@ export interface TableType
|
|
|
25
30
|
HeaderCell: HeaderCellType;
|
|
26
31
|
}
|
|
27
32
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
export interface TableContextProps {
|
|
34
|
+
size: "medium" | "small";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const TableContext = createContext<TableContextProps | null>(null);
|
|
38
|
+
|
|
39
|
+
const Table = forwardRef(
|
|
40
|
+
({ className, zebraStripes = false, size = "medium", ...rest }, ref) => (
|
|
41
|
+
<TableContext.Provider value={{ size }}>
|
|
42
|
+
<table
|
|
43
|
+
{...rest}
|
|
44
|
+
ref={ref}
|
|
45
|
+
className={cl("navds-table", `navds-table--${size}`, className, {
|
|
46
|
+
"navds-table--zebra-stripes": zebraStripes,
|
|
47
|
+
})}
|
|
48
|
+
/>
|
|
49
|
+
</TableContext.Provider>
|
|
50
|
+
)
|
|
51
|
+
) as TableType;
|
|
35
52
|
|
|
36
53
|
Table.Header = Header;
|
|
37
54
|
Table.Body = Body;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { useState } from "react";
|
|
2
2
|
import { Table } from "../index";
|
|
3
|
-
import { Alert, Link } from "@navikt/ds-react";
|
|
3
|
+
import { Alert, Checkbox, Link } from "@navikt/ds-react";
|
|
4
4
|
|
|
5
5
|
export default {
|
|
6
6
|
title: "ds-react/table",
|
|
@@ -8,70 +8,46 @@ export default {
|
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
export const All = () => {
|
|
11
|
+
const TableComponent = (props) => (
|
|
12
|
+
<Table {...props}>
|
|
13
|
+
<Table.Header>
|
|
14
|
+
<Table.Row>
|
|
15
|
+
<Table.HeaderCell>ID</Table.HeaderCell>
|
|
16
|
+
<Table.HeaderCell>Fornavn</Table.HeaderCell>
|
|
17
|
+
<Table.HeaderCell>Etternavn</Table.HeaderCell>
|
|
18
|
+
<Table.HeaderCell>Rolle</Table.HeaderCell>
|
|
19
|
+
</Table.Row>
|
|
20
|
+
</Table.Header>
|
|
21
|
+
<Table.Body>
|
|
22
|
+
<Table.Row>
|
|
23
|
+
<Table.HeaderCell>1</Table.HeaderCell>
|
|
24
|
+
<Table.DataCell>Jean-Luc</Table.DataCell>
|
|
25
|
+
<Table.DataCell>Picard</Table.DataCell>
|
|
26
|
+
<Table.DataCell>Kaptein</Table.DataCell>
|
|
27
|
+
</Table.Row>
|
|
28
|
+
<Table.Row>
|
|
29
|
+
<Table.HeaderCell>2</Table.HeaderCell>
|
|
30
|
+
<Table.DataCell>William</Table.DataCell>
|
|
31
|
+
<Table.DataCell>Riker</Table.DataCell>
|
|
32
|
+
<Table.DataCell>Kommandør</Table.DataCell>
|
|
33
|
+
</Table.Row>
|
|
34
|
+
<Table.Row>
|
|
35
|
+
<Table.HeaderCell>3</Table.HeaderCell>
|
|
36
|
+
<Table.DataCell>Geordi</Table.DataCell>
|
|
37
|
+
<Table.DataCell>La Forge</Table.DataCell>
|
|
38
|
+
<Table.DataCell>Sjefsingeniør</Table.DataCell>
|
|
39
|
+
</Table.Row>
|
|
40
|
+
</Table.Body>
|
|
41
|
+
</Table>
|
|
42
|
+
);
|
|
11
43
|
return (
|
|
12
44
|
<>
|
|
13
45
|
<h1>Table</h1>
|
|
14
|
-
<
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
<Table.HeaderCell>ID</Table.HeaderCell>
|
|
18
|
-
<Table.HeaderCell>Fornavn</Table.HeaderCell>
|
|
19
|
-
<Table.HeaderCell>Etternavn</Table.HeaderCell>
|
|
20
|
-
<Table.HeaderCell>Rolle</Table.HeaderCell>
|
|
21
|
-
</Table.Row>
|
|
22
|
-
</Table.Header>
|
|
23
|
-
<Table.Body>
|
|
24
|
-
<Table.Row>
|
|
25
|
-
<Table.HeaderCell>1</Table.HeaderCell>
|
|
26
|
-
<Table.DataCell>Jean-Luc</Table.DataCell>
|
|
27
|
-
<Table.DataCell>Picard</Table.DataCell>
|
|
28
|
-
<Table.DataCell>Kaptein</Table.DataCell>
|
|
29
|
-
</Table.Row>
|
|
30
|
-
<Table.Row>
|
|
31
|
-
<Table.HeaderCell>2</Table.HeaderCell>
|
|
32
|
-
<Table.DataCell>William</Table.DataCell>
|
|
33
|
-
<Table.DataCell>Riker</Table.DataCell>
|
|
34
|
-
<Table.DataCell>Kommandør</Table.DataCell>
|
|
35
|
-
</Table.Row>
|
|
36
|
-
<Table.Row>
|
|
37
|
-
<Table.HeaderCell>3</Table.HeaderCell>
|
|
38
|
-
<Table.DataCell>Geordi</Table.DataCell>
|
|
39
|
-
<Table.DataCell>La Forge</Table.DataCell>
|
|
40
|
-
<Table.DataCell>Sjefsingeniør</Table.DataCell>
|
|
41
|
-
</Table.Row>
|
|
42
|
-
</Table.Body>
|
|
43
|
-
</Table>
|
|
46
|
+
<TableComponent />
|
|
47
|
+
<h2>Zebra</h2>
|
|
48
|
+
<TableComponent zebraStripes />
|
|
44
49
|
<h2>Small Table</h2>
|
|
45
|
-
<
|
|
46
|
-
<Table.Header>
|
|
47
|
-
<Table.Row>
|
|
48
|
-
<Table.HeaderCell>ID</Table.HeaderCell>
|
|
49
|
-
<Table.HeaderCell>Fornavn</Table.HeaderCell>
|
|
50
|
-
<Table.HeaderCell>Etternavn</Table.HeaderCell>
|
|
51
|
-
<Table.HeaderCell>Rolle</Table.HeaderCell>
|
|
52
|
-
</Table.Row>
|
|
53
|
-
</Table.Header>
|
|
54
|
-
<Table.Body>
|
|
55
|
-
<Table.Row>
|
|
56
|
-
<Table.HeaderCell>1</Table.HeaderCell>
|
|
57
|
-
<Table.DataCell>Jean-Luc</Table.DataCell>
|
|
58
|
-
<Table.DataCell>Picard</Table.DataCell>
|
|
59
|
-
<Table.DataCell>Kaptein</Table.DataCell>
|
|
60
|
-
</Table.Row>
|
|
61
|
-
<Table.Row>
|
|
62
|
-
<Table.HeaderCell>2</Table.HeaderCell>
|
|
63
|
-
<Table.DataCell>William</Table.DataCell>
|
|
64
|
-
<Table.DataCell>Riker</Table.DataCell>
|
|
65
|
-
<Table.DataCell>Kommandør</Table.DataCell>
|
|
66
|
-
</Table.Row>
|
|
67
|
-
<Table.Row>
|
|
68
|
-
<Table.HeaderCell>3</Table.HeaderCell>
|
|
69
|
-
<Table.DataCell>Geordi</Table.DataCell>
|
|
70
|
-
<Table.DataCell>La Forge</Table.DataCell>
|
|
71
|
-
<Table.DataCell>Sjefsingeniør</Table.DataCell>
|
|
72
|
-
</Table.Row>
|
|
73
|
-
</Table.Body>
|
|
74
|
-
</Table>
|
|
50
|
+
<TableComponent size="small" />
|
|
75
51
|
<h2>Table with divs</h2>
|
|
76
52
|
<Alert variant="warning">
|
|
77
53
|
Obs! Hvis man skal bygge tabeller uten å bruke vanlig {"<tabell> "}
|
|
@@ -87,48 +63,48 @@ export const All = () => {
|
|
|
87
63
|
<div className="navds-table" role="table">
|
|
88
64
|
<div className="navds-table__header" role="rowgroup">
|
|
89
65
|
<div className="navds-table__row" role="row">
|
|
90
|
-
<div className="navds-
|
|
66
|
+
<div className="navds-table__header-cell" role="columnheader">
|
|
91
67
|
Fornavn
|
|
92
68
|
</div>
|
|
93
|
-
<div className="navds-
|
|
69
|
+
<div className="navds-table__header-cell" role="columnheader">
|
|
94
70
|
Etternavn
|
|
95
71
|
</div>
|
|
96
|
-
<div className="navds-
|
|
72
|
+
<div className="navds-table__header-cell" role="columnheader">
|
|
97
73
|
Rolle
|
|
98
74
|
</div>
|
|
99
75
|
</div>
|
|
100
76
|
</div>
|
|
101
77
|
<div className="navds-table__body" role="rowgroup">
|
|
102
78
|
<div className="navds-table__row" role="row">
|
|
103
|
-
<div className="navds-
|
|
79
|
+
<div className="navds-table__data-cell" role="cell">
|
|
104
80
|
Jean-Luc
|
|
105
81
|
</div>
|
|
106
|
-
<div className="navds-
|
|
82
|
+
<div className="navds-table__data-cell" role="cell">
|
|
107
83
|
Picard
|
|
108
84
|
</div>
|
|
109
|
-
<div className="navds-
|
|
85
|
+
<div className="navds-table__data-cell" role="cell">
|
|
110
86
|
Kaptein
|
|
111
87
|
</div>
|
|
112
88
|
</div>
|
|
113
89
|
<div className="navds-table__row" role="row">
|
|
114
|
-
<div className="navds-
|
|
90
|
+
<div className="navds-table__data-cell" role="cell">
|
|
115
91
|
William
|
|
116
92
|
</div>
|
|
117
|
-
<div className="navds-
|
|
93
|
+
<div className="navds-table__data-cell" role="cell">
|
|
118
94
|
Riker
|
|
119
95
|
</div>
|
|
120
|
-
<div className="navds-
|
|
96
|
+
<div className="navds-table__data-cell" role="cell">
|
|
121
97
|
Kommandør
|
|
122
98
|
</div>
|
|
123
99
|
</div>
|
|
124
100
|
<div className="navds-table__row" role="row">
|
|
125
|
-
<div className="navds-
|
|
101
|
+
<div className="navds-table__data-cell" role="cell">
|
|
126
102
|
Geordi
|
|
127
103
|
</div>
|
|
128
|
-
<div className="navds-
|
|
104
|
+
<div className="navds-table__data-cell" role="cell">
|
|
129
105
|
La Forge
|
|
130
106
|
</div>
|
|
131
|
-
<div className="navds-
|
|
107
|
+
<div className="navds-table__data-cell" role="cell">
|
|
132
108
|
Sjefsingeniør
|
|
133
109
|
</div>
|
|
134
110
|
</div>
|
|
@@ -137,3 +113,110 @@ export const All = () => {
|
|
|
137
113
|
</>
|
|
138
114
|
);
|
|
139
115
|
};
|
|
116
|
+
|
|
117
|
+
export const Selection = () => (
|
|
118
|
+
<>
|
|
119
|
+
<h1>Selection</h1>
|
|
120
|
+
<h2>Medium</h2>
|
|
121
|
+
<SelectionTable />
|
|
122
|
+
<h2>Small</h2>
|
|
123
|
+
<SelectionTable size="small" />
|
|
124
|
+
</>
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
const SelectionTable = ({ size = "medium" }: { size?: "small" | "medium" }) => {
|
|
128
|
+
const useToggleList = (initialState) => {
|
|
129
|
+
const [list, setList] = useState(initialState);
|
|
130
|
+
|
|
131
|
+
return [
|
|
132
|
+
list,
|
|
133
|
+
(value) =>
|
|
134
|
+
setList((list) =>
|
|
135
|
+
list.includes(value)
|
|
136
|
+
? list.filter((id) => id !== value)
|
|
137
|
+
: [...list, value]
|
|
138
|
+
),
|
|
139
|
+
];
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const [selectedRows, toggleSelectedRow] = useToggleList([]);
|
|
143
|
+
|
|
144
|
+
return (
|
|
145
|
+
<Table size={size} zebraStripes>
|
|
146
|
+
<Table.Body>
|
|
147
|
+
<Table.Row>
|
|
148
|
+
<Table.DataCell>
|
|
149
|
+
<Checkbox
|
|
150
|
+
size={size}
|
|
151
|
+
checked={selectedRows.includes("all")}
|
|
152
|
+
onChange={() => toggleSelectedRow("all")}
|
|
153
|
+
>
|
|
154
|
+
Select all
|
|
155
|
+
</Checkbox>
|
|
156
|
+
</Table.DataCell>
|
|
157
|
+
<Table.HeaderCell scope="col">Name</Table.HeaderCell>
|
|
158
|
+
<Table.HeaderCell scope="col">Age</Table.HeaderCell>
|
|
159
|
+
<Table.HeaderCell scope="col">Country</Table.HeaderCell>
|
|
160
|
+
<Table.HeaderCell scope="col">Points</Table.HeaderCell>
|
|
161
|
+
</Table.Row>
|
|
162
|
+
<Table.Row selected={selectedRows.includes("1")}>
|
|
163
|
+
<Table.DataCell>
|
|
164
|
+
<Checkbox
|
|
165
|
+
size={size}
|
|
166
|
+
hideLabel
|
|
167
|
+
checked={selectedRows.includes("1")}
|
|
168
|
+
onChange={() => toggleSelectedRow("1")}
|
|
169
|
+
aria-labelledby={`x_r1-${size}`}
|
|
170
|
+
>
|
|
171
|
+
{" "}
|
|
172
|
+
</Checkbox>
|
|
173
|
+
</Table.DataCell>
|
|
174
|
+
<Table.HeaderCell scope="row">
|
|
175
|
+
<span id={`x_r1-${size}`}>Donald Smith</span>
|
|
176
|
+
</Table.HeaderCell>
|
|
177
|
+
<Table.DataCell>32</Table.DataCell>
|
|
178
|
+
<Table.DataCell>USA</Table.DataCell>
|
|
179
|
+
<Table.DataCell>38</Table.DataCell>
|
|
180
|
+
</Table.Row>
|
|
181
|
+
<Table.Row selected={selectedRows.includes("2")}>
|
|
182
|
+
<Table.DataCell>
|
|
183
|
+
<Checkbox
|
|
184
|
+
size={size}
|
|
185
|
+
hideLabel
|
|
186
|
+
checked={selectedRows.includes("2")}
|
|
187
|
+
onChange={() => toggleSelectedRow("2")}
|
|
188
|
+
aria-labelledby={`x_r2-${size}`}
|
|
189
|
+
>
|
|
190
|
+
{" "}
|
|
191
|
+
</Checkbox>
|
|
192
|
+
</Table.DataCell>
|
|
193
|
+
<Table.HeaderCell scope="row">
|
|
194
|
+
<span id={`x_r2-${size}`}>Preben Aalborg</span>
|
|
195
|
+
</Table.HeaderCell>
|
|
196
|
+
<Table.DataCell>44</Table.DataCell>
|
|
197
|
+
<Table.DataCell>Denmark</Table.DataCell>
|
|
198
|
+
<Table.DataCell>11</Table.DataCell>
|
|
199
|
+
</Table.Row>
|
|
200
|
+
<Table.Row selected={selectedRows.includes("3")}>
|
|
201
|
+
<Table.DataCell>
|
|
202
|
+
<Checkbox
|
|
203
|
+
size={size}
|
|
204
|
+
hideLabel
|
|
205
|
+
checked={selectedRows.includes("3")}
|
|
206
|
+
onChange={() => toggleSelectedRow("3")}
|
|
207
|
+
aria-labelledby={`x_r3-${size}`}
|
|
208
|
+
>
|
|
209
|
+
{" "}
|
|
210
|
+
</Checkbox>
|
|
211
|
+
</Table.DataCell>
|
|
212
|
+
<Table.HeaderCell scope="row">
|
|
213
|
+
<span id={`x_r3-${size}`}>Rudolph Bachenmeier</span>
|
|
214
|
+
</Table.HeaderCell>
|
|
215
|
+
<Table.DataCell>32</Table.DataCell>
|
|
216
|
+
<Table.DataCell>Germany</Table.DataCell>
|
|
217
|
+
<Table.DataCell>70</Table.DataCell>
|
|
218
|
+
</Table.Row>
|
|
219
|
+
</Table.Body>
|
|
220
|
+
</Table>
|
|
221
|
+
);
|
|
222
|
+
};
|