@vygruppen/spor-react 9.11.4 → 9.13.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/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- export { Accordion, AccordionButton, AccordionIcon, AccordionItem, AccordionPanel, AttachedInputs, Badge, Box, Brand, Breadcrumb, BreadcrumbItem, BreadcrumbLink, Button, ButtonGroup, Card, CardSelect, Center, Checkbox, CheckboxGroup, ChoiceChip, ClosableAlert, CloseButton, Code, Collapse, ColorInlineLoader, ColorSpinner, Combobox, Container, ContentLoader, DarkFullScreenLoader, DarkInlineLoader, DarkMode, DarkSpinner, DatePicker, DateRangePicker, Divider, Drawer, DrawerBody, DrawerCloseButton, DrawerContent, DrawerFooter, ModalHeader as DrawerHeader, DrawerOverlay, Expandable, ExpandableAlert, ExpandableItem, Fade, Flex, FloatingActionButton, FormControl, FormErrorMessage, FormHelperText, FormLabel, FullScreenDrawer, Grid, GridItem, HStack, Heading, IconButton, Image, Img, InfoSelect, InfoTag, Input, InputGroup, InputLeftElement, InputRightElement, Item, ItemDescription, ItemLabel, JumpButton, Language, LanguageProvider, LightFullScreenLoader, LightInlineLoader, LightMode, LightSpinner, LineIcon, ListBox, ListItem, Modal, ModalBody, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalOverlay, NativeSelect, Nudge, NumericStepper, OrderedList, Pagination, PasswordInput, PhoneNumberInput, PlayPauseButton, Portal, PressableCard, PrideProvider, ProgressBar, ProgressIndicator, ProgressLoader, Radio, RadioCard, RadioCardGroup, RadioGroup, ScaleFade, SearchInput, Section, SimpleDrawer, SimpleGrid, Skeleton, SkeletonCircle, SkeletonText, SkipButton, Slide, SlideFade, Spacer, SporProvider, Stack, StaticAlert, StaticCard, Stepper, StepperStep, Switch, Tab, TabList, TabPanel, TabPanels, Table, TableCaption, Tabs, Tbody, Td, Text, TextLink, Textarea, Tfoot, Th, Thead, Time, TimePicker, TogglePride, Tooltip, Tr, TravelTag, UnorderedList, VStack, VyLogo, VyLogoDefault, VyLogoPride, WizardNudge, Wrap, WrapItem, brandTheme, createTexts, defineStyleConfig, extendTheme, fontFaces, slugify, theme, tokens, useBreakpointValue, useClipboard, useColorMode, useColorModePreference, useColorModeValue, useControllableProp, useDisclosure, useMediaQuery, useMergeRefs, useOutsideClick, usePrefersReducedMotion, usePride, useSize, useTheme, useToast, useToken, useTranslation } from './chunk-WCPDJEIZ.mjs';
1
+ export { Accordion, AccordionButton, AccordionIcon, AccordionItem, AccordionPanel, AttachedInputs, Badge, Box, Brand, Breadcrumb, BreadcrumbItem, BreadcrumbLink, Button, ButtonGroup, Card, CardSelect, Center, Checkbox, CheckboxGroup, ChoiceChip, ClosableAlert, CloseButton, Code, Collapse, ColorInlineLoader, ColorSpinner, Combobox, Container, ContentLoader, DarkFullScreenLoader, DarkInlineLoader, DarkMode, DarkSpinner, DatePicker, DateRangePicker, Divider, Drawer, DrawerBody, DrawerCloseButton, DrawerContent, DrawerFooter, ModalHeader as DrawerHeader, DrawerOverlay, Expandable, ExpandableAlert, ExpandableItem, Fade, Flex, FloatingActionButton, FormControl, FormErrorMessage, FormHelperText, FormLabel, FullScreenDrawer, Grid, GridItem, HStack, Heading, IconButton, Image, Img, InfoSelect, InfoTag, Input, InputGroup, InputLeftElement, InputRightElement, Item, ItemDescription, ItemLabel, JumpButton, Language, LanguageProvider, LightFullScreenLoader, LightInlineLoader, LightMode, LightSpinner, LineIcon, ListBox, ListItem, Modal, ModalBody, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalOverlay, NativeSelect, Nudge, NumericStepper, OrderedList, Pagination, PasswordInput, PhoneNumberInput, PlayPauseButton, Portal, PressableCard, PrideProvider, ProgressBar, ProgressIndicator, ProgressLoader, Radio, RadioCard, RadioCardGroup, RadioCardGroupContext, RadioGroup, ScaleFade, SearchInput, Section, SimpleDrawer, SimpleGrid, Skeleton, SkeletonCircle, SkeletonText, SkipButton, Slide, SlideFade, Spacer, SporProvider, Stack, StaticAlert, StaticCard, Stepper, StepperStep, Switch, Tab, TabList, TabPanel, TabPanels, Table, TableCaption, Tabs, Tbody, Td, Text, TextLink, Textarea, Tfoot, Th, Thead, Time, TimePicker, TogglePride, Tooltip, Tr, TravelTag, UnorderedList, VStack, VyLogo, VyLogoDefault, VyLogoPride, WizardNudge, Wrap, WrapItem, brandTheme, createTexts, defineStyleConfig, extendTheme, fontFaces, slugify, theme, tokens, useBreakpointValue, useClipboard, useColorMode, useColorModePreference, useColorModeValue, useControllableProp, useDisclosure, useMediaQuery, useMergeRefs, useOutsideClick, usePrefersReducedMotion, usePride, useSize, useTheme, useToast, useToken, useTranslation } from './chunk-KJYJYQBK.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vygruppen/spor-react",
3
- "version": "9.11.4",
3
+ "version": "9.13.0",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",
@@ -17,31 +17,31 @@
17
17
  "directory": "packages/spor-react"
