@navikt/ds-react 2.1.6 → 2.2.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.
Files changed (175) hide show
  1. package/README.md +4 -5
  2. package/_docs.json +316 -295
  3. package/cjs/accordion/AccordionContent.js +2 -2
  4. package/cjs/accordion/AccordionHeader.js +2 -2
  5. package/cjs/alert/Alert.js +2 -2
  6. package/cjs/chat/Chat.js +3 -3
  7. package/cjs/date/hooks/useRangeDatepicker.js +1 -1
  8. package/cjs/toggle-group/ToggleGroup.js +2 -2
  9. package/esm/accordion/AccordionContent.js +1 -1
  10. package/esm/accordion/AccordionContent.js.map +1 -1
  11. package/esm/accordion/AccordionHeader.js +1 -1
  12. package/esm/accordion/AccordionHeader.js.map +1 -1
  13. package/esm/accordion/index.d.ts +1 -1
  14. package/esm/accordion/index.js.map +1 -1
  15. package/esm/alert/Alert.js +1 -1
  16. package/esm/alert/Alert.js.map +1 -1
  17. package/esm/alert/index.d.ts +1 -1
  18. package/esm/button/Button.d.ts +1 -1
  19. package/esm/button/Button.js.map +1 -1
  20. package/esm/button/index.d.ts +1 -1
  21. package/esm/chat/Chat.js +1 -1
  22. package/esm/chat/Chat.js.map +1 -1
  23. package/esm/chat/index.d.ts +1 -1
  24. package/esm/chat/index.js.map +1 -1
  25. package/esm/chips/Removable.d.ts +1 -1
  26. package/esm/chips/Toggle.d.ts +1 -1
  27. package/esm/chips/index.d.ts +1 -1
  28. package/esm/chips/index.js.map +1 -1
  29. package/esm/date/hooks/useRangeDatepicker.js +1 -1
  30. package/esm/date/hooks/useRangeDatepicker.js.map +1 -1
  31. package/esm/date/index.d.ts +6 -6
  32. package/esm/date/utils/index.d.ts +1 -1
  33. package/esm/date/utils/index.js.map +1 -1
  34. package/esm/form/Fieldset/index.d.ts +1 -1
  35. package/esm/form/checkbox/index.d.ts +2 -2
  36. package/esm/form/checkbox/index.js +1 -1
  37. package/esm/form/checkbox/index.js.map +1 -1
  38. package/esm/form/error-summary/index.d.ts +1 -1
  39. package/esm/form/index.d.ts +10 -10
  40. package/esm/form/index.js +1 -1
  41. package/esm/form/index.js.map +1 -1
  42. package/esm/form/radio/index.d.ts +2 -2
  43. package/esm/form/radio/index.js.map +1 -1
  44. package/esm/form/search/index.d.ts +1 -1
  45. package/esm/form/search/index.js +1 -1
  46. package/esm/form/search/index.js.map +1 -1
  47. package/esm/grid/index.d.ts +3 -3
  48. package/esm/grid/index.js.map +1 -1
  49. package/esm/guide-panel/index.d.ts +2 -2
  50. package/esm/guide-panel/index.js.map +1 -1
  51. package/esm/help-text/index.d.ts +1 -1
  52. package/esm/link/Link.d.ts +1 -1
  53. package/esm/link/index.d.ts +1 -1
  54. package/esm/link-panel/LinkPanelTitle.d.ts +1 -1
  55. package/esm/link-panel/index.d.ts +1 -1
  56. package/esm/loader/index.d.ts +1 -1
  57. package/esm/modal/index.d.ts +2 -2
  58. package/esm/modal/index.js.map +1 -1
  59. package/esm/pagination/index.d.ts +1 -1
  60. package/esm/pagination/index.js.map +1 -1
  61. package/esm/panel/Panel.d.ts +1 -1
  62. package/esm/panel/index.d.ts +1 -1
  63. package/esm/popover/index.d.ts +2 -2
  64. package/esm/popover/index.js.map +1 -1
  65. package/esm/read-more/index.d.ts +1 -1
  66. package/esm/stepper/index.d.ts +1 -1
  67. package/esm/stepper/index.js.map +1 -1
  68. package/esm/table/index.d.ts +8 -8
  69. package/esm/table/index.js.map +1 -1
  70. package/esm/tabs/index.d.ts +4 -4
  71. package/esm/tabs/index.js.map +1 -1
  72. package/esm/tag/index.d.ts +1 -1
  73. package/esm/tag/index.js.map +1 -1
  74. package/esm/toggle-group/ToggleGroup.d.ts +5 -0
  75. package/esm/toggle-group/ToggleGroup.js +2 -2
  76. package/esm/toggle-group/ToggleGroup.js.map +1 -1
  77. package/esm/toggle-group/index.d.ts +2 -2
  78. package/esm/toggle-group/index.js.map +1 -1
  79. package/esm/tooltip/index.d.ts +1 -1
  80. package/esm/tooltip/index.js.map +1 -1
  81. package/esm/typography/BodyLong.d.ts +1 -1
  82. package/esm/typography/BodyShort.d.ts +1 -1
  83. package/esm/typography/Detail.d.ts +1 -1
  84. package/esm/typography/ErrorMessage.d.ts +1 -1
  85. package/esm/typography/Heading.d.ts +1 -1
  86. package/esm/typography/Ingress.d.ts +1 -1
  87. package/esm/typography/Label.d.ts +1 -1
  88. package/esm/typography/index.d.ts +7 -7
  89. package/esm/typography/index.js +1 -1
  90. package/esm/typography/index.js.map +1 -1
  91. package/package.json +3 -3
  92. package/src/accordion/AccordionContent.tsx +1 -1
  93. package/src/accordion/AccordionHeader.tsx +1 -1
  94. package/src/accordion/accordion.stories.tsx +16 -14
  95. package/src/accordion/index.ts +1 -1
  96. package/src/alert/Alert.tsx +1 -1
  97. package/src/alert/alert.stories.tsx +48 -28
  98. package/src/alert/index.ts +1 -1
  99. package/src/button/Button.tsx +8 -1
  100. package/src/button/button.stories.tsx +118 -84
  101. package/src/button/index.ts +1 -1
  102. package/src/chat/Chat.tsx +1 -1
  103. package/src/chat/chat.stories.tsx +27 -25
  104. package/src/chat/index.ts +1 -1
  105. package/src/chips/Removable.tsx +1 -1
  106. package/src/chips/Toggle.tsx +1 -1
  107. package/src/chips/chips.stories.tsx +32 -29
  108. package/src/chips/index.ts +1 -1
  109. package/src/date/datepicker/datepicker.stories.tsx +87 -81
  110. package/src/date/hooks/useRangeDatepicker.tsx +1 -1
  111. package/src/date/index.ts +8 -8
  112. package/src/date/monthpicker/monthpicker.stories.tsx +13 -11
  113. package/src/date/utils/index.ts +1 -1
  114. package/src/form/Fieldset/index.ts +1 -1
  115. package/src/form/checkbox/checkbox.stories.tsx +66 -61
  116. package/src/form/checkbox/index.ts +5 -2
  117. package/src/form/error-summary/error-summary.stories.tsx +16 -14
  118. package/src/form/error-summary/index.ts +1 -1
  119. package/src/form/index.ts +16 -11
  120. package/src/form/radio/index.ts +2 -2
  121. package/src/form/radio/radio.stories.tsx +39 -34
  122. package/src/form/search/index.ts +5 -1
  123. package/src/form/search/search.stories.tsx +26 -23
  124. package/src/form/stories/confirmation-panel.stories.tsx +19 -17
  125. package/src/form/stories/fieldset.stories.tsx +13 -11
  126. package/src/form/stories/select.stories.tsx +12 -10
  127. package/src/form/stories/switch.stories.tsx +9 -7
  128. package/src/form/stories/text-field.stories.tsx +8 -6
  129. package/src/form/stories/textarea.stories.tsx +16 -14
  130. package/src/grid/index.ts +3 -3
  131. package/src/guide-panel/guidepanel.stories.tsx +21 -19
  132. package/src/guide-panel/index.ts +2 -2
  133. package/src/help-text/help-text.stories.tsx +11 -9
  134. package/src/help-text/index.ts +1 -1
  135. package/src/link/Link.tsx +1 -1
  136. package/src/link/index.ts +1 -1
  137. package/src/link/link.stories.tsx +24 -22
  138. package/src/link-panel/LinkPanelTitle.tsx +1 -1
  139. package/src/link-panel/index.ts +1 -1
  140. package/src/link-panel/link-panel.stories.tsx +19 -17
  141. package/src/loader/index.ts +1 -1
  142. package/src/loader/loader.stories.tsx +8 -6
  143. package/src/modal/index.ts +2 -2
  144. package/src/modal/modal.stories.tsx +35 -30
  145. package/src/pagination/index.ts +1 -1
  146. package/src/pagination/pagination.stories.tsx +41 -36
  147. package/src/panel/Panel.tsx +1 -1
  148. package/src/panel/index.ts +1 -1
  149. package/src/panel/panel.stories.tsx +17 -15
  150. package/src/popover/index.ts +2 -2
  151. package/src/popover/popover.stories.tsx +25 -19
  152. package/src/read-more/index.ts +1 -1
  153. package/src/read-more/readmore.stories.tsx +20 -17
  154. package/src/stepper/index.ts +1 -1
  155. package/src/stepper/stepper.stories.tsx +44 -41
  156. package/src/table/index.ts +8 -8
  157. package/src/tabs/Tabs.stories.tsx +24 -22
  158. package/src/tabs/index.ts +4 -4
  159. package/src/tag/index.ts +1 -1
  160. package/src/tag/tag.stories.tsx +10 -7
  161. package/src/toggle-group/ToggleGroup.stories.tsx +50 -18
  162. package/src/toggle-group/ToggleGroup.tsx +11 -1
  163. package/src/toggle-group/index.ts +2 -2
  164. package/src/tooltip/index.ts +1 -1
  165. package/src/tooltip/tooltip.stories.tsx +22 -20
  166. package/src/typography/BodyLong.tsx +1 -1
  167. package/src/typography/BodyShort.tsx +1 -1
  168. package/src/typography/Detail.tsx +1 -1
  169. package/src/typography/ErrorMessage.tsx +1 -1
  170. package/src/typography/Heading.tsx +1 -1
  171. package/src/typography/Ingress.tsx +1 -1
  172. package/src/typography/Label.tsx +1 -1
  173. package/src/typography/heading.stories.tsx +5 -3
  174. package/src/typography/index.ts +10 -7
  175. package/src/typography/typography.stories.tsx +0 -44
