@navikt/ds-react 8.9.0 → 8.9.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.
Files changed (107) hide show
  1. package/cjs/data/drag-and-drop/drag-handler/DragAndDropDragHandler.d.ts +1 -0
  2. package/cjs/data/drag-and-drop/drag-handler/DragAndDropDragHandler.js +5 -3
  3. package/cjs/data/drag-and-drop/drag-handler/DragAndDropDragHandler.js.map +1 -1
  4. package/cjs/data/drag-and-drop/item/DragAndDropItem.d.ts +4 -0
  5. package/cjs/data/drag-and-drop/item/DragAndDropItem.js +3 -7
  6. package/cjs/data/drag-and-drop/item/DragAndDropItem.js.map +1 -1
  7. package/cjs/data/drag-and-drop/root/DragAndDrop.context.d.ts +2 -1
  8. package/cjs/data/drag-and-drop/root/DragAndDrop.context.js.map +1 -1
  9. package/cjs/data/drag-and-drop/root/DragAndDropRoot.d.ts +12 -10
  10. package/cjs/data/drag-and-drop/root/DragAndDropRoot.js +71 -39
  11. package/cjs/data/drag-and-drop/root/DragAndDropRoot.js.map +1 -1
  12. package/cjs/data/table/helpers/selection/getMultipleSelectProps.d.ts +3 -3
  13. package/cjs/data/table/helpers/selection/getMultipleSelectProps.js +4 -4
  14. package/cjs/data/table/helpers/selection/getMultipleSelectProps.js.map +1 -1
  15. package/cjs/data/table/helpers/selection/getSingleSelectProps.d.ts +2 -2
  16. package/cjs/data/table/helpers/selection/getSingleSelectProps.js +4 -1
  17. package/cjs/data/table/helpers/selection/getSingleSelectProps.js.map +1 -1
  18. package/cjs/data/table/helpers/selection/selection.types.d.ts +5 -5
  19. package/cjs/data/table/root/DataTableAuto.js +9 -11
  20. package/cjs/data/table/root/DataTableAuto.js.map +1 -1
  21. package/cjs/data/table/td/DataTableTd.d.ts +4 -0
  22. package/cjs/data/table/td/DataTableTd.js +4 -2
  23. package/cjs/data/table/td/DataTableTd.js.map +1 -1
  24. package/cjs/data/table/th/DataTableTh.d.ts +4 -0
  25. package/cjs/data/table/th/DataTableTh.js +6 -3
  26. package/cjs/data/table/th/DataTableTh.js.map +1 -1
  27. package/cjs/data/token-filter/FilterChip.d.ts +10 -0
  28. package/cjs/data/token-filter/FilterChip.js +65 -0
  29. package/cjs/data/token-filter/FilterChip.js.map +1 -0
  30. package/cjs/data/token-filter/TokenFilter.js +3 -10
  31. package/cjs/data/token-filter/TokenFilter.js.map +1 -1
  32. package/cjs/form/checkbox/Checkbox.js +19 -33
  33. package/cjs/form/checkbox/Checkbox.js.map +1 -1
  34. package/cjs/form/checkbox/checkbox-input/CheckboxInput.d.ts +21 -0
  35. package/cjs/form/checkbox/checkbox-input/CheckboxInput.js +65 -0
  36. package/cjs/form/checkbox/checkbox-input/CheckboxInput.js.map +1 -0
  37. package/cjs/form/checkbox/types.d.ts +1 -1
  38. package/cjs/form/fieldset/Fieldset.js +2 -6
  39. package/cjs/form/fieldset/Fieldset.js.map +1 -1
  40. package/cjs/form/radio/Radio.js +9 -7
  41. package/cjs/form/radio/Radio.js.map +1 -1
  42. package/cjs/form/radio/radio-input/RadioInput.d.ts +19 -0
  43. package/cjs/form/radio/radio-input/RadioInput.js +55 -0
  44. package/cjs/form/radio/radio-input/RadioInput.js.map +1 -0
  45. package/esm/data/drag-and-drop/drag-handler/DragAndDropDragHandler.d.ts +1 -0
  46. package/esm/data/drag-and-drop/drag-handler/DragAndDropDragHandler.js +5 -3
  47. package/esm/data/drag-and-drop/drag-handler/DragAndDropDragHandler.js.map +1 -1
  48. package/esm/data/drag-and-drop/item/DragAndDropItem.d.ts +4 -0
  49. package/esm/data/drag-and-drop/item/DragAndDropItem.js +3 -7
  50. package/esm/data/drag-and-drop/item/DragAndDropItem.js.map +1 -1
  51. package/esm/data/drag-and-drop/root/DragAndDrop.context.d.ts +2 -1
  52. package/esm/data/drag-and-drop/root/DragAndDrop.context.js.map +1 -1
  53. package/esm/data/drag-and-drop/root/DragAndDropRoot.d.ts +12 -10
  54. package/esm/data/drag-and-drop/root/DragAndDropRoot.js +71 -39
  55. package/esm/data/drag-and-drop/root/DragAndDropRoot.js.map +1 -1
  56. package/esm/data/table/helpers/selection/getMultipleSelectProps.d.ts +3 -3
  57. package/esm/data/table/helpers/selection/getMultipleSelectProps.js +4 -4
  58. package/esm/data/table/helpers/selection/getMultipleSelectProps.js.map +1 -1
  59. package/esm/data/table/helpers/selection/getSingleSelectProps.d.ts +2 -2
  60. package/esm/data/table/helpers/selection/getSingleSelectProps.js +4 -1
  61. package/esm/data/table/helpers/selection/getSingleSelectProps.js.map +1 -1
  62. package/esm/data/table/helpers/selection/selection.types.d.ts +5 -5
  63. package/esm/data/table/root/DataTableAuto.js +9 -11
  64. package/esm/data/table/root/DataTableAuto.js.map +1 -1
  65. package/esm/data/table/td/DataTableTd.d.ts +4 -0
  66. package/esm/data/table/td/DataTableTd.js +4 -2
  67. package/esm/data/table/td/DataTableTd.js.map +1 -1
  68. package/esm/data/table/th/DataTableTh.d.ts +4 -0
  69. package/esm/data/table/th/DataTableTh.js +6 -3
  70. package/esm/data/table/th/DataTableTh.js.map +1 -1
  71. package/esm/data/token-filter/FilterChip.d.ts +10 -0
  72. package/esm/data/token-filter/FilterChip.js +30 -0
  73. package/esm/data/token-filter/FilterChip.js.map +1 -0
  74. package/esm/data/token-filter/TokenFilter.js +3 -10
  75. package/esm/data/token-filter/TokenFilter.js.map +1 -1
  76. package/esm/form/checkbox/Checkbox.js +19 -33
  77. package/esm/form/checkbox/Checkbox.js.map +1 -1
  78. package/esm/form/checkbox/checkbox-input/CheckboxInput.d.ts +21 -0
  79. package/esm/form/checkbox/checkbox-input/CheckboxInput.js +29 -0
  80. package/esm/form/checkbox/checkbox-input/CheckboxInput.js.map +1 -0
  81. package/esm/form/checkbox/types.d.ts +1 -1
  82. package/esm/form/fieldset/Fieldset.js +2 -6
  83. package/esm/form/fieldset/Fieldset.js.map +1 -1
  84. package/esm/form/radio/Radio.js +9 -7
  85. package/esm/form/radio/Radio.js.map +1 -1
  86. package/esm/form/radio/radio-input/RadioInput.d.ts +19 -0
  87. package/esm/form/radio/radio-input/RadioInput.js +19 -0
  88. package/esm/form/radio/radio-input/RadioInput.js.map +1 -0
  89. package/package.json +3 -3
  90. package/src/data/drag-and-drop/drag-handler/DragAndDropDragHandler.tsx +7 -3
  91. package/src/data/drag-and-drop/item/DragAndDropItem.tsx +15 -11
  92. package/src/data/drag-and-drop/root/DragAndDrop.context.tsx +4 -2
  93. package/src/data/drag-and-drop/root/DragAndDropRoot.tsx +94 -45
  94. package/src/data/table/helpers/selection/getMultipleSelectProps.ts +7 -7
  95. package/src/data/table/helpers/selection/getSingleSelectProps.ts +6 -3
  96. package/src/data/table/helpers/selection/selection.types.ts +5 -5
  97. package/src/data/table/root/DataTableAuto.tsx +25 -15
  98. package/src/data/table/td/DataTableTd.tsx +15 -2
  99. package/src/data/table/th/DataTableTh.tsx +13 -2
  100. package/src/data/token-filter/FilterChip.tsx +100 -0
  101. package/src/data/token-filter/TokenFilter.tsx +8 -24
  102. package/src/form/checkbox/Checkbox.tsx +37 -64
  103. package/src/form/checkbox/checkbox-input/CheckboxInput.tsx +69 -0
  104. package/src/form/checkbox/types.ts +1 -1
  105. package/src/form/fieldset/Fieldset.tsx +4 -6
  106. package/src/form/radio/Radio.tsx +43 -38
  107. package/src/form/radio/radio-input/RadioInput.tsx +32 -0
