@navikt/ds-react 3.4.1 → 4.0.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 (234) hide show
  1. package/_docs.json +5615 -3780
  2. package/cjs/date/hooks/index.js +4 -4
  3. package/cjs/date/index.js +6 -6
  4. package/cjs/dropdown/Dropdown.js +57 -0
  5. package/cjs/dropdown/Menu/Divider.js +47 -0
  6. package/cjs/dropdown/Menu/GroupedList/Heading.js +47 -0
  7. package/cjs/dropdown/Menu/GroupedList/Item.js +54 -0
  8. package/cjs/dropdown/Menu/GroupedList/index.js +51 -0
  9. package/cjs/dropdown/Menu/GroupedList/package.json +6 -0
  10. package/cjs/dropdown/Menu/List/Item.js +54 -0
  11. package/cjs/dropdown/Menu/List/index.js +49 -0
  12. package/cjs/dropdown/Menu/List/package.json +6 -0
  13. package/cjs/dropdown/Menu/index.js +64 -0
  14. package/cjs/dropdown/Menu/package.json +6 -0
  15. package/cjs/dropdown/Toggle.js +66 -0
  16. package/cjs/dropdown/index.js +23 -0
  17. package/cjs/dropdown/package.json +6 -0
  18. package/cjs/form/radio/RadioGroup.js +10 -0
  19. package/cjs/index.js +3 -0
  20. package/cjs/internal-header/InternalHeader.js +55 -0
  21. package/cjs/internal-header/InternalHeaderButton.js +47 -0
  22. package/cjs/internal-header/InternalHeaderTitle.js +48 -0
  23. package/cjs/internal-header/InternalHeaderUser.js +51 -0
  24. package/cjs/internal-header/InternalHeaderUserButton.js +54 -0
  25. package/cjs/internal-header/index.js +8 -0
  26. package/cjs/internal-header/package.json +6 -0
  27. package/cjs/read-more/ReadMore.js +17 -0
  28. package/cjs/timeline/AxisLabels.js +90 -0
  29. package/cjs/timeline/Pin.js +106 -0
  30. package/cjs/timeline/Timeline.js +162 -0
  31. package/cjs/timeline/TimelineRow.js +86 -0
  32. package/cjs/timeline/hooks/usePeriodContext.js +16 -0
  33. package/cjs/timeline/hooks/useRowContext.js +18 -0
  34. package/cjs/timeline/hooks/useTimelineContext.js +23 -0
  35. package/cjs/timeline/hooks/useTimelineRows.js +79 -0
  36. package/cjs/timeline/index.js +8 -0
  37. package/cjs/timeline/package.json +6 -0
  38. package/cjs/timeline/period/ClickablePeriod.js +120 -0
  39. package/cjs/timeline/period/NonClickablePeriod.js +18 -0
  40. package/cjs/timeline/period/index.js +46 -0
  41. package/cjs/timeline/period/package.json +6 -0
  42. package/cjs/timeline/utils/calc.js +19 -0
  43. package/cjs/timeline/utils/filter.js +18 -0
  44. package/cjs/timeline/utils/index.js +7 -0
  45. package/cjs/timeline/utils/package.json +6 -0
  46. package/cjs/timeline/utils/period.js +40 -0
  47. package/cjs/timeline/utils/sort.js +10 -0
  48. package/cjs/timeline/utils/timeline.js +79 -0
  49. package/cjs/timeline/utils/types.external.js +2 -0
  50. package/cjs/timeline/utils/types.internal.js +2 -0
  51. package/cjs/timeline/zoom/ZoomButton.js +68 -0
  52. package/cjs/timeline/zoom/index.js +50 -0
  53. package/cjs/timeline/zoom/package.json +6 -0
  54. package/esm/date/hooks/index.d.ts +3 -3
  55. package/esm/date/hooks/index.js +3 -3
  56. package/esm/date/hooks/index.js.map +1 -1
  57. package/esm/date/index.d.ts +3 -3
  58. package/esm/date/index.js +3 -3
  59. package/esm/date/index.js.map +1 -1
  60. package/esm/dropdown/Dropdown.d.ts +37 -0
  61. package/esm/dropdown/Dropdown.js +29 -0
  62. package/esm/dropdown/Dropdown.js.map +1 -0
  63. package/esm/dropdown/Menu/Divider.d.ts +4 -0
  64. package/esm/dropdown/Menu/Divider.js +19 -0
  65. package/esm/dropdown/Menu/Divider.js.map +1 -0
  66. package/esm/dropdown/Menu/GroupedList/Heading.d.ts +10 -0
  67. package/esm/dropdown/Menu/GroupedList/Heading.js +19 -0
  68. package/esm/dropdown/Menu/GroupedList/Heading.js.map +1 -0
  69. package/esm/dropdown/Menu/GroupedList/Item.d.ts +11 -0
  70. package/esm/dropdown/Menu/GroupedList/Item.js +26 -0
  71. package/esm/dropdown/Menu/GroupedList/Item.js.map +1 -0
  72. package/esm/dropdown/Menu/GroupedList/index.d.ts +15 -0
  73. package/esm/dropdown/Menu/GroupedList/index.js +23 -0
  74. package/esm/dropdown/Menu/GroupedList/index.js.map +1 -0
  75. package/esm/dropdown/Menu/List/Item.d.ts +11 -0
  76. package/esm/dropdown/Menu/List/Item.js +26 -0
  77. package/esm/dropdown/Menu/List/Item.js.map +1 -0
  78. package/esm/dropdown/Menu/List/index.d.ts +13 -0
  79. package/esm/dropdown/Menu/List/index.js +21 -0
  80. package/esm/dropdown/Menu/List/index.js.map +1 -0
  81. package/esm/dropdown/Menu/index.d.ts +27 -0
  82. package/esm/dropdown/Menu/index.js +36 -0
  83. package/esm/dropdown/Menu/index.js.map +1 -0
  84. package/esm/dropdown/Toggle.d.ts +10 -0
  85. package/esm/dropdown/Toggle.js +38 -0
  86. package/esm/dropdown/Toggle.js.map +1 -0
  87. package/esm/dropdown/index.d.ts +2 -0
  88. package/esm/dropdown/index.js +3 -0
  89. package/esm/dropdown/index.js.map +1 -0
  90. package/esm/form/radio/RadioGroup.d.ts +10 -0
  91. package/esm/form/radio/RadioGroup.js +10 -0
  92. package/esm/form/radio/RadioGroup.js.map +1 -1
  93. package/esm/index.d.ts +3 -0
  94. package/esm/index.js +3 -0
  95. package/esm/index.js.map +1 -1
  96. package/esm/internal-header/InternalHeader.d.ts +16 -0
  97. package/esm/internal-header/InternalHeader.js +27 -0
  98. package/esm/internal-header/InternalHeader.js.map +1 -0
  99. package/esm/internal-header/InternalHeaderButton.d.ts +11 -0
  100. package/esm/internal-header/InternalHeaderButton.js +19 -0
  101. package/esm/internal-header/InternalHeaderButton.js.map +1 -0
  102. package/esm/internal-header/InternalHeaderTitle.d.ts +11 -0
  103. package/esm/internal-header/InternalHeaderTitle.js +20 -0
  104. package/esm/internal-header/InternalHeaderTitle.js.map +1 -0
  105. package/esm/internal-header/InternalHeaderUser.d.ts +14 -0
  106. package/esm/internal-header/InternalHeaderUser.js +23 -0
  107. package/esm/internal-header/InternalHeaderUser.js.map +1 -0
  108. package/esm/internal-header/InternalHeaderUserButton.d.ts +15 -0
  109. package/esm/internal-header/InternalHeaderUserButton.js +26 -0
  110. package/esm/internal-header/InternalHeaderUserButton.js.map +1 -0
  111. package/esm/internal-header/index.d.ts +5 -0
  112. package/esm/internal-header/index.js +2 -0
  113. package/esm/internal-header/index.js.map +1 -0
  114. package/esm/read-more/ReadMore.d.ts +17 -0
  115. package/esm/read-more/ReadMore.js +17 -0
  116. package/esm/read-more/ReadMore.js.map +1 -1
  117. package/esm/timeline/AxisLabels.d.ts +6 -0
  118. package/esm/timeline/AxisLabels.js +81 -0
  119. package/esm/timeline/AxisLabels.js.map +1 -0
  120. package/esm/timeline/Pin.d.ts +17 -0
  121. package/esm/timeline/Pin.js +81 -0
  122. package/esm/timeline/Pin.js.map +1 -0
  123. package/esm/timeline/Timeline.d.ts +45 -0
  124. package/esm/timeline/Timeline.js +134 -0
  125. package/esm/timeline/Timeline.js.map +1 -0
  126. package/esm/timeline/TimelineRow.d.ts +22 -0
  127. package/esm/timeline/TimelineRow.js +58 -0
  128. package/esm/timeline/TimelineRow.js.map +1 -0
  129. package/esm/timeline/hooks/usePeriodContext.d.ts +9 -0
  130. package/esm/timeline/hooks/usePeriodContext.js +13 -0
  131. package/esm/timeline/hooks/usePeriodContext.js.map +1 -0
  132. package/esm/timeline/hooks/useRowContext.d.ts +11 -0
  133. package/esm/timeline/hooks/useRowContext.js +15 -0
  134. package/esm/timeline/hooks/useRowContext.js.map +1 -0
  135. package/esm/timeline/hooks/useTimelineContext.d.ts +15 -0
  136. package/esm/timeline/hooks/useTimelineContext.js +20 -0
  137. package/esm/timeline/hooks/useTimelineContext.js.map +1 -0
  138. package/esm/timeline/hooks/useTimelineRows.d.ts +4 -0
  139. package/esm/timeline/hooks/useTimelineRows.js +74 -0
  140. package/esm/timeline/hooks/useTimelineRows.js.map +1 -0
  141. package/esm/timeline/index.d.ts +6 -0
  142. package/esm/timeline/index.js +2 -0
  143. package/esm/timeline/index.js.map +1 -0
  144. package/esm/timeline/period/ClickablePeriod.d.ts +9 -0
  145. package/esm/timeline/period/ClickablePeriod.js +93 -0
  146. package/esm/timeline/period/ClickablePeriod.js.map +1 -0
  147. package/esm/timeline/period/NonClickablePeriod.d.ts +7 -0
  148. package/esm/timeline/period/NonClickablePeriod.js +14 -0
  149. package/esm/timeline/period/NonClickablePeriod.js.map +1 -0
  150. package/esm/timeline/period/index.d.ts +57 -0
  151. package/esm/timeline/period/index.js +18 -0
  152. package/esm/timeline/period/index.js.map +1 -0
  153. package/esm/timeline/utils/calc.d.ts +5 -0
  154. package/esm/timeline/utils/calc.js +15 -0
  155. package/esm/timeline/utils/calc.js.map +1 -0
  156. package/esm/timeline/utils/filter.d.ts +10 -0
  157. package/esm/timeline/utils/filter.js +11 -0
  158. package/esm/timeline/utils/filter.js.map +1 -0
  159. package/esm/timeline/utils/index.d.ts +1 -0
  160. package/esm/timeline/utils/index.js +2 -0
  161. package/esm/timeline/utils/index.js.map +1 -0
  162. package/esm/timeline/utils/period.d.ts +2 -0
  163. package/esm/timeline/utils/period.js +33 -0
  164. package/esm/timeline/utils/period.js.map +1 -0
  165. package/esm/timeline/utils/sort.d.ts +4 -0
  166. package/esm/timeline/utils/sort.js +5 -0
  167. package/esm/timeline/utils/sort.js.map +1 -0
  168. package/esm/timeline/utils/timeline.d.ts +12 -0
  169. package/esm/timeline/utils/timeline.js +73 -0
  170. package/esm/timeline/utils/timeline.js.map +1 -0
  171. package/esm/timeline/utils/types.external.d.ts +53 -0
  172. package/esm/timeline/utils/types.external.js +2 -0
  173. package/esm/timeline/utils/types.external.js.map +1 -0
  174. package/esm/timeline/utils/types.internal.d.ts +61 -0
  175. package/esm/timeline/utils/types.internal.js +2 -0
  176. package/esm/timeline/utils/types.internal.js.map +1 -0
  177. package/esm/timeline/zoom/ZoomButton.d.ts +19 -0
  178. package/esm/timeline/zoom/ZoomButton.js +43 -0
  179. package/esm/timeline/zoom/ZoomButton.js.map +1 -0
  180. package/esm/timeline/zoom/index.d.ts +11 -0
  181. package/esm/timeline/zoom/index.js +22 -0
  182. package/esm/timeline/zoom/index.js.map +1 -0
  183. package/package.json +2 -2
  184. package/src/date/datepicker/datepicker.stories.tsx +19 -21
  185. package/src/date/datepicker/datepicker.test.tsx +5 -5
  186. package/src/date/hooks/index.ts +3 -3
  187. package/src/date/hooks/useRangeDatepicker.test.tsx +6 -6
  188. package/src/date/index.ts +5 -5
  189. package/src/date/monthpicker/monthpicker.stories.tsx +5 -5
  190. package/src/date/utils/__tests__/get-dates.test.ts +0 -1
  191. package/src/dropdown/Dropdown.tsx +80 -0
  192. package/src/dropdown/Menu/Divider.tsx +18 -0
  193. package/src/dropdown/Menu/GroupedList/Heading.tsx +31 -0
  194. package/src/dropdown/Menu/GroupedList/Item.tsx +45 -0
  195. package/src/dropdown/Menu/GroupedList/index.tsx +33 -0
  196. package/src/dropdown/Menu/List/Item.tsx +44 -0
  197. package/src/dropdown/Menu/List/index.tsx +27 -0
  198. package/src/dropdown/Menu/index.tsx +85 -0
  199. package/src/dropdown/Toggle.tsx +52 -0
  200. package/src/dropdown/dropdown.stories.tsx +91 -0
  201. package/src/dropdown/index.ts +2 -0
  202. package/src/form/radio/RadioGroup.tsx +10 -0
  203. package/src/index.ts +3 -0
  204. package/src/internal-header/InternalHeader.tsx +44 -0
  205. package/src/internal-header/InternalHeaderButton.tsx +28 -0
  206. package/src/internal-header/InternalHeaderTitle.tsx +35 -0
  207. package/src/internal-header/InternalHeaderUser.tsx +39 -0
  208. package/src/internal-header/InternalHeaderUserButton.tsx +43 -0
  209. package/src/internal-header/header.stories.tsx +225 -0
  210. package/src/internal-header/index.ts +8 -0
  211. package/src/read-more/ReadMore.tsx +17 -0
  212. package/src/timeline/AxisLabels.tsx +143 -0
  213. package/src/timeline/Pin.tsx +169 -0
  214. package/src/timeline/Timeline.tsx +219 -0
  215. package/src/timeline/TimelineRow.tsx +122 -0
  216. package/src/timeline/hooks/usePeriodContext.tsx +22 -0
  217. package/src/timeline/hooks/useRowContext.tsx +26 -0
  218. package/src/timeline/hooks/useTimelineContext.tsx +37 -0
  219. package/src/timeline/hooks/useTimelineRows.ts +161 -0
  220. package/src/timeline/index.ts +6 -0
  221. package/src/timeline/period/ClickablePeriod.tsx +193 -0
  222. package/src/timeline/period/NonClickablePeriod.tsx +46 -0
  223. package/src/timeline/period/index.tsx +130 -0
  224. package/src/timeline/timeline.stories.tsx +444 -0
  225. package/src/timeline/utils/calc.ts +26 -0
  226. package/src/timeline/utils/filter.ts +32 -0
  227. package/src/timeline/utils/index.ts +6 -0
  228. package/src/timeline/utils/period.ts +48 -0
  229. package/src/timeline/utils/sort.ts +11 -0
  230. package/src/timeline/utils/timeline.ts +83 -0
  231. package/src/timeline/utils/types.external.ts +67 -0
  232. package/src/timeline/utils/types.internal.ts +76 -0
  233. package/src/timeline/zoom/ZoomButton.tsx +83 -0
  234. package/src/timeline/zoom/index.tsx +30 -0
