@jobber/components 4.85.4-CJS-to-ESM.1 → 4.85.4-CJS-to-ESM.2
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/AnimatedPresence-20a02aaa.js +104 -0
- package/dist/AnimatedPresence-bbccdaf7.js +98 -0
- package/dist/AnimatedPresence.cjs +12 -0
- package/dist/AnimatedPresence.js +4 -0
- package/dist/AnimatedSwitcher-3aff3d12.js +90 -0
- package/dist/AnimatedSwitcher-3d45ec5d.js +96 -0
- package/dist/AnimatedSwitcher.cjs +13 -0
- package/dist/AnimatedSwitcher.js +5 -0
- package/dist/Autocomplete-b35c7ff5.js +196 -0
- package/dist/Autocomplete-dc7a4b9e.js +188 -0
- package/dist/Autocomplete.cjs +33 -0
- package/dist/Autocomplete.js +25 -0
- package/dist/Avatar-229083ec.js +70 -0
- package/dist/Avatar-cccf72b9.js +78 -0
- package/dist/Avatar.cjs +15 -0
- package/dist/Avatar.js +7 -0
- package/dist/Banner-18d94700.js +105 -0
- package/dist/Banner-5475a9ea.js +98 -0
- package/dist/Banner.cjs +20 -0
- package/dist/Banner.js +12 -0
- package/dist/Body-22878526.js +64 -0
- package/dist/Body-4fbe21ac.js +50 -0
- package/dist/Button-30154871.js +50 -0
- package/dist/Button-ec64869e.js +57 -0
- package/dist/Button.cjs +16 -0
- package/dist/Button.js +8 -0
- package/dist/ButtonDismiss-a11eef74.js +8 -0
- package/dist/ButtonDismiss-d7417429.js +14 -0
- package/dist/ButtonDismiss.cjs +17 -0
- package/dist/ButtonDismiss.js +9 -0
- package/dist/Card-27375ded.js +93 -0
- package/dist/Card-35bd61ce.js +86 -0
- package/dist/Card.cjs +24 -0
- package/dist/Card.js +16 -0
- package/dist/Checkbox-a91b14f7.js +56 -0
- package/dist/Checkbox-b6e46d80.js +63 -0
- package/dist/Checkbox.cjs +18 -0
- package/dist/Checkbox.js +10 -0
- package/dist/Chip-01343f8b.js +81 -0
- package/dist/Chip-24613c57.js +89 -0
- package/dist/Chip.cjs +27 -0
- package/dist/Chip.js +17 -0
- package/dist/ChipDismissible-1f2754bd.js +19 -0
- package/dist/ChipDismissible-a8ecc894.js +26 -0
- package/dist/Chips-7c44a2f9.js +494 -0
- package/dist/Chips-a8f4c9f2.js +505 -0
- package/dist/Chips.cjs +46 -0
- package/dist/Chips.js +37 -0
- package/dist/Combobox-44f0ec2a.js +468 -0
- package/dist/Combobox-d8d28b1e.js +479 -0
- package/dist/Combobox.cjs +40 -0
- package/dist/Combobox.js +31 -0
- package/dist/ConfirmationModal-09ec5d02.js +100 -0
- package/dist/ConfirmationModal-64f82a31.js +94 -0
- package/dist/ConfirmationModal.cjs +31 -0
- package/dist/ConfirmationModal.js +23 -0
- package/dist/Content-60a3452a.js +24 -0
- package/dist/Content-c96e9299.js +18 -0
- package/dist/Content.cjs +12 -0
- package/dist/Content.js +4 -0
- package/dist/Countdown-961d8a6e.js +70 -0
- package/dist/Countdown-ac081ced.js +63 -0
- package/dist/Countdown.cjs +12 -0
- package/dist/Countdown.js +4 -0
- package/dist/DataDump-6fae2727.js +15 -0
- package/dist/DataDump-f427abfe.js +21 -0
- package/dist/DataDump.cjs +27 -0
- package/dist/DataDump.js +19 -0
- package/dist/DataList-18f2d692.js +1310 -0
- package/dist/DataList-4b0f9e5d.js +1320 -0
- package/dist/DataList.cjs +52 -0
- package/dist/DataList.js +44 -0
- package/dist/DataTable-0f6649e0.js +245 -0
- package/dist/DataTable-aab7f6b9.js +252 -0
- package/dist/DataTable.cjs +65 -0
- package/dist/DataTable.js +36 -0
- package/dist/DatePicker-5d0c0353.js +125 -0
- package/dist/DatePicker-c091c0d2.js +134 -0
- package/dist/DatePicker.cjs +20 -0
- package/dist/DatePicker.js +12 -0
- package/dist/DescriptionList-2cb975a9.js +15 -0
- package/dist/DescriptionList-74db99a5.js +21 -0
- package/dist/DescriptionList.cjs +13 -0
- package/dist/DescriptionList.js +5 -0
- package/dist/Disclosure-00a9459b.js +36 -0
- package/dist/Disclosure-56309ff3.js +42 -0
- package/dist/Disclosure.cjs +16 -0
- package/dist/Disclosure.js +8 -0
- package/dist/Divider-1e6ac1ec.js +27 -0
- package/dist/Divider-589745c1.js +20 -0
- package/dist/Divider.cjs +12 -0
- package/dist/Divider.js +4 -0
- package/dist/Drawer.cjs +21 -0
- package/dist/Drawer.js +12 -0
- package/dist/DrawerGrid-0861e529.js +33 -0
- package/dist/DrawerGrid-b233d837.js +41 -0
- package/dist/Emphasis-2a640962.js +13 -0
- package/dist/Emphasis-84de1f3f.js +19 -0
- package/dist/Emphasis.cjs +13 -0
- package/dist/Emphasis.js +5 -0
- package/dist/FeatureSwitch-ddaebf27.js +62 -0
- package/dist/FeatureSwitch-e33e30a9.js +55 -0
- package/dist/FeatureSwitch.cjs +26 -0
- package/dist/FeatureSwitch.js +18 -0
- package/dist/Flex-041db5c8.js +31 -0
- package/dist/Flex-ddf28839.js +38 -0
- package/dist/Flex.cjs +12 -0
- package/dist/Flex.js +4 -0
- package/dist/Form-6a161b07.js +48 -0
- package/dist/Form-927647ef.js +54 -0
- package/dist/Form.cjs +12 -0
- package/dist/Form.js +4 -0
- package/dist/FormField-f1f405d2.js +246 -0
- package/dist/FormField-fc30bb1a.js +253 -0
- package/dist/FormField.cjs +24 -0
- package/dist/FormField.js +16 -0
- package/dist/FormatDate-70ea5b43.js +34 -0
- package/dist/FormatDate-720b39cf.js +27 -0
- package/dist/FormatDate.cjs +11 -0
- package/dist/FormatDate.js +2 -0
- package/dist/FormatEmail-04ee4085.js +14 -0
- package/dist/FormatEmail-298393bb.js +21 -0
- package/dist/FormatEmail.cjs +12 -0
- package/dist/FormatEmail.js +4 -0
- package/dist/FormatFile-648aea3e.js +154 -0
- package/dist/FormatFile-d57b8dfa.js +162 -0
- package/dist/FormatFile.cjs +36 -0
- package/dist/FormatFile.js +28 -0
- package/dist/FormatRelativeDateTime-529dc36b.js +64 -0
- package/dist/FormatRelativeDateTime-6336002d.js +70 -0
- package/dist/FormatRelativeDateTime.cjs +10 -0
- package/dist/FormatRelativeDateTime.js +2 -0
- package/dist/FormatTime-20538519.js +34 -0
- package/dist/FormatTime-764fd3c8.js +28 -0
- package/dist/FormatTime.cjs +10 -0
- package/dist/FormatTime.js +2 -0
- package/dist/Gallery-7760f21f.js +66 -0
- package/dist/Gallery-8d4d79a2.js +73 -0
- package/dist/Gallery.cjs +39 -0
- package/dist/Gallery.js +31 -0
- package/dist/Glimmer-3fcdae65.js +77 -0
- package/dist/Glimmer-6bf75ae0.js +69 -0
- package/dist/Glimmer.cjs +15 -0
- package/dist/Glimmer.js +6 -0
- package/dist/Grid-c28e226d.js +66 -0
- package/dist/Grid-cce44c9d.js +74 -0
- package/dist/Grid.cjs +14 -0
- package/dist/Grid.js +5 -0
- package/dist/Heading-a8a24775.js +55 -0
- package/dist/Heading-dfd4f1cf.js +49 -0
- package/dist/Heading.cjs +14 -0
- package/dist/Heading.js +6 -0
- package/dist/Icon-22723fe6.js +34 -0
- package/dist/Icon-405a216c.js +40 -0
- package/dist/Icon.cjs +11 -0
- package/dist/Icon.js +3 -0
- package/dist/InlineLabel-20f9095e.js +21 -0
- package/dist/InlineLabel-5144fa06.js +28 -0
- package/dist/InlineLabel.cjs +13 -0
- package/dist/InlineLabel.js +5 -0
- package/dist/InputAvatar-3a10bdb1.js +50 -0
- package/dist/InputAvatar-95c98620.js +56 -0
- package/dist/InputAvatar.cjs +28 -0
- package/dist/InputAvatar.js +20 -0
- package/dist/InputDate-c258f5cb.js +32 -0
- package/dist/InputDate-c5f19423.js +39 -0
- package/dist/InputDate.cjs +29 -0
- package/dist/InputDate.js +21 -0
- package/dist/InputEmail-4efba03d.js +27 -0
- package/dist/InputEmail-812bdffe.js +20 -0
- package/dist/InputEmail.cjs +26 -0
- package/dist/InputEmail.js +17 -0
- package/dist/InputFile-921c050e.js +190 -0
- package/dist/InputFile-d089b486.js +181 -0
- package/dist/InputFile.cjs +25 -0
- package/dist/InputFile.js +16 -0
- package/dist/InputGroup-436859cf.js +26 -0
- package/dist/InputGroup-8d4fd4eb.js +33 -0
- package/dist/InputGroup.cjs +12 -0
- package/dist/InputGroup.js +4 -0
- package/dist/InputNumber-4bd38b8e.js +56 -0
- package/dist/InputNumber-df9cb825.js +62 -0
- package/dist/InputNumber.cjs +25 -0
- package/dist/InputNumber.js +17 -0
- package/dist/InputPassword-08d2dfa1.js +25 -0
- package/dist/InputPassword-6b937a91.js +19 -0
- package/dist/InputPassword.cjs +25 -0
- package/dist/InputPassword.js +17 -0
- package/dist/InputPhoneNumber-947bdb49.js +97 -0
- package/dist/InputPhoneNumber-cbb2ca7d.js +103 -0
- package/dist/InputPhoneNumber.cjs +25 -0
- package/dist/InputPhoneNumber.js +17 -0
- package/dist/InputText-125769fd.js +102 -0
- package/dist/InputText-2fd8f942.js +96 -0
- package/dist/InputText.cjs +26 -0
- package/dist/InputText.js +18 -0
- package/dist/InputTime-3c4bdff0.js +194 -0
- package/dist/InputTime-ef8af2d9.js +187 -0
- package/dist/InputTime.cjs +27 -0
- package/dist/InputTime.js +19 -0
- package/dist/InputValidation-4a61254d.js +29 -0
- package/dist/InputValidation-fe42fc3f.js +23 -0
- package/dist/InputValidation.cjs +17 -0
- package/dist/InputValidation.js +9 -0
- package/dist/LightBox-3d6e74ba.js +117 -0
- package/dist/LightBox-8cc72953.js +109 -0
- package/dist/LightBox.cjs +24 -0
- package/dist/LightBox.js +16 -0
- package/dist/Link-b41bc1d3.js +7 -0
- package/dist/Link-fd7301ec.js +13 -0
- package/dist/Link.cjs +10 -0
- package/dist/Link.js +2 -0
- package/dist/List-4fe52f57.js +77 -0
- package/dist/List-821f249d.js +87 -0
- package/dist/List.cjs +25 -0
- package/dist/List.js +16 -0
- package/dist/Markdown-36854bd5.js +62 -0
- package/dist/Markdown-7b84fcdb.js +55 -0
- package/dist/Markdown.cjs +19 -0
- package/dist/Markdown.js +11 -0
- package/dist/Menu-5ce3cf41.js +139 -0
- package/dist/Menu-fb0b2e9b.js +132 -0
- package/dist/Menu.cjs +21 -0
- package/dist/Menu.js +13 -0
- package/dist/Modal-cda55f02.js +71 -0
- package/dist/Modal-eeb52d66.js +63 -0
- package/dist/Modal.cjs +25 -0
- package/dist/Modal.js +17 -0
- package/dist/MultiSelect-0af9c956.js +169 -0
- package/dist/MultiSelect-707000e1.js +176 -0
- package/dist/MultiSelect.cjs +19 -0
- package/dist/MultiSelect.js +11 -0
- package/dist/Option-58d7cab6.js +12 -0
- package/dist/Option-73515eec.js +19 -0
- package/dist/Page-0b334096.js +59 -0
- package/dist/Page-fdb087db.js +66 -0
- package/dist/Page.cjs +30 -0
- package/dist/Page.js +22 -0
- package/dist/Popover-798f548e.js +47 -0
- package/dist/Popover-968c63b2.js +53 -0
- package/dist/Popover.cjs +20 -0
- package/dist/Popover.js +12 -0
- package/dist/ProgressBar-022ef3f6.js +36 -0
- package/dist/ProgressBar-4ee648b7.js +43 -0
- package/dist/ProgressBar.cjs +12 -0
- package/dist/ProgressBar.js +4 -0
- package/dist/RadioGroup-68edd1e3.js +46 -0
- package/dist/RadioGroup-a089f132.js +39 -0
- package/dist/RadioGroup.cjs +15 -0
- package/dist/RadioGroup.js +6 -0
- package/dist/RecurringSelect-2de4014c.js +208 -0
- package/dist/RecurringSelect-e391af31.js +214 -0
- package/dist/RecurringSelect.cjs +38 -0
- package/dist/RecurringSelect.js +22 -0
- package/dist/Select.cjs +26 -0
- package/dist/Select.js +17 -0
- package/dist/Spinner-3480bc34.js +24 -0
- package/dist/Spinner-90081e20.js +17 -0
- package/dist/Spinner.cjs +12 -0
- package/dist/Spinner.js +4 -0
- package/dist/StatusIndicator-0c680acb.js +18 -0
- package/dist/StatusIndicator-d6f9aefa.js +12 -0
- package/dist/StatusIndicator.cjs +11 -0
- package/dist/StatusIndicator.js +3 -0
- package/dist/StatusLabel-5bf96fdb.js +26 -0
- package/dist/StatusLabel-66214fc7.js +19 -0
- package/dist/StatusLabel.cjs +15 -0
- package/dist/StatusLabel.js +7 -0
- package/dist/Switch-6c6c727b.js +56 -0
- package/dist/Switch-87706cde.js +49 -0
- package/dist/Switch.cjs +13 -0
- package/dist/Switch.js +5 -0
- package/dist/Table.cjs +20 -0
- package/dist/Table.js +5 -0
- package/dist/Tabs-109f1f10.js +70 -0
- package/dist/Tabs-d6c8b965.js +78 -0
- package/dist/Tabs.cjs +14 -0
- package/dist/Tabs.js +5 -0
- package/dist/Text-714f7d14.js +31 -0
- package/dist/Text-c92ddeb3.js +25 -0
- package/dist/Text.cjs +13 -0
- package/dist/Text.js +5 -0
- package/dist/Toast.cjs +19 -0
- package/dist/Toast.js +11 -0
- package/dist/Tooltip-2e477150.js +112 -0
- package/dist/Tooltip-a40fffbd.js +104 -0
- package/dist/Tooltip.cjs +16 -0
- package/dist/Tooltip.js +8 -0
- package/dist/Typography-52ed1386.js +55 -0
- package/dist/Typography-fd88fcce.js +62 -0
- package/dist/Typography.cjs +12 -0
- package/dist/Typography.js +4 -0
- package/dist/getAtlantisConfig-0f3e8af2.js +13 -0
- package/dist/getAtlantisConfig-5b50057c.js +11 -0
- package/dist/index.cjs +216 -6713
- package/dist/index.js +112 -0
- package/dist/showToast-63be1cf0.js +106 -0
- package/dist/showToast-ff666be8.js +100 -0
- package/dist/style-inject.es-9d2f5f4e.js +30 -0
- package/dist/style-inject.es-a0e1a0ba.js +28 -0
- package/dist/tslib.es6-754e2961.js +46 -0
- package/dist/tslib.es6-c563c1dd.js +43 -0
- package/package.json +6 -365
- package/AnimatedPresence.d.ts +0 -1
- package/AnimatedPresence.js +0 -17
- package/AnimatedSwitcher.d.ts +0 -1
- package/AnimatedSwitcher.js +0 -17
- package/Autocomplete.d.ts +0 -1
- package/Autocomplete.js +0 -17
- package/Avatar.d.ts +0 -1
- package/Avatar.js +0 -17
- package/Banner.d.ts +0 -1
- package/Banner.js +0 -17
- package/Button.d.ts +0 -1
- package/Button.js +0 -17
- package/ButtonDismiss.d.ts +0 -1
- package/ButtonDismiss.js +0 -17
- package/Card.d.ts +0 -1
- package/Card.js +0 -17
- package/Checkbox.d.ts +0 -1
- package/Checkbox.js +0 -17
- package/Chip.d.ts +0 -1
- package/Chip.js +0 -17
- package/Chips.d.ts +0 -1
- package/Chips.js +0 -17
- package/Combobox.d.ts +0 -1
- package/Combobox.js +0 -17
- package/ConfirmationModal.d.ts +0 -1
- package/ConfirmationModal.js +0 -17
- package/Content.d.ts +0 -1
- package/Content.js +0 -17
- package/Countdown.d.ts +0 -1
- package/Countdown.js +0 -17
- package/DataDump.d.ts +0 -1
- package/DataDump.js +0 -17
- package/DataList.d.ts +0 -1
- package/DataList.js +0 -17
- package/DataTable.d.ts +0 -1
- package/DataTable.js +0 -17
- package/DatePicker.d.ts +0 -1
- package/DatePicker.js +0 -17
- package/DescriptionList.d.ts +0 -1
- package/DescriptionList.js +0 -17
- package/Disclosure.d.ts +0 -1
- package/Disclosure.js +0 -17
- package/Divider.d.ts +0 -1
- package/Divider.js +0 -17
- package/Drawer.d.ts +0 -1
- package/Drawer.js +0 -17
- package/Emphasis.d.ts +0 -1
- package/Emphasis.js +0 -17
- package/FeatureSwitch.d.ts +0 -1
- package/FeatureSwitch.js +0 -17
- package/Flex.d.ts +0 -1
- package/Flex.js +0 -17
- package/Form.d.ts +0 -1
- package/Form.js +0 -17
- package/FormField.d.ts +0 -1
- package/FormField.js +0 -17
- package/FormatDate.d.ts +0 -1
- package/FormatDate.js +0 -17
- package/FormatEmail.d.ts +0 -1
- package/FormatEmail.js +0 -17
- package/FormatFile.d.ts +0 -1
- package/FormatFile.js +0 -17
- package/FormatRelativeDateTime.d.ts +0 -1
- package/FormatRelativeDateTime.js +0 -17
- package/FormatTime.d.ts +0 -1
- package/FormatTime.js +0 -17
- package/Gallery.d.ts +0 -1
- package/Gallery.js +0 -17
- package/Glimmer.d.ts +0 -1
- package/Glimmer.js +0 -17
- package/Grid.d.ts +0 -1
- package/Grid.js +0 -17
- package/Heading.d.ts +0 -1
- package/Heading.js +0 -17
- package/Icon.d.ts +0 -1
- package/Icon.js +0 -17
- package/InlineLabel.d.ts +0 -1
- package/InlineLabel.js +0 -17
- package/InputAvatar.d.ts +0 -1
- package/InputAvatar.js +0 -17
- package/InputDate.d.ts +0 -1
- package/InputDate.js +0 -17
- package/InputEmail.d.ts +0 -1
- package/InputEmail.js +0 -17
- package/InputFile.d.ts +0 -1
- package/InputFile.js +0 -17
- package/InputGroup.d.ts +0 -1
- package/InputGroup.js +0 -17
- package/InputNumber.d.ts +0 -1
- package/InputNumber.js +0 -17
- package/InputPassword.d.ts +0 -1
- package/InputPassword.js +0 -17
- package/InputPhoneNumber.d.ts +0 -1
- package/InputPhoneNumber.js +0 -17
- package/InputText.d.ts +0 -1
- package/InputText.js +0 -17
- package/InputTime.d.ts +0 -1
- package/InputTime.js +0 -17
- package/InputValidation.d.ts +0 -1
- package/InputValidation.js +0 -17
- package/LightBox.d.ts +0 -1
- package/LightBox.js +0 -17
- package/Link.d.ts +0 -1
- package/Link.js +0 -17
- package/List.d.ts +0 -1
- package/List.js +0 -17
- package/Markdown.d.ts +0 -1
- package/Markdown.js +0 -17
- package/Menu.d.ts +0 -1
- package/Menu.js +0 -17
- package/Modal.d.ts +0 -1
- package/Modal.js +0 -17
- package/MultiSelect.d.ts +0 -1
- package/MultiSelect.js +0 -17
- package/Page.d.ts +0 -1
- package/Page.js +0 -17
- package/Popover.d.ts +0 -1
- package/Popover.js +0 -17
- package/ProgressBar.d.ts +0 -1
- package/ProgressBar.js +0 -17
- package/RadioGroup.d.ts +0 -1
- package/RadioGroup.js +0 -17
- package/RecurringSelect.d.ts +0 -1
- package/RecurringSelect.js +0 -17
- package/Select.d.ts +0 -1
- package/Select.js +0 -17
- package/Spinner.d.ts +0 -1
- package/Spinner.js +0 -17
- package/StatusIndicator.d.ts +0 -1
- package/StatusIndicator.js +0 -17
- package/StatusLabel.d.ts +0 -1
- package/StatusLabel.js +0 -17
- package/Switch.d.ts +0 -1
- package/Switch.js +0 -17
- package/Table.d.ts +0 -1
- package/Table.js +0 -17
- package/Tabs.d.ts +0 -1
- package/Tabs.js +0 -17
- package/Text.d.ts +0 -1
- package/Text.js +0 -17
- package/Toast.d.ts +0 -1
- package/Toast.js +0 -17
- package/Tooltip.d.ts +0 -1
- package/Tooltip.js +0 -17
- package/Typography.d.ts +0 -1
- package/Typography.js +0 -17
- package/dist/index.esm.js +0 -6603
- package/rollup.config.js +0 -75
|
@@ -0,0 +1,494 @@
|
|
|
1
|
+
import React, { useRef, useState, useId, useEffect } from 'react';
|
|
2
|
+
import { s as styleInject } from './style-inject.es-a0e1a0ba.js';
|
|
3
|
+
import classnames from 'classnames';
|
|
4
|
+
import { useAssert } from '@jobber/hooks/useAssert';
|
|
5
|
+
import { I as Icon } from './Icon-22723fe6.js';
|
|
6
|
+
import { A as Avatar } from './Avatar-229083ec.js';
|
|
7
|
+
import { T as Typography } from './Typography-52ed1386.js';
|
|
8
|
+
import { T as Tooltip } from './Tooltip-a40fffbd.js';
|
|
9
|
+
import sortBy from 'lodash/sortBy';
|
|
10
|
+
import { useLiveAnnounce } from '@jobber/hooks/useLiveAnnounce';
|
|
11
|
+
import debounce from 'lodash/debounce';
|
|
12
|
+
import '@jobber/design';
|
|
13
|
+
import { usePopper } from 'react-popper';
|
|
14
|
+
import { T as Text } from './Text-c92ddeb3.js';
|
|
15
|
+
import { B as Button } from './Button-30154871.js';
|
|
16
|
+
import { S as Spinner } from './Spinner-90081e20.js';
|
|
17
|
+
|
|
18
|
+
var css_248z$1 = "/**\n * Used in the wrapping chips component:\n * - InternalChipSingleSelect\n * - InternalChipMultiSelect\n */\n\n.zn6onyiQVmA- {\n display: -ms-flexbox;\n display: flex;\n gap: var(--space-small);\n -ms-flex-wrap: wrap;\n flex-wrap: wrap;\n -ms-flex-align: center;\n align-items: center;\n}\n\n.PEnZzMEgbhU- {\n display: inline-grid;\n position: relative;\n max-width: 100%;\n box-sizing: border-box;\n padding: var(--space-small);\n border: var(--border-base) solid var(--color-border);\n border-radius: var(--radius-larger);\n color: var(--color-text--secondary);\n text-align: left;\n vertical-align: middle;\n background-color: var(--color-surface);\n transition: var(--timing-base) ease-in-out;\n transition-property: background-color, box-shadow, color;\n grid-template-columns: -webkit-max-content;\n grid-template-columns: max-content;\n -ms-flex-align: center;\n align-items: center;\n gap: var(--space-small);\n}\n\n.dtysUhwYdG4-,\n.xGaMCAYsdwA- {\n padding: calc(var(--space-smaller) + var(--space-smallest)) var(--space-small);\n}\n\n.dtysUhwYdG4- {\n grid-template-columns: -webkit-min-content 1fr;\n grid-template-columns: min-content 1fr;\n}\n\n.xGaMCAYsdwA- {\n grid-template-columns: 1fr -webkit-min-content;\n grid-template-columns: 1fr min-content;\n}\n\n.dtysUhwYdG4-.xGaMCAYsdwA- {\n grid-template-columns: -webkit-min-content 1fr -webkit-min-content;\n grid-template-columns: min-content 1fr min-content;\n}\n\n.SNT7gGV-h-o-,\n.W4D98cvEth4- ~ .PEnZzMEgbhU- {\n box-shadow: var(--shadow-base);\n cursor: pointer;\n -webkit-appearance: none;\n appearance: none;\n}\n\n/**\n * Interaction\n */\n\n.PEnZzMEgbhU-:focus,\n.W4D98cvEth4-:focus ~ .PEnZzMEgbhU- {\n box-shadow: var(--shadow-focus);\n outline: none;\n}\n\n.SNT7gGV-h-o-:hover,\n.W4D98cvEth4- ~ .PEnZzMEgbhU-:not(._0hEzaTXK9M0-):hover,\n.W4D98cvEth4-:focus ~ .PEnZzMEgbhU-:not(._0hEzaTXK9M0-) {\n background-color: var(--color-surface--hover);\n}\n\n/**\n * States\n */\n\n.PEnZzMEgbhU-._0hEzaTXK9M0- {\n border-color: var(--color-surface--reverse);\n color: var(--color-text--reverse);\n background-color: var(--color-surface--reverse);\n}\n\n.PEnZzMEgbhU-.JApS2787BU8- {\n border-color: var(--color-critical--onSurface);\n color: var(--color-critical--onSurface);\n background-color: var(--color-critical--surface);\n}\n\n.PEnZzMEgbhU-.Kg0c8WVgMpg- {\n border-color: var(--color-disabled--secondary);\n color: var(--color-disabled);\n background-color: var(--color-disabled--secondary);\n}\n\n._0hEzaTXK9M0-.Kg0c8WVgMpg- {\n border-color: var(--color-disabled);\n color: var(--color-white);\n background-color: var(--color-disabled);\n}\n\n.JApS2787BU8-.Kg0c8WVgMpg- {\n border-color: var(--color-critical);\n}\n\n/**\n * Input checkbox/radio\n *\n * Hide checkbox on UI but not screen readers and still allow focus state\n */\n\n.W4D98cvEth4- {\n position: absolute;\n width: 1px;\n height: 1px;\n overflow: hidden;\n clip: rect(0 0 0 0);\n -webkit-clip-path: inset(100%);\n clip-path: inset(100%);\n white-space: nowrap;\n}\n\n/**\n * Button\n */\n\n._0-ZWexS4Gfg- {\n display: -ms-flexbox;\n display: flex;\n border-radius: var(--radius-base);\n cursor: pointer;\n transition: background-color 200ms ease;\n}\n\n._0-ZWexS4Gfg-:hover,\n._0-ZWexS4Gfg-:focus {\n background-color: var(--color-surface--hover);\n}\n\n._0-ZWexS4Gfg-:focus,\n.SNT7gGV-h-o- ._0-ZWexS4Gfg-:hover {\n box-shadow: var(--shadow-focus);\n outline: none;\n}\n\n/**\n * Override icon default colors.\n *\n * NOTE: This is a workaround since some icons have default colors that we don't\n * want to override until the component color prop overrides it.\n * DO NOT COPY!\n */\n\n.DQPnZP4UZpw- > svg {\n fill: var(--color-interactive--subtle);\n}\n\n.DQPnZP4UZpw- {\n display: -ms-flexbox;\n display: flex;\n}\n";
|
|
19
|
+
var styles$1 = {"wrapper":"zn6onyiQVmA-","chip":"PEnZzMEgbhU-","hasPrefix":"dtysUhwYdG4-","hasSuffix":"xGaMCAYsdwA-","clickable":"SNT7gGV-h-o-","input":"W4D98cvEth4-","active":"_0hEzaTXK9M0-","invalid":"JApS2787BU8-","disabled":"Kg0c8WVgMpg-","button":"_0-ZWexS4Gfg-","icon":"DQPnZP4UZpw-"};
|
|
20
|
+
styleInject(css_248z$1);
|
|
21
|
+
|
|
22
|
+
function InternalChipButton({ icon, invalid, disabled, label, onClick, }) {
|
|
23
|
+
const buttonRef = useRef();
|
|
24
|
+
return (React.createElement("div", { ref: buttonRef, className: styles$1.button, tabIndex: 0, onKeyUp: handleKeyUp, onKeyDown: handleKeyDown, onClick: handleClick, role: "button", "aria-label": `Remove ${label}`, "aria-hidden": true, "aria-disabled": disabled, "data-testid": "remove-chip-button" },
|
|
25
|
+
React.createElement(Icon, { name: icon, color: getColor() })));
|
|
26
|
+
function handleKeyUp(event) {
|
|
27
|
+
if (document.activeElement === buttonRef.current &&
|
|
28
|
+
(event.key === " " || event.key === "Enter")) {
|
|
29
|
+
event.stopPropagation();
|
|
30
|
+
buttonRef.current.click();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function handleKeyDown(event) {
|
|
34
|
+
if (document.activeElement === buttonRef.current && event.key === " ") {
|
|
35
|
+
// Don't scroll down
|
|
36
|
+
event.preventDefault();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function getColor() {
|
|
40
|
+
if (disabled)
|
|
41
|
+
return "disabled";
|
|
42
|
+
if (invalid)
|
|
43
|
+
return "critical";
|
|
44
|
+
return "greyBlue";
|
|
45
|
+
}
|
|
46
|
+
function handleClick(event) {
|
|
47
|
+
event.stopPropagation();
|
|
48
|
+
onClick === null || onClick === void 0 ? void 0 : onClick(event);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function InternalChipAffix({ affix, active, invalid, disabled, }) {
|
|
53
|
+
assertProps();
|
|
54
|
+
if ((affix === null || affix === void 0 ? void 0 : affix.type) === Avatar) {
|
|
55
|
+
return React.createElement(Avatar, Object.assign({}, affix.props, { size: "small" }));
|
|
56
|
+
}
|
|
57
|
+
if ((affix === null || affix === void 0 ? void 0 : affix.type) === Icon) {
|
|
58
|
+
return renderChipIcon(affix);
|
|
59
|
+
}
|
|
60
|
+
if ((affix === null || affix === void 0 ? void 0 : affix.type) === InternalChipButton) {
|
|
61
|
+
return React.createElement(InternalChipButton, Object.assign({}, affix.props));
|
|
62
|
+
}
|
|
63
|
+
return React.createElement(React.Fragment, null);
|
|
64
|
+
function renderChipIcon(icon) {
|
|
65
|
+
const color = getIconColor();
|
|
66
|
+
return (React.createElement("div", { className: styles$1.icon }, React.cloneElement(icon, Object.assign({ size: "base" }, (color && { color: color })))));
|
|
67
|
+
}
|
|
68
|
+
function getIconColor() {
|
|
69
|
+
if (disabled && !active)
|
|
70
|
+
return "disabled";
|
|
71
|
+
if (invalid && !disabled)
|
|
72
|
+
return "critical";
|
|
73
|
+
if (active)
|
|
74
|
+
return "white";
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
function assertProps() {
|
|
78
|
+
const isAvatar = (affix === null || affix === void 0 ? void 0 : affix.type) === Avatar || false;
|
|
79
|
+
const isIcon = (affix === null || affix === void 0 ? void 0 : affix.type) === Icon || false;
|
|
80
|
+
const isChipButton = (affix === null || affix === void 0 ? void 0 : affix.type) === InternalChipButton || false;
|
|
81
|
+
useAssert(!!affix && !(isAvatar || isIcon || isChipButton), `Prefix prop only accepts "<Avatar />" or "<Icon />" component. You have "${affix === null || affix === void 0 ? void 0 : affix.type}".`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function InternalChip({ label, active = false, disabled = false, invalid = false, prefix, suffix, tabIndex, ariaLabel, onClick, onKeyDown, }) {
|
|
86
|
+
const [truncateRef, setTruncateRef] = useState();
|
|
87
|
+
const isClickable = onClick && !disabled;
|
|
88
|
+
const classNames = classnames(styles$1.chip, {
|
|
89
|
+
[styles$1.clickable]: isClickable,
|
|
90
|
+
[styles$1.active]: active,
|
|
91
|
+
[styles$1.disabled]: disabled,
|
|
92
|
+
[styles$1.invalid]: invalid,
|
|
93
|
+
[styles$1.hasPrefix]: prefix,
|
|
94
|
+
[styles$1.hasSuffix]: suffix,
|
|
95
|
+
});
|
|
96
|
+
const affixProps = { active, invalid, disabled };
|
|
97
|
+
const Tag = onClick ? "button" : "div";
|
|
98
|
+
const chip = (React.createElement(Tag, Object.assign({ className: classNames }, (isClickable && { onClick, disabled }), { onKeyDown: onKeyDown, "data-testid": "chip-wrapper", "aria-label": ariaLabel, tabIndex: tabIndex, role: tabIndex !== undefined ? "option" : undefined }),
|
|
99
|
+
React.createElement(InternalChipAffix, Object.assign({ affix: prefix }, affixProps)),
|
|
100
|
+
React.createElement(Typography, { element: "span", numberOfLines: 1, size: "base" },
|
|
101
|
+
React.createElement("span", { ref: setTruncateRef }, label)),
|
|
102
|
+
React.createElement(InternalChipAffix, Object.assign({ affix: suffix }, affixProps))));
|
|
103
|
+
return isTruncated() ? React.createElement(Tooltip, { message: label }, chip) : chip;
|
|
104
|
+
function isTruncated() {
|
|
105
|
+
var _a;
|
|
106
|
+
const truncateParentHeight = ((_a = truncateRef === null || truncateRef === void 0 ? void 0 : truncateRef.parentElement) === null || _a === void 0 ? void 0 : _a.offsetHeight) || 0;
|
|
107
|
+
const truncateChildHeight = (truncateRef === null || truncateRef === void 0 ? void 0 : truncateRef.offsetHeight) || 0;
|
|
108
|
+
return truncateChildHeight >= truncateParentHeight * 2;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function InternalChipSingleSelect({ children, selected, name = useId(), onChange, onClick, }) {
|
|
113
|
+
return (React.createElement("div", { className: styles$1.wrapper, "data-testid": "singleselect-chips" }, React.Children.map(children, child => {
|
|
114
|
+
const isSelected = child.props.value === selected;
|
|
115
|
+
return (React.createElement("label", null,
|
|
116
|
+
React.createElement("input", { type: "radio", checked: isSelected, className: styles$1.input, name: name, onClick: handleClick(child.props.value), onKeyUp: handleKeyUp(isSelected, child.props.value), onChange: () => {
|
|
117
|
+
/* No op. onClick handles the change to allow deselecting. */
|
|
118
|
+
}, disabled: child.props.disabled }),
|
|
119
|
+
React.createElement(InternalChip, Object.assign({}, child.props, { active: isSelected }))));
|
|
120
|
+
})));
|
|
121
|
+
function handleKeyUp(active, value) {
|
|
122
|
+
if (!active)
|
|
123
|
+
return;
|
|
124
|
+
return (event) => {
|
|
125
|
+
if (event.key === " ") {
|
|
126
|
+
// Wait for DOM changes before applying the new change.
|
|
127
|
+
setTimeout(() => handleChange(value), 0);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function handleClick(value) {
|
|
132
|
+
return (event) => {
|
|
133
|
+
onClick === null || onClick === void 0 ? void 0 : onClick(event, value);
|
|
134
|
+
handleChange(value);
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function handleChange(value) {
|
|
138
|
+
const newValue = value !== selected ? value : undefined;
|
|
139
|
+
onChange(newValue);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function InternalChipMultiSelect({ children, selected, onChange, onClick, }) {
|
|
144
|
+
return (React.createElement("div", { className: styles$1.wrapper, "data-testid": "multiselect-chips" }, React.Children.map(children, chip => {
|
|
145
|
+
const isChipActive = isChipSelected(chip.props.value);
|
|
146
|
+
return (React.createElement("label", null,
|
|
147
|
+
React.createElement("input", { type: "checkbox", checked: isChipActive, className: styles$1.input, onClick: handleClick(chip.props.value), onChange: handleChange(chip.props.value), disabled: chip.props.disabled }),
|
|
148
|
+
React.createElement(InternalChip, Object.assign({}, chip.props, { active: isChipActive, suffix: checkmarkIcon(isChipActive) }))));
|
|
149
|
+
})));
|
|
150
|
+
function isChipSelected(value) {
|
|
151
|
+
return selected.includes(value);
|
|
152
|
+
}
|
|
153
|
+
function handleClick(value) {
|
|
154
|
+
return (event) => onClick === null || onClick === void 0 ? void 0 : onClick(event, value);
|
|
155
|
+
}
|
|
156
|
+
function handleChange(value) {
|
|
157
|
+
return () => {
|
|
158
|
+
if (isChipSelected(value)) {
|
|
159
|
+
handleDeselect(value);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
handleSelect(value);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function handleSelect(value) {
|
|
167
|
+
const newVal = [...selected, value];
|
|
168
|
+
onChange(newVal);
|
|
169
|
+
}
|
|
170
|
+
function handleDeselect(value) {
|
|
171
|
+
const values = selected;
|
|
172
|
+
const newVal = values.filter(val => val !== value);
|
|
173
|
+
onChange(newVal);
|
|
174
|
+
}
|
|
175
|
+
function checkmarkIcon(show) {
|
|
176
|
+
// Ideally, we should be returning a fragment `<></>` when a function
|
|
177
|
+
// returns a component / element. However, this one needs to return nothing
|
|
178
|
+
// to prevent it from randomly rendering a suffix.
|
|
179
|
+
//
|
|
180
|
+
// DO NOT COPY!
|
|
181
|
+
if (!show)
|
|
182
|
+
return;
|
|
183
|
+
return React.createElement(Icon, { name: "checkmark" });
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
var css_248z = ".sCNIjluCskc- {\n display: -ms-flexbox;\n display: flex;\n position: relative;\n box-sizing: border-box;\n border: var(--border-base) solid transparent;\n border-radius: var(--radius-base);\n transition: all var(--timing-base);\n gap: var(--space-small);\n -ms-flex-wrap: wrap;\n flex-wrap: wrap;\n -ms-flex-align: center;\n align-items: center;\n}\n\n.MFUlz1WQLdk- {\n -ms-flex: 1;\n flex: 1;\n min-width: 120px;\n padding: var(--space-small) 0;\n border: none;\n border-radius: 0;\n color: inherit;\n font-family: inherit;\n font-size: inherit;\n font-size: var(--typography--fontSize-base);\n line-height: var(--typography--lineHeight-base);\n background: transparent;\n -webkit-appearance: none;\n appearance: none;\n}\n\n.MFUlz1WQLdk-:focus {\n outline: none;\n}\n\n.V9eYJdjPAeY- {\n position: relative;\n z-index: var(--elevation-menu);\n width: 100%;\n}\n\n.LdytkOeCU9c- {\n max-height: 320px;\n box-shadow: var(--shadow-base);\n padding: var(--space-small) 0;\n border-radius: var(--radius-base);\n overflow-y: scroll;\n background-color: var(--color-surface);\n}\n\n.y7Cz2u8BuNE-,\n._-7bmao8Q9As- {\n display: -ms-flexbox;\n display: flex;\n width: 100%;\n padding: var(--space-small);\n border: none;\n background-color: transparent;\n cursor: pointer;\n -webkit-appearance: none;\n appearance: none;\n -ms-flex-align: center;\n align-items: center;\n gap: var(--space-small);\n}\n\n.y7Cz2u8BuNE-:focus {\n box-shadow: var(--shadow-focus);\n}\n\n.y7Cz2u8BuNE-:focus,\n.iCwWdcmtInc- {\n outline: none;\n background-color: var(--color-surface--hover);\n}\n\n._-7bmao8Q9As- {\n -ms-flex-pack: center;\n justify-content: center;\n}\n";
|
|
188
|
+
var styles = {"wrapper":"sCNIjluCskc-","input":"MFUlz1WQLdk-","menu":"V9eYJdjPAeY-","menuList":"LdytkOeCU9c-","menuListOption":"y7Cz2u8BuNE-","loadingIndicator":"_-7bmao8Q9As-","activeOption":"iCwWdcmtInc-"};
|
|
189
|
+
styleInject(css_248z);
|
|
190
|
+
|
|
191
|
+
function useInternalChipDismissible({ children, selected, onChange, onClick, onCustomAdd, }) {
|
|
192
|
+
const ref = useRef(null);
|
|
193
|
+
const chipOptions = children.map(chip => chip.props);
|
|
194
|
+
const visibleChipOptions = chipOptions.filter(chip => selected.includes(chip.value));
|
|
195
|
+
const sortedVisibleChipOptions = sortBy(visibleChipOptions, chip => selected.indexOf(chip.value));
|
|
196
|
+
const availableChipOptions = chipOptions.filter(chip => !selected.includes(chip.value));
|
|
197
|
+
const { liveAnnounce } = useLiveAnnounce();
|
|
198
|
+
const actions = {
|
|
199
|
+
handleChipRemove: (value) => {
|
|
200
|
+
return () => {
|
|
201
|
+
liveAnnounce(`${value} Removed`);
|
|
202
|
+
onChange(selected.filter(val => val !== value));
|
|
203
|
+
};
|
|
204
|
+
},
|
|
205
|
+
handleChipAdd: (value) => onChange([...selected, value]),
|
|
206
|
+
handleCustomAdd: onCustomAdd,
|
|
207
|
+
handleChipClick: (value) => {
|
|
208
|
+
if (onClick === undefined)
|
|
209
|
+
return;
|
|
210
|
+
return (event) => onClick(event, value);
|
|
211
|
+
},
|
|
212
|
+
handleWrapperKeyDown: (event) => {
|
|
213
|
+
const target = event.target;
|
|
214
|
+
const isInputAndHasValue = target instanceof HTMLInputElement && target.value;
|
|
215
|
+
if (isInputAndHasValue)
|
|
216
|
+
return;
|
|
217
|
+
const nextElementToFocus = target.nextElementSibling;
|
|
218
|
+
const prevElementToFocus = target.previousElementSibling;
|
|
219
|
+
if (event.key === "ArrowLeft" &&
|
|
220
|
+
prevElementToFocus instanceof HTMLElement) {
|
|
221
|
+
prevElementToFocus.focus();
|
|
222
|
+
}
|
|
223
|
+
if (event.key === "ArrowRight" &&
|
|
224
|
+
nextElementToFocus instanceof HTMLElement) {
|
|
225
|
+
nextElementToFocus.focus();
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
handleChipKeyDown: (value) => {
|
|
229
|
+
return (event) => {
|
|
230
|
+
if (event.key === "Backspace" || event.key === "Delete") {
|
|
231
|
+
const target = event.target;
|
|
232
|
+
if (target instanceof HTMLElement) {
|
|
233
|
+
const prevElement = target.previousElementSibling;
|
|
234
|
+
const nextElement = target.nextElementSibling;
|
|
235
|
+
if (prevElement instanceof HTMLElement) {
|
|
236
|
+
prevElement.focus();
|
|
237
|
+
}
|
|
238
|
+
else if (nextElement instanceof HTMLElement) {
|
|
239
|
+
nextElement.focus();
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
actions.handleChipRemove(value)();
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
},
|
|
246
|
+
};
|
|
247
|
+
return Object.assign(Object.assign({}, actions), { ref,
|
|
248
|
+
sortedVisibleChipOptions,
|
|
249
|
+
availableChipOptions });
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// eslint-disable-next-line max-statements
|
|
253
|
+
function useInternalChipDismissibleInput({ options, isLoadingMore = false, onCustomOptionSelect, onOptionSelect, onSearch, }) {
|
|
254
|
+
const menuId = useId();
|
|
255
|
+
const [allOptions, setAllOptions] = useState([]);
|
|
256
|
+
const [searchValue, setSearchValue] = useState("");
|
|
257
|
+
const [menuOpen, setMenuOpen] = useState(false);
|
|
258
|
+
const [activeIndex, setActiveIndex] = useState(0);
|
|
259
|
+
const [shouldCancelBlur, setShouldCancelBlur] = useState(false);
|
|
260
|
+
const [shouldCancelEnter, setShouldCancelEnter] = useState(false);
|
|
261
|
+
const canAddCustomOption = onCustomOptionSelect !== undefined && !isLoadingMore;
|
|
262
|
+
const maxOptionIndex = allOptions.length - 1;
|
|
263
|
+
const { liveAnnounce } = useLiveAnnounce();
|
|
264
|
+
useEffect(() => {
|
|
265
|
+
setAllOptions(generateOptions(options, searchValue, canAddCustomOption));
|
|
266
|
+
}, [options]);
|
|
267
|
+
const computed = {
|
|
268
|
+
menuId,
|
|
269
|
+
inputRef: useRef(null),
|
|
270
|
+
activeOption: allOptions[activeIndex],
|
|
271
|
+
hasAvailableOptions: allOptions.length > 0,
|
|
272
|
+
nextOptionIndex: activeIndex < maxOptionIndex ? activeIndex + 1 : 0,
|
|
273
|
+
previousOptionIndex: activeIndex > 0 ? activeIndex - 1 : maxOptionIndex,
|
|
274
|
+
};
|
|
275
|
+
const actions = {
|
|
276
|
+
generateDescendantId: (index) => `${computed.menuId}-${index}`,
|
|
277
|
+
handleReset: () => {
|
|
278
|
+
setActiveIndex(activeIndex === 0 ? activeIndex : activeIndex - 1);
|
|
279
|
+
setSearchValue("");
|
|
280
|
+
},
|
|
281
|
+
handleOpenMenu: () => setMenuOpen(true),
|
|
282
|
+
handleCloseMenu: () => {
|
|
283
|
+
setMenuOpen(false);
|
|
284
|
+
setActiveIndex(0);
|
|
285
|
+
},
|
|
286
|
+
handleCancelBlur: () => setShouldCancelBlur(true),
|
|
287
|
+
handleEnableBlur: () => setShouldCancelBlur(false),
|
|
288
|
+
handleBlur: () => {
|
|
289
|
+
if (shouldCancelBlur)
|
|
290
|
+
return;
|
|
291
|
+
actions.handleReset();
|
|
292
|
+
actions.handleCloseMenu();
|
|
293
|
+
},
|
|
294
|
+
handleSearchChange: (event) => {
|
|
295
|
+
setActiveIndex(0);
|
|
296
|
+
setSearchValue(event.currentTarget.value);
|
|
297
|
+
setShouldCancelEnter(true);
|
|
298
|
+
},
|
|
299
|
+
handleSetActiveOnMouseOver: (index) => {
|
|
300
|
+
return () => setActiveIndex(index);
|
|
301
|
+
},
|
|
302
|
+
handleSelectOption: (selected) => {
|
|
303
|
+
var _a;
|
|
304
|
+
if (allOptions.length === 0)
|
|
305
|
+
return;
|
|
306
|
+
const setValue = selected.custom ? onCustomOptionSelect : onOptionSelect;
|
|
307
|
+
if (setValue) {
|
|
308
|
+
setValue(selected.value);
|
|
309
|
+
liveAnnounce(`${selected.label} Added`);
|
|
310
|
+
actions.handleReset();
|
|
311
|
+
(_a = computed.inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
312
|
+
}
|
|
313
|
+
},
|
|
314
|
+
handleKeyDown: (event) => {
|
|
315
|
+
const callbacks = {
|
|
316
|
+
Enter: () => {
|
|
317
|
+
if (shouldCancelEnter)
|
|
318
|
+
return;
|
|
319
|
+
actions.handleSelectOption(computed.activeOption);
|
|
320
|
+
},
|
|
321
|
+
Tab: () => actions.handleSelectOption(computed.activeOption),
|
|
322
|
+
",": () => {
|
|
323
|
+
if (searchValue.length === 0)
|
|
324
|
+
return;
|
|
325
|
+
actions.handleSelectOption(generateCustomOptionObject(searchValue));
|
|
326
|
+
},
|
|
327
|
+
ArrowDown: () => {
|
|
328
|
+
if (isLoadingMore && activeIndex === maxOptionIndex)
|
|
329
|
+
return;
|
|
330
|
+
setActiveIndex(computed.nextOptionIndex);
|
|
331
|
+
},
|
|
332
|
+
ArrowUp: () => setActiveIndex(computed.previousOptionIndex),
|
|
333
|
+
};
|
|
334
|
+
if (searchValue.length === 0) {
|
|
335
|
+
callbacks.Backspace = () => {
|
|
336
|
+
var _a;
|
|
337
|
+
// If there's no text left to delete,
|
|
338
|
+
// and delete is pressed again, focus on a chip instead.
|
|
339
|
+
const target = (_a = computed.inputRef.current) === null || _a === void 0 ? void 0 : _a.previousElementSibling;
|
|
340
|
+
if (target instanceof HTMLElement) {
|
|
341
|
+
target.focus();
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
handleKeydownEvents(callbacks, event);
|
|
346
|
+
},
|
|
347
|
+
handleDebouncedSearch: debounce(() => {
|
|
348
|
+
onSearch && onSearch(searchValue);
|
|
349
|
+
setAllOptions(generateOptions(options, searchValue, canAddCustomOption));
|
|
350
|
+
setShouldCancelEnter(false);
|
|
351
|
+
}, 300),
|
|
352
|
+
};
|
|
353
|
+
return Object.assign(Object.assign(Object.assign(Object.assign({}, actions), { activeIndex,
|
|
354
|
+
allOptions }), computed), { menuOpen,
|
|
355
|
+
searchValue,
|
|
356
|
+
shouldCancelBlur });
|
|
357
|
+
}
|
|
358
|
+
function generateOptions(options, searchValue, canAddCustomOption) {
|
|
359
|
+
const allOptions = options
|
|
360
|
+
.filter(option => option.label.toLowerCase().match(searchValue.trim().toLowerCase()))
|
|
361
|
+
.map(opt => (Object.assign(Object.assign({}, opt), { custom: false })));
|
|
362
|
+
const { shouldAddCustomOption, customOption } = generateCustomOption(allOptions, searchValue, canAddCustomOption);
|
|
363
|
+
shouldAddCustomOption && allOptions.push(customOption);
|
|
364
|
+
return allOptions;
|
|
365
|
+
}
|
|
366
|
+
function generateCustomOption(options, searchValue, canAddCustomOption) {
|
|
367
|
+
function shouldAddCustomOption() {
|
|
368
|
+
const isMatchingOption = options.some(option => option.label.toLowerCase() === searchValue.trim().toLowerCase());
|
|
369
|
+
return !!searchValue && !isMatchingOption;
|
|
370
|
+
}
|
|
371
|
+
return {
|
|
372
|
+
shouldAddCustomOption: canAddCustomOption && shouldAddCustomOption(),
|
|
373
|
+
customOption: generateCustomOptionObject(searchValue),
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
function generateCustomOptionObject(searchValue) {
|
|
377
|
+
return {
|
|
378
|
+
value: searchValue,
|
|
379
|
+
label: searchValue,
|
|
380
|
+
prefix: React.createElement(Icon, { name: "add" }),
|
|
381
|
+
custom: true,
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
function handleKeydownEvents(callbacks, event) {
|
|
385
|
+
if (event.shiftKey)
|
|
386
|
+
return;
|
|
387
|
+
Object.entries(callbacks).forEach(([key, callback]) => {
|
|
388
|
+
if (event.key === key) {
|
|
389
|
+
event.preventDefault();
|
|
390
|
+
callback(event);
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
function useInView() {
|
|
396
|
+
const ref = useRef(null);
|
|
397
|
+
const [isInView, setIsInView] = useState(false);
|
|
398
|
+
if (window.IntersectionObserver) {
|
|
399
|
+
const observer = new IntersectionObserver(entries => {
|
|
400
|
+
setIsInView(entries[0].isIntersecting);
|
|
401
|
+
});
|
|
402
|
+
useEffect(() => {
|
|
403
|
+
ref.current && observer.observe(ref.current);
|
|
404
|
+
return () => {
|
|
405
|
+
if (!ref.current)
|
|
406
|
+
return;
|
|
407
|
+
observer.unobserve(ref.current);
|
|
408
|
+
};
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
return { ref, isInView };
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
function useRepositionMenu(attachTo) {
|
|
415
|
+
var _a;
|
|
416
|
+
const [positionElement, setPositionedElementRef] = useState();
|
|
417
|
+
const popper = usePopper(attachTo.current, positionElement, {
|
|
418
|
+
modifiers: [
|
|
419
|
+
{ name: "offset", options: { offset: [0, 8] } },
|
|
420
|
+
{ name: "flip", options: { fallbackPlacements: ["top"] } },
|
|
421
|
+
],
|
|
422
|
+
});
|
|
423
|
+
const targetWidth = (_a = attachTo.current) === null || _a === void 0 ? void 0 : _a.clientWidth;
|
|
424
|
+
return Object.assign(Object.assign({}, popper), { setPositionedElementRef, targetWidth });
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
function useScrollToActive(index) {
|
|
428
|
+
const ref = useRef(null);
|
|
429
|
+
useEffect(() => {
|
|
430
|
+
var _a, _b;
|
|
431
|
+
if (!window.HTMLElement.prototype.scrollIntoView)
|
|
432
|
+
return;
|
|
433
|
+
(_b = (_a = ref.current) === null || _a === void 0 ? void 0 : _a.children[index]) === null || _b === void 0 ? void 0 : _b.scrollIntoView({
|
|
434
|
+
behavior: "smooth",
|
|
435
|
+
block: "nearest",
|
|
436
|
+
inline: "start",
|
|
437
|
+
});
|
|
438
|
+
}, [index]);
|
|
439
|
+
return ref;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
function InternalChipDismissibleInput(props) {
|
|
443
|
+
const { activator = React.createElement(Button, { icon: "add", type: "secondary", ariaLabel: "Add" }), attachTo, isLoadingMore = false, onLoadMore, } = props;
|
|
444
|
+
const { activeIndex, allOptions, hasAvailableOptions, inputRef, menuId, menuOpen, searchValue, generateDescendantId, handleBlur, handleOpenMenu, handleSearchChange, handleCancelBlur, handleEnableBlur, handleSetActiveOnMouseOver, handleKeyDown, handleSelectOption, handleDebouncedSearch, } = useInternalChipDismissibleInput(props);
|
|
445
|
+
const menuRef = useScrollToActive(activeIndex);
|
|
446
|
+
const { ref: visibleChildRef, isInView } = useInView();
|
|
447
|
+
const { styles: popperStyles, attributes, update, setPositionedElementRef, } = useRepositionMenu(attachTo);
|
|
448
|
+
useEffect(() => {
|
|
449
|
+
if (menuOpen && update)
|
|
450
|
+
update();
|
|
451
|
+
}, [allOptions]);
|
|
452
|
+
useEffect(() => {
|
|
453
|
+
handleDebouncedSearch();
|
|
454
|
+
return handleDebouncedSearch.cancel;
|
|
455
|
+
}, [searchValue]);
|
|
456
|
+
useEffect(() => {
|
|
457
|
+
isInView && onLoadMore && onLoadMore(searchValue);
|
|
458
|
+
}, [isInView]);
|
|
459
|
+
if (!menuOpen) {
|
|
460
|
+
return React.cloneElement(activator, { onClick: handleOpenMenu });
|
|
461
|
+
}
|
|
462
|
+
return (React.createElement(React.Fragment, null,
|
|
463
|
+
React.createElement("input", { ref: inputRef, className: styles.input, type: "text", role: "combobox", "aria-label": "Press up and down arrow to cycle through the options or type to narrow down the results", "aria-autocomplete": "list", "aria-owns": menuId, "aria-expanded": hasAvailableOptions, "aria-activedescendant": generateDescendantId(activeIndex), value: searchValue, onChange: handleSearchChange, onKeyDown: handleKeyDown, onBlur: debounce(handleBlur, 200), onFocus: handleOpenMenu, autoFocus: true }),
|
|
464
|
+
(hasAvailableOptions || isLoadingMore) && (React.createElement("div", Object.assign({ ref: setPositionedElementRef, className: styles.menu, style: popperStyles.popper }, attributes.popper),
|
|
465
|
+
React.createElement("div", { ref: menuRef, role: "listbox", id: menuId, className: styles.menuList, "data-testid": "chip-menu" },
|
|
466
|
+
allOptions.map((option, i) => (React.createElement("button", { key: option.value, role: "option", type: "button", id: generateDescendantId(i), className: classnames(styles.menuListOption, {
|
|
467
|
+
[styles.activeOption]: activeIndex === i,
|
|
468
|
+
}), onClick: () => handleSelectOption(option), onMouseEnter: handleSetActiveOnMouseOver(i), onMouseDown: handleCancelBlur, onMouseUp: handleEnableBlur },
|
|
469
|
+
React.createElement("span", { "aria-hidden": true }, option.prefix),
|
|
470
|
+
React.createElement(Text, null, option.label)))),
|
|
471
|
+
React.createElement("div", { ref: visibleChildRef }),
|
|
472
|
+
isLoadingMore && (React.createElement("div", { className: styles.loadingIndicator },
|
|
473
|
+
React.createElement(Spinner, { size: "small", inline: true }))))))));
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
function InternalChipDismissible(props) {
|
|
477
|
+
const { availableChipOptions, ref: wrapperRef, sortedVisibleChipOptions, handleChipAdd, handleChipClick, handleChipKeyDown, handleChipRemove, handleCustomAdd, handleWrapperKeyDown, } = useInternalChipDismissible(props);
|
|
478
|
+
return (React.createElement("div", { ref: wrapperRef, className: styles.wrapper, "data-testid": "dismissible-chips", onKeyDown: handleWrapperKeyDown, role: "listbox" },
|
|
479
|
+
sortedVisibleChipOptions.map(chip => (React.createElement(InternalChip, Object.assign({ key: chip.value }, chip, { onKeyDown: handleChipKeyDown(chip.value), onClick: handleChipClick(chip.value), ariaLabel: `${chip.label}. Press delete or backspace to remove ${chip.label}`, tabIndex: 0, suffix: React.createElement(InternalChipButton, { icon: "remove", invalid: chip.invalid, disabled: chip.disabled, label: chip.label, onClick: handleChipRemove(chip.value) }) })))),
|
|
480
|
+
React.createElement(InternalChipDismissibleInput, { activator: props.activator, attachTo: wrapperRef, isLoadingMore: props.isLoadingMore, options: availableChipOptions, onOptionSelect: handleChipAdd, onCustomOptionSelect: handleCustomAdd, onSearch: props.onSearch, onLoadMore: props.onLoadMore })));
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
function Chips(props) {
|
|
484
|
+
switch (props.type) {
|
|
485
|
+
case "dismissible":
|
|
486
|
+
return React.createElement(InternalChipDismissible, Object.assign({}, props));
|
|
487
|
+
case "multiselect":
|
|
488
|
+
return React.createElement(InternalChipMultiSelect, Object.assign({}, props));
|
|
489
|
+
default:
|
|
490
|
+
return React.createElement(InternalChipSingleSelect, Object.assign({}, props));
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
export { Chips as C, InternalChip as I, InternalChipButton as a };
|