@vygruppen/spor-react 12.8.7 → 12.8.8

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.8.7",
4
+ "version": "12.8.8",
5
5
  "exports": {
6
6
  ".": {
7
7
  "types": "./dist/index.d.ts",
@@ -47,8 +47,8 @@
47
47
  "react-swipeable": "^7.0.1",
48
48
  "usehooks-ts": "^3.1.0",
49
49
  "@vygruppen/spor-design-tokens": "4.0.7",
50
- "@vygruppen/spor-icon-react": "4.2.1",
51
- "@vygruppen/spor-loader": "0.7.0"
50
+ "@vygruppen/spor-loader": "0.7.0",
51
+ "@vygruppen/spor-icon-react": "4.2.1"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@react-types/datepicker": "^3.10.0",
@@ -67,8 +67,8 @@
67
67
  "vitest": "^0.26.3",
68
68
  "vitest-axe": "^0.1.0",
69
69
  "vitest-canvas-mock": "^0.2.2",
70
- "@vygruppen/tsconfig": "0.1.1",
71
- "@vygruppen/eslint-config": "1.1.1"
70
+ "@vygruppen/eslint-config": "1.1.1",
71
+ "@vygruppen/tsconfig": "0.1.1"
72
72
  },
73
73
  "peerDependencies": {
74
74
  "react": ">=18.0.0 <19.0.0",
@@ -130,6 +130,7 @@ export const DatePicker = forwardRef<HTMLDivElement, DatePickerProps>(
130
130
  errorText={errorText}
131
131
  invalid={invalid}
132
132
  helperText={helperText}
133
+ required={props.required}
133
134
  >
134
135
  <PopoverAnchor>
135
136
  <StyledField
@@ -127,6 +127,7 @@ type DateRangePickerProps = Omit<
127
127
  errorText={errorText}
128
128
  helperText={helperText}
129
129
  invalid={invalid}
130
+ required={props.required}
130
131
  >
131
132
  <PopoverAnchor>
132
133
  <StyledField
@@ -80,11 +80,21 @@ export const Field = React.forwardRef<HTMLDivElement, FieldProps>(
80
80
  css={styles.root}
81
81
  direction={direction}
82
82
  >
83
- {label && !floatingLabel && <Label>{label}</Label>}
83
+ {label && !floatingLabel && (
84
+ <Label>
85
+ {label}
86
+ <ChakraField.RequiredIndicator />
87
+ </Label>
88
+ )}
84
89
 
85
90
  {children}
86
91
 
87
- {label && floatingLabel && <FloatingLabel>{label}</FloatingLabel>}
92
+ {label && floatingLabel && (
93
+ <FloatingLabel>
94
+ {label}
95
+ <ChakraField.RequiredIndicator />
96
+ </FloatingLabel>
97
+ )}
88
98
  {errorText && (
89
99
  <ChakraField.ErrorText>{errorText}</ChakraField.ErrorText>
90
100
  )}
@@ -64,6 +64,7 @@ export const Input = forwardRef<HTMLInputElement, InputProps>(
64
64
  invalid,
65
65
  helperText,
66
66
  errorText,
67
+ required,
67
68
  ...props
68
69
  },
69
70
  ref,
@@ -76,6 +77,7 @@ export const Input = forwardRef<HTMLInputElement, InputProps>(
76
77
  <Field
77
78
  invalid={invalid}
78
79
  helperText={helperText}
80
+ required={required}
79
81
  errorText={errorText}
80
82
  label={
81
83
  // Render startElement invisibly to align label text with input content when an icon is present
@@ -72,7 +72,12 @@ export const Select = React.forwardRef<HTMLDivElement, SelectProps>(
72
72
  const styles = recipe({ variant });
73
73
 
74
74
  return (
75
- <Field errorText={errorText} invalid={invalid} helperText={helperText}>
75
+ <Field
76
+ errorText={errorText}
77
+ invalid={invalid}
78
+ helperText={helperText}
79
+ required={props.required}
80
+ >
76
81
  <ChakraSelect.Root
77
82
  {...rest}
78
83
  ref={ref}
@@ -65,6 +65,7 @@ export const Switch = forwardRef<HTMLInputElement, SwitchProps>(
65
65
  invalid={invalid}
66
66
  errorText={errorText}
67
67
  helperText={helperText}
68
+ required={props.required}
68
69
  >
69
70
  <ChakraSwitch.Root
70
71
  ref={rootRef}
@@ -16,6 +16,9 @@ export const fieldSlotRecipe = defineSlotRecipe({
16
16
  marginStart: 1,
17
17
  color: "brightRed",
18
18
  },
19
+ label: {
20
+ display: "flex",
21
+ },
19
22
  helperText: {
20
23
  marginTop: 2,
21
24
  color: "text.tertiary",
@@ -4,7 +4,7 @@ import {
4
4
  HeadingProps as ChakraHeadingProps,
5
5
  Text,
6
6
  } from "@chakra-ui/react";
7
- import { forwardRef } from "react";
7
+ import { forwardRef, useId } from "react";
8
8
 
9
9
  import { slugify } from "..";
10
10
 
@@ -52,11 +52,18 @@ export const Heading = forwardRef<HTMLHeadingElement, HeadingProps>(
52
52
  ...rest
53
53
  } = props;
54
54
 
55
- const id =
56
- (externalId ?? (autoId && typeof rest.children === "string"))
57
- ? slugify(rest.children as string)
58
- : undefined;
55
+ const reactId = useId();
59
56
 
60
- return <Text as={as} textStyle={variant} id={id} ref={ref} {...rest} />;
57
+ function getId() {
58
+ if (externalId !== undefined) return externalId;
59
+ if (!autoId) return;
60
+ return typeof rest.children === "string"
61
+ ? slugify(rest.children)
62
+ : reactId;
63
+ }
64
+
65
+ return (
66
+ <Text as={as} textStyle={variant} id={getId()} ref={ref} {...rest} />
67
+ );
61
68
  },
62
69
  );