@navikt/ds-react 0.17.17 → 0.17.20
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/search/Search.js +11 -17
- package/cjs/form/search/SearchButton.js +1 -1
- package/esm/form/search/Search.d.ts +4 -4
- package/esm/form/search/Search.js +13 -19
- package/esm/form/search/Search.js.map +1 -1
- package/esm/form/search/SearchButton.js +1 -1
- package/esm/form/search/SearchButton.js.map +1 -1
- package/package.json +13 -13
- package/src/accordion/accordion.stories.tsx +82 -70
- package/src/alert/alert.stories.tsx +85 -95
- package/src/button/button.stories.tsx +142 -130
- package/src/card/stories/card.stories.mdx +1 -1
- package/src/card/stories/card.stories.tsx +1 -1
- package/src/form/checkbox/Checkbox.test.tsx +12 -8
- package/src/form/radio/Radio.test.tsx +7 -4
- package/src/form/search/Search.tsx +22 -24
- package/src/form/search/SearchButton.tsx +1 -1
- package/src/form/search/search-themes.stories.tsx +52 -0
- package/src/form/search/search.stories.tsx +10 -3
- package/src/page-header/stories/header.stories.mdx +1 -1
- package/src/page-header/stories/header.stories.tsx +1 -1
- package/src/step-indicator/stories/step-indicator.stories.mdx +1 -1
- package/src/step-indicator/stories/step-indicator.stories.tsx +1 -1
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { Close } from "@navikt/ds-icons";
|
|
1
|
+
import { Close, Search as SearchIcon } from "@navikt/ds-icons";
|
|
2
2
|
import cl from "classnames";
|
|
3
3
|
import React, {
|
|
4
4
|
forwardRef,
|
|
5
5
|
InputHTMLAttributes,
|
|
6
6
|
useCallback,
|
|
7
|
-
useEffect,
|
|
8
7
|
useRef,
|
|
9
8
|
useState,
|
|
10
9
|
} from "react";
|
|
@@ -59,9 +58,9 @@ export interface SearchProps
|
|
|
59
58
|
clearButton?: boolean;
|
|
60
59
|
/**
|
|
61
60
|
* Changes button-variant
|
|
62
|
-
* @default "
|
|
61
|
+
* @default "primary"
|
|
63
62
|
*/
|
|
64
|
-
variant?: "
|
|
63
|
+
variant?: "primary" | "secondary" | "simple";
|
|
65
64
|
}
|
|
66
65
|
|
|
67
66
|
interface SearchComponent
|
|
@@ -74,8 +73,8 @@ interface SearchComponent
|
|
|
74
73
|
export interface SearchContextProps {
|
|
75
74
|
disabled?: boolean;
|
|
76
75
|
size: "medium" | "small";
|
|
77
|
-
variant
|
|
78
|
-
onSearch
|
|
76
|
+
variant: "primary" | "secondary" | "simple";
|
|
77
|
+
onSearch: () => void;
|
|
79
78
|
}
|
|
80
79
|
|
|
81
80
|
export const SearchContext = React.createContext<SearchContextProps | null>(
|
|
@@ -99,7 +98,9 @@ const Search = forwardRef<HTMLInputElement, SearchProps>((props, ref) => {
|
|
|
99
98
|
clearButton = true,
|
|
100
99
|
children,
|
|
101
100
|
onSearch,
|
|
102
|
-
variant = "
|
|
101
|
+
variant = "primary",
|
|
102
|
+
defaultValue,
|
|
103
|
+
onChange,
|
|
103
104
|
...rest
|
|
104
105
|
} = props;
|
|
105
106
|
|
|
@@ -107,26 +108,23 @@ const Search = forwardRef<HTMLInputElement, SearchProps>((props, ref) => {
|
|
|
107
108
|
const mergedRef = mergeRefs([searchRef, ref]);
|
|
108
109
|
const [wrapperRef, setWrapperRef] = useState<HTMLDivElement | null>(null);
|
|
109
110
|
|
|
110
|
-
const [
|
|
111
|
+
const [internalValue, setInternalValue] = useState(defaultValue ?? "");
|
|
111
112
|
|
|
112
113
|
const handleChange = useCallback(
|
|
113
114
|
(v: string) => {
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
value === undefined && setInternalValue(v);
|
|
116
|
+
onChange?.(v);
|
|
116
117
|
},
|
|
117
|
-
[
|
|
118
|
+
[onChange, value]
|
|
118
119
|
);
|
|
119
120
|
|
|
120
121
|
const handleClear = useCallback(
|
|
121
122
|
(event: SearchClearEvent) => {
|
|
122
123
|
onClear?.(event);
|
|
123
124
|
handleChange("");
|
|
124
|
-
if (searchRef.current && value === undefined) {
|
|
125
|
-
searchRef.current.value = "";
|
|
126
|
-
}
|
|
127
125
|
searchRef.current && searchRef.current?.focus?.();
|
|
128
126
|
},
|
|
129
|
-
[handleChange, onClear
|
|
127
|
+
[handleChange, onClear]
|
|
130
128
|
);
|
|
131
129
|
|
|
132
130
|
useEventListener(
|
|
@@ -143,10 +141,6 @@ const Search = forwardRef<HTMLInputElement, SearchProps>((props, ref) => {
|
|
|
143
141
|
wrapperRef
|
|
144
142
|
);
|
|
145
143
|
|
|
146
|
-
useEffect(() => {
|
|
147
|
-
value !== undefined && setControlledValue(value);
|
|
148
|
-
}, [value]);
|
|
149
|
-
|
|
150
144
|
return (
|
|
151
145
|
<div
|
|
152
146
|
ref={setWrapperRef}
|
|
@@ -184,23 +178,27 @@ const Search = forwardRef<HTMLInputElement, SearchProps>((props, ref) => {
|
|
|
184
178
|
)}
|
|
185
179
|
<div className="navds-search__wrapper">
|
|
186
180
|
<div className="navds-search__wrapper-inner">
|
|
181
|
+
{variant === "simple" && (
|
|
182
|
+
<SearchIcon aria-hidden className="navds-search__search-icon" />
|
|
183
|
+
)}
|
|
187
184
|
<input
|
|
188
185
|
ref={mergedRef}
|
|
189
186
|
{...omit(rest, ["size"])}
|
|
190
187
|
{...inputProps}
|
|
191
|
-
|
|
188
|
+
value={value ?? internalValue}
|
|
192
189
|
onChange={(e) => handleChange(e.target.value)}
|
|
193
190
|
type="search"
|
|
194
191
|
role="searchbox"
|
|
195
192
|
className={cl(
|
|
196
193
|
className,
|
|
197
194
|
"navds-search__input",
|
|
195
|
+
`navds-search__input--${variant}`,
|
|
198
196
|
"navds-text-field__input",
|
|
199
197
|
"navds-body-short",
|
|
200
|
-
`navds-body-${size
|
|
198
|
+
`navds-body-${size}`
|
|
201
199
|
)}
|
|
202
200
|
/>
|
|
203
|
-
{
|
|
201
|
+
{(value ?? internalValue) && clearButton && (
|
|
204
202
|
<button
|
|
205
203
|
type="button"
|
|
206
204
|
onClick={(e) => handleClear({ trigger: "Click", event: e })}
|
|
@@ -218,10 +216,10 @@ const Search = forwardRef<HTMLInputElement, SearchProps>((props, ref) => {
|
|
|
218
216
|
size,
|
|
219
217
|
disabled: inputProps.disabled,
|
|
220
218
|
variant,
|
|
221
|
-
onSearch: () => onSearch?.(
|
|
219
|
+
onSearch: () => onSearch?.(value ?? internalValue),
|
|
222
220
|
}}
|
|
223
221
|
>
|
|
224
|
-
{children ? children : <SearchButton />}
|
|
222
|
+
{children ? children : variant !== "simple" && <SearchButton />}
|
|
225
223
|
</SearchContext.Provider>
|
|
226
224
|
</div>
|
|
227
225
|
</div>
|
|
@@ -33,7 +33,7 @@ const SearchButton: SearchButtonType = forwardRef(
|
|
|
33
33
|
{...rest}
|
|
34
34
|
ref={ref}
|
|
35
35
|
size={size}
|
|
36
|
-
variant={variant}
|
|
36
|
+
variant={variant === "secondary" ? "secondary" : "primary"}
|
|
37
37
|
className={cl("navds-search__button-search", className)}
|
|
38
38
|
disabled={context?.disabled ?? disabled}
|
|
39
39
|
onClick={(e) => {
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Meta } from "@storybook/react/types-6-0";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { Heading } from "../..";
|
|
4
|
+
import { Search } from "..";
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
title: "ds-react/form/search",
|
|
8
|
+
component: Search,
|
|
9
|
+
} as Meta;
|
|
10
|
+
|
|
11
|
+
export const LightTheme = () => (
|
|
12
|
+
<div
|
|
13
|
+
style={{ maxWidth: 400, display: "flex", flexDirection: "column", gap: 16 }}
|
|
14
|
+
>
|
|
15
|
+
<Heading size="xlarge">Search</Heading>
|
|
16
|
+
<Heading level="2" size="large">
|
|
17
|
+
size medium
|
|
18
|
+
</Heading>
|
|
19
|
+
<Search label="hidden label" placeholder="Søk" />
|
|
20
|
+
<Search label="hidden label" variant="secondary" defaultValue="dagpenger" />
|
|
21
|
+
<Search label="hidden label" variant="simple" placeholder="Søk" />
|
|
22
|
+
<Search label="with label" hideLabel={false} />
|
|
23
|
+
|
|
24
|
+
<Heading level="2" size="large">
|
|
25
|
+
size small
|
|
26
|
+
</Heading>
|
|
27
|
+
<Search label="hidden label" size="small" placeholder="Søk" />
|
|
28
|
+
<Search
|
|
29
|
+
label="hidden label"
|
|
30
|
+
variant="secondary"
|
|
31
|
+
size="small"
|
|
32
|
+
defaultValue="dagpenger"
|
|
33
|
+
/>
|
|
34
|
+
<Search
|
|
35
|
+
label="hidden label"
|
|
36
|
+
variant="simple"
|
|
37
|
+
size="small"
|
|
38
|
+
placeholder="Søk"
|
|
39
|
+
/>
|
|
40
|
+
<Search label="with label" hideLabel={false} size="small" />
|
|
41
|
+
</div>
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
export const DarkTheme = () => (
|
|
45
|
+
<div data-theme="dark">
|
|
46
|
+
<LightTheme />
|
|
47
|
+
</div>
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
DarkTheme.parameters = {
|
|
51
|
+
backgrounds: { default: "dark" },
|
|
52
|
+
};
|
|
@@ -21,11 +21,18 @@ export const All = () => {
|
|
|
21
21
|
<h1>Search</h1>
|
|
22
22
|
|
|
23
23
|
<Search label="Søk alle sider om X og Y" onSearch={console.log}></Search>
|
|
24
|
-
<h2>
|
|
24
|
+
<h2>Secondary</h2>
|
|
25
25
|
<Search
|
|
26
26
|
label="Søk alle sider om X og Y"
|
|
27
27
|
onSearch={console.log}
|
|
28
|
-
variant="
|
|
28
|
+
variant="secondary"
|
|
29
|
+
></Search>
|
|
30
|
+
|
|
31
|
+
<h2>No button</h2>
|
|
32
|
+
<Search
|
|
33
|
+
label="Søk alle sider om X og Y"
|
|
34
|
+
onSearch={console.log}
|
|
35
|
+
variant="simple"
|
|
29
36
|
></Search>
|
|
30
37
|
|
|
31
38
|
<h2>Search small</h2>
|
|
@@ -42,7 +49,7 @@ export const All = () => {
|
|
|
42
49
|
description="Beskrivelse av søket"
|
|
43
50
|
size="small"
|
|
44
51
|
hideLabel
|
|
45
|
-
variant="
|
|
52
|
+
variant="secondary"
|
|
46
53
|
>
|
|
47
54
|
<Search.Button />
|
|
48
55
|
</Search>
|
|
@@ -2,7 +2,7 @@ import { Meta, Canvas } from "@storybook/addon-docs";
|
|
|
2
2
|
import { PageHeader } from "../index";
|
|
3
3
|
import { illustrationPictogram } from "./pictogram";
|
|
4
4
|
|
|
5
|
-
<Meta title="ds-react/page-header/intro" />
|
|
5
|
+
<Meta title="ds-react(deprecated)/page-header/intro" />
|
|
6
6
|
|
|
7
7
|
# Hvordan ta i bruk PageHeader
|
|
8
8
|
|
|
@@ -3,7 +3,7 @@ import { PageHeader } from "../index";
|
|
|
3
3
|
import { Meta } from "@storybook/react/types-6-0";
|
|
4
4
|
import { illustrationPictogram } from "./pictogram";
|
|
5
5
|
export default {
|
|
6
|
-
title: "ds-react/page-header",
|
|
6
|
+
title: "ds-react(deprecated)/page-header",
|
|
7
7
|
component: PageHeader,
|
|
8
8
|
} as Meta;
|
|
9
9
|
|
|
@@ -2,7 +2,7 @@ import { Meta, Canvas } from "@storybook/addon-docs";
|
|
|
2
2
|
import { StepIndicator } from "..";
|
|
3
3
|
import { Example } from "./Example";
|
|
4
4
|
|
|
5
|
-
<Meta title="ds-react/step-indicator/intro" />
|
|
5
|
+
<Meta title="ds-react(deprecated)/step-indicator/intro" />
|
|
6
6
|
|
|
7
7
|
# Hvordan ta i bruk StepIndicator
|
|
8
8
|
|
|
@@ -4,7 +4,7 @@ import { Meta } from "@storybook/react/types-6-0";
|
|
|
4
4
|
import { Link, HashRouter as Router, useLocation } from "react-router-dom";
|
|
5
5
|
|
|
6
6
|
export default {
|
|
7
|
-
title: "ds-react/step-indicator",
|
|
7
|
+
title: "ds-react(deprecated)/step-indicator",
|
|
8
8
|
component: StepIndicator,
|
|
9
9
|
} as Meta;
|
|
10
10
|
|