@vygruppen/spor-react 11.3.10 → 12.0.1
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 +33 -11
- package/.turbo/turbo-typegen.log +22 -0
- package/CHANGELOG.md +247 -0
- package/dist/index.d.mts +2589 -8303
- package/dist/index.d.ts +2589 -8303
- 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 +23 -15
- 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 +70 -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 +36 -21
- 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
@@ -1,95 +0,0 @@
|
|
1
|
-
import { Box, BoxProps, useFormControlContext } from "@chakra-ui/react";
|
2
|
-
import React from "react";
|
3
|
-
|
4
|
-
export type FormErrorMessageProps = BoxProps & {
|
5
|
-
/**
|
6
|
-
* The error message itself.
|
7
|
-
*/
|
8
|
-
children: React.ReactNode;
|
9
|
-
};
|
10
|
-
/** An error message
|
11
|
-
*
|
12
|
-
* This component is used to show error messages related to a form input.
|
13
|
-
* It should _always_ be used inside of a `FormControl` component.
|
14
|
-
*
|
15
|
-
* It will only render if the `isInvalid` prop of its enclosing `FormControl` component is set to true.
|
16
|
-
*
|
17
|
-
* ```tsx
|
18
|
-
* <FormControl isInvalid={email === ""}>
|
19
|
-
* <Input label="E-mail" value={email} onChange={updateEmail} />
|
20
|
-
* <FormErrorMessage>This field is required</FormErrorMessage>
|
21
|
-
* </FormControl>
|
22
|
-
* ```
|
23
|
-
*
|
24
|
-
* If you're using a `FormHelperText` (or any other components inside of the `FormControl`), make sure to render the `FormErrorMessage` before those.
|
25
|
-
* ```tsx
|
26
|
-
* <FormControl isInvalid={email === ""}>
|
27
|
-
* <Input label="E-mail" value={email} onChange={updateEmail} />
|
28
|
-
* <FormErrorMessage>This field is required</FormErrorMessage>
|
29
|
-
* <FormHelperText>We don't share your email</FormHelperText>
|
30
|
-
* </FormControl>
|
31
|
-
* ```
|
32
|
-
*
|
33
|
-
* @see https://spor.vy.no/components/form-control
|
34
|
-
*/
|
35
|
-
export const FormErrorMessage = ({
|
36
|
-
children,
|
37
|
-
...boxProps
|
38
|
-
}: FormErrorMessageProps) => {
|
39
|
-
const formControlContext = useFormControlContext();
|
40
|
-
if (!formControlContext) {
|
41
|
-
throw new Error(
|
42
|
-
"FormErrorMessage must be used within a FormControl component",
|
43
|
-
);
|
44
|
-
}
|
45
|
-
if (!formControlContext.isInvalid) {
|
46
|
-
return null;
|
47
|
-
}
|
48
|
-
const { ref, ...errorMessageProps } =
|
49
|
-
formControlContext.getErrorMessageProps();
|
50
|
-
return (
|
51
|
-
<Box position="relative" ref={ref}>
|
52
|
-
<Box
|
53
|
-
borderRadius="xs"
|
54
|
-
backgroundColor="lightRed"
|
55
|
-
color="darkGrey"
|
56
|
-
paddingX={1.5}
|
57
|
-
paddingY={1}
|
58
|
-
textStyle="xs"
|
59
|
-
width="fit-content"
|
60
|
-
position="absolute"
|
61
|
-
top={-0.5}
|
62
|
-
left={3}
|
63
|
-
zIndex="dropdown"
|
64
|
-
maxWidth="50ch"
|
65
|
-
{...errorMessageProps}
|
66
|
-
{...boxProps}
|
67
|
-
>
|
68
|
-
<Arrow position="absolute" top="-0.25em" left="1em" />
|
69
|
-
{children}
|
70
|
-
</Box>
|
71
|
-
</Box>
|
72
|
-
);
|
73
|
-
};
|
74
|
-
|
75
|
-
/** The arrow of the error message box */
|
76
|
-
const Arrow = (props: BoxProps) => {
|
77
|
-
return (
|
78
|
-
<Box
|
79
|
-
{...(props as any)}
|
80
|
-
as="svg"
|
81
|
-
width="16"
|
82
|
-
height="16"
|
83
|
-
viewBox="0 0 16 16"
|
84
|
-
fill="none"
|
85
|
-
transform="rotate(45deg)"
|
86
|
-
>
|
87
|
-
<Box
|
88
|
-
as="path"
|
89
|
-
fill="lightRed"
|
90
|
-
d="M 0
|
91
|
-
0 Q 2.4 6 0 12 Q 6 9.6 12 12 Q 9.6 6 12 0 Q 6 2.4 0 0 z"
|
92
|
-
/>
|
93
|
-
</Box>
|
94
|
-
);
|
95
|
-
};
|
package/src/input/FormLabel.tsx
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
FormLabel as ChakraFormLabel,
|
3
|
-
FormLabelProps as ChakraFormLabelProps,
|
4
|
-
forwardRef,
|
5
|
-
} from "@chakra-ui/react";
|
6
|
-
import React from "react";
|
7
|
-
|
8
|
-
export type FormLabelProps = ChakraFormLabelProps;
|
9
|
-
export const FormLabel = forwardRef<FormLabelProps, "label">((props, ref) => {
|
10
|
-
return <ChakraFormLabel {...props} ref={ref} />;
|
11
|
-
});
|
package/src/input/InfoSelect.tsx
DELETED
@@ -1,274 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
Box,
|
3
|
-
chakra,
|
4
|
-
Flex,
|
5
|
-
FormLabel,
|
6
|
-
ResponsiveValue,
|
7
|
-
useFormControlProps,
|
8
|
-
useMultiStyleConfig,
|
9
|
-
} from "@chakra-ui/react";
|
10
|
-
import {
|
11
|
-
DropdownDownFill24Icon,
|
12
|
-
DropdownUpFill24Icon,
|
13
|
-
} from "@vygruppen/spor-icon-react";
|
14
|
-
import React, { useRef } from "react";
|
15
|
-
import { HiddenSelect, useButton, useSelect } from "react-aria";
|
16
|
-
import { Column, useSelectState } from "react-stately";
|
17
|
-
import { createTexts, useTranslation } from "../";
|
18
|
-
import { ListBox } from "./ListBox";
|
19
|
-
import { Popover } from "./Popover";
|
20
|
-
|
21
|
-
type InfoSelectProps<T extends object> = {
|
22
|
-
/**
|
23
|
-
* Either a render function accepting an item, and returning a <Item />,
|
24
|
-
* or a list of <Item />s.
|
25
|
-
*
|
26
|
-
* Render function example:
|
27
|
-
* ```tsx
|
28
|
-
* <Select items={items}>
|
29
|
-
* {(item) => (
|
30
|
-
* <Item key={item.value} value={item.value}>
|
31
|
-
* {item.label}
|
32
|
-
* </Item>
|
33
|
-
* )}
|
34
|
-
* </Select>
|
35
|
-
* ```
|
36
|
-
*
|
37
|
-
* For this to work, the members in `items` need either a `key`
|
38
|
-
* or an `id` property.
|
39
|
-
*
|
40
|
-
* List of <Item />s example:
|
41
|
-
* ```tsx
|
42
|
-
* <Select label="Choose a color">
|
43
|
-
* <Item>Green</Item>
|
44
|
-
* <Item>Blue</Item>
|
45
|
-
* <Item>Yellow</Item>
|
46
|
-
* </Select>
|
47
|
-
* ```
|
48
|
-
**/
|
49
|
-
children: React.ReactElement | ((item: T) => React.ReactElement);
|
50
|
-
/**
|
51
|
-
* The items to render
|
52
|
-
*
|
53
|
-
* If you have a dynamic list of items you want to display, you should use this prop instead of mapping them out. This is a performance optimization.
|
54
|
-
*
|
55
|
-
* You can render each item in a render function, passed in as `children`:
|
56
|
-
*
|
57
|
-
* ```tsx
|
58
|
-
* <Select items={items}>
|
59
|
-
* {(item) => <div>{item.someProp}</div>}
|
60
|
-
* </Select>
|
61
|
-
* ```
|
62
|
-
*/
|
63
|
-
items?: T[];
|
64
|
-
/** Callback for when something is selected */
|
65
|
-
onChange?: (value: string | number) => void;
|
66
|
-
value?: string | number;
|
67
|
-
defaultValue?: string | number;
|
68
|
-
/** Controlled open state
|
69
|
-
*
|
70
|
-
* Useful if you want to control the open state from outside the component.
|
71
|
-
*/
|
72
|
-
isOpen?: boolean;
|
73
|
-
/** Callback for when the open state of the select box changes.
|
74
|
-
*
|
75
|
-
* Useful if you want to control the open state from outside the component.
|
76
|
-
*/
|
77
|
-
onOpenChange?: (isOpen: boolean) => void;
|
78
|
-
/** The label describing the choice */
|
79
|
-
label: string;
|
80
|
-
/** Hide the label visually
|
81
|
-
*
|
82
|
-
* Should be used sparingly, as it makes the component less accessible.
|
83
|
-
* Useful for the label is obvious, like a phone number country code select.
|
84
|
-
*/
|
85
|
-
isLabelSrOnly?: boolean;
|
86
|
-
/** The name of the select element */
|
87
|
-
name?: string;
|
88
|
-
/**
|
89
|
-
* What's shown if nothing is selected.
|
90
|
-
*
|
91
|
-
* Defaults to a localized version of "choose an option"
|
92
|
-
*/
|
93
|
-
placeholder?: string;
|
94
|
-
/** The width of the select box.
|
95
|
-
*
|
96
|
-
* Defaults to the width of the selected content
|
97
|
-
*/
|
98
|
-
width?: ResponsiveValue<string | number>;
|
99
|
-
/** The height of the select box.
|
100
|
-
*
|
101
|
-
* Defaults to "auto"
|
102
|
-
*/
|
103
|
-
height?: ResponsiveValue<string | number>;
|
104
|
-
isDisabled?: boolean;
|
105
|
-
/** A list of disabled keys.
|
106
|
-
*
|
107
|
-
* ```tsx
|
108
|
-
* <Select label="Choose a color" disabledKeys={["blue", "yellow"]}>
|
109
|
-
* <Item key="green">Green</Item>
|
110
|
-
* <Item key="blue">Blue</Item>
|
111
|
-
* <Item key="yellow">Yellow</Item>
|
112
|
-
* </Select>
|
113
|
-
* ```
|
114
|
-
**/
|
115
|
-
disabledKeys?: string[];
|
116
|
-
/** Whether or not the input is invalid */
|
117
|
-
"aria-invalid"?: boolean;
|
118
|
-
variant?: "base" | "floating";
|
119
|
-
};
|
120
|
-
/**
|
121
|
-
* A styled select component.
|
122
|
-
*
|
123
|
-
* This select component lets you choose between a list of options.
|
124
|
-
* Compared to the NativeSelect component, the InfoSelect component lets you style the options however you'd like – including both text, icons and other elements.
|
125
|
-
*
|
126
|
-
* ```tsx
|
127
|
-
* <InfoSelect label="Choose a color">
|
128
|
-
* <SelectOption>Blue</SelectOption>
|
129
|
-
* <SelectOption>Yellow</SelectOption>
|
130
|
-
* <SelectOption>Green</SelectOption>
|
131
|
-
* </InfoSelect>
|
132
|
-
* ```
|
133
|
-
*
|
134
|
-
* Alternatvely, you can pass the items into the `items` prop, and create a render function for the items.
|
135
|
-
*
|
136
|
-
* ```tsx
|
137
|
-
* <InfoSelect
|
138
|
-
* label="Choose a color"
|
139
|
-
* items={[
|
140
|
-
* { value: "#f00", label: "Red" },
|
141
|
-
* { value: "#0f0", label: "Green" },
|
142
|
-
* { value: "#00f", label: "Blue" },
|
143
|
-
* ]}
|
144
|
-
* >
|
145
|
-
* {(item) => (
|
146
|
-
* <Item key={item.key}>
|
147
|
-
* {item.label}
|
148
|
-
* </Item>
|
149
|
-
* )}
|
150
|
-
* </InfoSelect>
|
151
|
-
* ```
|
152
|
-
*
|
153
|
-
* @see https://spor.vy.no/components/info-select
|
154
|
-
*/
|
155
|
-
export function InfoSelect<T extends object>({
|
156
|
-
placeholder,
|
157
|
-
onChange,
|
158
|
-
value,
|
159
|
-
isLabelSrOnly,
|
160
|
-
defaultValue,
|
161
|
-
variant,
|
162
|
-
...props
|
163
|
-
}: InfoSelectProps<T>) {
|
164
|
-
const renamedProps = {
|
165
|
-
onSelectionChange: onChange,
|
166
|
-
selectedKey: value,
|
167
|
-
defaultSelectedKey: defaultValue,
|
168
|
-
...props,
|
169
|
-
};
|
170
|
-
const state = useSelectState(renamedProps);
|
171
|
-
const triggerRef = useRef<HTMLButtonElement>(null);
|
172
|
-
const listboxRef = useRef<HTMLUListElement>(null);
|
173
|
-
const { labelProps, triggerProps, valueProps, menuProps } = useSelect(
|
174
|
-
renamedProps,
|
175
|
-
state,
|
176
|
-
triggerRef,
|
177
|
-
);
|
178
|
-
|
179
|
-
const stateStyle = "completed";
|
180
|
-
|
181
|
-
const hasChosenValue = state.selectedItem !== null;
|
182
|
-
|
183
|
-
const styles = useMultiStyleConfig("InfoSelect", {
|
184
|
-
isOpen: state.isOpen,
|
185
|
-
isLabelSrOnly,
|
186
|
-
variant,
|
187
|
-
stateStyle,
|
188
|
-
hasChosenValue,
|
189
|
-
});
|
190
|
-
const { buttonProps } = useButton(triggerProps, triggerRef);
|
191
|
-
const { t } = useTranslation();
|
192
|
-
const formControl = useFormControlProps(props);
|
193
|
-
|
194
|
-
return (
|
195
|
-
<Box sx={styles.container}>
|
196
|
-
<HiddenSelect
|
197
|
-
state={state}
|
198
|
-
triggerRef={triggerRef}
|
199
|
-
label={props.label}
|
200
|
-
name={props.name}
|
201
|
-
/>
|
202
|
-
|
203
|
-
<chakra.button
|
204
|
-
type="button"
|
205
|
-
ref={triggerRef}
|
206
|
-
sx={styles.button}
|
207
|
-
{...buttonProps}
|
208
|
-
data-attachable
|
209
|
-
aria-invalid={formControl.isInvalid}
|
210
|
-
aria-describedby={formControl["aria-describedby"]}
|
211
|
-
>
|
212
|
-
<chakra.div sx={styles.innerButton}>
|
213
|
-
<chakra.div
|
214
|
-
{...labelProps}
|
215
|
-
sx={{
|
216
|
-
...styles.label,
|
217
|
-
...(hasChosenValue && {
|
218
|
-
transform: "scale(0.825) translateY(-10px) translateX(-10%)",
|
219
|
-
transitionProperty: "var(--spor-transition-property-common)",
|
220
|
-
transitionDuration: "var(--spor-transition-duration-normal)",
|
221
|
-
}),
|
222
|
-
}}
|
223
|
-
>
|
224
|
-
{props.label}
|
225
|
-
</chakra.div>
|
226
|
-
<Box
|
227
|
-
{...valueProps}
|
228
|
-
h={isLabelSrOnly ? "" : !hasChosenValue ? "0px" : "18px"}
|
229
|
-
hidden={!hasChosenValue}
|
230
|
-
transform={isLabelSrOnly ? "" : "scale(1) translateY(-12px)"}
|
231
|
-
transitionProperty={"var(--spor-transition-property-common)"}
|
232
|
-
transitionDuration={"var(--spor-transition-duration-normal)"}
|
233
|
-
>
|
234
|
-
{state.selectedItem
|
235
|
-
? (state.selectedItem.textValue ?? state.selectedItem.rendered)
|
236
|
-
: (placeholder ?? t(texts.selectAnOption))}
|
237
|
-
</Box>
|
238
|
-
</chakra.div>
|
239
|
-
<Box sx={styles.arrowIcon}>
|
240
|
-
{state.isOpen ? <DropdownUpFill24Icon /> : <DropdownDownFill24Icon />}
|
241
|
-
</Box>
|
242
|
-
</chakra.button>
|
243
|
-
|
244
|
-
{state.isOpen && (
|
245
|
-
<Popover
|
246
|
-
state={state}
|
247
|
-
triggerRef={triggerRef}
|
248
|
-
// The minimum padding should be 0, because the popover always should be
|
249
|
-
// aligned with the trigger field regardless of the left padding in the container.
|
250
|
-
containerPadding={0}
|
251
|
-
>
|
252
|
-
<ListBox
|
253
|
-
{...menuProps}
|
254
|
-
state={state}
|
255
|
-
listBoxRef={listboxRef}
|
256
|
-
borderBottomRadius="sm"
|
257
|
-
variant={variant}
|
258
|
-
>
|
259
|
-
{props.children}
|
260
|
-
</ListBox>
|
261
|
-
</Popover>
|
262
|
-
)}
|
263
|
-
</Box>
|
264
|
-
);
|
265
|
-
}
|
266
|
-
|
267
|
-
const texts = createTexts({
|
268
|
-
selectAnOption: {
|
269
|
-
nb: "Velg et alternativ",
|
270
|
-
nn: "Velg eit alternativ",
|
271
|
-
sv: "Välj ett alternativ",
|
272
|
-
en: "Choose an option",
|
273
|
-
},
|
274
|
-
});
|
@@ -1,44 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
forwardRef,
|
3
|
-
InputElementProps as ChakraInputElementProps,
|
4
|
-
InputLeftElement as ChakraInputLeftElement,
|
5
|
-
InputRightElement as ChakraInputRightElement,
|
6
|
-
} from "@chakra-ui/react";
|
7
|
-
import React from "react";
|
8
|
-
|
9
|
-
export type InputElementProps = ChakraInputElementProps;
|
10
|
-
/**
|
11
|
-
* Places an element inside the left side of an input field.
|
12
|
-
*
|
13
|
-
* Must be used inside of an `InputGroup` component, and before the `Input` component.
|
14
|
-
*
|
15
|
-
* ```tsx
|
16
|
-
* <FormControl>
|
17
|
-
* <InputGroup>
|
18
|
-
* <InputLeftElement>🔎</InputLeftElement>
|
19
|
-
* <Input label="Search" />
|
20
|
-
* </InputGroup>
|
21
|
-
* </FormControl>
|
22
|
-
* ```
|
23
|
-
*/
|
24
|
-
export const InputLeftElement = forwardRef<InputElementProps, "div">(
|
25
|
-
(props, ref) => <ChakraInputLeftElement {...props} ref={ref} />,
|
26
|
-
);
|
27
|
-
|
28
|
-
/**
|
29
|
-
* Places an element inside the right side of an input field.
|
30
|
-
*
|
31
|
-
* Must be used inside of an `InputGroup` component, and after the `Input` component.
|
32
|
-
*
|
33
|
-
* ```tsx
|
34
|
-
* <FormControl>
|
35
|
-
* <InputGroup>
|
36
|
-
* <Input label="Search" />
|
37
|
-
* <InputRightElement>🔎</InputRightElement>
|
38
|
-
* </InputGroup>
|
39
|
-
* </FormControl>
|
40
|
-
* ```
|
41
|
-
*/
|
42
|
-
export const InputRightElement = forwardRef<InputElementProps, "div">(
|
43
|
-
(props, ref) => <ChakraInputRightElement {...props} ref={ref} />,
|
44
|
-
);
|
package/src/input/RadioGroup.tsx
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
forwardRef,
|
3
|
-
RadioGroup as ChakraRadioGroup,
|
4
|
-
RadioGroupProps as ChakraRadioGroupProps,
|
5
|
-
Stack,
|
6
|
-
StackDirection,
|
7
|
-
} from "@chakra-ui/react";
|
8
|
-
import React from "react";
|
9
|
-
|
10
|
-
export type RadioGroupProps = Exclude<
|
11
|
-
ChakraRadioGroupProps,
|
12
|
-
"colorScheme" | "size" | "variant"
|
13
|
-
> & {
|
14
|
-
direction?: StackDirection;
|
15
|
-
};
|
16
|
-
/**
|
17
|
-
* Radio groups are used to group several radio buttons together.
|
18
|
-
*
|
19
|
-
* You can pass the common `name` prop to the `RadioGroup`, instead of to each `Radio` component.
|
20
|
-
*
|
21
|
-
* ```tsx
|
22
|
-
* <RadioGroup name="ticket">
|
23
|
-
* <Radio>Economy</Radio>
|
24
|
-
* <Radio>Business</Radio>
|
25
|
-
* <Radio>First Class</Radio>
|
26
|
-
* </RadioGroup>
|
27
|
-
* ```
|
28
|
-
*
|
29
|
-
* By default, radio buttons show up horizontally. If you want them to show up vertically, please specify the `direction="column"` prop.
|
30
|
-
*
|
31
|
-
* ```tsx
|
32
|
-
* <RadioGroup name="ticket" direction="column">
|
33
|
-
* <Radio>Economy</Radio>
|
34
|
-
* <Radio>Business</Radio>
|
35
|
-
* <Radio>First Class</Radio>
|
36
|
-
* </RadioGroup>
|
37
|
-
* ```
|
38
|
-
*/
|
39
|
-
export const RadioGroup = forwardRef<RadioGroupProps, "div">(
|
40
|
-
({ children, direction = "row", ...rest }, ref) => {
|
41
|
-
return (
|
42
|
-
<ChakraRadioGroup {...rest} ref={ref}>
|
43
|
-
<Stack direction={direction}>{children}</Stack>
|
44
|
-
</ChakraRadioGroup>
|
45
|
-
);
|
46
|
-
},
|
47
|
-
);
|
package/src/layout/Divider.tsx
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
BoxProps,
|
3
|
-
Divider as ChakraDivider,
|
4
|
-
DividerProps as ChakraDividerProps,
|
5
|
-
forwardRef,
|
6
|
-
} from "@chakra-ui/react";
|
7
|
-
import { As } from "@chakra-ui/system";
|
8
|
-
import React from "react";
|
9
|
-
|
10
|
-
export type DividerProps = ChakraDividerProps & {
|
11
|
-
size?: "sm" | "md" | "lg";
|
12
|
-
variant?: "solid" | "dashed";
|
13
|
-
};
|
14
|
-
/** A dividing line, used to divide content.
|
15
|
-
*
|
16
|
-
* You can specify margins if you need to give the content some space, or use a `Stack` component to do it for you
|
17
|
-
*
|
18
|
-
* ```tsx
|
19
|
-
* <Divider marginTop={4} marginBottom={6} />
|
20
|
-
* ```
|
21
|
-
*
|
22
|
-
* There are three different sizes available: `sm`, `md` and `lg`. The default is `md`.
|
23
|
-
* There are two different variants available: `solid` and `dashed`. The default is `solid`.
|
24
|
-
*/
|
25
|
-
export const Divider = forwardRef<BoxProps, As>((props, ref) => {
|
26
|
-
return <ChakraDivider {...props} ref={ref} />;
|
27
|
-
});
|
@@ -1,79 +0,0 @@
|
|
1
|
-
import { BoxProps, Stack } from "@chakra-ui/react";
|
2
|
-
import React, { useState } from "react";
|
3
|
-
import { FormLabel } from "../input";
|
4
|
-
|
5
|
-
/**
|
6
|
-
* RadioCardGroupContext is used to pass down the state and handlers to the RadioCard components.
|
7
|
-
*
|
8
|
-
* @see RadioCard
|
9
|
-
*/
|
10
|
-
|
11
|
-
type RadioGroupContextProps = {
|
12
|
-
name: string;
|
13
|
-
selectedValue: string;
|
14
|
-
onChange: (value: string) => void;
|
15
|
-
variant?: "base" | "floating";
|
16
|
-
defaultValue?: string;
|
17
|
-
value?: string;
|
18
|
-
};
|
19
|
-
|
20
|
-
export const RadioCardGroupContext =
|
21
|
-
React.createContext<RadioGroupContextProps | null>(null);
|
22
|
-
|
23
|
-
type RadioCardGroupProps = BoxProps & {
|
24
|
-
/** A string that will be assigned as the name attribute to all RadioCard components within the group. */
|
25
|
-
name: string;
|
26
|
-
/** The RadioCard components that make up the group. */
|
27
|
-
children: React.ReactNode;
|
28
|
-
/** Optional. Determines the style of the RadioCard. Can be either "base" or "floating". */
|
29
|
-
variant?: "base" | "floating";
|
30
|
-
/** Optional. Determines the direction of the group. Can be either "row" or "column". */
|
31
|
-
direction?: "row" | "column";
|
32
|
-
/** Optional. A label for the group. */
|
33
|
-
groupLabel?: string;
|
34
|
-
/** Optional. The default value of the RadioCard group. */
|
35
|
-
defaultValue?: string;
|
36
|
-
/** Optional. A function that will be called when the selected value changes. The function receives the value of the selected RadioCard. */
|
37
|
-
onChange?: (value: string) => void;
|
38
|
-
};
|
39
|
-
|
40
|
-
export const RadioCardGroup: React.FC<RadioCardGroupProps> = ({
|
41
|
-
children,
|
42
|
-
name,
|
43
|
-
variant = "base",
|
44
|
-
direction = "row",
|
45
|
-
groupLabel,
|
46
|
-
defaultValue,
|
47
|
-
onChange,
|
48
|
-
...props
|
49
|
-
}: RadioCardGroupProps) => {
|
50
|
-
const [selectedValue, setSelectedValue] = useState<string>(
|
51
|
-
defaultValue || "",
|
52
|
-
);
|
53
|
-
|
54
|
-
const handleChange = (value: string) => {
|
55
|
-
setSelectedValue(value);
|
56
|
-
onChange && onChange(value);
|
57
|
-
};
|
58
|
-
|
59
|
-
return (
|
60
|
-
<RadioCardGroupContext.Provider
|
61
|
-
value={{
|
62
|
-
name,
|
63
|
-
selectedValue,
|
64
|
-
onChange: handleChange,
|
65
|
-
variant,
|
66
|
-
defaultValue: defaultValue || "",
|
67
|
-
}}
|
68
|
-
>
|
69
|
-
<Stack as="fieldset" direction={direction} {...props}>
|
70
|
-
{groupLabel && (
|
71
|
-
<FormLabel as="legend" id={groupLabel}>
|
72
|
-
{groupLabel}
|
73
|
-
</FormLabel>
|
74
|
-
)}
|
75
|
-
{children}
|
76
|
-
</Stack>
|
77
|
-
</RadioCardGroupContext.Provider>
|
78
|
-
);
|
79
|
-
};
|
package/src/layout/Stack.tsx
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
Stack as ChakraStack,
|
3
|
-
StackProps as ChakraStackProps,
|
4
|
-
forwardRef,
|
5
|
-
} from "@chakra-ui/react";
|
6
|
-
import React from "react";
|
7
|
-
|
8
|
-
export type StackProps = Exclude<ChakraStackProps, "direction"> & {
|
9
|
-
flexDirection?: ChakraStackProps["direction"];
|
10
|
-
};
|
11
|
-
/**
|
12
|
-
* Adds consistent spacing between elements
|
13
|
-
*
|
14
|
-
* ```tsx
|
15
|
-
* <Stack>
|
16
|
-
* <Text>Here's a paragraph</Text>
|
17
|
-
* <Text>Here's another perfectly spaced paragraph</Text>
|
18
|
-
* </Stack>
|
19
|
-
* ```
|
20
|
-
*
|
21
|
-
* By default, the stack will be a column. You can change this by setting the `flexDirection` prop to any valid flex direction:
|
22
|
-
* ```tsx
|
23
|
-
* <Stack flexDirection="row">
|
24
|
-
* <Checkbox>Here's a checkbox</Checkbox>
|
25
|
-
* <Checkbox>Here's another checkbox, almost right next to the first one</Checkbox>
|
26
|
-
* </Stack>
|
27
|
-
* ```
|
28
|
-
*
|
29
|
-
* You can specify the spacing between elements with the `spacing` prop:
|
30
|
-
*
|
31
|
-
* ```tsx
|
32
|
-
* <Stack spacing={4}>
|
33
|
-
* <StaticCard>Here's one card</StaticCard>
|
34
|
-
* <StaticCard>Here's another card, with a lot of space between it</StaticCard>
|
35
|
-
* </Stack>
|
36
|
-
* ```
|
37
|
-
*/
|
38
|
-
export const Stack = forwardRef<StackProps, "div">(
|
39
|
-
({ flexDirection, ...props }, ref) => {
|
40
|
-
return <ChakraStack {...props} direction={flexDirection} ref={ref} />;
|
41
|
-
},
|
42
|
-
);
|
@@ -1,13 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
BoxProps,
|
3
|
-
SkeletonCircle as ChakraSkeletonCircle,
|
4
|
-
} from "@chakra-ui/react";
|
5
|
-
import React from "react";
|
6
|
-
|
7
|
-
export type SkeletonCircleProps = BoxProps;
|
8
|
-
/**
|
9
|
-
* SkeletonCircle renders a loading animation for a given circle. It works great as a placeholder to avoid layout shifts.
|
10
|
-
*/
|
11
|
-
export const SkeletonCircle = (props: SkeletonCircleProps) => (
|
12
|
-
<ChakraSkeletonCircle boxSize={6} borderRadius="50%" {...props} />
|
13
|
-
);
|
@@ -1,14 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
SkeletonText as ChakraSkeletonText,
|
3
|
-
SkeletonTextProps as ChakraSkeletonTextProps,
|
4
|
-
} from "@chakra-ui/react";
|
5
|
-
import React from "react";
|
6
|
-
|
7
|
-
export type SkeletonTextProps = ChakraSkeletonTextProps;
|
8
|
-
|
9
|
-
/**
|
10
|
-
* SkeletonText renders a loading animation for a given text. It works great as a placeholder to avoid layout shifts.
|
11
|
-
*/
|
12
|
-
export const SkeletonText = (props: SkeletonTextProps) => (
|
13
|
-
<ChakraSkeletonText boxSize={6} {...props} />
|
14
|
-
);
|