@navikt/ds-react 0.13.3 → 0.14.2
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/cjs/form/Switch.js +58 -0
- package/cjs/form/index.js +3 -1
- package/cjs/loader/Loader.js +1 -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/loader/Loader.js +1 -1
- package/esm/loader/Loader.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 -4
- 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/grid/stories/grid.stories.mdx +3 -3
- package/src/guide-panel/stories/example.css +4 -4
- package/src/guide-panel/stories/guidepanel.stories.mdx +7 -7
- package/src/guide-panel/stories/guidepanel.stories.tsx +6 -6
- package/src/loader/Loader.tsx +1 -1
- package/src/loader/stories/loader.stories.mdx +0 -16
- package/src/popover/stories/popover.stories.tsx +1 -1
- package/src/speech-bubble/stories/speechbubble.stories.mdx +4 -4
- package/src/speech-bubble/stories/speechbubble.stories.tsx +2 -2
- 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/src/typography/stories/index.css +1 -1
|
@@ -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
|
+
};
|
|
@@ -31,13 +31,13 @@ Stylingen som blir satt av den:
|
|
|
31
31
|
.navds-content-container {
|
|
32
32
|
margin-left: auto;
|
|
33
33
|
margin-right: auto;
|
|
34
|
-
max-width:
|
|
35
|
-
padding: var(--navds-
|
|
34
|
+
max-width: 79.5rem; # (1272px)
|
|
35
|
+
padding: var(--navds-spacing-4); # 1rem
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
@media (min-width: 448px) {
|
|
39
39
|
.navds-content-container {
|
|
40
|
-
padding: var(--navds-
|
|
40
|
+
padding: var(--navds-spacing-6); # 1.5rem
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
```
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
.sb-guidepanel__tokens--purple {
|
|
2
|
-
--navds-guide-panel-color-border: var(--navds-color-purple-
|
|
2
|
+
--navds-guide-panel-color-border: var(--navds-global-color-purple-400);
|
|
3
3
|
--navds-guide-panel-color-illustration-background: var(
|
|
4
|
-
--navds-color-purple-
|
|
4
|
+
--navds-global-color-purple-200
|
|
5
5
|
);
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
.sb-guidepanel__tokens--green {
|
|
9
|
-
--navds-guide-panel-color-border: var(--navds-color-green-
|
|
9
|
+
--navds-guide-panel-color-border: var(--navds-global-color-green-400);
|
|
10
10
|
--navds-guide-panel-color-illustration-background: var(
|
|
11
|
-
--navds-color-green-
|
|
11
|
+
--navds-global-color-green-200
|
|
12
12
|
);
|
|
13
13
|
}
|
|
@@ -38,9 +38,9 @@ Istedenfor fargetema/themes slik som tidligere veileder brukte velger man nå se
|
|
|
38
38
|
overskrive tokens. Det anbefalses å gjøre dette med eks Styled-Components eller css-klasser, men kan inlines også
|
|
39
39
|
|
|
40
40
|
```css
|
|
41
|
-
/*
|
|
42
|
-
--navds-guide-panel-color-border
|
|
43
|
-
--navds-guide-panel-color-illustration-background
|
|
41
|
+
/* Tokens */
|
|
42
|
+
--navds-guide-panel-color-border
|
|
43
|
+
--navds-guide-panel-color-illustration-background
|
|
44
44
|
```
|
|
45
45
|
|
|
46
46
|
```jsx
|
|
@@ -55,16 +55,16 @@ overskrive tokens. Det anbefalses å gjøre dette med eks Styled-Components elle
|
|
|
55
55
|
/* Inline */
|
|
56
56
|
<GuidePanel
|
|
57
57
|
style={{
|
|
58
|
-
["--navds-guide-panel-color-illustration-background" as any]: "var(--navds-color-orange-
|
|
59
|
-
["--navds-guide-panel-color-border" as any]: "var(--navds-color-orange-
|
|
58
|
+
["--navds-guide-panel-color-illustration-background" as any]: "var(--navds-global-color-orange-200)",
|
|
59
|
+
["--navds-guide-panel-color-border" as any]: "var(--navds-global-color-orange-400)",
|
|
60
60
|
}}
|
|
61
61
|
>
|
|
62
62
|
Cupidatat proident adipisicing eu nulla laborum dolore irure aliqua.
|
|
63
63
|
</GuidePanel>
|
|
64
64
|
<GuidePanel
|
|
65
65
|
style={{
|
|
66
|
-
["--navds-guide-panel-color-illustration-background" as any]: "var(--navds-color-orange-
|
|
67
|
-
["--navds-guide-panel-color-border" as any]: "var(--navds-color-orange-
|
|
66
|
+
["--navds-guide-panel-color-illustration-background" as any]: "var(--navds-global-color-orange-200)",
|
|
67
|
+
["--navds-guide-panel-color-border" as any]: "var(--navds-global-color-orange-400)",
|
|
68
68
|
}}
|
|
69
69
|
>
|
|
70
70
|
Cupidatat proident adipisicing eu nulla laborum dolore irure aliqua.
|
|
@@ -21,24 +21,24 @@ export const All = () => {
|
|
|
21
21
|
<h2>custom colors</h2>
|
|
22
22
|
<GuidePanel
|
|
23
23
|
style={{
|
|
24
|
-
["--navds-guide-panel-color-illustration-background" as any]: "var(--navds-color-purple-
|
|
25
|
-
["--navds-guide-panel-color-border" as any]: "var(--navds-color-purple-
|
|
24
|
+
["--navds-guide-panel-color-illustration-background" as any]: "var(--navds-global-color-purple-200)",
|
|
25
|
+
["--navds-guide-panel-color-border" as any]: "var(--navds-global-color-purple-400)",
|
|
26
26
|
}}
|
|
27
27
|
>
|
|
28
28
|
{panelText}
|
|
29
29
|
</GuidePanel>
|
|
30
30
|
<GuidePanel
|
|
31
31
|
style={{
|
|
32
|
-
["--navds-guide-panel-color-illustration-background" as any]: "var(--navds-color-green-
|
|
33
|
-
["--navds-guide-panel-color-border" as any]: "var(--navds-color-green-
|
|
32
|
+
["--navds-guide-panel-color-illustration-background" as any]: "var(--navds-global-color-green-200)",
|
|
33
|
+
["--navds-guide-panel-color-border" as any]: "var(--navds-global-color-green-400)",
|
|
34
34
|
}}
|
|
35
35
|
>
|
|
36
36
|
{panelText}
|
|
37
37
|
</GuidePanel>
|
|
38
38
|
<GuidePanel
|
|
39
39
|
style={{
|
|
40
|
-
["--navds-guide-panel-color-illustration-background" as any]: "var(--navds-color-orange-
|
|
41
|
-
["--navds-guide-panel-color-border" as any]: "var(--navds-color-orange-
|
|
40
|
+
["--navds-guide-panel-color-illustration-background" as any]: "var(--navds-global-color-orange-200)",
|
|
41
|
+
["--navds-guide-panel-color-border" as any]: "var(--navds-global-color-orange-400)",
|
|
42
42
|
}}
|
|
43
43
|
>
|
|
44
44
|
{panelText}Ullamco reprehenderit fugiat reprehenderit ad nisi aliqua
|
package/src/loader/Loader.tsx
CHANGED
|
@@ -85,19 +85,3 @@ Størrelsen justeres også automatisk, slik at alt man trenger er å sette Loade
|
|
|
85
85
|
<Loader />
|
|
86
86
|
</Button>
|
|
87
87
|
</Canvas>
|
|
88
|
-
|
|
89
|
-
## Overskrive farger for å sikre kontrast
|
|
90
|
-
|
|
91
|
-
I de casene der man må justere fargene for å ha bedre kontrast så kan man endre på selve css-variablene som bli brukt
|
|
92
|
-
|
|
93
|
-
```css
|
|
94
|
-
--navds-loader-color-foreground: var(--navds-color-gray-40);
|
|
95
|
-
--navds-loader-color-background: var(--navds-color-gray-10);
|
|
96
|
-
--navds-loader-color-neutral-foreground: var(--navds-color-gray-40);
|
|
97
|
-
--navds-loader-color-interaction-foreground: var(--navds-color-blue-50);
|
|
98
|
-
--navds-loader-color-inverted-foreground: var(--navds-color-white);
|
|
99
|
-
--navds-loader-color-inverted-background: rgba(255, 255, 255, 0.3);
|
|
100
|
-
--navds-loader-color-transparent-background: transparent;
|
|
101
|
-
--navds-loader-color-on-button-background: rgba(255, 255, 255, 0.3);
|
|
102
|
-
--navds-loader-color-on-button-foreground: currentColor;
|
|
103
|
-
```
|
|
@@ -80,8 +80,8 @@ Man kan endre bakgrunnsfargen selv med `illustrationBgColor` og `backgroundColor
|
|
|
80
80
|
<SpeechBubble
|
|
81
81
|
illustration="OLA"
|
|
82
82
|
position="left"
|
|
83
|
-
illustrationBgColor="var(--navds-color-lightblue-
|
|
84
|
-
backgroundColor="var(--navds-color-lightblue-
|
|
83
|
+
illustrationBgColor="var(--navds-global-color-lightblue-100)"
|
|
84
|
+
backgroundColor="var(--navds-global-color-lightblue-200)"
|
|
85
85
|
>
|
|
86
86
|
<SpeechBubble.Bubble>
|
|
87
87
|
Aute minim nisi sunt mollit duis sunt nulla minim non proident.
|
|
@@ -93,8 +93,8 @@ Man kan endre bakgrunnsfargen selv med `illustrationBgColor` og `backgroundColor
|
|
|
93
93
|
<SpeechBubble
|
|
94
94
|
illustration="OLA"
|
|
95
95
|
position="left"
|
|
96
|
-
illustrationBgColor="var(--navds-color-lightblue-
|
|
97
|
-
backgroundColor="var(--navds-color-lightblue-
|
|
96
|
+
illustrationBgColor="var(--navds-global-color-lightblue-100)"
|
|
97
|
+
backgroundColor="var(--navds-global-color-lightblue-200)"
|
|
98
98
|
>
|
|
99
99
|
<SpeechBubble.Bubble>
|
|
100
100
|
Aute minim nisi sunt mollit duis sunt nulla minim non proident.
|
|
@@ -14,7 +14,7 @@ export const All = () => {
|
|
|
14
14
|
<SpeechBubble
|
|
15
15
|
illustration={<Illustration />}
|
|
16
16
|
topText="Ola Normann 01.01.21 14:00"
|
|
17
|
-
backgroundColor="var(--navds-color-lightblue-
|
|
17
|
+
backgroundColor="var(--navds-global-color-lightblue-200)"
|
|
18
18
|
>
|
|
19
19
|
<SpeechBubble.Bubble>
|
|
20
20
|
Aute minim nisi sunt mollit duis sunt nulla minim non proident.
|
|
@@ -42,7 +42,7 @@ export const All = () => {
|
|
|
42
42
|
</div>
|
|
43
43
|
}
|
|
44
44
|
position="right"
|
|
45
|
-
backgroundColor="var(--navds-color-gray-
|
|
45
|
+
backgroundColor="var(--navds-global-color-gray-100)"
|
|
46
46
|
>
|
|
47
47
|
<SpeechBubble.Bubble>
|
|
48
48
|
Aute minim nisi sunt mollit duis sunt nulla minim non proident.
|
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;
|