@flipdish/ui-library 0.66.0 → 0.66.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.
- package/dist/components/__internal__/selectionControl/utilities/fieldProps.utils.cjs +30 -0
- package/dist/components/__internal__/selectionControl/utilities/fieldProps.utils.cjs.map +1 -0
- package/dist/components/__internal__/selectionControl/utilities/fieldProps.utils.d.ts +16 -0
- package/dist/components/__internal__/selectionControl/utilities/fieldProps.utils.d.ts.map +1 -0
- package/dist/components/__internal__/selectionControl/utilities/fieldProps.utils.js +28 -0
- package/dist/components/__internal__/selectionControl/utilities/fieldProps.utils.js.map +1 -0
- package/dist/components/atoms/Checkboxes/Checkbox/Checkbox.cjs +23 -16
- package/dist/components/atoms/Checkboxes/Checkbox/Checkbox.cjs.map +1 -1
- package/dist/components/atoms/Checkboxes/Checkbox/Checkbox.d.ts.map +1 -1
- package/dist/components/atoms/Checkboxes/Checkbox/Checkbox.js +24 -17
- package/dist/components/atoms/Checkboxes/Checkbox/Checkbox.js.map +1 -1
- package/dist/components/atoms/Checkboxes/Checkbox/components/CheckboxBase.cjs +1 -1
- package/dist/components/atoms/Checkboxes/Checkbox/components/CheckboxBase.d.ts +1 -1
- package/dist/components/atoms/Checkboxes/Checkbox/components/CheckboxBase.d.ts.map +1 -1
- package/dist/components/atoms/Checkboxes/Checkbox/components/CheckboxBase.js +1 -1
- package/dist/components/atoms/Radios/RadioButton/RadioButton.cjs +11 -4
- package/dist/components/atoms/Radios/RadioButton/RadioButton.cjs.map +1 -1
- package/dist/components/atoms/Radios/RadioButton/RadioButton.d.ts.map +1 -1
- package/dist/components/atoms/Radios/RadioButton/RadioButton.js +12 -5
- package/dist/components/atoms/Radios/RadioButton/RadioButton.js.map +1 -1
- package/dist/components/atoms/Radios/RadioButton/components/RadioButtonBase.cjs +1 -1
- package/dist/components/atoms/Radios/RadioButton/components/RadioButtonBase.d.ts +1 -1
- package/dist/components/atoms/Radios/RadioButton/components/RadioButtonBase.d.ts.map +1 -1
- package/dist/components/atoms/Radios/RadioButton/components/RadioButtonBase.js +1 -1
- package/dist/components/atoms/Toggle/index.cjs +17 -7
- package/dist/components/atoms/Toggle/index.cjs.map +1 -1
- package/dist/components/atoms/Toggle/index.d.ts +2 -2
- package/dist/components/atoms/Toggle/index.d.ts.map +1 -1
- package/dist/components/atoms/Toggle/index.js +18 -8
- package/dist/components/atoms/Toggle/index.js.map +1 -1
- package/dist/components/molecules/RadioCards/RadioCardAvatar/RadioCardAvatar.cjs +3 -1
- package/dist/components/molecules/RadioCards/RadioCardAvatar/RadioCardAvatar.cjs.map +1 -1
- package/dist/components/molecules/RadioCards/RadioCardAvatar/RadioCardAvatar.d.ts.map +1 -1
- package/dist/components/molecules/RadioCards/RadioCardAvatar/RadioCardAvatar.js +4 -2
- package/dist/components/molecules/RadioCards/RadioCardAvatar/RadioCardAvatar.js.map +1 -1
- package/dist/components/molecules/RadioCards/RadioCardAvatar/hooks/useCommitOnPress.cjs +9 -3
- package/dist/components/molecules/RadioCards/RadioCardAvatar/hooks/useCommitOnPress.cjs.map +1 -1
- package/dist/components/molecules/RadioCards/RadioCardAvatar/hooks/useCommitOnPress.d.ts.map +1 -1
- package/dist/components/molecules/RadioCards/RadioCardAvatar/hooks/useCommitOnPress.js +9 -3
- package/dist/components/molecules/RadioCards/RadioCardAvatar/hooks/useCommitOnPress.js.map +1 -1
- package/dist/components/molecules/RadioCards/RadioCardBullet/RadioCardBullet.cjs +3 -1
- package/dist/components/molecules/RadioCards/RadioCardBullet/RadioCardBullet.cjs.map +1 -1
- package/dist/components/molecules/RadioCards/RadioCardBullet/RadioCardBullet.d.ts.map +1 -1
- package/dist/components/molecules/RadioCards/RadioCardBullet/RadioCardBullet.js +4 -2
- package/dist/components/molecules/RadioCards/RadioCardBullet/RadioCardBullet.js.map +1 -1
- package/dist/components/molecules/RadioCards/RadioCardCheck/RadioCardCheck.cjs +3 -1
- package/dist/components/molecules/RadioCards/RadioCardCheck/RadioCardCheck.cjs.map +1 -1
- package/dist/components/molecules/RadioCards/RadioCardCheck/RadioCardCheck.d.ts.map +1 -1
- package/dist/components/molecules/RadioCards/RadioCardCheck/RadioCardCheck.js +4 -2
- package/dist/components/molecules/RadioCards/RadioCardCheck/RadioCardCheck.js.map +1 -1
- package/dist/components/molecules/RadioCards/RadioCardIcon/RadioCardIcon.cjs +3 -1
- package/dist/components/molecules/RadioCards/RadioCardIcon/RadioCardIcon.cjs.map +1 -1
- package/dist/components/molecules/RadioCards/RadioCardIcon/RadioCardIcon.d.ts.map +1 -1
- package/dist/components/molecules/RadioCards/RadioCardIcon/RadioCardIcon.js +4 -2
- package/dist/components/molecules/RadioCards/RadioCardIcon/RadioCardIcon.js.map +1 -1
- package/dist/components/molecules/RadioCards/RadioCardIconFeatured/RadioCardIconFeatured.cjs +3 -1
- package/dist/components/molecules/RadioCards/RadioCardIconFeatured/RadioCardIconFeatured.cjs.map +1 -1
- package/dist/components/molecules/RadioCards/RadioCardIconFeatured/RadioCardIconFeatured.d.ts.map +1 -1
- package/dist/components/molecules/RadioCards/RadioCardIconFeatured/RadioCardIconFeatured.js +4 -2
- package/dist/components/molecules/RadioCards/RadioCardIconFeatured/RadioCardIconFeatured.js.map +1 -1
- package/dist/components/molecules/RadioCards/RadioCardPayment/RadioCardPayment.cjs +3 -1
- package/dist/components/molecules/RadioCards/RadioCardPayment/RadioCardPayment.cjs.map +1 -1
- package/dist/components/molecules/RadioCards/RadioCardPayment/RadioCardPayment.d.ts.map +1 -1
- package/dist/components/molecules/RadioCards/RadioCardPayment/RadioCardPayment.js +4 -2
- package/dist/components/molecules/RadioCards/RadioCardPayment/RadioCardPayment.js.map +1 -1
- package/dist/components/molecules/RadioCards/hooks/useOptionIds.cjs +2 -2
- package/dist/components/molecules/RadioCards/hooks/useOptionIds.d.ts +2 -2
- package/dist/components/molecules/RadioCards/hooks/useOptionIds.js +2 -2
- package/dist/components/molecules/RadioGroup/components/RadioGroupAvatar.cjs +3 -1
- package/dist/components/molecules/RadioGroup/components/RadioGroupAvatar.cjs.map +1 -1
- package/dist/components/molecules/RadioGroup/components/RadioGroupAvatar.d.ts.map +1 -1
- package/dist/components/molecules/RadioGroup/components/RadioGroupAvatar.js +4 -2
- package/dist/components/molecules/RadioGroup/components/RadioGroupAvatar.js.map +1 -1
- package/dist/components/organisms/TextEditor/components/TextEditorExtensions.cjs +6 -4
- package/dist/components/organisms/TextEditor/components/TextEditorExtensions.cjs.map +1 -1
- package/dist/components/organisms/TextEditor/components/TextEditorExtensions.d.ts.map +1 -1
- package/dist/components/organisms/TextEditor/components/TextEditorExtensions.js +7 -5
- package/dist/components/organisms/TextEditor/components/TextEditorExtensions.js.map +1 -1
- package/dist/components/organisms/TreeView/index.cjs +3 -1
- package/dist/components/organisms/TreeView/index.cjs.map +1 -1
- package/dist/components/organisms/TreeView/index.d.ts.map +1 -1
- package/dist/components/organisms/TreeView/index.js +4 -2
- package/dist/components/organisms/TreeView/index.js.map +1 -1
- package/dist/native/components/atoms/Checkboxes/Checkbox/Checkbox.d.ts +1 -1
- package/dist/native/components/atoms/Checkboxes/Checkbox/Checkbox.js +1 -1
- package/dist/native/components/atoms/Radios/RadioButton/RadioButton.d.ts +1 -1
- package/dist/native/components/atoms/Radios/RadioButton/RadioButton.js +1 -1
- package/dist/native/components/atoms/Toggle/index.d.ts +1 -1
- package/dist/native/components/atoms/Toggle/index.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var filterDOMProps = require('react-aria/filterDOMProps');
|
|
4
|
+
|
|
5
|
+
// `ref` is a prop on React 19 when the component is not wrapped in `forwardRef`, and it always pointed at the `<label>`.
|
|
6
|
+
const LABEL_ONLY_PROPS = ['ref', 'style', 'render', 'onHoverStart', 'onHoverEnd', 'onHoverChange'];
|
|
7
|
+
// DOM props the control's own hook reads: `id` names the input and `onClick` is its press, so neither belongs on the `<label>`.
|
|
8
|
+
const FIELD_ONLY_PROPS = new Set(['id', 'onClick']);
|
|
9
|
+
/**
|
|
10
|
+
* Splits the props of a react-aria checkbox, radio or switch between its field and its button, keeping on the `<label>`
|
|
11
|
+
* every prop the one-element `Checkbox`, `Radio` and `Switch` put there.
|
|
12
|
+
*
|
|
13
|
+
* @param props The props left once the component has taken its own, `className` included.
|
|
14
|
+
* @returns `fieldProps` for the `CheckboxField`, `RadioField` or `SwitchField`, and `buttonProps` for the button inside it:
|
|
15
|
+
* `ref`, `style`, `render`, the hover callbacks, `data-*` attributes and the global DOM attributes and events.
|
|
16
|
+
*/
|
|
17
|
+
const splitFieldProps = (props) => {
|
|
18
|
+
// The module react-aria-components filters the `<label>`'s props with, so the two never disagree on what is a DOM prop.
|
|
19
|
+
const buttonPropNames = new Set([...Object.keys(filterDOMProps.filterDOMProps(props, { global: true })), ...LABEL_ONLY_PROPS]);
|
|
20
|
+
const fieldProps = {};
|
|
21
|
+
const buttonProps = {};
|
|
22
|
+
for (const [name, value] of Object.entries(props)) {
|
|
23
|
+
const target = buttonPropNames.has(name) && !FIELD_ONLY_PROPS.has(name) ? buttonProps : fieldProps;
|
|
24
|
+
target[name] = value;
|
|
25
|
+
}
|
|
26
|
+
return { fieldProps, buttonProps };
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
exports.splitFieldProps = splitFieldProps;
|
|
30
|
+
//# sourceMappingURL=fieldProps.utils.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fieldProps.utils.cjs","sources":["../../../../../src/components/__internal__/selectionControl/utilities/fieldProps.utils.ts"],"sourcesContent":[null],"names":["filterDOMProps"],"mappings":";;;;AAKA;AACA,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,YAAY,EAAE,eAAe,CAAC;AAClG;AACA,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;AAEnD;;;;;;;AAOG;AACI,MAAM,eAAe,GAAG,CAAwB,KAAa,KAAI;;IAEtE,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,CAACA,6BAAc,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,GAAG,gBAAgB,CAAC,CAAC;IAC/G,MAAM,UAAU,GAA4B,EAAE;IAC9C,MAAM,WAAW,GAA4B,EAAE;AAE/C,IAAA,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACjD,MAAM,MAAM,GAAG,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,WAAW,GAAG,UAAU;AAClG,QAAA,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK;IACtB;AAEA,IAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAG/B;AACH;;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { GlobalDOMAttributes, HoverEvents } from '@react-types/shared';
|
|
2
|
+
type ButtonPropName = 'ref' | 'style' | 'render' | keyof HoverEvents | Exclude<keyof GlobalDOMAttributes, 'onClick'> | `data-${string}`;
|
|
3
|
+
/**
|
|
4
|
+
* Splits the props of a react-aria checkbox, radio or switch between its field and its button, keeping on the `<label>`
|
|
5
|
+
* every prop the one-element `Checkbox`, `Radio` and `Switch` put there.
|
|
6
|
+
*
|
|
7
|
+
* @param props The props left once the component has taken its own, `className` included.
|
|
8
|
+
* @returns `fieldProps` for the `CheckboxField`, `RadioField` or `SwitchField`, and `buttonProps` for the button inside it:
|
|
9
|
+
* `ref`, `style`, `render`, the hover callbacks, `data-*` attributes and the global DOM attributes and events.
|
|
10
|
+
*/
|
|
11
|
+
export declare const splitFieldProps: <TProps extends object>(props: TProps) => {
|
|
12
|
+
fieldProps: Omit<TProps, ButtonPropName>;
|
|
13
|
+
buttonProps: Pick<TProps, Extract<keyof TProps, ButtonPropName>>;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=fieldProps.utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fieldProps.utils.d.ts","sourceRoot":"","sources":["../../../../../src/components/__internal__/selectionControl/utilities/fieldProps.utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAG5E,KAAK,cAAc,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,mBAAmB,EAAE,SAAS,CAAC,GAAG,QAAQ,MAAM,EAAE,CAAC;AAOxI;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,GAAI,MAAM,SAAS,MAAM,EAAE,OAAO,MAAM,KAW5B;IACpC,UAAU,EAAE,IAAI,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACzC,WAAW,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC;CAEpE,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { filterDOMProps } from 'react-aria/filterDOMProps';
|
|
2
|
+
|
|
3
|
+
// `ref` is a prop on React 19 when the component is not wrapped in `forwardRef`, and it always pointed at the `<label>`.
|
|
4
|
+
const LABEL_ONLY_PROPS = ['ref', 'style', 'render', 'onHoverStart', 'onHoverEnd', 'onHoverChange'];
|
|
5
|
+
// DOM props the control's own hook reads: `id` names the input and `onClick` is its press, so neither belongs on the `<label>`.
|
|
6
|
+
const FIELD_ONLY_PROPS = new Set(['id', 'onClick']);
|
|
7
|
+
/**
|
|
8
|
+
* Splits the props of a react-aria checkbox, radio or switch between its field and its button, keeping on the `<label>`
|
|
9
|
+
* every prop the one-element `Checkbox`, `Radio` and `Switch` put there.
|
|
10
|
+
*
|
|
11
|
+
* @param props The props left once the component has taken its own, `className` included.
|
|
12
|
+
* @returns `fieldProps` for the `CheckboxField`, `RadioField` or `SwitchField`, and `buttonProps` for the button inside it:
|
|
13
|
+
* `ref`, `style`, `render`, the hover callbacks, `data-*` attributes and the global DOM attributes and events.
|
|
14
|
+
*/
|
|
15
|
+
const splitFieldProps = (props) => {
|
|
16
|
+
// The module react-aria-components filters the `<label>`'s props with, so the two never disagree on what is a DOM prop.
|
|
17
|
+
const buttonPropNames = new Set([...Object.keys(filterDOMProps(props, { global: true })), ...LABEL_ONLY_PROPS]);
|
|
18
|
+
const fieldProps = {};
|
|
19
|
+
const buttonProps = {};
|
|
20
|
+
for (const [name, value] of Object.entries(props)) {
|
|
21
|
+
const target = buttonPropNames.has(name) && !FIELD_ONLY_PROPS.has(name) ? buttonProps : fieldProps;
|
|
22
|
+
target[name] = value;
|
|
23
|
+
}
|
|
24
|
+
return { fieldProps, buttonProps };
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export { splitFieldProps };
|
|
28
|
+
//# sourceMappingURL=fieldProps.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fieldProps.utils.js","sources":["../../../../../src/components/__internal__/selectionControl/utilities/fieldProps.utils.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAKA;AACA,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,YAAY,EAAE,eAAe,CAAC;AAClG;AACA,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;AAEnD;;;;;;;AAOG;AACI,MAAM,eAAe,GAAG,CAAwB,KAAa,KAAI;;IAEtE,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,GAAG,gBAAgB,CAAC,CAAC;IAC/G,MAAM,UAAU,GAA4B,EAAE;IAC9C,MAAM,WAAW,GAA4B,EAAE;AAE/C,IAAA,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACjD,MAAM,MAAM,GAAG,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,WAAW,GAAG,UAAU;AAClG,QAAA,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK;IACtB;AAEA,IAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAG/B;AACH;;"}
|
|
@@ -6,6 +6,7 @@ var testIdUtils = require('@flipdish/ui-library/utilities/testIdUtils');
|
|
|
6
6
|
var React = require('react');
|
|
7
7
|
var reactAriaComponents = require('react-aria-components');
|
|
8
8
|
var selectionControl_styles = require('../../../__internal__/selectionControl/selectionControl.styles.cjs');
|
|
9
|
+
var fieldProps_utils = require('../../../__internal__/selectionControl/utilities/fieldProps.utils.cjs');
|
|
9
10
|
var CheckboxGroup_context = require('../providers/CheckboxGroup.context.cjs');
|
|
10
11
|
var CheckboxBase = require('./components/CheckboxBase.cjs');
|
|
11
12
|
|
|
@@ -18,32 +19,38 @@ var CheckboxBase = require('./components/CheckboxBase.cjs');
|
|
|
18
19
|
const Checkbox = React.forwardRef(({ label, hint, size = 'sm', className, 'data-testid': dataTestId, ...ariaCheckboxProps }, ref) => {
|
|
19
20
|
const group = React.useContext(CheckboxGroup_context.CheckboxGroupContext);
|
|
20
21
|
const groupState = React.useContext(reactAriaComponents.CheckboxGroupStateContext);
|
|
22
|
+
const outerTextContext = React.useContext(reactAriaComponents.TextContext);
|
|
21
23
|
size = group?.size ?? size;
|
|
22
24
|
const fallbackTestId = testIdUtils.useResolvedTestId({ testId: dataTestId, segment: 'checkbox', rootName: 'checkbox' });
|
|
23
25
|
const { value } = ariaCheckboxProps;
|
|
24
26
|
// A box with no `value` leaves the group's state below, so what the group forbids is carried over by hand.
|
|
25
27
|
const isStandaloneInGroup = Boolean(group) && value === undefined;
|
|
26
|
-
// The group's restriction first, else the prop as given: an explicit `false` still overrides a `
|
|
28
|
+
// The group's restriction first, else the prop as given: an explicit `false` still overrides a `CheckboxFieldContext`.
|
|
27
29
|
const isDisabled = (isStandaloneInGroup && groupState?.isDisabled) || ariaCheckboxProps.isDisabled;
|
|
28
30
|
const isReadOnly = (isStandaloneInGroup && groupState?.isReadOnly) || ariaCheckboxProps.isReadOnly;
|
|
29
31
|
const isGroupOption = !dataTestId && group && value !== undefined;
|
|
30
32
|
const checkboxTestId = isGroupOption ? testIdUtils.joinTestId(group.testIdPrefix, `option-${testIdUtils.slugifyTestId(value)}`) : fallbackTestId;
|
|
31
|
-
const
|
|
33
|
+
const { fieldProps, buttonProps } = fieldProps_utils.splitFieldProps(ariaCheckboxProps);
|
|
34
|
+
const checkbox = (jsxRuntime.jsx(reactAriaComponents.CheckboxField, { ...fieldProps,
|
|
32
35
|
// Each box resolves this by itself and would fall back to the browser's own check, whatever its group asked for (react-aria-components 1.19).
|
|
33
|
-
validationBehavior: ariaCheckboxProps.validationBehavior ?? group?.validationBehavior, isDisabled: isDisabled, isReadOnly: isReadOnly,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
//
|
|
39
|
-
//
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
36
|
+
validationBehavior: ariaCheckboxProps.validationBehavior ?? group?.validationBehavior, isDisabled: isDisabled, isReadOnly: isReadOnly,
|
|
37
|
+
// No box of its own, so the `<label>` is still what the parent lays out.
|
|
38
|
+
className: "contents", children: jsxRuntime.jsx(reactAriaComponents.CheckboxButton, { ...buttonProps, ref: ref, "data-testid": checkboxTestId, className: (state) => cx.cx('relative flex items-start', state.isDisabled && 'cursor-not-allowed', selectionControl_styles.selectionControlSizes[size].root, typeof className === 'function' ? className(state) : className), children: ({ isSelected, isIndeterminate, isDisabled, isFocusVisible }) => (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(CheckboxBase.CheckboxBase, { size: size, isSelected: isSelected, isIndeterminate: isIndeterminate, isDisabled: isDisabled, isFocusVisible: isFocusVisible, className: label || hint ? 'mt-0.5' : '' }), (label || hint) && (
|
|
39
|
+
// The field scopes a react-aria `Text` to its own slots; `label` and `hint` keep the context they had before the field existed.
|
|
40
|
+
jsxRuntime.jsx(reactAriaComponents.TextContext.Provider, { value: outerTextContext, children: jsxRuntime.jsxs("div", { className: cx.cx('inline-flex flex-col', selectionControl_styles.selectionControlSizes[size].textWrapper), children: [label && jsxRuntime.jsx("p", { className: cx.cx('text-secondary select-none', selectionControl_styles.selectionControlSizes[size].label), children: label }), hint && (
|
|
41
|
+
// biome-ignore lint/a11y/noStaticElementInteractions: not independently interactive — only stops the click reaching outer React handlers, see below
|
|
42
|
+
// biome-ignore lint/a11y/useKeyWithClickEvents: same as above, no keyboard equivalent needed
|
|
43
|
+
jsxRuntime.jsx("span", { className: cx.cx('text-tertiary', selectionControl_styles.selectionControlSizes[size].hint), onClick: (event) => {
|
|
44
|
+
// Deliberately stopPropagation only, no preventDefault (matches the
|
|
45
|
+
// Untitled UI reference). The native <label>->control click-forwarding
|
|
46
|
+
// that toggles the checkbox happens during the real DOM bubble phase,
|
|
47
|
+
// which completes before React's synthetic onClick (delegated at the
|
|
48
|
+
// root) ever runs — so this can't and doesn't block the toggle. It only
|
|
49
|
+
// stops the click reaching an OUTER React onClick a consumer might wrap
|
|
50
|
+
// around the checkbox (e.g. a clickable row/card), so clicking the hint
|
|
51
|
+
// toggles this checkbox without also firing the row's handler.
|
|
52
|
+
event.stopPropagation();
|
|
53
|
+
}, children: hint }))] }) }))] })) }) }));
|
|
47
54
|
// A box with no `value` is not one of the group's options: it keeps its own state, as it does on React Native,
|
|
48
55
|
// where react-aria would otherwise hand every box inside a group to that group.
|
|
49
56
|
if (isStandaloneInGroup)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Checkbox.cjs","sources":["../../../../../src/components/atoms/Checkboxes/Checkbox/Checkbox.tsx"],"sourcesContent":[null],"names":["forwardRef","useContext","CheckboxGroupContext","CheckboxGroupStateContext","useResolvedTestId","joinTestId","slugifyTestId","_jsx","
|
|
1
|
+
{"version":3,"file":"Checkbox.cjs","sources":["../../../../../src/components/atoms/Checkboxes/Checkbox/Checkbox.tsx"],"sourcesContent":[null],"names":["forwardRef","useContext","CheckboxGroupContext","CheckboxGroupStateContext","TextContext","useResolvedTestId","joinTestId","slugifyTestId","splitFieldProps","_jsx","AriaCheckboxField","AriaCheckboxButton","cx","selectionControlSizes","_jsxs","_Fragment","CheckboxBase"],"mappings":";;;;;;;;;;;;AA4BA;;;;;AAKG;AACI,MAAM,QAAQ,GAAGA,gBAAU,CAChC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,GAAG,iBAAiB,EAAE,EAAE,GAAG,KAAI;AAChG,IAAA,MAAM,KAAK,GAAGC,gBAAU,CAACC,0CAAoB,CAAC;AAC9C,IAAA,MAAM,UAAU,GAAGD,gBAAU,CAACE,6CAAyB,CAAC;AACxD,IAAA,MAAM,gBAAgB,GAAGF,gBAAU,CAACG,+BAAW,CAAC;AAEhD,IAAA,IAAI,GAAG,KAAK,EAAE,IAAI,IAAI,IAAI;AAE1B,IAAA,MAAM,cAAc,GAAGC,6BAAiB,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC;AAC3G,IAAA,MAAM,EAAE,KAAK,EAAE,GAAG,iBAAiB;;IAEnC,MAAM,mBAAmB,GAAG,OAAO,CAAC,KAAK,CAAC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checkbox/Checkbox.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAc,KAAK,SAAS,EAAc,MAAM,OAAO,CAAC;AAC/D,OAAO,
|
|
1
|
+
{"version":3,"file":"Checkbox.d.ts","sourceRoot":"","sources":["../../../../../src/components/atoms/Checkboxes/Checkbox/Checkbox.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAc,KAAK,SAAS,EAAc,MAAM,OAAO,CAAC;AAC/D,OAAO,EAGL,KAAK,aAAa,IAAI,iBAAiB,EAGxC,MAAM,uBAAuB,CAAC;AAM/B,MAAM,WAAW,aAAc,SAAQ,iBAAiB;IACtD,0GAA0G;IAC1G,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IACnB,mEAAmE;IACnE,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,6CAA6C;IAC7C,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,0HAA0H;IAC1H,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,4GA4FpB,CAAC"}
|
|
@@ -2,8 +2,9 @@ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
|
2
2
|
import { cx } from '@flipdish/ui-library/utilities/cx';
|
|
3
3
|
import { useResolvedTestId, joinTestId, slugifyTestId } from '@flipdish/ui-library/utilities/testIdUtils';
|
|
4
4
|
import { forwardRef, useContext } from 'react';
|
|
5
|
-
import { CheckboxGroupStateContext,
|
|
5
|
+
import { CheckboxGroupStateContext, TextContext, CheckboxField, CheckboxButton } from 'react-aria-components';
|
|
6
6
|
import { selectionControlSizes } from '../../../__internal__/selectionControl/selectionControl.styles.js';
|
|
7
|
+
import { splitFieldProps } from '../../../__internal__/selectionControl/utilities/fieldProps.utils.js';
|
|
7
8
|
import { CheckboxGroupContext } from '../providers/CheckboxGroup.context.js';
|
|
8
9
|
import { CheckboxBase } from './components/CheckboxBase.js';
|
|
9
10
|
|
|
@@ -16,32 +17,38 @@ import { CheckboxBase } from './components/CheckboxBase.js';
|
|
|
16
17
|
const Checkbox = forwardRef(({ label, hint, size = 'sm', className, 'data-testid': dataTestId, ...ariaCheckboxProps }, ref) => {
|
|
17
18
|
const group = useContext(CheckboxGroupContext);
|
|
18
19
|
const groupState = useContext(CheckboxGroupStateContext);
|
|
20
|
+
const outerTextContext = useContext(TextContext);
|
|
19
21
|
size = group?.size ?? size;
|
|
20
22
|
const fallbackTestId = useResolvedTestId({ testId: dataTestId, segment: 'checkbox', rootName: 'checkbox' });
|
|
21
23
|
const { value } = ariaCheckboxProps;
|
|
22
24
|
// A box with no `value` leaves the group's state below, so what the group forbids is carried over by hand.
|
|
23
25
|
const isStandaloneInGroup = Boolean(group) && value === undefined;
|
|
24
|
-
// The group's restriction first, else the prop as given: an explicit `false` still overrides a `
|
|
26
|
+
// The group's restriction first, else the prop as given: an explicit `false` still overrides a `CheckboxFieldContext`.
|
|
25
27
|
const isDisabled = (isStandaloneInGroup && groupState?.isDisabled) || ariaCheckboxProps.isDisabled;
|
|
26
28
|
const isReadOnly = (isStandaloneInGroup && groupState?.isReadOnly) || ariaCheckboxProps.isReadOnly;
|
|
27
29
|
const isGroupOption = !dataTestId && group && value !== undefined;
|
|
28
30
|
const checkboxTestId = isGroupOption ? joinTestId(group.testIdPrefix, `option-${slugifyTestId(value)}`) : fallbackTestId;
|
|
29
|
-
const
|
|
31
|
+
const { fieldProps, buttonProps } = splitFieldProps(ariaCheckboxProps);
|
|
32
|
+
const checkbox = (jsx(CheckboxField, { ...fieldProps,
|
|
30
33
|
// Each box resolves this by itself and would fall back to the browser's own check, whatever its group asked for (react-aria-components 1.19).
|
|
31
|
-
validationBehavior: ariaCheckboxProps.validationBehavior ?? group?.validationBehavior, isDisabled: isDisabled, isReadOnly: isReadOnly,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
//
|
|
37
|
-
//
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
34
|
+
validationBehavior: ariaCheckboxProps.validationBehavior ?? group?.validationBehavior, isDisabled: isDisabled, isReadOnly: isReadOnly,
|
|
35
|
+
// No box of its own, so the `<label>` is still what the parent lays out.
|
|
36
|
+
className: "contents", children: jsx(CheckboxButton, { ...buttonProps, ref: ref, "data-testid": checkboxTestId, className: (state) => cx('relative flex items-start', state.isDisabled && 'cursor-not-allowed', selectionControlSizes[size].root, typeof className === 'function' ? className(state) : className), children: ({ isSelected, isIndeterminate, isDisabled, isFocusVisible }) => (jsxs(Fragment, { children: [jsx(CheckboxBase, { size: size, isSelected: isSelected, isIndeterminate: isIndeterminate, isDisabled: isDisabled, isFocusVisible: isFocusVisible, className: label || hint ? 'mt-0.5' : '' }), (label || hint) && (
|
|
37
|
+
// The field scopes a react-aria `Text` to its own slots; `label` and `hint` keep the context they had before the field existed.
|
|
38
|
+
jsx(TextContext.Provider, { value: outerTextContext, children: jsxs("div", { className: cx('inline-flex flex-col', selectionControlSizes[size].textWrapper), children: [label && jsx("p", { className: cx('text-secondary select-none', selectionControlSizes[size].label), children: label }), hint && (
|
|
39
|
+
// biome-ignore lint/a11y/noStaticElementInteractions: not independently interactive — only stops the click reaching outer React handlers, see below
|
|
40
|
+
// biome-ignore lint/a11y/useKeyWithClickEvents: same as above, no keyboard equivalent needed
|
|
41
|
+
jsx("span", { className: cx('text-tertiary', selectionControlSizes[size].hint), onClick: (event) => {
|
|
42
|
+
// Deliberately stopPropagation only, no preventDefault (matches the
|
|
43
|
+
// Untitled UI reference). The native <label>->control click-forwarding
|
|
44
|
+
// that toggles the checkbox happens during the real DOM bubble phase,
|
|
45
|
+
// which completes before React's synthetic onClick (delegated at the
|
|
46
|
+
// root) ever runs — so this can't and doesn't block the toggle. It only
|
|
47
|
+
// stops the click reaching an OUTER React onClick a consumer might wrap
|
|
48
|
+
// around the checkbox (e.g. a clickable row/card), so clicking the hint
|
|
49
|
+
// toggles this checkbox without also firing the row's handler.
|
|
50
|
+
event.stopPropagation();
|
|
51
|
+
}, children: hint }))] }) }))] })) }) }));
|
|
45
52
|
// A box with no `value` is not one of the group's options: it keeps its own state, as it does on React Native,
|
|
46
53
|
// where react-aria would otherwise hand every box inside a group to that group.
|
|
47
54
|
if (isStandaloneInGroup)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Checkbox.js","sources":["../../../../../src/components/atoms/Checkboxes/Checkbox/Checkbox.tsx"],"sourcesContent":[null],"names":["_jsx","
|
|
1
|
+
{"version":3,"file":"Checkbox.js","sources":["../../../../../src/components/atoms/Checkboxes/Checkbox/Checkbox.tsx"],"sourcesContent":[null],"names":["_jsx","AriaCheckboxField","AriaCheckboxButton","_jsxs","_Fragment"],"mappings":";;;;;;;;;;AA4BA;;;;;AAKG;AACI,MAAM,QAAQ,GAAG,UAAU,CAChC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,GAAG,iBAAiB,EAAE,EAAE,GAAG,KAAI;AAChG,IAAA,MAAM,KAAK,GAAG,UAAU,CAAC,oBAAoB,CAAC;AAC9C,IAAA,MAAM,UAAU,GAAG,UAAU,CAAC,yBAAyB,CAAC;AACxD,IAAA,MAAM,gBAAgB,GAAG,UAAU,CAAC,WAAW,CAAC;AAEhD,IAAA,IAAI,GAAG,KAAK,EAAE,IAAI,IAAI,IAAI;AAE1B,IAAA,MAAM,cAAc,GAAG,iBAAiB,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC;AAC3G,IAAA,MAAM,EAAE,KAAK,EAAE,GAAG,iBAAiB;;IAEnC,MAAM,mBAAmB,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,KAAK,SAAS;;AAEjE,IAAA,MAAM,UAAU,GAAG,CAAC,mBAAmB,IAAI,UAAU,EAAE,UAAU,KA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,KAAK,IAAI,IAAI,GAAG,QAAQ,GAAG,EAAE,EAAA,CACxC,EACD,CAAC,KAAK,IAAI,IAAI;;oBAEbA,GAAA,CAAC,WAAW,CAAC,QAAQ,EAAA,EAAC,KAAK,EAAE,gBAAgB,YAC3CG,IAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAE,EAAE,CAAC,sBAAsB,EAAE,qBAAqB,CAAC,IAAI,CAAC,CAAC,WAAW,CAAC,aAChF,KAAK,IAAIH,WAAG,SAAS,EAAE,EAAE,CAAC,4BAA4B,EAAE,qBAAqB,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,EAAA,QAAA,EAAG,KAAK,EAAA,CAAK,EACvG,IAAI;;;AAGH,gCAAAA,GAAA,CAAA,MAAA,EAAA,EACE,SAAS,EAAE,EAAE,CAAC,eAAe,EAAE,qBAAqB,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAChE,OAAO,EAAE,CAAC,KAAK,KAAI;;;;;;;;;wCASjB,KAAK,CAAC,eAAe,EAAE;AACzB,oCAAA,CAAC,EAAA,QAAA,EAEA,IAAI,EAAA,CACA,CACR,CAAA,EAAA,CACG,EAAA,CACe,CACxB,CAAA,EAAA,CACA,CACJ,EAAA,CACkB,EAAA,CACH,CACrB;;;AAID,IAAA,IAAI,mBAAmB;QAAE,OAAOA,GAAA,CAAC,yBAAyB,CAAC,QAAQ,EAAA,EAAC,KAAK,EAAE,IAAI,EAAA,QAAA,EAAG,QAAQ,EAAA,CAAsC;AAChI,IAAA,OAAO,QAAQ;AACjB,CAAC;AAEH,QAAQ,CAAC,WAAW,GAAG,UAAU;;"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
4
|
var cx = require('@flipdish/ui-library/utilities/cx');
|
|
5
5
|
|
|
6
|
-
/** Visual-only checkbox square with no input behaviour, for building custom selectable controls; `Checkbox` renders it inside a react-aria `
|
|
6
|
+
/** Visual-only checkbox square with no input behaviour, for building custom selectable controls; `Checkbox` renders it inside a react-aria `CheckboxButton`. */
|
|
7
7
|
const CheckboxBase = ({ className, isSelected, isDisabled, isIndeterminate, size = 'sm', isFocusVisible = false }) => {
|
|
8
8
|
return (jsxRuntime.jsxs("div", { className: cx.cx('relative flex size-4 shrink-0 cursor-pointer appearance-none items-center justify-center rounded bg-primary ring-1 ring-primary ring-inset', size === 'md' && 'size-5 rounded-md', (isSelected || isIndeterminate) && 'bg-brand-solid ring-brand-solid', isDisabled && 'cursor-not-allowed opacity-50', isDisabled && !(isSelected || isIndeterminate) && 'bg-tertiary', isFocusVisible && 'outline-2 outline-offset-2 outline-focus-ring', className), children: [jsxRuntime.jsx("svg", { "aria-hidden": "true", viewBox: "0 0 14 14", fill: "none", className: cx.cx('pointer-events-none absolute h-3 w-2.5 text-fg-white opacity-0 transition-inherit-all', size === 'md' && 'size-3.5', isIndeterminate && 'opacity-100'), children: jsxRuntime.jsx("path", { d: "M2.91675 7H11.0834", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) }), jsxRuntime.jsx("svg", { "aria-hidden": "true", viewBox: "0 0 14 14", fill: "none", className: cx.cx('pointer-events-none absolute size-3 text-fg-white opacity-0 transition-inherit-all', size === 'md' && 'size-3.5', isSelected && !isIndeterminate && 'opacity-100'), children: jsxRuntime.jsx("path", { d: "M11.6666 3.5L5.24992 9.91667L2.33325 7", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) })] }));
|
|
9
9
|
};
|
|
@@ -12,7 +12,7 @@ export interface CheckboxBaseProps {
|
|
|
12
12
|
/** Fills the box and shows a dash instead of the check mark, taking precedence over `isSelected`. */
|
|
13
13
|
isIndeterminate?: boolean;
|
|
14
14
|
}
|
|
15
|
-
/** Visual-only checkbox square with no input behaviour, for building custom selectable controls; `Checkbox` renders it inside a react-aria `
|
|
15
|
+
/** Visual-only checkbox square with no input behaviour, for building custom selectable controls; `Checkbox` renders it inside a react-aria `CheckboxButton`. */
|
|
16
16
|
export declare const CheckboxBase: {
|
|
17
17
|
({ className, isSelected, isDisabled, isIndeterminate, size, isFocusVisible }: CheckboxBaseProps): import("react").JSX.Element;
|
|
18
18
|
displayName: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CheckboxBase.d.ts","sourceRoot":"","sources":["../../../../../../src/components/atoms/Checkboxes/Checkbox/components/CheckboxBase.tsx"],"names":[],"mappings":"AAIA,MAAM,WAAW,iBAAiB;IAChC,qDAAqD;IACrD,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IACnB,iDAAiD;IACjD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oDAAoD;IACpD,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,oEAAoE;IACpE,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,mDAAmD;IACnD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,qGAAqG;IACrG,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,
|
|
1
|
+
{"version":3,"file":"CheckboxBase.d.ts","sourceRoot":"","sources":["../../../../../../src/components/atoms/Checkboxes/Checkbox/components/CheckboxBase.tsx"],"names":[],"mappings":"AAIA,MAAM,WAAW,iBAAiB;IAChC,qDAAqD;IACrD,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IACnB,iDAAiD;IACjD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oDAAoD;IACpD,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,oEAAoE;IACpE,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,mDAAmD;IACnD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,qGAAqG;IACrG,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,gKAAgK;AAChK,eAAO,MAAM,YAAY;mFAAiG,iBAAiB;;CAwC1I,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { cx } from '@flipdish/ui-library/utilities/cx';
|
|
3
3
|
|
|
4
|
-
/** Visual-only checkbox square with no input behaviour, for building custom selectable controls; `Checkbox` renders it inside a react-aria `
|
|
4
|
+
/** Visual-only checkbox square with no input behaviour, for building custom selectable controls; `Checkbox` renders it inside a react-aria `CheckboxButton`. */
|
|
5
5
|
const CheckboxBase = ({ className, isSelected, isDisabled, isIndeterminate, size = 'sm', isFocusVisible = false }) => {
|
|
6
6
|
return (jsxs("div", { className: cx('relative flex size-4 shrink-0 cursor-pointer appearance-none items-center justify-center rounded bg-primary ring-1 ring-primary ring-inset', size === 'md' && 'size-5 rounded-md', (isSelected || isIndeterminate) && 'bg-brand-solid ring-brand-solid', isDisabled && 'cursor-not-allowed opacity-50', isDisabled && !(isSelected || isIndeterminate) && 'bg-tertiary', isFocusVisible && 'outline-2 outline-offset-2 outline-focus-ring', className), children: [jsx("svg", { "aria-hidden": "true", viewBox: "0 0 14 14", fill: "none", className: cx('pointer-events-none absolute h-3 w-2.5 text-fg-white opacity-0 transition-inherit-all', size === 'md' && 'size-3.5', isIndeterminate && 'opacity-100'), children: jsx("path", { d: "M2.91675 7H11.0834", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) }), jsx("svg", { "aria-hidden": "true", viewBox: "0 0 14 14", fill: "none", className: cx('pointer-events-none absolute size-3 text-fg-white opacity-0 transition-inherit-all', size === 'md' && 'size-3.5', isSelected && !isIndeterminate && 'opacity-100'), children: jsx("path", { d: "M11.6666 3.5L5.24992 9.91667L2.33325 7", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) })] }));
|
|
7
7
|
};
|
|
@@ -6,6 +6,7 @@ var testIdUtils = require('@flipdish/ui-library/utilities/testIdUtils');
|
|
|
6
6
|
var React = require('react');
|
|
7
7
|
var reactAriaComponents = require('react-aria-components');
|
|
8
8
|
var selectionControl_styles = require('../../../__internal__/selectionControl/selectionControl.styles.cjs');
|
|
9
|
+
var fieldProps_utils = require('../../../__internal__/selectionControl/utilities/fieldProps.utils.cjs');
|
|
9
10
|
var RadioGroup_context = require('../providers/RadioGroup.context.cjs');
|
|
10
11
|
var RadioButtonBase = require('./components/RadioButtonBase.cjs');
|
|
11
12
|
|
|
@@ -17,15 +18,21 @@ var RadioButtonBase = require('./components/RadioButtonBase.cjs');
|
|
|
17
18
|
*/
|
|
18
19
|
const RadioButton = React.forwardRef(({ label, hint, className, size = 'sm', 'data-testid': dataTestId, ...ariaRadioProps }, ref) => {
|
|
19
20
|
const context = React.useContext(RadioGroup_context.RadioGroupContext);
|
|
21
|
+
const outerTextContext = React.useContext(reactAriaComponents.TextContext);
|
|
20
22
|
size = context?.size ?? size;
|
|
21
23
|
const fallbackTestId = testIdUtils.useResolvedTestId({ testId: dataTestId, segment: 'radio-button', rootName: 'radio-button' });
|
|
22
24
|
const radioTestId = !dataTestId && context?.testIdPrefix
|
|
23
25
|
? testIdUtils.joinTestId(context.testIdPrefix, `option-${testIdUtils.slugifyTestId(String(ariaRadioProps.value))}`)
|
|
24
26
|
: fallbackTestId;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
const { fieldProps, buttonProps } = fieldProps_utils.splitFieldProps(ariaRadioProps);
|
|
28
|
+
return (
|
|
29
|
+
// No box of its own, so the `<label>` is still what the group lays out.
|
|
30
|
+
jsxRuntime.jsx(reactAriaComponents.RadioField, { ...fieldProps, className: "contents", children: jsxRuntime.jsx(reactAriaComponents.RadioButton, { ...buttonProps, ref: ref, "data-testid": radioTestId, className: (state) => cx.cx('relative flex items-start', state.isDisabled && 'cursor-not-allowed', selectionControl_styles.selectionControlSizes[size].root, typeof className === 'function' ? className(state) : className), children: ({ isSelected, isDisabled, isFocusVisible }) => (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(RadioButtonBase.RadioButtonBase, { size: size, isSelected: isSelected, isDisabled: isDisabled, isFocusVisible: isFocusVisible, className: label || hint ? 'mt-0.5' : '' }), (label || hint) && (
|
|
31
|
+
// The field scopes a react-aria `Text` to its own slots; `label` and `hint` keep the context they had before the field existed.
|
|
32
|
+
jsxRuntime.jsx(reactAriaComponents.TextContext.Provider, { value: outerTextContext, children: jsxRuntime.jsxs("div", { className: cx.cx('inline-flex flex-col', selectionControl_styles.selectionControlSizes[size].textWrapper), children: [label && jsxRuntime.jsx("p", { className: cx.cx('text-secondary select-none', selectionControl_styles.selectionControlSizes[size].label), children: label }), hint && (
|
|
33
|
+
// biome-ignore lint/a11y/noStaticElementInteractions: This is a hint that is not interactive
|
|
34
|
+
// biome-ignore lint/a11y/useKeyWithClickEvents: This is a hint that is not interactive
|
|
35
|
+
jsxRuntime.jsx("span", { className: cx.cx('text-tertiary', selectionControl_styles.selectionControlSizes[size].hint), onClick: (event) => event.stopPropagation(), children: hint }))] }) }))] })) }) }));
|
|
29
36
|
});
|
|
30
37
|
RadioButton.displayName = 'RadioButton';
|
|
31
38
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RadioButton.cjs","sources":["../../../../../src/components/atoms/Radios/RadioButton/RadioButton.tsx"],"sourcesContent":[null],"names":["forwardRef","useContext","RadioGroupContext","useResolvedTestId","joinTestId","slugifyTestId","_jsx","
|
|
1
|
+
{"version":3,"file":"RadioButton.cjs","sources":["../../../../../src/components/atoms/Radios/RadioButton/RadioButton.tsx"],"sourcesContent":[null],"names":["forwardRef","useContext","RadioGroupContext","TextContext","useResolvedTestId","joinTestId","slugifyTestId","splitFieldProps","_jsx","AriaRadioField","AriaRadioButton","cx","selectionControlSizes","_jsxs","_Fragment","RadioButtonBase"],"mappings":";;;;;;;;;;;;AAsBA;;;;;AAKG;AACI,MAAM,WAAW,GAAGA,gBAAU,CACnC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,GAAG,IAAI,EAAE,aAAa,EAAE,UAAU,EAAE,GAAG,cAAc,EA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,UAAU,EACtB,cAAc,EAAE,cAAc,EAC9B,SAAS,EAAE,KAAK,IAAI,IAAI,GAAG,QAAQ,GAAG,EAAE,EAAA,CACxC,EACD,CAAC,KAAK,IAAI,IAAI;;oBAEbP,cAAA,CAACL,+BAAW,CAAC,QAAQ,EAAA,EAAC,KAAK,EAAE,gBAAgB,YAC3CU,eAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAEF,KAAE,CAAC,sBAAsB,EAAEC,6CAAqB,CAAC,IAAI,CAAC,CAAC,WAAW,CAAC,aAChF,KAAK,IAAIJ,sBAAG,SAAS,EAAEG,KAAE,CAAC,4BAA4B,EAAEC,6CAAqB,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,EAAA,QAAA,EAAG,KAAK,EAAA,CAAK,EACvG,IAAI;;;AAGH,gCAAAJ,cAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAEG,KAAE,CAAC,eAAe,EAAEC,6CAAqB,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC,KAAK,KAAK,KAAK,CAAC,eAAe,EAAE,YAChH,IAAI,EAAA,CACA,CACR,CAAA,EAAA,CACG,GACe,CACxB,CAAA,EAAA,CACA,CACJ,EAAA,CACe,EAAA,CACH;AAErB,CAAC;AAEH,WAAW,CAAC,WAAW,GAAG,aAAa;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RadioButton.d.ts","sourceRoot":"","sources":["../../../../../src/components/atoms/Radios/RadioButton/RadioButton.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAc,KAAK,SAAS,EAAc,MAAM,OAAO,CAAC;AAC/D,OAAO,
|
|
1
|
+
{"version":3,"file":"RadioButton.d.ts","sourceRoot":"","sources":["../../../../../src/components/atoms/Radios/RadioButton/RadioButton.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAc,KAAK,SAAS,EAAc,MAAM,OAAO,CAAC;AAC/D,OAAO,EAAgE,KAAK,UAAU,IAAI,cAAc,EAAe,MAAM,uBAAuB,CAAC;AAMrJ,MAAM,WAAW,gBAAiB,SAAQ,cAAc;IACtD,0GAA0G;IAC1G,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IACnB,oEAAoE;IACpE,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,6CAA6C;IAC7C,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,qHAAqH;IACrH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;GAKG;AACH,eAAO,MAAM,WAAW,+GA6DvB,CAAC"}
|
|
@@ -2,8 +2,9 @@ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
|
2
2
|
import { cx } from '@flipdish/ui-library/utilities/cx';
|
|
3
3
|
import { useResolvedTestId, joinTestId, slugifyTestId } from '@flipdish/ui-library/utilities/testIdUtils';
|
|
4
4
|
import { forwardRef, useContext } from 'react';
|
|
5
|
-
import {
|
|
5
|
+
import { TextContext, RadioField, RadioButton as RadioButton$1 } from 'react-aria-components';
|
|
6
6
|
import { selectionControlSizes } from '../../../__internal__/selectionControl/selectionControl.styles.js';
|
|
7
|
+
import { splitFieldProps } from '../../../__internal__/selectionControl/utilities/fieldProps.utils.js';
|
|
7
8
|
import { RadioGroupContext } from '../providers/RadioGroup.context.js';
|
|
8
9
|
import { RadioButtonBase } from './components/RadioButtonBase.js';
|
|
9
10
|
|
|
@@ -15,15 +16,21 @@ import { RadioButtonBase } from './components/RadioButtonBase.js';
|
|
|
15
16
|
*/
|
|
16
17
|
const RadioButton = forwardRef(({ label, hint, className, size = 'sm', 'data-testid': dataTestId, ...ariaRadioProps }, ref) => {
|
|
17
18
|
const context = useContext(RadioGroupContext);
|
|
19
|
+
const outerTextContext = useContext(TextContext);
|
|
18
20
|
size = context?.size ?? size;
|
|
19
21
|
const fallbackTestId = useResolvedTestId({ testId: dataTestId, segment: 'radio-button', rootName: 'radio-button' });
|
|
20
22
|
const radioTestId = !dataTestId && context?.testIdPrefix
|
|
21
23
|
? joinTestId(context.testIdPrefix, `option-${slugifyTestId(String(ariaRadioProps.value))}`)
|
|
22
24
|
: fallbackTestId;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
const { fieldProps, buttonProps } = splitFieldProps(ariaRadioProps);
|
|
26
|
+
return (
|
|
27
|
+
// No box of its own, so the `<label>` is still what the group lays out.
|
|
28
|
+
jsx(RadioField, { ...fieldProps, className: "contents", children: jsx(RadioButton$1, { ...buttonProps, ref: ref, "data-testid": radioTestId, className: (state) => cx('relative flex items-start', state.isDisabled && 'cursor-not-allowed', selectionControlSizes[size].root, typeof className === 'function' ? className(state) : className), children: ({ isSelected, isDisabled, isFocusVisible }) => (jsxs(Fragment, { children: [jsx(RadioButtonBase, { size: size, isSelected: isSelected, isDisabled: isDisabled, isFocusVisible: isFocusVisible, className: label || hint ? 'mt-0.5' : '' }), (label || hint) && (
|
|
29
|
+
// The field scopes a react-aria `Text` to its own slots; `label` and `hint` keep the context they had before the field existed.
|
|
30
|
+
jsx(TextContext.Provider, { value: outerTextContext, children: jsxs("div", { className: cx('inline-flex flex-col', selectionControlSizes[size].textWrapper), children: [label && jsx("p", { className: cx('text-secondary select-none', selectionControlSizes[size].label), children: label }), hint && (
|
|
31
|
+
// biome-ignore lint/a11y/noStaticElementInteractions: This is a hint that is not interactive
|
|
32
|
+
// biome-ignore lint/a11y/useKeyWithClickEvents: This is a hint that is not interactive
|
|
33
|
+
jsx("span", { className: cx('text-tertiary', selectionControlSizes[size].hint), onClick: (event) => event.stopPropagation(), children: hint }))] }) }))] })) }) }));
|
|
27
34
|
});
|
|
28
35
|
RadioButton.displayName = 'RadioButton';
|
|
29
36
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RadioButton.js","sources":["../../../../../src/components/atoms/Radios/RadioButton/RadioButton.tsx"],"sourcesContent":[null],"names":["_jsx","
|
|
1
|
+
{"version":3,"file":"RadioButton.js","sources":["../../../../../src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viour, for building custom selectable controls; `RadioButton` renders it inside a react-aria `
|
|
6
|
+
/** Visual-only radio circle with no input behaviour, for building custom selectable controls; `RadioButton` renders it inside a react-aria `RadioButton`. */
|
|
7
7
|
const RadioButtonBase = ({ className, isFocusVisible, isSelected, isDisabled, size = 'sm' }) => {
|
|
8
8
|
return (jsxRuntime.jsx("div", { className: cx.cx('flex size-4 shrink-0 cursor-pointer appearance-none items-center justify-center rounded-full bg-primary ring-1 ring-primary ring-inset', size === 'md' && 'size-5', isSelected && 'bg-brand-solid ring-brand-solid', isDisabled && 'cursor-not-allowed opacity-50', isDisabled && !isSelected && 'bg-tertiary', isFocusVisible && 'outline-2 outline-offset-2 outline-focus-ring', className), children: jsxRuntime.jsx("div", { className: cx.cx('size-1.5 rounded-full bg-fg-white opacity-0 transition-inherit-all', size === 'md' && 'size-2', isSelected && 'opacity-100') }) }));
|
|
9
9
|
};
|
|
@@ -10,7 +10,7 @@ export interface RadioButtonBaseProps {
|
|
|
10
10
|
/** Dims the circle and shows a not-allowed cursor. */
|
|
11
11
|
isDisabled?: boolean;
|
|
12
12
|
}
|
|
13
|
-
/** Visual-only radio circle with no input behaviour, for building custom selectable controls; `RadioButton` renders it inside a react-aria `
|
|
13
|
+
/** Visual-only radio circle with no input behaviour, for building custom selectable controls; `RadioButton` renders it inside a react-aria `RadioButton`. */
|
|
14
14
|
export declare const RadioButtonBase: {
|
|
15
15
|
({ className, isFocusVisible, isSelected, isDisabled, size }: RadioButtonBaseProps): import("react").JSX.Element;
|
|
16
16
|
displayName: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RadioButtonBase.d.ts","sourceRoot":"","sources":["../../../../../../src/components/atoms/Radios/RadioButton/components/RadioButtonBase.tsx"],"names":[],"mappings":"AAIA,MAAM,WAAW,oBAAoB;IACnC,wDAAwD;IACxD,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IACnB,oDAAoD;IACpD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uDAAuD;IACvD,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,sEAAsE;IACtE,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,sDAAsD;IACtD,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,
|
|
1
|
+
{"version":3,"file":"RadioButtonBase.d.ts","sourceRoot":"","sources":["../../../../../../src/components/atoms/Radios/RadioButton/components/RadioButtonBase.tsx"],"names":[],"mappings":"AAIA,MAAM,WAAW,oBAAoB;IACnC,wDAAwD;IACxD,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IACnB,oDAAoD;IACpD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uDAAuD;IACvD,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,sEAAsE;IACtE,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,sDAAsD;IACtD,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,6JAA6J;AAC7J,eAAO,MAAM,eAAe;kEAAwE,oBAAoB;;CAkBvH,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { cx } from '@flipdish/ui-library/utilities/cx';
|
|
3
3
|
|
|
4
|
-
/** Visual-only radio circle with no input behaviour, for building custom selectable controls; `RadioButton` renders it inside a react-aria `
|
|
4
|
+
/** Visual-only radio circle with no input behaviour, for building custom selectable controls; `RadioButton` renders it inside a react-aria `RadioButton`. */
|
|
5
5
|
const RadioButtonBase = ({ className, isFocusVisible, isSelected, isDisabled, size = 'sm' }) => {
|
|
6
6
|
return (jsx("div", { className: cx('flex size-4 shrink-0 cursor-pointer appearance-none items-center justify-center rounded-full bg-primary ring-1 ring-primary ring-inset', size === 'md' && 'size-5', isSelected && 'bg-brand-solid ring-brand-solid', isDisabled && 'cursor-not-allowed opacity-50', isDisabled && !isSelected && 'bg-tertiary', isFocusVisible && 'outline-2 outline-offset-2 outline-focus-ring', className), children: jsx("div", { className: cx('size-1.5 rounded-full bg-fg-white opacity-0 transition-inherit-all', size === 'md' && 'size-2', isSelected && 'opacity-100') }) }));
|
|
7
7
|
};
|
|
@@ -3,11 +3,13 @@
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
4
|
var cx = require('@flipdish/ui-library/utilities/cx');
|
|
5
5
|
var testIdUtils = require('@flipdish/ui-library/utilities/testIdUtils');
|
|
6
|
+
var React = require('react');
|
|
6
7
|
var reactAriaComponents = require('react-aria-components');
|
|
7
8
|
var selectionControl_styles = require('../../__internal__/selectionControl/selectionControl.styles.cjs');
|
|
9
|
+
var fieldProps_utils = require('../../__internal__/selectionControl/utilities/fieldProps.utils.cjs');
|
|
8
10
|
var Toggle_styles = require('./Toggle.styles.cjs');
|
|
9
11
|
|
|
10
|
-
/** Visual-only switch track and knob with no input behaviour, for building custom controls; `Toggle` renders it inside a react-aria `
|
|
12
|
+
/** Visual-only switch track and knob with no input behaviour, for building custom controls; `Toggle` renders it inside a react-aria `SwitchButton`. */
|
|
11
13
|
const ToggleBase = ({ className, isHovered, isDisabled, isFocusVisible, isSelected, slim, size = 'sm' }) => {
|
|
12
14
|
return (jsxRuntime.jsx("div", { className: cx.cx(
|
|
13
15
|
// Never narrower than its size: beside long text in a narrow container the text wraps, not the track.
|
|
@@ -22,12 +24,20 @@ const ToggleBase = ({ className, isHovered, isDisabled, isFocusVisible, isSelect
|
|
|
22
24
|
*/
|
|
23
25
|
const Toggle = ({ label, hint, className, size = 'sm', slim, 'data-testid': dataTestId, ...ariaSwitchProps }) => {
|
|
24
26
|
const toggleTestId = testIdUtils.useResolvedTestId({ testId: dataTestId, segment: 'toggle', rootName: 'toggle' });
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
const outerTextContext = React.useContext(reactAriaComponents.TextContext);
|
|
28
|
+
const { fieldProps, buttonProps } = fieldProps_utils.splitFieldProps(ariaSwitchProps);
|
|
29
|
+
return (jsxRuntime.jsx(reactAriaComponents.SwitchField, { ...fieldProps,
|
|
30
|
+
// `SwitchField` would default to the browser's own check; the one-element `Switch` only ever set `aria-invalid`.
|
|
31
|
+
validationBehavior: "aria",
|
|
32
|
+
// No box of its own, so the `<label>` is still what the parent lays out.
|
|
33
|
+
className: "contents", children: jsxRuntime.jsx(reactAriaComponents.SwitchButton, { ...buttonProps, "data-testid": toggleTestId, className: (state) => cx.cx(
|
|
34
|
+
// As wide as its text, up to the container: past that the label and hint wrap instead of overflowing it.
|
|
35
|
+
'relative flex w-max max-w-full items-start', state.isDisabled && 'cursor-not-allowed', selectionControl_styles.selectionControlSizes[size].root, typeof className === 'function' ? className(state) : className), children: ({ isSelected, isDisabled, isFocusVisible, isHovered }) => (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(ToggleBase, { slim: slim, size: size, isHovered: isHovered, isDisabled: isDisabled, isFocusVisible: isFocusVisible, isSelected: isSelected, className: slim ? 'mt-0.5' : '' }), (label || hint) && (
|
|
36
|
+
// The field scopes a react-aria `Text` to its own slots; `label` and `hint` keep the context they had before the field existed.
|
|
37
|
+
jsxRuntime.jsx(reactAriaComponents.TextContext.Provider, { value: outerTextContext, children: jsxRuntime.jsxs("div", { className: cx.cx('flex flex-col', selectionControl_styles.selectionControlSizes[size].textWrapper), children: [label && jsxRuntime.jsx("p", { className: cx.cx('text-secondary select-none', selectionControl_styles.selectionControlSizes[size].label), children: label }), hint && (
|
|
38
|
+
// biome-ignore lint/a11y/noStaticElementInteractions: This is a hint that is not interactive
|
|
39
|
+
// biome-ignore lint/a11y/useKeyWithClickEvents: This is a hint that is not interactive
|
|
40
|
+
jsxRuntime.jsx("span", { className: cx.cx('text-tertiary', selectionControl_styles.selectionControlSizes[size].hint), onClick: (event) => event.stopPropagation(), children: hint }))] }) }))] })) }) }));
|
|
31
41
|
};
|
|
32
42
|
|
|
33
43
|
exports.Toggle = Toggle;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../../../src/components/atoms/Toggle/index.tsx"],"sourcesContent":[null],"names":["_jsx","cx","styles","useResolvedTestId","
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../../../src/components/atoms/Toggle/index.tsx"],"sourcesContent":[null],"names":["_jsx","cx","styles","useResolvedTestId","useContext","TextContext","splitFieldProps","AriaSwitchField","AriaSwitchButton","selectionControlSizes","_jsxs"],"mappings":";;;;;;;;;;;AAwBA;MACa,UAAU,GAAG,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,cAAc,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,EAAmB,KAAI;AACjI,IAAA,QACEA,cAAA,CAAA,KAAA,EAAA,EACE,SAAS,EAAEC,KAAE;;QAEX,gJAAgJ,EAChJ,UAAU,IAAI,gBAAgB,EAC9B,UAAU,IAAI,SAAS,IAAI,sBAAsB,EACjD,UAAU,IAAI,+BAA+B,EAC7C,cAAc,IAAI,4BAA4B,EAE9C,IAAI,IAAI,QAAQ,EAChB,IAAI,IAAI,UAAU,IAAI,kBAAkB,EACxCC,oBAAM,CAAC,KAAK,CAAC,IAAI,GAAG,MAAM,GAAG,SAAS,CAAC,CAAC,IAAI,CAAC,EAC7C,SAAS,CACV,EAAA,QAAA,EAEDF,cAAA,CAAA,KAAA,EAAA,EACE,KAAK,EAAE;AACL,gBAAA,UAAU,EAAE,kHAAkH;aAC/H,EACD,SAAS,EAAEC,KAAE,CACX,oCAAoC,EAEpC,IAAI,IAAI,WAAW,EACnB,IAAI,IAAI,6BAA6B,EACrC,IAAI,IAAI,UAAU,IAAI,mCAAmC,EACzD,IAAI,IAAI,UAAU,IAAI,SAAS,IAAI,yCAAyC,EAE5EC,oBAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EACjB,UAAU,IAAIA,oBAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CACxC,EAAA,CACD,EAAA,CACE;AAEV;AA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QAAQ,EAAA,EAAC,KAAK,EAAE,gBAAgB,YAC3CK,eAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAET,KAAE,CAAC,eAAe,EAAEQ,6CAAqB,CAAC,IAAI,CAAC,CAAC,WAAW,CAAC,aACzE,KAAK,IAAIT,sBAAG,SAAS,EAAEC,KAAE,CAAC,4BAA4B,EAAEQ,6CAAqB,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,EAAA,QAAA,EAAG,KAAK,EAAA,CAAK,EACvG,IAAI;;;AAGH,gCAAAT,cAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAEC,KAAE,CAAC,eAAe,EAAEQ,6CAAqB,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC,KAAK,KAAK,KAAK,CAAC,eAAe,EAAE,YAChH,IAAI,EAAA,CACA,CACR,CAAA,EAAA,CACG,GACe,CACxB,CAAA,EAAA,CACA,CACJ,EAAA,CACgB,EAAA,CACH;AAEtB;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
2
|
import type { SwitchProps as AriaSwitchProps } from 'react-aria-components';
|
|
3
3
|
import type { ToggleSize } from './toggle.types';
|
|
4
4
|
export type { ToggleSize } from './toggle.types';
|
|
@@ -11,7 +11,7 @@ interface ToggleBaseProps {
|
|
|
11
11
|
isSelected?: boolean;
|
|
12
12
|
isDisabled?: boolean;
|
|
13
13
|
}
|
|
14
|
-
/** Visual-only switch track and knob with no input behaviour, for building custom controls; `Toggle` renders it inside a react-aria `
|
|
14
|
+
/** Visual-only switch track and knob with no input behaviour, for building custom controls; `Toggle` renders it inside a react-aria `SwitchButton`. */
|
|
15
15
|
export declare const ToggleBase: ({ className, isHovered, isDisabled, isFocusVisible, isSelected, slim, size }: ToggleBaseProps) => import("react").JSX.Element;
|
|
16
16
|
export interface ToggleProps extends AriaSwitchProps {
|
|
17
17
|
/** Sets the switch size and the label and hint text size. */
|