@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.
- package/_docs.json +5615 -3780
- package/cjs/date/hooks/index.js +4 -4
- package/cjs/date/index.js +6 -6
- package/cjs/dropdown/Dropdown.js +57 -0
- package/cjs/dropdown/Menu/Divider.js +47 -0
- package/cjs/dropdown/Menu/GroupedList/Heading.js +47 -0
- package/cjs/dropdown/Menu/GroupedList/Item.js +54 -0
- package/cjs/dropdown/Menu/GroupedList/index.js +51 -0
- package/cjs/dropdown/Menu/GroupedList/package.json +6 -0
- package/cjs/dropdown/Menu/List/Item.js +54 -0
- package/cjs/dropdown/Menu/List/index.js +49 -0
- package/cjs/dropdown/Menu/List/package.json +6 -0
- package/cjs/dropdown/Menu/index.js +64 -0
- package/cjs/dropdown/Menu/package.json +6 -0
- package/cjs/dropdown/Toggle.js +66 -0
- package/cjs/dropdown/index.js +23 -0
- package/cjs/dropdown/package.json +6 -0
- package/cjs/form/radio/RadioGroup.js +10 -0
- package/cjs/index.js +3 -0
- package/cjs/internal-header/InternalHeader.js +55 -0
- package/cjs/internal-header/InternalHeaderButton.js +47 -0
- package/cjs/internal-header/InternalHeaderTitle.js +48 -0
- package/cjs/internal-header/InternalHeaderUser.js +51 -0
- package/cjs/internal-header/InternalHeaderUserButton.js +54 -0
- package/cjs/internal-header/index.js +8 -0
- package/cjs/internal-header/package.json +6 -0
- package/cjs/read-more/ReadMore.js +17 -0
- package/cjs/timeline/AxisLabels.js +90 -0
- package/cjs/timeline/Pin.js +106 -0
- package/cjs/timeline/Timeline.js +162 -0
- package/cjs/timeline/TimelineRow.js +86 -0
- package/cjs/timeline/hooks/usePeriodContext.js +16 -0
- package/cjs/timeline/hooks/useRowContext.js +18 -0
- package/cjs/timeline/hooks/useTimelineContext.js +23 -0
- package/cjs/timeline/hooks/useTimelineRows.js +79 -0
- package/cjs/timeline/index.js +8 -0
- package/cjs/timeline/package.json +6 -0
- package/cjs/timeline/period/ClickablePeriod.js +120 -0
- package/cjs/timeline/period/NonClickablePeriod.js +18 -0
- package/cjs/timeline/period/index.js +46 -0
- package/cjs/timeline/period/package.json +6 -0
- package/cjs/timeline/utils/calc.js +19 -0
- package/cjs/timeline/utils/filter.js +18 -0
- package/cjs/timeline/utils/index.js +7 -0
- package/cjs/timeline/utils/package.json +6 -0
- package/cjs/timeline/utils/period.js +40 -0
- package/cjs/timeline/utils/sort.js +10 -0
- package/cjs/timeline/utils/timeline.js +79 -0
- package/cjs/timeline/utils/types.external.js +2 -0
- package/cjs/timeline/utils/types.internal.js +2 -0
- package/cjs/timeline/zoom/ZoomButton.js +68 -0
- package/cjs/timeline/zoom/index.js +50 -0
- package/cjs/timeline/zoom/package.json +6 -0
- package/esm/date/hooks/index.d.ts +3 -3
- package/esm/date/hooks/index.js +3 -3
- package/esm/date/hooks/index.js.map +1 -1
- package/esm/date/index.d.ts +3 -3
- package/esm/date/index.js +3 -3
- package/esm/date/index.js.map +1 -1
- package/esm/dropdown/Dropdown.d.ts +37 -0
- package/esm/dropdown/Dropdown.js +29 -0
- package/esm/dropdown/Dropdown.js.map +1 -0
- package/esm/dropdown/Menu/Divider.d.ts +4 -0
- package/esm/dropdown/Menu/Divider.js +19 -0
- package/esm/dropdown/Menu/Divider.js.map +1 -0
- package/esm/dropdown/Menu/GroupedList/Heading.d.ts +10 -0
- package/esm/dropdown/Menu/GroupedList/Heading.js +19 -0
- package/esm/dropdown/Menu/GroupedList/Heading.js.map +1 -0
- package/esm/dropdown/Menu/GroupedList/Item.d.ts +11 -0
- package/esm/dropdown/Menu/GroupedList/Item.js +26 -0
- package/esm/dropdown/Menu/GroupedList/Item.js.map +1 -0
- package/esm/dropdown/Menu/GroupedList/index.d.ts +15 -0
- package/esm/dropdown/Menu/GroupedList/index.js +23 -0
- package/esm/dropdown/Menu/GroupedList/index.js.map +1 -0
- package/esm/dropdown/Menu/List/Item.d.ts +11 -0
- package/esm/dropdown/Menu/List/Item.js +26 -0
- package/esm/dropdown/Menu/List/Item.js.map +1 -0
- package/esm/dropdown/Menu/List/index.d.ts +13 -0
- package/esm/dropdown/Menu/List/index.js +21 -0
- package/esm/dropdown/Menu/List/index.js.map +1 -0
- package/esm/dropdown/Menu/index.d.ts +27 -0
- package/esm/dropdown/Menu/index.js +36 -0
- package/esm/dropdown/Menu/index.js.map +1 -0
- package/esm/dropdown/Toggle.d.ts +10 -0
- package/esm/dropdown/Toggle.js +38 -0
- package/esm/dropdown/Toggle.js.map +1 -0
- package/esm/dropdown/index.d.ts +2 -0
- package/esm/dropdown/index.js +3 -0
- package/esm/dropdown/index.js.map +1 -0
- package/esm/form/radio/RadioGroup.d.ts +10 -0
- package/esm/form/radio/RadioGroup.js +10 -0
- package/esm/form/radio/RadioGroup.js.map +1 -1
- package/esm/index.d.ts +3 -0
- package/esm/index.js +3 -0
- package/esm/index.js.map +1 -1
- package/esm/internal-header/InternalHeader.d.ts +16 -0
- package/esm/internal-header/InternalHeader.js +27 -0
- package/esm/internal-header/InternalHeader.js.map +1 -0
- package/esm/internal-header/InternalHeaderButton.d.ts +11 -0
- package/esm/internal-header/InternalHeaderButton.js +19 -0
- package/esm/internal-header/InternalHeaderButton.js.map +1 -0
- package/esm/internal-header/InternalHeaderTitle.d.ts +11 -0
- package/esm/internal-header/InternalHeaderTitle.js +20 -0
- package/esm/internal-header/InternalHeaderTitle.js.map +1 -0
- package/esm/internal-header/InternalHeaderUser.d.ts +14 -0
- package/esm/internal-header/InternalHeaderUser.js +23 -0
- package/esm/internal-header/InternalHeaderUser.js.map +1 -0
- package/esm/internal-header/InternalHeaderUserButton.d.ts +15 -0
- package/esm/internal-header/InternalHeaderUserButton.js +26 -0
- package/esm/internal-header/InternalHeaderUserButton.js.map +1 -0
- package/esm/internal-header/index.d.ts +5 -0
- package/esm/internal-header/index.js +2 -0
- package/esm/internal-header/index.js.map +1 -0
- package/esm/read-more/ReadMore.d.ts +17 -0
- package/esm/read-more/ReadMore.js +17 -0
- package/esm/read-more/ReadMore.js.map +1 -1
- package/esm/timeline/AxisLabels.d.ts +6 -0
- package/esm/timeline/AxisLabels.js +81 -0
- package/esm/timeline/AxisLabels.js.map +1 -0
- package/esm/timeline/Pin.d.ts +17 -0
- package/esm/timeline/Pin.js +81 -0
- package/esm/timeline/Pin.js.map +1 -0
- package/esm/timeline/Timeline.d.ts +45 -0
- package/esm/timeline/Timeline.js +134 -0
- package/esm/timeline/Timeline.js.map +1 -0
- package/esm/timeline/TimelineRow.d.ts +22 -0
- package/esm/timeline/TimelineRow.js +58 -0
- package/esm/timeline/TimelineRow.js.map +1 -0
- package/esm/timeline/hooks/usePeriodContext.d.ts +9 -0
- package/esm/timeline/hooks/usePeriodContext.js +13 -0
- package/esm/timeline/hooks/usePeriodContext.js.map +1 -0
- package/esm/timeline/hooks/useRowContext.d.ts +11 -0
- package/esm/timeline/hooks/useRowContext.js +15 -0
- package/esm/timeline/hooks/useRowContext.js.map +1 -0
- package/esm/timeline/hooks/useTimelineContext.d.ts +15 -0
- package/esm/timeline/hooks/useTimelineContext.js +20 -0
- package/esm/timeline/hooks/useTimelineContext.js.map +1 -0
- package/esm/timeline/hooks/useTimelineRows.d.ts +4 -0
- package/esm/timeline/hooks/useTimelineRows.js +74 -0
- package/esm/timeline/hooks/useTimelineRows.js.map +1 -0
- package/esm/timeline/index.d.ts +6 -0
- package/esm/timeline/index.js +2 -0
- package/esm/timeline/index.js.map +1 -0
- package/esm/timeline/period/ClickablePeriod.d.ts +9 -0
- package/esm/timeline/period/ClickablePeriod.js +93 -0
- package/esm/timeline/period/ClickablePeriod.js.map +1 -0
- package/esm/timeline/period/NonClickablePeriod.d.ts +7 -0
- package/esm/timeline/period/NonClickablePeriod.js +14 -0
- package/esm/timeline/period/NonClickablePeriod.js.map +1 -0
- package/esm/timeline/period/index.d.ts +57 -0
- package/esm/timeline/period/index.js +18 -0
- package/esm/timeline/period/index.js.map +1 -0
- package/esm/timeline/utils/calc.d.ts +5 -0
- package/esm/timeline/utils/calc.js +15 -0
- package/esm/timeline/utils/calc.js.map +1 -0
- package/esm/timeline/utils/filter.d.ts +10 -0
- package/esm/timeline/utils/filter.js +11 -0
- package/esm/timeline/utils/filter.js.map +1 -0
- package/esm/timeline/utils/index.d.ts +1 -0
- package/esm/timeline/utils/index.js +2 -0
- package/esm/timeline/utils/index.js.map +1 -0
- package/esm/timeline/utils/period.d.ts +2 -0
- package/esm/timeline/utils/period.js +33 -0
- package/esm/timeline/utils/period.js.map +1 -0
- package/esm/timeline/utils/sort.d.ts +4 -0
- package/esm/timeline/utils/sort.js +5 -0
- package/esm/timeline/utils/sort.js.map +1 -0
- package/esm/timeline/utils/timeline.d.ts +12 -0
- package/esm/timeline/utils/timeline.js +73 -0
- package/esm/timeline/utils/timeline.js.map +1 -0
- package/esm/timeline/utils/types.external.d.ts +53 -0
- package/esm/timeline/utils/types.external.js +2 -0
- package/esm/timeline/utils/types.external.js.map +1 -0
- package/esm/timeline/utils/types.internal.d.ts +61 -0
- package/esm/timeline/utils/types.internal.js +2 -0
- package/esm/timeline/utils/types.internal.js.map +1 -0
- package/esm/timeline/zoom/ZoomButton.d.ts +19 -0
- package/esm/timeline/zoom/ZoomButton.js +43 -0
- package/esm/timeline/zoom/ZoomButton.js.map +1 -0
- package/esm/timeline/zoom/index.d.ts +11 -0
- package/esm/timeline/zoom/index.js +22 -0
- package/esm/timeline/zoom/index.js.map +1 -0
- package/package.json +2 -2
- package/src/date/datepicker/datepicker.stories.tsx +19 -21
- package/src/date/datepicker/datepicker.test.tsx +5 -5
- package/src/date/hooks/index.ts +3 -3
- package/src/date/hooks/useRangeDatepicker.test.tsx +6 -6
- package/src/date/index.ts +5 -5
- package/src/date/monthpicker/monthpicker.stories.tsx +5 -5
- package/src/date/utils/__tests__/get-dates.test.ts +0 -1
- package/src/dropdown/Dropdown.tsx +80 -0
- package/src/dropdown/Menu/Divider.tsx +18 -0
- package/src/dropdown/Menu/GroupedList/Heading.tsx +31 -0
- package/src/dropdown/Menu/GroupedList/Item.tsx +45 -0
- package/src/dropdown/Menu/GroupedList/index.tsx +33 -0
- package/src/dropdown/Menu/List/Item.tsx +44 -0
- package/src/dropdown/Menu/List/index.tsx +27 -0
- package/src/dropdown/Menu/index.tsx +85 -0
- package/src/dropdown/Toggle.tsx +52 -0
- package/src/dropdown/dropdown.stories.tsx +91 -0
- package/src/dropdown/index.ts +2 -0
- package/src/form/radio/RadioGroup.tsx +10 -0
- package/src/index.ts +3 -0
- package/src/internal-header/InternalHeader.tsx +44 -0
- package/src/internal-header/InternalHeaderButton.tsx +28 -0
- package/src/internal-header/InternalHeaderTitle.tsx +35 -0
- package/src/internal-header/InternalHeaderUser.tsx +39 -0
- package/src/internal-header/InternalHeaderUserButton.tsx +43 -0
- package/src/internal-header/header.stories.tsx +225 -0
- package/src/internal-header/index.ts +8 -0
- package/src/read-more/ReadMore.tsx +17 -0
- package/src/timeline/AxisLabels.tsx +143 -0
- package/src/timeline/Pin.tsx +169 -0
- package/src/timeline/Timeline.tsx +219 -0
- package/src/timeline/TimelineRow.tsx +122 -0
- package/src/timeline/hooks/usePeriodContext.tsx +22 -0
- package/src/timeline/hooks/useRowContext.tsx +26 -0
- package/src/timeline/hooks/useTimelineContext.tsx +37 -0
- package/src/timeline/hooks/useTimelineRows.ts +161 -0
- package/src/timeline/index.ts +6 -0
- package/src/timeline/period/ClickablePeriod.tsx +193 -0
- package/src/timeline/period/NonClickablePeriod.tsx +46 -0
- package/src/timeline/period/index.tsx +130 -0
- package/src/timeline/timeline.stories.tsx +444 -0
- package/src/timeline/utils/calc.ts +26 -0
- package/src/timeline/utils/filter.ts +32 -0
- package/src/timeline/utils/index.ts +6 -0
- package/src/timeline/utils/period.ts +48 -0
- package/src/timeline/utils/sort.ts +11 -0
- package/src/timeline/utils/timeline.ts +83 -0
- package/src/timeline/utils/types.external.ts +67 -0
- package/src/timeline/utils/types.internal.ts +76 -0
- package/src/timeline/zoom/ZoomButton.tsx +83 -0
- package/src/timeline/zoom/index.tsx +30 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
26
|
+
var t = {};
|
|
27
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
28
|
+
t[p] = s[p];
|
|
29
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
30
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
31
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
32
|
+
t[p[i]] = s[p[i]];
|
|
33
|
+
}
|
|
34
|
+
return t;
|
|
35
|
+
};
|
|
36
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.TimelineRow = void 0;
|
|
41
|
+
const BodyShort_1 = require("../typography/BodyShort");
|
|
42
|
+
const date_fns_1 = require("date-fns");
|
|
43
|
+
const react_1 = __importStar(require("react"));
|
|
44
|
+
const usePeriodContext_1 = require("./hooks/usePeriodContext");
|
|
45
|
+
const useRowContext_1 = require("./hooks/useRowContext");
|
|
46
|
+
const useTimelineContext_1 = require("./hooks/useTimelineContext");
|
|
47
|
+
const period_1 = __importDefault(require("./period"));
|
|
48
|
+
const clsx_1 = __importDefault(require("clsx"));
|
|
49
|
+
exports.TimelineRow = (0, react_1.forwardRef)((_a, ref) => {
|
|
50
|
+
var { label, className, headingTag = "h3", icon } = _a, rest = __rest(_a, ["label", "className", "headingTag", "icon"]);
|
|
51
|
+
const { periods, id, active } = (0, useRowContext_1.useRowContext)();
|
|
52
|
+
const { setActiveRow } = (0, useTimelineContext_1.useTimelineContext)();
|
|
53
|
+
const latest = periods.reduce((a, b) => {
|
|
54
|
+
return a.end > b.end ? a : b;
|
|
55
|
+
}, {});
|
|
56
|
+
const earliest = periods.reduce((a, b) => {
|
|
57
|
+
return a.end < b.end ? a : b;
|
|
58
|
+
}, {});
|
|
59
|
+
const firstFocusable = periods.find((p) => !!p.children || !!p.onSelectPeriod);
|
|
60
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
61
|
+
label && (react_1.default.createElement(BodyShort_1.BodyShort, { as: headingTag, id: `timeline-row-${id}`, className: "navds-timeline__row-label", size: "small" },
|
|
62
|
+
icon,
|
|
63
|
+
label)),
|
|
64
|
+
react_1.default.createElement("div", { className: (0, clsx_1.default)("navds-timeline__row", {
|
|
65
|
+
"navds-timeline__row--active": active,
|
|
66
|
+
}) },
|
|
67
|
+
react_1.default.createElement("ol", Object.assign({}, rest, { ref: ref, "aria-label": periods.length === 0
|
|
68
|
+
? "Ingen perioder"
|
|
69
|
+
: `${(0, date_fns_1.format)(earliest.start, "dd.MM.yyyy")} til ${(0, date_fns_1.format)(latest.end, "dd.MM.yyyy")}`, className: (0, clsx_1.default)("navds-timeline__row-periods", className), onKeyDown: (e) => {
|
|
70
|
+
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
71
|
+
e.preventDefault();
|
|
72
|
+
setActiveRow(e.key);
|
|
73
|
+
}
|
|
74
|
+
} }), periods &&
|
|
75
|
+
periods.map((period) => {
|
|
76
|
+
return (react_1.default.createElement("li", { key: `period-${period.id}` },
|
|
77
|
+
react_1.default.createElement(usePeriodContext_1.PeriodContext.Provider, { value: {
|
|
78
|
+
periodId: period.id,
|
|
79
|
+
firstFocus: (firstFocusable === null || firstFocusable === void 0 ? void 0 : firstFocusable.id) === period.id,
|
|
80
|
+
restProps: period === null || period === void 0 ? void 0 : period.restProps,
|
|
81
|
+
} },
|
|
82
|
+
react_1.default.createElement(period_1.default, { start: period.start, end: period.endInclusive, icon: period.icon, ref: period === null || period === void 0 ? void 0 : period.ref }))));
|
|
83
|
+
})))));
|
|
84
|
+
});
|
|
85
|
+
exports.TimelineRow.componentType = "row";
|
|
86
|
+
exports.default = exports.TimelineRow;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.usePeriodContext = exports.PeriodContext = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
exports.PeriodContext = (0, react_1.createContext)({
|
|
6
|
+
periodId: "",
|
|
7
|
+
firstFocus: false,
|
|
8
|
+
});
|
|
9
|
+
const usePeriodContext = () => {
|
|
10
|
+
const context = (0, react_1.useContext)(exports.PeriodContext);
|
|
11
|
+
if (!context) {
|
|
12
|
+
console.warn("usePeriodContext must be used with PeriodContext");
|
|
13
|
+
}
|
|
14
|
+
return context;
|
|
15
|
+
};
|
|
16
|
+
exports.usePeriodContext = usePeriodContext;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useRowContext = exports.RowContext = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
exports.RowContext = (0, react_1.createContext)({
|
|
6
|
+
periods: [],
|
|
7
|
+
id: "",
|
|
8
|
+
active: false,
|
|
9
|
+
index: 0,
|
|
10
|
+
});
|
|
11
|
+
const useRowContext = () => {
|
|
12
|
+
const context = (0, react_1.useContext)(exports.RowContext);
|
|
13
|
+
if (!context) {
|
|
14
|
+
console.warn("useRowContext must be used with RowContext");
|
|
15
|
+
}
|
|
16
|
+
return context;
|
|
17
|
+
};
|
|
18
|
+
exports.useRowContext = useRowContext;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useTimelineContext = exports.TimelineContext = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
exports.TimelineContext = (0, react_1.createContext)({
|
|
6
|
+
startDate: new Date(),
|
|
7
|
+
endDate: new Date(),
|
|
8
|
+
direction: "left",
|
|
9
|
+
setStart: () => null,
|
|
10
|
+
setEndInclusive: () => null,
|
|
11
|
+
activeRow: 0,
|
|
12
|
+
setActiveRow: () => null,
|
|
13
|
+
initiate: () => null,
|
|
14
|
+
addFocusable: () => null,
|
|
15
|
+
});
|
|
16
|
+
const useTimelineContext = () => {
|
|
17
|
+
const context = (0, react_1.useContext)(exports.TimelineContext);
|
|
18
|
+
if (!context) {
|
|
19
|
+
console.warn("useTimelineContext must be used with TimelineContext (<Timeline />)");
|
|
20
|
+
}
|
|
21
|
+
return context;
|
|
22
|
+
};
|
|
23
|
+
exports.useTimelineContext = useTimelineContext;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useLatestDate = exports.useEarliestDate = exports.useTimelineRows = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const date_fns_1 = require("date-fns");
|
|
6
|
+
const sort_1 = require("../utils/sort");
|
|
7
|
+
const calc_1 = require("../utils/calc");
|
|
8
|
+
const filter_1 = require("../utils/filter");
|
|
9
|
+
const spatialPeriod = (period, timelineStart, timelineEndInclusive, direction = "left", i, periods, rowIndex) => {
|
|
10
|
+
const start = period.start;
|
|
11
|
+
const endInclusive = period.end;
|
|
12
|
+
const rightOverlap = i < periods.length - 1 && !(0, date_fns_1.isAfter)(periods[i + 1].start, endInclusive);
|
|
13
|
+
const { horizontalPosition, width } = (0, calc_1.horizontalPositionAndWidth)((0, date_fns_1.startOfDay)(start), (0, date_fns_1.endOfDay)(rightOverlap ? (0, date_fns_1.startOfDay)((0, date_fns_1.subDays)(periods[i + 1].start, 1)) : endInclusive), timelineStart, timelineEndInclusive);
|
|
14
|
+
return {
|
|
15
|
+
id: `r-${rowIndex}-p-${i}`,
|
|
16
|
+
start: start,
|
|
17
|
+
endInclusive: endInclusive,
|
|
18
|
+
horizontalPosition: horizontalPosition,
|
|
19
|
+
direction: direction,
|
|
20
|
+
width: width,
|
|
21
|
+
end: endInclusive,
|
|
22
|
+
status: period.status,
|
|
23
|
+
onSelectPeriod: period.onSelectPeriod,
|
|
24
|
+
icon: period.icon,
|
|
25
|
+
children: period.children,
|
|
26
|
+
isActive: period.isActive,
|
|
27
|
+
statusLabel: period.statusLabel,
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
const adjustedEdges = (period, i, allPeriods) => {
|
|
31
|
+
const left = i > 0 && (0, filter_1.withinADay)(period.start, allPeriods[i - 1].endInclusive);
|
|
32
|
+
const right = i < allPeriods.length - 1 &&
|
|
33
|
+
(0, filter_1.withinADay)(allPeriods[i + 1].start, period.endInclusive);
|
|
34
|
+
return left && right
|
|
35
|
+
? Object.assign(Object.assign({}, period), { cropped: "both" }) : left
|
|
36
|
+
? Object.assign(Object.assign({}, period), { cropped: "left" }) : right
|
|
37
|
+
? Object.assign(Object.assign({}, period), { cropped: "right" }) : period;
|
|
38
|
+
};
|
|
39
|
+
const trimmedPeriods = (period) => {
|
|
40
|
+
let { horizontalPosition, width, cropped } = period;
|
|
41
|
+
if (horizontalPosition + width > 100) {
|
|
42
|
+
width = 100 - horizontalPosition;
|
|
43
|
+
cropped = cropped === "left" || cropped === "both" ? "both" : "right";
|
|
44
|
+
}
|
|
45
|
+
if (horizontalPosition < 0 && horizontalPosition + width > 0) {
|
|
46
|
+
width = horizontalPosition + width;
|
|
47
|
+
horizontalPosition = 0;
|
|
48
|
+
cropped = cropped === "right" || cropped === "both" ? "both" : "left";
|
|
49
|
+
}
|
|
50
|
+
return Object.assign(Object.assign({}, period), { width: width, horizontalPosition: horizontalPosition, cropped: cropped });
|
|
51
|
+
};
|
|
52
|
+
const useTimelineRows = (rows, startDate, endDate, direction) => (0, react_1.useMemo)(() => rows.map((periods, i) => {
|
|
53
|
+
const rowIndex = i;
|
|
54
|
+
const timelinePeriods = periods.periods
|
|
55
|
+
.sort((a, b) => a.start.valueOf() - b.start.valueOf())
|
|
56
|
+
.map((period, i) => (Object.assign(Object.assign({}, spatialPeriod(period, startDate, endDate, direction, i, periods.periods, rowIndex)), { restProps: period === null || period === void 0 ? void 0 : period.restProps, ref: period === null || period === void 0 ? void 0 : period.ref })))
|
|
57
|
+
.sort(sort_1.lastPeriod)
|
|
58
|
+
.map(adjustedEdges)
|
|
59
|
+
.map(trimmedPeriods)
|
|
60
|
+
.filter(filter_1.invisiblePeriods);
|
|
61
|
+
return {
|
|
62
|
+
id: `tl-row-${rowIndex}`,
|
|
63
|
+
label: periods.label,
|
|
64
|
+
headingTag: periods.headingTag || "h3",
|
|
65
|
+
icon: periods.icon,
|
|
66
|
+
periods: direction === "left" ? timelinePeriods : timelinePeriods.reverse(),
|
|
67
|
+
restProps: periods === null || periods === void 0 ? void 0 : periods.restProps,
|
|
68
|
+
ref: periods === null || periods === void 0 ? void 0 : periods.ref,
|
|
69
|
+
};
|
|
70
|
+
}), [rows, startDate, endDate, direction]);
|
|
71
|
+
exports.useTimelineRows = useTimelineRows;
|
|
72
|
+
const earliestDate = (earliest, period) => period.start < earliest ? period.start : earliest;
|
|
73
|
+
const earliestFomDate = (rader) => rader.flat().reduce(earliestDate, new Date());
|
|
74
|
+
const useEarliestDate = ({ startDate, rows }) => (0, react_1.useMemo)(() => (startDate ? startDate : earliestFomDate(rows)), [startDate, rows]);
|
|
75
|
+
exports.useEarliestDate = useEarliestDate;
|
|
76
|
+
const latestDate = (latest, period) => period.end > latest ? period.end : latest;
|
|
77
|
+
const latestTomDate = (rows) => rows.flat().reduce(latestDate, new Date(0));
|
|
78
|
+
const useLatestDate = ({ endDate, rows }) => (0, react_1.useMemo)(() => (endDate ? endDate : (0, date_fns_1.addDays)(latestTomDate(rows), 1)), [endDate, rows]);
|
|
79
|
+
exports.useLatestDate = useLatestDate;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Timeline = void 0;
|
|
7
|
+
var Timeline_1 = require("./Timeline");
|
|
8
|
+
Object.defineProperty(exports, "Timeline", { enumerable: true, get: function () { return __importDefault(Timeline_1).default; } });
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const react_1 = require("@floating-ui/react");
|
|
30
|
+
const util_1 = require("../../util");
|
|
31
|
+
const clsx_1 = __importDefault(require("clsx"));
|
|
32
|
+
const react_2 = __importStar(require("react"));
|
|
33
|
+
const usePeriodContext_1 = require("../hooks/usePeriodContext");
|
|
34
|
+
const useRowContext_1 = require("../hooks/useRowContext");
|
|
35
|
+
const useTimelineContext_1 = require("../hooks/useTimelineContext");
|
|
36
|
+
const period_1 = require("../utils/period");
|
|
37
|
+
const ClickablePeriod = react_2.default.memo(({ onSelectPeriod, start, end, status, cropped, direction, left, width, icon, children, isActive, statusLabel, restProps, periodRef, }) => {
|
|
38
|
+
const [open, setOpen] = (0, react_2.useState)(false);
|
|
39
|
+
const { index } = (0, useRowContext_1.useRowContext)();
|
|
40
|
+
const { firstFocus } = (0, usePeriodContext_1.usePeriodContext)();
|
|
41
|
+
const { initiate, addFocusable } = (0, useTimelineContext_1.useTimelineContext)();
|
|
42
|
+
const arrowRef = (0, react_2.useRef)(null);
|
|
43
|
+
const { context, placement, middlewareData: { arrow: { x: arrowX, y: arrowY } = {} }, refs, floatingStyles, } = (0, react_1.useFloating)({
|
|
44
|
+
placement: "top",
|
|
45
|
+
open: open,
|
|
46
|
+
onOpenChange: setOpen,
|
|
47
|
+
middleware: [
|
|
48
|
+
(0, react_1.offset)(16),
|
|
49
|
+
(0, react_1.shift)(),
|
|
50
|
+
(0, react_1.flip)({ padding: 5, fallbackPlacements: ["bottom", "top"] }),
|
|
51
|
+
(0, react_1.arrow)({ element: arrowRef, padding: 5 }),
|
|
52
|
+
],
|
|
53
|
+
whileElementsMounted: react_1.autoUpdate,
|
|
54
|
+
});
|
|
55
|
+
const { getFloatingProps, getReferenceProps } = (0, react_1.useInteractions)([
|
|
56
|
+
(0, react_1.useHover)(context, {
|
|
57
|
+
handleClose: (0, react_1.safePolygon)(),
|
|
58
|
+
restMs: 25,
|
|
59
|
+
delay: { open: 1000 },
|
|
60
|
+
}),
|
|
61
|
+
(0, react_1.useFocus)(context),
|
|
62
|
+
(0, react_1.useDismiss)(context),
|
|
63
|
+
]);
|
|
64
|
+
const mergedRef = (0, react_2.useMemo)(() => (0, util_1.mergeRefs)([refs.setReference, periodRef]), [periodRef, refs.setReference]);
|
|
65
|
+
(0, util_1.useEventListener)("focusin", (0, react_2.useCallback)((e) => {
|
|
66
|
+
var _a;
|
|
67
|
+
if (![refs.domReference.current, (_a = refs === null || refs === void 0 ? void 0 : refs.floating) === null || _a === void 0 ? void 0 : _a.current].some((element) => element === null || element === void 0 ? void 0 : element.contains(e.target))) {
|
|
68
|
+
open && setOpen(false);
|
|
69
|
+
}
|
|
70
|
+
}, [open, refs.domReference, refs === null || refs === void 0 ? void 0 : refs.floating]));
|
|
71
|
+
const staticSide = {
|
|
72
|
+
top: "bottom",
|
|
73
|
+
right: "left",
|
|
74
|
+
bottom: "top",
|
|
75
|
+
left: "right",
|
|
76
|
+
}[placement.split("-")[0]];
|
|
77
|
+
return (react_2.default.createElement(react_2.default.Fragment, null,
|
|
78
|
+
react_2.default.createElement("button", Object.assign({}, restProps, { type: "button", ref: (r) => {
|
|
79
|
+
firstFocus && addFocusable(r, index);
|
|
80
|
+
mergedRef(r);
|
|
81
|
+
}, "aria-label": (0, period_1.ariaLabel)(start, end, status, statusLabel), className: (0, clsx_1.default)("navds-timeline__period--clickable", (0, period_1.getConditionalClasses)(cropped, direction, status), restProps === null || restProps === void 0 ? void 0 : restProps.className, {
|
|
82
|
+
"navds-timeline__period--selected": isActive,
|
|
83
|
+
}), "aria-expanded": children ? open : undefined, "aria-current": isActive || undefined }, getReferenceProps({
|
|
84
|
+
onFocus: () => {
|
|
85
|
+
initiate(index);
|
|
86
|
+
},
|
|
87
|
+
onKeyDown: (e) => {
|
|
88
|
+
var _a;
|
|
89
|
+
(_a = restProps === null || restProps === void 0 ? void 0 : restProps.onKeydown) === null || _a === void 0 ? void 0 : _a.call(restProps, e);
|
|
90
|
+
if (e.key === "Enter") {
|
|
91
|
+
setOpen((prev) => !prev);
|
|
92
|
+
}
|
|
93
|
+
if (e.key === " ") {
|
|
94
|
+
onSelectPeriod === null || onSelectPeriod === void 0 ? void 0 : onSelectPeriod(e);
|
|
95
|
+
setOpen(false);
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
style: {
|
|
99
|
+
width: `${width}%`,
|
|
100
|
+
[direction]: `${left}%`,
|
|
101
|
+
},
|
|
102
|
+
onClick: (e) => {
|
|
103
|
+
var _a;
|
|
104
|
+
(_a = restProps === null || restProps === void 0 ? void 0 : restProps.onClick) === null || _a === void 0 ? void 0 : _a.call(restProps, e);
|
|
105
|
+
if (e.detail === 0) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
onSelectPeriod === null || onSelectPeriod === void 0 ? void 0 : onSelectPeriod(e);
|
|
109
|
+
},
|
|
110
|
+
})),
|
|
111
|
+
react_2.default.createElement("span", { className: "navds-timeline__period--inner" }, icon)),
|
|
112
|
+
children && (react_2.default.createElement("div", Object.assign({ className: "navds-timeline__popover", "data-placement": placement, "aria-hidden": !open, ref: refs.setFloating }, getFloatingProps({
|
|
113
|
+
tabIndex: -1,
|
|
114
|
+
}), { style: Object.assign(Object.assign({}, floatingStyles), { display: open ? undefined : "none" }) }),
|
|
115
|
+
react_2.default.createElement("div", { className: "navds-timeline__popover-content" }, children),
|
|
116
|
+
react_2.default.createElement("div", { ref: (node) => {
|
|
117
|
+
arrowRef.current = node;
|
|
118
|
+
}, style: Object.assign(Object.assign(Object.assign({}, (arrowX != null ? { left: arrowX } : {})), (arrowY != null ? { top: arrowY } : {})), (staticSide ? { [staticSide]: "-0.5rem" } : {})), className: "navds-timeline__popover-arrow" })))));
|
|
119
|
+
});
|
|
120
|
+
exports.default = ClickablePeriod;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const react_1 = __importDefault(require("react"));
|
|
7
|
+
const period_1 = require("../utils/period");
|
|
8
|
+
const clsx_1 = __importDefault(require("clsx"));
|
|
9
|
+
const NonClickablePeriod = ({ start, end, status, cropped, direction, left, width, icon, statusLabel, restProps, periodRef, }) => {
|
|
10
|
+
return (react_1.default.createElement("div", Object.assign({ ref: periodRef }, restProps, { className: (0, clsx_1.default)((0, period_1.getConditionalClasses)(cropped, direction, status), restProps === null || restProps === void 0 ? void 0 : restProps.classname), style: {
|
|
11
|
+
width: `${width}%`,
|
|
12
|
+
[direction]: `${left}%`,
|
|
13
|
+
} }),
|
|
14
|
+
react_1.default.createElement("span", { className: "navds-timeline__period--inner" },
|
|
15
|
+
icon,
|
|
16
|
+
react_1.default.createElement("span", { className: "sr-only" }, (0, period_1.ariaLabel)(start, end, status, statusLabel)))));
|
|
17
|
+
};
|
|
18
|
+
exports.default = NonClickablePeriod;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.Period = void 0;
|
|
30
|
+
const react_1 = __importStar(require("react"));
|
|
31
|
+
const usePeriodContext_1 = require("../hooks/usePeriodContext");
|
|
32
|
+
const useRowContext_1 = require("../hooks/useRowContext");
|
|
33
|
+
const ClickablePeriod_1 = __importDefault(require("./ClickablePeriod"));
|
|
34
|
+
const NonClickablePeriod_1 = __importDefault(require("./NonClickablePeriod"));
|
|
35
|
+
exports.Period = (0, react_1.forwardRef)(({ icon }, ref) => {
|
|
36
|
+
const { periods } = (0, useRowContext_1.useRowContext)();
|
|
37
|
+
const { periodId, restProps } = (0, usePeriodContext_1.usePeriodContext)();
|
|
38
|
+
const period = periods.find((p) => p.id === periodId);
|
|
39
|
+
if (!period) {
|
|
40
|
+
return react_1.default.createElement(react_1.default.Fragment, null);
|
|
41
|
+
}
|
|
42
|
+
const { start, endInclusive, width, horizontalPosition, status = "neutral", onSelectPeriod, cropped, direction, children, isActive, statusLabel, } = period;
|
|
43
|
+
return onSelectPeriod || children ? (react_1.default.createElement(ClickablePeriod_1.default, { periodRef: ref, start: start, end: endInclusive, status: status, onSelectPeriod: onSelectPeriod, cropped: cropped || "", direction: direction, width: width, left: horizontalPosition, icon: icon, children: children, isActive: isActive, statusLabel: statusLabel, restProps: restProps })) : (react_1.default.createElement(NonClickablePeriod_1.default, { periodRef: ref, start: start, end: endInclusive, status: status, cropped: cropped || "", direction: direction, width: width, left: horizontalPosition, icon: icon, statusLabel: statusLabel, restProps: restProps }));
|
|
44
|
+
});
|
|
45
|
+
exports.Period.componentType = "period";
|
|
46
|
+
exports.default = exports.Period;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.horizontalPositionAndWidth = exports.position = void 0;
|
|
4
|
+
const date_fns_1 = require("date-fns");
|
|
5
|
+
const position = (date, start, endInclusive) => {
|
|
6
|
+
const diff = (0, date_fns_1.differenceInMilliseconds)(endInclusive, start);
|
|
7
|
+
return ((0, date_fns_1.differenceInMilliseconds)(date, start) / diff) * 100;
|
|
8
|
+
};
|
|
9
|
+
exports.position = position;
|
|
10
|
+
const horizontalPositionAndWidth = (start, endInclusive, timelineStart, timelineEndInclusive) => {
|
|
11
|
+
const horizontalPosition = (0, exports.position)(start, timelineStart, timelineEndInclusive);
|
|
12
|
+
const width = (0, exports.position)(endInclusive, timelineStart, timelineEndInclusive) -
|
|
13
|
+
horizontalPosition;
|
|
14
|
+
return {
|
|
15
|
+
horizontalPosition: horizontalPosition,
|
|
16
|
+
width: width,
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
exports.horizontalPositionAndWidth = horizontalPositionAndWidth;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.invisiblePeriods = exports.withinADay = exports.getLastDate = exports.getFirstDate = exports.isVisible = void 0;
|
|
4
|
+
const date_fns_1 = require("date-fns");
|
|
5
|
+
const isVisible = ({ horizontalPosition }) => horizontalPosition <= 98 && horizontalPosition >= 0;
|
|
6
|
+
exports.isVisible = isVisible;
|
|
7
|
+
const getFirstDate = (periods) => {
|
|
8
|
+
return periods.sort((a, b) => a.start.getTime() - b.start.getTime())[0].start;
|
|
9
|
+
};
|
|
10
|
+
exports.getFirstDate = getFirstDate;
|
|
11
|
+
const getLastDate = (periods) => {
|
|
12
|
+
return periods.sort((a, b) => a.end.getTime() - b.end.getTime())[periods.length - 1].end;
|
|
13
|
+
};
|
|
14
|
+
exports.getLastDate = getLastDate;
|
|
15
|
+
const withinADay = (date1, date2) => (0, date_fns_1.differenceInDays)(date1, date2) <= 1;
|
|
16
|
+
exports.withinADay = withinADay;
|
|
17
|
+
const invisiblePeriods = ({ horizontalPosition, width, }) => horizontalPosition >= 0 && horizontalPosition <= 100 && width > 0;
|
|
18
|
+
exports.invisiblePeriods = invisiblePeriods;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isVisible = exports.getLastDate = exports.getFirstDate = void 0;
|
|
4
|
+
var filter_1 = require("./filter");
|
|
5
|
+
Object.defineProperty(exports, "getFirstDate", { enumerable: true, get: function () { return filter_1.getFirstDate; } });
|
|
6
|
+
Object.defineProperty(exports, "getLastDate", { enumerable: true, get: function () { return filter_1.getLastDate; } });
|
|
7
|
+
Object.defineProperty(exports, "isVisible", { enumerable: true, get: function () { return filter_1.isVisible; } });
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ariaLabel = exports.getConditionalClasses = void 0;
|
|
7
|
+
const clsx_1 = __importDefault(require("clsx"));
|
|
8
|
+
const date_fns_1 = require("date-fns");
|
|
9
|
+
const getConditionalClasses = (cropped, direction, status) => {
|
|
10
|
+
return (0, clsx_1.default)(`navds-timeline__period navds-timeline__period--${status}`, {
|
|
11
|
+
"navds-timeline__period--connected-both": cropped === "both",
|
|
12
|
+
"navds-timeline__period--connected-right": (cropped === "right" && direction === "left") ||
|
|
13
|
+
(cropped === "left" && direction === "right"),
|
|
14
|
+
"navds-timeline__period--connected-left": (cropped === "left" && direction === "left") ||
|
|
15
|
+
(cropped === "right" && direction === "right"),
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
exports.getConditionalClasses = getConditionalClasses;
|
|
19
|
+
const translateStatus = (status) => {
|
|
20
|
+
switch (status) {
|
|
21
|
+
case "success":
|
|
22
|
+
return "Suksess";
|
|
23
|
+
case "warning":
|
|
24
|
+
return "Advarsel";
|
|
25
|
+
case "danger":
|
|
26
|
+
return "Fare";
|
|
27
|
+
case "info":
|
|
28
|
+
return "Info";
|
|
29
|
+
case "neutral":
|
|
30
|
+
return "Nøytral";
|
|
31
|
+
default:
|
|
32
|
+
return status;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const ariaLabel = (startDate, endDate, status, statusLabel) => {
|
|
36
|
+
const start = (0, date_fns_1.format)(startDate, "dd.MM.yyyy");
|
|
37
|
+
const end = (0, date_fns_1.format)(endDate, "dd.MM.yyyy");
|
|
38
|
+
return `${statusLabel ? statusLabel : translateStatus(status)} fra ${start} til ${end}`;
|
|
39
|
+
};
|
|
40
|
+
exports.ariaLabel = ariaLabel;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.lastSinglePeriod = exports.lastPeriod = exports.lastDate = void 0;
|
|
4
|
+
const date_fns_1 = require("date-fns");
|
|
5
|
+
const lastDate = (a, b) => (0, date_fns_1.differenceInMilliseconds)(a, b);
|
|
6
|
+
exports.lastDate = lastDate;
|
|
7
|
+
const lastPeriod = (a, b) => a.horizontalPosition - b.horizontalPosition;
|
|
8
|
+
exports.lastPeriod = lastPeriod;
|
|
9
|
+
const lastSinglePeriod = (a, b) => (0, date_fns_1.differenceInMilliseconds)(b.endInclusive, a.endInclusive);
|
|
10
|
+
exports.lastSinglePeriod = lastSinglePeriod;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.parseRows = void 0;
|
|
7
|
+
const util_1 = require("../../util");
|
|
8
|
+
const react_1 = __importDefault(require("react"));
|
|
9
|
+
const parseRows = (rowChildren) => {
|
|
10
|
+
let parsedChildren = [];
|
|
11
|
+
rowChildren === null || rowChildren === void 0 ? void 0 : rowChildren.forEach((r) => {
|
|
12
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
13
|
+
let periods = [];
|
|
14
|
+
if (react_1.default.isValidElement(r) && ((_a = r === null || r === void 0 ? void 0 : r.props) === null || _a === void 0 ? void 0 : _a.children)) {
|
|
15
|
+
if (Array.isArray(r.props.children)) {
|
|
16
|
+
for (let i = 0; i < r.props.children.length; i++) {
|
|
17
|
+
const p = r.props.children[i];
|
|
18
|
+
periods.push({
|
|
19
|
+
start: (_b = p === null || p === void 0 ? void 0 : p.props) === null || _b === void 0 ? void 0 : _b.start,
|
|
20
|
+
end: (_c = p === null || p === void 0 ? void 0 : p.props) === null || _c === void 0 ? void 0 : _c.end,
|
|
21
|
+
status: ((_d = p === null || p === void 0 ? void 0 : p.props) === null || _d === void 0 ? void 0 : _d.status) || "neutral",
|
|
22
|
+
onSelectPeriod: (_e = p.props) === null || _e === void 0 ? void 0 : _e.onSelectPeriod,
|
|
23
|
+
label: r.props.label,
|
|
24
|
+
icon: p.props.icon,
|
|
25
|
+
children: p.props.children,
|
|
26
|
+
isActive: p.props.isActive,
|
|
27
|
+
statusLabel: p.props.statusLabel,
|
|
28
|
+
restProps: (0, util_1.omit)(p.props, [
|
|
29
|
+
"start",
|
|
30
|
+
"end",
|
|
31
|
+
"status",
|
|
32
|
+
"onSelectPeriod",
|
|
33
|
+
"label",
|
|
34
|
+
"icon",
|
|
35
|
+
"children",
|
|
36
|
+
"isActive",
|
|
37
|
+
"statusLabel",
|
|
38
|
+
]),
|
|
39
|
+
ref: p === null || p === void 0 ? void 0 : p.ref,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
periods.push({
|
|
45
|
+
start: r.props.children.props.start,
|
|
46
|
+
end: r.props.children.props.end,
|
|
47
|
+
status: ((_f = r.props.children.props) === null || _f === void 0 ? void 0 : _f.status) || "neutral",
|
|
48
|
+
onSelectPeriod: (_g = r.props.children.props) === null || _g === void 0 ? void 0 : _g.onSelectPeriod,
|
|
49
|
+
label: r.props.label,
|
|
50
|
+
icon: (_h = r.props.children.props) === null || _h === void 0 ? void 0 : _h.icon,
|
|
51
|
+
children: (_j = r.props.children.props) === null || _j === void 0 ? void 0 : _j.children,
|
|
52
|
+
statusLabel: (_k = r.props.children.props) === null || _k === void 0 ? void 0 : _k.statusLabel,
|
|
53
|
+
restProps: (0, util_1.omit)(r.props.children.props, [
|
|
54
|
+
"start",
|
|
55
|
+
"end",
|
|
56
|
+
"status",
|
|
57
|
+
"onSelectPeriod",
|
|
58
|
+
"label",
|
|
59
|
+
"icon",
|
|
60
|
+
"children",
|
|
61
|
+
"isActive",
|
|
62
|
+
"statusLabel",
|
|
63
|
+
]),
|
|
64
|
+
ref: (_m = (_l = r.props) === null || _l === void 0 ? void 0 : _l.children) === null || _m === void 0 ? void 0 : _m.ref,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
parsedChildren.push({
|
|
68
|
+
label: r.props.label,
|
|
69
|
+
icon: r.props.icon,
|
|
70
|
+
headingTag: r.props.headingTag,
|
|
71
|
+
periods: periods,
|
|
72
|
+
restProps: (0, util_1.omit)(r.props, ["label", "icon", "headingTag"]),
|
|
73
|
+
ref: r === null || r === void 0 ? void 0 : r.ref,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
return parsedChildren;
|
|
78
|
+
};
|
|
79
|
+
exports.parseRows = parseRows;
|