@jobber/components 4.85.4-CJS-to-ESM.0 → 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 +224 -0
- 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 +8 -368
- 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.cjs.js +0 -6721
- package/dist/index.esm.js +0 -6603
- package/rollup.config.js +0 -75
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var tslib_es6 = require('./tslib.es6-754e2961.js');
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var reactHookForm = require('react-hook-form');
|
|
6
|
+
|
|
7
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
+
|
|
9
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
10
|
+
|
|
11
|
+
const Form = React.forwardRef(function InternalForm({ onSubmit, children, onStateChange }, ref) {
|
|
12
|
+
const methods = reactHookForm.useForm({ mode: "onTouched" });
|
|
13
|
+
const { trigger, handleSubmit, formState: { isDirty, isValid, errors }, } = methods;
|
|
14
|
+
React.useEffect(() => onStateChange && onStateChange({ isDirty, isValid }), [isDirty, isValid]);
|
|
15
|
+
React.useImperativeHandle(ref, () => ({
|
|
16
|
+
/**
|
|
17
|
+
* The `trigger()` method can also accept an array
|
|
18
|
+
* of fields to validate. We may at some point want
|
|
19
|
+
* to consider adding a `validate()` method to the
|
|
20
|
+
* `Form` component.
|
|
21
|
+
*/
|
|
22
|
+
submit: () => tslib_es6.__awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
const valid = yield trigger();
|
|
24
|
+
if (valid) {
|
|
25
|
+
submitHandler();
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
trigger();
|
|
29
|
+
errorHandler(errors);
|
|
30
|
+
}
|
|
31
|
+
}),
|
|
32
|
+
}));
|
|
33
|
+
/**
|
|
34
|
+
* If an onSubmit is not passed into a form, it will only be used
|
|
35
|
+
* for validation. For that, we do not need to wrap it in a <form>
|
|
36
|
+
* tag. This allows the <Form> component to be used in legacy code.
|
|
37
|
+
*/
|
|
38
|
+
const Wrapper = onSubmit ? "form" : "div";
|
|
39
|
+
const formProps = {
|
|
40
|
+
onSubmit: onSubmit && handleSubmit(submitHandler, errorHandler),
|
|
41
|
+
};
|
|
42
|
+
return (React__default["default"].createElement(reactHookForm.FormProvider, Object.assign({}, methods),
|
|
43
|
+
React__default["default"].createElement(Wrapper, Object.assign({}, formProps, { "data-testid": "atlantis-form" }), children)));
|
|
44
|
+
function submitHandler() {
|
|
45
|
+
onSubmit && onSubmit();
|
|
46
|
+
}
|
|
47
|
+
function errorHandler(errs) {
|
|
48
|
+
const firstErrName = Object.keys(errs)[0];
|
|
49
|
+
const element = document.querySelector(`[name="${firstErrName}"]`);
|
|
50
|
+
element === null || element === void 0 ? void 0 : element.focus();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
exports.Form = Form;
|
package/dist/Form.cjs
ADDED
package/dist/Form.js
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { _ as __rest } from './tslib.es6-c563c1dd.js';
|
|
2
|
+
import React, { useRef, useState, useEffect, useId, useImperativeHandle } from 'react';
|
|
3
|
+
import { useFormContext, useForm, Controller } from 'react-hook-form';
|
|
4
|
+
import { s as styleInject } from './style-inject.es-a0e1a0ba.js';
|
|
5
|
+
import classnames from 'classnames';
|
|
6
|
+
import { useShowClear } from '@jobber/hooks/useShowClear';
|
|
7
|
+
import { B as Button } from './Button-30154871.js';
|
|
8
|
+
import { I as Icon } from './Icon-22723fe6.js';
|
|
9
|
+
import { T as Text } from './Text-c92ddeb3.js';
|
|
10
|
+
import { I as InputValidation } from './InputValidation-fe42fc3f.js';
|
|
11
|
+
import { S as Spinner } from './Spinner-90081e20.js';
|
|
12
|
+
|
|
13
|
+
var css_248z$1 = ":root {\n /**\n * These `--public-field` properties are used in other components such\n * as InputGroup, therefore they must stay on :root\n **/\n --public-field--top-left-radius: var(--radius-base);\n --public-field--top-right-radius: var(--radius-base);\n --public-field--bottom-left-radius: var(--radius-base);\n --public-field--bottom-right-radius: var(--radius-base);\n\n --field--placeholder-color: var(--color-greyBlue--light);\n --field--value-color: var(--color-heading);\n --field--border-color: var(--color-border);\n}\n\n.geR7qBhrMfk- {\n width: 100%;\n}\n\n/**\n * Wrapper\n **/\n\n.nPGhTEEzsoU- {\n --field--placeholder-offset: 50%;\n --field--placeholder-transform: -50%;\n\n --field--textAlign: left;\n\n --field--height: var(--space-largest);\n\n --field--padding-top: calc(var(--space-base) - var(--space-smallest));\n --field--padding-bottom: calc(var(--space-base) - var(--space-smallest));\n --field--padding-left: var(--space-base);\n --field--padding-right: var(--space-base);\n\n --field--value-lineHeight: calc(var(--base-unit) * 1.25);\n\n --field--background-color: var(--color-surface);\n\n --field--base-elevation: var(--elevation-base);\n --field--label-elevation: calc(var(--field--base-elevation) + 1);\n --field--postfix-elevation: calc(var(--field--base-elevation) - 1);\n --field--postfix-action-elevation: calc(var(--field--base-elevation) + 2);\n\n display: -ms-flexbox;\n\n display: flex;\n width: 100%;\n height: var(--space-largest);\n height: var(--field--height);\n border: var(--border-base) solid var(--color-border);\n border: var(--border-base) solid var(--field--border-color);\n border-radius: var(--radius-base);\n border-top-right-radius: var(--radius-base);\n border-top-right-radius: var(--public-field--top-right-radius);\n border-bottom-right-radius: var(--radius-base);\n border-bottom-right-radius: var(--public-field--bottom-right-radius);\n border-bottom-left-radius: var(--radius-base);\n border-bottom-left-radius: var(--public-field--bottom-left-radius);\n border-top-left-radius: var(--radius-base);\n border-top-left-radius: var(--public-field--top-left-radius);\n color: var(--color-heading);\n color: var(--field--value-color);\n font-size: var(--typography--fontSize-base);\n background-color: var(--color-surface);\n background-color: var(--field--background-color);\n}\n\n.nPGhTEEzsoU- * {\n box-sizing: border-box;\n}\n\n.nPGhTEEzsoU-:focus-within {\n position: relative;\n z-index: var(--field--base-elevation);\n box-shadow: var(--shadow-focus);\n}\n\n.YhserUiOeFE-:not(:focus-within) input {\n color: var(--field--background-color);\n -webkit-text-fill-color: var(--field--background-color);\n}\n\n.YhserUiOeFE-:focus-within,\n.UIZq8hTmJVU- {\n --field--placeholder-color: var(--color-text--secondary);\n --field--placeholder-offset: var(--space-smallest);\n --field--placeholder-transform: 0;\n --field--padding-top: calc(var(--space-base) + var(--space-smaller));\n --field--padding-bottom: var(--space-small);\n}\n\n.YhserUiOeFE-.Ku8sWS0mLew-:focus-within,\n.UIZq8hTmJVU-.Ku8sWS0mLew- {\n --field--padding-top: calc(var(--space-large) + var(--space-smaller));\n}\n\n.nPGhTEEzsoU-.mgPacJ6Z71Y- {\n --field--placeholder-offset: 0;\n --field--placeholder-transform: 0;\n height: auto;\n min-height: auto;\n}\n\n.gJ-15M615eY-,\n.gJ-15M615eY-:focus-within {\n --field--border-color: var(--color-critical);\n position: relative;\n}\n\n._1rsTLm5GwcM- {\n --field--placeholder-color: var(--color-disabled);\n --field--value-color: var(--color-disabled);\n --field--background-color: var(--color-surface--background);\n --field--border-color: var(--color-disabled--secondary);\n}\n\n/* override iOS default styling for disabled input */\n\n._1rsTLm5GwcM- :disabled {\n -webkit-text-fill-color: var(--color-heading);\n -webkit-text-fill-color: var(--field--value-color);\n opacity: 1;\n}\n\n.o8D-H-lKfDk- {\n --field--padding-left: calc(var(--space-base) - var(--space-smaller));\n --field--padding-right: calc(var(--space-base) - var(--space-smaller));\n --field--padding-top: var(--space-small);\n --field--padding-bottom: var(--space-small);\n --field--height: calc(var(--space-larger) + var(--space-smaller));\n}\n\n.Ku8sWS0mLew- {\n --field--padding-left: var(--space-large);\n --field--padding-right: var(--space-large);\n --field--height: calc(var(--space-extravagant));\n}\n\n._5Hu2F3cBvng- {\n display: inline-block;\n width: auto;\n}\n\n.s1WLQs6ffD8- {\n --field--textAlign: center;\n}\n\n.a2r4QheWYIA- {\n --field--textAlign: right;\n}\n\n/**\n * The custom property --formField-maxLength is getting defined inside the\n * component.\n */\n\n.KdAnXK1gClo- {\n width: calc(\n (var(--base-unit) * var(--formField-maxLength)) + var(--field--padding-left) +\n var(--field--padding-right)\n );\n}\n\n/**\n * Input Wrapper\n **/\n\n.iQFhpFYnz-8- {\n display: -ms-flexbox;\n display: flex;\n -ms-flex: 1;\n flex: 1;\n position: relative;\n /* Ensure input stays with the rest of the element stack */\n z-index: var(--elevation-default);\n}\n\n.Yo2Wi9dpa-Y- {\n position: relative;\n -ms-flex: 1;\n flex: 1;\n}\n\n/**\n * Input\n **/\n\n.LSHPV7PwOTg- {\n position: relative;\n z-index: var(--field--base-elevation);\n width: 100%;\n height: 100%;\n padding-top: var(--field--padding-top);\n padding-bottom: var(--field--padding-bottom);\n padding-left: var(--field--padding-left);\n padding-right: var(--field--padding-right);\n border: none;\n border-radius: 0;\n color: inherit;\n font-family: inherit;\n font-size: inherit;\n line-height: var(--field--value-lineHeight);\n text-align: var(--field--textAlign);\n background: transparent;\n -webkit-appearance: none;\n appearance: none;\n}\n\n.LSHPV7PwOTg-:focus {\n outline: none;\n}\n\n.mgPacJ6Z71Y- .LSHPV7PwOTg- {\n resize: vertical;\n}\n\n.i31GQXcMz54- .LSHPV7PwOTg- {\n z-index: var(--field--label-elevation);\n}\n\n.LSHPV7PwOTg-:-webkit-autofill,\n.LSHPV7PwOTg-:-webkit-autofill:hover,\n.LSHPV7PwOTg-:-webkit-autofill:focus,\n.LSHPV7PwOTg-:-webkit-autofill:active {\n -webkit-box-shadow: 0 0 0 30px var(--color-surface) inset !important;\n}\n\n/**\n * Label\n **/\n\n._3xREbTN5pPg- {\n position: absolute;\n top: var(--field--placeholder-offset);\n z-index: var(--field--label-elevation);\n width: 100%;\n padding-left: var(--field--padding-left);\n padding-right: var(--field--padding-right);\n overflow: hidden;\n color: var(--color-greyBlue--light);\n color: var(--field--placeholder-color);\n line-height: var(--field--value-lineHeight);\n text-align: var(--field--textAlign);\n text-overflow: ellipsis;\n white-space: nowrap;\n pointer-events: none;\n -webkit-transform: translateY(var(--field--placeholder-transform));\n transform: translateY(var(--field--placeholder-transform));\n transition: all var(--timing-quick);\n}\n\n.mgPacJ6Z71Y- ._3xREbTN5pPg- {\n /* Changes the width so that the scrollbar on the textarea doesn't get cut off */\n width: calc(100% - var(--field--padding-right));\n padding-top: var(--field--padding-top);\n /* Remove padding on right to make use of the entire width */\n padding-right: 0;\n -webkit-transform: translateY(--field--placeholder-transform);\n transform: translateY(--field--placeholder-transform);\n}\n\n.UIZq8hTmJVU- ._3xREbTN5pPg-,\n.YhserUiOeFE-:focus-within ._3xREbTN5pPg- {\n font-size: var(--typography--fontSize-small);\n}\n\n.mgPacJ6Z71Y-.UIZq8hTmJVU- ._3xREbTN5pPg- {\n padding-top: var(--space-smallest);\n background-color: var(--field--background-color);\n}\n\n.o8D-H-lKfDk-.UIZq8hTmJVU- ._3xREbTN5pPg-,\n.YhserUiOeFE-.o8D-H-lKfDk-.UIZq8hTmJVU-:focus-within ._3xREbTN5pPg- {\n display: none;\n}\n\n/**This is valid cascading order **/\n\n/* stylelint-disable-next-line no-descending-specificity */\n\n.Ku8sWS0mLew-.UIZq8hTmJVU- ._3xREbTN5pPg-,\n.YhserUiOeFE-.Ku8sWS0mLew-.UIZq8hTmJVU-:focus-within ._3xREbTN5pPg- {\n padding-top: var(--space-small);\n}\n\n/**\n * Postfix\n **/\n\n.VtnAk1HYMMk- {\n position: absolute;\n top: 50%;\n right: var(--space-base);\n z-index: var(--field--postfix-elevation);\n -webkit-transform: translateY(-50%);\n transform: translateY(-50%);\n}\n\n/**\n * Affix\n **/\n\n.uPLklxvtfJw- {\n display: -ms-flexbox;\n display: flex;\n -ms-flex-align: center;\n align-items: center;\n -ms-flex-pack: center;\n justify-content: center;\n margin: 0 calc(var(--field--padding-left) * -1) 0 0;\n padding: 0 var(--field--padding-right) 0 var(--field--padding-left);\n}\n\n@supports (aspect-ratio: 1/1) {\n .uPLklxvtfJw- {\n /*\n * disabling property-no-unknown here as this is a real property\n * that stylelint just doesn't know about. We may be able to remove\n * this when we update our stylelint to not care about IE11.\n */\n /* stylelint-disable-next-line property-no-unknown */\n aspect-ratio: 1/1;\n padding: 0;\n }\n}\n\n.uPLklxvtfJw-.pYqqDvv57JE- {\n margin: 0 0 0 calc(var(--field--padding-right) * -1);\n}\n\n.uPLklxvtfJw-.eI44oQpuVlk- {\n position: relative;\n z-index: var(--field--postfix-action-elevation);\n}\n\n.jO8P2iSHilM- {\n display: -ms-flexbox;\n display: flex;\n margin: 0 calc((var(--field--padding-left) - var(--space-smallest)) * -1) 0 0;\n padding: 0 0 0 var(--field--padding-left);\n line-height: var(--field--value-lineHeight);\n -ms-flex-align: center;\n align-items: center;\n -ms-flex: 0 0 auto;\n flex: 0 0 auto;\n}\n\n.jO8P2iSHilM-.pYqqDvv57JE- {\n margin: 0 0 0 calc((var(--field--padding-left) - var(--space-smallest)) * -1);\n padding: 0 var(--field--padding-left) 0 0;\n}\n\n.UIZq8hTmJVU-:not(.o8D-H-lKfDk-) .jO8P2iSHilM- {\n padding-top: var(--field--padding-top);\n padding-bottom: var(--field--padding-bottom);\n}\n\n._2GfgzNnLOSI- {\n margin-top: var(--space-smaller);\n}\n";
|
|
14
|
+
var styles$1 = {"container":"geR7qBhrMfk-","wrapper":"nPGhTEEzsoU-","timeInputLabel":"YhserUiOeFE-","miniLabel":"UIZq8hTmJVU-","large":"Ku8sWS0mLew-","textarea":"mgPacJ6Z71Y-","invalid":"gJ-15M615eY-","disabled":"_1rsTLm5GwcM-","small":"o8D-H-lKfDk-","inline":"_5Hu2F3cBvng-","center":"s1WLQs6ffD8-","right":"a2r4QheWYIA-","maxLength":"KdAnXK1gClo-","inputWrapper":"iQFhpFYnz-8-","childrenWrapper":"Yo2Wi9dpa-Y-","input":"LSHPV7PwOTg-","select":"i31GQXcMz54-","label":"_3xREbTN5pPg-","postfix":"VtnAk1HYMMk-","affixIcon":"uPLklxvtfJw-","suffix":"pYqqDvv57JE-","hasAction":"eI44oQpuVlk-","affixLabel":"jO8P2iSHilM-","description":"_2GfgzNnLOSI-"};
|
|
15
|
+
styleInject(css_248z$1);
|
|
16
|
+
|
|
17
|
+
function AffixLabel({ label, variation = "prefix", labelRef, }) {
|
|
18
|
+
const affixLabelClass = classnames(styles$1.affixLabel, {
|
|
19
|
+
[styles$1.suffix]: variation === "suffix",
|
|
20
|
+
});
|
|
21
|
+
return (React.createElement("div", { ref: labelRef, className: affixLabelClass }, label));
|
|
22
|
+
}
|
|
23
|
+
function AffixIcon({ icon, onClick, ariaLabel, variation = "prefix", size, }) {
|
|
24
|
+
const affixIconClass = classnames(styles$1.affixIcon, {
|
|
25
|
+
[styles$1.suffix]: variation === "suffix",
|
|
26
|
+
[styles$1.hasAction]: onClick,
|
|
27
|
+
});
|
|
28
|
+
const iconSize = size === "small" ? "small" : "base";
|
|
29
|
+
if (!icon)
|
|
30
|
+
return React.createElement(React.Fragment, null);
|
|
31
|
+
return (React.createElement("div", { className: affixIconClass }, onClick ? (React.createElement(Button
|
|
32
|
+
/**
|
|
33
|
+
* We can cast the ariaLabel here as a `Suffix`
|
|
34
|
+
* requires an ariaLabel if there is an action
|
|
35
|
+
*/
|
|
36
|
+
, {
|
|
37
|
+
/**
|
|
38
|
+
* We can cast the ariaLabel here as a `Suffix`
|
|
39
|
+
* requires an ariaLabel if there is an action
|
|
40
|
+
*/
|
|
41
|
+
ariaLabel: ariaLabel, icon: icon, onClick: onClick, variation: "subtle", type: "tertiary", size: iconSize })) : (React.createElement(Icon, { name: icon, size: iconSize, color: "greyBlue" }))));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function FormFieldDescription({ id, description, }) {
|
|
45
|
+
return (React.createElement("div", { id: id, className: styles$1.description },
|
|
46
|
+
React.createElement(Text, { size: "small", variation: "subdued" }, description)));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
var css_248z = "._07kZJ5ltI5E- {\n display: -ms-flexbox;\n display: flex;\n -ms-flex-align: center;\n align-items: center;\n padding-left: var(--space-small);\n}\n\n.t1fFX8kDJh8- {\n display: -ms-flexbox;\n display: flex;\n position: relative;\n right: var(--space-small);\n z-index: var(--elevation-tooltip);\n width: var(--space-large);\n height: var(--space-large);\n padding: 0;\n border: none;\n border-radius: var(--radius-circle);\n background-color: var(--color-surface--background);\n cursor: pointer;\n -ms-flex-pack: center;\n justify-content: center;\n -ms-flex-align: center;\n align-items: center;\n}\n\n.t1fFX8kDJh8-:focus {\n outline: none;\n}\n\n.t1fFX8kDJh8-:hover,\n.t1fFX8kDJh8-:focus-visible {\n outline: none;\n background-color: var(--color-surface--background);\n}\n\n.t1fFX8kDJh8-:focus-visible {\n box-shadow: var(--shadow-focus);\n}\n";
|
|
50
|
+
var styles = {"clearContainer":"_07kZJ5ltI5E-","clearInput":"t1fFX8kDJh8-"};
|
|
51
|
+
styleInject(css_248z);
|
|
52
|
+
|
|
53
|
+
function ClearAction({ onClick }) {
|
|
54
|
+
return (React.createElement("div", { className: styles.clearContainer },
|
|
55
|
+
React.createElement("button", { className: styles.clearInput, onClick: onClick, type: "button", "aria-label": "Clear input" },
|
|
56
|
+
React.createElement(Icon, { name: "remove", size: "small" }))));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function FormFieldWrapper({ align, description, descriptionIdentifier, placeholder, value, children, invalid, error, size, prefix, suffix, max, maxLength, type, disabled, inline, identifier, clearable, onClear, }) {
|
|
60
|
+
const wrapperClasses = classnames(styles$1.wrapper, size && styles$1[size], align && styles$1[align], {
|
|
61
|
+
[styles$1.miniLabel]: (placeholder && value !== "") ||
|
|
62
|
+
(placeholder && type === "select") ||
|
|
63
|
+
// Naively assume that if the the type is tel, it is the InputPhoneNumber
|
|
64
|
+
(placeholder && type === "tel"),
|
|
65
|
+
[styles$1.textarea]: type === "textarea",
|
|
66
|
+
[styles$1.select]: type === "select",
|
|
67
|
+
[styles$1.invalid]: invalid !== null && invalid !== void 0 ? invalid : error,
|
|
68
|
+
[styles$1.disabled]: disabled,
|
|
69
|
+
[styles$1.maxLength]: maxLength,
|
|
70
|
+
[styles$1.timeInputLabel]: placeholder && type === "time" && placeholder && value === "",
|
|
71
|
+
});
|
|
72
|
+
const containerClasses = classnames(styles$1.container, {
|
|
73
|
+
[styles$1.inline]: inline,
|
|
74
|
+
});
|
|
75
|
+
const wrapperInlineStyle = {
|
|
76
|
+
["--formField-maxLength"]: maxLength || max,
|
|
77
|
+
};
|
|
78
|
+
const prefixRef = useRef();
|
|
79
|
+
const suffixRef = useRef();
|
|
80
|
+
const [labelStyle, setLabelStyle] = useState({
|
|
81
|
+
paddingLeft: undefined,
|
|
82
|
+
paddingRight: undefined,
|
|
83
|
+
});
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
setLabelStyle(getAffixPaddding);
|
|
86
|
+
}, [value]);
|
|
87
|
+
const [focused, setFocused] = useState(false);
|
|
88
|
+
const showClear = useShowClear({
|
|
89
|
+
clearable,
|
|
90
|
+
multiline: type === "textarea",
|
|
91
|
+
focused,
|
|
92
|
+
hasValue: Boolean(value),
|
|
93
|
+
disabled,
|
|
94
|
+
});
|
|
95
|
+
return (React.createElement("div", { className: containerClasses, onFocus: () => setFocused(true), onBlur: () => setFocused(false) },
|
|
96
|
+
React.createElement("div", { className: wrapperClasses, style: wrapperInlineStyle, "data-testid": "Form-Field-Wrapper" },
|
|
97
|
+
(prefix === null || prefix === void 0 ? void 0 : prefix.icon) && React.createElement(AffixIcon, Object.assign({}, prefix, { size: size })),
|
|
98
|
+
React.createElement("div", { className: styles$1.inputWrapper },
|
|
99
|
+
placeholder && (React.createElement("label", { className: styles$1.label, htmlFor: identifier, style: (prefixRef === null || prefixRef === void 0 ? void 0 : prefixRef.current) || (suffixRef === null || suffixRef === void 0 ? void 0 : suffixRef.current)
|
|
100
|
+
? labelStyle
|
|
101
|
+
: undefined }, placeholder)),
|
|
102
|
+
(prefix === null || prefix === void 0 ? void 0 : prefix.label) && React.createElement(AffixLabel, Object.assign({}, prefix, { labelRef: prefixRef })),
|
|
103
|
+
React.createElement("div", { className: styles$1.childrenWrapper }, children),
|
|
104
|
+
(suffix === null || suffix === void 0 ? void 0 : suffix.label) && (React.createElement(AffixLabel, Object.assign({}, suffix, { labelRef: suffixRef, variation: "suffix" })))),
|
|
105
|
+
showClear && React.createElement(ClearAction, { onClick: onClear }),
|
|
106
|
+
(suffix === null || suffix === void 0 ? void 0 : suffix.icon) && (React.createElement(AffixIcon, Object.assign({}, suffix, { variation: "suffix", size: size })))),
|
|
107
|
+
description && !inline && (React.createElement(FormFieldDescription, { id: descriptionIdentifier, description: description })),
|
|
108
|
+
error && !inline && React.createElement(InputValidation, { message: error })));
|
|
109
|
+
function getAffixPaddding() {
|
|
110
|
+
const hasValue = value !== "";
|
|
111
|
+
const newPadding = {
|
|
112
|
+
paddingLeft: undefined,
|
|
113
|
+
paddingRight: undefined,
|
|
114
|
+
};
|
|
115
|
+
// Naively assume that if the the type is tel, it is the InputPhoneNumber
|
|
116
|
+
if (type === "tel")
|
|
117
|
+
return newPadding;
|
|
118
|
+
if ((prefixRef === null || prefixRef === void 0 ? void 0 : prefixRef.current) && !hasValue) {
|
|
119
|
+
const { offsetWidth } = prefixRef.current;
|
|
120
|
+
newPadding.paddingLeft = offset(offsetWidth);
|
|
121
|
+
}
|
|
122
|
+
if ((suffixRef === null || suffixRef === void 0 ? void 0 : suffixRef.current) && !hasValue) {
|
|
123
|
+
const { offsetWidth } = suffixRef.current;
|
|
124
|
+
newPadding.paddingRight = offset(offsetWidth);
|
|
125
|
+
}
|
|
126
|
+
function offset(width) {
|
|
127
|
+
return `calc(${width}px + var(--space-smallest)`;
|
|
128
|
+
}
|
|
129
|
+
return newPadding;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function FormFieldPostFix({ variation }) {
|
|
134
|
+
return (React.createElement("span", { className: styles$1.postfix }, variation === "select" ? (React.createElement(Icon, { name: "arrowDown" })) : (React.createElement(Spinner, { size: "small" }))));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Added 13th statement to accommodate getErrorMessage function
|
|
138
|
+
/*eslint max-statements: ["error", 13]*/
|
|
139
|
+
function FormField(props) {
|
|
140
|
+
var _a, _b;
|
|
141
|
+
const { actionsRef, autocomplete = true, children, defaultValue, description, disabled, inputRef, inline, keyboard, max, maxLength, min, name, readonly, rows, loading, type = "text", validations, value, onChange, onEnter, onFocus, onBlur, onValidation, onKeyUp, clearable = "never", } = props;
|
|
142
|
+
const { control, formState: { errors }, setValue, watch, } = useFormContext() != undefined
|
|
143
|
+
? useFormContext()
|
|
144
|
+
: // If there isn't a Form Context being provided, get a form for this field.
|
|
145
|
+
useForm({ mode: "onTouched" });
|
|
146
|
+
const [identifier] = useState(useId());
|
|
147
|
+
const [descriptionIdentifier] = useState(`descriptionUUID--${useId()}`);
|
|
148
|
+
/**
|
|
149
|
+
* Generate a name if one is not supplied, this is the name
|
|
150
|
+
* that will be used for react-hook-form and not neccessarily
|
|
151
|
+
* attached to the DOM
|
|
152
|
+
*/
|
|
153
|
+
const [controlledName] = useState(name ? name : `generatedName--${identifier}`);
|
|
154
|
+
useEffect(() => {
|
|
155
|
+
if (value != undefined) {
|
|
156
|
+
setValue(controlledName, value);
|
|
157
|
+
}
|
|
158
|
+
}, [value, watch(controlledName)]);
|
|
159
|
+
useImperativeHandle(actionsRef, () => ({
|
|
160
|
+
setValue: newValue => {
|
|
161
|
+
setValue(controlledName, newValue, { shouldValidate: true });
|
|
162
|
+
},
|
|
163
|
+
}));
|
|
164
|
+
const message = (_a = errors[controlledName]) === null || _a === void 0 ? void 0 : _a.message;
|
|
165
|
+
const error = getErrorMessage();
|
|
166
|
+
useEffect(() => handleValidation(), [error]);
|
|
167
|
+
return (React.createElement(Controller, { control: control, name: controlledName, rules: Object.assign({}, validations), defaultValue: (_b = value !== null && value !== void 0 ? value : defaultValue) !== null && _b !== void 0 ? _b : "", render: (_a) => {
|
|
168
|
+
var _b = _a.field, { onChange: onControllerChange, onBlur: onControllerBlur, name: controllerName } = _b, rest = __rest(_b, ["onChange", "onBlur", "name"]);
|
|
169
|
+
const fieldProps = Object.assign(Object.assign(Object.assign({}, rest), { id: identifier, className: styles$1.input, name: (validations || name) && controllerName, disabled: disabled, readOnly: readonly, inputMode: keyboard, onChange: handleChange, onBlur: handleBlur, onFocus: handleFocus }), (description &&
|
|
170
|
+
!inline && { "aria-describedby": descriptionIdentifier }));
|
|
171
|
+
const textFieldProps = Object.assign(Object.assign({}, fieldProps), { onKeyDown: handleKeyDown });
|
|
172
|
+
return (React.createElement(FormFieldWrapper, Object.assign({}, props, { value: rest.value, error: error, identifier: identifier, descriptionIdentifier: descriptionIdentifier, clearable: clearable, onClear: handleClear }), renderField()));
|
|
173
|
+
function renderField() {
|
|
174
|
+
switch (type) {
|
|
175
|
+
case "select":
|
|
176
|
+
return (React.createElement(React.Fragment, null,
|
|
177
|
+
React.createElement("select", Object.assign({}, fieldProps), children),
|
|
178
|
+
React.createElement(FormFieldPostFix, { variation: "select" })));
|
|
179
|
+
case "textarea":
|
|
180
|
+
return (React.createElement("textarea", Object.assign({}, textFieldProps, { rows: rows, ref: inputRef })));
|
|
181
|
+
default:
|
|
182
|
+
return (React.createElement(React.Fragment, null,
|
|
183
|
+
React.createElement("input", Object.assign({}, textFieldProps, { autoComplete: setAutocomplete(autocomplete), type: type, maxLength: maxLength, max: max, min: min, ref: inputRef, onKeyUp: onKeyUp })),
|
|
184
|
+
loading && React.createElement(FormFieldPostFix, { variation: "spinner" }),
|
|
185
|
+
children));
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
function handleClear() {
|
|
189
|
+
var _a;
|
|
190
|
+
handleBlur();
|
|
191
|
+
setValue(controlledName, undefined, { shouldValidate: true });
|
|
192
|
+
onChange && onChange("");
|
|
193
|
+
(_a = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
194
|
+
}
|
|
195
|
+
function handleChange(event) {
|
|
196
|
+
let newValue;
|
|
197
|
+
newValue = event.currentTarget.value;
|
|
198
|
+
if (type === "number" && newValue.length > 0) {
|
|
199
|
+
newValue = parseFloat(newValue);
|
|
200
|
+
}
|
|
201
|
+
onChange && onChange(newValue, event);
|
|
202
|
+
onControllerChange(event);
|
|
203
|
+
}
|
|
204
|
+
function handleKeyDown(event) {
|
|
205
|
+
if (!onEnter)
|
|
206
|
+
return;
|
|
207
|
+
if (event.key !== "Enter")
|
|
208
|
+
return;
|
|
209
|
+
if (event.shiftKey || event.ctrlKey)
|
|
210
|
+
return;
|
|
211
|
+
event.preventDefault();
|
|
212
|
+
onEnter && onEnter(event);
|
|
213
|
+
}
|
|
214
|
+
function handleFocus(event) {
|
|
215
|
+
const target = event.currentTarget;
|
|
216
|
+
if (target.select) {
|
|
217
|
+
setTimeout(() => readonly && target.select());
|
|
218
|
+
}
|
|
219
|
+
onFocus && onFocus();
|
|
220
|
+
}
|
|
221
|
+
function handleBlur() {
|
|
222
|
+
onBlur && onBlur();
|
|
223
|
+
onControllerBlur();
|
|
224
|
+
}
|
|
225
|
+
} }));
|
|
226
|
+
function getErrorMessage() {
|
|
227
|
+
if (typeof message === "string") {
|
|
228
|
+
return message;
|
|
229
|
+
}
|
|
230
|
+
return "";
|
|
231
|
+
}
|
|
232
|
+
function handleValidation() {
|
|
233
|
+
onValidation && onValidation(error);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
function setAutocomplete(autocompleteSetting) {
|
|
237
|
+
if (autocompleteSetting === true) {
|
|
238
|
+
return undefined;
|
|
239
|
+
}
|
|
240
|
+
else if (autocompleteSetting === false) {
|
|
241
|
+
return "off";
|
|
242
|
+
}
|
|
243
|
+
return autocompleteSetting;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export { FormField as F };
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var tslib_es6 = require('./tslib.es6-754e2961.js');
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var reactHookForm = require('react-hook-form');
|
|
6
|
+
var styleInject_es = require('./style-inject.es-9d2f5f4e.js');
|
|
7
|
+
var classnames = require('classnames');
|
|
8
|
+
var useShowClear = require('@jobber/hooks/useShowClear');
|
|
9
|
+
var Button = require('./Button-ec64869e.js');
|
|
10
|
+
var Icon = require('./Icon-405a216c.js');
|
|
11
|
+
var Text = require('./Text-714f7d14.js');
|
|
12
|
+
var InputValidation = require('./InputValidation-4a61254d.js');
|
|
13
|
+
var Spinner = require('./Spinner-3480bc34.js');
|
|
14
|
+
|
|
15
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
16
|
+
|
|
17
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
18
|
+
var classnames__default = /*#__PURE__*/_interopDefaultLegacy(classnames);
|
|
19
|
+
|
|
20
|
+
var css_248z$1 = ":root {\n /**\n * These `--public-field` properties are used in other components such\n * as InputGroup, therefore they must stay on :root\n **/\n --public-field--top-left-radius: var(--radius-base);\n --public-field--top-right-radius: var(--radius-base);\n --public-field--bottom-left-radius: var(--radius-base);\n --public-field--bottom-right-radius: var(--radius-base);\n\n --field--placeholder-color: var(--color-greyBlue--light);\n --field--value-color: var(--color-heading);\n --field--border-color: var(--color-border);\n}\n\n.geR7qBhrMfk- {\n width: 100%;\n}\n\n/**\n * Wrapper\n **/\n\n.nPGhTEEzsoU- {\n --field--placeholder-offset: 50%;\n --field--placeholder-transform: -50%;\n\n --field--textAlign: left;\n\n --field--height: var(--space-largest);\n\n --field--padding-top: calc(var(--space-base) - var(--space-smallest));\n --field--padding-bottom: calc(var(--space-base) - var(--space-smallest));\n --field--padding-left: var(--space-base);\n --field--padding-right: var(--space-base);\n\n --field--value-lineHeight: calc(var(--base-unit) * 1.25);\n\n --field--background-color: var(--color-surface);\n\n --field--base-elevation: var(--elevation-base);\n --field--label-elevation: calc(var(--field--base-elevation) + 1);\n --field--postfix-elevation: calc(var(--field--base-elevation) - 1);\n --field--postfix-action-elevation: calc(var(--field--base-elevation) + 2);\n\n display: -ms-flexbox;\n\n display: flex;\n width: 100%;\n height: var(--space-largest);\n height: var(--field--height);\n border: var(--border-base) solid var(--color-border);\n border: var(--border-base) solid var(--field--border-color);\n border-radius: var(--radius-base);\n border-top-right-radius: var(--radius-base);\n border-top-right-radius: var(--public-field--top-right-radius);\n border-bottom-right-radius: var(--radius-base);\n border-bottom-right-radius: var(--public-field--bottom-right-radius);\n border-bottom-left-radius: var(--radius-base);\n border-bottom-left-radius: var(--public-field--bottom-left-radius);\n border-top-left-radius: var(--radius-base);\n border-top-left-radius: var(--public-field--top-left-radius);\n color: var(--color-heading);\n color: var(--field--value-color);\n font-size: var(--typography--fontSize-base);\n background-color: var(--color-surface);\n background-color: var(--field--background-color);\n}\n\n.nPGhTEEzsoU- * {\n box-sizing: border-box;\n}\n\n.nPGhTEEzsoU-:focus-within {\n position: relative;\n z-index: var(--field--base-elevation);\n box-shadow: var(--shadow-focus);\n}\n\n.YhserUiOeFE-:not(:focus-within) input {\n color: var(--field--background-color);\n -webkit-text-fill-color: var(--field--background-color);\n}\n\n.YhserUiOeFE-:focus-within,\n.UIZq8hTmJVU- {\n --field--placeholder-color: var(--color-text--secondary);\n --field--placeholder-offset: var(--space-smallest);\n --field--placeholder-transform: 0;\n --field--padding-top: calc(var(--space-base) + var(--space-smaller));\n --field--padding-bottom: var(--space-small);\n}\n\n.YhserUiOeFE-.Ku8sWS0mLew-:focus-within,\n.UIZq8hTmJVU-.Ku8sWS0mLew- {\n --field--padding-top: calc(var(--space-large) + var(--space-smaller));\n}\n\n.nPGhTEEzsoU-.mgPacJ6Z71Y- {\n --field--placeholder-offset: 0;\n --field--placeholder-transform: 0;\n height: auto;\n min-height: auto;\n}\n\n.gJ-15M615eY-,\n.gJ-15M615eY-:focus-within {\n --field--border-color: var(--color-critical);\n position: relative;\n}\n\n._1rsTLm5GwcM- {\n --field--placeholder-color: var(--color-disabled);\n --field--value-color: var(--color-disabled);\n --field--background-color: var(--color-surface--background);\n --field--border-color: var(--color-disabled--secondary);\n}\n\n/* override iOS default styling for disabled input */\n\n._1rsTLm5GwcM- :disabled {\n -webkit-text-fill-color: var(--color-heading);\n -webkit-text-fill-color: var(--field--value-color);\n opacity: 1;\n}\n\n.o8D-H-lKfDk- {\n --field--padding-left: calc(var(--space-base) - var(--space-smaller));\n --field--padding-right: calc(var(--space-base) - var(--space-smaller));\n --field--padding-top: var(--space-small);\n --field--padding-bottom: var(--space-small);\n --field--height: calc(var(--space-larger) + var(--space-smaller));\n}\n\n.Ku8sWS0mLew- {\n --field--padding-left: var(--space-large);\n --field--padding-right: var(--space-large);\n --field--height: calc(var(--space-extravagant));\n}\n\n._5Hu2F3cBvng- {\n display: inline-block;\n width: auto;\n}\n\n.s1WLQs6ffD8- {\n --field--textAlign: center;\n}\n\n.a2r4QheWYIA- {\n --field--textAlign: right;\n}\n\n/**\n * The custom property --formField-maxLength is getting defined inside the\n * component.\n */\n\n.KdAnXK1gClo- {\n width: calc(\n (var(--base-unit) * var(--formField-maxLength)) + var(--field--padding-left) +\n var(--field--padding-right)\n );\n}\n\n/**\n * Input Wrapper\n **/\n\n.iQFhpFYnz-8- {\n display: -ms-flexbox;\n display: flex;\n -ms-flex: 1;\n flex: 1;\n position: relative;\n /* Ensure input stays with the rest of the element stack */\n z-index: var(--elevation-default);\n}\n\n.Yo2Wi9dpa-Y- {\n position: relative;\n -ms-flex: 1;\n flex: 1;\n}\n\n/**\n * Input\n **/\n\n.LSHPV7PwOTg- {\n position: relative;\n z-index: var(--field--base-elevation);\n width: 100%;\n height: 100%;\n padding-top: var(--field--padding-top);\n padding-bottom: var(--field--padding-bottom);\n padding-left: var(--field--padding-left);\n padding-right: var(--field--padding-right);\n border: none;\n border-radius: 0;\n color: inherit;\n font-family: inherit;\n font-size: inherit;\n line-height: var(--field--value-lineHeight);\n text-align: var(--field--textAlign);\n background: transparent;\n -webkit-appearance: none;\n appearance: none;\n}\n\n.LSHPV7PwOTg-:focus {\n outline: none;\n}\n\n.mgPacJ6Z71Y- .LSHPV7PwOTg- {\n resize: vertical;\n}\n\n.i31GQXcMz54- .LSHPV7PwOTg- {\n z-index: var(--field--label-elevation);\n}\n\n.LSHPV7PwOTg-:-webkit-autofill,\n.LSHPV7PwOTg-:-webkit-autofill:hover,\n.LSHPV7PwOTg-:-webkit-autofill:focus,\n.LSHPV7PwOTg-:-webkit-autofill:active {\n -webkit-box-shadow: 0 0 0 30px var(--color-surface) inset !important;\n}\n\n/**\n * Label\n **/\n\n._3xREbTN5pPg- {\n position: absolute;\n top: var(--field--placeholder-offset);\n z-index: var(--field--label-elevation);\n width: 100%;\n padding-left: var(--field--padding-left);\n padding-right: var(--field--padding-right);\n overflow: hidden;\n color: var(--color-greyBlue--light);\n color: var(--field--placeholder-color);\n line-height: var(--field--value-lineHeight);\n text-align: var(--field--textAlign);\n text-overflow: ellipsis;\n white-space: nowrap;\n pointer-events: none;\n -webkit-transform: translateY(var(--field--placeholder-transform));\n transform: translateY(var(--field--placeholder-transform));\n transition: all var(--timing-quick);\n}\n\n.mgPacJ6Z71Y- ._3xREbTN5pPg- {\n /* Changes the width so that the scrollbar on the textarea doesn't get cut off */\n width: calc(100% - var(--field--padding-right));\n padding-top: var(--field--padding-top);\n /* Remove padding on right to make use of the entire width */\n padding-right: 0;\n -webkit-transform: translateY(--field--placeholder-transform);\n transform: translateY(--field--placeholder-transform);\n}\n\n.UIZq8hTmJVU- ._3xREbTN5pPg-,\n.YhserUiOeFE-:focus-within ._3xREbTN5pPg- {\n font-size: var(--typography--fontSize-small);\n}\n\n.mgPacJ6Z71Y-.UIZq8hTmJVU- ._3xREbTN5pPg- {\n padding-top: var(--space-smallest);\n background-color: var(--field--background-color);\n}\n\n.o8D-H-lKfDk-.UIZq8hTmJVU- ._3xREbTN5pPg-,\n.YhserUiOeFE-.o8D-H-lKfDk-.UIZq8hTmJVU-:focus-within ._3xREbTN5pPg- {\n display: none;\n}\n\n/**This is valid cascading order **/\n\n/* stylelint-disable-next-line no-descending-specificity */\n\n.Ku8sWS0mLew-.UIZq8hTmJVU- ._3xREbTN5pPg-,\n.YhserUiOeFE-.Ku8sWS0mLew-.UIZq8hTmJVU-:focus-within ._3xREbTN5pPg- {\n padding-top: var(--space-small);\n}\n\n/**\n * Postfix\n **/\n\n.VtnAk1HYMMk- {\n position: absolute;\n top: 50%;\n right: var(--space-base);\n z-index: var(--field--postfix-elevation);\n -webkit-transform: translateY(-50%);\n transform: translateY(-50%);\n}\n\n/**\n * Affix\n **/\n\n.uPLklxvtfJw- {\n display: -ms-flexbox;\n display: flex;\n -ms-flex-align: center;\n align-items: center;\n -ms-flex-pack: center;\n justify-content: center;\n margin: 0 calc(var(--field--padding-left) * -1) 0 0;\n padding: 0 var(--field--padding-right) 0 var(--field--padding-left);\n}\n\n@supports (aspect-ratio: 1/1) {\n .uPLklxvtfJw- {\n /*\n * disabling property-no-unknown here as this is a real property\n * that stylelint just doesn't know about. We may be able to remove\n * this when we update our stylelint to not care about IE11.\n */\n /* stylelint-disable-next-line property-no-unknown */\n aspect-ratio: 1/1;\n padding: 0;\n }\n}\n\n.uPLklxvtfJw-.pYqqDvv57JE- {\n margin: 0 0 0 calc(var(--field--padding-right) * -1);\n}\n\n.uPLklxvtfJw-.eI44oQpuVlk- {\n position: relative;\n z-index: var(--field--postfix-action-elevation);\n}\n\n.jO8P2iSHilM- {\n display: -ms-flexbox;\n display: flex;\n margin: 0 calc((var(--field--padding-left) - var(--space-smallest)) * -1) 0 0;\n padding: 0 0 0 var(--field--padding-left);\n line-height: var(--field--value-lineHeight);\n -ms-flex-align: center;\n align-items: center;\n -ms-flex: 0 0 auto;\n flex: 0 0 auto;\n}\n\n.jO8P2iSHilM-.pYqqDvv57JE- {\n margin: 0 0 0 calc((var(--field--padding-left) - var(--space-smallest)) * -1);\n padding: 0 var(--field--padding-left) 0 0;\n}\n\n.UIZq8hTmJVU-:not(.o8D-H-lKfDk-) .jO8P2iSHilM- {\n padding-top: var(--field--padding-top);\n padding-bottom: var(--field--padding-bottom);\n}\n\n._2GfgzNnLOSI- {\n margin-top: var(--space-smaller);\n}\n";
|
|
21
|
+
var styles$1 = {"container":"geR7qBhrMfk-","wrapper":"nPGhTEEzsoU-","timeInputLabel":"YhserUiOeFE-","miniLabel":"UIZq8hTmJVU-","large":"Ku8sWS0mLew-","textarea":"mgPacJ6Z71Y-","invalid":"gJ-15M615eY-","disabled":"_1rsTLm5GwcM-","small":"o8D-H-lKfDk-","inline":"_5Hu2F3cBvng-","center":"s1WLQs6ffD8-","right":"a2r4QheWYIA-","maxLength":"KdAnXK1gClo-","inputWrapper":"iQFhpFYnz-8-","childrenWrapper":"Yo2Wi9dpa-Y-","input":"LSHPV7PwOTg-","select":"i31GQXcMz54-","label":"_3xREbTN5pPg-","postfix":"VtnAk1HYMMk-","affixIcon":"uPLklxvtfJw-","suffix":"pYqqDvv57JE-","hasAction":"eI44oQpuVlk-","affixLabel":"jO8P2iSHilM-","description":"_2GfgzNnLOSI-"};
|
|
22
|
+
styleInject_es.styleInject(css_248z$1);
|
|
23
|
+
|
|
24
|
+
function AffixLabel({ label, variation = "prefix", labelRef, }) {
|
|
25
|
+
const affixLabelClass = classnames__default["default"](styles$1.affixLabel, {
|
|
26
|
+
[styles$1.suffix]: variation === "suffix",
|
|
27
|
+
});
|
|
28
|
+
return (React__default["default"].createElement("div", { ref: labelRef, className: affixLabelClass }, label));
|
|
29
|
+
}
|
|
30
|
+
function AffixIcon({ icon, onClick, ariaLabel, variation = "prefix", size, }) {
|
|
31
|
+
const affixIconClass = classnames__default["default"](styles$1.affixIcon, {
|
|
32
|
+
[styles$1.suffix]: variation === "suffix",
|
|
33
|
+
[styles$1.hasAction]: onClick,
|
|
34
|
+
});
|
|
35
|
+
const iconSize = size === "small" ? "small" : "base";
|
|
36
|
+
if (!icon)
|
|
37
|
+
return React__default["default"].createElement(React__default["default"].Fragment, null);
|
|
38
|
+
return (React__default["default"].createElement("div", { className: affixIconClass }, onClick ? (React__default["default"].createElement(Button.Button
|
|
39
|
+
/**
|
|
40
|
+
* We can cast the ariaLabel here as a `Suffix`
|
|
41
|
+
* requires an ariaLabel if there is an action
|
|
42
|
+
*/
|
|
43
|
+
, {
|
|
44
|
+
/**
|
|
45
|
+
* We can cast the ariaLabel here as a `Suffix`
|
|
46
|
+
* requires an ariaLabel if there is an action
|
|
47
|
+
*/
|
|
48
|
+
ariaLabel: ariaLabel, icon: icon, onClick: onClick, variation: "subtle", type: "tertiary", size: iconSize })) : (React__default["default"].createElement(Icon.Icon, { name: icon, size: iconSize, color: "greyBlue" }))));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function FormFieldDescription({ id, description, }) {
|
|
52
|
+
return (React__default["default"].createElement("div", { id: id, className: styles$1.description },
|
|
53
|
+
React__default["default"].createElement(Text.Text, { size: "small", variation: "subdued" }, description)));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
var css_248z = "._07kZJ5ltI5E- {\n display: -ms-flexbox;\n display: flex;\n -ms-flex-align: center;\n align-items: center;\n padding-left: var(--space-small);\n}\n\n.t1fFX8kDJh8- {\n display: -ms-flexbox;\n display: flex;\n position: relative;\n right: var(--space-small);\n z-index: var(--elevation-tooltip);\n width: var(--space-large);\n height: var(--space-large);\n padding: 0;\n border: none;\n border-radius: var(--radius-circle);\n background-color: var(--color-surface--background);\n cursor: pointer;\n -ms-flex-pack: center;\n justify-content: center;\n -ms-flex-align: center;\n align-items: center;\n}\n\n.t1fFX8kDJh8-:focus {\n outline: none;\n}\n\n.t1fFX8kDJh8-:hover,\n.t1fFX8kDJh8-:focus-visible {\n outline: none;\n background-color: var(--color-surface--background);\n}\n\n.t1fFX8kDJh8-:focus-visible {\n box-shadow: var(--shadow-focus);\n}\n";
|
|
57
|
+
var styles = {"clearContainer":"_07kZJ5ltI5E-","clearInput":"t1fFX8kDJh8-"};
|
|
58
|
+
styleInject_es.styleInject(css_248z);
|
|
59
|
+
|
|
60
|
+
function ClearAction({ onClick }) {
|
|
61
|
+
return (React__default["default"].createElement("div", { className: styles.clearContainer },
|
|
62
|
+
React__default["default"].createElement("button", { className: styles.clearInput, onClick: onClick, type: "button", "aria-label": "Clear input" },
|
|
63
|
+
React__default["default"].createElement(Icon.Icon, { name: "remove", size: "small" }))));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function FormFieldWrapper({ align, description, descriptionIdentifier, placeholder, value, children, invalid, error, size, prefix, suffix, max, maxLength, type, disabled, inline, identifier, clearable, onClear, }) {
|
|
67
|
+
const wrapperClasses = classnames__default["default"](styles$1.wrapper, size && styles$1[size], align && styles$1[align], {
|
|
68
|
+
[styles$1.miniLabel]: (placeholder && value !== "") ||
|
|
69
|
+
(placeholder && type === "select") ||
|
|
70
|
+
// Naively assume that if the the type is tel, it is the InputPhoneNumber
|
|
71
|
+
(placeholder && type === "tel"),
|
|
72
|
+
[styles$1.textarea]: type === "textarea",
|
|
73
|
+
[styles$1.select]: type === "select",
|
|
74
|
+
[styles$1.invalid]: invalid !== null && invalid !== void 0 ? invalid : error,
|
|
75
|
+
[styles$1.disabled]: disabled,
|
|
76
|
+
[styles$1.maxLength]: maxLength,
|
|
77
|
+
[styles$1.timeInputLabel]: placeholder && type === "time" && placeholder && value === "",
|
|
78
|
+
});
|
|
79
|
+
const containerClasses = classnames__default["default"](styles$1.container, {
|
|
80
|
+
[styles$1.inline]: inline,
|
|
81
|
+
});
|
|
82
|
+
const wrapperInlineStyle = {
|
|
83
|
+
["--formField-maxLength"]: maxLength || max,
|
|
84
|
+
};
|
|
85
|
+
const prefixRef = React.useRef();
|
|
86
|
+
const suffixRef = React.useRef();
|
|
87
|
+
const [labelStyle, setLabelStyle] = React.useState({
|
|
88
|
+
paddingLeft: undefined,
|
|
89
|
+
paddingRight: undefined,
|
|
90
|
+
});
|
|
91
|
+
React.useEffect(() => {
|
|
92
|
+
setLabelStyle(getAffixPaddding);
|
|
93
|
+
}, [value]);
|
|
94
|
+
const [focused, setFocused] = React.useState(false);
|
|
95
|
+
const showClear = useShowClear.useShowClear({
|
|
96
|
+
clearable,
|
|
97
|
+
multiline: type === "textarea",
|
|
98
|
+
focused,
|
|
99
|
+
hasValue: Boolean(value),
|
|
100
|
+
disabled,
|
|
101
|
+
});
|
|
102
|
+
return (React__default["default"].createElement("div", { className: containerClasses, onFocus: () => setFocused(true), onBlur: () => setFocused(false) },
|
|
103
|
+
React__default["default"].createElement("div", { className: wrapperClasses, style: wrapperInlineStyle, "data-testid": "Form-Field-Wrapper" },
|
|
104
|
+
(prefix === null || prefix === void 0 ? void 0 : prefix.icon) && React__default["default"].createElement(AffixIcon, Object.assign({}, prefix, { size: size })),
|
|
105
|
+
React__default["default"].createElement("div", { className: styles$1.inputWrapper },
|
|
106
|
+
placeholder && (React__default["default"].createElement("label", { className: styles$1.label, htmlFor: identifier, style: (prefixRef === null || prefixRef === void 0 ? void 0 : prefixRef.current) || (suffixRef === null || suffixRef === void 0 ? void 0 : suffixRef.current)
|
|
107
|
+
? labelStyle
|
|
108
|
+
: undefined }, placeholder)),
|
|
109
|
+
(prefix === null || prefix === void 0 ? void 0 : prefix.label) && React__default["default"].createElement(AffixLabel, Object.assign({}, prefix, { labelRef: prefixRef })),
|
|
110
|
+
React__default["default"].createElement("div", { className: styles$1.childrenWrapper }, children),
|
|
111
|
+
(suffix === null || suffix === void 0 ? void 0 : suffix.label) && (React__default["default"].createElement(AffixLabel, Object.assign({}, suffix, { labelRef: suffixRef, variation: "suffix" })))),
|
|
112
|
+
showClear && React__default["default"].createElement(ClearAction, { onClick: onClear }),
|
|
113
|
+
(suffix === null || suffix === void 0 ? void 0 : suffix.icon) && (React__default["default"].createElement(AffixIcon, Object.assign({}, suffix, { variation: "suffix", size: size })))),
|
|
114
|
+
description && !inline && (React__default["default"].createElement(FormFieldDescription, { id: descriptionIdentifier, description: description })),
|
|
115
|
+
error && !inline && React__default["default"].createElement(InputValidation.InputValidation, { message: error })));
|
|
116
|
+
function getAffixPaddding() {
|
|
117
|
+
const hasValue = value !== "";
|
|
118
|
+
const newPadding = {
|
|
119
|
+
paddingLeft: undefined,
|
|
120
|
+
paddingRight: undefined,
|
|
121
|
+
};
|
|
122
|
+
// Naively assume that if the the type is tel, it is the InputPhoneNumber
|
|
123
|
+
if (type === "tel")
|
|
124
|
+
return newPadding;
|
|
125
|
+
if ((prefixRef === null || prefixRef === void 0 ? void 0 : prefixRef.current) && !hasValue) {
|
|
126
|
+
const { offsetWidth } = prefixRef.current;
|
|
127
|
+
newPadding.paddingLeft = offset(offsetWidth);
|
|
128
|
+
}
|
|
129
|
+
if ((suffixRef === null || suffixRef === void 0 ? void 0 : suffixRef.current) && !hasValue) {
|
|
130
|
+
const { offsetWidth } = suffixRef.current;
|
|
131
|
+
newPadding.paddingRight = offset(offsetWidth);
|
|
132
|
+
}
|
|
133
|
+
function offset(width) {
|
|
134
|
+
return `calc(${width}px + var(--space-smallest)`;
|
|
135
|
+
}
|
|
136
|
+
return newPadding;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function FormFieldPostFix({ variation }) {
|
|
141
|
+
return (React__default["default"].createElement("span", { className: styles$1.postfix }, variation === "select" ? (React__default["default"].createElement(Icon.Icon, { name: "arrowDown" })) : (React__default["default"].createElement(Spinner.Spinner, { size: "small" }))));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Added 13th statement to accommodate getErrorMessage function
|
|
145
|
+
/*eslint max-statements: ["error", 13]*/
|
|
146
|
+
function FormField(props) {
|
|
147
|
+
var _a, _b;
|
|
148
|
+
const { actionsRef, autocomplete = true, children, defaultValue, description, disabled, inputRef, inline, keyboard, max, maxLength, min, name, readonly, rows, loading, type = "text", validations, value, onChange, onEnter, onFocus, onBlur, onValidation, onKeyUp, clearable = "never", } = props;
|
|
149
|
+
const { control, formState: { errors }, setValue, watch, } = reactHookForm.useFormContext() != undefined
|
|
150
|
+
? reactHookForm.useFormContext()
|
|
151
|
+
: // If there isn't a Form Context being provided, get a form for this field.
|
|
152
|
+
reactHookForm.useForm({ mode: "onTouched" });
|
|
153
|
+
const [identifier] = React.useState(React.useId());
|
|
154
|
+
const [descriptionIdentifier] = React.useState(`descriptionUUID--${React.useId()}`);
|
|
155
|
+
/**
|
|
156
|
+
* Generate a name if one is not supplied, this is the name
|
|
157
|
+
* that will be used for react-hook-form and not neccessarily
|
|
158
|
+
* attached to the DOM
|
|
159
|
+
*/
|
|
160
|
+
const [controlledName] = React.useState(name ? name : `generatedName--${identifier}`);
|
|
161
|
+
React.useEffect(() => {
|
|
162
|
+
if (value != undefined) {
|
|
163
|
+
setValue(controlledName, value);
|
|
164
|
+
}
|
|
165
|
+
}, [value, watch(controlledName)]);
|
|
166
|
+
React.useImperativeHandle(actionsRef, () => ({
|
|
167
|
+
setValue: newValue => {
|
|
168
|
+
setValue(controlledName, newValue, { shouldValidate: true });
|
|
169
|
+
},
|
|
170
|
+
}));
|
|
171
|
+
const message = (_a = errors[controlledName]) === null || _a === void 0 ? void 0 : _a.message;
|
|
172
|
+
const error = getErrorMessage();
|
|
173
|
+
React.useEffect(() => handleValidation(), [error]);
|
|
174
|
+
return (React__default["default"].createElement(reactHookForm.Controller, { control: control, name: controlledName, rules: Object.assign({}, validations), defaultValue: (_b = value !== null && value !== void 0 ? value : defaultValue) !== null && _b !== void 0 ? _b : "", render: (_a) => {
|
|
175
|
+
var _b = _a.field, { onChange: onControllerChange, onBlur: onControllerBlur, name: controllerName } = _b, rest = tslib_es6.__rest(_b, ["onChange", "onBlur", "name"]);
|
|
176
|
+
const fieldProps = Object.assign(Object.assign(Object.assign({}, rest), { id: identifier, className: styles$1.input, name: (validations || name) && controllerName, disabled: disabled, readOnly: readonly, inputMode: keyboard, onChange: handleChange, onBlur: handleBlur, onFocus: handleFocus }), (description &&
|
|
177
|
+
!inline && { "aria-describedby": descriptionIdentifier }));
|
|
178
|
+
const textFieldProps = Object.assign(Object.assign({}, fieldProps), { onKeyDown: handleKeyDown });
|
|
179
|
+
return (React__default["default"].createElement(FormFieldWrapper, Object.assign({}, props, { value: rest.value, error: error, identifier: identifier, descriptionIdentifier: descriptionIdentifier, clearable: clearable, onClear: handleClear }), renderField()));
|
|
180
|
+
function renderField() {
|
|
181
|
+
switch (type) {
|
|
182
|
+
case "select":
|
|
183
|
+
return (React__default["default"].createElement(React__default["default"].Fragment, null,
|
|
184
|
+
React__default["default"].createElement("select", Object.assign({}, fieldProps), children),
|
|
185
|
+
React__default["default"].createElement(FormFieldPostFix, { variation: "select" })));
|
|
186
|
+
case "textarea":
|
|
187
|
+
return (React__default["default"].createElement("textarea", Object.assign({}, textFieldProps, { rows: rows, ref: inputRef })));
|
|
188
|
+
default:
|
|
189
|
+
return (React__default["default"].createElement(React__default["default"].Fragment, null,
|
|
190
|
+
React__default["default"].createElement("input", Object.assign({}, textFieldProps, { autoComplete: setAutocomplete(autocomplete), type: type, maxLength: maxLength, max: max, min: min, ref: inputRef, onKeyUp: onKeyUp })),
|
|
191
|
+
loading && React__default["default"].createElement(FormFieldPostFix, { variation: "spinner" }),
|
|
192
|
+
children));
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function handleClear() {
|
|
196
|
+
var _a;
|
|
197
|
+
handleBlur();
|
|
198
|
+
setValue(controlledName, undefined, { shouldValidate: true });
|
|
199
|
+
onChange && onChange("");
|
|
200
|
+
(_a = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
201
|
+
}
|
|
202
|
+
function handleChange(event) {
|
|
203
|
+
let newValue;
|
|
204
|
+
newValue = event.currentTarget.value;
|
|
205
|
+
if (type === "number" && newValue.length > 0) {
|
|
206
|
+
newValue = parseFloat(newValue);
|
|
207
|
+
}
|
|
208
|
+
onChange && onChange(newValue, event);
|
|
209
|
+
onControllerChange(event);
|
|
210
|
+
}
|
|
211
|
+
function handleKeyDown(event) {
|
|
212
|
+
if (!onEnter)
|
|
213
|
+
return;
|
|
214
|
+
if (event.key !== "Enter")
|
|
215
|
+
return;
|
|
216
|
+
if (event.shiftKey || event.ctrlKey)
|
|
217
|
+
return;
|
|
218
|
+
event.preventDefault();
|
|
219
|
+
onEnter && onEnter(event);
|
|
220
|
+
}
|
|
221
|
+
function handleFocus(event) {
|
|
222
|
+
const target = event.currentTarget;
|
|
223
|
+
if (target.select) {
|
|
224
|
+
setTimeout(() => readonly && target.select());
|
|
225
|
+
}
|
|
226
|
+
onFocus && onFocus();
|
|
227
|
+
}
|
|
228
|
+
function handleBlur() {
|
|
229
|
+
onBlur && onBlur();
|
|
230
|
+
onControllerBlur();
|
|
231
|
+
}
|
|
232
|
+
} }));
|
|
233
|
+
function getErrorMessage() {
|
|
234
|
+
if (typeof message === "string") {
|
|
235
|
+
return message;
|
|
236
|
+
}
|
|
237
|
+
return "";
|
|
238
|
+
}
|
|
239
|
+
function handleValidation() {
|
|
240
|
+
onValidation && onValidation(error);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
function setAutocomplete(autocompleteSetting) {
|
|
244
|
+
if (autocompleteSetting === true) {
|
|
245
|
+
return undefined;
|
|
246
|
+
}
|
|
247
|
+
else if (autocompleteSetting === false) {
|
|
248
|
+
return "off";
|
|
249
|
+
}
|
|
250
|
+
return autocompleteSetting;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
exports.FormField = FormField;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var FormField = require('./FormField-fc30bb1a.js');
|
|
6
|
+
require('./tslib.es6-754e2961.js');
|
|
7
|
+
require('react');
|
|
8
|
+
require('react-hook-form');
|
|
9
|
+
require('./style-inject.es-9d2f5f4e.js');
|
|
10
|
+
require('classnames');
|
|
11
|
+
require('@jobber/hooks/useShowClear');
|
|
12
|
+
require('./Button-ec64869e.js');
|
|
13
|
+
require('react-router-dom');
|
|
14
|
+
require('./Icon-405a216c.js');
|
|
15
|
+
require('@jobber/design');
|
|
16
|
+
require('./Typography-fd88fcce.js');
|
|
17
|
+
require('./Text-714f7d14.js');
|
|
18
|
+
require('./InputValidation-4a61254d.js');
|
|
19
|
+
require('framer-motion');
|
|
20
|
+
require('./Spinner-3480bc34.js');
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
exports.FormField = FormField.FormField;
|