18
18
  },
19
19
  "dependencies": {
20
- "@chakra-ui/react": "^2.6.1",
20
+ "@chakra-ui/react": "^2.8.2",
21
21
  "@chakra-ui/theme-tools": "^2.0.12",
22
- "@emotion/react": "^11.10.4",
23
- "@emotion/styled": "^11.10.4",
24
- "@internationalized/date": "^3.0.1",
25
- "@vygruppen/spor-design-tokens": ">3.6.0",
26
- "@vygruppen/spor-icon-react": ">3.6.0",
27
- "@vygruppen/spor-loader": ">0.3.1",
28
- "awesome-phonenumber": "^5.10.0",
22
+ "@emotion/react": "^11.11.4",
23
+ "@emotion/styled": "^11.11.5",
24
+ "@internationalized/date": "^3.5.4",
25
+ "@vygruppen/spor-design-tokens": "^3.7.0",
26
+ "@vygruppen/spor-icon-react": "^3.9.0",
27
+ "@vygruppen/spor-loader": "^0.4.0",
28
+ "awesome-phonenumber": "^5.11.0",
29
29
  "deepmerge": "^4.3.1",
30
30
  "framer-motion": "^9.1.7",
31
- "lottie-react": "^2.3.1",
32
- "react-aria": "^3.30.0",
33
- "react-stately": "^3.28.0",
34
- "react-swipeable": "^7.0.0"
31
+ "lottie-react": "^2.4.0",
32
+ "react-aria": "^3.33.1",
33
+ "react-stately": "^3.31.1",
34
+ "react-swipeable": "^7.0.1"
35
35
  },
