@cimpress-ui/react 1.0.2 → 1.2.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/commonjs/components/checkbox/checkbox-group.d.ts +2 -2
- package/dist/commonjs/components/checkbox/checkbox-group.d.ts.map +1 -1
- package/dist/commonjs/components/checkbox/checkbox-group.js +8 -1
- package/dist/commonjs/components/checkbox/checkbox-group.js.map +1 -1
- package/dist/commonjs/components/checkbox/checkbox.d.ts +1 -1
- package/dist/commonjs/components/checkbox/checkbox.d.ts.map +1 -1
- package/dist/commonjs/components/checkbox/checkbox.js.map +1 -1
- package/dist/commonjs/components/combo-box/combo-box.d.ts +2 -2
- package/dist/commonjs/components/combo-box/combo-box.d.ts.map +1 -1
- package/dist/commonjs/components/combo-box/combo-box.js +9 -5
- package/dist/commonjs/components/combo-box/combo-box.js.map +1 -1
- package/dist/commonjs/components/date-picker/date-picker.d.ts +1 -1
- package/dist/commonjs/components/date-picker/date-picker.d.ts.map +1 -1
- package/dist/commonjs/components/date-picker/date-picker.js.map +1 -1
- package/dist/commonjs/components/drawer/drawer.d.ts +19 -18
- package/dist/commonjs/components/drawer/drawer.d.ts.map +1 -1
- package/dist/commonjs/components/drawer/drawer.js +16 -21
- package/dist/commonjs/components/drawer/drawer.js.map +1 -1
- package/dist/commonjs/components/file-picker/file-picker.d.ts.map +1 -1
- package/dist/commonjs/components/file-picker/file-picker.js +3 -3
- package/dist/commonjs/components/file-picker/file-picker.js.map +1 -1
- package/dist/commonjs/components/modal-dialog/modal-dialog.d.ts +2 -1
- package/dist/commonjs/components/modal-dialog/modal-dialog.d.ts.map +1 -1
- package/dist/commonjs/components/modal-dialog/modal-dialog.js +1 -1
- package/dist/commonjs/components/modal-dialog/modal-dialog.js.map +1 -1
- package/dist/commonjs/components/radio/radio-group.d.ts +2 -2
- package/dist/commonjs/components/radio/radio-group.d.ts.map +1 -1
- package/dist/commonjs/components/radio/radio-group.js +8 -1
- package/dist/commonjs/components/radio/radio-group.js.map +1 -1
- package/dist/commonjs/components/select/select.d.ts +2 -2
- package/dist/commonjs/components/select/select.d.ts.map +1 -1
- package/dist/commonjs/components/select/select.js +9 -5
- package/dist/commonjs/components/select/select.js.map +1 -1
- package/dist/commonjs/components/tabs/tabs.d.ts +1 -1
- package/dist/commonjs/components/tabs/tabs.d.ts.map +1 -1
- package/dist/commonjs/components/tabs/tabs.js +2 -4
- package/dist/commonjs/components/tabs/tabs.js.map +1 -1
- package/dist/commonjs/components/tag/tag-group.d.ts +1 -1
- package/dist/commonjs/components/tag/tag-group.d.ts.map +1 -1
- package/dist/commonjs/components/tag/tag-group.js.map +1 -1
- package/dist/commonjs/components/tag/tag.d.ts +1 -1
- package/dist/commonjs/components/tag/tag.d.ts.map +1 -1
- package/dist/commonjs/components/tag/tag.js.map +1 -1
- package/dist/commonjs/components/tag-field/tag-field.d.ts.map +1 -1
- package/dist/commonjs/components/tag-field/tag-field.js +6 -3
- package/dist/commonjs/components/tag-field/tag-field.js.map +1 -1
- package/dist/commonjs/components/text-inputs/text-field.d.ts.map +1 -1
- package/dist/commonjs/components/text-inputs/text-field.js +1 -1
- package/dist/commonjs/components/text-inputs/text-field.js.map +1 -1
- package/dist/commonjs/components/toggle/toggle.d.ts +1 -1
- package/dist/commonjs/components/toggle/toggle.d.ts.map +1 -1
- package/dist/commonjs/components/toggle/toggle.js.map +1 -1
- package/dist/commonjs/components/toggle-button/context.d.ts +2 -0
- package/dist/commonjs/components/toggle-button/context.d.ts.map +1 -0
- package/dist/commonjs/components/toggle-button/context.js +7 -0
- package/dist/commonjs/components/toggle-button/context.js.map +1 -0
- package/dist/commonjs/components/toggle-button/internal-toggle-button.d.ts +2 -0
- package/dist/commonjs/components/toggle-button/internal-toggle-button.d.ts.map +1 -0
- package/dist/commonjs/components/toggle-button/internal-toggle-button.js +57 -0
- package/dist/commonjs/components/toggle-button/internal-toggle-button.js.map +1 -0
- package/dist/commonjs/components/toggle-button/toggle-button-group.d.ts +10 -6
- package/dist/commonjs/components/toggle-button/toggle-button-group.d.ts.map +1 -1
- package/dist/commonjs/components/toggle-button/toggle-button-group.js +61 -9
- package/dist/commonjs/components/toggle-button/toggle-button-group.js.map +1 -1
- package/dist/commonjs/components/toggle-button/toggle-button.d.ts +8 -8
- package/dist/commonjs/components/toggle-button/toggle-button.d.ts.map +1 -1
- package/dist/commonjs/components/toggle-button/toggle-button.js +6 -6
- package/dist/commonjs/components/toggle-button/toggle-button.js.map +1 -1
- package/dist/commonjs/components/toggle-button/toggle-icon-button.d.ts +7 -6
- package/dist/commonjs/components/toggle-button/toggle-icon-button.d.ts.map +1 -1
- package/dist/commonjs/components/toggle-button/toggle-icon-button.js +7 -10
- package/dist/commonjs/components/toggle-button/toggle-icon-button.js.map +1 -1
- package/dist/commonjs/components/types.d.ts +14 -1
- package/dist/commonjs/components/types.d.ts.map +1 -1
- package/dist/commonjs/components/types.js.map +1 -1
- package/dist/commonjs/i18n/messages/en-US.d.ts.map +1 -1
- package/dist/commonjs/i18n/messages/en-US.js +1 -0
- package/dist/commonjs/i18n/messages/en-US.js.map +1 -1
- package/dist/commonjs/i18n/messages/types.d.ts +6 -0
- package/dist/commonjs/i18n/messages/types.d.ts.map +1 -1
- package/dist/commonjs/i18n/messages/types.js.map +1 -1
- package/dist/commonjs/icons/category-apparel.d.ts.map +1 -1
- package/dist/commonjs/icons/category-apparel.js +1 -1
- package/dist/commonjs/icons/category-apparel.js.map +1 -1
- package/dist/commonjs/icons/clock-user.d.ts +8 -0
- package/dist/commonjs/icons/clock-user.d.ts.map +1 -0
- package/dist/commonjs/icons/clock-user.js +24 -0
- package/dist/commonjs/icons/clock-user.js.map +1 -0
- package/dist/commonjs/icons/external-link.d.ts +8 -0
- package/dist/commonjs/icons/external-link.d.ts.map +1 -0
- package/dist/commonjs/icons/external-link.js +24 -0
- package/dist/commonjs/icons/external-link.js.map +1 -0
- package/dist/commonjs/icons/file-design.d.ts +8 -0
- package/dist/commonjs/icons/file-design.d.ts.map +1 -0
- package/dist/commonjs/icons/file-design.js +24 -0
- package/dist/commonjs/icons/file-design.js.map +1 -0
- package/dist/commonjs/icons/index.d.ts +11 -0
- package/dist/commonjs/icons/index.d.ts.map +1 -1
- package/dist/commonjs/icons/index.js +24 -2
- package/dist/commonjs/icons/index.js.map +1 -1
- package/dist/commonjs/icons/invoice.d.ts +8 -0
- package/dist/commonjs/icons/invoice.d.ts.map +1 -0
- package/dist/commonjs/icons/invoice.js +24 -0
- package/dist/commonjs/icons/invoice.js.map +1 -0
- package/dist/commonjs/icons/print.d.ts +8 -0
- package/dist/commonjs/icons/print.d.ts.map +1 -0
- package/dist/commonjs/icons/print.js +24 -0
- package/dist/commonjs/icons/print.js.map +1 -0
- package/dist/commonjs/icons/refresh.d.ts +8 -0
- package/dist/commonjs/icons/refresh.d.ts.map +1 -0
- package/dist/commonjs/icons/refresh.js +24 -0
- package/dist/commonjs/icons/refresh.js.map +1 -0
- package/dist/commonjs/icons/share-alt.d.ts +8 -0
- package/dist/commonjs/icons/share-alt.d.ts.map +1 -0
- package/dist/commonjs/icons/share-alt.js +24 -0
- package/dist/commonjs/icons/share-alt.js.map +1 -0
- package/dist/commonjs/icons/share.d.ts +8 -0
- package/dist/commonjs/icons/share.d.ts.map +1 -0
- package/dist/commonjs/icons/share.js +24 -0
- package/dist/commonjs/icons/share.js.map +1 -0
- package/dist/commonjs/icons/style-color.d.ts +8 -0
- package/dist/commonjs/icons/style-color.d.ts.map +1 -0
- package/dist/commonjs/icons/style-color.js +24 -0
- package/dist/commonjs/icons/style-color.js.map +1 -0
- package/dist/commonjs/icons/style-embroidery.d.ts +8 -0
- package/dist/commonjs/icons/style-embroidery.d.ts.map +1 -0
- package/dist/commonjs/icons/style-embroidery.js +24 -0
- package/dist/commonjs/icons/style-embroidery.js.map +1 -0
- package/dist/commonjs/icons/style-monochrome.d.ts +8 -0
- package/dist/commonjs/icons/style-monochrome.d.ts.map +1 -0
- package/dist/commonjs/icons/style-monochrome.js +24 -0
- package/dist/commonjs/icons/style-monochrome.js.map +1 -0
- package/dist/commonjs/index.d.ts +5 -5
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +5 -5
- package/dist/commonjs/index.js.map +1 -1
- package/dist/esm/components/checkbox/checkbox-group.d.ts +2 -2
- package/dist/esm/components/checkbox/checkbox-group.d.ts.map +1 -1
- package/dist/esm/components/checkbox/checkbox-group.js +8 -1
- package/dist/esm/components/checkbox/checkbox-group.js.map +1 -1
- package/dist/esm/components/checkbox/checkbox.d.ts +1 -1
- package/dist/esm/components/checkbox/checkbox.d.ts.map +1 -1
- package/dist/esm/components/checkbox/checkbox.js.map +1 -1
- package/dist/esm/components/combo-box/combo-box.d.ts +2 -2
- package/dist/esm/components/combo-box/combo-box.d.ts.map +1 -1
- package/dist/esm/components/combo-box/combo-box.js +7 -3
- package/dist/esm/components/combo-box/combo-box.js.map +1 -1
- package/dist/esm/components/date-picker/date-picker.d.ts +1 -1
- package/dist/esm/components/date-picker/date-picker.d.ts.map +1 -1
- package/dist/esm/components/date-picker/date-picker.js.map +1 -1
- package/dist/esm/components/drawer/drawer.d.ts +19 -18
- package/dist/esm/components/drawer/drawer.d.ts.map +1 -1
- package/dist/esm/components/drawer/drawer.js +12 -17
- package/dist/esm/components/drawer/drawer.js.map +1 -1
- package/dist/esm/components/file-picker/file-picker.d.ts.map +1 -1
- package/dist/esm/components/file-picker/file-picker.js +3 -3
- package/dist/esm/components/file-picker/file-picker.js.map +1 -1
- package/dist/esm/components/modal-dialog/modal-dialog.d.ts +2 -1
- package/dist/esm/components/modal-dialog/modal-dialog.d.ts.map +1 -1
- package/dist/esm/components/modal-dialog/modal-dialog.js +1 -1
- package/dist/esm/components/modal-dialog/modal-dialog.js.map +1 -1
- package/dist/esm/components/radio/radio-group.d.ts +2 -2
- package/dist/esm/components/radio/radio-group.d.ts.map +1 -1
- package/dist/esm/components/radio/radio-group.js +8 -1
- package/dist/esm/components/radio/radio-group.js.map +1 -1
- package/dist/esm/components/select/select.d.ts +2 -2
- package/dist/esm/components/select/select.d.ts.map +1 -1
- package/dist/esm/components/select/select.js +7 -3
- package/dist/esm/components/select/select.js.map +1 -1
- package/dist/esm/components/tabs/tabs.d.ts +1 -1
- package/dist/esm/components/tabs/tabs.d.ts.map +1 -1
- package/dist/esm/components/tabs/tabs.js +2 -4
- package/dist/esm/components/tabs/tabs.js.map +1 -1
- package/dist/esm/components/tag/tag-group.d.ts +1 -1
- package/dist/esm/components/tag/tag-group.d.ts.map +1 -1
- package/dist/esm/components/tag/tag-group.js.map +1 -1
- package/dist/esm/components/tag/tag.d.ts +1 -1
- package/dist/esm/components/tag/tag.d.ts.map +1 -1
- package/dist/esm/components/tag/tag.js.map +1 -1
- package/dist/esm/components/tag-field/tag-field.d.ts.map +1 -1
- package/dist/esm/components/tag-field/tag-field.js +6 -3
- package/dist/esm/components/tag-field/tag-field.js.map +1 -1
- package/dist/esm/components/text-inputs/text-field.d.ts.map +1 -1
- package/dist/esm/components/text-inputs/text-field.js +1 -1
- package/dist/esm/components/text-inputs/text-field.js.map +1 -1
- package/dist/esm/components/toggle/toggle.d.ts +1 -1
- package/dist/esm/components/toggle/toggle.d.ts.map +1 -1
- package/dist/esm/components/toggle/toggle.js.map +1 -1
- package/dist/esm/components/toggle-button/context.d.ts +2 -0
- package/dist/esm/components/toggle-button/context.d.ts.map +1 -0
- package/dist/esm/components/toggle-button/context.js +4 -0
- package/dist/esm/components/toggle-button/context.js.map +1 -0
- package/dist/esm/components/toggle-button/internal-toggle-button.d.ts +2 -0
- package/dist/esm/components/toggle-button/internal-toggle-button.d.ts.map +1 -0
- package/dist/esm/components/toggle-button/internal-toggle-button.js +51 -0
- package/dist/esm/components/toggle-button/internal-toggle-button.js.map +1 -0
- package/dist/esm/components/toggle-button/toggle-button-group.d.ts +10 -6
- package/dist/esm/components/toggle-button/toggle-button-group.d.ts.map +1 -1
- package/dist/esm/components/toggle-button/toggle-button-group.js +62 -10
- package/dist/esm/components/toggle-button/toggle-button-group.js.map +1 -1
- package/dist/esm/components/toggle-button/toggle-button.d.ts +8 -8
- package/dist/esm/components/toggle-button/toggle-button.d.ts.map +1 -1
- package/dist/esm/components/toggle-button/toggle-button.js +5 -5
- package/dist/esm/components/toggle-button/toggle-button.js.map +1 -1
- package/dist/esm/components/toggle-button/toggle-icon-button.d.ts +7 -6
- package/dist/esm/components/toggle-button/toggle-icon-button.d.ts.map +1 -1
- package/dist/esm/components/toggle-button/toggle-icon-button.js +6 -6
- package/dist/esm/components/toggle-button/toggle-icon-button.js.map +1 -1
- package/dist/esm/components/types.d.ts +14 -1
- package/dist/esm/components/types.d.ts.map +1 -1
- package/dist/esm/components/types.js.map +1 -1
- package/dist/esm/i18n/messages/en-US.d.ts.map +1 -1
- package/dist/esm/i18n/messages/en-US.js +1 -0
- package/dist/esm/i18n/messages/en-US.js.map +1 -1
- package/dist/esm/i18n/messages/types.d.ts +6 -0
- package/dist/esm/i18n/messages/types.d.ts.map +1 -1
- package/dist/esm/i18n/messages/types.js.map +1 -1
- package/dist/esm/icons/category-apparel.d.ts.map +1 -1
- package/dist/esm/icons/category-apparel.js +1 -1
- package/dist/esm/icons/category-apparel.js.map +1 -1
- package/dist/esm/icons/clock-user.d.ts +8 -0
- package/dist/esm/icons/clock-user.d.ts.map +1 -0
- package/dist/esm/icons/clock-user.js +19 -0
- package/dist/esm/icons/clock-user.js.map +1 -0
- package/dist/esm/icons/external-link.d.ts +8 -0
- package/dist/esm/icons/external-link.d.ts.map +1 -0
- package/dist/esm/icons/external-link.js +19 -0
- package/dist/esm/icons/external-link.js.map +1 -0
- package/dist/esm/icons/file-design.d.ts +8 -0
- package/dist/esm/icons/file-design.d.ts.map +1 -0
- package/dist/esm/icons/file-design.js +19 -0
- package/dist/esm/icons/file-design.js.map +1 -0
- package/dist/esm/icons/index.d.ts +11 -0
- package/dist/esm/icons/index.d.ts.map +1 -1
- package/dist/esm/icons/index.js +11 -0
- package/dist/esm/icons/index.js.map +1 -1
- package/dist/esm/icons/invoice.d.ts +8 -0
- package/dist/esm/icons/invoice.d.ts.map +1 -0
- package/dist/esm/icons/invoice.js +19 -0
- package/dist/esm/icons/invoice.js.map +1 -0
- package/dist/esm/icons/print.d.ts +8 -0
- package/dist/esm/icons/print.d.ts.map +1 -0
- package/dist/esm/icons/print.js +19 -0
- package/dist/esm/icons/print.js.map +1 -0
- package/dist/esm/icons/refresh.d.ts +8 -0
- package/dist/esm/icons/refresh.d.ts.map +1 -0
- package/dist/esm/icons/refresh.js +19 -0
- package/dist/esm/icons/refresh.js.map +1 -0
- package/dist/esm/icons/share-alt.d.ts +8 -0
- package/dist/esm/icons/share-alt.d.ts.map +1 -0
- package/dist/esm/icons/share-alt.js +19 -0
- package/dist/esm/icons/share-alt.js.map +1 -0
- package/dist/esm/icons/share.d.ts +8 -0
- package/dist/esm/icons/share.d.ts.map +1 -0
- package/dist/esm/icons/share.js +19 -0
- package/dist/esm/icons/share.js.map +1 -0
- package/dist/esm/icons/style-color.d.ts +8 -0
- package/dist/esm/icons/style-color.d.ts.map +1 -0
- package/dist/esm/icons/style-color.js +19 -0
- package/dist/esm/icons/style-color.js.map +1 -0
- package/dist/esm/icons/style-embroidery.d.ts +8 -0
- package/dist/esm/icons/style-embroidery.d.ts.map +1 -0
- package/dist/esm/icons/style-embroidery.js +19 -0
- package/dist/esm/icons/style-embroidery.js.map +1 -0
- package/dist/esm/icons/style-monochrome.d.ts +8 -0
- package/dist/esm/icons/style-monochrome.d.ts.map +1 -0
- package/dist/esm/icons/style-monochrome.js +19 -0
- package/dist/esm/icons/style-monochrome.js.map +1 -0
- package/dist/esm/index.d.ts +5 -5
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +5 -5
- package/dist/esm/index.js.map +1 -1
- package/dist-styles/core.css +1 -1
- package/dist-styles/styles.css +1 -1
- package/package.json +19 -15
|
@@ -27,7 +27,7 @@ const utils_js_1 = require("../typography/utils.js");
|
|
|
27
27
|
const tag_field_input_js_1 = require("./tag-field-input.js");
|
|
28
28
|
const tag_field_list_box_js_1 = require("./tag-field-list-box.js");
|
|
29
29
|
const tag_field_tags_js_1 = require("./tag-field-tags.js");
|
|
30
|
-
function TagField({ label, description, error, items, children, placeholder, UNSAFE_className, UNSAFE_style, isReadOnly, inputValue: consumerInputValue, defaultInputValue: defaultConsumerInputValue, onInputChange, name, validate, onScroll, selectedKeys: consumerSelectedKeys, defaultSelectedKeys: defaultConsumerSelectedKeys, onSelectionChange, id, renderEmptyState, isVirtualized = false, ...props }, ref) {
|
|
30
|
+
function TagField({ label, description, error, items, children, placeholder, UNSAFE_className, UNSAFE_style, isReadOnly, inputValue: consumerInputValue, defaultInputValue: defaultConsumerInputValue, onInputChange, form, name, validate, onScroll, selectedKeys: consumerSelectedKeys, defaultSelectedKeys: defaultConsumerSelectedKeys, onSelectionChange, id, renderEmptyState, isVirtualized = false, ...props }, ref) {
|
|
31
31
|
const { 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, isRequired, isDisabled, isInvalid } = props;
|
|
32
32
|
(0, use_production_warning_js_1.useProductionWarning)(() => {
|
|
33
33
|
if (!label && !ariaLabel && !ariaLabelledBy) {
|
|
@@ -60,7 +60,9 @@ function TagField({ label, description, error, items, children, placeholder, UNS
|
|
|
60
60
|
validate,
|
|
61
61
|
validationBehavior: 'native',
|
|
62
62
|
});
|
|
63
|
-
|
|
63
|
+
const [initialSelectedKeys] = (0, react_1.useState)(selectedKeys);
|
|
64
|
+
const [initialInputValue] = (0, react_1.useState)(inputValue);
|
|
65
|
+
(0, utils_1.useFormReset)(formInputRef, [defaultConsumerSelectedKeys ?? initialSelectedKeys, defaultConsumerInputValue ?? initialInputValue], ([a, b]) => {
|
|
64
66
|
setSelectedKeys(a);
|
|
65
67
|
setInputValue(b);
|
|
66
68
|
});
|
|
@@ -117,7 +119,8 @@ function TagField({ label, description, error, items, children, placeholder, UNS
|
|
|
117
119
|
[react_aria_components_1.FieldErrorContext, validationState.displayValidation],
|
|
118
120
|
], children: [(0, jsx_runtime_1.jsx)(form_field_js_1.FormFieldLabel, { isRequired: isRequired, isDisabled: isDisabled, children: label }), (0, jsx_runtime_1.jsxs)(react_aria_components_1.Group, { className: "cim-combo-box-input-group", children: [(0, jsx_runtime_1.jsx)(tag_field_input_js_1.TagFieldInput, { "aria-describedby": props['aria-describedby'], isReadOnly: isReadOnly, isRequired: isRequired, isInvalid: validationState.displayValidation.isInvalid, placeholder: selectedSet.size === 0 && placeholder
|
|
119
121
|
? placeholder
|
|
120
|
-
: messages.format('itemsSelected', { selectedItemCount: selectedSet.size }), onFocusChange: onFocusChange }), (0, jsx_runtime_1.jsx)(react_aria_components_1.Button, { className: "cim-combo-box-button", children: (0, jsx_runtime_1.jsx)(index_js_1.IconChevronDown, {}) })] }), (0, jsx_runtime_1.jsx)(form_field_js_1.FormFieldError, { children: error }), (0, jsx_runtime_1.jsx)(form_field_js_1.FormFieldDescription, { children: description }), (0, jsx_runtime_1.jsx)(tag_field_tags_js_1.TagFieldTags, { inputId: inputId, selectedKeys: selectedSet, isDisabled: isDisabled, isReadOnly: isReadOnly, renderEmptyState: renderEmptyState, onRemove: onItemSelectionChange }), (0, jsx_runtime_1.jsx)(collapsible_list_js_1.CollapsibleList, { offset: 5, maxHeight: 315, children: (0, jsx_runtime_1.jsx)(tag_field_list_box_js_1.TagFieldListBox, { inputId: inputId, items: items, selectedKeys: selectedSet, setSelectedKeys: setSelectedKeys, onScroll: onScroll, isVirtualized: isVirtualized, children: children }) })] }) }), (0, jsx_runtime_1.jsx)(react_aria_components_1.Input, { ref: formInputRef, style: { display: 'none' }, value: selectedSet.size || '', required: isRequired, "aria-invalid": validationState.displayValidation.isInvalid || undefined, onChange: () => { } }), name &&
|
|
122
|
+
: messages.format('itemsSelected', { selectedItemCount: selectedSet.size }), onFocusChange: onFocusChange }), (0, jsx_runtime_1.jsx)(react_aria_components_1.Button, { className: "cim-combo-box-button", children: (0, jsx_runtime_1.jsx)(index_js_1.IconChevronDown, {}) })] }), (0, jsx_runtime_1.jsx)(form_field_js_1.FormFieldError, { children: error }), (0, jsx_runtime_1.jsx)(form_field_js_1.FormFieldDescription, { children: description }), (0, jsx_runtime_1.jsx)(tag_field_tags_js_1.TagFieldTags, { inputId: inputId, selectedKeys: selectedSet, isDisabled: isDisabled, isReadOnly: isReadOnly, renderEmptyState: renderEmptyState, onRemove: onItemSelectionChange }), (0, jsx_runtime_1.jsx)(collapsible_list_js_1.CollapsibleList, { offset: 5, maxHeight: 315, children: (0, jsx_runtime_1.jsx)(tag_field_list_box_js_1.TagFieldListBox, { inputId: inputId, items: items, selectedKeys: selectedSet, setSelectedKeys: setSelectedKeys, onScroll: onScroll, isVirtualized: isVirtualized, children: children }) })] }) }), (0, jsx_runtime_1.jsx)(react_aria_components_1.Input, { ref: formInputRef, style: { display: 'none' }, value: selectedSet.size || '', required: isRequired, "aria-invalid": validationState.displayValidation.isInvalid || undefined, onChange: () => { } }), name &&
|
|
123
|
+
[...selectedSet].map((value) => (0, jsx_runtime_1.jsx)("input", { type: "hidden", form: form, name: name, value: value }, value))] }));
|
|
121
124
|
}
|
|
122
125
|
/**
|
|
123
126
|
* Allows users to filter a collapsible list and select multiple items from it.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tag-field.js","sourceRoot":"","sources":["../../../../src/components/tag-field/tag-field.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;AAgVb,oCAqBC;AAYD,0CAoBC;;AAnYD,2CAAqD;AACrD,6CAAmE;AACnE,8CAA6D;AAC7D,gDAA0D;AAC1D,gDAAwB;AACxB,iCAAqE;AACrE,iEAiB+B;AAC/B,yDAAkD;AAClD,kFAA2E;AAC3E,mDAAsE;AACtE,mEAA4D;AAC5D,qFAA6E;AAC7E,mEAA2D;AAC3D,0FAAmF;AACnF,wEAA4G;AAU5G,qDAAmD;AACnD,6DAAqD;AACrD,mEAA0D;AAC1D,2DAAmD;AA2CnD,SAAS,QAAQ,CACf,EACE,KAAK,EACL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AO,CAAC,IAAI,CAAC,gFAAgF,CAAC,CAAC;IACjG,CAAC;IAED,OAAO,CACL,wBAAC,sCAAiB,OAAK,KAAK,EAAE,SAAS,EAAC,uBAAuB,aAC7D,uBAAC,8BAAS,IACR,SAAS,EAAE,IAAA,cAAI,EAAC,8BAA8B,EAAE,IAAA,oBAAS,EAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC,YAExG,KAAK,GACI,EACZ,uBAAC,kCAAa,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAAiB,IACrC,CACrB,CAAC;AACJ,CAAC;AAED,eAAe,CAAC,WAAW,GAAG,iBAAiB,CAAC","sourcesContent":["'use client';\n\nimport { useFormValidation } from '@react-aria/form';\nimport { useFormReset, useId, useSlotId } from '@react-aria/utils';\nimport { useFormValidationState } from '@react-stately/form';\nimport { useControlledState } from '@react-stately/utils';\nimport clsx from 'clsx';\nimport { useMemo, useRef, useState, type ForwardedRef } from 'react';\nimport {\n Button as RACButton,\n Collection as RACCollection,\n ComboBox as RACComboBox,\n Group as RACGroup,\n Header as RACHeader,\n Input as RACInput,\n type ListBoxProps as RACListBoxProps,\n ListBoxItem as RACListBoxItem,\n ListBoxSection as RACListBoxSection,\n Text as RACText,\n type ComboBoxProps as RACComboBoxProps,\n type ListBoxItemProps as RACListBoxItemProps,\n Provider as RACProvider,\n TextContext as RACTextContext,\n GroupContext as RACGroupContext,\n FieldErrorContext as RACFieldErrorContext,\n} from 'react-aria-components';\nimport { forwardRef } from '../../forward-ref.js';\nimport { useLocalizedMessages } from '../../i18n/localization-provider.js';\nimport { IconCheckBold, IconChevronDown } from '../../icons/index.js';\nimport { isProduction } from '../../utils/is-production.js';\nimport { useProductionWarning } from '../../utils/use-production-warning.js';\nimport { withStyleProps } from '../../with-style-props.js';\nimport { CollapsibleList } from '../internal/collapsible-list/collapsible-list.js';\nimport { FormFieldDescription, FormFieldError, FormFieldLabel } from '../internal/form-field/form-field.js';\nimport type { TagGroupProps } from '../tag/tag-group.js';\nimport type {\n CollectionItem,\n CollectionProps,\n CommonProps,\n FieldWithPlaceholderProps,\n Key,\n StringLikeChildren,\n} from '../types.js';\nimport { textStyle } from '../typography/utils.js';\nimport { TagFieldInput } from './tag-field-input.js';\nimport { TagFieldListBox } from './tag-field-list-box.js';\nimport { TagFieldTags } from './tag-field-tags.js';\n\n/** Represents the state of the `TagField` component for validation purposes. */\nexport interface TagFieldValidationValue {\n /** The selected keys in the TagField. */\n selectedKeys: Set<Key> | null;\n /** The value of the TagField input. */\n inputValue: string;\n}\n\nexport interface TagFieldProps<T extends CollectionItem = CollectionItem>\n extends CommonProps,\n FieldWithPlaceholderProps<TagFieldValidationValue>,\n CollectionProps<T>,\n Pick<\n RACComboBoxProps<T>,\n | 'isRequired'\n | 'isDisabled'\n | 'isInvalid'\n | 'isReadOnly'\n | 'inputValue'\n | 'defaultInputValue'\n | 'autoFocus'\n | 'onInputChange'\n | 'onFocus'\n | 'onBlur'\n | 'onOpenChange'\n >,\n Pick<RACListBoxProps<T>, 'onScroll'>,\n Pick<TagGroupProps<T>, 'renderEmptyState'> {\n /** The currently selected keys in the collection (controlled). */\n selectedKeys?: Iterable<Key>;\n /** The initial selected keys in the collection (uncontrolled). */\n defaultSelectedKeys?: Iterable<Key>;\n /** Handler that is called when the selection changes. */\n onSelectionChange?: (keys: Set<Key>) => void;\n /**\n * Whether the list of options should be virtualized. Use this as a performance optimization for large lists.\n * @default false\n */\n isVirtualized?: boolean;\n}\n\nfunction TagField<T extends CollectionItem>(\n {\n label,\n description,\n error,\n items,\n children,\n placeholder,\n UNSAFE_className,\n UNSAFE_style,\n isReadOnly,\n inputValue: consumerInputValue,\n defaultInputValue: defaultConsumerInputValue,\n onInputChange,\n name,\n validate,\n onScroll,\n selectedKeys: consumerSelectedKeys,\n defaultSelectedKeys: defaultConsumerSelectedKeys,\n onSelectionChange,\n id,\n renderEmptyState,\n isVirtualized = false,\n ...props\n }: TagFieldProps<T>,\n ref: ForwardedRef<HTMLDivElement>,\n) {\n const { 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, isRequired, isDisabled, isInvalid } = props;\n\n useProductionWarning(() => {\n if (!label && !ariaLabel && !ariaLabelledBy) {\n console.warn('TagField requires one of label / aria-label / aria-labelledby for accessibility');\n }\n }, [label, ariaLabel, ariaLabelledBy]);\n\n if (!isProduction() && items != null && typeof children !== 'function') {\n console.warn('`TagField` requires `children` to be a function when using `items` prop');\n }\n\n const messages = useLocalizedMessages('tagField');\n\n // State\n\n const [defaultSelectedKeys] = useState(() => defaultConsumerSelectedKeys ?? new Set<Key>());\n const [selectedKeys, setSelectedKeys] = useControlledState(\n consumerSelectedKeys,\n defaultSelectedKeys,\n onSelectionChange,\n );\n const [inputValue, setInputValue] = useControlledState(\n consumerInputValue,\n defaultConsumerInputValue ?? '',\n onInputChange,\n );\n\n const selectedSet = useMemo(() => {\n // eslint-disable-next-line unicorn/no-instanceof-builtins\n if (selectedKeys instanceof Set) {\n return new Set<Key>(selectedKeys.values());\n }\n\n return new Set<Key>(selectedKeys);\n }, [selectedKeys]);\n\n // Validation\n\n const inputId = useId(id);\n const formInputRef = useRef<HTMLInputElement>(null);\n\n const validationState = useFormValidationState({\n name,\n value: useMemo(() => ({ selectedKeys: selectedSet, inputValue }), [selectedSet, inputValue]),\n isInvalid,\n isRequired,\n validate,\n validationBehavior: 'native',\n });\n\n useFormReset<[Set<Key>, string]>(formInputRef, [selectedSet, inputValue], ([a, b]) => {\n setSelectedKeys(a);\n setInputValue(b);\n });\n\n useFormValidation(\n {\n focus: () => {\n // Querying by element ID because a ref is always null here, I don't know why :(\n document.getElementById(inputId)?.focus();\n },\n isInvalid,\n isRequired,\n validate,\n validationBehavior: 'native',\n },\n validationState,\n formInputRef,\n );\n\n // Event handlers\n\n // Commit validation on input blur if the values have changed\n const inputValueOnFocus = useRef(inputValue);\n const selectedSetOnFocus = useRef(selectedSet);\n\n const onFocusChange = (isFocused: boolean) => {\n if (isFocused) {\n inputValueOnFocus.current = inputValue;\n selectedSetOnFocus.current = selectedSet;\n } else if (inputValue !== inputValueOnFocus.current || selectedSet !== selectedSetOnFocus.current) {\n validationState.commitValidation();\n }\n };\n\n const onItemSelectionChange = (key: Key) => {\n if (selectedSet.has(key)) {\n // This is a temporary mutation followed immediately by a state update, so this is fine\n // eslint-disable-next-line react-hooks/react-compiler\n selectedSet.delete(key);\n } else {\n selectedSet.add(key);\n }\n\n setSelectedKeys(new Set(selectedSet.values()));\n validationState.commitValidation();\n };\n\n // Text slots\n\n const descriptionId = useSlotId([Boolean(description)]);\n\n const errorMessageId = useSlotId([\n Boolean(error || validationState.displayValidation.validationErrors),\n validationState.displayValidation.isInvalid,\n ]);\n\n return (\n <>\n <RACComboBox\n {...props}\n ref={ref}\n id={inputId}\n className={clsx('cim-combo-box', 'cim-tag-field', UNSAFE_className)}\n style={UNSAFE_style}\n // Force no internal selection - we handle selection manually\n selectedKey={null}\n inputValue={inputValue}\n onInputChange={setInputValue}\n menuTrigger=\"focus\"\n isReadOnly={isReadOnly}\n data-readonly={isReadOnly ? true : undefined}\n onSelectionChange={(key) => {\n if (key) {\n onItemSelectionChange(key);\n }\n }}\n >\n <RACProvider\n values={[\n [RACTextContext, { slots: { description: { id: descriptionId }, errorMessage: { id: errorMessageId } } }],\n [RACGroupContext, { isInvalid: validationState.displayValidation.isInvalid, isDisabled }],\n [RACFieldErrorContext, validationState.displayValidation],\n ]}\n >\n <FormFieldLabel isRequired={isRequired} isDisabled={isDisabled}>\n {label}\n </FormFieldLabel>\n\n <RACGroup className=\"cim-combo-box-input-group\">\n <TagFieldInput\n aria-describedby={props['aria-describedby']}\n isReadOnly={isReadOnly}\n isRequired={isRequired}\n isInvalid={validationState.displayValidation.isInvalid}\n placeholder={\n selectedSet.size === 0 && placeholder\n ? placeholder\n : messages.format('itemsSelected', { selectedItemCount: selectedSet.size })\n }\n onFocusChange={onFocusChange}\n />\n <RACButton className=\"cim-combo-box-button\">\n <IconChevronDown />\n </RACButton>\n </RACGroup>\n\n <FormFieldError>{error}</FormFieldError>\n <FormFieldDescription>{description}</FormFieldDescription>\n\n <TagFieldTags<T>\n inputId={inputId}\n selectedKeys={selectedSet}\n isDisabled={isDisabled}\n isReadOnly={isReadOnly}\n renderEmptyState={renderEmptyState}\n onRemove={onItemSelectionChange}\n />\n\n <CollapsibleList\n offset={5} // 1px border + 4px actual offset\n maxHeight={315}\n >\n <TagFieldListBox<T>\n inputId={inputId}\n items={items}\n selectedKeys={selectedSet}\n setSelectedKeys={setSelectedKeys}\n onScroll={onScroll}\n isVirtualized={isVirtualized}\n >\n {children}\n </TagFieldListBox>\n </CollapsibleList>\n </RACProvider>\n </RACComboBox>\n\n {/* This input is used for native form validation. We can't use the combo box input because its value has no relation to the selected values. */}\n <RACInput\n ref={formInputRef}\n style={{ display: 'none' }}\n value={selectedSet.size || ''}\n required={isRequired}\n aria-invalid={validationState.displayValidation.isInvalid || undefined}\n onChange={() => {}}\n />\n\n {/* These hidden inputs provide values when a form is submitted. */}\n {name && [...selectedSet].map((value) => <input type=\"hidden\" key={value} name={name} value={value} />)}\n </>\n );\n}\n\n/**\n * Allows users to filter a collapsible list and select multiple items from it.\n *\n * See [tag field usage guidelines](https://ui.cimpress.com/components/tag-field).\n */\nconst _TagField = withStyleProps(forwardRef(TagField), 'TagField');\n\nexport { _TagField as TagField };\n\nexport interface TagFieldItemProps<T extends CollectionItem>\n extends Pick<RACListBoxItemProps<T>, 'id' | 'isDisabled' | 'onHoverStart' | 'onHoverEnd'> {\n /** The content to display as the label. */\n children: StringLikeChildren;\n}\n\n/** Renders a single list item within `TagField`. */\nexport function TagFieldItem<T extends CollectionItem>({ children, ...props }: TagFieldItemProps<T>) {\n const textValue =\n typeof children === 'string' ? children : typeof children === 'number' ? String(children) : children.join('');\n\n return (\n <RACListBoxItem {...props} className=\"cim-tag-field-item cim-checkbox\" textValue={textValue}>\n {({ isDisabled }) => (\n <>\n <div className=\"cim-checkbox-toggle-wrapper\" aria-hidden>\n <div className=\"cim-checkbox-toggle\">\n <IconCheckBold />\n </div>\n </div>\n\n <RACText slot=\"label\" className={textStyle({ variant: 'medium', tone: isDisabled ? 'muted' : 'base' })}>\n {children}\n </RACText>\n </>\n )}\n </RACListBoxItem>\n );\n}\n\nTagFieldItem.displayName = 'TagFieldItem';\n\nexport interface TagFieldSectionProps<T extends CollectionItem> extends CollectionProps<T> {\n /** The ID of the section. Has to be unique across all sections and items. */\n id?: Key;\n /** The content to display as the section title. */\n title: string;\n}\n\n/** Groups list items within `TagField` into a section. */\nexport function TagFieldSection<T extends CollectionItem>({\n title,\n children,\n items,\n ...props\n}: TagFieldSectionProps<T>) {\n if (!isProduction() && items != null && typeof children !== 'function') {\n console.warn('`TagFieldSection` requires `children` to be a function when using `items` prop');\n }\n\n return (\n <RACListBoxSection {...props} className=\"cim-combo-box-section\">\n <RACHeader\n className={clsx('cim-combo-box-section-header', textStyle({ variant: 'small-semibold', tone: 'subtle' }))}\n >\n {title}\n </RACHeader>\n <RACCollection items={items}>{children}</RACCollection>\n </RACListBoxSection>\n );\n}\n\nTagFieldSection.displayName = 'TagFieldSection';\n"]}
|
|
1
|
+
{"version":3,"file":"tag-field.js","sourceRoot":"","sources":["../../../../src/components/tag-field/tag-field.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;AAyVb,oCAqBC;AAYD,0CAoBC;;AA5YD,2CAAqD;AACrD,6CAAmE;AACnE,8CAA6D;AAC7D,gDAA0D;AAC1D,gDAAwB;AACxB,iCAAqE;AACrE,iEAiB+B;AAC/B,yDAAkD;AAClD,kFAA2E;AAC3E,mDAAsE;AACtE,mEAA4D;AAC5D,qFAA6E;AAC7E,mEAA2D;AAC3D,0FAAmF;AACnF,wEAA4G;AAU5G,qDAAmD;AACnD,6DAAqD;AACrD,mEAA0D;AAC1D,2DAAmD;AA2CnD,SAAS,QAAQ,CACf,EACE,KAAK,EACL,WAAW,EACX,KAAK,EACL,KAAK,EACL,Q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B,eAAe,CAA2B,EACxD,KAAK,EACL,QAAQ,EACR,KAAK,EACL,GAAG,KAAK,EACgB;IACxB,IAAI,CAAC,IAAA,+BAAY,GAAE,IAAI,KAAK,IAAI,IAAI,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE,CAAC;QACvE,OAAO,CAAC,IAAI,CAAC,gFAAgF,CAAC,CAAC;IACjG,CAAC;IAED,OAAO,CACL,wBAAC,sCAAiB,OAAK,KAAK,EAAE,SAAS,EAAC,uBAAuB,aAC7D,uBAAC,8BAAS,IACR,SAAS,EAAE,IAAA,cAAI,EAAC,8BAA8B,EAAE,IAAA,oBAAS,EAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC,YAExG,KAAK,GACI,EACZ,uBAAC,kCAAa,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAAiB,IACrC,CACrB,CAAC;AACJ,CAAC;AAED,eAAe,CAAC,WAAW,GAAG,iBAAiB,CAAC","sourcesContent":["'use client';\n\nimport { useFormValidation } from '@react-aria/form';\nimport { useFormReset, useId, useSlotId } from '@react-aria/utils';\nimport { useFormValidationState } from '@react-stately/form';\nimport { useControlledState } from '@react-stately/utils';\nimport clsx from 'clsx';\nimport { useMemo, useRef, useState, type ForwardedRef } from 'react';\nimport {\n Button as RACButton,\n Collection as RACCollection,\n ComboBox as RACComboBox,\n Group as RACGroup,\n Header as RACHeader,\n Input as RACInput,\n type ListBoxProps as RACListBoxProps,\n ListBoxItem as RACListBoxItem,\n ListBoxSection as RACListBoxSection,\n Text as RACText,\n type ComboBoxProps as RACComboBoxProps,\n type ListBoxItemProps as RACListBoxItemProps,\n Provider as RACProvider,\n TextContext as RACTextContext,\n GroupContext as RACGroupContext,\n FieldErrorContext as RACFieldErrorContext,\n} from 'react-aria-components';\nimport { forwardRef } from '../../forward-ref.js';\nimport { useLocalizedMessages } from '../../i18n/localization-provider.js';\nimport { IconCheckBold, IconChevronDown } from '../../icons/index.js';\nimport { isProduction } from '../../utils/is-production.js';\nimport { useProductionWarning } from '../../utils/use-production-warning.js';\nimport { withStyleProps } from '../../with-style-props.js';\nimport { CollapsibleList } from '../internal/collapsible-list/collapsible-list.js';\nimport { FormFieldDescription, FormFieldError, FormFieldLabel } from '../internal/form-field/form-field.js';\nimport type { TagGroupProps } from '../tag/tag-group.js';\nimport type {\n CollectionItem,\n CollectionProps,\n CommonProps,\n FieldWithPlaceholderProps,\n Key,\n StringLikeChildren,\n} from '../types.js';\nimport { textStyle } from '../typography/utils.js';\nimport { TagFieldInput } from './tag-field-input.js';\nimport { TagFieldListBox } from './tag-field-list-box.js';\nimport { TagFieldTags } from './tag-field-tags.js';\n\n/** Represents the state of the `TagField` component for validation purposes. */\nexport interface TagFieldValidationValue {\n /** The selected keys in the TagField. */\n selectedKeys: Set<Key> | null;\n /** The value of the TagField input. */\n inputValue: string;\n}\n\nexport interface TagFieldProps<T extends CollectionItem = CollectionItem>\n extends CommonProps,\n FieldWithPlaceholderProps<TagFieldValidationValue>,\n CollectionProps<T>,\n Pick<\n RACComboBoxProps<T>,\n | 'isRequired'\n | 'isDisabled'\n | 'isInvalid'\n | 'isReadOnly'\n | 'inputValue'\n | 'defaultInputValue'\n | 'autoFocus'\n | 'onInputChange'\n | 'onFocus'\n | 'onBlur'\n | 'onOpenChange'\n >,\n Pick<RACListBoxProps<T>, 'onScroll'>,\n Pick<TagGroupProps<T>, 'renderEmptyState'> {\n /** The currently selected keys in the collection (controlled). */\n selectedKeys?: Iterable<Key>;\n /** The initial selected keys in the collection (uncontrolled). */\n defaultSelectedKeys?: Iterable<Key>;\n /** Handler that is called when the selection changes. */\n onSelectionChange?: (keys: Set<Key>) => void;\n /**\n * Whether the list of options should be virtualized. Use this as a performance optimization for large lists.\n * @default false\n */\n isVirtualized?: boolean;\n}\n\nfunction TagField<T extends CollectionItem>(\n {\n label,\n description,\n error,\n items,\n children,\n placeholder,\n UNSAFE_className,\n UNSAFE_style,\n isReadOnly,\n inputValue: consumerInputValue,\n defaultInputValue: defaultConsumerInputValue,\n onInputChange,\n form,\n name,\n validate,\n onScroll,\n selectedKeys: consumerSelectedKeys,\n defaultSelectedKeys: defaultConsumerSelectedKeys,\n onSelectionChange,\n id,\n renderEmptyState,\n isVirtualized = false,\n ...props\n }: TagFieldProps<T>,\n ref: ForwardedRef<HTMLDivElement>,\n) {\n const { 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, isRequired, isDisabled, isInvalid } = props;\n\n useProductionWarning(() => {\n if (!label && !ariaLabel && !ariaLabelledBy) {\n console.warn('TagField requires one of label / aria-label / aria-labelledby for accessibility');\n }\n }, [label, ariaLabel, ariaLabelledBy]);\n\n if (!isProduction() && items != null && typeof children !== 'function') {\n console.warn('`TagField` requires `children` to be a function when using `items` prop');\n }\n\n const messages = useLocalizedMessages('tagField');\n\n // State\n\n const [defaultSelectedKeys] = useState(() => defaultConsumerSelectedKeys ?? new Set<Key>());\n const [selectedKeys, setSelectedKeys] = useControlledState(\n consumerSelectedKeys,\n defaultSelectedKeys,\n onSelectionChange,\n );\n const [inputValue, setInputValue] = useControlledState(\n consumerInputValue,\n defaultConsumerInputValue ?? '',\n onInputChange,\n );\n\n const selectedSet = useMemo(() => {\n // eslint-disable-next-line unicorn/no-instanceof-builtins\n if (selectedKeys instanceof Set) {\n return new Set<Key>(selectedKeys.values());\n }\n\n return new Set<Key>(selectedKeys);\n }, [selectedKeys]);\n\n // Validation\n\n const inputId = useId(id);\n const formInputRef = useRef<HTMLInputElement>(null);\n\n const validationState = useFormValidationState({\n name,\n value: useMemo(() => ({ selectedKeys: selectedSet, inputValue }), [selectedSet, inputValue]),\n isInvalid,\n isRequired,\n validate,\n validationBehavior: 'native',\n });\n\n const [initialSelectedKeys] = useState(selectedKeys);\n const [initialInputValue] = useState(inputValue);\n\n useFormReset<[Iterable<Key>, string]>(\n formInputRef,\n [defaultConsumerSelectedKeys ?? initialSelectedKeys, defaultConsumerInputValue ?? initialInputValue],\n ([a, b]) => {\n setSelectedKeys(a);\n setInputValue(b);\n },\n );\n\n useFormValidation(\n {\n focus: () => {\n // Querying by element ID because a ref is always null here, I don't know why :(\n document.getElementById(inputId)?.focus();\n },\n isInvalid,\n isRequired,\n validate,\n validationBehavior: 'native',\n },\n validationState,\n formInputRef,\n );\n\n // Event handlers\n\n // Commit validation on input blur if the values have changed\n const inputValueOnFocus = useRef(inputValue);\n const selectedSetOnFocus = useRef(selectedSet);\n\n const onFocusChange = (isFocused: boolean) => {\n if (isFocused) {\n inputValueOnFocus.current = inputValue;\n selectedSetOnFocus.current = selectedSet;\n } else if (inputValue !== inputValueOnFocus.current || selectedSet !== selectedSetOnFocus.current) {\n validationState.commitValidation();\n }\n };\n\n const onItemSelectionChange = (key: Key) => {\n if (selectedSet.has(key)) {\n // This is a temporary mutation followed immediately by a state update, so this is fine\n // eslint-disable-next-line react-hooks/react-compiler\n selectedSet.delete(key);\n } else {\n selectedSet.add(key);\n }\n\n setSelectedKeys(new Set(selectedSet.values()));\n validationState.commitValidation();\n };\n\n // Text slots\n\n const descriptionId = useSlotId([Boolean(description)]);\n\n const errorMessageId = useSlotId([\n Boolean(error || validationState.displayValidation.validationErrors),\n validationState.displayValidation.isInvalid,\n ]);\n\n return (\n <>\n <RACComboBox\n {...props}\n ref={ref}\n id={inputId}\n className={clsx('cim-combo-box', 'cim-tag-field', UNSAFE_className)}\n style={UNSAFE_style}\n // Force no internal selection - we handle selection manually\n selectedKey={null}\n inputValue={inputValue}\n onInputChange={setInputValue}\n menuTrigger=\"focus\"\n isReadOnly={isReadOnly}\n data-readonly={isReadOnly ? true : undefined}\n onSelectionChange={(key) => {\n if (key) {\n onItemSelectionChange(key);\n }\n }}\n >\n <RACProvider\n values={[\n [RACTextContext, { slots: { description: { id: descriptionId }, errorMessage: { id: errorMessageId } } }],\n [RACGroupContext, { isInvalid: validationState.displayValidation.isInvalid, isDisabled }],\n [RACFieldErrorContext, validationState.displayValidation],\n ]}\n >\n <FormFieldLabel isRequired={isRequired} isDisabled={isDisabled}>\n {label}\n </FormFieldLabel>\n\n <RACGroup className=\"cim-combo-box-input-group\">\n <TagFieldInput\n aria-describedby={props['aria-describedby']}\n isReadOnly={isReadOnly}\n isRequired={isRequired}\n isInvalid={validationState.displayValidation.isInvalid}\n placeholder={\n selectedSet.size === 0 && placeholder\n ? placeholder\n : messages.format('itemsSelected', { selectedItemCount: selectedSet.size })\n }\n onFocusChange={onFocusChange}\n />\n <RACButton className=\"cim-combo-box-button\">\n <IconChevronDown />\n </RACButton>\n </RACGroup>\n\n <FormFieldError>{error}</FormFieldError>\n <FormFieldDescription>{description}</FormFieldDescription>\n\n <TagFieldTags<T>\n inputId={inputId}\n selectedKeys={selectedSet}\n isDisabled={isDisabled}\n isReadOnly={isReadOnly}\n renderEmptyState={renderEmptyState}\n onRemove={onItemSelectionChange}\n />\n\n <CollapsibleList\n offset={5} // 1px border + 4px actual offset\n maxHeight={315}\n >\n <TagFieldListBox<T>\n inputId={inputId}\n items={items}\n selectedKeys={selectedSet}\n setSelectedKeys={setSelectedKeys}\n onScroll={onScroll}\n isVirtualized={isVirtualized}\n >\n {children}\n </TagFieldListBox>\n </CollapsibleList>\n </RACProvider>\n </RACComboBox>\n\n {/* This input is used for native form validation. We can't use the combo box input because its value has no relation to the selected values. */}\n <RACInput\n ref={formInputRef}\n style={{ display: 'none' }}\n value={selectedSet.size || ''}\n required={isRequired}\n aria-invalid={validationState.displayValidation.isInvalid || undefined}\n onChange={() => {}}\n />\n\n {/* These hidden inputs provide values when a form is submitted. */}\n {name &&\n [...selectedSet].map((value) => <input type=\"hidden\" key={value} form={form} name={name} value={value} />)}\n </>\n );\n}\n\n/**\n * Allows users to filter a collapsible list and select multiple items from it.\n *\n * See [tag field usage guidelines](https://ui.cimpress.com/components/tag-field).\n */\nconst _TagField = withStyleProps(forwardRef(TagField), 'TagField');\n\nexport { _TagField as TagField };\n\nexport interface TagFieldItemProps<T extends CollectionItem>\n extends Pick<RACListBoxItemProps<T>, 'id' | 'isDisabled' | 'onHoverStart' | 'onHoverEnd'> {\n /** The content to display as the label. */\n children: StringLikeChildren;\n}\n\n/** Renders a single list item within `TagField`. */\nexport function TagFieldItem<T extends CollectionItem>({ children, ...props }: TagFieldItemProps<T>) {\n const textValue =\n typeof children === 'string' ? children : typeof children === 'number' ? String(children) : children.join('');\n\n return (\n <RACListBoxItem {...props} className=\"cim-tag-field-item cim-checkbox\" textValue={textValue}>\n {({ isDisabled }) => (\n <>\n <div className=\"cim-checkbox-toggle-wrapper\" aria-hidden>\n <div className=\"cim-checkbox-toggle\">\n <IconCheckBold />\n </div>\n </div>\n\n <RACText slot=\"label\" className={textStyle({ variant: 'medium', tone: isDisabled ? 'muted' : 'base' })}>\n {children}\n </RACText>\n </>\n )}\n </RACListBoxItem>\n );\n}\n\nTagFieldItem.displayName = 'TagFieldItem';\n\nexport interface TagFieldSectionProps<T extends CollectionItem> extends CollectionProps<T> {\n /** The ID of the section. Has to be unique across all sections and items. */\n id?: Key;\n /** The content to display as the section title. */\n title: string;\n}\n\n/** Groups list items within `TagField` into a section. */\nexport function TagFieldSection<T extends CollectionItem>({\n title,\n children,\n items,\n ...props\n}: TagFieldSectionProps<T>) {\n if (!isProduction() && items != null && typeof children !== 'function') {\n console.warn('`TagFieldSection` requires `children` to be a function when using `items` prop');\n }\n\n return (\n <RACListBoxSection {...props} className=\"cim-combo-box-section\">\n <RACHeader\n className={clsx('cim-combo-box-section-header', textStyle({ variant: 'small-semibold', tone: 'subtle' }))}\n >\n {title}\n </RACHeader>\n <RACCollection items={items}>{children}</RACCollection>\n </RACListBoxSection>\n );\n}\n\nTagFieldSection.displayName = 'TagFieldSection';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text-field.d.ts","sourceRoot":"","sources":["../../../../src/components/text-inputs/text-field.tsx"],"names":[],"mappings":"AAIA,OAAO,EAGL,KAAK,cAAc,IAAI,iBAAiB,EAEzC,MAAM,uBAAuB,CAAC;AAK/B,OAAO,KAAK,EAAE,WAAW,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAG1E,MAAM,WAAW,cACf,SAAQ,WAAW,EACjB,yBAAyB,CAAC,MAAM,CAAC,EACjC,IAAI,CACF,iBAAiB,EACf,OAAO,GACP,cAAc,GACd,UAAU,GACV,YAAY,GACZ,YAAY,GACZ,WAAW,GACX,YAAY,GACZ,MAAM,GACN,WAAW,GACX,cAAc,GACd,WAAW,GACX,WAAW,GACX,WAAW,GACX,SAAS,GACT,SAAS,GACT,QAAQ,CACX;CAAG;
|
|
1
|
+
{"version":3,"file":"text-field.d.ts","sourceRoot":"","sources":["../../../../src/components/text-inputs/text-field.tsx"],"names":[],"mappings":"AAIA,OAAO,EAGL,KAAK,cAAc,IAAI,iBAAiB,EAEzC,MAAM,uBAAuB,CAAC;AAK/B,OAAO,KAAK,EAAE,WAAW,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAG1E,MAAM,WAAW,cACf,SAAQ,WAAW,EACjB,yBAAyB,CAAC,MAAM,CAAC,EACjC,IAAI,CACF,iBAAiB,EACf,OAAO,GACP,cAAc,GACd,UAAU,GACV,YAAY,GACZ,YAAY,GACZ,WAAW,GACX,YAAY,GACZ,MAAM,GACN,WAAW,GACX,cAAc,GACd,WAAW,GACX,WAAW,GACX,WAAW,GACX,SAAS,GACT,SAAS,GACT,QAAQ,CACX;CAAG;AAmCR;;;;GAIG;AACH,QAAA,MAAM,UAAU,gKAAqD,CAAC;AAEtE,OAAO,EAAE,UAAU,IAAI,SAAS,EAAE,CAAC"}
|
|
@@ -20,7 +20,7 @@ function TextField({ label, description, error: errorMessage, placeholder, UNSAF
|
|
|
20
20
|
console.warn('TextField requires one of label / aria-label / aria-labelledby for accessibility');
|
|
21
21
|
}
|
|
22
22
|
}, [label, ariaLabel, ariaLabelledBy]);
|
|
23
|
-
return ((0, jsx_runtime_1.jsx)(react_aria_components_1.TextField, { ...props, ref: ref, className: (0, clsx_1.default)('cim-text-field', UNSAFE_className), style: UNSAFE_style, children: ({ isDisabled,
|
|
23
|
+
return ((0, jsx_runtime_1.jsx)(react_aria_components_1.TextField, { ...props, ref: ref, className: (0, clsx_1.default)('cim-text-field', UNSAFE_className), style: UNSAFE_style, children: ({ isDisabled, isRequired }) => ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(form_field_js_1.FormFieldLabel, { isRequired: isRequired, isDisabled: isDisabled, children: label }), (0, jsx_runtime_1.jsx)(react_aria_components_1.Group, { className: "cim-text-field-input-group", children: (0, jsx_runtime_1.jsx)(react_aria_components_1.Input, { className: (0, clsx_1.default)('cim-text-field-input', (0, utils_js_1.textStyle)({ variant: 'body' })), placeholder: placeholder }) }), (0, jsx_runtime_1.jsx)(form_field_js_1.FormFieldError, { children: errorMessage }), (0, jsx_runtime_1.jsx)(form_field_js_1.FormFieldDescription, { children: description })] })) }));
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* Allows users to enter a single line of text with a keyboard.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text-field.js","sourceRoot":"","sources":["../../../../src/components/text-inputs/text-field.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;AAEb,gDAAwB;AAExB,iEAK+B;AAC/B,yDAAkD;AAClD,qFAA6E;AAC7E,mEAA2D;AAC3D,wEAA4G;AAE5G,qDAAmD;AAyBnD,SAAS,SAAS,CAChB,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,gBAAgB,EAAE,YAAY,EAAE,GAAG,KAAK,EAAkB,EAClH,GAAiC;IAEjC,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,iBAAiB,EAAE,cAAc,EAAE,GAAG,KAAK,CAAC;IAE7E,IAAA,gDAAoB,EAAC,GAAG,EAAE;QACxB,IAAI,CAAC,KAAK,IAAI,CAAC,SAAS,IAAI,CAAC,cAAc,EAAE,CAAC;YAC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C,8BAAc,IAAC,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,YAC3D,KAAK,GACS,EACjB,uBAAC,6BAAQ,IAAC,SAAS,EAAC,4BAA4B,YAC9C,uBAAC,6BAAQ,IACP,SAAS,EAAE,IAAA,cAAI,EAAC,sBAAsB,EAAE,IAAA,oBAAS,EAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,EACvE,WAAW,EAAE,WAAW,GACxB,GACO,EACX,uBAAC,8BAAc,cAAE,YAAY,GAAkB,EAC/C,uBAAC,oCAAoB,cAAE,WAAW,GAAwB,IACzD,CACJ,GACY,CAChB,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,GAAG,IAAA,oCAAc,EAAC,IAAA,2BAAU,EAAC,SAAS,CAAC,EAAE,WAAW,CAAC,CAAC;AAE/C,+BAAS","sourcesContent":["'use client';\n\nimport clsx from 'clsx';\nimport type { ForwardedRef } from 'react';\nimport {\n Input as RACInput,\n TextField as RACTextField,\n type TextFieldProps as RACTextFieldProps,\n Group as RACGroup,\n} from 'react-aria-components';\nimport { forwardRef } from '../../forward-ref.js';\nimport { useProductionWarning } from '../../utils/use-production-warning.js';\nimport { withStyleProps } from '../../with-style-props.js';\nimport { FormFieldDescription, FormFieldError, FormFieldLabel } from '../internal/form-field/form-field.js';\nimport type { CommonProps, FieldWithPlaceholderProps } from '../types.js';\nimport { textStyle } from '../typography/utils.js';\n\nexport interface TextFieldProps\n extends CommonProps,\n FieldWithPlaceholderProps<string>,\n Pick<\n RACTextFieldProps,\n | 'value'\n | 'defaultValue'\n | 'onChange'\n | 'isDisabled'\n | 'isRequired'\n | 'isInvalid'\n | 'isReadOnly'\n | 'type'\n | 'autoFocus'\n | 'autoComplete'\n | 'inputMode'\n | 'minLength'\n | 'maxLength'\n | 'pattern'\n | 'onFocus'\n | 'onBlur'\n > {}\n\nfunction TextField(\n { label, description, error: errorMessage, placeholder, UNSAFE_className, UNSAFE_style, ...props }: TextFieldProps,\n ref: ForwardedRef<HTMLDivElement>,\n) {\n const { 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy } = props;\n\n useProductionWarning(() => {\n if (!label && !ariaLabel && !ariaLabelledBy) {\n console.warn('TextField requires one of label / aria-label / aria-labelledby for accessibility');\n }\n }, [label, ariaLabel, ariaLabelledBy]);\n\n return (\n <RACTextField {...props} ref={ref} className={clsx('cim-text-field', UNSAFE_className)} style={UNSAFE_style}>\n {({ isDisabled, isRequired }) => (\n <>\n <FormFieldLabel isRequired={isRequired} isDisabled={isDisabled}>\n {label}\n </FormFieldLabel>\n <RACGroup className=\"cim-text-field-input-group\">\n <RACInput\n className={clsx('cim-text-field-input', textStyle({ variant: 'body' }))}\n placeholder={placeholder}\n />\n </RACGroup>\n <FormFieldError>{errorMessage}</FormFieldError>\n <FormFieldDescription>{description}</FormFieldDescription>\n </>\n )}\n </RACTextField>\n );\n}\n\n/**\n * Allows users to enter a single line of text with a keyboard.\n *\n * See [text field usage guidelines](https://ui.cimpress.io/components/text-field/).\n */\nconst _TextField = withStyleProps(forwardRef(TextField), 'TextField');\n\nexport { _TextField as TextField };\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type SwitchProps as RACSwitchProps } from 'react-aria-components';
|
|
2
2
|
import type { AriaLabelingProps, CommonProps, StringLikeChildren } from '../types.js';
|
|
3
|
-
export interface UNSTABLE_ToggleProps extends CommonProps, AriaLabelingProps, Pick<RACSwitchProps, 'onChange' | 'isSelected' | 'isDisabled' | 'isReadOnly' | 'defaultSelected' | 'autoFocus' | 'name' | 'value'> {
|
|
3
|
+
export interface UNSTABLE_ToggleProps extends CommonProps, AriaLabelingProps, Pick<RACSwitchProps, 'onChange' | 'isSelected' | 'isDisabled' | 'isReadOnly' | 'defaultSelected' | 'autoFocus' | 'form' | 'name' | 'value'> {
|
|
4
4
|
/** The label rendered next to the toggle. */
|
|
5
5
|
children?: StringLikeChildren;
|
|
6
6
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toggle.d.ts","sourceRoot":"","sources":["../../../../src/components/toggle/toggle.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAuB,KAAK,WAAW,IAAI,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAKhG,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAGtF,MAAM,WAAW,oBACf,SAAQ,WAAW,EACjB,iBAAiB,EACjB,IAAI,CACF,cAAc,
|
|
1
|
+
{"version":3,"file":"toggle.d.ts","sourceRoot":"","sources":["../../../../src/components/toggle/toggle.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAuB,KAAK,WAAW,IAAI,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAKhG,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAGtF,MAAM,WAAW,oBACf,SAAQ,WAAW,EACjB,iBAAiB,EACjB,IAAI,CACF,cAAc,EACZ,UAAU,GACV,YAAY,GACZ,YAAY,GACZ,YAAY,GACZ,iBAAiB,GACjB,WAAW,GACX,MAAM,GACN,MAAM,GACN,OAAO,CACV;IACH,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,kBAAkB,CAAC;CAC/B;AAgCD;;;;GAIG;AACH,QAAA,MAAM,gBAAgB,wKAAwD,CAAC;AAE/E,OAAO,EAAE,gBAAgB,IAAI,eAAe,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toggle.js","sourceRoot":"","sources":["../../../../src/components/toggle/toggle.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;AAEb,gDAAwB;AAExB,iEAAgG;AAChG,yDAAkD;AAClD,mDAAoE;AACpE,qFAA6E;AAC7E,mEAA2D;AAE3D,mDAA6C;
|
|
1
|
+
{"version":3,"file":"toggle.js","sourceRoot":"","sources":["../../../../src/components/toggle/to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ForwardedRef } from 'react';\nimport { Switch as RACSwitch, type SwitchProps as RACSwitchProps } from 'react-aria-components';\nimport { forwardRef } from '../../forward-ref.js';\nimport { IconCheckBold, IconCloseBold } from '../../icons/index.js';\nimport { useProductionWarning } from '../../utils/use-production-warning.js';\nimport { withStyleProps } from '../../with-style-props.js';\nimport type { AriaLabelingProps, CommonProps, StringLikeChildren } from '../types.js';\nimport { Text } from '../typography/text.js';\n\nexport interface UNSTABLE_ToggleProps\n extends CommonProps,\n AriaLabelingProps,\n Pick<\n RACSwitchProps,\n | 'onChange'\n | 'isSelected'\n | 'isDisabled'\n | 'isReadOnly'\n | 'defaultSelected'\n | 'autoFocus'\n | 'form'\n | 'name'\n | 'value'\n > {\n /** The label rendered next to the toggle. */\n children?: StringLikeChildren;\n}\n\nfunction UNSTABLE_Toggle(\n { children, UNSAFE_className, UNSAFE_style, ...props }: UNSTABLE_ToggleProps,\n ref: ForwardedRef<HTMLLabelElement>,\n) {\n const { 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy } = props;\n\n useProductionWarning(() => {\n if (!children && !ariaLabel && !ariaLabelledBy) {\n console.warn('Toggle requires one of children / aria-label / aria-labelledby for accessibility');\n }\n }, [children, ariaLabel, ariaLabelledBy]);\n\n return (\n <RACSwitch {...props} ref={ref} className={clsx('cim-toggle', UNSAFE_className)} style={UNSAFE_style}>\n <div className=\"cim-toggle-track-wrapper\" aria-hidden>\n <div className=\"cim-toggle-track\">\n <IconCheckBold />\n <IconCloseBold />\n <div className=\"cim-toggle-track-head\" />\n </div>\n </div>\n {children && (\n <Text as=\"span\" variant=\"medium\">\n {children}\n </Text>\n )}\n </RACSwitch>\n );\n}\n\n/**\n * Allows users to turn a setting on or off.\n *\n * See [toggle usage guidelines](https://ui.cimpress.io/components/toggle/).\n */\nconst _UNSTABLE_Toggle = withStyleProps(forwardRef(UNSTABLE_Toggle), 'Toggle');\n\nexport { _UNSTABLE_Toggle as UNSTABLE_Toggle };\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../src/components/toggle-button/context.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ToggleButtonGroupContext = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
/** @internal */
|
|
6
|
+
exports.ToggleButtonGroupContext = (0, react_1.createContext)(null);
|
|
7
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../../../src/components/toggle-button/context.tsx"],"names":[],"mappings":";;;AACA,iCAAsC;AAWtC,gBAAgB;AACH,QAAA,wBAAwB,GAAG,IAAA,qBAAa,EAAuC,IAAI,CAAC,CAAC","sourcesContent":["import type { FormValidationState } from '@react-stately/form';\nimport { createContext } from 'react';\n\n/** @internal */\nexport interface ToggleButtonGroupContextValue {\n form?: string;\n name?: string;\n isInvalid?: boolean;\n isRequired?: boolean;\n validationState: FormValidationState;\n}\n\n/** @internal */\nexport const ToggleButtonGroupContext = createContext<ToggleButtonGroupContextValue | null>(null);\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal-toggle-button.d.ts","sourceRoot":"","sources":["../../../../src/components/toggle-button/internal-toggle-button.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.InternalToggleButton = InternalToggleButton;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const form_1 = require("@react-aria/form");
|
|
9
|
+
const utils_1 = require("@react-aria/utils");
|
|
10
|
+
const form_2 = require("@react-stately/form");
|
|
11
|
+
const utils_2 = require("@react-stately/utils");
|
|
12
|
+
const clsx_1 = __importDefault(require("clsx"));
|
|
13
|
+
const react_1 = require("react");
|
|
14
|
+
const react_aria_components_1 = require("react-aria-components");
|
|
15
|
+
const context_js_1 = require("./context.js");
|
|
16
|
+
/** @internal */
|
|
17
|
+
function InternalToggleButton({ buttonRef: ref, children, size = 'medium', isDisabled, fullWidth, UNSAFE_className, UNSAFE_style, form, name, value, isSelected: consumerIsSelected, defaultSelected: consumerDefaultSelected, onChange, ...props }) {
|
|
18
|
+
// State
|
|
19
|
+
const toggleButtonGroupContext = (0, react_1.useContext)(context_js_1.ToggleButtonGroupContext);
|
|
20
|
+
const toggleGroupState = (0, react_1.useContext)(react_aria_components_1.ToggleGroupStateContext);
|
|
21
|
+
const descriptionProps = (0, react_aria_components_1.useSlottedContext)(react_aria_components_1.TextContext, 'description');
|
|
22
|
+
const errorMessageProps = (0, react_aria_components_1.useSlottedContext)(react_aria_components_1.TextContext, 'errorMessage');
|
|
23
|
+
const [isSelected, setIsSelected] = (0, utils_2.useControlledState)(toggleGroupState && value ? toggleGroupState.selectedKeys.has(value) : consumerIsSelected, consumerDefaultSelected ?? false, (newIsSelected) => {
|
|
24
|
+
onChange?.(newIsSelected);
|
|
25
|
+
if (toggleGroupState && value) {
|
|
26
|
+
toggleGroupState.setSelected(value, newIsSelected);
|
|
27
|
+
}
|
|
28
|
+
validationState.commitValidation();
|
|
29
|
+
});
|
|
30
|
+
// Validation
|
|
31
|
+
const buttonRef = (0, utils_1.useObjectRef)(ref);
|
|
32
|
+
const formInputRef = (0, react_1.useRef)(null);
|
|
33
|
+
const formInputName = toggleButtonGroupContext?.name ?? name;
|
|
34
|
+
const validationState = (0, form_2.useFormValidationState)({
|
|
35
|
+
// If part of a group, validation is handled at group level
|
|
36
|
+
name: toggleButtonGroupContext ? undefined : name,
|
|
37
|
+
value,
|
|
38
|
+
validationBehavior: 'native',
|
|
39
|
+
[form_2.privateValidationStateProp]: toggleButtonGroupContext?.validationState ?? undefined,
|
|
40
|
+
});
|
|
41
|
+
const [initialSelected] = (0, react_1.useState)(isSelected);
|
|
42
|
+
(0, utils_1.useFormReset)(formInputRef, consumerDefaultSelected ?? initialSelected, setIsSelected);
|
|
43
|
+
(0, form_1.useFormValidation)({
|
|
44
|
+
focus: () => buttonRef.current?.focus(),
|
|
45
|
+
validationBehavior: 'native',
|
|
46
|
+
}, validationState, formInputRef);
|
|
47
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_aria_components_1.ToggleButton, { ...props, ref: buttonRef, className: (0, clsx_1.default)('cim-toggle-button', UNSAFE_className), style: UNSAFE_style, id: toggleButtonGroupContext ? value : undefined, isDisabled: isDisabled, isSelected: isSelected, onChange: setIsSelected, "aria-describedby": [
|
|
48
|
+
props['aria-describedby'],
|
|
49
|
+
toggleButtonGroupContext?.isInvalid ? errorMessageProps?.id : null,
|
|
50
|
+
descriptionProps?.id,
|
|
51
|
+
]
|
|
52
|
+
.filter(Boolean)
|
|
53
|
+
.join(' ') || undefined, "data-variant": "secondary", "data-tone": "base", "data-size": size, "data-full-width": fullWidth || undefined, children: children }), formInputName && ((0, jsx_runtime_1.jsx)("input", { ref: formInputRef, style: { display: 'none' }, type: "checkbox", form: toggleButtonGroupContext?.form ?? form, name: formInputName, checked: isSelected, value: value, required: toggleButtonGroupContext?.isRequired, "aria-invalid": toggleButtonGroupContext?.validationState.displayValidation.isInvalid ??
|
|
54
|
+
validationState.displayValidation.isInvalid ??
|
|
55
|
+
undefined, onChange: () => { } }))] }));
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=internal-toggle-button.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal-toggle-button.js","sourceRoot":"","sources":["../../../../src/components/toggle-button/internal-toggle-button.tsx"],"names":[],"mappings":";;;;;AA2DA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f,IAAI,CAAC,GAAG,CAAC,IAAI,SAAS,kBAEd,WAAW,eACd,MAAM,eACL,IAAI,qBACE,SAAS,IAAI,SAAS,YAEtC,QAAQ,GACO,EAEjB,aAAa,IAAI,CAChB,kCACE,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,EAC1B,IAAI,EAAC,UAAU,EACf,IAAI,EAAE,wBAAwB,EAAE,IAAI,IAAI,IAAI,EAC5C,IAAI,EAAE,aAAa,EACnB,OAAO,EAAE,UAAU,EACnB,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,wBAAwB,EAAE,UAAU,kBAE5C,wBAAwB,EAAE,eAAe,CAAC,iBAAiB,CAAC,SAAS;oBACrE,eAAe,CAAC,iBAAiB,CAAC,SAAS;oBAC3C,SAAS,EAEX,QAAQ,EAAE,GAAG,EAAE,GAAE,CAAC,GAClB,CACH,IACA,CACJ,CAAC;AACJ,CAAC","sourcesContent":["import { useFormValidation } from '@react-aria/form';\nimport { useFormReset, useObjectRef } from '@react-aria/utils';\nimport { privateValidationStateProp, useFormValidationState } from '@react-stately/form';\nimport { useControlledState } from '@react-stately/utils';\nimport clsx from 'clsx';\nimport { type ReactNode, useContext, useRef, useState, type Ref } from 'react';\nimport {\n TextContext as RACTextContext,\n ToggleButton as RACToggleButton,\n type ToggleButtonProps as RACToggleButtonProps,\n ToggleGroupStateContext as RACToggleGroupStateContext,\n useSlottedContext,\n} from 'react-aria-components';\nimport type { BaseButtonProps } from '../button/types.js';\nimport type { AriaLabelingProps, CommonProps } from '../types.js';\nimport { ToggleButtonGroupContext } from './context.js';\n\n/** @internal */\nexport interface BaseToggleButtonProps\n extends Omit<CommonProps, 'id'>,\n AriaLabelingProps,\n Pick<BaseButtonProps, 'size' | 'fullWidth'>,\n Pick<\n RACToggleButtonProps,\n | 'defaultSelected'\n | 'isSelected'\n | 'onPress'\n | 'onHoverStart'\n | 'onHoverEnd'\n | 'onChange'\n | 'isDisabled'\n | 'autoFocus'\n > {\n /**\n * The `<form>` element to associate the input with.\n * The value of this attribute must be the id of a `<form>` in the same document.\n * See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input#form).\n */\n form?: string;\n /**\n * The name of the input element, used when submitting an HTML form.\n * See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input#name).\n */\n name?: string;\n /**\n * The value of the input element, used when submitting an HTML form.\n * See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input#value).\n *\n * When used in a `ToggleButtonGroup`, `value` serves as an identifier for this button, and has to be unique across all buttons in the group.\n */\n value?: string;\n}\n\ninterface InternalToggleButtonProps extends BaseToggleButtonProps {\n children?: ReactNode;\n buttonRef?: Ref<HTMLButtonElement>;\n}\n\n/** @internal */\nexport function InternalToggleButton({\n buttonRef: ref,\n children,\n size = 'medium',\n isDisabled,\n fullWidth,\n UNSAFE_className,\n UNSAFE_style,\n form,\n name,\n value,\n isSelected: consumerIsSelected,\n defaultSelected: consumerDefaultSelected,\n onChange,\n ...props\n}: InternalToggleButtonProps) {\n // State\n\n const toggleButtonGroupContext = useContext(ToggleButtonGroupContext);\n const toggleGroupState = useContext(RACToggleGroupStateContext);\n const descriptionProps = useSlottedContext(RACTextContext, 'description');\n const errorMessageProps = useSlottedContext(RACTextContext, 'errorMessage');\n\n const [isSelected, setIsSelected] = useControlledState(\n toggleGroupState && value ? toggleGroupState.selectedKeys.has(value) : consumerIsSelected,\n consumerDefaultSelected ?? false,\n (newIsSelected) => {\n onChange?.(newIsSelected);\n\n if (toggleGroupState && value) {\n toggleGroupState.setSelected(value, newIsSelected);\n }\n\n validationState.commitValidation();\n },\n );\n\n // Validation\n\n const buttonRef = useObjectRef(ref);\n const formInputRef = useRef<HTMLInputElement>(null);\n const formInputName = toggleButtonGroupContext?.name ?? name;\n\n const validationState = useFormValidationState({\n // If part of a group, validation is handled at group level\n name: toggleButtonGroupContext ? undefined : name,\n value,\n validationBehavior: 'native',\n [privateValidationStateProp]: toggleButtonGroupContext?.validationState ?? undefined,\n });\n\n const [initialSelected] = useState(isSelected);\n useFormReset(formInputRef, consumerDefaultSelected ?? initialSelected, setIsSelected);\n\n useFormValidation(\n {\n focus: () => buttonRef.current?.focus(),\n validationBehavior: 'native',\n },\n validationState,\n formInputRef,\n );\n\n return (\n <>\n <RACToggleButton\n {...props}\n ref={buttonRef}\n className={clsx('cim-toggle-button', UNSAFE_className)}\n style={UNSAFE_style}\n id={toggleButtonGroupContext ? value : undefined}\n isDisabled={isDisabled}\n isSelected={isSelected}\n onChange={setIsSelected}\n aria-describedby={\n [\n props['aria-describedby'],\n toggleButtonGroupContext?.isInvalid ? errorMessageProps?.id : null,\n descriptionProps?.id,\n ]\n .filter(Boolean)\n .join(' ') || undefined\n }\n data-variant=\"secondary\"\n data-tone=\"base\"\n data-size={size}\n data-full-width={fullWidth || undefined}\n >\n {children}\n </RACToggleButton>\n\n {formInputName && (\n <input\n ref={formInputRef}\n style={{ display: 'none' }}\n type=\"checkbox\"\n form={toggleButtonGroupContext?.form ?? form}\n name={formInputName}\n checked={isSelected}\n value={value}\n required={toggleButtonGroupContext?.isRequired}\n aria-invalid={\n toggleButtonGroupContext?.validationState.displayValidation.isInvalid ??\n validationState.displayValidation.isInvalid ??\n undefined\n }\n onChange={() => {}}\n />\n )}\n </>\n );\n}\n"]}
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
2
|
import { type ToggleButtonGroupProps as RACToggleButtonGroupProps } from 'react-aria-components';
|
|
3
|
-
import type { CommonProps,
|
|
4
|
-
export interface
|
|
5
|
-
/** Toggle buttons belonging to the group. Each button must have
|
|
3
|
+
import type { CommonProps, FieldProps, Key, WithRequired } from '../types.js';
|
|
4
|
+
export interface ToggleButtonGroupProps extends Omit<CommonProps, 'id'>, WithRequired<FieldProps<Set<Key>>, 'label'>, Pick<RACToggleButtonGroupProps, 'selectedKeys' | 'defaultSelectedKeys' | 'onSelectionChange' | 'selectionMode' | 'isDisabled'> {
|
|
5
|
+
/** Toggle buttons belonging to the group. Each button must have a `value` prop defined. */
|
|
6
6
|
children: ReactNode;
|
|
7
|
+
/** Whether the current selection is invalid. */
|
|
8
|
+
isInvalid?: boolean;
|
|
9
|
+
/** Whether a selection is required before form submission. */
|
|
10
|
+
isRequired?: boolean;
|
|
7
11
|
}
|
|
8
12
|
/**
|
|
9
13
|
* Allows users to toggle multiple options, with single or multiple selection.
|
|
10
14
|
*
|
|
11
15
|
* See [toggle button usage guidelines](https://ui.cimpress.io/components/toggle-button/).
|
|
12
16
|
*/
|
|
13
|
-
declare const
|
|
14
|
-
export {
|
|
17
|
+
declare const _ToggleButtonGroup: (props: ToggleButtonGroupProps & import("react").RefAttributes<HTMLDivElement> & import("../../with-style-props.js").StyleProps) => import("react").JSX.Element | null;
|
|
18
|
+
export { _ToggleButtonGroup as ToggleButtonGroup };
|
|
15
19
|
//# sourceMappingURL=toggle-button-group.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toggle-button-group.d.ts","sourceRoot":"","sources":["../../../../src/components/toggle-button/toggle-button-group.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"toggle-button-group.d.ts","sourceRoot":"","sources":["../../../../src/components/toggle-button/toggle-button-group.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAW,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAGhD,OAAO,EAML,KAAK,sBAAsB,IAAI,yBAAyB,EACzD,MAAM,uBAAuB,CAAC;AAO/B,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAI9E,MAAM,WAAW,sBACf,SAAQ,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,EAC7B,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,EAC3C,IAAI,CACF,yBAAyB,EACzB,cAAc,GAAG,qBAAqB,GAAG,mBAAmB,GAAG,eAAe,GAAG,YAAY,CAC9F;IACH,2FAA2F;IAC3F,QAAQ,EAAE,SAAS,CAAC;IACpB,gDAAgD;IAChD,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,8DAA8D;IAC9D,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAuHD;;;;GAIG;AACH,QAAA,MAAM,kBAAkB,wKAAqE,CAAC;AAE9F,OAAO,EAAE,kBAAkB,IAAI,iBAAiB,EAAE,CAAC"}
|
|
@@ -4,27 +4,79 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.
|
|
7
|
+
exports.ToggleButtonGroup = void 0;
|
|
8
8
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
9
|
+
const form_1 = require("@react-stately/form");
|
|
10
|
+
const utils_1 = require("@react-stately/utils");
|
|
9
11
|
const clsx_1 = __importDefault(require("clsx"));
|
|
12
|
+
const react_1 = require("react");
|
|
13
|
+
const react_aria_1 = require("react-aria");
|
|
10
14
|
const react_aria_components_1 = require("react-aria-components");
|
|
11
15
|
const forward_ref_js_1 = require("../../forward-ref.js");
|
|
16
|
+
const index_js_1 = require("../../i18n/index.js");
|
|
12
17
|
const use_production_warning_js_1 = require("../../utils/use-production-warning.js");
|
|
13
18
|
const with_style_props_js_1 = require("../../with-style-props.js");
|
|
14
|
-
|
|
15
|
-
|
|
19
|
+
const form_field_js_1 = require("../internal/form-field/form-field.js");
|
|
20
|
+
const stack_js_1 = require("../spacing/stack/stack.js");
|
|
21
|
+
const visually_hidden_js_1 = require("../visually-hidden/visually-hidden.js");
|
|
22
|
+
const context_js_1 = require("./context.js");
|
|
23
|
+
function ToggleButtonGroup({ children, label, description, error: errorMessage, validate, form, name, isInvalid, isRequired, selectedKeys: consumerSelectedKeys, defaultSelectedKeys: consumerDefaultSelectedKeys, onSelectionChange, UNSAFE_className, UNSAFE_style, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, 'aria-details': ariaDetails, ...props }, ref) {
|
|
16
24
|
(0, use_production_warning_js_1.useProductionWarning)(() => {
|
|
17
|
-
if (!ariaLabel && !ariaLabelledBy) {
|
|
18
|
-
console.warn('ToggleButtonGroup requires one of aria-label / aria-labelledby for accessibility');
|
|
25
|
+
if (!label && !ariaLabel && !ariaLabelledBy) {
|
|
26
|
+
console.warn('ToggleButtonGroup requires one of label / aria-label / aria-labelledby for accessibility');
|
|
19
27
|
}
|
|
20
|
-
}, [ariaLabel, ariaLabelledBy]);
|
|
21
|
-
|
|
28
|
+
}, [label, ariaLabel, ariaLabelledBy]);
|
|
29
|
+
const labelMessages = (0, index_js_1.useLocalizedMessages)('label');
|
|
30
|
+
// State
|
|
31
|
+
const [selectedKeys, setSelectedKeys] = (0, utils_1.useControlledState)(consumerSelectedKeys, consumerDefaultSelectedKeys ?? [], (newSelectedKeys) => {
|
|
32
|
+
onSelectionChange?.(new Set(newSelectedKeys));
|
|
33
|
+
validationState.commitValidation();
|
|
34
|
+
});
|
|
35
|
+
const selectedSet = (0, react_1.useMemo)(() => new Set(selectedKeys), [selectedKeys]);
|
|
36
|
+
// Validation
|
|
37
|
+
const validationState = (0, form_1.useFormValidationState)({
|
|
38
|
+
value: selectedSet,
|
|
39
|
+
isInvalid,
|
|
40
|
+
isRequired,
|
|
41
|
+
name,
|
|
42
|
+
validate,
|
|
43
|
+
validationBehavior: 'native',
|
|
44
|
+
});
|
|
45
|
+
const { labelProps, fieldProps, descriptionProps, errorMessageProps } = (0, react_aria_1.useField)({
|
|
46
|
+
'aria-label': ariaLabel,
|
|
47
|
+
'aria-labelledby': ariaLabelledBy,
|
|
48
|
+
'aria-describedby': ariaDescribedBy,
|
|
49
|
+
'aria-details': ariaDetails,
|
|
50
|
+
description,
|
|
51
|
+
errorMessage: errorMessage || validationState.displayValidation.validationErrors,
|
|
52
|
+
isInvalid: isInvalid || validationState.displayValidation.isInvalid,
|
|
53
|
+
label,
|
|
54
|
+
labelElementType: 'span',
|
|
55
|
+
validate,
|
|
56
|
+
validationBehavior: 'native',
|
|
57
|
+
});
|
|
58
|
+
// Remove props that we don't want from fieldProps
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
60
|
+
const { id, ...filteredFieldProps } = fieldProps;
|
|
61
|
+
const toggleButtonGroupContext = {
|
|
62
|
+
form,
|
|
63
|
+
name,
|
|
64
|
+
isInvalid: isInvalid || validationState.displayValidation.isInvalid,
|
|
65
|
+
isRequired: isRequired && selectedSet.size === 0,
|
|
66
|
+
validationState,
|
|
67
|
+
};
|
|
68
|
+
return ((0, jsx_runtime_1.jsx)(react_aria_components_1.ToggleButtonGroup, { ...(0, react_aria_1.mergeProps)(props, filteredFieldProps), ref: ref, className: (0, clsx_1.default)('cim-toggle-button-group', UNSAFE_className), style: UNSAFE_style, selectedKeys: selectedKeys, onSelectionChange: setSelectedKeys, children: (0, jsx_runtime_1.jsxs)(react_aria_components_1.Provider, { values: [
|
|
69
|
+
[react_aria_components_1.LabelContext, { ...labelProps, elementType: 'span' }],
|
|
70
|
+
[react_aria_components_1.TextContext, { slots: { description: descriptionProps, errorMessage: errorMessageProps } }],
|
|
71
|
+
[react_aria_components_1.FieldErrorContext, validationState.displayValidation],
|
|
72
|
+
[context_js_1.ToggleButtonGroupContext, toggleButtonGroupContext],
|
|
73
|
+
], children: [(0, jsx_runtime_1.jsxs)(form_field_js_1.FormFieldLabel, { isRequired: isRequired, children: [label, isRequired && (0, jsx_runtime_1.jsx)(visually_hidden_js_1.UNSTABLE_VisuallyHidden, { children: labelMessages.format('required') })] }), (0, jsx_runtime_1.jsx)(stack_js_1.Stack, { gap: 8, direction: "horizontal", wrap: true, children: children }), (0, jsx_runtime_1.jsx)(form_field_js_1.FormFieldError, { children: errorMessage }), (0, jsx_runtime_1.jsx)(form_field_js_1.FormFieldDescription, { children: description })] }) }));
|
|
22
74
|
}
|
|
23
75
|
/**
|
|
24
76
|
* Allows users to toggle multiple options, with single or multiple selection.
|
|
25
77
|
*
|
|
26
78
|
* See [toggle button usage guidelines](https://ui.cimpress.io/components/toggle-button/).
|
|
27
79
|
*/
|
|
28
|
-
const
|
|
29
|
-
exports.
|
|
80
|
+
const _ToggleButtonGroup = (0, with_style_props_js_1.withStyleProps)((0, forward_ref_js_1.forwardRef)(ToggleButtonGroup), 'ToggleButtonGroup');
|
|
81
|
+
exports.ToggleButtonGroup = _ToggleButtonGroup;
|
|
30
82
|
//# sourceMappingURL=toggle-button-group.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toggle-button-group.js","sourceRoot":"","sources":["../../../../src/components/toggle-button/toggle-button-group.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;AAEb,gDAAwB;
|
|
1
|
+
{"version":3,"file":"toggle-button-group.js","sourceRoot":"","sources":["../../../../src/components/toggle-button/toggle-button-group.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;AAEb,8CAA6D;AAC7D,gDAA0D;AAC1D,gDAAwB;AACxB,iCAAgD;AAEhD,2CAAkD;AAClD,iEAO+B;AAC/B,yDAAkD;AAClD,kDAA2D;AAC3D,qFAA6E;AAC7E,mEAA2D;AAC3D,wEAA4G;AAC5G,wDAAkD;AAElD,8EAAkG;AAClG,6CAA4F;AAiB5F,SAAS,iBAAiB,CACxB,EACE,QAAQ,EACR,KAAK,EACL,WAAW,EACX,KAAK,EAAE,YAAY,EACnB,QAAQ,EACR,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,UAAU,EACV,YAAY,EAAE,oBAAoB,EAClC,mBAAmB,EAAE,2BAA2B,EAChD,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,YAAY,EAAE,SAAS,EACvB,iBAAiB,EAAE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AAK,IAAC,GAAG,EAAE,CAAC,EAAE,SAAS,EAAC,YAAY,EAAC,IAAI,kBACvC,QAAQ,GACH,EACR,uBAAC,8BAAc,cAAE,YAAY,GAAkB,EAC/C,uBAAC,oCAAoB,cAAE,WAAW,GAAwB,IAC9C,GACO,CACxB,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,kBAAkB,GAAG,IAAA,oCAAc,EAAC,IAAA,2BAAU,EAAC,iBAAiB,CAAC,EAAE,mBAAmB,CAAC,CAAC;AAE/D,+CAAiB","sourcesContent":["'use client';\n\nimport { useFormValidationState } from '@react-stately/form';\nimport { useControlledState } from '@react-stately/utils';\nimport clsx from 'clsx';\nimport { useMemo, type ReactNode } from 'react';\nimport type { ForwardedRef } from 'react';\nimport { mergeProps, useField } from 'react-aria';\nimport {\n LabelContext as RACLabelContext,\n FieldErrorContext as RACFieldErrorContext,\n Provider as RACProvider,\n TextContext as RACTextContext,\n ToggleButtonGroup as RACToggleButtonGroup,\n type ToggleButtonGroupProps as RACToggleButtonGroupProps,\n} from 'react-aria-components';\nimport { forwardRef } from '../../forward-ref.js';\nimport { useLocalizedMessages } from '../../i18n/index.js';\nimport { useProductionWarning } from '../../utils/use-production-warning.js';\nimport { withStyleProps } from '../../with-style-props.js';\nimport { FormFieldDescription, FormFieldError, FormFieldLabel } from '../internal/form-field/form-field.js';\nimport { Stack } from '../spacing/stack/stack.js';\nimport type { CommonProps, FieldProps, Key, WithRequired } from '../types.js';\nimport { UNSTABLE_VisuallyHidden as VisuallyHidden } from '../visually-hidden/visually-hidden.js';\nimport { ToggleButtonGroupContext, type ToggleButtonGroupContextValue } from './context.js';\n\nexport interface ToggleButtonGroupProps\n extends Omit<CommonProps, 'id'>,\n WithRequired<FieldProps<Set<Key>>, 'label'>,\n Pick<\n RACToggleButtonGroupProps,\n 'selectedKeys' | 'defaultSelectedKeys' | 'onSelectionChange' | 'selectionMode' | 'isDisabled'\n > {\n /** Toggle buttons belonging to the group. Each button must have a `value` prop defined. */\n children: ReactNode;\n /** Whether the current selection is invalid. */\n isInvalid?: boolean;\n /** Whether a selection is required before form submission. */\n isRequired?: boolean;\n}\n\nfunction ToggleButtonGroup(\n {\n children,\n label,\n description,\n error: errorMessage,\n validate,\n form,\n name,\n isInvalid,\n isRequired,\n selectedKeys: consumerSelectedKeys,\n defaultSelectedKeys: consumerDefaultSelectedKeys,\n onSelectionChange,\n UNSAFE_className,\n UNSAFE_style,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n 'aria-describedby': ariaDescribedBy,\n 'aria-details': ariaDetails,\n ...props\n }: ToggleButtonGroupProps,\n ref: ForwardedRef<HTMLDivElement>,\n) {\n useProductionWarning(() => {\n if (!label && !ariaLabel && !ariaLabelledBy) {\n console.warn('ToggleButtonGroup requires one of label / aria-label / aria-labelledby for accessibility');\n }\n }, [label, ariaLabel, ariaLabelledBy]);\n\n const labelMessages = useLocalizedMessages('label');\n\n // State\n\n const [selectedKeys, setSelectedKeys] = useControlledState(\n consumerSelectedKeys,\n consumerDefaultSelectedKeys ?? [],\n (newSelectedKeys) => {\n onSelectionChange?.(new Set(newSelectedKeys));\n validationState.commitValidation();\n },\n );\n\n const selectedSet = useMemo(() => new Set<Key>(selectedKeys), [selectedKeys]);\n\n // Validation\n\n const validationState = useFormValidationState({\n value: selectedSet,\n isInvalid,\n isRequired,\n name,\n validate,\n validationBehavior: 'native',\n });\n\n const { labelProps, fieldProps, descriptionProps, errorMessageProps } = useField({\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n 'aria-describedby': ariaDescribedBy,\n 'aria-details': ariaDetails,\n description,\n errorMessage: errorMessage || validationState.displayValidation.validationErrors,\n isInvalid: isInvalid || validationState.displayValidation.isInvalid,\n label,\n labelElementType: 'span',\n validate,\n validationBehavior: 'native',\n });\n\n // Remove props that we don't want from fieldProps\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { id, ...filteredFieldProps } = fieldProps;\n\n const toggleButtonGroupContext: ToggleButtonGroupContextValue = {\n form,\n name,\n isInvalid: isInvalid || validationState.displayValidation.isInvalid,\n isRequired: isRequired && selectedSet.size === 0,\n validationState,\n };\n\n return (\n <RACToggleButtonGroup\n {...mergeProps(props, filteredFieldProps)}\n ref={ref}\n className={clsx('cim-toggle-button-group', UNSAFE_className)}\n style={UNSAFE_style}\n selectedKeys={selectedKeys}\n onSelectionChange={setSelectedKeys}\n >\n <RACProvider\n values={[\n [RACLabelContext, { ...labelProps, elementType: 'span' }],\n [RACTextContext, { slots: { description: descriptionProps, errorMessage: errorMessageProps } }],\n [RACFieldErrorContext, validationState.displayValidation],\n [ToggleButtonGroupContext, toggleButtonGroupContext],\n ]}\n >\n <FormFieldLabel isRequired={isRequired}>\n {label}\n {/*\n * Button elements don't support `aria-required`, so we need to add visually hidden text to indicate that the field is required.\n * See: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-required#examples:~:text=Note%3A%20If%20the%20field%27s%20label%20already%20contains%20the%20word%20%22required%22%2C%20it%20is%20recommended%20to%20leave%20out%20the%20aria%2Drequired%20attribute.%20This%20avoids%20that%20screen%20readers%20read%20out%20the%20term%20%22required%22%20twice.\n */}\n {isRequired && <VisuallyHidden>{labelMessages.format('required')}</VisuallyHidden>}\n </FormFieldLabel>\n <Stack gap={8} direction=\"horizontal\" wrap>\n {children}\n </Stack>\n <FormFieldError>{errorMessage}</FormFieldError>\n <FormFieldDescription>{description}</FormFieldDescription>\n </RACProvider>\n </RACToggleButtonGroup>\n );\n}\n\n/**\n * Allows users to toggle multiple options, with single or multiple selection.\n *\n * See [toggle button usage guidelines](https://ui.cimpress.io/components/toggle-button/).\n */\nconst _ToggleButtonGroup = withStyleProps(forwardRef(ToggleButtonGroup), 'ToggleButtonGroup');\n\nexport { _ToggleButtonGroup as ToggleButtonGroup };\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type {
|
|
3
|
-
import
|
|
4
|
-
export interface
|
|
5
|
-
/**
|
|
6
|
-
|
|
1
|
+
import type { TextButtonProps } from '../button/types.js';
|
|
2
|
+
import type { StringLikeChildren } from '../types.js';
|
|
3
|
+
import { type BaseToggleButtonProps } from './internal-toggle-button.js';
|
|
4
|
+
export interface ToggleButtonProps extends BaseToggleButtonProps, Omit<TextButtonProps, 'children'> {
|
|
5
|
+
/** The text displayed on the button. Must remain the same regardless of selection state. */
|
|
6
|
+
children: StringLikeChildren;
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
9
|
* Displays a labelled button that allows users to toggle between two states.
|
|
@@ -11,6 +11,6 @@ export interface UNSTABLE_ToggleButtonProps extends Omit<CommonProps, 'id'>, Tex
|
|
|
11
11
|
*
|
|
12
12
|
* See [toggle button usage guidelines](https://ui.cimpress.io/components/toggle-button/).
|
|
13
13
|
*/
|
|
14
|
-
declare const
|
|
15
|
-
export {
|
|
14
|
+
declare const _ToggleButton: (props: ToggleButtonProps & import("react").RefAttributes<HTMLButtonElement> & import("../../with-style-props.js").StyleProps) => import("react").JSX.Element | null;
|
|
15
|
+
export { _ToggleButton as ToggleButton };
|
|
16
16
|
//# sourceMappingURL=toggle-button.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toggle-button.d.ts","sourceRoot":"","sources":["../../../../src/components/toggle-button/toggle-button.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"toggle-button.d.ts","sourceRoot":"","sources":["../../../../src/components/toggle-button/toggle-button.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAwB,KAAK,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAE/F,MAAM,WAAW,iBAAkB,SAAQ,qBAAqB,EAAE,IAAI,CAAC,eAAe,EAAE,UAAU,CAAC;IACjG,4FAA4F;IAC5F,QAAQ,EAAE,kBAAkB,CAAC;CAC9B;AAeD;;;;;GAKG;AACH,QAAA,MAAM,aAAa,sKAA2D,CAAC;AAE/E,OAAO,EAAE,aAAa,IAAI,YAAY,EAAE,CAAC"}
|
|
@@ -4,14 +4,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.
|
|
7
|
+
exports.ToggleButton = void 0;
|
|
8
8
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
9
9
|
const clsx_1 = __importDefault(require("clsx"));
|
|
10
|
-
const react_aria_components_1 = require("react-aria-components");
|
|
11
10
|
const forward_ref_js_1 = require("../../forward-ref.js");
|
|
12
11
|
const with_style_props_js_1 = require("../../with-style-props.js");
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
const internal_toggle_button_js_1 = require("./internal-toggle-button.js");
|
|
13
|
+
function ToggleButton({ children, iconStart, iconEnd, UNSAFE_className, ...props }, ref) {
|
|
14
|
+
return ((0, jsx_runtime_1.jsxs)(internal_toggle_button_js_1.InternalToggleButton, { ...props, buttonRef: ref, UNSAFE_className: (0, clsx_1.default)('cim-button', UNSAFE_className), children: [iconStart, (0, jsx_runtime_1.jsx)("span", { className: "cim-button-text", children: children }), iconEnd] }));
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
17
|
* Displays a labelled button that allows users to toggle between two states.
|
|
@@ -19,6 +19,6 @@ function UNSTABLE_ToggleButton({ children, size = 'medium', iconStart, iconEnd,
|
|
|
19
19
|
*
|
|
20
20
|
* See [toggle button usage guidelines](https://ui.cimpress.io/components/toggle-button/).
|
|
21
21
|
*/
|
|
22
|
-
const
|
|
23
|
-
exports.
|
|
22
|
+
const _ToggleButton = (0, with_style_props_js_1.withStyleProps)((0, forward_ref_js_1.forwardRef)(ToggleButton), 'ToggleButton');
|
|
23
|
+
exports.ToggleButton = _ToggleButton;
|
|
24
24
|
//# sourceMappingURL=toggle-button.js.map
|