@@ -0,0 +1,444 @@
1
+ import { CheckmarkCircleFillIcon } from "@navikt/aksel-icons";
2
+ import { useState } from "@storybook/addons";
3
+ import { Meta } from "@storybook/react";
4
+ import * as React from "react";
5
+ import Timeline from "./Timeline";
6
+
7
+ export default {
8
+ title: "ds-react/Timeline",
9
+ component: Timeline,
10
+ argTypes: {},
11
+ } as Meta;
12
+
13
+ const DummyLabel = () => {
14
+ return (
15
+ <div
16
+ style={{
17
+ width: "239px",
18
+ margin: 0,
19
+ textAlign: "left",
20
+ fontSize: "14px",
21
+ }}
22
+ >
23
+ <p>Periode: 15.07.2019 - 25.07.2019</p>
24
+ <p>Utbetalt: 12 345,00 kr</p>
25
+ <p style={{ color: "red" }}>Dager igjen: 0</p>
26
+ </div>
27
+ );
28
+ };
29
+
30
+ const row1 = [
31
+ {
32
+ id: "1",
33
+ start: new Date("Jan 1 2022"),
34
+ end: new Date("Jan 31 2022"),
35
+ status: "success",
36
+ icon: <CheckmarkCircleFillIcon aria-hidden />,
37
+ statusLabel: "Sykemeldt",
38
+ },
39
+ {
40
+ id: "2",
41
+ start: new Date("Feb 1 2022"),
42
+ end: new Date("Mar 15 2022"),
43
+ status: "danger",
44
+ onSelectPeriod: () => console.log("PERIOD SELECTED!"),
45
+ statusLabel: "Sykemeldt",
46
+ },
47
+ {
48
+ id: "3",
49
+ start: new Date("May 2 2022"),
50
+ end: new Date("May 25 2022"),
51
+ status: "success",
52
+ icon: <CheckmarkCircleFillIcon aria-hidden />,
53
+ statusLabel: "Sykemeldt",
54
+ },
55
+ {
56
+ id: "4",
57
+ start: new Date("Mar 1 2022"),
58
+ end: new Date("Mar 31 2022"),
59
+ status: "success",
60
+ onSelectPeriod: () => console.log("PERIOD SELECTED!"),
61
+ icon: <CheckmarkCircleFillIcon aria-hidden />,
62
+ label: "test",
63
+ statusLabel: "Sykemeldt",
64
+ },
65
+ {
66
+ id: "5",
67
+ start: new Date("Jul 1 2022"),
68
+ end: new Date("Jul 31 2022"),
69
+ status: "warning",
70
+ icon: <CheckmarkCircleFillIcon aria-hidden />,
71
+ onSelectPeriod: () => console.log("PERIOD SELECTED!"),
72
+ statusLabel: "Sykemeldt",
73
+ },
74
+ {
75
+ id: "6",
76
+ start: new Date("Aug 1 2022"),
77
+ end: new Date("Aug 30 2022"),
78
+ status: "warning",
79
+ icon: <CheckmarkCircleFillIcon aria-hidden />,
80
+ statusLabel: "Sykemeldt",
81
+ },
82
+ ];
83
+
84
+ const row2 = [
85
+ {
86
+ id: "7",
87
+ start: new Date("May 13 2022"),
88
+ end: new Date("May 25 2022"),
89
+ status: "warning",
90
+ onSelectPeriod: () => console.log("PERIOD SELECTED!"),
91
+ icon: <CheckmarkCircleFillIcon aria-hidden />,
92
+ children: <DummyLabel />,
93
+ },
94
+ {
95
+ id: "8",
96
+ start: new Date("Feb 1 2022"),
97
+ end: new Date("May 2 2022"),
98
+ status: "neutral",
99
+ onSelectPeriod: () => console.log("PERIOD SELECTED!"),
100
+ icon: <CheckmarkCircleFillIcon aria-hidden />,
101
+ children: <DummyLabel />,
102
+ },
103
+ ];
104
+
105
+ export const Default = () => {
106
+ return (
107
+ <div style={{ width: "80vw" }}>
108
+ <Timeline>
109
+ <Timeline.Row
110
+ label="Row 1"
111
+ icon={<CheckmarkCircleFillIcon aria-hidden />}
112
+ >
113
+ {row1.map((p: any, i) => {
114
+ return (
115
+ <Timeline.Period
116
+ key={p.id}
117
+ start={p.start}
118
+ end={p.end}
119
+ status={p.status}
120
+ icon={p.icon}
121
+ />
122
+ );
123
+ })}
124
+ </Timeline.Row>
125
+ <Timeline.Row
126
+ label="Row 2"
127
+ icon={<CheckmarkCircleFillIcon aria-hidden />}
128
+ >
129
+ {row2.map((p: any, i) => {
130
+ return (
131
+ <Timeline.Period
132
+ key={p.id}
133
+ start={p.start}
134
+ end={p.end}
135
+ status={p.status}
136
+ icon={p.icon}
137
+ />
138
+ );
139
+ })}
140
+ </Timeline.Row>
141
+ </Timeline>
142
+ </div>
143
+ );
144
+ };
145
+
146
+ export const WithPins = () => {
147
+ return (
148
+ <div style={{ width: "80vw" }}>
149
+ <Timeline>
150
+ <Timeline.Pin date={new Date("Apr 15 2022")}>Pin 1</Timeline.Pin>
151
+ <Timeline.Pin date={new Date("Jun 12 2022")}>Pin 2</Timeline.Pin>
152
+ <Timeline.Pin date={new Date("Jul 28 2022")}>Pin 3</Timeline.Pin>
153
+ <Timeline.Row
154
+ label="Row 1"
155
+ icon={<CheckmarkCircleFillIcon aria-hidden />}
156
+ >
157
+ {row1.map((p: any, i) => {
158
+ return (
159
+ <Timeline.Period
160
+ key={p.id}
161
+ start={p.start}
162
+ end={p.end}
163
+ status={p.status}
164
+ icon={p.icon}
165
+ />
166
+ );
167
+ })}
168
+ </Timeline.Row>
169
+ <Timeline.Row
170
+ label="Row 2"
171
+ icon={<CheckmarkCircleFillIcon aria-hidden />}
172
+ >
173
+ {row2.map((p: any, i) => {
174
+ return (
175
+ <Timeline.Period
176
+ key={p.id}
177
+ start={p.start}
178
+ end={p.end}
179
+ status={p.status}
180
+ icon={p.icon}
181
+ />
182
+ );
183
+ })}
184
+ </Timeline.Row>
185
+ </Timeline>
186
+ </div>
187
+ );
188
+ };
189
+
190
+ export const WithZoom = () => {
191
+ return (
192
+ <div style={{ width: "80vw" }}>
193
+ <Timeline>
194
+ <Timeline.Row
195
+ label="Row 1"
196
+ icon={<CheckmarkCircleFillIcon aria-hidden />}
197
+ >
198
+ {row1.map((p: any, i) => {
199
+ return (
200
+ <Timeline.Period
201
+ key={p.id}
202
+ start={p.start}
203
+ end={p.end}
204
+ status={p.status}
205
+ icon={p.icon}
206
+ />
207
+ );
208
+ })}
209
+ </Timeline.Row>
210
+ <Timeline.Row
211
+ label="Row 2"
212
+ icon={<CheckmarkCircleFillIcon aria-hidden />}
213
+ >
214
+ {row2.map((p: any, i) => {
215
+ return (
216
+ <Timeline.Period
217
+ key={p.id}
218
+ start={p.start}
219
+ end={p.end}
220
+ status={p.status}
221
+ icon={p.icon}
222
+ />
223
+ );
224
+ })}
225
+ </Timeline.Row>
226
+ <Timeline.Zoom>
227
+ <Timeline.Zoom.Button label="3 mnd" interval="month" count={3} />
228
+ <Timeline.Zoom.Button label="7 mnd" interval="month" count={7} />
229
+ <Timeline.Zoom.Button label="9 mnd" interval="month" count={9} />
230
+ </Timeline.Zoom>
231
+ </Timeline>
232
+ </div>
233
+ );
234
+ };
235
+
236
+ export const ActivePeriod = () => {
237
+ const [activePeriod, setActivePeriod] = useState(row1[0]);
238
+
239
+ return (
240
+ <div style={{ width: "80vw" }}>
241
+ <Timeline>
242
+ <Timeline.Pin date={new Date("Apr 15 2022")}>Pin 1</Timeline.Pin>
243
+ <Timeline.Pin date={new Date("Jun 12 2022")}>Pin 2</Timeline.Pin>
244
+ <Timeline.Pin date={new Date("Jul 28 2022")}>Pin 3</Timeline.Pin>
245
+ <Timeline.Row
246
+ label="Rad 1"
247
+ icon={<CheckmarkCircleFillIcon aria-hidden />}
248
+ >
249
+ {row1.map((p: any, i) => {
250
+ return (
251
+ <Timeline.Period
252
+ key={p.id}
253
+ start={p.start}
254
+ end={p.end}
255
+ status={p.status}
256
+ onSelectPeriod={() => {
257
+ setActivePeriod(p);
258
+ p?.onSelectPeriod?.();
259
+ console.log("PERIOD SELECTED!");
260
+ }}
261
+ icon={p.icon}
262
+ isActive={activePeriod.id === p.id}
263
+ statusLabel={p.statusLabel}
264
+ >
265
+ {p.children}
266
+ </Timeline.Period>
267
+ );
268
+ })}
269
+ </Timeline.Row>
270
+ <Timeline.Row label="Rad 2">
271
+ {row2.map((p: any, i) => {
272
+ return (
273
+ <Timeline.Period
274
+ key={p.id}
275
+ start={p.start}
276
+ end={p.end}
277
+ status={p.status}
278
+ onSelectPeriod={() => {
279
+ setActivePeriod(p);
280
+ p?.onSelectPeriod?.();
281
+ }}
282
+ icon={p.icon}
283
+ isActive={activePeriod.id === p.id}
284
+ statusLabel={p.statusLabel}
285
+ >
286
+ {p.children}
287
+ </Timeline.Period>
288
+ );
289
+ })}
290
+ </Timeline.Row>
291
+ <Timeline.Row label="Rad 3">
292
+ <Timeline.Period
293
+ start={new Date("Jan 1 2022")}
294
+ end={new Date("Aug 20 2022")}
295
+ status="info"
296
+ icon={<CheckmarkCircleFillIcon aria-hidden />}
297
+ />
298
+ </Timeline.Row>
299
+ </Timeline>
300
+ </div>
301
+ );
302
+ };
303
+
304
+ export const WithDayLabels = () => {
305
+ return (
306
+ <div style={{ width: "80vw" }}>
307
+ <Timeline>
308
+ <Timeline.Row
309
+ label="Row 1"
310
+ icon={<CheckmarkCircleFillIcon aria-hidden />}
311
+ >
312
+ <Timeline.Period
313
+ start={new Date("Feb 4 2022")}
314
+ end={new Date("Feb 13 2022")}
315
+ status="success"
316
+ />
317
+ </Timeline.Row>
318
+ <Timeline.Row
319
+ label="Row 2"
320
+ icon={<CheckmarkCircleFillIcon aria-hidden />}
321
+ >
322
+ <Timeline.Period
323
+ start={new Date("Feb 17 2022")}
324
+ end={new Date("Feb 22 2022")}
325
+ status="warning"
326
+ />
327
+ </Timeline.Row>
328
+ </Timeline>
329
+ </div>
330
+ );
331
+ };
332
+
333
+ export const WithYearLabels = () => {
334
+ return (
335
+ <div style={{ width: "80vw" }}>
336
+ <Timeline>
337
+ <Timeline.Row
338
+ label="Row 1"
339
+ icon={<CheckmarkCircleFillIcon aria-hidden />}
340
+ >
341
+ <Timeline.Period
342
+ start={new Date("Feb 4 2022")}
343
+ end={new Date("Feb 13 2028")}
344
+ status="success"
345
+ />
346
+ </Timeline.Row>
347
+ <Timeline.Row
348
+ label="Row 2"
349
+ icon={<CheckmarkCircleFillIcon aria-hidden />}
350
+ >
351
+ <Timeline.Period
352
+ start={new Date("Feb 17 2024")}
353
+ end={new Date("Feb 22 2031")}
354
+ status="warning"
355
+ />
356
+ </Timeline.Row>
357
+ </Timeline>
358
+ </div>
359
+ );
360
+ };
361
+
362
+ export const ContentDemo = () => {
363
+ const [activePeriod, setActivePeriod] = useState<any>(undefined);
364
+
365
+ return (
366
+ <div style={{ width: "80vw" }}>
367
+ <Timeline>
368
+ <Timeline.Pin date={new Date("Apr 15 2022")}>Pin 1</Timeline.Pin>
369
+ <Timeline.Pin date={new Date("Jun 12 2022")}>
370
+ Pin 2 <button>test</button>
371
+ </Timeline.Pin>
372
+ <Timeline.Pin date={new Date("Jul 28 2022")}>Pin 3</Timeline.Pin>
373
+ <Timeline.Row
374
+ label="Rad 1"
375
+ icon={<CheckmarkCircleFillIcon aria-hidden />}
376
+ >
377
+ {row1.map((p: any, i) => {
378
+ return (
379
+ <Timeline.Period
380
+ key={p.id}
381
+ start={p.start}
382
+ end={p.end}
383
+ status={p.status}
384
+ onSelectPeriod={() => {
385
+ setActivePeriod(p);
386
+ p?.onSelectPeriod?.();
387
+ console.log("PERIOD SELECTED!");
388
+ }}
389
+ icon={p.icon}
390
+ isActive={activePeriod?.id === p.id}
391
+ statusLabel={p.statusLabel}
392
+ aria-controls={
393
+ activePeriod?.id === p.id ? "timeline-data" : undefined
394
+ }
395
+ id={p.id}
396
+ >
397
+ {p.children}
398
+ </Timeline.Period>
399
+ );
400
+ })}
401
+ </Timeline.Row>
402
+ <Timeline.Row label="Rad 2">
403
+ {row2.map((p: any, i) => {
404
+ return (
405
+ <Timeline.Period
406
+ key={p.id}
407
+ start={p.start}
408
+ end={p.end}
409
+ status={p.status}
410
+ onSelectPeriod={() => {
411
+ setActivePeriod(p);
412
+ p?.onSelectPeriod?.();
413
+ }}
414
+ icon={p.icon}
415
+ isActive={activePeriod?.id === p.id}
416
+ statusLabel={p.statusLabel}
417
+ aria-controls={
418
+ activePeriod?.id === p.id ? "timeline-data" : undefined
419
+ }
420
+ id={p.id}
421
+ >
422
+ {p.children}
423
+ </Timeline.Period>
424
+ );
425
+ })}
426
+ </Timeline.Row>
427
+ <Timeline.Row label="Rad 3">
428
+ <Timeline.Period
429
+ start={new Date("Jan 1 2022")}
430
+ end={new Date("Aug 20 2022")}
431
+ status="info"
432
+ icon={<CheckmarkCircleFillIcon aria-hidden />}
433
+ />
434
+ </Timeline.Row>
435
+ </Timeline>
436
+ {activePeriod && (
437
+ <div id="timeline-data" aria-controls={activePeriod.id}>
438
+ <h2>Period-data</h2>
439
+ <p>{`Periode:${activePeriod.id}, dato:${activePeriod.start}`}</p>
440
+ </div>
441
+ )}
442
+ </div>
443
+ );
444
+ };
@@ -0,0 +1,26 @@
1
+ import { differenceInMilliseconds } from "date-fns";
2
+
3
+ export const position = (date: Date, start: Date, endInclusive: Date) => {
4
+ const diff = differenceInMilliseconds(endInclusive, start);
5
+ return (differenceInMilliseconds(date, start) / diff) * 100;
6
+ };
7
+
8
+ export const horizontalPositionAndWidth = (
9
+ start: Date,
10
+ endInclusive: Date,
11
+ timelineStart: Date,
12
+ timelineEndInclusive: Date
13
+ ) => {
14
+ const horizontalPosition = position(
15
+ start,
16
+ timelineStart,
17
+ timelineEndInclusive
18
+ );
19
+ const width =
20
+ position(endInclusive, timelineStart, timelineEndInclusive) -
21
+ horizontalPosition;
22
+ return {
23
+ horizontalPosition: horizontalPosition,
24
+ width: width,
25
+ };
26
+ };
@@ -0,0 +1,32 @@
1
+ import { differenceInDays } from "date-fns";
2
+ import { PeriodProps } from "../period";
3
+ import { Spatial } from "./types.internal";
4
+
5
+ export interface Positioned {
6
+ horizontalPosition: number;
7
+ direction: "left" | "right";
8
+ }
9
+
10
+ export const isVisible = ({ horizontalPosition }: Positioned): boolean =>
11
+ horizontalPosition <= 98 && horizontalPosition >= 0;
12
+
13
+ export const getFirstDate = (periods: any) => {
14
+ return periods.sort(
15
+ (a: PeriodProps, b: PeriodProps) => a.start.getTime() - b.start.getTime()
16
+ )[0].start;
17
+ };
18
+
19
+ export const getLastDate = (periods: any) => {
20
+ return periods.sort(
21
+ (a: PeriodProps, b: PeriodProps) => a.end.getTime() - b.end.getTime()
22
+ )[periods.length - 1].end;
23
+ };
24
+
25
+ export const withinADay = (date1: Date, date2: Date): boolean =>
26
+ differenceInDays(date1, date2) <= 1;
27
+
28
+ export const invisiblePeriods = ({
29
+ horizontalPosition,
30
+ width,
31
+ }: Positioned & Spatial) =>
32
+ horizontalPosition >= 0 && horizontalPosition <= 100 && width > 0;
@@ -0,0 +1,6 @@
1
+ export {
2
+ getFirstDate,
3
+ getLastDate,
4
+ isVisible,
5
+ type Positioned,
6
+ } from "./filter";
@@ -0,0 +1,48 @@
1
+ import cl from "clsx";
2
+ import { format } from "date-fns";
3
+
4
+ export const getConditionalClasses = (
5
+ cropped: string,
6
+ direction: string,
7
+ status: string
8
+ ) => {
9
+ return cl(`navds-timeline__period navds-timeline__period--${status}`, {
10
+ "navds-timeline__period--connected-both": cropped === "both",
11
+ "navds-timeline__period--connected-right":
12
+ (cropped === "right" && direction === "left") ||
13
+ (cropped === "left" && direction === "right"),
14
+ "navds-timeline__period--connected-left":
15
+ (cropped === "left" && direction === "left") ||
16
+ (cropped === "right" && direction === "right"),
17
+ });
18
+ };
19
+
20
+ const translateStatus = (status: string): string => {
21
+ switch (status) {
22
+ case "success":
23
+ return "Suksess";
24
+ case "warning":
25
+ return "Advarsel";
26
+ case "danger":
27
+ return "Fare";
28
+ case "info":
29
+ return "Info";
30
+ case "neutral":
31
+ return "Nøytral";
32
+ default:
33
+ return status;
34
+ }
35
+ };
36
+
37
+ export const ariaLabel = (
38
+ startDate: Date,
39
+ endDate: Date,
40
+ status: string,
41
+ statusLabel?: string
42
+ ): string => {
43
+ const start = format(startDate, "dd.MM.yyyy");
44
+ const end = format(endDate, "dd.MM.yyyy");
45
+ return `${
46
+ statusLabel ? statusLabel : translateStatus(status)
47
+ } fra ${start} til ${end}`;
48
+ };
@@ -0,0 +1,11 @@
1
+ import { differenceInMilliseconds } from "date-fns";
2
+ import { Period, PositionedPeriod } from "./types.internal";
3
+
4
+ export const lastDate = (a: Date, b: Date): number =>
5
+ differenceInMilliseconds(a, b);
6
+
7
+ export const lastPeriod = (a: PositionedPeriod, b: PositionedPeriod): number =>
8
+ a.horizontalPosition - b.horizontalPosition;
9
+
10
+ export const lastSinglePeriod = (a: Period, b: Period): number =>
11
+ differenceInMilliseconds(b.endInclusive, a.endInclusive);
@@ -0,0 +1,83 @@
1
+ import { omit } from "../../util";
2
+ import React, { ReactNode } from "react";
3
+ import { Period } from "./types.external";
4
+
5
+ type ParsedChild = {
6
+ label?: string;
7
+ icon?: React.ReactNode;
8
+ headingTag: string;
9
+ periods: Omit<Period, "id" | "endInclusive">[];
10
+ restProps: any;
11
+ ref: any;
12
+ };
13
+
14
+ export const parseRows = (rowChildren: ReactNode[]) => {
15
+ let parsedChildren: ParsedChild[] = [];
16
+ rowChildren?.forEach((r: React.ReactNode) => {
17
+ let periods: ParsedChild["periods"] = [];
18
+ if (React.isValidElement(r) && r?.props?.children) {
19
+ if (Array.isArray(r.props.children)) {
20
+ for (let i = 0; i < r.props.children.length; i++) {
21
+ const p = r.props.children[i];
22
+
23
+ periods.push({
24
+ start: p?.props?.start,
25
+ end: p?.props?.end,
26
+ status: p?.props?.status || "neutral",
27
+ onSelectPeriod: p.props?.onSelectPeriod,
28
+ label: r.props.label,
29
+ icon: p.props.icon,
30
+ children: p.props.children,
31
+ isActive: p.props.isActive,
32
+ statusLabel: p.props.statusLabel,
33
+ restProps: omit(p.props, [
34
+ "start",
35
+ "end",
36
+ "status",
37
+ "onSelectPeriod",
38
+ "label",
39
+ "icon",
40
+ "children",
41
+ "isActive",
42
+ "statusLabel",
43
+ ]),
44
+ ref: p?.ref,
45
+ });
46
+ }
47
+ } else {
48
+ periods.push({
49
+ start: r.props.children.props.start,
50
+ end: r.props.children.props.end,
51
+ status: r.props.children.props?.status || "neutral",
52
+ onSelectPeriod: r.props.children.props?.onSelectPeriod,
53
+ label: r.props.label,
54
+ icon: r.props.children.props?.icon,
55
+ children: r.props.children.props?.children,
56
+ statusLabel: r.props.children.props?.statusLabel,
57
+ restProps: omit(r.props.children.props, [
58
+ "start",
59
+ "end",
60
+ "status",
61
+ "onSelectPeriod",
62
+ "label",
63
+ "icon",
64
+ "children",
65
+ "isActive",
66
+ "statusLabel",
67
+ ]),
68
+ ref: r.props?.children?.ref,
69
+ });
70
+ }
71
+ parsedChildren.push({
72
+ label: r.props.label,
73
+ icon: r.props.icon,
74
+ headingTag: r.props.headingTag,
75
+ periods: periods,
76
+ restProps: omit(r.props, ["label", "icon", "headingTag"]),
77
+ ref: (r as any)?.ref,
78
+ });
79
+ }
80
+ });
81
+
82
+ return parsedChildren;
83
+ };