@@ -8,11 +8,72 @@ export default {
8
8
  parameters: {
9
9
  chromatic: { delay: 600 },
10
10
  },
11
+ };
12
+
13
+ const variants: Array<
14
+ | "primary"
15
+ | "secondary"
16
+ | "tertiary"
17
+ | "primary-neutral"
18
+ | "secondary-neutral"
19
+ | "tertiary-neutral"
20
+ | "danger"
21
+ > = [
22
+ "primary",
23
+ "secondary",
24
+ "tertiary",
25
+ "danger",
26
+ "primary-neutral",
27
+ "secondary-neutral",
28
+ "tertiary-neutral",
29
+ ];
30
+
31
+ const varSwitch = {
32
+ primary: "Primary",
33
+ secondary: "Secondary",
34
+ tertiary: "Tertiary",
35
+ danger: "Danger",
36
+ "primary-neutral": "Primary",
37
+ "secondary-neutral": "Secondary",
38
+ "tertiary-neutral": "Tertiary",
39
+ };
40
+
41
+ export const Default = {
42
+ render: (props) => {
43
+ return (
44
+ <Button
45
+ variant={props.variant}
46
+ size={props.size}
47
+ loading={props.loading}
48
+ icon={props.icon ? <Star /> : undefined}
49
+ iconPosition={props.iconPosition}
50
+ >
51
+ {props.children}
52
+ </Button>
53
+ );
54
+ },
55
+
56
+ args: {
57
+ icon: false,
58
+ loading: false,
59
+ iconPosition: "left",
60
+ children: "Knapp",
61
+ variant: "primary",
62
+ size: "medium",
63
+ },
11
64
  argTypes: {
12
65
  variant: {
13
66
  control: {
14
67
  type: "radio",
15
- options: ["primary", "secondary", "tertiary", "danger"],
68
+ options: [
69
+ "primary",
70
+ "secondary",
71
+ "tertiary",
72
+ "danger",
73
+ "primary-neutral",
74
+ "secondary-neutral",
75
+ "tertiary-neutral",
76
+ ],
16
77
  },
17
78
  },
18
79
  size: {
@@ -30,41 +91,6 @@ export default {
30
91
  },
31
92
  };
32
93
 
33
- const variants: Array<"primary" | "secondary" | "tertiary" | "danger"> = [
34
- "primary",
35
- "secondary",
36
- "tertiary",
37
- "danger",
38
- ];
39
-
40
- const varSwitch = {
41
- primary: "Primary",
42
- secondary: "Secondary",
43
- tertiary: "Tertiary",
44
- danger: "Danger",
45
- };
46
-
47
- export const Default = (props) => {
48
- return (
49
- <Button
50
- variant={props.variant}
51
- size={props.size}
52
- loading={props.loading}
53
- icon={props.icon ? <Star /> : undefined}
54
- iconPosition={props.iconPosition}
55
- >
56
- {props.children}
57
- </Button>
58
- );
59
- };
60
-
61
- Default.args = {
62
- icon: false,
63
- loading: false,
64
- iconPosition: "left",
65
- children: "Knapp",
66
- };
67
-
68
94
  export const Small = () => (
69
95
  <div className="rowgap">
70
96
  {variants.map((variant) => (
@@ -95,31 +121,35 @@ export const Link = () => (
95
121
  </div>
96
122
  );
97
123
 
98
- export const Loading = () => (
99
- <div className="colgap">
100
- <div className="rowgap">
101
- {variants.map((variant) => (
102
- <Button key={variant} variant={variant} loading>
103
- {varSwitch[variant]}
104
- </Button>
105
- ))}
106
- </div>
107
- <div className="rowgap">
108
- {variants.map((variant) => (
109
- <Button key={variant} variant={variant} loading size="small">
110
- {varSwitch[variant]}
111
- </Button>
112
- ))}
113
- </div>
114
- <div className="rowgap">
115
- {variants.map((variant) => (
116
- <Button key={variant} variant={variant} loading size="xsmall">
117
- {varSwitch[variant]}
118
- </Button>
119
- ))}
124
+ export const Loading = {
125
+ render: () => (
126
+ <div className="colgap">
127
+ <div className="rowgap">
128
+ {variants.map((variant) => (
129
+ <Button key={variant} variant={variant} loading>
130
+ {varSwitch[variant]}
131
+ </Button>
132
+ ))}
133
+ </div>
134
+ <div className="rowgap">
135
+ {variants.map((variant) => (
136
+ <Button key={variant} variant={variant} loading size="small">
137
+ {varSwitch[variant]}
138
+ </Button>
139
+ ))}
140
+ </div>
141
+ <div className="rowgap">
142
+ {variants.map((variant) => (
143
+ <Button key={variant} variant={variant} loading size="xsmall">
144
+ {varSwitch[variant]}
145
+ </Button>
146
+ ))}
147
+ </div>
120
148
  </div>
121
- </div>
122
- );
149
+ ),
150
+
151
+ args: { chromatic: { delay: 300 } },
152
+ };
123
153
 
124
154
  export const Icon = () => (
125
155
  <div className="colgap">
@@ -217,28 +247,32 @@ export const Disabled = () => (
217
247
  </div>
218
248
  );
219
249
 
220
- export const LoadingWithAs = () => (
221
- <div className="colgap">
222
- <div className="rowgap">
223
- {variants.map((variant) => (
224
- <Button key={variant} variant={variant} loading size="small">
225
- {varSwitch[variant]}
226
- </Button>
227
- ))}
250
+ export const LoadingWithAs = {
251
+ render: () => (
252
+ <div className="colgap">
253
+ <div className="rowgap">
254
+ {variants.map((variant) => (
255
+ <Button key={variant} variant={variant} loading size="small">
256
+ {varSwitch[variant]}
257
+ </Button>
258
+ ))}
259
+ </div>
260
+ <div className="rowgap">
261
+ {variants.map((variant) => (
262
+ <Button
263
+ key={variant}
264
+ variant={variant}
265
+ loading
266
+ size="small"
267
+ as="a"
268
+ href="#"
269
+ >
270
+ {varSwitch[variant]}
271
+ </Button>
272
+ ))}
273
+ </div>
228
274
  </div>
229
- <div className="rowgap">
230
- {variants.map((variant) => (
231
- <Button
232
- key={variant}
233
- variant={variant}
234
- loading
235
- size="small"
236
- as="a"
237
- href="#"
238
- >
239
- {varSwitch[variant]}
240
- </Button>
241
- ))}
242
- </div>
243
- </div>
244
- );
275
+ ),
276
+
277
+ args: { chromatic: { delay: 300 } },
278
+ };
@@ -1,2 +1,2 @@
1
1
  export { default as Button } from "./Button";
2
- export { ButtonProps } from "./Button";
2
+ export { type ButtonProps } from "./Button";
package/src/chat/Chat.tsx CHANGED
@@ -1,7 +1,7 @@
1
1
  import React, { forwardRef, HTMLAttributes } from "react";
2
2
  import cl from "clsx";
3
3
  import Bubble, { BubbleType } from "./Bubble";
4
- import { BodyLong, BodyShort } from "..";
4
+ import { BodyLong, BodyShort } from "../typography";
5
5
 
6
6
  export interface ChatProps extends HTMLAttributes<HTMLDivElement> {
7
7
  /**
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
  import { Chat } from "../index";
3
- import { Meta } from "@storybook/react/types-6-0";
3
+ import { Meta } from "@storybook/react";
4
4
 
5
5
  export default {
6
6
  title: "ds-react/Chat",
@@ -19,31 +19,33 @@ export default {
19
19
  },
20
20
  } as Meta;
21
21
 
22
- export const Default = (props) => {
23
- return (
24
- <Chat
25
- avatar={props?.avatar ?? "ON"}
26
- name={props?.name ?? "Ola Normann"}
27
- timestamp={props?.timestamp ?? "01.01.21 14:00"}
28
- avatarBgColor={props?.avatarBgColor}
29
- backgroundColor={props?.backgroundColor}
30
- >
31
- <Chat.Bubble>
32
- Aute minim nisi sunt mollit duis sunt nulla minim non proident.
33
- </Chat.Bubble>
34
- <Chat.Bubble>Tempor fugiat amet eu sint in in ullamco.</Chat.Bubble>
35
- <Chat.Bubble>
36
- Adipisicing laborum est eu laborum est sit in commodo enim sint laboris
37
- labore nisi ut.
38
- </Chat.Bubble>
39
- </Chat>
40
- );
41
- };
22
+ export const Default = {
23
+ render: (props) => {
24
+ return (
25
+ <Chat
26
+ avatar={props?.avatar ?? "ON"}
27
+ name={props?.name ?? "Ola Normann"}
28
+ timestamp={props?.timestamp ?? "01.01.21 14:00"}
29
+ avatarBgColor={props?.avatarBgColor}
30
+ backgroundColor={props?.backgroundColor}
31
+ >
32
+ <Chat.Bubble>
33
+ Aute minim nisi sunt mollit duis sunt nulla minim non proident.
34
+ </Chat.Bubble>
35
+ <Chat.Bubble>Tempor fugiat amet eu sint in in ullamco.</Chat.Bubble>
36
+ <Chat.Bubble>
37
+ Adipisicing laborum est eu laborum est sit in commodo enim sint
38
+ laboris labore nisi ut.
39
+ </Chat.Bubble>
40
+ </Chat>
41
+ );
42
+ },
42
43
 
43
- Default.args = {
44
- name: "Ola Normann",
45
- timestamp: "01.01.21 14:00",
46
- avatar: "ON",
44
+ args: {
45
+ name: "Ola Normann",
46
+ timestamp: "01.01.21 14:00",
47
+ avatar: "ON",
48
+ },
47
49
  };
48
50
 
49
51
  export const Farger = () => {
package/src/chat/index.ts CHANGED
@@ -1 +1 @@
1
- export { default as Chat, ChatProps } from "./Chat";
1
+ export { default as Chat, type ChatProps } from "./Chat";
@@ -1,7 +1,7 @@
1
1
  import { Close } from "@navikt/ds-icons";
2
2
  import cl from "clsx";
3
3
  import React, { forwardRef } from "react";
4
- import { OverridableComponent } from "..";
4
+ import { OverridableComponent } from "../util/OverridableComponent";
5
5
 
6
6
  export interface RemovableChipsProps
7
7
  extends React.ButtonHTMLAttributes<HTMLButtonElement> {
@@ -1,7 +1,7 @@
1
1
  import { SuccessStroke } from "@navikt/ds-icons";
2
2
  import cl from "clsx";
3
3
  import React, { forwardRef } from "react";
4
- import { OverridableComponent } from "..";
4
+ import { OverridableComponent } from "../util/OverridableComponent";
5
5
 
6
6
  export interface ToggleChipsProps
7
7
  extends React.ButtonHTMLAttributes<HTMLButtonElement> {
@@ -1,3 +1,4 @@
1
+ /* eslint-disable react-hooks/rules-of-hooks */
1
2
  import React, { useState } from "react";
2
3
  import { Chips } from ".";
3
4
 
@@ -22,44 +23,46 @@ export default {
22
23
 
23
24
  const options = ["Norsk", "Dansk", "Svensk", "Tysk", "Spansk"];
24
25
 
25
- export const Default = (props) => {
26
- const [selected, setSelected] = useState(["Dansk", "Svensk"]);
27
- const [filter, setFilter] = useState(options);
26
+ export const Default = {
27
+ render: (props) => {
28
+ const [selected, setSelected] = useState(["Dansk", "Svensk"]);
29
+ const [filter, setFilter] = useState(options);
30
+
31
+ if (props.type === "toggle") {
32
+ return (
33
+ <Chips size={props.size ?? "medium"}>
34
+ {options.map((c) => (
35
+ <Chips.Toggle
36
+ selected={selected.includes(c)}
37
+ key={c}
38
+ onClick={() =>
39
+ setSelected(
40
+ selected.includes(c)
41
+ ? selected.filter((x) => x !== c)
42
+ : [...selected, c]
43
+ )
44
+ }
45
+ >
46
+ {c}
47
+ </Chips.Toggle>
48
+ ))}
49
+ </Chips>
50
+ );
51
+ }
28
52
 
29
- if (props.type === "toggle") {
30
53
  return (
31
54
  <Chips size={props.size ?? "medium"}>
32
- {options.map((c) => (
33
- <Chips.Toggle
34
- selected={selected.includes(c)}
55
+ {filter.map((c) => (
56
+ <Chips.Removable
35
57
  key={c}
36
- onClick={() =>
37
- setSelected(
38
- selected.includes(c)
39
- ? selected.filter((x) => x !== c)
40
- : [...selected, c]
41
- )
42
- }
58
+ onClick={() => setFilter((x) => x.filter((y) => y !== c))}
43
59
  >
44
60
  {c}
45
- </Chips.Toggle>
61
+ </Chips.Removable>
46
62
  ))}
47
63
  </Chips>
48
64
  );
49
- }
50
-
51
- return (
52
- <Chips size={props.size ?? "medium"}>
53
- {filter.map((c) => (
54
- <Chips.Removable
55
- key={c}
56
- onClick={() => setFilter((x) => x.filter((y) => y !== c))}
57
- >
58
- {c}
59
- </Chips.Removable>
60
- ))}
61
- </Chips>
62
- );
65
+ },
63
66
  };
64
67
 
65
68
  export const Toggle = () => {
@@ -1 +1 @@
1
- export { default as Chips, ChipsProps } from "./Chips";
1
+ export { default as Chips, type ChipsProps } from "./Chips";
@@ -1,3 +1,4 @@
1
+ /* eslint-disable react-hooks/rules-of-hooks */
1
2
  import React, { useId, useState } from "react";
2
3
  import { UNSAFE_useDatepicker, UNSAFE_useRangeDatepicker } from "..";
3
4
  import { Button } from "../..";
@@ -34,93 +35,95 @@ export default {
34
35
  },
35
36
  };
36
37
 
37
- export const Default = (props) => {
38
- const [open, setOpen] = useState(false);
38
+ export const Default = {
39
+ render: (props) => {
40
+ const [open, setOpen] = useState(false);
39
41
 
40
- const rangeCtx = UNSAFE_useRangeDatepicker({
41
- fromDate: new Date("Aug 23 2020"),
42
- toDate: new Date("Aug 23 2023"),
43
- });
42
+ const rangeCtx = UNSAFE_useRangeDatepicker({
43
+ fromDate: new Date("Aug 23 2020"),
44
+ toDate: new Date("Aug 23 2023"),
45
+ });
44
46
 
45
- const singleCtx = UNSAFE_useDatepicker({
46
- fromDate: new Date("Aug 23 2020"),
47
- toDate: new Date("Aug 23 2023"),
48
- });
47
+ const singleCtx = UNSAFE_useDatepicker({
48
+ fromDate: new Date("Aug 23 2020"),
49
+ toDate: new Date("Aug 23 2023"),
50
+ });
49
51
 
50
- const newProps = {
51
- ...(!props.inputfield || props.mode === "multiple"
52
- ? {
53
- open,
54
- onClose: () => setOpen(false),
55
- fromDate: new Date("Aug 23 2020"),
56
- toDate: new Date("Aug 23 2023"),
57
- }
58
- : {}),
59
- };
52
+ const newProps = {
53
+ ...(!props.inputfield || props.mode === "multiple"
54
+ ? {
55
+ open,
56
+ onClose: () => setOpen(false),
57
+ fromDate: new Date("Aug 23 2020"),
58
+ toDate: new Date("Aug 23 2023"),
59
+ }
60
+ : {}),
61
+ };
60
62
 
61
- const Comp = !props.standalone ? DatePicker : DatePicker.Standalone;
63
+ const Comp = !props.standalone ? DatePicker : DatePicker.Standalone;
62
64
 
63
- return (
64
- <div>
65
- <Comp
66
- locale={props?.locale}
67
- dropdownCaption={props?.dropdownCaption}
68
- disableWeekends={props?.disableWeekends}
69
- showWeekNumber={props.showWeekNumber}
70
- mode={props.mode}
71
- {...(props.mode === "single"
72
- ? singleCtx.datepickerProps
73
- : props.mode === "range"
74
- ? rangeCtx.datepickerProps
75
- : {})}
76
- {...newProps}
77
- >
78
- {!props.standalone && (
79
- <>
80
- {props.inputfield && props.mode !== "multiple" ? (
81
- <>
82
- {props.mode === "range" ? (
83
- <div style={{ display: "flex", gap: "1rem" }}>
84
- <DatePicker.Input
85
- label="Fra"
86
- size={props?.size}
87
- {...rangeCtx.fromInputProps}
88
- />
89
- <DatePicker.Input
90
- label="Til"
91
- size={props?.size}
92
- {...rangeCtx.toInputProps}
93
- />
94
- </div>
95
- ) : (
96
- <>
97
- <DatePicker.Input
98
- label="Velg dato"
99
- size={props?.size}
100
- {...singleCtx.inputProps}
101
- />
102
- </>
103
- )}
104
- </>
105
- ) : (
106
- <Button onClick={() => setOpen((x) => !x)}>
107
- Åpne datovelger
108
- </Button>
109
- )}
110
- </>
111
- )}
112
- </Comp>
113
- </div>
114
- );
115
- };
65
+ return (
66
+ <div>
67
+ <Comp
68
+ locale={props?.locale}
69
+ dropdownCaption={props?.dropdownCaption}
70
+ disableWeekends={props?.disableWeekends}
71
+ showWeekNumber={props.showWeekNumber}
72
+ mode={props.mode}
73
+ {...(props.mode === "single"
74
+ ? singleCtx.datepickerProps
75
+ : props.mode === "range"
76
+ ? rangeCtx.datepickerProps
77
+ : {})}
78
+ {...newProps}
79
+ >
80
+ {!props.standalone && (
81
+ <>
82
+ {props.inputfield && props.mode !== "multiple" ? (
83
+ <>
84
+ {props.mode === "range" ? (
85
+ <div style={{ display: "flex", gap: "1rem" }}>
86
+ <DatePicker.Input
87
+ label="Fra"
88
+ size={props?.size}
89
+ {...rangeCtx.fromInputProps}
90
+ />
91
+ <DatePicker.Input
92
+ label="Til"
93
+ size={props?.size}
94
+ {...rangeCtx.toInputProps}
95
+ />
96
+ </div>
97
+ ) : (
98
+ <>
99
+ <DatePicker.Input
100
+ label="Velg dato"
101
+ size={props?.size}
102
+ {...singleCtx.inputProps}
103
+ />
104
+ </>
105
+ )}
106
+ </>
107
+ ) : (
108
+ <Button onClick={() => setOpen((x) => !x)}>
109
+ Åpne datovelger
110
+ </Button>
111
+ )}
112
+ </>
113
+ )}
114
+ </Comp>
115
+ </div>
116
+ );
117
+ },
116
118
 
117
- Default.args = {
118
- dropdownCaption: false,
119
- disableWeekends: false,
120
- showWeekNumber: false,
121
- inputfield: true,
122
- standalone: false,
123
- openOnFocus: true,
119
+ args: {
120
+ dropdownCaption: false,
121
+ disableWeekends: false,
122
+ showWeekNumber: false,
123
+ inputfield: true,
124
+ standalone: false,
125
+ openOnFocus: true,
126
+ },
124
127
  };
125
128
 
126
129
  export const DropdownCaption = () => (
@@ -198,9 +201,11 @@ export const OpenOnFocus = () => {
198
201
  export const NB = () => (
199
202
  <DatePicker.Standalone locale="nb" today={new Date("2006-07-01")} />
200
203
  );
204
+
201
205
  export const NN = () => (
202
206
  <DatePicker.Standalone locale="nn" today={new Date("2006-07-01")} />
203
207
  );
208
+
204
209
  export const EN = () => (
205
210
  <DatePicker.Standalone locale="en" today={new Date("2006-07-01")} />
206
211
  );
@@ -212,6 +217,7 @@ export const Standalone = () => (
212
217
  export const StandaloneRange = () => (
213
218
  <DatePicker.Standalone mode="range" today={new Date("2006-07-01")} />
214
219
  );
220
+
215
221
  export const StandaloneMultiple = () => (
216
222
  <DatePicker.Standalone mode="multiple" today={new Date("2006-07-01")} />
217
223
  );
@@ -388,11 +388,11 @@ export const useRangeDatepicker = (
388
388
  formatDateForInput(prevToRange, locale, "date", inputFormat)
389
389
  )
390
390
  : setToInputValue("");
391
+ updateRange({ from: range?.from, to: resetTo ? undefined : prevToRange });
391
392
  updateValidation(
392
393
  { isValidDate: !!range?.from, isEmpty: !range?.from },
393
394
  { isValidDate: !!range?.to, isEmpty: !prevToRange || resetTo }
394
395
  );
395
- updateRange({ from: range?.from, to: resetTo ? undefined : prevToRange });
396
396
  };
397
397
 
398
398
  const fromChange = (
package/src/date/index.ts CHANGED
@@ -1,19 +1,19 @@
1
- export { DateInputProps } from "./DateInput";
1
+ export { type DateInputProps } from "./DateInput";
2
2
  export {
3
- DatePickerProps,
3
+ type DatePickerProps,
4
4
  default as UNSAFE_DatePicker,
5
5
  } from "./datepicker/DatePicker";
6
- export { DatePickerStandaloneProps } from "./datepicker/DatePickerStandalone";
7
- export { MonthPickerStandaloneProps } from "./monthpicker/MonthPickerStandalone";
6
+ export { type DatePickerStandaloneProps } from "./datepicker/DatePickerStandalone";
7
+ export { type MonthPickerStandaloneProps } from "./monthpicker/MonthPickerStandalone";
8
8
  export {
9
9
  UNSAFE_useDatepicker,
10
10
  UNSAFE_useMonthpicker,
11
11
  UNSAFE_useRangeDatepicker,
12
- RangeValidationT,
13
- DateValidationT,
14
- MonthValidationT,
12
+ type RangeValidationT,
13
+ type DateValidationT,
14
+ type MonthValidationT,
15
15
  } from "./hooks";
16
16
  export {
17
17
  default as UNSAFE_MonthPicker,
18
- MonthPickerProps,
18
+ type MonthPickerProps,
19
19
  } from "./monthpicker/MonthPicker";