@@ -3,93 +3,66 @@ import { BodyShort } from "../../typography";
3
3
  import { omit, useId } from "../../utils-external";
4
4
  import { cl } from "../../utils/helpers";
5
5
  import { ReadOnlyIconWithTitle } from "../ReadOnlyIcon";
6
+ import { CheckboxInput } from "./checkbox-input/CheckboxInput";
6
7
  import { CheckboxProps } from "./types";
7
8
  import useCheckbox from "./useCheckbox";
8
9
 
9
10
  export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
10
- (props, ref) => {
11
+ (props: CheckboxProps, forwardedRef) => {
11
12
  const { inputProps, hasError, size, readOnly, nested } = useCheckbox(props);
12
13
  const descriptionId = useId();
13
14
 
15
+ const { className, description, children, indeterminate, hideLabel } =
16
+ props;
17
+
14
18
  return (
15
19
  <div
16
- className={cl(
17
- props.className,
18
- "aksel-checkbox",
19
- `aksel-checkbox--${size}`,
20
- {
21
- "aksel-checkbox--error": hasError,
22
- "aksel-checkbox--disabled": inputProps.disabled,
23
- "aksel-checkbox--readonly": readOnly,
24
- },
25
- )}
20
+ className={cl(className, "aksel-checkbox", `aksel-checkbox--${size}`, {
21
+ "aksel-checkbox--error": hasError,
22
+ "aksel-checkbox--disabled": inputProps.disabled,
23
+ "aksel-checkbox--readonly": readOnly,
24
+ })}
26
25
  data-color={hasError ? "danger" : props["data-color"]}
27
26
  >
28
- <div className="aksel-checkbox__input-wrapper">
29
- <input
30
- {...omit(props, [
31
- "children",
32
- "size",
33
- "error",
34
- "description",
35
- "hideLabel",
36
- "indeterminate",
37
- "errorId",
38
- "readOnly",
39
- ])}
40
- {...omit(inputProps, ["aria-invalid", "aria-describedby"])}
41
- aria-describedby={
42
- cl(inputProps["aria-describedby"], {
43
- [descriptionId]: props.description,
44
- }) || undefined
45
- }
46
- type="checkbox"
47
- className="aksel-checkbox__input"
48
- ref={(el) => {
49
- if (el) {
50
- el.indeterminate = props.indeterminate ?? false;
51
- }
52
-
53
- if (typeof ref === "function") {
54
- ref(el);
55
- } else if (ref != null) {
56
- ref.current = el;
57
- }
58
- }}
59
- />
60
- <svg
61
- xmlns="http://www.w3.org/2000/svg"
62
- viewBox="0 0 13 10"
63
- fill="none"
64
- focusable={false}
65
- role="img"
66
- aria-hidden
67
- className="aksel-checkbox__icon"
68
- >
69
- <path
70
- d="M4.03524 6.41478L10.4752 0.404669C11.0792 -0.160351 12.029 -0.130672 12.5955 0.47478C13.162 1.08027 13.1296 2.03007 12.5245 2.59621L5.02111 9.59934C4.74099 9.85904 4.37559 10 4.00025 10C3.60651 10 3.22717 9.84621 2.93914 9.56111L0.439143 7.06111C-0.146381 6.47558 -0.146381 5.52542 0.439143 4.93989C1.02467 4.35437 1.97483 4.35437 2.56036 4.93989L4.03524 6.41478Z"
71
- fill="currentColor"
72
- />
73
- </svg>
74
- </div>
27
+ <CheckboxInput
28
+ ref={forwardedRef}
29
+ {...omit(props, [
30
+ "children",
31
+ "size",
32
+ "error",
33
+ "description",
34
+ "hideLabel",
35
+ "indeterminate",
36
+ "errorId",
37
+ "readOnly",
38
+ ])}
39
+ {...omit(inputProps, ["aria-invalid", "aria-describedby"])}
40
+ aria-describedby={
41
+ cl(inputProps["aria-describedby"], {
42
+ [descriptionId]: description,
43
+ }) || undefined
44
+ }
45
+ indeterminate={indeterminate ?? false}
46
+ standalone={false}
47
+ />
75
48
  <BodyShort
76
49
  as="label"
77
50
  htmlFor={inputProps.id}
78
51
  size={size}
79
- className={cl("aksel-checkbox__label", {
80
- "aksel-sr-only": props.hideLabel,
81
- })}
52
+ className="aksel-checkbox__label"
53
+ visuallyHidden={hideLabel}
82
54
  >
83
55
  {!nested && readOnly && <ReadOnlyIconWithTitle />}
84
- {props.children}
56
+ {children}
85
57
  </BodyShort>
86
- {props.description && (
58
+ {description && (
87
59
  <BodyShort
88
60
  id={descriptionId}
89
61
  size={size}
90
62
  className="aksel-form-field__subdescription aksel-checkbox__description"
63
+ visuallyHidden={hideLabel}
91
64
  >
92
- {props.description}
65
+ {description}
93
66
  </BodyShort>
94
67
  )}
95
68
  </div>
@@ -0,0 +1,69 @@
1
+ import React, { forwardRef, useCallback } from "react";
2
+ import { cl } from "../../../utils/helpers";
3
+ import { useMergeRefs } from "../../../utils/hooks";
4
+
5
+ type CheckboxInputProps = React.InputHTMLAttributes<HTMLInputElement> & {
6
+ indeterminate?: boolean;
7
+ children?: never;
8
+ standalone?: boolean;
9
+ /**
10
+ * Reduces pseudo-element target-size.
11
+ */
12
+ compact?: boolean;
13
+ };
14
+
15
+ const CheckboxInput = forwardRef<HTMLInputElement, CheckboxInputProps>(
16
+ (
17
+ {
18
+ className,
19
+ indeterminate,
20
+ standalone = true,
21
+ compact,
22
+ ...rest
23
+ }: CheckboxInputProps,
24
+ forwardedRef,
25
+ ) => {
26
+ const indeterminateRef = useCallback(
27
+ (el: HTMLInputElement | null) => {
28
+ if (el) {
29
+ el.indeterminate = indeterminate ?? false;
30
+ }
31
+ },
32
+ [indeterminate],
33
+ );
34
+
35
+ const mergedRef = useMergeRefs(indeterminateRef, forwardedRef);
36
+
37
+ return (
38
+ <div
39
+ className="aksel-checkbox__input-wrapper"
40
+ data-standalone={standalone}
41
+ data-compact={compact}
42
+ >
43
+ <input
44
+ {...rest}
45
+ className={cl("aksel-checkbox__input", className)}
46
+ type="checkbox"
47
+ ref={mergedRef}
48
+ />
49
+ <svg
50
+ xmlns="http://www.w3.org/2000/svg"
51
+ viewBox="0 0 13 10"
52
+ fill="none"
53
+ focusable={false}
54
+ role="img"
55
+ aria-hidden
56
+ className="aksel-checkbox__icon"
57
+ >
58
+ <path
59
+ d="M4.03524 6.41478L10.4752 0.404669C11.0792 -0.160351 12.029 -0.130672 12.5955 0.47478C13.162 1.08027 13.1296 2.03007 12.5245 2.59621L5.02111 9.59934C4.74099 9.85904 4.37559 10 4.00025 10C3.60651 10 3.22717 9.84621 2.93914 9.56111L0.439143 7.06111C-0.146381 6.47558 -0.146381 5.52542 0.439143 4.93989C1.02467 4.35437 1.97483 4.35437 2.56036 4.93989L4.03524 6.41478Z"
60
+ fill="currentColor"
61
+ />
62
+ </svg>
63
+ </div>
64
+ );
65
+ },
66
+ );
67
+
68
+ export { CheckboxInput };
69
+ export type { CheckboxInputProps };
@@ -19,7 +19,7 @@ export interface CheckboxProps
19
19
  */
20
20
  children: React.ReactNode;
21
21
  /**
22
- * Hides label and makes it viewable for screen-readers only.
22
+ * Visually hides label and description, and makes it viewable for screen-readers only.
23
23
  */
24
24
  hideLabel?: boolean;
25
25
  /**
@@ -108,9 +108,8 @@ export const Fieldset = forwardRef<HTMLFieldSetElement, FieldsetProps>(
108
108
  id={legendId}
109
109
  size={size}
110
110
  as="legend"
111
- className={cl("aksel-fieldset__legend", {
112
- "aksel-sr-only": !!hideLegend,
113
- })}
111
+ className="aksel-fieldset__legend"
112
+ visuallyHidden={!!hideLegend}
114
113
  >
115
114
  {readOnly &&
116
115
  (_fieldsSupportNativeReadOnly ? (
@@ -122,9 +121,8 @@ export const Fieldset = forwardRef<HTMLFieldSetElement, FieldsetProps>(
122
121
  </Label>
123
122
  {!!description && (
124
123
  <BodyShort
125
- className={cl("aksel-fieldset__description", {
126
- "aksel-sr-only": !!hideLegend,
127
- })}
124
+ className="aksel-fieldset__description"
125
+ visuallyHidden={!!hideLegend}
128
126
  id={inputDescriptionId}
129
127
  size={size ?? "medium"}
130
128
  as="div"
@@ -2,52 +2,57 @@ import React, { forwardRef } from "react";
2
2
  import { BodyShort } from "../../typography";
3
3
  import { omit, useId } from "../../utils-external";
4
4
  import { cl } from "../../utils/helpers";
5
+ import { RadioInput } from "./radio-input/RadioInput";
5
6
  import { RadioProps } from "./types";
6
7
  import { useRadio } from "./useRadio";
7
8
 
8
- export const Radio = forwardRef<HTMLInputElement, RadioProps>((props, ref) => {
9
- const { inputProps, size, hasError, readOnly } = useRadio(props);
10
- const descriptionId = useId();
9
+ export const Radio = forwardRef<HTMLInputElement, RadioProps>(
10
+ (props: RadioProps, forwardedRef) => {
11
+ const { inputProps, size, hasError, readOnly } = useRadio(props);
12
+ const descriptionId = useId();
11
13
 
12
- return (
13
- <div
14
- className={cl(props.className, "aksel-radio", `aksel-radio--${size}`, {
15
- "aksel-radio--error": hasError,
16
- "aksel-radio--disabled": inputProps.disabled,
17
- "aksel-radio--readonly": readOnly,
18
- })}
19
- data-color={hasError ? "danger" : props["data-color"]}
20
- >
21
- <input
22
- {...omit(props, ["children", "size", "description", "readOnly"])}
23
- {...omit(inputProps, ["aria-invalid", "aria-describedby"])}
24
- aria-describedby={
25
- cl(inputProps["aria-describedby"], {
26
- [descriptionId]: props.description,
27
- }) || undefined
28
- }
29
- className="aksel-radio__input"
30
- ref={ref}
31
- />
32
- <BodyShort
33
- as="label"
34
- htmlFor={inputProps.id}
35
- className="aksel-radio__label"
36
- size={size}
14
+ const { className, description, children } = props;
15
+
16
+ return (
17
+ <div
18
+ className={cl(className, "aksel-radio", `aksel-radio--${size}`, {
19
+ "aksel-radio--error": hasError,
20
+ "aksel-radio--disabled": inputProps.disabled,
21
+ "aksel-radio--readonly": readOnly,
22
+ })}
23
+ data-color={hasError ? "danger" : props["data-color"]}
37
24
  >
38
- {props.children}
39
- </BodyShort>
40
- {props.description && (
25
+ <RadioInput
26
+ ref={forwardedRef}
27
+ {...omit(props, ["children", "size", "description", "readOnly"])}
28
+ {...omit(inputProps, ["aria-invalid", "aria-describedby"])}
29
+ aria-describedby={
30
+ cl(inputProps["aria-describedby"], {
31
+ [descriptionId]: description,
32
+ }) || undefined
33
+ }
34
+ standalone={false}
35
+ />
41
36
  <BodyShort
42
- id={descriptionId}
37
+ as="label"
38
+ htmlFor={inputProps.id}
39
+ className="aksel-radio__label"
43
40
  size={size}
44
- className="aksel-form-field__subdescription aksel-radio__description"
45
41
  >
46
- {props.description}
42
+ {children}
47
43
  </BodyShort>
48
- )}
49
- </div>
50
- );
51
- });
44
+ {description && (
45
+ <BodyShort
46
+ id={descriptionId}
47
+ size={size}
48
+ className="aksel-form-field__subdescription aksel-radio__description"
49
+ >
50
+ {description}
51
+ </BodyShort>
52
+ )}
53
+ </div>
54
+ );
55
+ },
56
+ );
52
57
 
53
58
  export default Radio;
@@ -0,0 +1,32 @@
1
+ import React, { forwardRef } from "react";
2
+ import { cl } from "../../../utils/helpers";
3
+
4
+ type RadioInputProps = React.InputHTMLAttributes<HTMLInputElement> & {
5
+ children?: never;
6
+ standalone?: boolean;
7
+ /**
8
+ * Reduces pseudo-element target-size.
9
+ */
10
+ compact?: boolean;
11
+ };
12
+
13
+ const RadioInput = forwardRef<HTMLInputElement, RadioInputProps>(
14
+ (
15
+ { className, standalone = true, compact, ...rest }: RadioInputProps,
16
+ forwardedRef,
17
+ ) => {
18
+ return (
19
+ <input
20
+ {...rest}
21
+ ref={forwardedRef}
22
+ className={cl("aksel-radio__input", className)}
23
+ data-standalone={standalone}
24
+ data-compact={compact}
25
+ type="radio"
26
+ />
27
+ );
28
+ },
29
+ );
30
+
31
+ export { RadioInput };
32
+ export type { RadioInputProps };