@toptal/picasso-forms 66.3.2 → 67.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{Autocomplete → dist-package/src/Autocomplete}/Autocomplete.d.ts +1 -0
- package/dist-package/src/Autocomplete/Autocomplete.d.ts.map +1 -0
- package/dist-package/src/Autocomplete/Autocomplete.js.map +1 -0
- package/{Autocomplete → dist-package/src/Autocomplete}/index.d.ts +1 -0
- package/dist-package/src/Autocomplete/index.d.ts.map +1 -0
- package/dist-package/src/Autocomplete/index.js.map +1 -0
- package/{AvatarUpload → dist-package/src/AvatarUpload}/AvatarUpload.d.ts +1 -0
- package/dist-package/src/AvatarUpload/AvatarUpload.d.ts.map +1 -0
- package/dist-package/src/AvatarUpload/AvatarUpload.js.map +1 -0
- package/{AvatarUpload → dist-package/src/AvatarUpload}/index.d.ts +1 -0
- package/dist-package/src/AvatarUpload/index.d.ts.map +1 -0
- package/dist-package/src/AvatarUpload/index.js.map +1 -0
- package/{ButtonCheckbox → dist-package/src/ButtonCheckbox}/ButtonCheckbox.d.ts +1 -0
- package/dist-package/src/ButtonCheckbox/ButtonCheckbox.d.ts.map +1 -0
- package/dist-package/src/ButtonCheckbox/ButtonCheckbox.js.map +1 -0
- package/{ButtonCheckbox → dist-package/src/ButtonCheckbox}/index.d.ts +1 -0
- package/dist-package/src/ButtonCheckbox/index.d.ts.map +1 -0
- package/dist-package/src/ButtonCheckbox/index.js.map +1 -0
- package/{ButtonRadio → dist-package/src/ButtonRadio}/ButtonRadio.d.ts +1 -0
- package/dist-package/src/ButtonRadio/ButtonRadio.d.ts.map +1 -0
- package/dist-package/src/ButtonRadio/ButtonRadio.js.map +1 -0
- package/{ButtonRadio → dist-package/src/ButtonRadio}/index.d.ts +1 -0
- package/dist-package/src/ButtonRadio/index.d.ts.map +1 -0
- package/dist-package/src/ButtonRadio/index.js.map +1 -0
- package/{Checkbox → dist-package/src/Checkbox}/Checkbox.d.ts +1 -0
- package/dist-package/src/Checkbox/Checkbox.d.ts.map +1 -0
- package/dist-package/src/Checkbox/Checkbox.js.map +1 -0
- package/dist-package/src/Checkbox/index.d.ts +3 -0
- package/dist-package/src/Checkbox/index.d.ts.map +1 -0
- package/dist-package/src/Checkbox/index.js.map +1 -0
- package/{CheckboxGroup → dist-package/src/CheckboxGroup}/CheckboxGroup.d.ts +1 -0
- package/dist-package/src/CheckboxGroup/CheckboxGroup.d.ts.map +1 -0
- package/dist-package/src/CheckboxGroup/CheckboxGroup.js.map +1 -0
- package/{CheckboxGroup → dist-package/src/CheckboxGroup}/CheckboxGroupContext.d.ts +1 -0
- package/dist-package/src/CheckboxGroup/CheckboxGroupContext.d.ts.map +1 -0
- package/dist-package/src/CheckboxGroup/CheckboxGroupContext.js.map +1 -0
- package/{CheckboxGroup → dist-package/src/CheckboxGroup}/index.d.ts +1 -0
- package/dist-package/src/CheckboxGroup/index.d.ts.map +1 -0
- package/dist-package/src/CheckboxGroup/index.js.map +1 -0
- package/{DatePicker → dist-package/src/DatePicker}/DatePicker.d.ts +1 -0
- package/dist-package/src/DatePicker/DatePicker.d.ts.map +1 -0
- package/dist-package/src/DatePicker/DatePicker.js.map +1 -0
- package/{DatePicker → dist-package/src/DatePicker}/index.d.ts +1 -0
- package/dist-package/src/DatePicker/index.d.ts.map +1 -0
- package/dist-package/src/DatePicker/index.js.map +1 -0
- package/{Dropzone → dist-package/src/Dropzone}/Dropzone.d.ts +1 -0
- package/dist-package/src/Dropzone/Dropzone.d.ts.map +1 -0
- package/dist-package/src/Dropzone/Dropzone.js.map +1 -0
- package/{Dropzone → dist-package/src/Dropzone}/index.d.ts +1 -0
- package/dist-package/src/Dropzone/index.d.ts.map +1 -0
- package/dist-package/src/Dropzone/index.js.map +1 -0
- package/{Field → dist-package/src/Field}/Field.d.ts +1 -0
- package/dist-package/src/Field/Field.d.ts.map +1 -0
- package/dist-package/src/Field/Field.js.map +1 -0
- package/{Field → dist-package/src/Field}/index.d.ts +1 -0
- package/dist-package/src/Field/index.d.ts.map +1 -0
- package/dist-package/src/Field/index.js.map +1 -0
- package/dist-package/src/FieldBase/index.d.ts +2 -0
- package/dist-package/src/FieldBase/index.d.ts.map +1 -0
- package/dist-package/src/FieldBase/index.js.map +1 -0
- package/dist-package/src/FieldBase/types.d.ts +6 -0
- package/dist-package/src/FieldBase/types.d.ts.map +1 -0
- package/{FieldBase → dist-package/src/FieldBase}/types.js.map +1 -1
- package/{FieldLabel → dist-package/src/FieldLabel}/FieldLabel.d.ts +1 -0
- package/dist-package/src/FieldLabel/FieldLabel.d.ts.map +1 -0
- package/dist-package/src/FieldLabel/FieldLabel.js.map +1 -0
- package/{FieldLabel → dist-package/src/FieldLabel}/index.d.ts +1 -0
- package/dist-package/src/FieldLabel/index.d.ts.map +1 -0
- package/dist-package/src/FieldLabel/index.js.map +1 -0
- package/{FieldWrapper → dist-package/src/FieldWrapper}/FieldWrapper.d.ts +1 -0
- package/dist-package/src/FieldWrapper/FieldWrapper.d.ts.map +1 -0
- package/dist-package/src/FieldWrapper/FieldWrapper.js.map +1 -0
- package/{FieldWrapper → dist-package/src/FieldWrapper}/index.d.ts +1 -0
- package/dist-package/src/FieldWrapper/index.d.ts.map +1 -0
- package/dist-package/src/FieldWrapper/index.js.map +1 -0
- package/{FileInput → dist-package/src/FileInput}/FileInput.d.ts +1 -0
- package/dist-package/src/FileInput/FileInput.d.ts.map +1 -0
- package/dist-package/src/FileInput/FileInput.js.map +1 -0
- package/{FileInput → dist-package/src/FileInput}/index.d.ts +1 -0
- package/dist-package/src/FileInput/index.d.ts.map +1 -0
- package/dist-package/src/FileInput/index.js.map +1 -0
- package/{Form → dist-package/src/Form}/Form.d.ts +1 -0
- package/dist-package/src/Form/Form.d.ts.map +1 -0
- package/{Form → dist-package/src/Form}/Form.js +1 -1
- package/dist-package/src/Form/Form.js.map +1 -0
- package/{Form → dist-package/src/Form}/FormContext.d.ts +1 -0
- package/dist-package/src/Form/FormContext.d.ts.map +1 -0
- package/dist-package/src/Form/FormContext.js.map +1 -0
- package/{Form → dist-package/src/Form}/FormRenderer.d.ts +1 -0
- package/dist-package/src/Form/FormRenderer.d.ts.map +1 -0
- package/dist-package/src/Form/FormRenderer.js.map +1 -0
- package/{Form → dist-package/src/Form}/index.d.ts +1 -0
- package/dist-package/src/Form/index.d.ts.map +1 -0
- package/dist-package/src/Form/index.js.map +1 -0
- package/{Form → dist-package/src/Form}/mutators/index.d.ts +1 -0
- package/dist-package/src/Form/mutators/index.d.ts.map +1 -0
- package/dist-package/src/Form/mutators/index.js.map +1 -0
- package/{Form → dist-package/src/Form}/mutators/set-active-field-touched.d.ts +1 -0
- package/dist-package/src/Form/mutators/set-active-field-touched.d.ts.map +1 -0
- package/dist-package/src/Form/mutators/set-active-field-touched.js.map +1 -0
- package/{Form → dist-package/src/Form}/mutators/set-has-multiline-counter.d.ts +1 -0
- package/dist-package/src/Form/mutators/set-has-multiline-counter.d.ts.map +1 -0
- package/dist-package/src/Form/mutators/set-has-multiline-counter.js.map +1 -0
- package/{FormCompound → dist-package/src/FormCompound}/index.d.ts +7 -6
- package/dist-package/src/FormCompound/index.d.ts.map +1 -0
- package/dist-package/src/FormCompound/index.js.map +1 -0
- package/{FormConfig → dist-package/src/FormConfig}/FormConfig.d.ts +1 -0
- package/dist-package/src/FormConfig/FormConfig.d.ts.map +1 -0
- package/dist-package/src/FormConfig/FormConfig.js.map +1 -0
- package/dist-package/src/FormConfig/index.d.ts +2 -0
- package/dist-package/src/FormConfig/index.d.ts.map +1 -0
- package/dist-package/src/FormConfig/index.js.map +1 -0
- package/{Input → dist-package/src/Input}/Input.d.ts +1 -0
- package/dist-package/src/Input/Input.d.ts.map +1 -0
- package/dist-package/src/Input/Input.js.map +1 -0
- package/{Input → dist-package/src/Input}/index.d.ts +1 -0
- package/dist-package/src/Input/index.d.ts.map +1 -0
- package/dist-package/src/Input/index.js.map +1 -0
- package/{InputField → dist-package/src/InputField}/InputField.d.ts +1 -0
- package/dist-package/src/InputField/InputField.d.ts.map +1 -0
- package/dist-package/src/InputField/InputField.js.map +1 -0
- package/{InputField → dist-package/src/InputField}/index.d.ts +1 -0
- package/dist-package/src/InputField/index.d.ts.map +1 -0
- package/dist-package/src/InputField/index.js.map +1 -0
- package/{NumberInput → dist-package/src/NumberInput}/NumberInput.d.ts +1 -0
- package/dist-package/src/NumberInput/NumberInput.d.ts.map +1 -0
- package/dist-package/src/NumberInput/NumberInput.js.map +1 -0
- package/dist-package/src/NumberInput/index.d.ts +3 -0
- package/dist-package/src/NumberInput/index.d.ts.map +1 -0
- package/dist-package/src/NumberInput/index.js.map +1 -0
- package/{PasswordInput → dist-package/src/PasswordInput}/FieldRenderer.d.ts +1 -0
- package/dist-package/src/PasswordInput/FieldRenderer.d.ts.map +1 -0
- package/dist-package/src/PasswordInput/FieldRenderer.js.map +1 -0
- package/{PasswordInput → dist-package/src/PasswordInput}/PasswordInput.d.ts +1 -0
- package/dist-package/src/PasswordInput/PasswordInput.d.ts.map +1 -0
- package/dist-package/src/PasswordInput/PasswordInput.js.map +1 -0
- package/{PasswordInput → dist-package/src/PasswordInput}/index.d.ts +1 -0
- package/dist-package/src/PasswordInput/index.d.ts.map +1 -0
- package/dist-package/src/PasswordInput/index.js.map +1 -0
- package/{PasswordInput → dist-package/src/PasswordInput}/validators.d.ts +1 -0
- package/dist-package/src/PasswordInput/validators.d.ts.map +1 -0
- package/dist-package/src/PasswordInput/validators.js.map +1 -0
- package/{Radio → dist-package/src/Radio}/Radio.d.ts +1 -0
- package/dist-package/src/Radio/Radio.d.ts.map +1 -0
- package/dist-package/src/Radio/Radio.js.map +1 -0
- package/{Radio → dist-package/src/Radio}/index.d.ts +1 -0
- package/dist-package/src/Radio/index.d.ts.map +1 -0
- package/dist-package/src/Radio/index.js.map +1 -0
- package/{RadioGroup → dist-package/src/RadioGroup}/RadioGroup.d.ts +1 -0
- package/dist-package/src/RadioGroup/RadioGroup.d.ts.map +1 -0
- package/dist-package/src/RadioGroup/RadioGroup.js.map +1 -0
- package/{RadioGroup → dist-package/src/RadioGroup}/RadioGroupContext.d.ts +1 -0
- package/dist-package/src/RadioGroup/RadioGroupContext.d.ts.map +1 -0
- package/dist-package/src/RadioGroup/RadioGroupContext.js.map +1 -0
- package/{RadioGroup → dist-package/src/RadioGroup}/index.d.ts +1 -0
- package/dist-package/src/RadioGroup/index.d.ts.map +1 -0
- package/dist-package/src/RadioGroup/index.js.map +1 -0
- package/{Rating → dist-package/src/Rating}/Rating.d.ts +1 -0
- package/dist-package/src/Rating/Rating.d.ts.map +1 -0
- package/dist-package/src/Rating/Rating.js.map +1 -0
- package/{Rating → dist-package/src/Rating}/index.d.ts +1 -0
- package/dist-package/src/Rating/index.d.ts.map +1 -0
- package/dist-package/src/Rating/index.js.map +1 -0
- package/{RichTextEditor → dist-package/src/RichTextEditor}/RichTextEditor.d.ts +2 -1
- package/dist-package/src/RichTextEditor/RichTextEditor.d.ts.map +1 -0
- package/dist-package/src/RichTextEditor/RichTextEditor.js.map +1 -0
- package/dist-package/src/RichTextEditor/hooks/index.d.ts +2 -0
- package/dist-package/src/RichTextEditor/hooks/index.d.ts.map +1 -0
- package/dist-package/src/RichTextEditor/hooks/index.js.map +1 -0
- package/{RichTextEditor → dist-package/src/RichTextEditor}/hooks/use-enforce-highlight-autofill.d.ts +1 -0
- package/dist-package/src/RichTextEditor/hooks/use-enforce-highlight-autofill.d.ts.map +1 -0
- package/dist-package/src/RichTextEditor/hooks/use-enforce-highlight-autofill.js.map +1 -0
- package/{RichTextEditor → dist-package/src/RichTextEditor}/index.d.ts +1 -0
- package/dist-package/src/RichTextEditor/index.d.ts.map +1 -0
- package/dist-package/src/RichTextEditor/index.js.map +1 -0
- package/{Select → dist-package/src/Select}/Select.d.ts +1 -0
- package/dist-package/src/Select/Select.d.ts.map +1 -0
- package/{Select → dist-package/src/Select}/Select.js +1 -1
- package/dist-package/src/Select/Select.js.map +1 -0
- package/dist-package/src/Select/index.d.ts +3 -0
- package/dist-package/src/Select/index.d.ts.map +1 -0
- package/dist-package/src/Select/index.js.map +1 -0
- package/{SubmitButton → dist-package/src/SubmitButton}/SubmitButton.d.ts +2 -2
- package/dist-package/src/SubmitButton/SubmitButton.d.ts.map +1 -0
- package/dist-package/src/SubmitButton/SubmitButton.js.map +1 -0
- package/{SubmitButton → dist-package/src/SubmitButton}/index.d.ts +1 -0
- package/dist-package/src/SubmitButton/index.d.ts.map +1 -0
- package/dist-package/src/SubmitButton/index.js.map +1 -0
- package/{Switch → dist-package/src/Switch}/Switch.d.ts +1 -0
- package/dist-package/src/Switch/Switch.d.ts.map +1 -0
- package/dist-package/src/Switch/Switch.js.map +1 -0
- package/{Switch → dist-package/src/Switch}/index.d.ts +1 -0
- package/dist-package/src/Switch/index.d.ts.map +1 -0
- package/dist-package/src/Switch/index.js.map +1 -0
- package/{TagSelector → dist-package/src/TagSelector}/TagSelector.d.ts +1 -0
- package/dist-package/src/TagSelector/TagSelector.d.ts.map +1 -0
- package/dist-package/src/TagSelector/TagSelector.js.map +1 -0
- package/dist-package/src/TagSelector/index.d.ts +3 -0
- package/dist-package/src/TagSelector/index.d.ts.map +1 -0
- package/dist-package/src/TagSelector/index.js.map +1 -0
- package/{TimePicker → dist-package/src/TimePicker}/TimePicker.d.ts +1 -0
- package/dist-package/src/TimePicker/TimePicker.d.ts.map +1 -0
- package/dist-package/src/TimePicker/TimePicker.js.map +1 -0
- package/{TimePicker → dist-package/src/TimePicker}/index.d.ts +1 -0
- package/dist-package/src/TimePicker/index.d.ts.map +1 -0
- package/dist-package/src/TimePicker/index.js.map +1 -0
- package/{index.d.ts → dist-package/src/index.d.ts} +10 -0
- package/dist-package/src/index.d.ts.map +1 -0
- package/{index.js → dist-package/src/index.js} +3 -0
- package/dist-package/src/index.js.map +1 -0
- package/{utils → dist-package/src/utils}/flat-map.d.ts +1 -0
- package/dist-package/src/utils/flat-map.d.ts.map +1 -0
- package/dist-package/src/utils/flat-map.js.map +1 -0
- package/{utils → dist-package/src/utils}/form-values-change-decorator/form-values-change-decorator.d.ts +1 -0
- package/dist-package/src/utils/form-values-change-decorator/form-values-change-decorator.d.ts.map +1 -0
- package/dist-package/src/utils/form-values-change-decorator/form-values-change-decorator.js.map +1 -0
- package/{utils → dist-package/src/utils}/form-values-change-decorator/index.d.ts +1 -0
- package/dist-package/src/utils/form-values-change-decorator/index.d.ts.map +1 -0
- package/dist-package/src/utils/form-values-change-decorator/index.js.map +1 -0
- package/{utils → dist-package/src/utils}/index.d.ts +1 -0
- package/dist-package/src/utils/index.d.ts.map +1 -0
- package/dist-package/src/utils/index.js.map +1 -0
- package/{utils → dist-package/src/utils}/scroll-to-error-decorator.d.ts +1 -0
- package/dist-package/src/utils/scroll-to-error-decorator.d.ts.map +1 -0
- package/dist-package/src/utils/scroll-to-error-decorator.js.map +1 -0
- package/{utils → dist-package/src/utils}/scroll-to.d.ts +1 -0
- package/dist-package/src/utils/scroll-to.d.ts.map +1 -0
- package/dist-package/src/utils/scroll-to.js.map +1 -0
- package/{utils → dist-package/src/utils}/use-field-validation/index.d.ts +1 -0
- package/dist-package/src/utils/use-field-validation/index.d.ts.map +1 -0
- package/dist-package/src/utils/use-field-validation/index.js.map +1 -0
- package/{utils → dist-package/src/utils}/use-field-validation/use-field-validation.d.ts +1 -0
- package/dist-package/src/utils/use-field-validation/use-field-validation.d.ts.map +1 -0
- package/dist-package/src/utils/use-field-validation/use-field-validation.js.map +1 -0
- package/{utils → dist-package/src/utils}/use-form-auto-save/index.d.ts +1 -0
- package/dist-package/src/utils/use-form-auto-save/index.d.ts.map +1 -0
- package/dist-package/src/utils/use-form-auto-save/index.js.map +1 -0
- package/{utils → dist-package/src/utils}/use-form-auto-save/use-form-auto-save.d.ts +1 -0
- package/dist-package/src/utils/use-form-auto-save/use-form-auto-save.d.ts.map +1 -0
- package/dist-package/src/utils/use-form-auto-save/use-form-auto-save.js.map +1 -0
- package/{utils → dist-package/src/utils}/use-form-input-reset/index.d.ts +1 -0
- package/dist-package/src/utils/use-form-input-reset/index.d.ts.map +1 -0
- package/dist-package/src/utils/use-form-input-reset/index.js.map +1 -0
- package/{utils → dist-package/src/utils}/use-form-input-reset/use-form-input-reset.d.ts +1 -0
- package/dist-package/src/utils/use-form-input-reset/use-form-input-reset.d.ts.map +1 -0
- package/dist-package/src/utils/use-form-input-reset/use-form-input-reset.js.map +1 -0
- package/{utils → dist-package/src/utils}/validators.d.ts +1 -0
- package/dist-package/src/utils/validators.d.ts.map +1 -0
- package/dist-package/src/utils/validators.js.map +1 -0
- package/package.json +24 -11
- package/src/Autocomplete/Autocomplete.tsx +37 -0
- package/src/Autocomplete/index.ts +1 -0
- package/src/AvatarUpload/AvatarUpload.tsx +92 -0
- package/src/AvatarUpload/index.ts +1 -0
- package/src/ButtonCheckbox/ButtonCheckbox.tsx +63 -0
- package/src/ButtonCheckbox/index.ts +1 -0
- package/src/ButtonRadio/ButtonRadio.tsx +25 -0
- package/src/ButtonRadio/index.ts +1 -0
- package/src/Checkbox/Checkbox.tsx +79 -0
- package/src/Checkbox/__snapshots__/test.tsx.snap +259 -0
- package/src/Checkbox/index.ts +2 -0
- package/src/Checkbox/test.tsx +92 -0
- package/src/CheckboxGroup/CheckboxGroup.tsx +47 -0
- package/src/CheckboxGroup/CheckboxGroupContext.ts +3 -0
- package/src/CheckboxGroup/index.ts +3 -0
- package/src/CheckboxGroup/test.tsx +36 -0
- package/src/DatePicker/DatePicker.tsx +40 -0
- package/src/DatePicker/index.ts +1 -0
- package/src/Dropzone/Dropzone.tsx +102 -0
- package/src/Dropzone/index.ts +6 -0
- package/src/Field/Field.tsx +196 -0
- package/src/Field/index.ts +2 -0
- package/src/FieldBase/index.ts +1 -0
- package/src/FieldBase/types.ts +23 -0
- package/src/FieldLabel/FieldLabel.tsx +64 -0
- package/src/FieldLabel/__snapshots__/test.tsx.snap +21 -0
- package/src/FieldLabel/index.ts +2 -0
- package/src/FieldLabel/test.tsx +52 -0
- package/src/FieldWrapper/FieldWrapper.tsx +48 -0
- package/src/FieldWrapper/index.ts +6 -0
- package/src/FieldWrapper/story/index.jsx +153 -0
- package/src/FieldWrapper/test.tsx +32 -0
- package/src/FileInput/FileInput.tsx +85 -0
- package/src/FileInput/index.ts +1 -0
- package/src/Form/Form.tsx +161 -0
- package/src/Form/FormContext.ts +38 -0
- package/src/Form/FormRenderer.tsx +38 -0
- package/src/Form/__snapshots__/test.tsx.snap +140 -0
- package/src/Form/index.ts +2 -0
- package/src/Form/mutators/index.ts +2 -0
- package/src/Form/mutators/set-active-field-touched.ts +16 -0
- package/src/Form/mutators/set-has-multiline-counter.ts +16 -0
- package/src/Form/story/AutoSave.example.tsx +120 -0
- package/src/Form/story/AvatarUpload.example.tsx +81 -0
- package/src/Form/story/BackendCommunication.example.tsx +137 -0
- package/src/Form/story/CustomFormLevelConfiguration.example.tsx +35 -0
- package/src/Form/story/CustomValidator.example.tsx +53 -0
- package/src/Form/story/Default.example.tsx +218 -0
- package/src/Form/story/Dropzone.example.tsx +42 -0
- package/src/Form/story/FieldRequirements.example.tsx +58 -0
- package/src/Form/story/FileInput.example.tsx +43 -0
- package/src/Form/story/HighlightAutofill.example.tsx +96 -0
- package/src/Form/story/Horizontal.example.tsx +281 -0
- package/src/Form/story/HorizontalLabelWidth.example.tsx +26 -0
- package/src/Form/story/NoScrolling.example.tsx +42 -0
- package/src/Form/story/ParseInput.example.tsx +31 -0
- package/src/Form/story/RichTextEditor.example.tsx +32 -0
- package/src/Form/story/Status.example.tsx +35 -0
- package/src/Form/story/TitleCase.example.tsx +194 -0
- package/src/Form/story/ValidateOnSubmit.example.tsx +99 -0
- package/src/Form/story/index.jsx +289 -0
- package/src/Form/test.tsx +202 -0
- package/src/FormCompound/index.ts +51 -0
- package/src/FormConfig/FormConfig.ts +35 -0
- package/src/FormConfig/index.ts +1 -0
- package/src/FormConfig/test.tsx +44 -0
- package/src/Input/Input.tsx +80 -0
- package/src/Input/index.ts +2 -0
- package/src/Input/test.tsx +35 -0
- package/src/InputField/InputField.tsx +71 -0
- package/src/InputField/index.ts +1 -0
- package/src/InputField/test.ts +105 -0
- package/src/NumberInput/NumberInput.tsx +58 -0
- package/src/NumberInput/index.ts +2 -0
- package/src/PasswordInput/FieldRenderer.tsx +36 -0
- package/src/PasswordInput/PasswordInput.tsx +144 -0
- package/src/PasswordInput/index.ts +1 -0
- package/src/PasswordInput/test.ts +45 -0
- package/src/PasswordInput/validators.ts +28 -0
- package/src/Radio/Radio.tsx +25 -0
- package/src/Radio/__snapshots__/test.tsx.snap +235 -0
- package/src/Radio/index.ts +1 -0
- package/src/Radio/test.tsx +49 -0
- package/src/RadioGroup/RadioGroup.tsx +53 -0
- package/src/RadioGroup/RadioGroupContext.ts +3 -0
- package/src/RadioGroup/index.ts +3 -0
- package/src/RadioGroup/test.tsx +36 -0
- package/src/Rating/Rating.tsx +95 -0
- package/src/Rating/__snapshots__/test.tsx.snap +226 -0
- package/src/Rating/index.ts +1 -0
- package/src/Rating/test.tsx +171 -0
- package/src/RichTextEditor/RichTextEditor.tsx +87 -0
- package/{RichTextEditor/hooks/index.d.ts → src/RichTextEditor/hooks/index.ts} +1 -1
- package/src/RichTextEditor/hooks/use-enforce-highlight-autofill.test.tsx +67 -0
- package/src/RichTextEditor/hooks/use-enforce-highlight-autofill.ts +48 -0
- package/src/RichTextEditor/index.ts +1 -0
- package/src/Select/Select.tsx +55 -0
- package/src/Select/index.ts +2 -0
- package/src/SubmitButton/SubmitButton.tsx +71 -0
- package/src/SubmitButton/index.ts +6 -0
- package/src/SubmitButton/story/ButtonTypes.example.tsx +45 -0
- package/src/SubmitButton/story/Default.example.tsx +16 -0
- package/src/SubmitButton/story/index.jsx +35 -0
- package/src/Switch/Switch.tsx +40 -0
- package/src/Switch/index.ts +1 -0
- package/src/TagSelector/TagSelector.tsx +41 -0
- package/src/TagSelector/index.ts +2 -0
- package/src/TimePicker/TimePicker.tsx +43 -0
- package/src/TimePicker/index.ts +1 -0
- package/src/index.ts +86 -0
- package/src/story/Deserialization.example.tsx +40 -0
- package/src/story/FormSpy.example.tsx +50 -0
- package/src/story/index.jsx +39 -0
- package/src/utils/flat-map.ts +4 -0
- package/src/utils/form-values-change-decorator/form-values-change-decorator.ts +64 -0
- package/src/utils/form-values-change-decorator/index.ts +3 -0
- package/src/utils/form-values-change-decorator/test.tsx +77 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/scroll-to-error-decorator.ts +85 -0
- package/src/utils/scroll-to.ts +10 -0
- package/src/utils/use-field-validation/index.ts +1 -0
- package/src/utils/use-field-validation/test.tsx +73 -0
- package/src/utils/use-field-validation/use-field-validation.ts +63 -0
- package/src/utils/use-form-auto-save/index.ts +1 -0
- package/src/utils/use-form-auto-save/use-form-auto-save.ts +59 -0
- package/src/utils/use-form-input-reset/index.ts +1 -0
- package/src/utils/use-form-input-reset/test.ts +72 -0
- package/src/utils/use-form-input-reset/use-form-input-reset.ts +32 -0
- package/src/utils/validators.ts +18 -0
- package/utils.d.ts +1 -0
- package/utils.js +4 -0
- package/Autocomplete/Autocomplete.js.map +0 -1
- package/Autocomplete/index.js.map +0 -1
- package/AvatarUpload/AvatarUpload.js.map +0 -1
- package/AvatarUpload/index.js.map +0 -1
- package/ButtonCheckbox/ButtonCheckbox.js.map +0 -1
- package/ButtonCheckbox/index.js.map +0 -1
- package/ButtonRadio/ButtonRadio.js.map +0 -1
- package/ButtonRadio/index.js.map +0 -1
- package/Checkbox/Checkbox.js.map +0 -1
- package/Checkbox/index.d.ts +0 -1
- package/Checkbox/index.js.map +0 -1
- package/CheckboxGroup/CheckboxGroup.js.map +0 -1
- package/CheckboxGroup/CheckboxGroupContext.js.map +0 -1
- package/CheckboxGroup/index.js.map +0 -1
- package/DatePicker/DatePicker.js.map +0 -1
- package/DatePicker/index.js.map +0 -1
- package/Dropzone/Dropzone.js.map +0 -1
- package/Dropzone/index.js.map +0 -1
- package/Field/Field.js.map +0 -1
- package/Field/index.js.map +0 -1
- package/FieldBase/index.d.ts +0 -1
- package/FieldBase/index.js.map +0 -1
- package/FieldBase/types.d.ts +0 -8
- package/FieldLabel/FieldLabel.js.map +0 -1
- package/FieldLabel/index.js.map +0 -1
- package/FieldWrapper/FieldWrapper.js.map +0 -1
- package/FieldWrapper/index.js.map +0 -1
- package/FileInput/FileInput.js.map +0 -1
- package/FileInput/index.js.map +0 -1
- package/Form/Form.js.map +0 -1
- package/Form/FormContext.js.map +0 -1
- package/Form/FormRenderer.js.map +0 -1
- package/Form/index.js.map +0 -1
- package/Form/mutators/index.js.map +0 -1
- package/Form/mutators/set-active-field-touched.js.map +0 -1
- package/Form/mutators/set-has-multiline-counter.js.map +0 -1
- package/FormCompound/index.js.map +0 -1
- package/FormConfig/FormConfig.js.map +0 -1
- package/FormConfig/index.d.ts +0 -1
- package/FormConfig/index.js.map +0 -1
- package/Input/Input.js.map +0 -1
- package/Input/index.js.map +0 -1
- package/InputField/InputField.js.map +0 -1
- package/InputField/index.js.map +0 -1
- package/LICENSE +0 -20
- package/NumberInput/NumberInput.js.map +0 -1
- package/NumberInput/index.d.ts +0 -1
- package/NumberInput/index.js.map +0 -1
- package/PasswordInput/FieldRenderer.js.map +0 -1
- package/PasswordInput/PasswordInput.js.map +0 -1
- package/PasswordInput/index.js.map +0 -1
- package/PasswordInput/validators.js.map +0 -1
- package/Radio/Radio.js.map +0 -1
- package/Radio/index.js.map +0 -1
- package/RadioGroup/RadioGroup.js.map +0 -1
- package/RadioGroup/RadioGroupContext.js.map +0 -1
- package/RadioGroup/index.js.map +0 -1
- package/Rating/Rating.js.map +0 -1
- package/Rating/index.js.map +0 -1
- package/RichTextEditor/RichTextEditor.js.map +0 -1
- package/RichTextEditor/hooks/index.js.map +0 -1
- package/RichTextEditor/hooks/use-enforce-highlight-autofill.js.map +0 -1
- package/RichTextEditor/hooks/use-enforce-highlight-autofill.test.d.ts +0 -1
- package/RichTextEditor/hooks/use-enforce-highlight-autofill.test.js +0 -51
- package/RichTextEditor/hooks/use-enforce-highlight-autofill.test.js.map +0 -1
- package/RichTextEditor/index.js.map +0 -1
- package/Select/Select.js.map +0 -1
- package/Select/index.d.ts +0 -1
- package/Select/index.js.map +0 -1
- package/SubmitButton/SubmitButton.js.map +0 -1
- package/SubmitButton/index.js.map +0 -1
- package/Switch/Switch.js.map +0 -1
- package/Switch/index.js.map +0 -1
- package/TagSelector/TagSelector.js.map +0 -1
- package/TagSelector/index.d.ts +0 -1
- package/TagSelector/index.js.map +0 -1
- package/TimePicker/TimePicker.js.map +0 -1
- package/TimePicker/index.js.map +0 -1
- package/index.js.map +0 -1
- package/utils/flat-map.js.map +0 -1
- package/utils/form-values-change-decorator/form-values-change-decorator.js.map +0 -1
- package/utils/form-values-change-decorator/index.js.map +0 -1
- package/utils/index.js.map +0 -1
- package/utils/scroll-to-error-decorator.js.map +0 -1
- package/utils/scroll-to.js.map +0 -1
- package/utils/use-field-validation/index.js.map +0 -1
- package/utils/use-field-validation/use-field-validation.js.map +0 -1
- package/utils/use-form-auto-save/index.js.map +0 -1
- package/utils/use-form-auto-save/use-form-auto-save.js.map +0 -1
- package/utils/use-form-input-reset/index.js.map +0 -1
- package/utils/use-form-input-reset/use-form-input-reset.js.map +0 -1
- package/utils/validators.js.map +0 -1
- /package/{Autocomplete → dist-package/src/Autocomplete}/Autocomplete.js +0 -0
- /package/{Autocomplete → dist-package/src/Autocomplete}/index.js +0 -0
- /package/{AvatarUpload → dist-package/src/AvatarUpload}/AvatarUpload.js +0 -0
- /package/{AvatarUpload → dist-package/src/AvatarUpload}/index.js +0 -0
- /package/{ButtonCheckbox → dist-package/src/ButtonCheckbox}/ButtonCheckbox.js +0 -0
- /package/{ButtonCheckbox → dist-package/src/ButtonCheckbox}/index.js +0 -0
- /package/{ButtonRadio → dist-package/src/ButtonRadio}/ButtonRadio.js +0 -0
- /package/{ButtonRadio → dist-package/src/ButtonRadio}/index.js +0 -0
- /package/{Checkbox → dist-package/src/Checkbox}/Checkbox.js +0 -0
- /package/{Checkbox → dist-package/src/Checkbox}/index.js +0 -0
- /package/{CheckboxGroup → dist-package/src/CheckboxGroup}/CheckboxGroup.js +0 -0
- /package/{CheckboxGroup → dist-package/src/CheckboxGroup}/CheckboxGroupContext.js +0 -0
- /package/{CheckboxGroup → dist-package/src/CheckboxGroup}/index.js +0 -0
- /package/{DatePicker → dist-package/src/DatePicker}/DatePicker.js +0 -0
- /package/{DatePicker → dist-package/src/DatePicker}/index.js +0 -0
- /package/{Dropzone → dist-package/src/Dropzone}/Dropzone.js +0 -0
- /package/{Dropzone → dist-package/src/Dropzone}/index.js +0 -0
- /package/{Field → dist-package/src/Field}/Field.js +0 -0
- /package/{Field → dist-package/src/Field}/index.js +0 -0
- /package/{FieldBase → dist-package/src/FieldBase}/index.js +0 -0
- /package/{FieldBase → dist-package/src/FieldBase}/types.js +0 -0
- /package/{FieldLabel → dist-package/src/FieldLabel}/FieldLabel.js +0 -0
- /package/{FieldLabel → dist-package/src/FieldLabel}/index.js +0 -0
- /package/{FieldWrapper → dist-package/src/FieldWrapper}/FieldWrapper.js +0 -0
- /package/{FieldWrapper → dist-package/src/FieldWrapper}/index.js +0 -0
- /package/{FileInput → dist-package/src/FileInput}/FileInput.js +0 -0
- /package/{FileInput → dist-package/src/FileInput}/index.js +0 -0
- /package/{Form → dist-package/src/Form}/FormContext.js +0 -0
- /package/{Form → dist-package/src/Form}/FormRenderer.js +0 -0
- /package/{Form → dist-package/src/Form}/index.js +0 -0
- /package/{Form → dist-package/src/Form}/mutators/index.js +0 -0
- /package/{Form → dist-package/src/Form}/mutators/set-active-field-touched.js +0 -0
- /package/{Form → dist-package/src/Form}/mutators/set-has-multiline-counter.js +0 -0
- /package/{FormCompound → dist-package/src/FormCompound}/index.js +0 -0
- /package/{FormConfig → dist-package/src/FormConfig}/FormConfig.js +0 -0
- /package/{FormConfig → dist-package/src/FormConfig}/index.js +0 -0
- /package/{Input → dist-package/src/Input}/Input.js +0 -0
- /package/{Input → dist-package/src/Input}/index.js +0 -0
- /package/{InputField → dist-package/src/InputField}/InputField.js +0 -0
- /package/{InputField → dist-package/src/InputField}/index.js +0 -0
- /package/{NumberInput → dist-package/src/NumberInput}/NumberInput.js +0 -0
- /package/{NumberInput → dist-package/src/NumberInput}/index.js +0 -0
- /package/{PasswordInput → dist-package/src/PasswordInput}/FieldRenderer.js +0 -0
- /package/{PasswordInput → dist-package/src/PasswordInput}/PasswordInput.js +0 -0
- /package/{PasswordInput → dist-package/src/PasswordInput}/index.js +0 -0
- /package/{PasswordInput → dist-package/src/PasswordInput}/validators.js +0 -0
- /package/{Radio → dist-package/src/Radio}/Radio.js +0 -0
- /package/{Radio → dist-package/src/Radio}/index.js +0 -0
- /package/{RadioGroup → dist-package/src/RadioGroup}/RadioGroup.js +0 -0
- /package/{RadioGroup → dist-package/src/RadioGroup}/RadioGroupContext.js +0 -0
- /package/{RadioGroup → dist-package/src/RadioGroup}/index.js +0 -0
- /package/{Rating → dist-package/src/Rating}/Rating.js +0 -0
- /package/{Rating → dist-package/src/Rating}/index.js +0 -0
- /package/{RichTextEditor → dist-package/src/RichTextEditor}/RichTextEditor.js +0 -0
- /package/{RichTextEditor → dist-package/src/RichTextEditor}/hooks/index.js +0 -0
- /package/{RichTextEditor → dist-package/src/RichTextEditor}/hooks/use-enforce-highlight-autofill.js +0 -0
- /package/{RichTextEditor → dist-package/src/RichTextEditor}/index.js +0 -0
- /package/{Select → dist-package/src/Select}/index.js +0 -0
- /package/{SubmitButton → dist-package/src/SubmitButton}/SubmitButton.js +0 -0
- /package/{SubmitButton → dist-package/src/SubmitButton}/index.js +0 -0
- /package/{Switch → dist-package/src/Switch}/Switch.js +0 -0
- /package/{Switch → dist-package/src/Switch}/index.js +0 -0
- /package/{TagSelector → dist-package/src/TagSelector}/TagSelector.js +0 -0
- /package/{TagSelector → dist-package/src/TagSelector}/index.js +0 -0
- /package/{TimePicker → dist-package/src/TimePicker}/TimePicker.js +0 -0
- /package/{TimePicker → dist-package/src/TimePicker}/index.js +0 -0
- /package/{utils → dist-package/src/utils}/flat-map.js +0 -0
- /package/{utils → dist-package/src/utils}/form-values-change-decorator/form-values-change-decorator.js +0 -0
- /package/{utils → dist-package/src/utils}/form-values-change-decorator/index.js +0 -0
- /package/{utils → dist-package/src/utils}/index.js +0 -0
- /package/{utils → dist-package/src/utils}/scroll-to-error-decorator.js +0 -0
- /package/{utils → dist-package/src/utils}/scroll-to.js +0 -0
- /package/{utils → dist-package/src/utils}/use-field-validation/index.js +0 -0
- /package/{utils → dist-package/src/utils}/use-field-validation/use-field-validation.js +0 -0
- /package/{utils → dist-package/src/utils}/use-form-auto-save/index.js +0 -0
- /package/{utils → dist-package/src/utils}/use-form-auto-save/use-form-auto-save.js +0 -0
- /package/{utils → dist-package/src/utils}/use-form-input-reset/index.js +0 -0
- /package/{utils → dist-package/src/utils}/use-form-input-reset/use-form-input-reset.js +0 -0
- /package/{utils → dist-package/src/utils}/validators.js +0 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import type { ChangeEvent, FocusEvent } from 'react'
|
|
2
|
+
import React, { useMemo } from 'react'
|
|
3
|
+
import type {
|
|
4
|
+
FieldProps as FinalFieldProps,
|
|
5
|
+
FieldRenderProps,
|
|
6
|
+
} from 'react-final-form'
|
|
7
|
+
import { useField } from 'react-final-form'
|
|
8
|
+
import type { OutlinedInputStatus } from '@toptal/picasso'
|
|
9
|
+
import { Form as PicassoForm } from '@toptal/picasso'
|
|
10
|
+
import type { TextLabelProps } from '@toptal/picasso-shared'
|
|
11
|
+
import { detect } from 'detect-browser'
|
|
12
|
+
|
|
13
|
+
import { useFormConfig } from '../FormConfig'
|
|
14
|
+
import { validators, useFieldValidation } from '../utils'
|
|
15
|
+
import type { ValueType, IFormComponentProps } from '../FieldBase'
|
|
16
|
+
|
|
17
|
+
const { composeValidators, required: requiredValidator } = validators
|
|
18
|
+
|
|
19
|
+
export type FieldProps<TInputValue> = FinalFieldProps<
|
|
20
|
+
TInputValue,
|
|
21
|
+
FieldRenderProps<TInputValue, HTMLInputElement>,
|
|
22
|
+
HTMLInputElement
|
|
23
|
+
> &
|
|
24
|
+
TextLabelProps
|
|
25
|
+
|
|
26
|
+
export type Props<
|
|
27
|
+
TWrappedComponentProps extends IFormComponentProps,
|
|
28
|
+
TInputValue
|
|
29
|
+
> = TWrappedComponentProps &
|
|
30
|
+
FieldProps<TInputValue> & {
|
|
31
|
+
name: string
|
|
32
|
+
type?: string
|
|
33
|
+
label?: React.ReactNode
|
|
34
|
+
status?: OutlinedInputStatus
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
|
+
children: (props: any) => React.ReactNode
|
|
37
|
+
renderFieldRequirements?: (props: {
|
|
38
|
+
value?: TInputValue
|
|
39
|
+
error?: boolean
|
|
40
|
+
}) => React.ReactNode
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
44
|
+
const getValidators = (required: boolean, validate?: any) => {
|
|
45
|
+
if (required && validate) {
|
|
46
|
+
return composeValidators([requiredValidator, validate])
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (required && !validate) {
|
|
50
|
+
return requiredValidator
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return validate
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const isFirefox = detect()?.name === 'firefox'
|
|
57
|
+
|
|
58
|
+
const Field = <
|
|
59
|
+
TWrappedComponentProps extends IFormComponentProps,
|
|
60
|
+
TInputValue extends ValueType = TWrappedComponentProps['value']
|
|
61
|
+
>(
|
|
62
|
+
props: Props<TWrappedComponentProps, TInputValue>
|
|
63
|
+
) => {
|
|
64
|
+
const {
|
|
65
|
+
type,
|
|
66
|
+
hint,
|
|
67
|
+
label,
|
|
68
|
+
required,
|
|
69
|
+
'data-testid': dataTestId,
|
|
70
|
+
renderFieldRequirements,
|
|
71
|
+
status,
|
|
72
|
+
// FieldProps - https://final-form.org/docs/react-final-form/types/FieldProps
|
|
73
|
+
afterSubmit,
|
|
74
|
+
allowNull,
|
|
75
|
+
beforeSubmit,
|
|
76
|
+
children,
|
|
77
|
+
data,
|
|
78
|
+
defaultValue,
|
|
79
|
+
format,
|
|
80
|
+
formatOnBlur,
|
|
81
|
+
initialValue,
|
|
82
|
+
isEqual,
|
|
83
|
+
name,
|
|
84
|
+
id = name,
|
|
85
|
+
parse,
|
|
86
|
+
subscription,
|
|
87
|
+
validate,
|
|
88
|
+
validateFields,
|
|
89
|
+
value,
|
|
90
|
+
autoSaveIndicator,
|
|
91
|
+
...rest
|
|
92
|
+
} = props
|
|
93
|
+
|
|
94
|
+
const { validateOnSubmit: shouldValidateOnSubmit, highlightAutofill } =
|
|
95
|
+
useFormConfig()
|
|
96
|
+
const validators = useMemo(
|
|
97
|
+
() => getValidators(required, validate),
|
|
98
|
+
[required, validate]
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
const { meta, input } = useField<TInputValue>(name, {
|
|
102
|
+
validate: shouldValidateOnSubmit ? undefined : validators,
|
|
103
|
+
type,
|
|
104
|
+
afterSubmit,
|
|
105
|
+
allowNull,
|
|
106
|
+
beforeSubmit,
|
|
107
|
+
data,
|
|
108
|
+
defaultValue,
|
|
109
|
+
format,
|
|
110
|
+
formatOnBlur,
|
|
111
|
+
initialValue,
|
|
112
|
+
isEqual,
|
|
113
|
+
parse,
|
|
114
|
+
subscription,
|
|
115
|
+
validateFields,
|
|
116
|
+
value,
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
const error = useFieldValidation({
|
|
120
|
+
name,
|
|
121
|
+
meta,
|
|
122
|
+
validators,
|
|
123
|
+
shouldValidateOnSubmit,
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
const shouldHighlightAutofill =
|
|
127
|
+
highlightAutofill && !meta.visited && meta.pristine && input.value
|
|
128
|
+
|
|
129
|
+
const childProps: Record<string, unknown> = {
|
|
130
|
+
id,
|
|
131
|
+
status,
|
|
132
|
+
...rest,
|
|
133
|
+
...input,
|
|
134
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
135
|
+
onChange: (event: ChangeEvent<HTMLElement> | any) => {
|
|
136
|
+
if (isFirefox && event?.target) {
|
|
137
|
+
/**
|
|
138
|
+
* The fix for autofill in Firefox, it's taken from:
|
|
139
|
+
* https://github.com/facebook/react/issues/18986#issuecomment-636354428
|
|
140
|
+
* https://github.com/facebook/react/issues/15739
|
|
141
|
+
*/
|
|
142
|
+
Object.defineProperty(event.target, 'defaultValue', {
|
|
143
|
+
configurable: true,
|
|
144
|
+
get() {
|
|
145
|
+
return defaultValue ?? ''
|
|
146
|
+
},
|
|
147
|
+
set() {},
|
|
148
|
+
})
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
input.onChange(event)
|
|
152
|
+
|
|
153
|
+
if (rest.onChange) {
|
|
154
|
+
rest.onChange(event)
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
onBlur: (event: FocusEvent<HTMLElement>) => {
|
|
158
|
+
input.onBlur(event)
|
|
159
|
+
|
|
160
|
+
if (rest.onBlur) {
|
|
161
|
+
rest.onBlur(event)
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
onFocus: (event: FocusEvent<HTMLElement>) => {
|
|
165
|
+
input.onFocus(event)
|
|
166
|
+
|
|
167
|
+
if (rest.onFocus) {
|
|
168
|
+
rest.onFocus(event)
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
...(shouldHighlightAutofill ? { highlight: 'autofill' } : {}),
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return (
|
|
175
|
+
<PicassoForm.Field
|
|
176
|
+
error={error}
|
|
177
|
+
hint={hint}
|
|
178
|
+
data-testid={dataTestId}
|
|
179
|
+
fieldRequirements={renderFieldRequirements?.({
|
|
180
|
+
value: input.value,
|
|
181
|
+
error: status === 'error',
|
|
182
|
+
})}
|
|
183
|
+
autoSaveIndicator={autoSaveIndicator}
|
|
184
|
+
hasMultilineCounter={meta.data?.hasMultilineCounter}
|
|
185
|
+
>
|
|
186
|
+
{label}
|
|
187
|
+
{children(childProps)}
|
|
188
|
+
</PicassoForm.Field>
|
|
189
|
+
)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
Field.defaultProps = {}
|
|
193
|
+
|
|
194
|
+
Field.displayName = 'Field'
|
|
195
|
+
|
|
196
|
+
export default Field
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './types'
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
DateOrDateRangeType,
|
|
3
|
+
FileUpload,
|
|
4
|
+
AvatarUploadFileUpload,
|
|
5
|
+
AutocompleteItem as Item,
|
|
6
|
+
} from '@toptal/picasso'
|
|
7
|
+
|
|
8
|
+
export type ValueType =
|
|
9
|
+
| string
|
|
10
|
+
| string[]
|
|
11
|
+
| number
|
|
12
|
+
| boolean
|
|
13
|
+
| null
|
|
14
|
+
| undefined
|
|
15
|
+
| AvatarUploadFileUpload
|
|
16
|
+
| FileUpload[]
|
|
17
|
+
| DateOrDateRangeType
|
|
18
|
+
| Item
|
|
19
|
+
| Item[]
|
|
20
|
+
|
|
21
|
+
export interface IFormComponentProps {
|
|
22
|
+
value?: ValueType
|
|
23
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import type { RequiredDecoration } from '@toptal/picasso'
|
|
3
|
+
import { Form as PicassoForm } from '@toptal/picasso'
|
|
4
|
+
import type { TextLabelProps } from '@toptal/picasso-shared'
|
|
5
|
+
|
|
6
|
+
import type { RequiredVariant } from '../FormConfig'
|
|
7
|
+
import { useFormConfig } from '../FormConfig'
|
|
8
|
+
|
|
9
|
+
export type Props = {
|
|
10
|
+
name?: string
|
|
11
|
+
label?: React.ReactNode
|
|
12
|
+
required?: boolean
|
|
13
|
+
alignment?: 'top' | 'middle'
|
|
14
|
+
} & TextLabelProps
|
|
15
|
+
|
|
16
|
+
const getRequiredDecoration = (
|
|
17
|
+
required?: boolean,
|
|
18
|
+
requiredVariant?: RequiredVariant
|
|
19
|
+
): RequiredDecoration | undefined => {
|
|
20
|
+
const showAsterisk = required && requiredVariant === 'asterisk'
|
|
21
|
+
|
|
22
|
+
if (showAsterisk) {
|
|
23
|
+
return 'asterisk'
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const showOptional =
|
|
27
|
+
!required && (!requiredVariant || requiredVariant === 'default')
|
|
28
|
+
|
|
29
|
+
if (showOptional) {
|
|
30
|
+
return 'optional'
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const FieldLabel = (props: Props) => {
|
|
35
|
+
const { label, required, titleCase, name, alignment } = props
|
|
36
|
+
|
|
37
|
+
const formConfig = useFormConfig()
|
|
38
|
+
|
|
39
|
+
if (!label) {
|
|
40
|
+
return null
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const requiredDecoration = getRequiredDecoration(
|
|
44
|
+
required,
|
|
45
|
+
formConfig.requiredVariant
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<PicassoForm.Label
|
|
50
|
+
requiredDecoration={requiredDecoration}
|
|
51
|
+
htmlFor={name}
|
|
52
|
+
titleCase={titleCase}
|
|
53
|
+
alignment={alignment}
|
|
54
|
+
>
|
|
55
|
+
{label}
|
|
56
|
+
</PicassoForm.Label>
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
FieldLabel.defaultProps = {}
|
|
61
|
+
|
|
62
|
+
FieldLabel.displayName = 'FieldLabel'
|
|
63
|
+
|
|
64
|
+
export default FieldLabel
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`FieldLabel renders default field label 1`] = `
|
|
4
|
+
<div>
|
|
5
|
+
<div
|
|
6
|
+
class="Picasso-root"
|
|
7
|
+
>
|
|
8
|
+
<label
|
|
9
|
+
class="PicassoFormLabel-root"
|
|
10
|
+
for="name"
|
|
11
|
+
>
|
|
12
|
+
<span
|
|
13
|
+
class="PicassoFormLabel-medium"
|
|
14
|
+
>
|
|
15
|
+
label
|
|
16
|
+
(optional)
|
|
17
|
+
</span>
|
|
18
|
+
</label>
|
|
19
|
+
</div>
|
|
20
|
+
</div>
|
|
21
|
+
`;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { render } from '@toptal/picasso-test-utils'
|
|
3
|
+
|
|
4
|
+
import { FormCompound as Form } from '../FormCompound'
|
|
5
|
+
import FieldLabel from './FieldLabel'
|
|
6
|
+
|
|
7
|
+
describe('FieldLabel', () => {
|
|
8
|
+
it('renders default field label', () => {
|
|
9
|
+
const { container } = render(<FieldLabel name='name' label='label' />)
|
|
10
|
+
|
|
11
|
+
expect(container).toMatchSnapshot()
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
describe('optional required variant', () => {
|
|
15
|
+
it('renders label with optional mark', () => {
|
|
16
|
+
const { queryByText } = render(<FieldLabel name='name' label='label' />)
|
|
17
|
+
|
|
18
|
+
expect(queryByText('label (optional)')).toBeInTheDocument()
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
it('renders label without optional mark', () => {
|
|
22
|
+
const { queryByText } = render(
|
|
23
|
+
<FieldLabel name='name' label='label' required />
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
expect(queryByText('label (optional)')).not.toBeInTheDocument()
|
|
27
|
+
expect(queryByText('label')).toBeInTheDocument()
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
describe('asterisk required variant', () => {
|
|
32
|
+
it('renders label without asterisk', () => {
|
|
33
|
+
const { queryByText } = render(
|
|
34
|
+
<Form.ConfigProvider value={{ requiredVariant: 'asterisk' }}>
|
|
35
|
+
<FieldLabel name='name' label='label' />
|
|
36
|
+
</Form.ConfigProvider>
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
expect(queryByText('*')).not.toBeInTheDocument()
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('renders label with asterisk', () => {
|
|
43
|
+
const { queryByText } = render(
|
|
44
|
+
<Form.ConfigProvider value={{ requiredVariant: 'asterisk' }}>
|
|
45
|
+
<FieldLabel name='name' label='label' required />
|
|
46
|
+
</Form.ConfigProvider>
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
expect(queryByText('*')).toBeInTheDocument()
|
|
50
|
+
})
|
|
51
|
+
})
|
|
52
|
+
})
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ReactNode } from 'react'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
|
|
4
|
+
import type { Props as FieldProps } from '../Field'
|
|
5
|
+
import type { ValueType, IFormComponentProps } from '../FieldBase'
|
|
6
|
+
import FieldLabel from '../FieldLabel'
|
|
7
|
+
import InputField from '../InputField'
|
|
8
|
+
|
|
9
|
+
export type Props<TWrappedComponentProps, TInputValue> = Omit<
|
|
10
|
+
FieldProps<TWrappedComponentProps, TInputValue>,
|
|
11
|
+
'label'
|
|
12
|
+
> & {
|
|
13
|
+
label?: ReactNode
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const FieldWrapper = <
|
|
17
|
+
TWrappedComponentProps extends IFormComponentProps,
|
|
18
|
+
TInputValue extends ValueType = TWrappedComponentProps['value']
|
|
19
|
+
>(
|
|
20
|
+
props: Props<TWrappedComponentProps, TInputValue>
|
|
21
|
+
) => {
|
|
22
|
+
const { label, name, titleCase, children, ...rest } = props
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<InputField<IFormComponentProps, TInputValue>
|
|
26
|
+
{...rest}
|
|
27
|
+
name={name}
|
|
28
|
+
label={
|
|
29
|
+
label ? (
|
|
30
|
+
<FieldLabel
|
|
31
|
+
name={props.name}
|
|
32
|
+
required={props.required}
|
|
33
|
+
label={label}
|
|
34
|
+
titleCase={titleCase}
|
|
35
|
+
/>
|
|
36
|
+
) : null
|
|
37
|
+
}
|
|
38
|
+
>
|
|
39
|
+
{children}
|
|
40
|
+
</InputField>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
FieldWrapper.defaultProps = {}
|
|
45
|
+
|
|
46
|
+
FieldWrapper.displayName = 'FieldWrapper'
|
|
47
|
+
|
|
48
|
+
export default FieldWrapper
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import FieldWrapper from '../FieldWrapper'
|
|
2
|
+
import PicassoBook from '~/.storybook/components/PicassoBook'
|
|
3
|
+
|
|
4
|
+
const componentDocs = PicassoBook.createComponentDocs(
|
|
5
|
+
FieldWrapper,
|
|
6
|
+
'FieldWrapper',
|
|
7
|
+
undefined,
|
|
8
|
+
{
|
|
9
|
+
name: {
|
|
10
|
+
name: 'name',
|
|
11
|
+
type: 'string',
|
|
12
|
+
description: 'The field name',
|
|
13
|
+
required: true,
|
|
14
|
+
},
|
|
15
|
+
label: {
|
|
16
|
+
name: 'label',
|
|
17
|
+
type: 'string',
|
|
18
|
+
description: 'The field label text',
|
|
19
|
+
},
|
|
20
|
+
hint: {
|
|
21
|
+
name: 'hint',
|
|
22
|
+
type: 'string',
|
|
23
|
+
description: 'The hint of the field with some additional information',
|
|
24
|
+
},
|
|
25
|
+
required: {
|
|
26
|
+
name: 'required',
|
|
27
|
+
type: 'boolean',
|
|
28
|
+
description: 'Makes field to be required in the form',
|
|
29
|
+
},
|
|
30
|
+
// FieldProps - https://final-form.org/docs/react-final-form/types/FieldProps
|
|
31
|
+
afterSubmit: {
|
|
32
|
+
name: 'afterSubmit',
|
|
33
|
+
type: {
|
|
34
|
+
name: 'function',
|
|
35
|
+
description: '() => void',
|
|
36
|
+
},
|
|
37
|
+
description:
|
|
38
|
+
'A callback to notify fields after submission has completed successfully',
|
|
39
|
+
},
|
|
40
|
+
allowNull: {
|
|
41
|
+
name: 'allowNull',
|
|
42
|
+
type: 'boolean',
|
|
43
|
+
description: 'By default null value is converted to empty string',
|
|
44
|
+
defaultValue: false,
|
|
45
|
+
},
|
|
46
|
+
beforeSubmit: {
|
|
47
|
+
name: 'beforeSubmit',
|
|
48
|
+
type: {
|
|
49
|
+
name: 'function',
|
|
50
|
+
description: '() => void | false',
|
|
51
|
+
},
|
|
52
|
+
description: 'A function to call just before calling onSubmit',
|
|
53
|
+
},
|
|
54
|
+
data: {
|
|
55
|
+
name: 'data',
|
|
56
|
+
type: 'object',
|
|
57
|
+
description:
|
|
58
|
+
'Initial state for arbitrary values to be placed by mutators',
|
|
59
|
+
},
|
|
60
|
+
defaultValue: {
|
|
61
|
+
name: 'defaultValue',
|
|
62
|
+
type: 'any',
|
|
63
|
+
description: 'Default value of the field upon creation',
|
|
64
|
+
},
|
|
65
|
+
format: {
|
|
66
|
+
name: 'format',
|
|
67
|
+
type: {
|
|
68
|
+
name: 'function',
|
|
69
|
+
description: '(value: any, name: string) => any',
|
|
70
|
+
},
|
|
71
|
+
description:
|
|
72
|
+
'A function that takes the value from the form values and the name of the field and formats the value to give to the input',
|
|
73
|
+
},
|
|
74
|
+
formatOnBlur: {
|
|
75
|
+
name: 'formatOnBlur',
|
|
76
|
+
type: 'boolean',
|
|
77
|
+
description:
|
|
78
|
+
'If true, the format function will only be called when the field is blurred. If false, format will be called on every render',
|
|
79
|
+
},
|
|
80
|
+
initialValue: {
|
|
81
|
+
name: 'initialValue',
|
|
82
|
+
type: 'any',
|
|
83
|
+
description: 'The initial value for the field',
|
|
84
|
+
},
|
|
85
|
+
isEqual: {
|
|
86
|
+
name: 'isEqual',
|
|
87
|
+
type: {
|
|
88
|
+
name: 'function',
|
|
89
|
+
description: '(a: any, b: any) => boolean',
|
|
90
|
+
},
|
|
91
|
+
description: 'A function to determine if two values are equal',
|
|
92
|
+
},
|
|
93
|
+
parse: {
|
|
94
|
+
name: 'parse',
|
|
95
|
+
type: {
|
|
96
|
+
name: 'function',
|
|
97
|
+
description: '(value: any, name: string) => any',
|
|
98
|
+
},
|
|
99
|
+
description:
|
|
100
|
+
"A function that takes the value from the input and name of the field and converts the value into the value you want stored as this field's value in the form",
|
|
101
|
+
},
|
|
102
|
+
status: {
|
|
103
|
+
name: 'status',
|
|
104
|
+
type: {
|
|
105
|
+
name: 'OutlinedFieldStatus',
|
|
106
|
+
description: '"default" | "error" | "success"',
|
|
107
|
+
},
|
|
108
|
+
description:
|
|
109
|
+
'The status of the field to be used by the OutlinedInput component',
|
|
110
|
+
},
|
|
111
|
+
subscription: {
|
|
112
|
+
name: 'subscription',
|
|
113
|
+
type: {
|
|
114
|
+
name: 'object',
|
|
115
|
+
description: '{ [string]: boolean }',
|
|
116
|
+
},
|
|
117
|
+
description:
|
|
118
|
+
'An object of the parts of FieldState (final-form) to subscribe to',
|
|
119
|
+
},
|
|
120
|
+
validate: {
|
|
121
|
+
name: 'validate',
|
|
122
|
+
type: {
|
|
123
|
+
name: 'function',
|
|
124
|
+
description:
|
|
125
|
+
'(value: ?any, allValues: Object, meta: ?FieldState) => ?any',
|
|
126
|
+
},
|
|
127
|
+
description:
|
|
128
|
+
'A function that takes the field value, all the values of the form and the meta data about the field and returns an error if the value is invalid, or undefined if the value is valid',
|
|
129
|
+
},
|
|
130
|
+
validateFields: {
|
|
131
|
+
name: 'validateFields',
|
|
132
|
+
type: 'string[]',
|
|
133
|
+
description:
|
|
134
|
+
'An array of field names to validate when this field changes',
|
|
135
|
+
},
|
|
136
|
+
// //
|
|
137
|
+
allFieldProps: {
|
|
138
|
+
name: '<all field props>',
|
|
139
|
+
type: 'any',
|
|
140
|
+
description:
|
|
141
|
+
'This component also accepts all the native props from the corresponding form component, ex. Form.Input accepts all the Picasso Input props',
|
|
142
|
+
},
|
|
143
|
+
autoSaveIndicator: {
|
|
144
|
+
name: 'autoSaveIndicator',
|
|
145
|
+
type: 'ReactNode',
|
|
146
|
+
description: 'instance of FormAutoSaveIndicator component',
|
|
147
|
+
},
|
|
148
|
+
}
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
export default {
|
|
152
|
+
componentDocs,
|
|
153
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Input } from '@toptal/picasso'
|
|
2
|
+
import { act, render, fireEvent } from '@toptal/picasso-test-utils'
|
|
3
|
+
import { noop } from '@toptal/picasso-utils'
|
|
4
|
+
import React from 'react'
|
|
5
|
+
|
|
6
|
+
import { FormCompound as Form } from '../FormCompound'
|
|
7
|
+
import FieldWrapper from './FieldWrapper'
|
|
8
|
+
|
|
9
|
+
const renderFieldWrapper = () =>
|
|
10
|
+
render(
|
|
11
|
+
<Form onSubmit={noop}>
|
|
12
|
+
<FieldWrapper name='name' required>
|
|
13
|
+
{(inputProps: any) => <Input {...inputProps} />}
|
|
14
|
+
</FieldWrapper>
|
|
15
|
+
|
|
16
|
+
<Form.SubmitButton data-testid='submit'>Submit</Form.SubmitButton>
|
|
17
|
+
</Form>
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
describe('FieldWrapper', () => {
|
|
21
|
+
describe('when there is a field error', () => {
|
|
22
|
+
it('passes status to its children', () => {
|
|
23
|
+
const { getByTestId, getByText } = renderFieldWrapper()
|
|
24
|
+
|
|
25
|
+
act(() => {
|
|
26
|
+
fireEvent.click(getByTestId('submit'))
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
expect(getByText('Please complete this field.')).toBeVisible()
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
})
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import type { FileInputProps, FileUpload } from '@toptal/picasso'
|
|
3
|
+
import { FileInput as PicassoFileInput } from '@toptal/picasso'
|
|
4
|
+
import type { FieldInputProps as FinalFieldInputProps } from 'react-final-form'
|
|
5
|
+
|
|
6
|
+
import type { FieldProps } from '../Field'
|
|
7
|
+
import PicassoField from '../Field'
|
|
8
|
+
import FieldLabel from '../FieldLabel'
|
|
9
|
+
|
|
10
|
+
type FinalFormOnChangeType = FinalFieldInputProps<
|
|
11
|
+
FileInputProps['value']
|
|
12
|
+
>['onChange']
|
|
13
|
+
|
|
14
|
+
export type Props = FileInputProps & FieldProps<FileInputProps['value']>
|
|
15
|
+
|
|
16
|
+
export const FileInput = (props: Props) => {
|
|
17
|
+
const handleChange = (
|
|
18
|
+
event: React.ChangeEvent<HTMLInputElement>,
|
|
19
|
+
value: FileUpload[] | undefined = [],
|
|
20
|
+
finalFormOnChange: FinalFormOnChangeType
|
|
21
|
+
) => {
|
|
22
|
+
if (!event.target || !event.target.files || !event.target.files.length) {
|
|
23
|
+
return null
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const newFiles = Array.from(event.target.files).map(file => ({
|
|
27
|
+
file,
|
|
28
|
+
uploading: false,
|
|
29
|
+
}))
|
|
30
|
+
|
|
31
|
+
finalFormOnChange([...value, ...newFiles])
|
|
32
|
+
|
|
33
|
+
// reset input
|
|
34
|
+
event.target.value = ''
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const handleRemove = (
|
|
38
|
+
fileIndex: number,
|
|
39
|
+
value: FileUpload[] | undefined = [],
|
|
40
|
+
finalFormOnChange: FinalFormOnChangeType
|
|
41
|
+
) => {
|
|
42
|
+
const updatedFiles = value.filter((_, index) => index !== fileIndex)
|
|
43
|
+
|
|
44
|
+
finalFormOnChange(updatedFiles)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<PicassoField<FileInputProps, FileUpload[] | undefined>
|
|
49
|
+
{...props}
|
|
50
|
+
label={
|
|
51
|
+
props.label ? (
|
|
52
|
+
<FieldLabel
|
|
53
|
+
name={props.name}
|
|
54
|
+
required={props.required}
|
|
55
|
+
label={props.label}
|
|
56
|
+
titleCase={props.titleCase}
|
|
57
|
+
/>
|
|
58
|
+
) : null
|
|
59
|
+
}
|
|
60
|
+
>
|
|
61
|
+
{({
|
|
62
|
+
// omit 'highlight' as it is used only for classic inputs
|
|
63
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
64
|
+
highlight,
|
|
65
|
+
...inputProps
|
|
66
|
+
}) => (
|
|
67
|
+
<PicassoFileInput
|
|
68
|
+
{...inputProps}
|
|
69
|
+
onChange={(event: React.ChangeEvent<HTMLInputElement>) => {
|
|
70
|
+
handleChange(event, inputProps.value, inputProps.onChange)
|
|
71
|
+
}}
|
|
72
|
+
onRemove={(_: string, index: number) => {
|
|
73
|
+
handleRemove(index, inputProps.value, inputProps.onChange)
|
|
74
|
+
}}
|
|
75
|
+
/>
|
|
76
|
+
)}
|
|
77
|
+
</PicassoField>
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
FileInput.defaultProps = {}
|
|
82
|
+
|
|
83
|
+
FileInput.displayName = 'FileInput'
|
|
84
|
+
|
|
85
|
+
export default FileInput
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './FileInput'
|