36
36
  "devDependencies": {
37
- "@testing-library/jest-dom": "^6.1.3",
38
- "@testing-library/react": "^14.0.0",
39
- "react": "^18.2.0",
40
- "react-dom": "^18.2.0",
37
+ "@testing-library/jest-dom": "^6.4.5",
38
+ "@testing-library/react": "^14.3.1",
39
+ "react": "^18.3.1",
40
+ "react-dom": "^18.3.1",
41
41
  "tsup": "^7.2.0",
42
42
  "vitest": "^0.26.3",
43
43
  "vitest-axe": "^0.1.0",
44
- "vitest-canvas-mock": "^0.2.0"
44
+ "vitest-canvas-mock": "^0.2.2"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "react": "^18.2.0",
@@ -69,7 +69,7 @@ export const PhoneNumberInput = forwardRef<PhoneNumberInputProps, As>(
69
69
  fallback={
70
70
  <InfoSelect
71
71
  isLabelSrOnly
72
- label=""
72
+ label={t(texts.countryCodeLabel)}
73
73
  width="6.25rem"
74
74
  height="100%"
75
75
  value="+47"
@@ -120,6 +120,12 @@ const texts = createTexts({
120
120
  en: "Phone number",
121
121
  sv: "Telefonnummer",
122
122
  },
123
+ countryCodeLabel: {
124
+ nb: "Landskode",
125
+ nn: "Landskode",
126
+ en: "Country code",
127
+ sv: "Landskod",
128
+ },
123
129
  });
124
130
 
125
131
  const LazyCountryCodeSelect = React.lazy(() => import("./CountryCodeSelect"));
@@ -1,34 +1,19 @@
1
1
  import {
2
2
  Box,
3
3
  BoxProps,
4
- UseRadioProps,
5
4
  chakra,
6
5
  forwardRef,
7
6
  useMultiStyleConfig,
8
7
  } from "@chakra-ui/react";
9
- import React, { useId } from "react";
8
+ import React, { useContext, useEffect, useId } from "react";
9
+ import { RadioCardGroupContext } from "./RadioCardGroup";
10
10
 
11
11
  /**
12
12
  * Radio cards are used to present a set of options where only one option can be selected.
13
13
  *
14
- * The most basic version looks like this:
15
- *
16
- * ```tsx
17
- * <RadioCard>
18
- * Content
19
- * </RadioCard>
20
- * ```
21
- *
22
- * In order to use RadioCard outside a RadioCardGroup, you need to pass the `isChecked` and `onChange` props.
23
- *
24
- * ```tsx
25
- * <RadioCard isChecked={true} onChange={(e) => console.log(e.target.value)}>
26
- * Content
27
- * </RadioCard>
28
- * ```
29
- *
30
- * In order to use RadioCard, you typically want to place these components in a group with several other RadioCards.
14
+ * RadioCard components must be wrapped in a RadioCardGroup component.
31
15
  *
16
+ * @example
32
17
  * ```tsx
33
18
  * <RadioCardGroup name="ticket">
34
19
  * <RadioCard value="economy">Economy</RadioCard>
@@ -37,65 +22,84 @@ import React, { useId } from "react";
37
22
  * </RadioCardGroup>
38
23
  * ```
39
24
  *
40
- * You can add styling to each card seperately, or you can add a common style to the group.
41
- * Group styling overrides single styling if both are present.
25
+ * RadioCard inherits props from Box.
42
26
  *
43
- * This example shows how to style all cards in a group:
44
- *
45
- * ```tsx
46
- * <RadioCardGroup name="ticket" variant="floating" padding={3}>
47
- * <RadioCard value="economy">Economy</RadioCard>
48
- * <RadioCard value="business">Business</RadioCard>
49
- * <RadioCard value="first-class">First Class</RadioCard>
50
- * </RadioCardGroup>
51
- * ```
27
+ * Be advised to not use the `name` prop on the RadioCard component.
52
28
  *
53
- * This example shows how to style a single card:
29
+ * Changing the semantics may also cause the component to not work as expected.
54
30
  *
55
- * ```tsx
56
- * <RadioCard variant="floating" padding={3}>
57
- * Economy
58
- * </RadioCard>
59
- * ```
31
+ * @see Docs https://spor.vy.no/components/radiocard
60
32
  */
61
33
 
62
- export type RadioCardProps = UseRadioProps &
63
- BoxProps & {
64
- children: React.ReactNode;
65
- /** Defaults to "base" */
66
- variant?: "floating" | "base";
67
- /** Needs to be defined if RadioCard is used outside RadioCardGroup */
68
- isChecked?: boolean;
69
- /** Needs to be defined if RadioCard is used outside RadioCardGroup */
70
- onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
71
- };
34
+ export type RadioCardProps = BoxProps & {
35
+ value: string;
36
+ children: React.ReactNode;
37
+ isDisabled?: boolean;
38
+ };
39
+
40
+ export const RadioCard = forwardRef(
41
+ ({ children, value = "base", isDisabled, ...props }: RadioCardProps, ref) => {
42
+ const context = useContext(RadioCardGroupContext);
43
+
44
+ if (!context) {
45
+ throw new Error(
46
+ "RadioCard components must be wrapped in a RadioCardGroup component",
47
+ );
48
+ }
49
+
50
+ const { name, selectedValue, onChange, variant } = context;
72
51
 
73
- export const RadioCard = forwardRef<RadioCardProps, "div">(
74
- ({ children, variant = "base", isChecked, onChange, ...props }, ref) => {
75
52
  const styles = useMultiStyleConfig("RadioCard", { variant });
76
53
 
77
- const id = `radio-card-${useId()}`;
54
+ const isChecked = selectedValue === value;
55
+
56
+ const radioCardId = `radio-card-${useId()}`;
78
57
 
79
- const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
80
- onChange && onChange(event);
58
+ useEffect(() => {
59
+ if (isChecked && typeof ref !== "function" && ref?.current) {
60
+ ref.current.focus();
61
+ }
62
+ }, [isChecked]);
63
+
64
+ const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
65
+ if (event.key === "Enter" || event.key === " ") {
66
+ onChange(value);
67
+ }
68
+ if (
69
+ event.key === "ArrowRight" ||
70
+ event.key === "ArrowDown" ||
71
+ event.key === "ArrowLeft" ||
72
+ event.key === "ArrowUp"
73
+ ) {
74
+ const nextRadioCard = event.currentTarget
75
+ .nextElementSibling as HTMLElement;
76
+ nextRadioCard.focus();
77
+ }
81
78
  };
82
79
 
83
80
  return (
84
- <Box as="label" htmlFor={id} aria-label={String(children)} ref={ref}>
81
+ <Box as="label" aria-label={String(children)} onKeyDown={handleKeyDown}>
85
82
  <chakra.input
86
83
  type="radio"
87
- id={id}
84
+ id={radioCardId}
85
+ ref={ref}
86
+ value={value}
87
+ name={name}
88
88
  checked={isChecked}
89
- onChange={handleChange}
90
- {...props}
91
- sx={styles.radioInput}
89
+ onChange={() => onChange(value)}
90
+ disabled={isDisabled}
91
+ __css={styles.radioInput}
92
92
  />
93
93
  <Box
94
94
  {...props}
95
- __css={{
96
- ...styles.container,
97
- ...(isChecked && styles.checked),
98
- }}
95
+ tabIndex={0}
96
+ ref={ref}
97
+ role="radio"
98
+ aria-checked={isChecked}
99
+ aria-labelledby={radioCardId}
100
+ __css={{ ...styles.container, ...(isChecked && styles.checked) }}
101
+ data-checked={isChecked}
102
+ data-disabled={isDisabled}
99
103
  >
100
104
  {children}
101
105
  </Box>
@@ -1,120 +1,76 @@
1
- import {
2
- useRadioGroup,
3
- RadioGroupProps,
4
- StackDirection,
5
- Stack,
6
- } from "@chakra-ui/react";
7
- import React from "react";
8
- import { RadioCard, RadioCardProps } from "./RadioCard";
9
-
10
- type RadioCardGroupProps = RadioGroupProps & {
11
- children: React.ReactNode;
12
- props?: RadioGroupProps;
13
- /** Defaults to "row" */
14
- direction?: StackDirection;
15
- /** Defaults to "base" */
16
- variant?: string;
17
- /** The name of the radio group */
18
- name?: string;
19
- /** The default value of the radio group */
20
- defaultValue?: string;
21
- /** The callback function to be called when the radio group value changes */
22
- onChange?: (value: string) => void;
23
- };
1
+ import { BoxProps, Stack } from "@chakra-ui/react";
2
+ import React, { useState } from "react";
3
+ import { FormLabel } from "../input";
4
+ import { RadioCard } from "./RadioCard";
24
5
 
25
6
  /**
26
- * Radio card groups are used to group several radio cards together.
27
- *
28
- * You can and should pass the common `name` prop to the `RadioGroup`, instead of to each `Radio` component.
29
- *
30
- * ```tsx
31
- * <RadioCardGroup name="ticket">
32
- * <RadioCard>Economy</RadioCard>
33
- * <RadioCard>Business</RadioCard>
34
- * <RadioCard>First Class</RadioCard>
35
- * </RadioCardGroup>
36
- * ```
7
+ * RadioCardGroupContext is used to pass down the state and handlers to the RadioCard components.
37
8
  *
38
- * By default, radio cards show up horizontally. If you want them to show up vertically, please specify the `direction="column"` prop.
39
- *
40
- * ```tsx
41
- * <RadioCardGroup name="ticket" direction="column">
42
- * <RadioCard>Economy</RadioCard>
43
- * <RadioCard>Business</RadioCard>
44
- * <RadioCard>First Class</RadioCard>
45
- * </RadioCardGroup>
46
- * ```
47
- *
48
- * You can also specify the `defaultValue` prop to set the default value of the radio group.
49
- *
50
- * ```tsx
51
- * <RadioCardGroup name="ticket" defaultValue="Economy">
52
- * <RadioCard>Economy</RadioCard>
53
- * <RadioCard>Business</RadioCard>
54
- * <RadioCard>First Class</RadioCard>
55
- * </RadioCardGroup>
56
- * ```
57
- *
58
- * Check out RadioCard for more information on how to style the radio cards.
59
9
  * @see RadioCard
60
10
  */
61
11
 
62
- export const RadioCardGroup = ({
12
+ type RadioGroupContextProps = {
13
+ name: string;
14
+ selectedValue: string;
15
+ onChange: (value: string) => void;
16
+ variant?: "base" | "floating";
17
+ defaultValue?: string;
18
+ };
19
+
20
+ export const RadioCardGroupContext =
21
+ React.createContext<RadioGroupContextProps | null>(null);
22
+
23
+ type RadioCardGroupProps = BoxProps & {
24
+ name: string;
25
+ children: React.ReactNode;
26
+ variant?: "base" | "floating";
27
+ direction?: "row" | "column";
28
+ groupLabel?: string;
29
+ defaultValue?: string;
30
+ };
31
+
32
+ export const RadioCardGroup: React.FC<RadioCardGroupProps> = ({
63
33
  children,
64
34
  name,
35
+ variant = "base",
65
36
  direction = "row",
66
- onChange,
37
+ groupLabel,
67
38
  defaultValue,
68
- variant = "base",
69
39
  ...props
70
40
  }: RadioCardGroupProps) => {
71
- const { getRootProps, getRadioProps } = useRadioGroup({
72
- defaultValue: defaultValue,
73
- name: name,
74
- onChange: onChange,
75
- ...props,
76
- });
41
+ const [selectedValue, setSelectedValue] = useState<string>(
42
+ defaultValue || "",
43
+ );
77
44
 
78
- const rootProps = getRootProps();
45
+ const handleChange = (value: string) => {
46
+ setSelectedValue(value);
47
+ };
79
48
 
80
49
  return (
81
- <Stack direction={direction} {...rootProps}>
82
- {recursiveMap(children, (child: React.ReactElement) => {
83
- if (child.type === RadioCard) {
84
- const radioProps = getRadioProps({ value: child.props.value });
85
- const variantValue = variant as "base" | "floating" | undefined;
86
- return React.cloneElement(
87
- child as React.ReactElement<RadioCardProps>,
88
- {
89
- ...radioProps,
90
- variant: variantValue,
91
- ...props,
92
- },
93
- );
94
- }
95
- return child;
96
- })}
97
- </Stack>
50
+ <RadioCardGroupContext.Provider
51
+ value={{
52
+ name,
53
+ selectedValue,
54
+ onChange: handleChange,
55
+ variant,
56
+ defaultValue: defaultValue || "",
57
+ }}
58
+ >
59
+ <Stack
60
+ as="fieldset"
61
+ direction={direction}
62
+ aria-labelledby={groupLabel || name}
63
+ role="radiogroup"
64
+ tabIndex={0}
65
+ {...props}
66
+ >
67
+ {groupLabel && (
68
+ <FormLabel as="legend" id={groupLabel}>
69
+ {groupLabel}
70
+ </FormLabel>
71
+ )}
72
+ {children}
73
+ </Stack>
74
+ </RadioCardGroupContext.Provider>
98
75
  );
99
76
  };
100
-
101
- function recursiveMap(
102
- children: React.ReactNode,
103
- fn: (child: React.ReactElement) => React.ReactElement,
104
- ): React.ReactNode {
105
- return React.Children.map(children, (child) => {
106
- // If this child is a React element and has children, recurse
107
- if (React.isValidElement(child) && child.props.children) {
108
- child = React.cloneElement(child as React.ReactElement<any>, {
109
- children: recursiveMap(child.props.children, fn),
110
- });
111
- }
112
-
113
- // Apply the function to the child (if it's a React element)
114
- if (React.isValidElement(child)) {
115
- return fn(child);
116
- }
117
-
118
- return child;
119
- });
120
- }
@@ -1,11 +1,8 @@
1
- import {
2
- createMultiStyleConfigHelpers,
3
- defineStyleConfig,
4
- } from "@chakra-ui/react";
1
+ import { createMultiStyleConfigHelpers } from "@chakra-ui/react";
5
2
  import { baseBackground, baseBorder, baseText } from "../utils/base-utils";
6
3
  import { floatingBackground, floatingBorder } from "../utils/floating-utils";
7
4
  import { focusVisibleStyles } from "../utils/focus-utils";
8
- import { anatomy } from "@chakra-ui/theme-tools";
5
+ import { anatomy, mode } from "@chakra-ui/theme-tools";
9
6
  import { outlineBorder } from "../utils/outline-utils";
10
7
 
11
8
  const parts = anatomy("radio-card").parts("container", "checked", "radioInput");
@@ -14,7 +11,6 @@ const helpers = createMultiStyleConfigHelpers(parts.keys);
14
11
  const config = helpers.defineMultiStyleConfig({
15
12
  baseStyle: (props: any) => ({
16
13
  container: {
17
- appearance: "none",
18
14
  border: "none",
19
15
  overflow: "hidden",
20
16
  fontSize: "inherit",
@@ -57,6 +53,9 @@ const config = helpers.defineMultiStyleConfig({
57
53
  ...baseBackground("active", props),
58
54
  ...baseBorder("active", props),
59
55
  },
56
+ _focus: {
57
+ ...outlineBorder("focus", props),
58
+ },
60
59
  },
61
60
  checked: {
62
61
  _hover: {
@@ -66,12 +65,16 @@ const config = helpers.defineMultiStyleConfig({
66
65
  ...baseBackground("active", props),
67
66
  ...baseBorder("active", props),
68
67
  },
68
+ _focus: {
69
+ outline: "4px solid",
70
+ outlineStyle: "double",
71
+ ...outlineBorder("focus", props),
72
+ outlineOffset: "-1px",
73
+ },
69
74
  },
70
75
  }),
71
76
  floating: (props) => ({
72
77
  container: {
73
- ...baseText("default", props),
74
- ...baseBackground("default", props),
75
78
  ...floatingBackground("default", props),
76
79
  ...floatingBorder("default", props),
77
80
  boxShadow: "sm",
@@ -84,17 +87,25 @@ const config = helpers.defineMultiStyleConfig({
84
87
  ...floatingBackground("active", props),
85
88
  ...floatingBorder("active", props),
86
89
  },
90
+ _focus: {
91
+ ...outlineBorder("focus", props),
92
+ },
87
93
  },
88
94
  checked: {
89
- cursor: "normal",
90
-
91
95
  _hover: {
92
96
  ...floatingBorder("hover", props),
97
+ boxShadow: "md",
93
98
  },
94
99
  _active: {
95
100
  ...floatingBackground("active", props),
96
101
  ...floatingBorder("active", props),
97
102
  },
103
+ _focus: {
104
+ outline: "4px solid",
105
+ outlineStyle: "double",
106
+ ...outlineBorder("focus", props),
107
+ outlineOffset: "-1px",
108
+ },
98
109
  },
99
110
  }),
100
111
  },