@digdir/designsystemet-react 1.5.0 → 1.6.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/cjs/components/field/field-counter.js +12 -1
- package/dist/cjs/components/popover/popover.js +1 -1
- package/dist/cjs/components/toggle-group/toggle-group-item.js +2 -2
- package/dist/cjs/components/toggle-group/toggle-group.js +3 -2
- package/dist/cjs/components/toggle-group/use-toggle-groupitem.js +2 -0
- package/dist/esm/components/field/field-counter.js +12 -1
- package/dist/esm/components/popover/popover.js +1 -1
- package/dist/esm/components/toggle-group/toggle-group-item.js +2 -2
- package/dist/esm/components/toggle-group/toggle-group.js +3 -2
- package/dist/esm/components/toggle-group/use-toggle-groupitem.js +2 -0
- package/dist/types/components/avatar/avatar.d.ts +8 -27
- package/dist/types/components/avatar/avatar.d.ts.map +1 -1
- package/dist/types/components/field/field-counter.d.ts.map +1 -1
- package/dist/types/components/spinner/spinner.d.ts +0 -1
- package/dist/types/components/spinner/spinner.d.ts.map +1 -1
- package/dist/types/components/toggle-group/toggle-group.d.ts +12 -1
- package/dist/types/components/toggle-group/toggle-group.d.ts.map +1 -1
- package/dist/types/components/toggle-group/use-toggle-groupitem.d.ts +1 -0
- package/dist/types/components/toggle-group/use-toggle-groupitem.d.ts.map +1 -1
- package/package.json +10 -10
|
@@ -19,9 +19,11 @@ const label = (text, count) => text.replace('%d', Math.abs(count).toString());
|
|
|
19
19
|
*/
|
|
20
20
|
const FieldCounter = react.forwardRef(function FieldCounter({ limit, under = '%d tegn igjen', over = '%d tegn for mye', ...rest }, ref) {
|
|
21
21
|
const [count, setCount] = react.useState(0);
|
|
22
|
+
const fieldInputRef = react.useRef(null);
|
|
22
23
|
const counterRef = react.useRef(null);
|
|
23
24
|
const hasExceededLimit = count > limit;
|
|
24
25
|
const remainder = limit - count;
|
|
26
|
+
// Listen to native input events (user typing) to update the counter in real time
|
|
25
27
|
react.useEffect(() => {
|
|
26
28
|
const field = counterRef.current?.closest('.ds-field');
|
|
27
29
|
const input = Array.from(field?.getElementsByTagName('*') || []).find(fieldObserver.isInputLike);
|
|
@@ -31,9 +33,18 @@ const FieldCounter = react.forwardRef(function FieldCounter({ limit, under = '%d
|
|
|
31
33
|
};
|
|
32
34
|
if (input)
|
|
33
35
|
onInput({ target: input }); // Initial setup
|
|
36
|
+
fieldInputRef.current = input;
|
|
34
37
|
field?.addEventListener('input', onInput);
|
|
35
38
|
return () => field?.removeEventListener('input', onInput);
|
|
36
|
-
}, [
|
|
39
|
+
}, []);
|
|
40
|
+
/* React does not dispatch a native input event when the value prop changes externally.
|
|
41
|
+
Since the parent re-renders this component when value changes, we can sync on render. */
|
|
42
|
+
react.useEffect(() => {
|
|
43
|
+
if (fieldInputRef.current) {
|
|
44
|
+
const valueLength = fieldInputRef.current.value.length;
|
|
45
|
+
setCount((prev) => (prev === valueLength ? prev : valueLength));
|
|
46
|
+
}
|
|
47
|
+
});
|
|
37
48
|
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", { "data-field": 'description', className: 'ds-sr-only', "aria-live": 'polite', ref: counterRef, children: hasExceededLimit && label(over, remainder) }), hasExceededLimit ? (jsxRuntime.jsx(validationMessage.ValidationMessage, { ref: ref, ...rest, children: label(over, remainder) })) : (jsxRuntime.jsx(paragraph.Paragraph, { ref: ref, ...rest, "data-field": 'validation', children: label(under, remainder) }))] }));
|
|
38
49
|
});
|
|
39
50
|
|
|
@@ -13,8 +13,8 @@ var useToggleGroupitem = require('./use-toggle-groupitem.js');
|
|
|
13
13
|
* <ToggleGroupItem value='1'>Toggle 1</ToggleGroupItem>
|
|
14
14
|
*/
|
|
15
15
|
const ToggleGroupItem = react.forwardRef(function ToggleGroupItem(rest, ref) {
|
|
16
|
-
const { active, buttonProps, value } = useToggleGroupitem.useToggleGroupItem(rest);
|
|
17
|
-
return (jsxRuntime.jsx(rovingFocusItem.RovingFocusItem, { asChild: true, value: value, children: jsxRuntime.jsx(button.Button, { variant: active ?
|
|
16
|
+
const { active, buttonProps, value, variant } = useToggleGroupitem.useToggleGroupItem(rest);
|
|
17
|
+
return (jsxRuntime.jsx(rovingFocusItem.RovingFocusItem, { asChild: true, value: value, children: jsxRuntime.jsx(button.Button, { variant: active ? variant : 'tertiary', ref: ref, ...rest, ...buttonProps }) }));
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
exports.ToggleGroupItem = ToggleGroupItem;
|
|
@@ -17,7 +17,7 @@ const ToggleGroupContext = react.createContext({});
|
|
|
17
17
|
* <ToggleGroup.Item value='3'>Toggle 3</ToggleGroup.Item>
|
|
18
18
|
* </ToggleGroup>
|
|
19
19
|
*/
|
|
20
|
-
const ToggleGroup = react.forwardRef(function ToggleGroup({ children, value, defaultValue, onChange, name, className, ...rest }, ref) {
|
|
20
|
+
const ToggleGroup = react.forwardRef(function ToggleGroup({ children, variant = 'primary', value, defaultValue, onChange, name, className, ...rest }, ref) {
|
|
21
21
|
const nameId = react.useId();
|
|
22
22
|
const isControlled = value !== undefined;
|
|
23
23
|
const [uncontrolledValue, setUncontrolledValue] = react.useState(defaultValue);
|
|
@@ -30,11 +30,12 @@ const ToggleGroup = react.forwardRef(function ToggleGroup({ children, value, def
|
|
|
30
30
|
value = uncontrolledValue;
|
|
31
31
|
}
|
|
32
32
|
return (jsxRuntime.jsx(ToggleGroupContext.Provider, { value: {
|
|
33
|
+
variant,
|
|
33
34
|
value,
|
|
34
35
|
defaultValue,
|
|
35
36
|
name: name ?? `togglegroup-name-${nameId}`,
|
|
36
37
|
onChange: onValueChange,
|
|
37
|
-
}, children: jsxRuntime.jsx(rovingFocusRoot.RovingFocusRoot, { asChild: true, activeValue: value, orientation: 'ambiguous', children: jsxRuntime.jsxs("div", { className: cl('ds-toggle-group', className), role: 'radiogroup', ref: ref, ...rest, children: [name && jsxRuntime.jsx("input", { type: 'hidden', name: name, value: value }), children] }) }) }));
|
|
38
|
+
}, children: jsxRuntime.jsx(rovingFocusRoot.RovingFocusRoot, { asChild: true, activeValue: value, orientation: 'ambiguous', children: jsxRuntime.jsxs("div", { className: cl('ds-toggle-group', className), role: 'radiogroup', "data-variant": variant, ref: ref, ...rest, children: [name && jsxRuntime.jsx("input", { type: 'hidden', name: name, value: value }), children] }) }) }));
|
|
38
39
|
});
|
|
39
40
|
|
|
40
41
|
exports.ToggleGroup = ToggleGroup;
|
|
@@ -11,11 +11,13 @@ const useToggleGroupItem = (props) => {
|
|
|
11
11
|
const toggleGroup$1 = react.useContext(toggleGroup.ToggleGroupContext);
|
|
12
12
|
const value = props.value ?? genValue;
|
|
13
13
|
const active = toggleGroup$1.value === value;
|
|
14
|
+
const variant = toggleGroup$1.variant;
|
|
14
15
|
const buttonId = `togglegroup-item-${react.useId()}`;
|
|
15
16
|
return {
|
|
16
17
|
...rest,
|
|
17
18
|
active: active,
|
|
18
19
|
value,
|
|
20
|
+
variant,
|
|
19
21
|
buttonProps: {
|
|
20
22
|
id: buttonId,
|
|
21
23
|
'aria-checked': active,
|
|
@@ -17,9 +17,11 @@ const label = (text, count) => text.replace('%d', Math.abs(count).toString());
|
|
|
17
17
|
*/
|
|
18
18
|
const FieldCounter = forwardRef(function FieldCounter({ limit, under = '%d tegn igjen', over = '%d tegn for mye', ...rest }, ref) {
|
|
19
19
|
const [count, setCount] = useState(0);
|
|
20
|
+
const fieldInputRef = useRef(null);
|
|
20
21
|
const counterRef = useRef(null);
|
|
21
22
|
const hasExceededLimit = count > limit;
|
|
22
23
|
const remainder = limit - count;
|
|
24
|
+
// Listen to native input events (user typing) to update the counter in real time
|
|
23
25
|
useEffect(() => {
|
|
24
26
|
const field = counterRef.current?.closest('.ds-field');
|
|
25
27
|
const input = Array.from(field?.getElementsByTagName('*') || []).find(isInputLike);
|
|
@@ -29,9 +31,18 @@ const FieldCounter = forwardRef(function FieldCounter({ limit, under = '%d tegn
|
|
|
29
31
|
};
|
|
30
32
|
if (input)
|
|
31
33
|
onInput({ target: input }); // Initial setup
|
|
34
|
+
fieldInputRef.current = input;
|
|
32
35
|
field?.addEventListener('input', onInput);
|
|
33
36
|
return () => field?.removeEventListener('input', onInput);
|
|
34
|
-
}, [
|
|
37
|
+
}, []);
|
|
38
|
+
/* React does not dispatch a native input event when the value prop changes externally.
|
|
39
|
+
Since the parent re-renders this component when value changes, we can sync on render. */
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
if (fieldInputRef.current) {
|
|
42
|
+
const valueLength = fieldInputRef.current.value.length;
|
|
43
|
+
setCount((prev) => (prev === valueLength ? prev : valueLength));
|
|
44
|
+
}
|
|
45
|
+
});
|
|
35
46
|
return (jsxs(Fragment, { children: [jsx("div", { "data-field": 'description', className: 'ds-sr-only', "aria-live": 'polite', ref: counterRef, children: hasExceededLimit && label(over, remainder) }), hasExceededLimit ? (jsx(ValidationMessage, { ref: ref, ...rest, children: label(over, remainder) })) : (jsx(Paragraph, { ref: ref, ...rest, "data-field": 'validation', children: label(under, remainder) }))] }));
|
|
36
47
|
});
|
|
37
48
|
|
|
@@ -11,8 +11,8 @@ import { useToggleGroupItem } from './use-toggle-groupitem.js';
|
|
|
11
11
|
* <ToggleGroupItem value='1'>Toggle 1</ToggleGroupItem>
|
|
12
12
|
*/
|
|
13
13
|
const ToggleGroupItem = forwardRef(function ToggleGroupItem(rest, ref) {
|
|
14
|
-
const { active, buttonProps, value } = useToggleGroupItem(rest);
|
|
15
|
-
return (jsx(RovingFocusItem, { asChild: true, value: value, children: jsx(Button, { variant: active ?
|
|
14
|
+
const { active, buttonProps, value, variant } = useToggleGroupItem(rest);
|
|
15
|
+
return (jsx(RovingFocusItem, { asChild: true, value: value, children: jsx(Button, { variant: active ? variant : 'tertiary', ref: ref, ...rest, ...buttonProps }) }));
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
export { ToggleGroupItem };
|
|
@@ -15,7 +15,7 @@ const ToggleGroupContext = createContext({});
|
|
|
15
15
|
* <ToggleGroup.Item value='3'>Toggle 3</ToggleGroup.Item>
|
|
16
16
|
* </ToggleGroup>
|
|
17
17
|
*/
|
|
18
|
-
const ToggleGroup = forwardRef(function ToggleGroup({ children, value, defaultValue, onChange, name, className, ...rest }, ref) {
|
|
18
|
+
const ToggleGroup = forwardRef(function ToggleGroup({ children, variant = 'primary', value, defaultValue, onChange, name, className, ...rest }, ref) {
|
|
19
19
|
const nameId = useId();
|
|
20
20
|
const isControlled = value !== undefined;
|
|
21
21
|
const [uncontrolledValue, setUncontrolledValue] = useState(defaultValue);
|
|
@@ -28,11 +28,12 @@ const ToggleGroup = forwardRef(function ToggleGroup({ children, value, defaultVa
|
|
|
28
28
|
value = uncontrolledValue;
|
|
29
29
|
}
|
|
30
30
|
return (jsx(ToggleGroupContext.Provider, { value: {
|
|
31
|
+
variant,
|
|
31
32
|
value,
|
|
32
33
|
defaultValue,
|
|
33
34
|
name: name ?? `togglegroup-name-${nameId}`,
|
|
34
35
|
onChange: onValueChange,
|
|
35
|
-
}, children: jsx(RovingFocusRoot, { asChild: true, activeValue: value, orientation: 'ambiguous', children: jsxs("div", { className: cl('ds-toggle-group', className), role: 'radiogroup', ref: ref, ...rest, children: [name && jsx("input", { type: 'hidden', name: name, value: value }), children] }) }) }));
|
|
36
|
+
}, children: jsx(RovingFocusRoot, { asChild: true, activeValue: value, orientation: 'ambiguous', children: jsxs("div", { className: cl('ds-toggle-group', className), role: 'radiogroup', "data-variant": variant, ref: ref, ...rest, children: [name && jsx("input", { type: 'hidden', name: name, value: value }), children] }) }) }));
|
|
36
37
|
});
|
|
37
38
|
|
|
38
39
|
export { ToggleGroup, ToggleGroupContext };
|
|
@@ -9,11 +9,13 @@ const useToggleGroupItem = (props) => {
|
|
|
9
9
|
const toggleGroup = useContext(ToggleGroupContext);
|
|
10
10
|
const value = props.value ?? genValue;
|
|
11
11
|
const active = toggleGroup.value === value;
|
|
12
|
+
const variant = toggleGroup.variant;
|
|
12
13
|
const buttonId = `togglegroup-item-${useId()}`;
|
|
13
14
|
return {
|
|
14
15
|
...rest,
|
|
15
16
|
active: active,
|
|
16
17
|
value,
|
|
18
|
+
variant,
|
|
17
19
|
buttonProps: {
|
|
18
20
|
id: buttonId,
|
|
19
21
|
'aria-checked': active,
|
|
@@ -2,11 +2,16 @@ import type { Size } from '@digdir/designsystemet/types';
|
|
|
2
2
|
import type { HTMLAttributes, ReactNode } from 'react';
|
|
3
3
|
import type { DefaultProps } from '../../types';
|
|
4
4
|
import type { MergeRight } from '../../utilities';
|
|
5
|
-
|
|
5
|
+
type AriaLabel = {
|
|
6
6
|
/**
|
|
7
7
|
* The name of the person the avatar represents.
|
|
8
8
|
*/
|
|
9
9
|
'aria-label': string;
|
|
10
|
+
};
|
|
11
|
+
type AriaHidden = Partial<AriaLabel> & {
|
|
12
|
+
'aria-hidden': true | 'true';
|
|
13
|
+
};
|
|
14
|
+
export type AvatarProps = MergeRight<DefaultProps & HTMLAttributes<HTMLSpanElement>, (AriaLabel | AriaHidden) & {
|
|
10
15
|
/**
|
|
11
16
|
* The size of the avatar.
|
|
12
17
|
*/
|
|
@@ -44,30 +49,6 @@ export type AvatarProps = MergeRight<DefaultProps & HTMLAttributes<HTMLSpanEleme
|
|
|
44
49
|
* <Icon />
|
|
45
50
|
* </Avatar>
|
|
46
51
|
*/
|
|
47
|
-
export declare const Avatar: React.ForwardRefExoticComponent<
|
|
48
|
-
|
|
49
|
-
* The name of the person the avatar represents.
|
|
50
|
-
*/
|
|
51
|
-
'aria-label': string;
|
|
52
|
-
/**
|
|
53
|
-
* The size of the avatar.
|
|
54
|
-
*/
|
|
55
|
-
'data-size'?: "xs" | Size;
|
|
56
|
-
/**
|
|
57
|
-
* The shape of the avatar.
|
|
58
|
-
*
|
|
59
|
-
* @default 'circle'
|
|
60
|
-
*/
|
|
61
|
-
variant?: "circle" | "square";
|
|
62
|
-
/**
|
|
63
|
-
* Initials to display inside the avatar.
|
|
64
|
-
*/
|
|
65
|
-
initials?: string;
|
|
66
|
-
/**
|
|
67
|
-
* Image, icon or initials to display inside the avatar.
|
|
68
|
-
*
|
|
69
|
-
* Gets `aria-hidden="true"`
|
|
70
|
-
*/
|
|
71
|
-
children?: ReactNode;
|
|
72
|
-
} & React.RefAttributes<HTMLSpanElement>>;
|
|
52
|
+
export declare const Avatar: React.ForwardRefExoticComponent<AvatarProps & React.RefAttributes<HTMLSpanElement>>;
|
|
53
|
+
export {};
|
|
73
54
|
//# sourceMappingURL=avatar.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"avatar.d.ts","sourceRoot":"","sources":["../../../src/components/avatar/avatar.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAC;AAGzD,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,MAAM,MAAM,WAAW,GAAG,UAAU,CAClC,YAAY,GAAG,cAAc,CAAC,eAAe,CAAC,EAC9C
|
|
1
|
+
{"version":3,"file":"avatar.d.ts","sourceRoot":"","sources":["../../../src/components/avatar/avatar.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAC;AAGzD,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,KAAK,SAAS,GAAG;IACf;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AACF,KAAK,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC,GAAG;IAAE,aAAa,EAAE,IAAI,GAAG,MAAM,CAAA;CAAE,CAAC;AAExE,MAAM,MAAM,WAAW,GAAG,UAAU,CAClC,YAAY,GAAG,cAAc,CAAC,eAAe,CAAC,EAC9C,CAAC,SAAS,GAAG,UAAU,CAAC,GAAG;IACzB;;OAEG;IACH,WAAW,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IAC1B;;;;OAIG;IACH,OAAO,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC9B;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB,CACF,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,MAAM,qFA8BjB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-counter.d.ts","sourceRoot":"","sources":["../../../src/components/field/field-counter.tsx"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,sBAAsB,EAC5B,MAAM,0CAA0C,CAAC;AAGlD,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;OAKG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;QAII;IACJ,KAAK,EAAE,MAAM,CAAC;CACf,GAAG,sBAAsB,CAAC;AAK3B;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY;IAlCvB;;;;;OAKG;WACI,MAAM;IACb;;;;;OAKG;YACK,MAAM;IACd;;;;QAII;WACG,MAAM;;;;
|
|
1
|
+
{"version":3,"file":"field-counter.d.ts","sourceRoot":"","sources":["../../../src/components/field/field-counter.tsx"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,sBAAsB,EAC5B,MAAM,0CAA0C,CAAC;AAGlD,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;OAKG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;QAII;IACJ,KAAK,EAAE,MAAM,CAAC;CACf,GAAG,sBAAsB,CAAC;AAK3B;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY;IAlCvB;;;;;OAKG;WACI,MAAM;IACb;;;;;OAKG;YACK,MAAM;IACd;;;;QAII;WACG,MAAM;;;;8CA0Ed,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spinner.d.ts","sourceRoot":"","sources":["../../../src/components/spinner/spinner.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,wBAAwB,EAAc,MAAM,OAAO,CAAC;AAIlE,MAAM,MAAM,YAAY,GAAG;IACzB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,WAAW,CAAC,EAAE,KAAK,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;CACxD,GAAG,wBAAwB,CAAC,KAAK,CAAC,GACjC,CACI;IAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"spinner.d.ts","sourceRoot":"","sources":["../../../src/components/spinner/spinner.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,wBAAwB,EAAc,MAAM,OAAO,CAAC;AAIlE,MAAM,MAAM,YAAY,GAAG;IACzB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,WAAW,CAAC,EAAE,KAAK,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;CACxD,GAAG,wBAAwB,CAAC,KAAK,CAAC,GACjC,CACI;IAAE,YAAY,EAAE,MAAM,CAAA;CAAE,GACxB;IAAE,YAAY,CAAC,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,IAAI,GAAG,MAAM,CAAA;CAAE,CAC1D,CAAC;AAEJ;;;;;GAKG;AACH,eAAO,MAAM,OAAO,oFA0ClB,CAAC"}
|
|
@@ -2,6 +2,7 @@ import type { HTMLAttributes } from 'react';
|
|
|
2
2
|
import type { DefaultProps } from '../../types';
|
|
3
3
|
import type { MergeRight } from '../../utilities';
|
|
4
4
|
export type ToggleGroupContextProps = {
|
|
5
|
+
variant?: 'primary' | 'secondary';
|
|
5
6
|
value?: string;
|
|
6
7
|
defaultValue?: string;
|
|
7
8
|
onChange?: (value: string) => void;
|
|
@@ -9,6 +10,11 @@ export type ToggleGroupContextProps = {
|
|
|
9
10
|
};
|
|
10
11
|
export declare const ToggleGroupContext: React.Context<ToggleGroupContextProps>;
|
|
11
12
|
export type ToggleGroupProps = MergeRight<DefaultProps & Omit<HTMLAttributes<HTMLDivElement>, 'value' | 'onChange'>, {
|
|
13
|
+
/**
|
|
14
|
+
* Specify which variant to use
|
|
15
|
+
* @default 'primary'
|
|
16
|
+
*/
|
|
17
|
+
variant?: 'primary' | 'secondary';
|
|
12
18
|
/**
|
|
13
19
|
* Controlled state for `ToggleGroup` component.
|
|
14
20
|
*/
|
|
@@ -36,7 +42,12 @@ export type ToggleGroupProps = MergeRight<DefaultProps & Omit<HTMLAttributes<HTM
|
|
|
36
42
|
* <ToggleGroup.Item value='3'>Toggle 3</ToggleGroup.Item>
|
|
37
43
|
* </ToggleGroup>
|
|
38
44
|
*/
|
|
39
|
-
export declare const ToggleGroup: React.ForwardRefExoticComponent<Omit<DefaultProps & Omit<HTMLAttributes<HTMLDivElement>, "value" | "onChange">, "defaultValue" | "name" | "value" | "onChange"> & {
|
|
45
|
+
export declare const ToggleGroup: React.ForwardRefExoticComponent<Omit<DefaultProps & Omit<HTMLAttributes<HTMLDivElement>, "value" | "onChange">, "defaultValue" | "name" | "value" | "onChange" | "variant"> & {
|
|
46
|
+
/**
|
|
47
|
+
* Specify which variant to use
|
|
48
|
+
* @default 'primary'
|
|
49
|
+
*/
|
|
50
|
+
variant?: "primary" | "secondary";
|
|
40
51
|
/**
|
|
41
52
|
* Controlled state for `ToggleGroup` component.
|
|
42
53
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toggle-group.d.ts","sourceRoot":"","sources":["../../../src/components/toggle-group/toggle-group.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGlD,MAAM,MAAM,uBAAuB,GAAG;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,eAAO,MAAM,kBAAkB,wCAA6C,CAAC;AAE7E,MAAM,MAAM,gBAAgB,GAAG,UAAU,CACvC,YAAY,GAAG,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,EAAE,OAAO,GAAG,UAAU,CAAC,EACzE;IACE;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CACF,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,WAAW;
|
|
1
|
+
{"version":3,"file":"toggle-group.d.ts","sourceRoot":"","sources":["../../../src/components/toggle-group/toggle-group.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGlD,MAAM,MAAM,uBAAuB,GAAG;IACpC,OAAO,CAAC,EAAE,SAAS,GAAG,WAAW,CAAC;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,eAAO,MAAM,kBAAkB,wCAA6C,CAAC;AAE7E,MAAM,MAAM,gBAAgB,GAAG,UAAU,CACvC,YAAY,GAAG,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,EAAE,OAAO,GAAG,UAAU,CAAC,EACzE;IACE;;;OAGG;IACH,OAAO,CAAC,EAAE,SAAS,GAAG,WAAW,CAAC;IAClC;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CACF,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,WAAW;IAlCpB;;;OAGG;cACO,SAAS,GAAG,WAAW;IACjC;;OAEG;YACK,MAAM;IACd;;OAEG;mBACY,MAAM;IACrB;;OAEG;eACQ,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI;IAClC;;OAEG;WACI,MAAM;wCAoEhB,CAAC"}
|
|
@@ -2,6 +2,7 @@ import type { ButtonProps } from '../button/button';
|
|
|
2
2
|
import type { ToggleGroupItemProps } from './toggle-group-item';
|
|
3
3
|
type UseToggleGroupItem = (props: ToggleGroupItemProps) => {
|
|
4
4
|
active: boolean;
|
|
5
|
+
variant?: 'primary' | 'secondary';
|
|
5
6
|
value: string;
|
|
6
7
|
buttonProps?: Pick<ButtonProps, 'id' | 'onClick' | 'role' | 'aria-checked' | 'aria-current' | 'name'>;
|
|
7
8
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-toggle-groupitem.d.ts","sourceRoot":"","sources":["../../../src/components/toggle-group/use-toggle-groupitem.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAEhE,KAAK,kBAAkB,GAAG,CAAC,KAAK,EAAE,oBAAoB,KAAK;IACzD,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,IAAI,CAChB,WAAW,EACX,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,cAAc,GAAG,cAAc,GAAG,MAAM,CACrE,CAAC;CACH,CAAC;AAEF,2FAA2F;AAC3F,eAAO,MAAM,kBAAkB,EAAE,
|
|
1
|
+
{"version":3,"file":"use-toggle-groupitem.d.ts","sourceRoot":"","sources":["../../../src/components/toggle-group/use-toggle-groupitem.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAEhE,KAAK,kBAAkB,GAAG,CAAC,KAAK,EAAE,oBAAoB,KAAK;IACzD,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,SAAS,GAAG,WAAW,CAAC;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,IAAI,CAChB,WAAW,EACX,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,cAAc,GAAG,cAAc,GAAG,MAAM,CACrE,CAAC;CACH,CAAC;AAEF,2FAA2F;AAC3F,eAAO,MAAM,kBAAkB,EAAE,kBA2BhC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digdir/designsystemet-react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.6.0",
|
|
5
5
|
"description": "React components for Designsystemet",
|
|
6
6
|
"author": "Designsystemet team",
|
|
7
7
|
"repository": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@floating-ui/dom": "^1.7.4",
|
|
40
40
|
"@floating-ui/react": "0.26.23",
|
|
41
|
-
"@navikt/aksel-icons": "^7.
|
|
41
|
+
"@navikt/aksel-icons": "^7.30.1",
|
|
42
42
|
"@radix-ui/react-slot": "^1.2.3",
|
|
43
43
|
"@tanstack/react-virtual": "^3.13.12",
|
|
44
44
|
"@u-elements/u-combobox": "^1.0.1",
|
|
@@ -49,26 +49,26 @@
|
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@rollup/plugin-commonjs": "^28.0.6",
|
|
51
51
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
52
|
-
"@storybook/addon-docs": "^9.1.
|
|
53
|
-
"@storybook/addon-vitest": "^9.1.
|
|
54
|
-
"@storybook/react-vite": "^9.1.
|
|
52
|
+
"@storybook/addon-docs": "^9.1.7",
|
|
53
|
+
"@storybook/addon-vitest": "^9.1.7",
|
|
54
|
+
"@storybook/react-vite": "^9.1.7",
|
|
55
55
|
"@testing-library/dom": "^10.4.1",
|
|
56
56
|
"@testing-library/jest-dom": "^6.8.0",
|
|
57
57
|
"@testing-library/react": "^16.3.0",
|
|
58
58
|
"@testing-library/user-event": "^14.6.1",
|
|
59
|
-
"@types/react": "^19.1.
|
|
59
|
+
"@types/react": "^19.1.13",
|
|
60
60
|
"@types/react-dom": "^19.1.9",
|
|
61
61
|
"jsdom": "^26.1.0",
|
|
62
62
|
"react": "^19.1.1",
|
|
63
63
|
"react-dom": "^19.1.1",
|
|
64
64
|
"rimraf": "^6.0.1",
|
|
65
|
-
"rollup": "^4.
|
|
65
|
+
"rollup": "^4.52.0",
|
|
66
66
|
"rollup-plugin-copy": "^3.5.0",
|
|
67
|
-
"storybook": "^9.1.
|
|
67
|
+
"storybook": "^9.1.7",
|
|
68
68
|
"tsx": "4.20.5",
|
|
69
69
|
"typescript": "^5.9.2",
|
|
70
|
-
"@digdir/designsystemet": "^1.
|
|
71
|
-
"@digdir/designsystemet-css": "^1.
|
|
70
|
+
"@digdir/designsystemet": "^1.6.0",
|
|
71
|
+
"@digdir/designsystemet-css": "^1.6.0"
|
|
72
72
|
},
|
|
73
73
|
"scripts": {
|
|
74
74
|
"build": "pnpm run clean && tsc -b tsconfig.lib.json --emitDeclarationOnly false && rollup -c --bundleConfigAsCjs",
|