@vygruppen/spor-react 12.22.1 → 12.22.2

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vygruppen/spor-react",
3
3
  "type": "module",
4
- "version": "12.22.1",
4
+ "version": "12.22.2",
5
5
  "exports": {
6
6
  ".": {
7
7
  "types": "./dist/index.d.ts",
@@ -46,9 +46,9 @@
46
46
  "react-stately": "^3.31.1",
47
47
  "react-swipeable": "^7.0.1",
48
48
  "usehooks-ts": "^3.1.0",
49
+ "@vygruppen/spor-design-tokens": "4.3.2",
49
50
  "@vygruppen/spor-icon-react": "4.5.1",
50
- "@vygruppen/spor-loader": "0.7.0",
51
- "@vygruppen/spor-design-tokens": "4.3.2"
51
+ "@vygruppen/spor-loader": "0.7.0"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@react-types/datepicker": "^3.10.0",
@@ -68,8 +68,8 @@
68
68
  "vitest": "^0.26.3",
69
69
  "vitest-axe": "^0.1.0",
70
70
  "vitest-canvas-mock": "^0.2.2",
71
- "@vygruppen/eslint-config": "2.1.0",
72
- "@vygruppen/tsconfig": "0.1.1"
71
+ "@vygruppen/tsconfig": "0.1.1",
72
+ "@vygruppen/eslint-config": "2.1.0"
73
73
  },
74
74
  "peerDependencies": {
75
75
  "react": ">=18.0.0 <19.0.0",
@@ -13,6 +13,7 @@ import {
13
13
  WarningFill24Icon,
14
14
  } from "@vygruppen/spor-icon-react";
15
15
  import { forwardRef } from "react";
16
+ import { VisuallyHidden } from "react-aria";
16
17
 
17
18
  import { createTexts, useTranslation } from "../i18n";
18
19
  import { AlertProps } from "./Alert";
@@ -30,7 +31,10 @@ export const AlertIcon = forwardRef<SVGSVGElement, AlertIconProps>(
30
31
  const { t } = useTranslation();
31
32
 
32
33
  return (
33
- <Box ref={ref} aria-label={t(texts[variant as keyof typeof texts])}>
34
+ <Box ref={ref}>
35
+ <VisuallyHidden>
36
+ {t(texts[variant as keyof typeof texts])}
37
+ </VisuallyHidden>
34
38
  {CustomAlertIcon ? (
35
39
  <CustomAlertIcon color={`alert.${variant}.icon`} />
36
40
  ) : (
@@ -90,7 +90,7 @@ const SwitchButton = chakra(
90
90
  defineRecipe({
91
91
  base: {
92
92
  position: "absolute !important",
93
- zIndex: "docked !important",
93
+ zIndex: "101 !important",
94
94
  // eslint-disable-next-line spor/use-semantic-tokens
95
95
  bg: "bg !important",
96
96
  outlineWidth: "1px !important",
@@ -107,7 +107,7 @@ const SwitchButton = chakra(
107
107
  },
108
108
  vertical: {
109
109
  top: "calc(50% - 15px)",
110
- right: "12px",
110
+ right: "3rem",
111
111
  transform: "rotate(90deg)",
112
112
  },
113
113
  },
@@ -2,6 +2,7 @@ import {
2
2
  Combobox,
3
3
  ComboboxItemProps,
4
4
  ComboboxRootProps,
5
+ useCombobox,
5
6
  useComboboxContext,
6
7
  useFilter,
7
8
  useListCollection,
@@ -24,6 +25,8 @@ type Props = {
24
25
  leftIcon?: React.ReactNode;
25
26
  filteredExternally?: boolean;
26
27
  loading?: boolean;
28
+ emptyLabel?: React.ReactNode;
29
+ openOnFocus?: boolean;
27
30
  } & Omit<ComboboxRootProps, "collection"> &
28
31
  FieldProps;
29
32
 
@@ -40,6 +43,9 @@ export const Autocomplete = ({
40
43
  filteredExternally,
41
44
  loading,
42
45
  disabled,
46
+ emptyLabel,
47
+ openOnClick = true,
48
+ openOnFocus = true,
43
49
  ...rest
44
50
  }: Props) => {
45
51
  const { contains } = useFilter({ sensitivity: "base" });
@@ -64,26 +70,29 @@ export const Autocomplete = ({
64
70
  [children, collection.items],
65
71
  );
66
72
 
73
+ const combobox = useCombobox({
74
+ collection,
75
+ openOnClick,
76
+ onInputValueChange: (event) => {
77
+ if (!filteredExternally) {
78
+ filter(event.inputValue);
79
+ }
80
+ onInputValueChange?.(event);
81
+ },
82
+ positioning: {
83
+ placement: "bottom",
84
+ offset: {
85
+ mainAxis: 3,
86
+ crossAxis: -1,
87
+ },
88
+ flip: false,
89
+ },
90
+ disabled,
91
+ ...rest,
92
+ });
93
+
67
94
  return (
68
- <Combobox.Root
69
- {...rest}
70
- collection={collection}
71
- onInputValueChange={(event) => {
72
- if (!filteredExternally) {
73
- filter(event.inputValue);
74
- }
75
- onInputValueChange?.(event);
76
- }}
77
- positioning={{
78
- placement: "bottom",
79
- offset: {
80
- mainAxis: 3,
81
- crossAxis: -1,
82
- },
83
- flip: false,
84
- }}
85
- disabled={disabled}
86
- >
95
+ <Combobox.RootProvider value={combobox}>
87
96
  <Combobox.Control>
88
97
  <Combobox.Input asChild>
89
98
  <Input
@@ -95,17 +104,22 @@ export const Autocomplete = ({
95
104
  helperText={helperText}
96
105
  errorText={errorText}
97
106
  required={required}
107
+ onFocus={() => {
108
+ if (openOnFocus) combobox.setOpen(true);
109
+ }}
98
110
  />
99
111
  </Combobox.Input>
100
112
  <Combobox.IndicatorGroup>
101
- <Combobox.ClearTrigger asChild>
113
+ <Combobox.ClearTrigger asChild aria-label={t(texts.clearValue)}>
102
114
  <CloseButton size="xs" />
103
115
  </Combobox.ClearTrigger>
104
116
  </Combobox.IndicatorGroup>
105
117
  </Combobox.Control>
106
118
  <Combobox.Positioner>
107
119
  <Combobox.Content>
108
- <Combobox.Empty>{!loading && t(texts.noItemsFound)}</Combobox.Empty>
120
+ <Combobox.Empty>
121
+ {!loading && (emptyLabel ?? t(texts.noItemsFound))}
122
+ </Combobox.Empty>
109
123
  {loading ? (
110
124
  <ColorSpinner width="1.5rem" p="2" />
111
125
  ) : (
@@ -113,7 +127,7 @@ export const Autocomplete = ({
113
127
  )}
114
128
  </Combobox.Content>
115
129
  </Combobox.Positioner>
116
- </Combobox.Root>
130
+ </Combobox.RootProvider>
117
131
  );
118
132
  };
119
133
 
@@ -206,4 +220,10 @@ const texts = createTexts({
206
220
  sv: "Inga resultat",
207
221
  en: "No results found",
208
222
  },
223
+ clearValue: {
224
+ nb: "Tøm verdi",
225
+ nn: "Tøm verdi",
226
+ sv: "Rensa värde",
227
+ en: "Clear value",
228
+ },
209
229
  });
@@ -129,7 +129,9 @@ export const Field = React.forwardRef<HTMLDivElement, FieldProps>(
129
129
  </FloatingLabel>
130
130
  )}
131
131
  {errorText && (
132
- <ChakraField.ErrorText>{errorText}</ChakraField.ErrorText>
132
+ <ChakraField.ErrorText aria-live="polite">
133
+ {errorText}
134
+ </ChakraField.ErrorText>
133
135
  )}
134
136
  </ChakraField.Root>
135
137
  {helperText && (
@@ -19,14 +19,14 @@ const floatingLabelStyles = defineStyle({
19
19
  },
20
20
 
21
21
  pos: "absolute",
22
- transition: "position",
22
+ transition: "top 160ms ease, font-size 160ms ease",
23
23
 
24
24
  top: "0.9rem",
25
25
  color: "text",
26
26
  fontSize: ["mobile.sm", "desktop.sm"],
27
27
 
28
28
  "&[data-float]": {
29
- fontSize: ["mobile.xs", "desktop.xs"],
29
+ fontSize: ["mobile.2xs", "desktop.2xs"],
30
30
  color: "text",
31
31
  top: "0.3rem",
32
32
  },
@@ -107,7 +107,7 @@ export const Input = forwardRef<HTMLInputElement, InputProps>(
107
107
  id={props.id}
108
108
  labelAsChild={labelAsChild}
109
109
  label={
110
- <Flex fontSize={fontSize ?? "mobile.md"}>
110
+ <Flex>
111
111
  <Box visibility="hidden">{startElement}</Box>
112
112
  {label}
113
113
  </Flex>
@@ -119,6 +119,7 @@ export const Input = forwardRef<HTMLInputElement, InputProps>(
119
119
  <InputElement
120
120
  pointerEvents="none"
121
121
  paddingX={2}
122
+ aria-hidden="true"
122
123
  fontSize={fontSize ?? "mobile.md"}
123
124
  >
124
125
  {startElement}
@@ -107,7 +107,6 @@ export const NumericStepper = React.forwardRef<
107
107
  <Field
108
108
  css={styles.root}
109
109
  width="auto"
110
- id={idProperty}
111
110
  ref={ref}
112
111
  label={label}
113
112
  helperText={helperText}
@@ -133,7 +132,6 @@ export const NumericStepper = React.forwardRef<
133
132
  }
134
133
  }}
135
134
  disabled={disabled || value <= minValue}
136
- id={value <= minValue ? undefined : idProperty}
137
135
  />
138
136
  {withInput ? (
139
137
  <Input
@@ -142,7 +140,7 @@ export const NumericStepper = React.forwardRef<
142
140
  name={nameProperty}
143
141
  value={value}
144
142
  disabled={disabled}
145
- id={value === 0 ? undefined : idProperty}
143
+ id={idProperty}
146
144
  css={styles.input}
147
145
  width={`${Math.max(value.toString().length + 1, 3)}ch`}
148
146
  aria-live="assertive"
@@ -189,7 +187,6 @@ export const NumericStepper = React.forwardRef<
189
187
  )}
190
188
  onClick={() => onChange(Math.min(value + clampedStepSize, maxValue))}
191
189
  disabled={disabled || value >= maxValue}
192
- id={value >= maxValue ? undefined : idProperty}
193
190
  />
194
191
  </Field>
195
192
  );
@@ -8,12 +8,13 @@ export const attachedInputsRecipe = defineRecipe({
8
8
  "& select": {
9
9
  borderEndRadius: 0,
10
10
  },
11
+
11
12
  "& > *": {
12
13
  position: "relative",
13
- zIndex: 0,
14
+ zIndex: 100,
14
15
  },
15
16
  "& > *:focus-within": {
16
- zIndex: 1,
17
+ zIndex: 101,
17
18
  },
18
19
  },
19
20
  variants: {
@@ -16,7 +16,6 @@ export const comboboxSlotRecipe = defineSlotRecipe({
16
16
  label: {
17
17
  fontWeight: "medium",
18
18
  userSelect: "none",
19
- textStyle: "sm",
20
19
  },
21
20
 
22
21
  input: {
@@ -6,8 +6,6 @@ export const textStyles = defineTextStyles({
6
6
  value: {
7
7
  fontSize: [
8
8
  tokens.font.style.xxl["font-size"].mobile,
9
- null,
10
- null,
11
9
  tokens.font.style.xxl["font-size"].desktop,
12
10
  ],
13
11
  fontFamily: tokens.font.style.xxl["font-family"],
@@ -18,8 +16,6 @@ export const textStyles = defineTextStyles({
18
16
  value: {
19
17
  fontSize: [
20
18
  tokens.font.style["xl-display"]["font-size"].mobile,
21
- null,
22
- null,
23
19
  tokens.font.style["xl-display"]["font-size"].desktop,
24
20
  ],
25
21
  fontFamily: tokens.font.style["xl-display"]["font-family"],
@@ -30,8 +26,6 @@ export const textStyles = defineTextStyles({
30
26
  value: {
31
27
  fontSize: [
32
28
  tokens.font.style["xl-sans"]["font-size"].mobile,
33
- null,
34
- null,
35
29
  tokens.font.style["xl-sans"]["font-size"].desktop,
36
30
  ],
37
31
  fontFamily: tokens.font.style["xl-sans"]["font-family"],
@@ -42,8 +36,6 @@ export const textStyles = defineTextStyles({
42
36
  value: {
43
37
  fontSize: [
44
38
  tokens.font.style.lg["font-size"].mobile,
45
- null,
46
- null,
47
39
  tokens.font.style.lg["font-size"].desktop,
48
40
  ],
49
41
  fontFamily: tokens.font.style.lg["font-family"],
@@ -54,8 +46,6 @@ export const textStyles = defineTextStyles({
54
46
  value: {
55
47
  fontSize: [
56
48
  tokens.font.style["md-lg"]["font-size"].mobile,
57
- null,
58
- null,
59
49
  tokens.font.style["md-lg"]["font-size"].desktop,
60
50
  ],
61
51
  fontFamily: tokens.font.style["md-lg"]["font-family"],
@@ -66,8 +56,6 @@ export const textStyles = defineTextStyles({
66
56
  value: {
67
57
  fontSize: [
68
58
  tokens.font.style.md["font-size"].mobile,
69
- null,
70
- null,
71
59
  tokens.font.style.md["font-size"].desktop,
72
60
  ],
73
61
  fontFamily: tokens.font.style.md["font-family"],
@@ -78,8 +66,6 @@ export const textStyles = defineTextStyles({
78
66
  value: {
79
67
  fontSize: [
80
68
  tokens.font.style.sm["font-size"].mobile,
81
- null,
82
- null,
83
69
  tokens.font.style.sm["font-size"].desktop,
84
70
  ],
85
71
  fontFamily: tokens.font.style.sm["font-family"],
@@ -90,8 +76,6 @@ export const textStyles = defineTextStyles({
90
76
  value: {
91
77
  fontSize: [
92
78
  tokens.font.style.xs["font-size"].mobile,
93
- null,
94
- null,
95
79
  tokens.font.style.xs["font-size"].desktop,
96
80
  ],
97
81
  fontFamily: tokens.font.style.xs["font-family"],
@@ -102,8 +86,6 @@ export const textStyles = defineTextStyles({
102
86
  value: {
103
87
  fontSize: [
104
88
  tokens.font.style["2xs"]["font-size"].mobile,
105
- null,
106
- null,
107
89
  tokens.font.style["2xs"]["font-size"].desktop,
108
90
  ],
109
91
  fontFamily: tokens.font.style["2xs"]["font-family"],