@vygruppen/spor-react 11.3.10 → 12.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/.turbo/turbo-build.log +32 -11
- package/.turbo/turbo-typegen.log +23 -0
- package/CHANGELOG.md +239 -0
- package/dist/index.d.mts +2552 -8319
- package/dist/index.d.ts +2552 -8319
- package/dist/index.js +9609 -8608
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9487 -8455
- package/dist/index.mjs.map +1 -1
- package/package.json +21 -13
- package/src/accordion/Accordion.tsx +96 -45
- package/src/accordion/Expandable.tsx +54 -127
- package/src/accordion/helpers.ts +31 -0
- package/src/accordion/types.ts +60 -0
- package/src/alert/Alert.tsx +101 -0
- package/src/alert/AlertIcon.tsx +63 -45
- package/src/alert/ExpandableAlert.tsx +96 -64
- package/src/alert/ServiceAlert.tsx +127 -125
- package/src/alert/{index.tsx → index.ts} +1 -2
- package/src/breadcrumb/Breadcrumb.tsx +39 -24
- package/src/button/Button.tsx +86 -105
- package/src/button/ButtonGroup.tsx +45 -20
- package/src/button/Clipboard.tsx +82 -0
- package/src/button/CloseButton.tsx +4 -3
- package/src/button/FloatingActionButton.tsx +35 -41
- package/src/button/IconButton.tsx +34 -30
- package/src/button/index.tsx +1 -0
- package/src/color-mode/color-mode.tsx +75 -0
- package/src/color-mode/index.ts +1 -0
- package/src/datepicker/Calendar.tsx +17 -8
- package/src/datepicker/CalendarCell.tsx +20 -13
- package/src/datepicker/CalendarGrid.tsx +18 -10
- package/src/datepicker/CalendarHeader.tsx +2 -0
- package/src/datepicker/CalendarNavigationButton.tsx +1 -0
- package/src/datepicker/CalendarTriggerButton.tsx +43 -45
- package/src/datepicker/DateField.tsx +21 -12
- package/src/datepicker/DatePicker.tsx +61 -58
- package/src/datepicker/DateRangePicker.tsx +52 -58
- package/src/datepicker/DateTimeSegment.tsx +13 -5
- package/src/datepicker/RangeCalendar.tsx +13 -7
- package/src/datepicker/StyledField.tsx +25 -17
- package/src/datepicker/TimeField.tsx +10 -8
- package/src/datepicker/TimePicker.tsx +48 -45
- package/src/datepicker/types.ts +5 -0
- package/src/dialog/Dialog.tsx +56 -0
- package/src/dialog/Drawer.tsx +187 -0
- package/src/dialog/index.ts +2 -0
- package/src/dialog/types.ts +26 -0
- package/src/image/index.tsx +2 -2
- package/src/index.tsx +5 -3
- package/src/input/AttachedInputs.tsx +17 -42
- package/src/input/CardSelect.tsx +75 -162
- package/src/input/Checkbox.tsx +30 -6
- package/src/input/CheckboxGroup.tsx +25 -16
- package/src/input/ChoiceChip.tsx +58 -77
- package/src/input/Combobox.tsx +172 -172
- package/src/input/CountryCodeSelect.tsx +42 -28
- package/src/input/Dialog.tsx +1 -0
- package/src/input/Field.tsx +71 -0
- package/src/input/Fieldset.tsx +7 -0
- package/src/input/Input.tsx +68 -73
- package/src/input/InputGroup.tsx +66 -0
- package/src/input/ListBox.tsx +83 -70
- package/src/input/NativeSelect.tsx +68 -33
- package/src/input/NumericStepper.tsx +173 -171
- package/src/input/PasswordInput.tsx +99 -52
- package/src/input/PhoneNumberInput.tsx +69 -72
- package/src/input/Popover.tsx +1 -0
- package/src/input/Radio.tsx +37 -17
- package/src/input/SearchInput.tsx +24 -86
- package/src/input/Select.tsx +237 -0
- package/src/input/Switch.tsx +60 -18
- package/src/input/Textarea.tsx +53 -101
- package/src/input/{index.tsx → index.ts} +2 -8
- package/src/layout/PressableCard.tsx +12 -21
- package/src/layout/RadioCard.tsx +68 -101
- package/src/layout/Separator.tsx +32 -0
- package/src/layout/StaticCard.tsx +13 -33
- package/src/layout/index.tsx +3 -7
- package/src/linjetag/InfoTag.tsx +16 -9
- package/src/linjetag/LineIcon.tsx +74 -28
- package/src/linjetag/TravelTag.tsx +38 -27
- package/src/link/TextLink.tsx +25 -16
- package/src/list/index.tsx +24 -2
- package/src/loader/ClientOnly.tsx +8 -7
- package/src/loader/ColorInlineLoader.tsx +4 -3
- package/src/loader/ColorSpinner.tsx +5 -4
- package/src/loader/ContentLoader.tsx +6 -4
- package/src/loader/DarkFullScreenLoader.tsx +11 -3
- package/src/loader/DarkInlineLoader.tsx +5 -3
- package/src/loader/DarkSpinner.tsx +7 -3
- package/src/loader/LightFullScreenLoader.tsx +11 -3
- package/src/loader/LightInlineLoader.tsx +11 -3
- package/src/loader/LightSpinner.tsx +5 -3
- package/src/loader/Lottie.tsx +3 -3
- package/src/loader/ProgressBar.tsx +83 -84
- package/src/loader/ProgressLoader.tsx +120 -75
- package/src/loader/Skeleton.tsx +94 -19
- package/src/loader/index.tsx +0 -2
- package/src/loader/useHydrated.tsx +1 -0
- package/src/loader/useRotatingLabel.tsx +2 -1
- package/src/logo/CargonetLogo.tsx +89 -89
- package/src/logo/VyLogo.tsx +61 -42
- package/src/logo/VyLogoPride.tsx +137 -139
- package/src/media-controller/JumpButton.tsx +48 -38
- package/src/media-controller/PlayPauseButton.tsx +31 -29
- package/src/media-controller/SkipButton.tsx +38 -37
- package/src/nudge/Nudge.tsx +195 -123
- package/src/nudge/index.tsx +0 -1
- package/src/pagination/Pagination.tsx +221 -118
- package/src/pagination/types.ts +23 -0
- package/src/popover/index.tsx +67 -0
- package/src/progress-indicator/ProgressDot.tsx +11 -10
- package/src/progress-indicator/ProgressIndicator.tsx +28 -15
- package/src/provider/SporProvider.tsx +17 -14
- package/src/stepper/Stepper.tsx +88 -85
- package/src/stepper/StepperContext.tsx +2 -1
- package/src/stepper/StepperStep.tsx +28 -21
- package/src/tab/Tabs.tsx +62 -12
- package/src/tab/index.tsx +1 -9
- package/src/table/Table.tsx +35 -30
- package/src/table/index.tsx +11 -7
- package/src/theme/brand.ts +7 -0
- package/src/theme/index.ts +45 -37
- package/src/theme/recipes/attached-inputs.ts +43 -0
- package/src/theme/recipes/badge.ts +104 -0
- package/src/theme/recipes/button.ts +124 -0
- package/src/theme/recipes/choice-chip.ts +144 -0
- package/src/theme/recipes/close-button.ts +41 -0
- package/src/theme/recipes/code.ts +14 -0
- package/src/theme/recipes/group.ts +19 -0
- package/src/theme/recipes/index.ts +29 -0
- package/src/theme/recipes/input.ts +89 -0
- package/src/theme/recipes/link.ts +64 -0
- package/src/theme/recipes/nudge.ts +12 -0
- package/src/theme/recipes/pressable-card.ts +83 -0
- package/src/theme/recipes/progress-loader.ts +14 -0
- package/src/theme/recipes/separator.ts +85 -0
- package/src/theme/recipes/skeleton.ts +57 -0
- package/src/theme/recipes/static-card.ts +39 -0
- package/src/theme/recipes/textarea.ts +27 -0
- package/src/theme/semantic-tokens/colors.ts +22 -0
- package/src/theme/semantic-tokens/index.ts +24 -0
- package/src/theme/semantic-tokens/radii.ts +14 -0
- package/src/theme/semantic-tokens/shadows.ts +17 -0
- package/src/theme/slot-recipes/accordion.ts +131 -0
- package/src/theme/slot-recipes/alert-expandable.ts +133 -0
- package/src/theme/slot-recipes/alert-service.ts +66 -0
- package/src/theme/slot-recipes/alert.ts +72 -0
- package/src/theme/slot-recipes/anatomy.ts +269 -0
- package/src/theme/slot-recipes/breadcrumb.ts +61 -0
- package/src/theme/slot-recipes/checkbox.ts +89 -0
- package/src/theme/slot-recipes/datepicker.ts +214 -0
- package/src/theme/slot-recipes/dialog.ts +221 -0
- package/src/theme/slot-recipes/drawer.ts +205 -0
- package/src/theme/slot-recipes/field.ts +79 -0
- package/src/theme/slot-recipes/floating-action-button.ts +131 -0
- package/src/theme/slot-recipes/index.ts +65 -0
- package/src/theme/slot-recipes/info-tag.ts +62 -0
- package/src/theme/slot-recipes/line-icon.ts +140 -0
- package/src/theme/slot-recipes/list.ts +45 -0
- package/src/theme/slot-recipes/listbox.ts +72 -0
- package/src/theme/slot-recipes/media-controller-button.ts +131 -0
- package/src/theme/slot-recipes/native-select.ts +54 -0
- package/src/theme/slot-recipes/numeric-stepper.ts +65 -0
- package/src/theme/slot-recipes/pagination.ts +41 -0
- package/src/theme/slot-recipes/popover.ts +78 -0
- package/src/theme/slot-recipes/progress-bar.ts +39 -0
- package/src/theme/slot-recipes/progress-indicator.ts +22 -0
- package/src/theme/slot-recipes/radio-card.ts +112 -0
- package/src/theme/slot-recipes/radio.ts +80 -0
- package/src/theme/slot-recipes/select.ts +243 -0
- package/src/theme/slot-recipes/stepper.ts +92 -0
- package/src/theme/slot-recipes/switch.ts +147 -0
- package/src/theme/slot-recipes/table.ts +200 -0
- package/src/theme/slot-recipes/tabs.ts +169 -0
- package/src/theme/slot-recipes/toast.ts +56 -0
- package/src/theme/slot-recipes/travel-tag.ts +192 -0
- package/src/theme/tokens/animation-styles.ts +50 -0
- package/src/theme/tokens/animations.ts +22 -0
- package/src/theme/tokens/aspect-ratios.ts +22 -0
- package/src/theme/tokens/blurs.ts +28 -0
- package/src/theme/tokens/borders.ts +26 -0
- package/src/theme/{foundations → tokens}/breakpoints.ts +0 -1
- package/src/theme/tokens/colors.ts +10 -0
- package/src/theme/tokens/config.ts +10 -0
- package/src/theme/tokens/cursor.ts +28 -0
- package/src/theme/tokens/durations.ts +25 -0
- package/src/theme/tokens/easings.ts +16 -0
- package/src/theme/tokens/font-sizes.ts +30 -0
- package/src/theme/tokens/font-weights.ts +31 -0
- package/src/theme/tokens/fonts.ts +8 -0
- package/src/theme/tokens/global-css.ts +18 -0
- package/src/theme/tokens/index.ts +37 -0
- package/src/theme/tokens/keyframes.ts +255 -0
- package/src/theme/tokens/letter-spacings.ts +19 -0
- package/src/theme/tokens/line-heights.ts +19 -0
- package/src/theme/tokens/radii.ts +13 -0
- package/src/theme/tokens/sizes.ts +51 -0
- package/src/theme/tokens/spacing.ts +20 -0
- package/src/theme/tokens/text-styles.ts +89 -0
- package/src/theme/tokens/z-index.ts +17 -0
- package/src/theme/utils/accent-utils.ts +8 -21
- package/src/theme/utils/bg-utils.ts +4 -6
- package/src/theme/utils/brand-utils.ts +6 -19
- package/src/theme/utils/core-utils.ts +91 -0
- package/src/theme/utils/floating-utils.ts +20 -39
- package/src/theme/utils/ghost-utils.ts +7 -21
- package/src/theme/utils/input-utils.ts +32 -37
- package/src/theme/utils/outline-utils.ts +4 -11
- package/src/theme/utils/surface-utils.ts +5 -19
- package/src/theme/utils/types.ts +1 -0
- package/src/toast/index.tsx +1 -1
- package/src/toast/toast.tsx +105 -0
- package/src/transition/index.ts +2 -8
- package/src/typography/Badge.tsx +15 -61
- package/src/typography/Code.tsx +16 -28
- package/src/typography/Heading.tsx +34 -19
- package/src/typography/Text.tsx +9 -6
- package/src/typography/{index.tsx → index.ts} +1 -0
- package/src/util/externals.tsx +13 -27
- package/tsconfig.json +5 -1
- package/src/accordion/Accordion.test.tsx +0 -20
- package/src/alert/BaseAlert.test.tsx +0 -37
- package/src/alert/BaseAlert.tsx +0 -34
- package/src/alert/ClosableAlert.test.tsx +0 -37
- package/src/alert/ClosableAlert.tsx +0 -85
- package/src/alert/ExpandableAlert.test.tsx +0 -84
- package/src/alert/StaticAlert.tsx +0 -33
- package/src/button/Button.test.tsx +0 -23
- package/src/datepicker/TimePicker.test.tsx +0 -74
- package/src/input/FormControl.tsx +0 -2
- package/src/input/FormErrorMessage.tsx +0 -95
- package/src/input/FormLabel.tsx +0 -11
- package/src/input/InfoSelect.tsx +0 -274
- package/src/input/InputElement.tsx +0 -44
- package/src/input/RadioGroup.tsx +0 -47
- package/src/layout/Divider.tsx +0 -27
- package/src/layout/RadioCardGroup.tsx +0 -79
- package/src/layout/Stack.tsx +0 -42
- package/src/loader/SkeletonCircle.tsx +0 -13
- package/src/loader/SkeletonText.tsx +0 -14
- package/src/media-controller/index.test.tsx +0 -59
- package/src/modal/Drawer.tsx +0 -120
- package/src/modal/FullScreenDrawer.tsx +0 -239
- package/src/modal/Modal.tsx +0 -15
- package/src/modal/ModalHeader.tsx +0 -31
- package/src/modal/SimpleDrawer.tsx +0 -51
- package/src/modal/index.tsx +0 -5
- package/src/nudge/WizardNudge.tsx +0 -107
- package/src/theme/components/accordion.ts +0 -102
- package/src/theme/components/alert-expandable.ts +0 -125
- package/src/theme/components/alert-service.ts +0 -98
- package/src/theme/components/alert.ts +0 -71
- package/src/theme/components/badge.ts +0 -109
- package/src/theme/components/breadcrumb.ts +0 -60
- package/src/theme/components/button.ts +0 -125
- package/src/theme/components/card-select.ts +0 -117
- package/src/theme/components/checkbox.ts +0 -88
- package/src/theme/components/choice-chip.ts +0 -161
- package/src/theme/components/close-button.ts +0 -48
- package/src/theme/components/code.ts +0 -17
- package/src/theme/components/datepicker.ts +0 -198
- package/src/theme/components/divider.ts +0 -50
- package/src/theme/components/drawer.ts +0 -95
- package/src/theme/components/fab.ts +0 -109
- package/src/theme/components/form-label.ts +0 -17
- package/src/theme/components/form.ts +0 -27
- package/src/theme/components/index.ts +0 -45
- package/src/theme/components/info-select.ts +0 -85
- package/src/theme/components/info-tag.ts +0 -63
- package/src/theme/components/input.ts +0 -28
- package/src/theme/components/line-icon.ts +0 -129
- package/src/theme/components/link.ts +0 -78
- package/src/theme/components/list.ts +0 -23
- package/src/theme/components/listbox.ts +0 -77
- package/src/theme/components/media-controller-button.ts +0 -97
- package/src/theme/components/modal.ts +0 -96
- package/src/theme/components/numeric-stepper.ts +0 -65
- package/src/theme/components/pagination.ts +0 -74
- package/src/theme/components/popover.ts +0 -68
- package/src/theme/components/pressable-card.ts +0 -72
- package/src/theme/components/progress-bar.ts +0 -47
- package/src/theme/components/progress-indicator.ts +0 -44
- package/src/theme/components/radio-card.ts +0 -134
- package/src/theme/components/radio.ts +0 -68
- package/src/theme/components/select.ts +0 -74
- package/src/theme/components/skeleton.ts +0 -40
- package/src/theme/components/static-card.ts +0 -82
- package/src/theme/components/stepper.ts +0 -100
- package/src/theme/components/switch.ts +0 -112
- package/src/theme/components/table.ts +0 -161
- package/src/theme/components/tabs.ts +0 -135
- package/src/theme/components/textarea.ts +0 -33
- package/src/theme/components/toast.ts +0 -28
- package/src/theme/components/travel-tag.ts +0 -256
- package/src/theme/foundations/borders.ts +0 -11
- package/src/theme/foundations/colors.ts +0 -12
- package/src/theme/foundations/config.ts +0 -5
- package/src/theme/foundations/fontSizes.ts +0 -29
- package/src/theme/foundations/fontWeights.ts +0 -5
- package/src/theme/foundations/fonts.ts +0 -7
- package/src/theme/foundations/index.ts +0 -15
- package/src/theme/foundations/lineHeights.ts +0 -6
- package/src/theme/foundations/radii.ts +0 -12
- package/src/theme/foundations/shadows.ts +0 -8
- package/src/theme/foundations/sizes.ts +0 -36
- package/src/theme/foundations/spacing.ts +0 -31
- package/src/theme/foundations/styles.ts +0 -12
- package/src/theme/foundations/textStyles.ts +0 -74
- package/src/theme/foundations/zIndices.ts +0 -17
- package/src/theme/utils/base-utils.ts +0 -104
- package/src/theme/utils/focus-utils.ts +0 -10
- package/src/toast/ActionToast.test.tsx +0 -22
- package/src/toast/ActionToast.tsx +0 -28
- package/src/toast/BaseToast.test.tsx +0 -27
- package/src/toast/BaseToast.tsx +0 -75
- package/src/toast/ClosableToast.test.tsx +0 -17
- package/src/toast/ClosableToast.tsx +0 -40
- package/src/toast/useToast.tsx +0 -121
- package/src/tooltip/Tooltip.tsx +0 -70
- package/src/tooltip/index.tsx +0 -1
package/src/alert/AlertIcon.tsx
CHANGED
@@ -1,47 +1,59 @@
|
|
1
|
+
"use client";
|
2
|
+
|
1
3
|
import {
|
2
|
-
|
4
|
+
AltTransportFill24Icon,
|
5
|
+
ErrorFill24Icon,
|
3
6
|
ErrorOutline24Icon,
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
WarningFill24Icon,
|
7
|
+
IconComponent,
|
8
|
+
InformationFill24Icon,
|
9
|
+
QuestionFill24Icon,
|
8
10
|
ServiceFill24Icon,
|
11
|
+
SuccessFill24Icon,
|
12
|
+
WarningFill24Icon,
|
9
13
|
} from "@vygruppen/spor-icon-react";
|
10
|
-
import React from "react";
|
14
|
+
import React, { PropsWithChildren } from "react";
|
11
15
|
import { createTexts, useTranslation } from "../i18n";
|
12
|
-
import {
|
16
|
+
import { AlertProps } from "./Alert";
|
17
|
+
import { Box, useSlotRecipe, Alert as ChakraAlert } from "@chakra-ui/react";
|
18
|
+
|
19
|
+
type AlertIconProps = {
|
20
|
+
variant: ChakraAlert.RootProps["variant"];
|
21
|
+
customIcon?: IconComponent;
|
22
|
+
};
|
13
23
|
|
14
|
-
type AlertIconProps = { variant: BaseAlertProps["variant"] };
|
15
24
|
/**
|
16
25
|
* Internal component that shows the correct icon for the alert
|
17
26
|
*/
|
18
|
-
export const AlertIcon = ({ variant }: AlertIconProps) => {
|
19
|
-
const Icon = getIcon(variant);
|
27
|
+
export const AlertIcon = ({ variant, customIcon }: AlertIconProps) => {
|
20
28
|
const { t } = useTranslation();
|
29
|
+
|
30
|
+
const icon = customIcon ?? getIcon(variant);
|
31
|
+
|
21
32
|
return (
|
22
|
-
<
|
23
|
-
|
24
|
-
aria-label={t(texts[variant])}
|
25
|
-
|
26
|
-
color="darkGrey"
|
33
|
+
<Box
|
34
|
+
as={icon}
|
35
|
+
aria-label={t(texts[variant as keyof typeof texts])}
|
36
|
+
color={customIcon ? `alert.${variant}.icon` : undefined}
|
27
37
|
/>
|
28
38
|
);
|
29
39
|
};
|
30
40
|
|
31
|
-
const getIcon = (variant:
|
41
|
+
const getIcon = (variant: AlertProps["variant"]) => {
|
32
42
|
switch (variant) {
|
33
43
|
case "info":
|
34
|
-
return
|
44
|
+
return InformationFill24Icon;
|
35
45
|
case "success":
|
36
|
-
return
|
37
|
-
case "
|
38
|
-
return
|
39
|
-
case "alt
|
40
|
-
return
|
46
|
+
return SuccessFill24Icon;
|
47
|
+
case "important":
|
48
|
+
return WarningFill24Icon;
|
49
|
+
case "alt":
|
50
|
+
return AltTransportFill24Icon;
|
41
51
|
case "error":
|
52
|
+
return ErrorFill24Icon;
|
53
|
+
case "error-secondary":
|
42
54
|
return ErrorOutline24Icon;
|
43
|
-
case "
|
44
|
-
return
|
55
|
+
case "neutral":
|
56
|
+
return QuestionFill24Icon;
|
45
57
|
case "service":
|
46
58
|
return ServiceFill24Icon;
|
47
59
|
}
|
@@ -60,34 +72,40 @@ const texts = createTexts({
|
|
60
72
|
sv: "Succé",
|
61
73
|
en: "Success",
|
62
74
|
},
|
63
|
-
|
64
|
-
nb: "
|
65
|
-
nn: "
|
66
|
-
sv: "
|
67
|
-
en: "
|
75
|
+
important: {
|
76
|
+
nb: "Viktig",
|
77
|
+
nn: "Viktig",
|
78
|
+
sv: "Viktig",
|
79
|
+
en: "Important",
|
80
|
+
},
|
81
|
+
alt: {
|
82
|
+
nb: "Alternativ",
|
83
|
+
nn: "Alternativ",
|
84
|
+
sv: "Alternativ",
|
85
|
+
en: "Alternative",
|
68
86
|
},
|
69
87
|
error: {
|
70
88
|
nb: "Feil",
|
71
89
|
nn: "Feil",
|
72
|
-
sv: "
|
90
|
+
sv: "Fel",
|
73
91
|
en: "Error",
|
74
92
|
},
|
75
|
-
"
|
76
|
-
nb: "
|
77
|
-
nn: "
|
78
|
-
sv: "
|
79
|
-
en: "
|
93
|
+
"error-secondary": {
|
94
|
+
nb: "Feil",
|
95
|
+
nn: "Feil",
|
96
|
+
sv: "Fel",
|
97
|
+
en: "Error",
|
80
98
|
},
|
81
|
-
|
82
|
-
nb: "
|
83
|
-
nn: "
|
84
|
-
sv: "
|
85
|
-
en: "
|
99
|
+
neutral: {
|
100
|
+
nb: "Nøytral",
|
101
|
+
nn: "Nøytral",
|
102
|
+
sv: "Neutral",
|
103
|
+
en: "Neutral",
|
86
104
|
},
|
87
|
-
|
88
|
-
nb: "
|
89
|
-
nn: "
|
90
|
-
sv: "
|
91
|
-
en: "
|
105
|
+
service: {
|
106
|
+
nb: "Service",
|
107
|
+
nn: "Service",
|
108
|
+
sv: "Service",
|
109
|
+
en: "Service",
|
92
110
|
},
|
93
111
|
});
|
@@ -1,30 +1,52 @@
|
|
1
|
+
"use client";
|
2
|
+
|
1
3
|
import {
|
2
4
|
Accordion,
|
3
|
-
AccordionButton,
|
4
|
-
AccordionIcon,
|
5
|
-
AccordionItem,
|
6
|
-
AccordionPanel,
|
7
5
|
Box,
|
8
|
-
|
9
|
-
|
6
|
+
ConditionalValue,
|
7
|
+
HStack,
|
8
|
+
RecipeVariantProps,
|
9
|
+
Span,
|
10
|
+
useSlotRecipe,
|
10
11
|
} from "@chakra-ui/react";
|
11
|
-
import React from "react";
|
12
|
+
import React, { forwardRef, PropsWithChildren } from "react";
|
12
13
|
import { AlertIcon } from "./AlertIcon";
|
13
|
-
import {
|
14
|
+
import { AlertProps } from "./Alert";
|
15
|
+
import { alertExpandableSlotRecipe } from "@/theme/slot-recipes/alert-expandable";
|
16
|
+
import { DropdownDownFill18Icon } from "@vygruppen/spor-icon-react";
|
17
|
+
import { AccordionItemContent } from "@/accordion";
|
18
|
+
|
19
|
+
type ExpandableAlertVariantProps = RecipeVariantProps<
|
20
|
+
typeof alertExpandableSlotRecipe
|
21
|
+
>;
|
14
22
|
|
15
|
-
type ExpandableAlertProps =
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
type ExpandableAlertProps = PropsWithChildren<ExpandableAlertVariantProps> &
|
24
|
+
Omit<Accordion.RootProps, "variant" | "orientation" | "size" | "value"> & {
|
25
|
+
/** The title string */
|
26
|
+
title: string;
|
27
|
+
/** Whether or not the default state of the expandable alert is open */
|
28
|
+
defaultOpen?: boolean;
|
29
|
+
/**
|
30
|
+
* The HTML element used for the `title` prop.
|
31
|
+
*
|
32
|
+
* Defaults to h3 */
|
33
|
+
headingLevel?: "h2" | "h3" | "h4" | "h5" | "h6";
|
34
|
+
/** If the user should be able to close the Accordion. Defaults to true */
|
35
|
+
collapsible?: boolean;
|
36
|
+
/**
|
37
|
+
* The variant of the alert. Default: info
|
38
|
+
* "info"
|
39
|
+
| "success"
|
40
|
+
| "important"
|
41
|
+
| "alt-transport"
|
42
|
+
| "error"
|
43
|
+
| "service"
|
44
|
+
| "global-deviation";
|
45
|
+
*/
|
46
|
+
variant?: ConditionalValue<
|
47
|
+
"important" | "success" | "alt" | "info" | "error" | undefined
|
48
|
+
>;
|
49
|
+
};
|
28
50
|
/**
|
29
51
|
* An expandable alert component.
|
30
52
|
*
|
@@ -36,58 +58,68 @@ type ExpandableAlertProps = BaseAlertProps & {
|
|
36
58
|
* </ExpandableAlert>
|
37
59
|
* ```
|
38
60
|
*/
|
39
|
-
export const ExpandableAlert = (
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
61
|
+
export const ExpandableAlert = forwardRef<HTMLDivElement, ExpandableAlertProps>(
|
62
|
+
(props, ref) => {
|
63
|
+
const {
|
64
|
+
variant = "info",
|
65
|
+
children,
|
66
|
+
title,
|
67
|
+
collapsible = true,
|
68
|
+
headingLevel = "h3",
|
69
|
+
defaultOpen = false,
|
70
|
+
css,
|
71
|
+
...rest
|
72
|
+
} = props;
|
73
|
+
const recipe = useSlotRecipe({ key: "alertExpandable" });
|
74
|
+
const styles = recipe({ variant });
|
75
|
+
|
76
|
+
const defaultValue = "alert-expandable";
|
77
|
+
|
78
|
+
return (
|
79
|
+
<Accordion.Root
|
80
|
+
defaultValue={defaultOpen ? [defaultValue] : undefined}
|
81
|
+
ref={ref}
|
82
|
+
css={{ ...styles.root, ...css }}
|
83
|
+
collapsible={collapsible}
|
84
|
+
{...rest}
|
56
85
|
>
|
57
|
-
<
|
58
|
-
<
|
59
|
-
<
|
60
|
-
|
86
|
+
<Accordion.Item value={defaultValue}>
|
87
|
+
<Accordion.ItemTrigger css={styles.itemTrigger}>
|
88
|
+
<HStack
|
89
|
+
gap="1"
|
61
90
|
alignItems="center"
|
62
|
-
|
91
|
+
justifyContent="space-between"
|
92
|
+
flex="1"
|
93
|
+
width="full"
|
63
94
|
>
|
64
|
-
<
|
65
|
-
<
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
95
|
+
<HStack gap="1" alignItems="center">
|
96
|
+
<Box css={styles.indicator}>
|
97
|
+
<AlertIcon variant={variant} />
|
98
|
+
</Box>
|
99
|
+
<Span
|
100
|
+
as={headingLevel}
|
101
|
+
css={{
|
70
102
|
// Truncate the title to one line
|
71
103
|
display: "-webkit-box",
|
72
104
|
overflow: "hidden",
|
73
105
|
WebkitLineClamp: "1",
|
74
106
|
WebkitBoxOrient: "vertical",
|
75
107
|
}}
|
76
|
-
color={variant === "service" ? "white" : "darkGrey"}
|
77
108
|
>
|
78
109
|
{title}
|
79
|
-
</
|
80
|
-
</
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
110
|
+
</Span>
|
111
|
+
</HStack>
|
112
|
+
|
113
|
+
<Accordion.ItemIndicator>
|
114
|
+
<DropdownDownFill18Icon />
|
115
|
+
</Accordion.ItemIndicator>
|
116
|
+
</HStack>
|
117
|
+
</Accordion.ItemTrigger>
|
118
|
+
<AccordionItemContent css={styles.itemContent}>
|
87
119
|
{children}
|
88
|
-
</
|
89
|
-
</
|
90
|
-
</Accordion>
|
91
|
-
|
92
|
-
|
93
|
-
|
120
|
+
</AccordionItemContent>
|
121
|
+
</Accordion.Item>
|
122
|
+
</Accordion.Root>
|
123
|
+
);
|
124
|
+
},
|
125
|
+
);
|
@@ -1,41 +1,50 @@
|
|
1
|
+
"use client";
|
2
|
+
|
1
3
|
import {
|
2
4
|
Accordion,
|
3
|
-
AccordionButton,
|
4
|
-
AccordionIcon,
|
5
|
-
AccordionItem,
|
6
|
-
AccordionPanel,
|
7
|
-
Box,
|
8
5
|
Flex,
|
6
|
+
HStack,
|
7
|
+
RecipeVariantProps,
|
8
|
+
Span,
|
9
9
|
Stack,
|
10
10
|
Text,
|
11
|
-
|
11
|
+
useSlotRecipe,
|
12
12
|
} from "@chakra-ui/react";
|
13
|
-
import React from "react";
|
13
|
+
import React, { forwardRef, PropsWithChildren } from "react";
|
14
|
+
import { AlertProps } from "./Alert";
|
14
15
|
import { createTexts, useTranslation } from "../i18n";
|
15
|
-
import {
|
16
|
-
import {
|
16
|
+
import { alertServiceSlotRecipe } from "../theme/slot-recipes/alert-service";
|
17
|
+
import {
|
18
|
+
DropdownDownFill24Icon,
|
19
|
+
ServiceFill24Icon,
|
20
|
+
WarningFill24Icon,
|
21
|
+
} from "@vygruppen/spor-icon-react";
|
17
22
|
|
18
|
-
type
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
23
|
+
type ServiceAlertVariantProps = RecipeVariantProps<
|
24
|
+
typeof alertServiceSlotRecipe
|
25
|
+
>;
|
26
|
+
|
27
|
+
type ServiceAlertProps = Omit<AlertProps, "variant"> &
|
28
|
+
PropsWithChildren<ServiceAlertVariantProps> &
|
29
|
+
Omit<Accordion.RootProps, "variant" | "orientation" | "size" | "value"> & {
|
30
|
+
/** The title string */
|
31
|
+
title: string;
|
32
|
+
/** The number of notifications when there is a list of multiple alerts */
|
33
|
+
notification: number;
|
34
|
+
/** The maximum width to display the service message
|
35
|
+
*
|
36
|
+
* Defaults to container.md */
|
37
|
+
contentWidth: string;
|
38
|
+
/** Whether or not the default state of the alert is open */
|
39
|
+
defaultOpen?: boolean;
|
40
|
+
/**
|
41
|
+
* The HTML element used for the `title` prop.
|
42
|
+
*
|
43
|
+
* Defaults to h3 */
|
44
|
+
headingLevel?: "h2" | "h3" | "h4" | "h5" | "h6";
|
45
|
+
/** The variant of Service Alert. Default: service */
|
46
|
+
variant?: "service" | "global-deviation";
|
47
|
+
};
|
39
48
|
/**
|
40
49
|
* A service alert component.
|
41
50
|
*
|
@@ -47,111 +56,92 @@ type ServiceAlertProps = BaseAlertProps & {
|
|
47
56
|
* </ServiceAlert>
|
48
57
|
* ```
|
49
58
|
*/
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
<Accordion
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
variant={variant}
|
59
|
+
|
60
|
+
export const ServiceAlert = forwardRef<HTMLDivElement, ServiceAlertProps>(
|
61
|
+
(props, ref) => {
|
62
|
+
const {
|
63
|
+
variant = "service",
|
64
|
+
children,
|
65
|
+
title,
|
66
|
+
notification,
|
67
|
+
contentWidth = "container.md",
|
68
|
+
headingLevel = "h3",
|
69
|
+
defaultOpen = false,
|
70
|
+
collapsible = true,
|
71
|
+
css,
|
72
|
+
...rest
|
73
|
+
} = props;
|
74
|
+
const { t } = useTranslation();
|
75
|
+
const recipe = useSlotRecipe({ key: "alertService" });
|
76
|
+
const styles = recipe({ variant });
|
77
|
+
|
78
|
+
const defaultValue = "spor-service-alert";
|
79
|
+
return (
|
80
|
+
<Accordion.Root
|
81
|
+
defaultValue={defaultOpen ? [defaultValue] : undefined}
|
82
|
+
collapsible={collapsible}
|
83
|
+
css={{ ...styles.root, ...css }}
|
84
|
+
ref={ref}
|
85
|
+
{...rest}
|
78
86
|
>
|
79
|
-
<
|
80
|
-
<
|
81
|
-
<
|
82
|
-
|
83
|
-
|
87
|
+
<Accordion.Item value={defaultValue}>
|
88
|
+
<Accordion.ItemTrigger css={styles.itemTrigger}>
|
89
|
+
<HStack
|
90
|
+
justifyContent="space-between"
|
91
|
+
alignContent="center"
|
84
92
|
width="100%"
|
85
|
-
|
93
|
+
maxWidth={contentWidth}
|
86
94
|
>
|
87
|
-
<
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
<AccordionIcon />
|
118
|
-
</Flex>
|
95
|
+
<HStack as={headingLevel} alignItems="center" gap="1">
|
96
|
+
{variant === "service" ? (
|
97
|
+
<ServiceFill24Icon aria-label={t(texts.service)} />
|
98
|
+
) : (
|
99
|
+
<WarningFill24Icon
|
100
|
+
aria-label={t(texts["global-deviation"])}
|
101
|
+
/>
|
102
|
+
)}
|
103
|
+
<Span
|
104
|
+
css={{
|
105
|
+
// Truncate the title to one line
|
106
|
+
display: "-webkit-box",
|
107
|
+
overflow: "hidden",
|
108
|
+
WebkitLineClamp: "1",
|
109
|
+
WebkitBoxOrient: "vertical",
|
110
|
+
...styles.itemTriggerTitle,
|
111
|
+
}}
|
112
|
+
>
|
113
|
+
{title}
|
114
|
+
</Span>
|
115
|
+
</HStack>
|
116
|
+
<Flex alignItems="center" gap={[0.5, null, null, 1]}>
|
117
|
+
{notification && (
|
118
|
+
<Text css={styles.notificationText}>
|
119
|
+
{t(texts.notification(notification))}
|
120
|
+
</Text>
|
121
|
+
)}
|
122
|
+
<Accordion.ItemIndicator>
|
123
|
+
<DropdownDownFill24Icon color="icon.inverted" />
|
124
|
+
</Accordion.ItemIndicator>
|
119
125
|
</Flex>
|
120
|
-
</
|
121
|
-
</
|
126
|
+
</HStack>
|
127
|
+
</Accordion.ItemTrigger>
|
122
128
|
|
123
|
-
<
|
129
|
+
<Accordion.ItemContent asChild>
|
124
130
|
<Stack flexDirection="row" justifyContent="center" width="100%">
|
125
|
-
<
|
126
|
-
|
127
|
-
alignItems="center"
|
128
|
-
flexGrow={1}
|
131
|
+
<Accordion.ItemBody
|
132
|
+
as={Stack}
|
129
133
|
maxWidth={contentWidth}
|
130
|
-
|
131
|
-
gap={2}
|
132
|
-
sx={{
|
133
|
-
p: {
|
134
|
-
padding: "0.8rem 0",
|
135
|
-
borderBottom: "0.08rem solid",
|
136
|
-
borderColor:
|
137
|
-
variant === "global-deviation"
|
138
|
-
? "blackAlpha.400"
|
139
|
-
: "whiteAlpha.400",
|
140
|
-
},
|
141
|
-
"p:last-child": {
|
142
|
-
borderBottom: "none",
|
143
|
-
},
|
144
|
-
}}
|
134
|
+
css={styles.itemBody}
|
145
135
|
>
|
146
136
|
{children}
|
147
|
-
</
|
137
|
+
</Accordion.ItemBody>
|
148
138
|
</Stack>
|
149
|
-
</
|
150
|
-
</
|
151
|
-
</Accordion>
|
152
|
-
|
153
|
-
|
154
|
-
|
139
|
+
</Accordion.ItemContent>
|
140
|
+
</Accordion.Item>
|
141
|
+
</Accordion.Root>
|
142
|
+
);
|
143
|
+
},
|
144
|
+
);
|
155
145
|
|
156
146
|
const texts = createTexts({
|
157
147
|
notification: (notification) => {
|
@@ -163,4 +153,16 @@ const texts = createTexts({
|
|
163
153
|
en: `${numNotification} ${numNotification > 1 ? "notifications" : "notification"}`,
|
164
154
|
};
|
165
155
|
},
|
156
|
+
service: {
|
157
|
+
nb: "Driftsmelding",
|
158
|
+
nn: "Driftsmelding",
|
159
|
+
sv: "Service meddelande",
|
160
|
+
en: "Service message",
|
161
|
+
},
|
162
|
+
"global-deviation": {
|
163
|
+
nb: "Trafikkmelding",
|
164
|
+
nn: "Trafikkmelding",
|
165
|
+
sv: "Trafikmeddelande",
|
166
|
+
en: "Traffic announcement",
|
167
|
+
},
|
166
168
|
});
|