@navikt/ds-react 3.4.2 → 4.1.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 +5912 -3911
- package/cjs/accordion/Accordion.js +22 -2
- package/cjs/alert/Alert.js +9 -0
- package/cjs/button/Button.js +10 -0
- package/cjs/chat/Chat.js +16 -0
- package/cjs/chips/Chips.js +27 -0
- package/cjs/chips/Toggle.js +4 -6
- package/cjs/copybutton/CopyButton.js +11 -0
- package/cjs/date/DateInput.js +1 -1
- package/cjs/date/datepicker/DatePicker.js +22 -0
- package/cjs/date/hooks/index.js +4 -4
- package/cjs/date/hooks/useDatepicker.js +13 -0
- package/cjs/date/hooks/useMonthPicker.js +13 -0
- package/cjs/date/hooks/useRangeDatepicker.js +12 -0
- package/cjs/date/index.js +6 -6
- package/cjs/date/monthpicker/MonthPicker.js +22 -0
- package/cjs/dropdown/Dropdown.js +88 -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/expansion-card/ExpansionCard.js +18 -0
- package/cjs/form/ConfirmationPanel.js +18 -0
- package/cjs/form/Select.js +16 -0
- package/cjs/form/Switch.js +11 -0
- package/cjs/form/TextField.js +11 -0
- package/cjs/form/Textarea.js +11 -0
- package/cjs/form/checkbox/CheckboxGroup.js +15 -0
- package/cjs/form/error-summary/ErrorSummary.js +18 -0
- package/cjs/form/radio/RadioGroup.js +10 -0
- package/cjs/form/search/Search.js +13 -0
- package/cjs/guide-panel/GuidePanel.js +15 -0
- package/cjs/help-text/HelpText.js +13 -0
- package/cjs/index.js +4 -0
- package/cjs/internal-header/InternalHeader.js +83 -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/link/Link.js +13 -0
- package/cjs/link-panel/LinkPanel.js +17 -0
- package/cjs/loader/Loader.js +11 -0
- package/cjs/modal/Modal.js +27 -0
- package/cjs/pagination/Pagination.js +17 -0
- package/cjs/panel/Panel.js +19 -0
- package/cjs/popover/Popover.js +20 -0
- package/cjs/provider/Provider.js +13 -0
- package/cjs/read-more/ReadMore.js +17 -0
- package/cjs/skeleton/Skeleton.js +51 -0
- package/cjs/skeleton/index.js +8 -0
- package/cjs/skeleton/package.json +6 -0
- package/cjs/stepper/Step.js +3 -4
- package/cjs/stepper/Stepper.js +24 -0
- package/cjs/table/Table.js +32 -0
- package/cjs/tabs/Tabs.js +27 -1
- package/cjs/tag/Tag.js +11 -0
- package/cjs/timeline/AxisLabels.js +90 -0
- package/cjs/timeline/Pin.js +106 -0
- package/cjs/timeline/Timeline.js +180 -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/cjs/toggle-group/ToggleGroup.js +17 -2
- package/cjs/tooltip/Tooltip.js +13 -0
- package/cjs/typography/BodyLong.js +14 -0
- package/cjs/typography/BodyShort.js +14 -0
- package/cjs/typography/Detail.js +14 -0
- package/cjs/typography/ErrorMessage.js +14 -0
- package/cjs/typography/Heading.js +14 -0
- package/cjs/typography/Ingress.js +14 -0
- package/cjs/typography/Label.js +14 -0
- package/esm/accordion/Accordion.d.ts +40 -6
- package/esm/accordion/Accordion.js +22 -2
- package/esm/accordion/Accordion.js.map +1 -1
- package/esm/accordion/AccordionContent.d.ts +1 -2
- package/esm/accordion/AccordionContent.js.map +1 -1
- package/esm/accordion/AccordionHeader.d.ts +1 -2
- package/esm/accordion/AccordionHeader.js.map +1 -1
- package/esm/accordion/AccordionItem.d.ts +1 -2
- package/esm/accordion/AccordionItem.js.map +1 -1
- package/esm/alert/Alert.d.ts +9 -0
- package/esm/alert/Alert.js +9 -0
- package/esm/alert/Alert.js.map +1 -1
- package/esm/button/Button.d.ts +10 -0
- package/esm/button/Button.js +10 -0
- package/esm/button/Button.js.map +1 -1
- package/esm/chat/Bubble.d.ts +1 -2
- package/esm/chat/Bubble.js.map +1 -1
- package/esm/chat/Chat.d.ts +21 -2
- package/esm/chat/Chat.js +16 -0
- package/esm/chat/Chat.js.map +1 -1
- package/esm/chips/Chips.d.ts +42 -4
- package/esm/chips/Chips.js +27 -0
- package/esm/chips/Chips.js.map +1 -1
- package/esm/chips/Removable.d.ts +0 -2
- package/esm/chips/Removable.js.map +1 -1
- package/esm/chips/Toggle.d.ts +11 -3
- package/esm/chips/Toggle.js +4 -6
- package/esm/chips/Toggle.js.map +1 -1
- package/esm/copybutton/CopyButton.d.ts +11 -0
- package/esm/copybutton/CopyButton.js +11 -0
- package/esm/copybutton/CopyButton.js.map +1 -1
- package/esm/date/DateInput.d.ts +2 -3
- package/esm/date/DateInput.js +1 -1
- package/esm/date/DateInput.js.map +1 -1
- package/esm/date/datepicker/DatePicker.d.ts +38 -2
- package/esm/date/datepicker/DatePicker.js +22 -0
- package/esm/date/datepicker/DatePicker.js.map +1 -1
- 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/hooks/useDatepicker.d.ts +13 -0
- package/esm/date/hooks/useDatepicker.js +13 -0
- package/esm/date/hooks/useDatepicker.js.map +1 -1
- package/esm/date/hooks/useMonthPicker.d.ts +13 -0
- package/esm/date/hooks/useMonthPicker.js +13 -0
- package/esm/date/hooks/useMonthPicker.js.map +1 -1
- package/esm/date/hooks/useRangeDatepicker.d.ts +12 -0
- package/esm/date/hooks/useRangeDatepicker.js +12 -0
- package/esm/date/hooks/useRangeDatepicker.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/date/monthpicker/MonthPicker.d.ts +34 -4
- package/esm/date/monthpicker/MonthPicker.js +22 -0
- package/esm/date/monthpicker/MonthPicker.js.map +1 -1
- package/esm/dropdown/Dropdown.d.ts +74 -0
- package/esm/dropdown/Dropdown.js +60 -0
- package/esm/dropdown/Dropdown.js.map +1 -0
- package/esm/dropdown/Menu/Divider.d.ts +3 -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 +9 -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 +10 -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 +23 -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 +10 -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 +18 -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 +35 -0
- package/esm/dropdown/Menu/index.js +36 -0
- package/esm/dropdown/Menu/index.js.map +1 -0
- package/esm/dropdown/Toggle.d.ts +9 -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/expansion-card/ExpansionCard.d.ts +40 -8
- package/esm/expansion-card/ExpansionCard.js +18 -0
- package/esm/expansion-card/ExpansionCard.js.map +1 -1
- package/esm/expansion-card/ExpansionCardContent.d.ts +1 -2
- package/esm/expansion-card/ExpansionCardContent.js.map +1 -1
- package/esm/expansion-card/ExpansionCardDescription.d.ts +2 -4
- package/esm/expansion-card/ExpansionCardDescription.js.map +1 -1
- package/esm/expansion-card/ExpansionCardHeader.d.ts +1 -2
- package/esm/expansion-card/ExpansionCardHeader.js.map +1 -1
- package/esm/expansion-card/ExpansionCardTitle.d.ts +2 -4
- package/esm/expansion-card/ExpansionCardTitle.js.map +1 -1
- package/esm/form/ConfirmationPanel.d.ts +18 -0
- package/esm/form/ConfirmationPanel.js +18 -0
- package/esm/form/ConfirmationPanel.js.map +1 -1
- package/esm/form/Select.d.ts +16 -0
- package/esm/form/Select.js +16 -0
- package/esm/form/Select.js.map +1 -1
- package/esm/form/Switch.d.ts +11 -0
- package/esm/form/Switch.js +11 -0
- package/esm/form/Switch.js.map +1 -1
- package/esm/form/TextField.d.ts +11 -0
- package/esm/form/TextField.js +11 -0
- package/esm/form/TextField.js.map +1 -1
- package/esm/form/Textarea.d.ts +11 -0
- package/esm/form/Textarea.js +11 -0
- package/esm/form/Textarea.js.map +1 -1
- package/esm/form/checkbox/CheckboxGroup.d.ts +15 -0
- package/esm/form/checkbox/CheckboxGroup.js +15 -0
- package/esm/form/checkbox/CheckboxGroup.js.map +1 -1
- package/esm/form/error-summary/ErrorSummary.d.ts +18 -0
- package/esm/form/error-summary/ErrorSummary.js +18 -0
- package/esm/form/error-summary/ErrorSummary.js.map +1 -1
- 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/form/search/Search.d.ts +13 -0
- package/esm/form/search/Search.js +13 -0
- package/esm/form/search/Search.js.map +1 -1
- package/esm/guide-panel/GuidePanel.d.ts +15 -0
- package/esm/guide-panel/GuidePanel.js +15 -0
- package/esm/guide-panel/GuidePanel.js.map +1 -1
- package/esm/help-text/HelpText.d.ts +13 -0
- package/esm/help-text/HelpText.js +13 -0
- package/esm/help-text/HelpText.js.map +1 -1
- package/esm/index.d.ts +4 -0
- package/esm/index.js +4 -0
- package/esm/index.js.map +1 -1
- package/esm/internal-header/InternalHeader.d.ts +60 -0
- package/esm/internal-header/InternalHeader.js +55 -0
- package/esm/internal-header/InternalHeader.js.map +1 -0
- package/esm/internal-header/InternalHeaderButton.d.ts +10 -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 +10 -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 +13 -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 +14 -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/link/Link.d.ts +13 -0
- package/esm/link/Link.js +13 -0
- package/esm/link/Link.js.map +1 -1
- package/esm/link-panel/LinkPanel.d.ts +28 -4
- package/esm/link-panel/LinkPanel.js +17 -0
- package/esm/link-panel/LinkPanel.js.map +1 -1
- package/esm/link-panel/LinkPanelDescription.d.ts +2 -4
- package/esm/link-panel/LinkPanelDescription.js.map +1 -1
- package/esm/link-panel/LinkPanelTitle.d.ts +2 -4
- package/esm/link-panel/LinkPanelTitle.js.map +1 -1
- package/esm/list/List.d.ts +5 -2
- package/esm/list/List.js.map +1 -1
- package/esm/list/ListItem.d.ts +1 -3
- package/esm/list/ListItem.js.map +1 -1
- package/esm/loader/Loader.d.ts +11 -0
- package/esm/loader/Loader.js +11 -0
- package/esm/loader/Loader.js.map +1 -1
- package/esm/modal/Modal.d.ts +27 -0
- package/esm/modal/Modal.js +27 -0
- package/esm/modal/Modal.js.map +1 -1
- package/esm/pagination/Pagination.d.ts +17 -0
- package/esm/pagination/Pagination.js +17 -0
- package/esm/pagination/Pagination.js.map +1 -1
- package/esm/panel/Panel.d.ts +19 -0
- package/esm/panel/Panel.js +19 -0
- package/esm/panel/Panel.js.map +1 -1
- package/esm/popover/Popover.d.ts +20 -0
- package/esm/popover/Popover.js +20 -0
- package/esm/popover/Popover.js.map +1 -1
- package/esm/provider/Provider.d.ts +13 -0
- package/esm/provider/Provider.js +13 -0
- package/esm/provider/Provider.js.map +1 -1
- 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/skeleton/Skeleton.d.ts +18 -0
- package/esm/skeleton/Skeleton.js +23 -0
- package/esm/skeleton/Skeleton.js.map +1 -0
- package/esm/skeleton/index.d.ts +2 -0
- package/esm/skeleton/index.js +2 -0
- package/esm/skeleton/index.js.map +1 -0
- package/esm/stepper/Step.d.ts +1 -4
- package/esm/stepper/Step.js +1 -2
- package/esm/stepper/Step.js.map +1 -1
- package/esm/stepper/Stepper.d.ts +31 -2
- package/esm/stepper/Stepper.js +24 -0
- package/esm/stepper/Stepper.js.map +1 -1
- package/esm/table/Table.d.ts +32 -0
- package/esm/table/Table.js +32 -0
- package/esm/table/Table.js.map +1 -1
- package/esm/tabs/Tab.d.ts +1 -2
- package/esm/tabs/Tab.js.map +1 -1
- package/esm/tabs/TabList.d.ts +1 -2
- package/esm/tabs/TabList.js.map +1 -1
- package/esm/tabs/TabPanel.d.ts +1 -2
- package/esm/tabs/TabPanel.js.map +1 -1
- package/esm/tabs/Tabs.d.ts +43 -6
- package/esm/tabs/Tabs.js +27 -1
- package/esm/tabs/Tabs.js.map +1 -1
- package/esm/tag/Tag.d.ts +11 -0
- package/esm/tag/Tag.js +11 -0
- package/esm/tag/Tag.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 +63 -0
- package/esm/timeline/Timeline.js +152 -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/esm/toggle-group/ToggleGroup.d.ts +20 -2
- package/esm/toggle-group/ToggleGroup.js +17 -2
- package/esm/toggle-group/ToggleGroup.js.map +1 -1
- package/esm/toggle-group/ToggleItem.d.ts +1 -2
- package/esm/toggle-group/ToggleItem.js.map +1 -1
- package/esm/tooltip/Tooltip.d.ts +13 -0
- package/esm/tooltip/Tooltip.js +13 -0
- package/esm/tooltip/Tooltip.js.map +1 -1
- package/esm/typography/BodyLong.d.ts +14 -0
- package/esm/typography/BodyLong.js +14 -0
- package/esm/typography/BodyLong.js.map +1 -1
- package/esm/typography/BodyShort.d.ts +14 -0
- package/esm/typography/BodyShort.js +14 -0
- package/esm/typography/BodyShort.js.map +1 -1
- package/esm/typography/Detail.d.ts +14 -0
- package/esm/typography/Detail.js +14 -0
- package/esm/typography/Detail.js.map +1 -1
- package/esm/typography/ErrorMessage.d.ts +14 -0
- package/esm/typography/ErrorMessage.js +14 -0
- package/esm/typography/ErrorMessage.js.map +1 -1
- package/esm/typography/Heading.d.ts +14 -0
- package/esm/typography/Heading.js +14 -0
- package/esm/typography/Heading.js.map +1 -1
- package/esm/typography/Ingress.d.ts +14 -0
- package/esm/typography/Ingress.js +14 -0
- package/esm/typography/Ingress.js.map +1 -1
- package/esm/typography/Label.d.ts +14 -0
- package/esm/typography/Label.js +14 -0
- package/esm/typography/Label.js.map +1 -1
- package/package.json +2 -2
- package/src/accordion/Accordion.tsx +49 -7
- package/src/accordion/AccordionContent.tsx +1 -5
- package/src/accordion/AccordionHeader.tsx +1 -5
- package/src/accordion/AccordionItem.tsx +1 -5
- package/src/accordion/accordion.stories.tsx +4 -2
- package/src/alert/Alert.tsx +9 -0
- package/src/button/Button.tsx +10 -0
- package/src/chat/Bubble.tsx +1 -5
- package/src/chat/Chat.tsx +23 -2
- package/src/chips/Chips.tsx +42 -4
- package/src/chips/Removable.tsx +1 -4
- package/src/chips/Toggle.tsx +47 -11
- package/src/chips/chips.stories.tsx +73 -20
- package/src/copybutton/CopyButton.tsx +11 -0
- package/src/date/DateInput.tsx +105 -115
- package/src/date/datepicker/DatePicker.tsx +40 -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/useDatepicker.tsx +13 -0
- package/src/date/hooks/useMonthPicker.tsx +13 -0
- package/src/date/hooks/useRangeDatepicker.test.tsx +6 -6
- package/src/date/hooks/useRangeDatepicker.tsx +13 -1
- package/src/date/index.ts +5 -5
- package/src/date/monthpicker/MonthPicker.tsx +36 -4
- 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 +119 -0
- package/src/dropdown/Menu/Divider.tsx +15 -0
- package/src/dropdown/Menu/GroupedList/Heading.tsx +28 -0
- package/src/dropdown/Menu/GroupedList/Item.tsx +41 -0
- package/src/dropdown/Menu/GroupedList/index.tsx +43 -0
- package/src/dropdown/Menu/List/Item.tsx +38 -0
- package/src/dropdown/Menu/List/index.tsx +32 -0
- package/src/dropdown/Menu/index.tsx +96 -0
- package/src/dropdown/Toggle.tsx +48 -0
- package/src/dropdown/dropdown.stories.tsx +91 -0
- package/src/dropdown/index.ts +2 -0
- package/src/expansion-card/ExpansionCard.tsx +46 -8
- package/src/expansion-card/ExpansionCardContent.tsx +25 -28
- package/src/expansion-card/ExpansionCardDescription.tsx +22 -24
- package/src/expansion-card/ExpansionCardHeader.tsx +31 -34
- package/src/expansion-card/ExpansionCardTitle.tsx +3 -5
- package/src/form/ConfirmationPanel.tsx +18 -0
- package/src/form/Select.tsx +16 -0
- package/src/form/Switch.tsx +11 -0
- package/src/form/TextField.tsx +11 -0
- package/src/form/Textarea.tsx +11 -0
- package/src/form/checkbox/CheckboxGroup.tsx +15 -0
- package/src/form/error-summary/ErrorSummary.tsx +18 -0
- package/src/form/radio/RadioGroup.tsx +10 -0
- package/src/form/search/Search.tsx +13 -0
- package/src/guide-panel/GuidePanel.tsx +15 -0
- package/src/help-text/HelpText.tsx +13 -0
- package/src/index.ts +4 -0
- package/src/internal-header/InternalHeader.tsx +93 -0
- package/src/internal-header/InternalHeaderButton.tsx +23 -0
- package/src/internal-header/InternalHeaderTitle.tsx +27 -0
- package/src/internal-header/InternalHeaderUser.tsx +35 -0
- package/src/internal-header/InternalHeaderUserButton.tsx +40 -0
- package/src/internal-header/header.stories.tsx +225 -0
- package/src/internal-header/index.ts +8 -0
- package/src/link/Link.tsx +13 -0
- package/src/link-panel/LinkPanel.tsx +30 -4
- package/src/link-panel/LinkPanelDescription.tsx +12 -15
- package/src/link-panel/LinkPanelTitle.tsx +15 -18
- package/src/list/List.tsx +7 -2
- package/src/list/ListItem.tsx +1 -6
- package/src/loader/Loader.tsx +11 -0
- package/src/modal/Modal.tsx +27 -0
- package/src/pagination/Pagination.tsx +17 -0
- package/src/panel/Panel.tsx +19 -0
- package/src/popover/Popover.tsx +20 -0
- package/src/provider/Provider.tsx +13 -0
- package/src/read-more/ReadMore.tsx +17 -0
- package/src/skeleton/Skeleton.tsx +48 -0
- package/src/skeleton/index.ts +2 -0
- package/src/skeleton/skeleton.stories.tsx +118 -0
- package/src/stepper/Step.tsx +57 -60
- package/src/stepper/Stepper.tsx +31 -2
- package/src/table/Table.tsx +32 -0
- package/src/tabs/Tab.tsx +38 -39
- package/src/tabs/TabList.tsx +1 -5
- package/src/tabs/TabPanel.tsx +1 -5
- package/src/tabs/Tabs.tsx +48 -7
- package/src/tag/Tag.tsx +11 -0
- package/src/timeline/AxisLabels.tsx +143 -0
- package/src/timeline/Pin.tsx +169 -0
- package/src/timeline/Timeline.tsx +237 -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
- package/src/toggle-group/ToggleGroup.tsx +23 -3
- package/src/toggle-group/ToggleItem.tsx +1 -5
- package/src/tooltip/Tooltip.tsx +13 -0
- package/src/typography/BodyLong.tsx +14 -0
- package/src/typography/BodyShort.tsx +14 -0
- package/src/typography/Detail.tsx +14 -0
- package/src/typography/ErrorMessage.tsx +14 -0
- package/src/typography/Heading.tsx +14 -0
- package/src/typography/Ingress.tsx +14 -0
- package/src/typography/Label.tsx +14 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { Detail } from "../typography/Detail";
|
|
2
|
+
import {
|
|
3
|
+
addDays,
|
|
4
|
+
addMonths,
|
|
5
|
+
addYears,
|
|
6
|
+
differenceInDays,
|
|
7
|
+
differenceInMonths,
|
|
8
|
+
differenceInYears,
|
|
9
|
+
endOfMonth,
|
|
10
|
+
endOfYear,
|
|
11
|
+
format,
|
|
12
|
+
startOfDay,
|
|
13
|
+
startOfMonth,
|
|
14
|
+
startOfYear,
|
|
15
|
+
subDays,
|
|
16
|
+
} from "date-fns";
|
|
17
|
+
import nbLocale from "date-fns/locale/nb";
|
|
18
|
+
import React from "react";
|
|
19
|
+
import { useTimelineContext } from "./hooks/useTimelineContext";
|
|
20
|
+
import { isVisible } from "./utils";
|
|
21
|
+
import { horizontalPositionAndWidth } from "./utils/calc";
|
|
22
|
+
import { AxisLabel } from "./utils/types.external";
|
|
23
|
+
|
|
24
|
+
export const dayLabels = (
|
|
25
|
+
start: Date,
|
|
26
|
+
end: Date,
|
|
27
|
+
totalDays: number,
|
|
28
|
+
direction: "left" | "right"
|
|
29
|
+
): AxisLabel[] => {
|
|
30
|
+
const increment = Math.ceil(totalDays / 10);
|
|
31
|
+
const lastDay = startOfDay(end);
|
|
32
|
+
return new Array(totalDays)
|
|
33
|
+
.fill(lastDay)
|
|
34
|
+
.map((thisDay, i) => {
|
|
35
|
+
if (i % increment !== 0) return null;
|
|
36
|
+
const day: Date = subDays(thisDay, i);
|
|
37
|
+
const { horizontalPosition, width } = horizontalPositionAndWidth(
|
|
38
|
+
day,
|
|
39
|
+
addDays(day, 1),
|
|
40
|
+
start,
|
|
41
|
+
end
|
|
42
|
+
);
|
|
43
|
+
return {
|
|
44
|
+
direction: direction,
|
|
45
|
+
horizontalPosition: horizontalPosition,
|
|
46
|
+
label: format(day, "dd.MM", { locale: nbLocale }),
|
|
47
|
+
date: day,
|
|
48
|
+
width: width,
|
|
49
|
+
};
|
|
50
|
+
})
|
|
51
|
+
.filter((label) => label !== null) as AxisLabel[];
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const monthLabels = (
|
|
55
|
+
start: Date,
|
|
56
|
+
end: Date,
|
|
57
|
+
direction: "left" | "right"
|
|
58
|
+
): AxisLabel[] => {
|
|
59
|
+
const startMonth = startOfMonth(start);
|
|
60
|
+
const endMonth = endOfMonth(end);
|
|
61
|
+
const numberOfMonths = differenceInMonths(endMonth, startMonth) + 1;
|
|
62
|
+
return new Array(numberOfMonths).fill(startMonth).map((thisMonth, i) => {
|
|
63
|
+
const month: Date = addMonths(thisMonth, i);
|
|
64
|
+
const { horizontalPosition, width } = horizontalPositionAndWidth(
|
|
65
|
+
month,
|
|
66
|
+
addMonths(month, 1),
|
|
67
|
+
start,
|
|
68
|
+
end
|
|
69
|
+
);
|
|
70
|
+
return {
|
|
71
|
+
direction: direction,
|
|
72
|
+
horizontalPosition: horizontalPosition,
|
|
73
|
+
label: format(month, "MMM yy", { locale: nbLocale }),
|
|
74
|
+
date: month,
|
|
75
|
+
width: width,
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export const yearLabels = (
|
|
81
|
+
start: Date,
|
|
82
|
+
end: Date,
|
|
83
|
+
direction: "left" | "right"
|
|
84
|
+
): AxisLabel[] => {
|
|
85
|
+
const firstYear = startOfYear(start);
|
|
86
|
+
const lastYear = endOfYear(end);
|
|
87
|
+
const yearCount = differenceInYears(lastYear, start) + 1;
|
|
88
|
+
return new Array(yearCount).fill(firstYear).map((thisYear, i) => {
|
|
89
|
+
const year: Date = addYears(thisYear, i);
|
|
90
|
+
const { horizontalPosition, width } = horizontalPositionAndWidth(
|
|
91
|
+
year,
|
|
92
|
+
addYears(year, 1),
|
|
93
|
+
start,
|
|
94
|
+
end
|
|
95
|
+
);
|
|
96
|
+
return {
|
|
97
|
+
direction: direction,
|
|
98
|
+
horizontalPosition: horizontalPosition,
|
|
99
|
+
label: year.getFullYear().toString(),
|
|
100
|
+
date: year,
|
|
101
|
+
width: width,
|
|
102
|
+
};
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const axisLabels = (
|
|
107
|
+
start: Date,
|
|
108
|
+
end: Date,
|
|
109
|
+
direction: "left" | "right"
|
|
110
|
+
): AxisLabel[] => {
|
|
111
|
+
const totalDays = differenceInDays(end, start);
|
|
112
|
+
if (totalDays < 40) {
|
|
113
|
+
return dayLabels(start, end, totalDays, direction);
|
|
114
|
+
} else if (totalDays < 370) {
|
|
115
|
+
return monthLabels(start, end, direction);
|
|
116
|
+
} else {
|
|
117
|
+
return yearLabels(start, end, direction);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export const AxisLabels = () => {
|
|
122
|
+
const { endDate, startDate, direction } = useTimelineContext();
|
|
123
|
+
const labels = axisLabels(startDate, endDate, direction).filter(isVisible);
|
|
124
|
+
|
|
125
|
+
return (
|
|
126
|
+
<div className="navds-timeline__axislabels" aria-hidden="true">
|
|
127
|
+
{labels.map((etikett) => (
|
|
128
|
+
<Detail
|
|
129
|
+
className="navds-timeline__axislabels-label"
|
|
130
|
+
as="div"
|
|
131
|
+
key={etikett.label}
|
|
132
|
+
style={{
|
|
133
|
+
justifyContent: direction === "left" ? "flex-start" : "flex-end",
|
|
134
|
+
[direction]: `${etikett.horizontalPosition}%`,
|
|
135
|
+
width: `${etikett.width}%`,
|
|
136
|
+
}}
|
|
137
|
+
>
|
|
138
|
+
{etikett.label}
|
|
139
|
+
</Detail>
|
|
140
|
+
))}
|
|
141
|
+
</div>
|
|
142
|
+
);
|
|
143
|
+
};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import {
|
|
2
|
+
autoUpdate,
|
|
3
|
+
arrow as flArrow,
|
|
4
|
+
flip,
|
|
5
|
+
offset,
|
|
6
|
+
safePolygon,
|
|
7
|
+
shift,
|
|
8
|
+
useDismiss,
|
|
9
|
+
useFloating,
|
|
10
|
+
useFocus,
|
|
11
|
+
useHover,
|
|
12
|
+
useInteractions,
|
|
13
|
+
} from "@floating-ui/react";
|
|
14
|
+
import { useEventListener, mergeRefs } from "../util";
|
|
15
|
+
import { format } from "date-fns";
|
|
16
|
+
import React, {
|
|
17
|
+
forwardRef,
|
|
18
|
+
useCallback,
|
|
19
|
+
useMemo,
|
|
20
|
+
useRef,
|
|
21
|
+
useState,
|
|
22
|
+
} from "react";
|
|
23
|
+
import { useTimelineContext } from "./hooks/useTimelineContext";
|
|
24
|
+
import { position } from "./utils/calc";
|
|
25
|
+
import { TimelineComponentTypes } from "./utils/types.internal";
|
|
26
|
+
|
|
27
|
+
export interface TimelinePinProps
|
|
28
|
+
extends React.HTMLAttributes<HTMLButtonElement> {
|
|
29
|
+
/**
|
|
30
|
+
* Date position for the pin.
|
|
31
|
+
*/
|
|
32
|
+
date: Date;
|
|
33
|
+
/**
|
|
34
|
+
* Content in Pin Popover.
|
|
35
|
+
*/
|
|
36
|
+
children?: React.ReactNode;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface PinType
|
|
40
|
+
extends React.ForwardRefExoticComponent<
|
|
41
|
+
TimelinePinProps & React.RefAttributes<HTMLButtonElement>
|
|
42
|
+
> {
|
|
43
|
+
componentType: TimelineComponentTypes;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const Pin = forwardRef<HTMLButtonElement, TimelinePinProps>(
|
|
47
|
+
({ date, children, ...rest }, ref) => {
|
|
48
|
+
const { startDate, endDate, direction } = useTimelineContext();
|
|
49
|
+
const [open, setOpen] = useState(false);
|
|
50
|
+
const arrowRef = useRef<HTMLDivElement | null>(null);
|
|
51
|
+
|
|
52
|
+
const {
|
|
53
|
+
context,
|
|
54
|
+
placement,
|
|
55
|
+
middlewareData: { arrow: { x: arrowX, y: arrowY } = {} },
|
|
56
|
+
refs,
|
|
57
|
+
floatingStyles,
|
|
58
|
+
} = useFloating({
|
|
59
|
+
placement: "top",
|
|
60
|
+
open: open,
|
|
61
|
+
onOpenChange: setOpen,
|
|
62
|
+
middleware: [
|
|
63
|
+
offset(16),
|
|
64
|
+
shift(),
|
|
65
|
+
flip({ padding: 5, fallbackPlacements: ["bottom", "top"] }),
|
|
66
|
+
flArrow({ element: arrowRef, padding: 5 }),
|
|
67
|
+
],
|
|
68
|
+
whileElementsMounted: autoUpdate,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const { getFloatingProps, getReferenceProps } = useInteractions([
|
|
72
|
+
useHover(context, {
|
|
73
|
+
handleClose: safePolygon(),
|
|
74
|
+
restMs: 25,
|
|
75
|
+
delay: { open: 1000 },
|
|
76
|
+
}),
|
|
77
|
+
useFocus(context),
|
|
78
|
+
useDismiss(context),
|
|
79
|
+
]);
|
|
80
|
+
|
|
81
|
+
const mergedRef = useMemo(
|
|
82
|
+
() => mergeRefs([refs.setReference, ref]),
|
|
83
|
+
[ref, refs.setReference]
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
useEventListener(
|
|
87
|
+
"focusin",
|
|
88
|
+
useCallback(
|
|
89
|
+
(e: FocusEvent) => {
|
|
90
|
+
if (
|
|
91
|
+
![refs.domReference.current, refs?.floating?.current].some(
|
|
92
|
+
(element) => element?.contains(e.target as Node)
|
|
93
|
+
)
|
|
94
|
+
) {
|
|
95
|
+
open && setOpen(false);
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
[open, refs.domReference, refs?.floating]
|
|
99
|
+
)
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
const staticSide = {
|
|
103
|
+
top: "bottom",
|
|
104
|
+
right: "left",
|
|
105
|
+
bottom: "top",
|
|
106
|
+
left: "right",
|
|
107
|
+
}[placement.split("-")[0]];
|
|
108
|
+
|
|
109
|
+
return (
|
|
110
|
+
<>
|
|
111
|
+
<div
|
|
112
|
+
className="navds-timeline__pin-wrapper"
|
|
113
|
+
style={{ [direction]: `${position(date, startDate, endDate)}%` }}
|
|
114
|
+
>
|
|
115
|
+
<button
|
|
116
|
+
{...rest}
|
|
117
|
+
ref={mergedRef}
|
|
118
|
+
className="navds-timeline__pin-button"
|
|
119
|
+
aria-label={`pin:${format(date, "dd.MM.yyyy")}`}
|
|
120
|
+
type="button"
|
|
121
|
+
aria-expanded={children ? open : undefined}
|
|
122
|
+
{...getReferenceProps({
|
|
123
|
+
onKeyDown: (e) => {
|
|
124
|
+
rest?.onKeyDown?.(e as React.KeyboardEvent<HTMLButtonElement>);
|
|
125
|
+
if (e.key === "Enter") {
|
|
126
|
+
setOpen((prev) => !prev);
|
|
127
|
+
} else if (e.key === " ") {
|
|
128
|
+
setOpen(false);
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
})}
|
|
132
|
+
/>
|
|
133
|
+
</div>
|
|
134
|
+
{children && (
|
|
135
|
+
<div
|
|
136
|
+
className="navds-timeline__popover"
|
|
137
|
+
data-placement={placement}
|
|
138
|
+
aria-hidden={!open}
|
|
139
|
+
ref={refs.setFloating}
|
|
140
|
+
{...getFloatingProps({
|
|
141
|
+
tabIndex: -1,
|
|
142
|
+
})}
|
|
143
|
+
style={{
|
|
144
|
+
...floatingStyles,
|
|
145
|
+
display: open ? undefined : "none",
|
|
146
|
+
}}
|
|
147
|
+
>
|
|
148
|
+
<div className="navds-timeline__popover-content">{children}</div>
|
|
149
|
+
<div
|
|
150
|
+
ref={(node) => {
|
|
151
|
+
arrowRef.current = node;
|
|
152
|
+
}}
|
|
153
|
+
style={{
|
|
154
|
+
...(arrowX != null ? { left: arrowX } : {}),
|
|
155
|
+
...(arrowY != null ? { top: arrowY } : {}),
|
|
156
|
+
...(staticSide ? { [staticSide]: "-0.5rem" } : {}),
|
|
157
|
+
}}
|
|
158
|
+
className="navds-timeline__popover-arrow"
|
|
159
|
+
/>
|
|
160
|
+
</div>
|
|
161
|
+
)}
|
|
162
|
+
</>
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
) as PinType;
|
|
166
|
+
|
|
167
|
+
Pin.componentType = "pin";
|
|
168
|
+
|
|
169
|
+
export default Pin;
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { endOfDay, isSameDay, startOfDay } from "date-fns";
|
|
2
|
+
import React, { forwardRef, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { AxisLabels } from "./AxisLabels";
|
|
4
|
+
import { RowContext } from "./hooks/useRowContext";
|
|
5
|
+
import { TimelineContext } from "./hooks/useTimelineContext";
|
|
6
|
+
import {
|
|
7
|
+
useEarliestDate,
|
|
8
|
+
useLatestDate,
|
|
9
|
+
useTimelineRows,
|
|
10
|
+
} from "./hooks/useTimelineRows";
|
|
11
|
+
import Period, { PeriodType } from "./period";
|
|
12
|
+
import Pin, { PinType } from "./Pin";
|
|
13
|
+
import TimelineRow, { TimelineRowType } from "./TimelineRow";
|
|
14
|
+
import { parseRows } from "./utils/timeline";
|
|
15
|
+
import Zoom, { ZoomType } from "./zoom";
|
|
16
|
+
|
|
17
|
+
export interface TimelineProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
18
|
+
children: React.ReactNode;
|
|
19
|
+
/**
|
|
20
|
+
* Decides startingpoint in timeline.
|
|
21
|
+
* Defaults to earliest date among the timeline periods.
|
|
22
|
+
* @note Using this disables use of ZoomButtons. You will need to control zooming yourself.
|
|
23
|
+
*/
|
|
24
|
+
startDate?: Date;
|
|
25
|
+
/**
|
|
26
|
+
* Decides end-date for timeline.
|
|
27
|
+
* Defaults to the latest date among the timeline periods.
|
|
28
|
+
* @note Using this disables use of ZoomButtons. You will need to control zooming yourself.
|
|
29
|
+
*/
|
|
30
|
+
endDate?: Date;
|
|
31
|
+
/**
|
|
32
|
+
* Decides direction which periods are sorted/displayed. "left" ascends from earliest date on left.
|
|
33
|
+
* @default "left"
|
|
34
|
+
*/
|
|
35
|
+
direction?: "left" | "right";
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface TimelineComponent
|
|
39
|
+
extends React.ForwardRefExoticComponent<TimelineProps> {
|
|
40
|
+
/**
|
|
41
|
+
* @see 🏷️ {@link TimelineRowType}
|
|
42
|
+
*/
|
|
43
|
+
Row: TimelineRowType;
|
|
44
|
+
/**
|
|
45
|
+
* @see 🏷️ {@link PeriodType}
|
|
46
|
+
*/
|
|
47
|
+
Period: PeriodType;
|
|
48
|
+
/**
|
|
49
|
+
* @see 🏷️ {@link PinType}
|
|
50
|
+
*/
|
|
51
|
+
Pin: PinType;
|
|
52
|
+
/**
|
|
53
|
+
* @see 🏷️ {@link ZoomType}
|
|
54
|
+
*/
|
|
55
|
+
Zoom: ZoomType;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* A component that displays a timeline of events. Meant for Internal systems.
|
|
60
|
+
* @note Component is made for desktop enviroments and will start having issues on smaller screens.
|
|
61
|
+
*
|
|
62
|
+
* @see [📝 Documentation](https://aksel.nav.no/komponenter/core/timeline)
|
|
63
|
+
* @see 🏷️ {@link TimelineProps}
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```jsx
|
|
67
|
+
* <Timeline>
|
|
68
|
+
* <Timeline.Row>
|
|
69
|
+
* <Timeline.Period start={new Date("2020-01-01")} end={new Date("2020-01-31")}>
|
|
70
|
+
* <p>Period 1</p>
|
|
71
|
+
* </Timeline.Period>
|
|
72
|
+
* <Timeline.Row>
|
|
73
|
+
* </Timeline>
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export const Timeline = forwardRef<HTMLDivElement, TimelineProps>(
|
|
77
|
+
({ children, startDate, endDate, direction = "left", ...rest }, ref) => {
|
|
78
|
+
const isMultipleRows = Array.isArray(children);
|
|
79
|
+
|
|
80
|
+
const firstFocusabled = useRef<
|
|
81
|
+
{ ref: HTMLButtonElement | null; id: number }[]
|
|
82
|
+
>([]);
|
|
83
|
+
|
|
84
|
+
if (!isMultipleRows) {
|
|
85
|
+
children = [children];
|
|
86
|
+
}
|
|
87
|
+
const rowChildren = React.Children.toArray(children).filter(
|
|
88
|
+
(c: any) => c?.type?.componentType === "row"
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
const pins = React.Children.toArray(children).filter(
|
|
92
|
+
(c: any) => c?.type?.componentType === "pin"
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
const zoomComponent = React.Children.toArray(children).find(
|
|
96
|
+
(c: any) => c?.type?.componentType === "zoom"
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
const rowsRaw = useMemo(() => {
|
|
100
|
+
return parseRows(rowChildren);
|
|
101
|
+
}, [rowChildren]);
|
|
102
|
+
|
|
103
|
+
const rows = rowsRaw.map((r) => {
|
|
104
|
+
if (r?.periods) {
|
|
105
|
+
return r.periods;
|
|
106
|
+
}
|
|
107
|
+
return [];
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const initialStartDate = startOfDay(useEarliestDate({ startDate, rows }));
|
|
111
|
+
const [start, setStart] = useState(initialStartDate);
|
|
112
|
+
const [activeRow, setActiveRow] = useState<number | null>(null);
|
|
113
|
+
const [endInclusive, setEndInclusive] = useState(
|
|
114
|
+
endOfDay(useLatestDate({ endDate, rows }))
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
const initialEndDate = endOfDay(useLatestDate({ endDate, rows }));
|
|
118
|
+
const processedRows = useTimelineRows(
|
|
119
|
+
rowsRaw,
|
|
120
|
+
startDate ?? start,
|
|
121
|
+
endDate ?? endInclusive,
|
|
122
|
+
direction
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
const handleZoomChange = (zoomStart: Date) => {
|
|
126
|
+
if (startDate || endDate) {
|
|
127
|
+
if (process.env.NODE_ENV !== "production") {
|
|
128
|
+
console.warn(
|
|
129
|
+
"Zooming is not supported when startDate or endDate is set"
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (direction === "left") {
|
|
135
|
+
if (isSameDay(zoomStart, start)) {
|
|
136
|
+
setStart(initialStartDate);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
setStart(zoomStart);
|
|
140
|
+
} else {
|
|
141
|
+
if (isSameDay(zoomStart, endInclusive)) {
|
|
142
|
+
setEndInclusive(initialEndDate);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
setEndInclusive(zoomStart);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const handleActiveRowChange = (key: string) => {
|
|
150
|
+
if (activeRow !== null && key === "ArrowDown") {
|
|
151
|
+
for (let i = activeRow + 1; i < processedRows.length; i++) {
|
|
152
|
+
const row = processedRows[i];
|
|
153
|
+
if (row.periods.find((p) => !!p.children || !!p.onSelectPeriod)) {
|
|
154
|
+
setActiveRow(i);
|
|
155
|
+
firstFocusabled.current.find((x) => x.id === i)?.ref?.focus();
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (activeRow !== null && key === "ArrowUp") {
|
|
162
|
+
for (let i = activeRow - 1; i >= 0; i--) {
|
|
163
|
+
const row = processedRows[i];
|
|
164
|
+
if (row.periods.find((p) => !!p.children || !!p.onSelectPeriod)) {
|
|
165
|
+
setActiveRow(i);
|
|
166
|
+
firstFocusabled.current.find((x) => x.id === i)?.ref?.focus();
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const addFocusable = (ref: HTMLButtonElement | null, id: number) => {
|
|
175
|
+
let items = firstFocusabled.current;
|
|
176
|
+
items = items.filter((x) => x.id !== id);
|
|
177
|
+
items.push({ ref, id });
|
|
178
|
+
firstFocusabled.current = items;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
return (
|
|
182
|
+
<TimelineContext.Provider
|
|
183
|
+
value={{
|
|
184
|
+
startDate: startDate ?? start,
|
|
185
|
+
endDate: endDate ?? endInclusive,
|
|
186
|
+
direction: direction,
|
|
187
|
+
setStart: (d) => handleZoomChange(d),
|
|
188
|
+
setEndInclusive: (d) => setEndInclusive(d),
|
|
189
|
+
activeRow: activeRow,
|
|
190
|
+
setActiveRow: (key) => handleActiveRowChange(key),
|
|
191
|
+
initiate: (i) => setActiveRow(i),
|
|
192
|
+
addFocusable,
|
|
193
|
+
}}
|
|
194
|
+
>
|
|
195
|
+
<div {...rest} ref={ref}>
|
|
196
|
+
<div className="navds-timeline">
|
|
197
|
+
<AxisLabels />
|
|
198
|
+
|
|
199
|
+
{pins.map((pin) => {
|
|
200
|
+
return pin;
|
|
201
|
+
})}
|
|
202
|
+
|
|
203
|
+
{processedRows.map((row, i) => {
|
|
204
|
+
return (
|
|
205
|
+
<RowContext.Provider
|
|
206
|
+
key={`row-${row.id}`}
|
|
207
|
+
value={{
|
|
208
|
+
periods: row.periods,
|
|
209
|
+
id: row.id,
|
|
210
|
+
active: activeRow === i,
|
|
211
|
+
index: i,
|
|
212
|
+
}}
|
|
213
|
+
>
|
|
214
|
+
<TimelineRow
|
|
215
|
+
{...row?.restProps}
|
|
216
|
+
ref={row?.ref}
|
|
217
|
+
label={row.label}
|
|
218
|
+
icon={row.icon}
|
|
219
|
+
headingTag={row.headingTag}
|
|
220
|
+
/>
|
|
221
|
+
</RowContext.Provider>
|
|
222
|
+
);
|
|
223
|
+
})}
|
|
224
|
+
</div>
|
|
225
|
+
{zoomComponent && zoomComponent}
|
|
226
|
+
</div>
|
|
227
|
+
</TimelineContext.Provider>
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
) as TimelineComponent;
|
|
231
|
+
|
|
232
|
+
Timeline.Row = TimelineRow;
|
|
233
|
+
Timeline.Period = Period;
|
|
234
|
+
Timeline.Pin = Pin;
|
|
235
|
+
Timeline.Zoom = Zoom;
|
|
236
|
+
|
|
237
|
+
export default Timeline;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { BodyShort } from "../typography/BodyShort";
|
|
2
|
+
import { format } from "date-fns";
|
|
3
|
+
import React, { forwardRef } from "react";
|
|
4
|
+
import { PeriodContext } from "./hooks/usePeriodContext";
|
|
5
|
+
import { useRowContext } from "./hooks/useRowContext";
|
|
6
|
+
import { useTimelineContext } from "./hooks/useTimelineContext";
|
|
7
|
+
import Period from "./period";
|
|
8
|
+
import {
|
|
9
|
+
PositionedPeriod,
|
|
10
|
+
TimelineComponentTypes,
|
|
11
|
+
} from "./utils/types.internal";
|
|
12
|
+
import cl from "clsx";
|
|
13
|
+
|
|
14
|
+
export interface TimelineRowProps
|
|
15
|
+
extends React.HTMLAttributes<HTMLOListElement> {
|
|
16
|
+
/**
|
|
17
|
+
* Label for the timeline row
|
|
18
|
+
*/
|
|
19
|
+
label: string;
|
|
20
|
+
/**
|
|
21
|
+
* Heading level for the label e.g h2, h3...
|
|
22
|
+
* @default "h3"
|
|
23
|
+
*/
|
|
24
|
+
headingTag?: "h2" | "h3" | "h4" | "h5" | "h6";
|
|
25
|
+
/**
|
|
26
|
+
* Icon next to label
|
|
27
|
+
*/
|
|
28
|
+
icon?: React.ReactNode;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface TimelineRowType
|
|
32
|
+
extends React.ForwardRefExoticComponent<
|
|
33
|
+
TimelineRowProps & React.RefAttributes<HTMLOListElement>
|
|
34
|
+
> {
|
|
35
|
+
componentType: TimelineComponentTypes;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const TimelineRow = forwardRef<HTMLOListElement, TimelineRowProps>(
|
|
39
|
+
({ label, className, headingTag = "h3", icon, ...rest }, ref) => {
|
|
40
|
+
const { periods, id, active } = useRowContext();
|
|
41
|
+
const { setActiveRow } = useTimelineContext();
|
|
42
|
+
|
|
43
|
+
const latest = periods.reduce((a, b) => {
|
|
44
|
+
return a.end > b.end ? a : b;
|
|
45
|
+
}, {} as PositionedPeriod);
|
|
46
|
+
|
|
47
|
+
const earliest = periods.reduce((a, b) => {
|
|
48
|
+
return a.end < b.end ? a : b;
|
|
49
|
+
}, {} as PositionedPeriod);
|
|
50
|
+
|
|
51
|
+
const firstFocusable = periods.find(
|
|
52
|
+
(p) => !!p.children || !!p.onSelectPeriod
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<>
|
|
57
|
+
{label && (
|
|
58
|
+
<BodyShort
|
|
59
|
+
as={headingTag}
|
|
60
|
+
id={`timeline-row-${id}`}
|
|
61
|
+
className="navds-timeline__row-label"
|
|
62
|
+
size="small"
|
|
63
|
+
>
|
|
64
|
+
{icon}
|
|
65
|
+
{label}
|
|
66
|
+
</BodyShort>
|
|
67
|
+
)}
|
|
68
|
+
<div
|
|
69
|
+
className={cl("navds-timeline__row", {
|
|
70
|
+
"navds-timeline__row--active": active,
|
|
71
|
+
})}
|
|
72
|
+
>
|
|
73
|
+
<ol
|
|
74
|
+
{...rest}
|
|
75
|
+
ref={ref}
|
|
76
|
+
aria-label={
|
|
77
|
+
periods.length === 0
|
|
78
|
+
? "Ingen perioder"
|
|
79
|
+
: `${format(earliest.start, "dd.MM.yyyy")} til ${format(
|
|
80
|
+
latest.end,
|
|
81
|
+
"dd.MM.yyyy"
|
|
82
|
+
)}`
|
|
83
|
+
}
|
|
84
|
+
className={cl("navds-timeline__row-periods", className)}
|
|
85
|
+
onKeyDown={(e) => {
|
|
86
|
+
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
87
|
+
e.preventDefault();
|
|
88
|
+
setActiveRow(e.key);
|
|
89
|
+
}
|
|
90
|
+
}}
|
|
91
|
+
>
|
|
92
|
+
{periods &&
|
|
93
|
+
periods.map((period) => {
|
|
94
|
+
return (
|
|
95
|
+
<li key={`period-${period.id}`}>
|
|
96
|
+
<PeriodContext.Provider
|
|
97
|
+
value={{
|
|
98
|
+
periodId: period.id,
|
|
99
|
+
firstFocus: firstFocusable?.id === period.id,
|
|
100
|
+
restProps: period?.restProps,
|
|
101
|
+
}}
|
|
102
|
+
>
|
|
103
|
+
<Period
|
|
104
|
+
start={period.start}
|
|
105
|
+
end={period.endInclusive}
|
|
106
|
+
icon={period.icon}
|
|
107
|
+
ref={period?.ref}
|
|
108
|
+
/>
|
|
109
|
+
</PeriodContext.Provider>
|
|
110
|
+
</li>
|
|
111
|
+
);
|
|
112
|
+
})}
|
|
113
|
+
</ol>
|
|
114
|
+
</div>
|
|
115
|
+
</>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
) as TimelineRowType;
|
|
119
|
+
|
|
120
|
+
TimelineRow.componentType = "row";
|
|
121
|
+
|
|
122
|
+
export default TimelineRow;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
|
|
3
|
+
interface PeriodContextProps {
|
|
4
|
+
periodId: String;
|
|
5
|
+
firstFocus: boolean;
|
|
6
|
+
restProps?: any;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const PeriodContext = createContext<PeriodContextProps>({
|
|
10
|
+
periodId: "",
|
|
11
|
+
firstFocus: false,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export const usePeriodContext = () => {
|
|
15
|
+
const context = useContext(PeriodContext);
|
|
16
|
+
|
|
17
|
+
if (!context) {
|
|
18
|
+
console.warn("usePeriodContext must be used with PeriodContext");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return context;
|
|
22
|
+
};
|