@x15ventures/x15-ui-library 3.15.0 → 3.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/autoGenerated/libraryThemes.js +12 -12
- package/dist/cjs/autoGenerated/libraryThemes.js.map +1 -1
- package/dist/cjs/autoGenerated/libraryThemes.json +12 -12
- package/dist/cjs/components/design/dialog/Dialog.js +1 -1
- package/dist/cjs/components/design/dialog/Dialog.js.map +1 -1
- package/dist/cjs/components/design/headerBar/HeaderBar.js +3 -1
- package/dist/cjs/components/design/headerBar/HeaderBar.js.map +1 -1
- package/dist/cjs/components/design/headerBar/headerBar.css +6 -1
- package/dist/cjs/components/design/tooltip/Tooltip.js +67 -15
- package/dist/cjs/components/design/tooltip/Tooltip.js.map +1 -1
- package/dist/cjs/components/design/tooltip/tooltip.css +1 -1
- package/dist/cjs/components/form/formFields/formFieldWrapper/FormField.js +8 -5
- package/dist/cjs/components/form/formFields/formFieldWrapper/FormField.js.map +1 -1
- package/dist/cjs/components/form/formFields/formFieldWrapper/formFieldProps.js.map +1 -1
- package/dist/cjs/components/form/formFields/subComponents/inputs/autocomplete/Autocomplete.js +15 -11
- package/dist/cjs/components/form/formFields/subComponents/inputs/autocomplete/Autocomplete.js.map +1 -1
- package/dist/cjs/components/form/formFields/subComponents/inputs/checkbox/InputCheckbox.js +37 -15
- package/dist/cjs/components/form/formFields/subComponents/inputs/checkbox/InputCheckbox.js.map +1 -1
- package/dist/cjs/components/form/formFields/subComponents/inputs/checkbox/inputCheckbox.css +4 -4
- package/dist/cjs/components/form/formFields/subComponents/inputs/checkbox/inputCheckboxProps.js.map +1 -1
- package/dist/cjs/components/form/formFields/subComponents/inputs/file/dragAndDrop/DragAndDropFileUpload.js +9 -9
- package/dist/cjs/components/form/formFields/subComponents/inputs/file/dragAndDrop/DragAndDropFileUpload.js.map +1 -1
- package/dist/cjs/components/form/formFields/subComponents/inputs/radio/styled/StyledRadioGroup.js +14 -4
- package/dist/cjs/components/form/formFields/subComponents/inputs/radio/styled/StyledRadioGroup.js.map +1 -1
- package/dist/cjs/components/form/formFields/subComponents/inputs/text/InputText.js +23 -17
- package/dist/cjs/components/form/formFields/subComponents/inputs/text/InputText.js.map +1 -1
- package/dist/cjs/components/form/formFields/subComponents/select/Select.js +6 -5
- package/dist/cjs/components/form/formFields/subComponents/select/Select.js.map +1 -1
- package/dist/cjs/components/form/formFields/subComponents/textarea/Textarea.js +55 -83
- package/dist/cjs/components/form/formFields/subComponents/textarea/Textarea.js.map +1 -1
- package/dist/cjs/components/form/formFields/subComponents/textarea/textarea.css +20 -0
- package/dist/cjs/components/form/hookFormWrapper/HookFormWrapper.js +22 -5
- package/dist/cjs/components/form/hookFormWrapper/HookFormWrapper.js.map +1 -1
- package/dist/cjs/components/form/validation/ValidationMessages.js +36 -38
- package/dist/cjs/components/form/validation/ValidationMessages.js.map +1 -1
- package/dist/cjs/exampleUIs/exampleComponents/DemoContactForm.js +1 -2
- package/dist/cjs/exampleUIs/exampleComponents/DemoContactForm.js.map +1 -1
- package/dist/cjs/helpers/index.js +12 -0
- package/dist/cjs/helpers/index.js.map +1 -1
- package/dist/cjs/helpers/stringHelpers.js +48 -2
- package/dist/cjs/helpers/stringHelpers.js.map +1 -1
- package/dist/cjs/hooks/EdgeProximityDetect.js +18 -10
- package/dist/cjs/hooks/EdgeProximityDetect.js.map +1 -1
- package/dist/cjs/interfaces/headerText.interface.js.map +1 -1
- package/dist/cjs/package.json +137 -151
- package/dist/cjs/styles/index.css +22 -25
- package/dist/cjs/styles/shared/_allPartials.css +22 -25
- package/dist/cjs/styles/shared/forms/_forms.css +22 -25
- package/dist/components/design/dialog/Dialog.d.ts.map +1 -1
- package/dist/components/design/dialog/Dialog.test.d.ts +5 -0
- package/dist/components/design/dialog/Dialog.test.d.ts.map +1 -0
- package/dist/components/design/headerBar/HeaderBar.d.ts.map +1 -1
- package/dist/components/design/tooltip/Tooltip.d.ts +2 -0
- package/dist/components/design/tooltip/Tooltip.d.ts.map +1 -1
- package/dist/components/design/tooltip/Tooltip.test.d.ts +2 -0
- package/dist/components/design/tooltip/Tooltip.test.d.ts.map +1 -0
- package/dist/components/form/formFields/formFieldWrapper/FormField.d.ts.map +1 -1
- package/dist/components/form/formFields/formFieldWrapper/formFieldProps.d.ts +7 -2
- package/dist/components/form/formFields/formFieldWrapper/formFieldProps.d.ts.map +1 -1
- package/dist/components/form/formFields/subComponents/inputs/autocomplete/Autocomplete.d.ts.map +1 -1
- package/dist/components/form/formFields/subComponents/inputs/checkbox/InputCheckbox.d.ts.map +1 -1
- package/dist/components/form/formFields/subComponents/inputs/checkbox/InputCheckbox.test.d.ts +5 -0
- package/dist/components/form/formFields/subComponents/inputs/checkbox/InputCheckbox.test.d.ts.map +1 -0
- package/dist/components/form/formFields/subComponents/inputs/checkbox/inputCheckboxProps.d.ts +8 -6
- package/dist/components/form/formFields/subComponents/inputs/checkbox/inputCheckboxProps.d.ts.map +1 -1
- package/dist/components/form/formFields/subComponents/inputs/file/dragAndDrop/DragAndDropFileUpload.d.ts.map +1 -1
- package/dist/components/form/formFields/subComponents/inputs/radio/styled/StyledRadioGroup.d.ts.map +1 -1
- package/dist/components/form/formFields/subComponents/inputs/text/InputText.d.ts.map +1 -1
- package/dist/components/form/formFields/subComponents/nestedFormContext.test.d.ts +5 -0
- package/dist/components/form/formFields/subComponents/nestedFormContext.test.d.ts.map +1 -0
- package/dist/components/form/formFields/subComponents/select/Select.d.ts.map +1 -1
- package/dist/components/form/formFields/subComponents/textarea/Textarea.d.ts +4 -3
- package/dist/components/form/formFields/subComponents/textarea/Textarea.d.ts.map +1 -1
- package/dist/components/form/hookFormWrapper/HookFormWrapper.d.ts +3 -0
- package/dist/components/form/hookFormWrapper/HookFormWrapper.d.ts.map +1 -1
- package/dist/components/form/hookFormWrapper/HookFormWrapper.test.d.ts +5 -0
- package/dist/components/form/hookFormWrapper/HookFormWrapper.test.d.ts.map +1 -0
- package/dist/components/form/validation/ValidationMessages.d.ts +8 -1
- package/dist/components/form/validation/ValidationMessages.d.ts.map +1 -1
- package/dist/components/form/validation/ValidationMessages.test.d.ts +5 -0
- package/dist/components/form/validation/ValidationMessages.test.d.ts.map +1 -0
- package/dist/esm/autoGenerated/libraryThemes.js +12 -12
- package/dist/esm/autoGenerated/libraryThemes.js.map +1 -1
- package/dist/esm/autoGenerated/libraryThemes.json +12 -12
- package/dist/esm/components/design/dialog/Dialog.js +1 -1
- package/dist/esm/components/design/dialog/Dialog.js.map +1 -1
- package/dist/esm/components/design/headerBar/HeaderBar.js +3 -1
- package/dist/esm/components/design/headerBar/HeaderBar.js.map +1 -1
- package/dist/esm/components/design/headerBar/headerBar.css +6 -1
- package/dist/esm/components/design/tooltip/Tooltip.js +67 -15
- package/dist/esm/components/design/tooltip/Tooltip.js.map +1 -1
- package/dist/esm/components/design/tooltip/tooltip.css +1 -1
- package/dist/esm/components/form/formFields/formFieldWrapper/FormField.js +8 -5
- package/dist/esm/components/form/formFields/formFieldWrapper/FormField.js.map +1 -1
- package/dist/esm/components/form/formFields/formFieldWrapper/formFieldProps.js.map +1 -1
- package/dist/esm/components/form/formFields/subComponents/inputs/autocomplete/Autocomplete.js +16 -12
- package/dist/esm/components/form/formFields/subComponents/inputs/autocomplete/Autocomplete.js.map +1 -1
- package/dist/esm/components/form/formFields/subComponents/inputs/checkbox/InputCheckbox.js +37 -15
- package/dist/esm/components/form/formFields/subComponents/inputs/checkbox/InputCheckbox.js.map +1 -1
- package/dist/esm/components/form/formFields/subComponents/inputs/checkbox/inputCheckbox.css +4 -4
- package/dist/esm/components/form/formFields/subComponents/inputs/checkbox/inputCheckboxProps.js.map +1 -1
- package/dist/esm/components/form/formFields/subComponents/inputs/file/dragAndDrop/DragAndDropFileUpload.js +8 -8
- package/dist/esm/components/form/formFields/subComponents/inputs/file/dragAndDrop/DragAndDropFileUpload.js.map +1 -1
- package/dist/esm/components/form/formFields/subComponents/inputs/radio/styled/StyledRadioGroup.js +16 -6
- package/dist/esm/components/form/formFields/subComponents/inputs/radio/styled/StyledRadioGroup.js.map +1 -1
- package/dist/esm/components/form/formFields/subComponents/inputs/text/InputText.js +23 -17
- package/dist/esm/components/form/formFields/subComponents/inputs/text/InputText.js.map +1 -1
- package/dist/esm/components/form/formFields/subComponents/select/Select.js +6 -5
- package/dist/esm/components/form/formFields/subComponents/select/Select.js.map +1 -1
- package/dist/esm/components/form/formFields/subComponents/textarea/Textarea.js +50 -78
- package/dist/esm/components/form/formFields/subComponents/textarea/Textarea.js.map +1 -1
- package/dist/esm/components/form/formFields/subComponents/textarea/textarea.css +20 -0
- package/dist/esm/components/form/hookFormWrapper/HookFormWrapper.js +22 -5
- package/dist/esm/components/form/hookFormWrapper/HookFormWrapper.js.map +1 -1
- package/dist/esm/components/form/validation/ValidationMessages.js +36 -38
- package/dist/esm/components/form/validation/ValidationMessages.js.map +1 -1
- package/dist/esm/exampleUIs/exampleComponents/DemoContactForm.js +1 -2
- package/dist/esm/exampleUIs/exampleComponents/DemoContactForm.js.map +1 -1
- package/dist/esm/helpers/index.js +1 -1
- package/dist/esm/helpers/index.js.map +1 -1
- package/dist/esm/helpers/stringHelpers.js +44 -0
- package/dist/esm/helpers/stringHelpers.js.map +1 -1
- package/dist/esm/hooks/EdgeProximityDetect.js +19 -11
- package/dist/esm/hooks/EdgeProximityDetect.js.map +1 -1
- package/dist/esm/interfaces/headerText.interface.js.map +1 -1
- package/dist/esm/package.json +137 -151
- package/dist/esm/styles/index.css +22 -25
- package/dist/esm/styles/shared/_allPartials.css +22 -25
- package/dist/esm/styles/shared/forms/_forms.css +22 -25
- package/dist/exampleUIs/exampleComponents/DemoContactForm.d.ts.map +1 -1
- package/dist/helpers/index.d.ts +1 -1
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/stringHelpers.d.ts +17 -0
- package/dist/helpers/stringHelpers.d.ts.map +1 -1
- package/dist/hooks/EdgeProximityDetect.d.ts.map +1 -1
- package/dist/interfaces/headerText.interface.d.ts +1 -0
- package/dist/interfaces/headerText.interface.d.ts.map +1 -1
- package/dist/package.json +137 -151
- package/package.json +137 -151
- package/dist/cjs/components/form/formFields/utilities/formUtilities.js +0 -22
- package/dist/cjs/components/form/formFields/utilities/formUtilities.js.map +0 -1
- package/dist/components/form/formFields/utilities/formUtilities.d.ts +0 -18
- package/dist/components/form/formFields/utilities/formUtilities.d.ts.map +0 -1
- package/dist/esm/components/form/formFields/utilities/formUtilities.js +0 -16
- package/dist/esm/components/form/formFields/utilities/formUtilities.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DragAndDropFileUpload.js","names":["React","useCallback","useEffect","useMemo","useRef","useState","arrowUpFromBracket","SvgIcon","useFormContext","HookFormWrapper","Spinner","FormFieldLabel","InputFile","ValidationMessages","NoHookFormContext","generateButtonClass","FileAttachmentsList","DEFAULT_UPLOAD_FILE_EXTENSIONS","DEFAULT_UPLOAD_FILE_TYPES","BLACKLISTED_FILE_TYPES","DragAndDropFileUpload","label","field","showSpinner","fileDisplayStyle","fileListSettings","fileList","validation","customContent","customCssClasses","labelStyle","labelAsButtonStyles","color","variant","labelUploadIcon","createElement","svgDefinition","multiple","restrictionsTxt","validFiles","extensions","fileTypes","maxFileCount","maxFileSize","onFilesChange","setValue","trigger","setError","activeFileList","setFileList","isTouched","setIsTouched","isDragActive","setIsDragActive","inputId","id","inputElRef","dialogOpenRef","current","document","getElementById","onFocus","noneSelected","files","length","name","window","addEventListener","removeEventListener","supportedFileTypes","join","validateAndCommit","validated","filter","file","ext","split","pop","toLowerCase","isBlacklisted","includes","isValidExt","isValidSize","size","clipped","slice","shouldValidate","shouldDirty","shouldTouch","handleFileInputChange","event","target","Array","from","handleDrop","dropped","handleFilesEdited","wrapperCssClass","wrapper","position","labelProps","isRequired","required","labelStyleAsButtonClasses","cssClass","buttonStyle","hideLabel","hide","labelCssClass","className","onDragOver","e","preventDefault","onDragLeave","currentTarget","onDrop","dataTransfer","labelId","htmlFor","onClick","type","defaultValue","accept","onInput","map","index","key","customFileListSettings","onFilesRemoved","onFilesEdited"],"sources":["../../../../../../../../../src/components/form/formFields/subComponents/inputs/file/dragAndDrop/DragAndDropFileUpload.tsx"],"sourcesContent":["'use client';\n\n/* eslint-disable no-unused-vars */\nimport React, { FormEvent, useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport { arrowUpFromBracket } from '@x15ventures/x15-ui-library-icons/iconDefinitions';\nimport { SvgIcon } from '@x15ventures/x15-ui-library-icons/svgIcon/SvgIcon';\nimport { useFormContext } from 'react-hook-form';\nimport { HookFormWrapper } from '../../../../../hookFormWrapper/HookFormWrapper';\nimport { Spinner } from '../../../../../../design/spinner/Spinner';\nimport { FormFieldLabel } from '../../../../subComponents/labels/FormFieldLabel';\nimport { InputFile } from '../../../../subComponents/inputs/file/InputFile';\nimport { ValidationMessages } from '../../../../../validation/ValidationMessages';\nimport { NoHookFormContext } from '../../../../utilities/formUtilities';\nimport { generateButtonClass } from '../../../../../buttons/button.helpers';\nimport { FileAttachmentsList } from '../fileAttachmentList/FileAttachmentsList';\nimport { DragAndDropFileUploadProps } from '../fileInputProps';\nimport {\n DEFAULT_UPLOAD_FILE_EXTENSIONS,\n DEFAULT_UPLOAD_FILE_TYPES,\n BLACKLISTED_FILE_TYPES\n} from '../../../../../../../constants';\n\nimport './dragAndDropFileUpload.scss';\n\nexport const DragAndDropFileUpload: React.FC<DragAndDropFileUploadProps> = (\n {\n label,\n field,\n showSpinner,\n fileDisplayStyle = 'names',\n fileListSettings,\n fileList,\n validation,\n customContent,\n customCssClasses,\n labelStyle = 'dragArea',\n labelAsButtonStyles = { color: 'primary', variant: 'outline' },\n labelUploadIcon = <SvgIcon svgDefinition={ arrowUpFromBracket } />,\n multiple = false,\n restrictionsTxt = '',\n validFiles = {\n extensions: DEFAULT_UPLOAD_FILE_EXTENSIONS,\n fileTypes: DEFAULT_UPLOAD_FILE_TYPES,\n maxFileCount: 5,\n maxFileSize: 52428800 // 50 MB\n },\n onFilesChange = () => {}\n }\n) => {\n const { setValue, trigger, setError } = useFormContext() || NoHookFormContext;\n\n const [activeFileList, setFileList] = useState<File[]>(fileList || []);\n const [isTouched, setIsTouched] = useState(false);\n const [isDragActive, setIsDragActive] = useState(false);\n\n const inputId = field.id;\n const inputElRef = useRef<HTMLInputElement | null>(null);\n const dialogOpenRef = useRef(false);\n\n useEffect(() => {\n inputElRef.current = document.getElementById(inputId) as HTMLInputElement | null;\n }, [inputId]);\n\n // Detect “Cancel” -> dialog closes, window regains focus, but input had no change.\n useEffect(() => {\n const onFocus = () => {\n if (!dialogOpenRef.current) { return; }\n dialogOpenRef.current = false;\n const noneSelected = !inputElRef.current?.files?.length;\n if (noneSelected) {\n // Trigger React Hook Form validators (e.g., required)\n trigger(field.name);\n }\n };\n window.addEventListener('focus', onFocus);\n return () => window.removeEventListener('focus', onFocus);\n }, [trigger, field.name]);\n\n const supportedFileTypes = useMemo(\n () => validFiles?.fileTypes?.join(', ') || '',\n [validFiles?.fileTypes]\n );\n\n const validateAndCommit = useCallback(\n (files: File[]) => {\n // basic validations\n const validated = files.filter((file) => {\n const ext = file.name.split('.').pop()?.toLowerCase() || '';\n const isBlacklisted = BLACKLISTED_FILE_TYPES.includes(ext);\n const isValidExt = validFiles.extensions ? validFiles.extensions.includes(ext) : true;\n const isValidSize = validFiles.maxFileSize ? file.size <= validFiles.maxFileSize : true;\n return !isBlacklisted && isValidExt && isValidSize;\n });\n\n const clipped = validFiles.maxFileCount\n ? validated.slice(0, validFiles.maxFileCount)\n : validated;\n\n setFileList(clipped);\n setIsTouched(true);\n\n setValue(field.name, clipped.length ? clipped : null, {\n shouldValidate: true,\n shouldDirty: true,\n shouldTouch: true\n });\n\n onFilesChange(clipped);\n },\n [field.name, onFilesChange, setValue, fileDisplayStyle, validFiles]\n );\n\n const handleFileInputChange = useCallback((event: FormEvent<HTMLInputElement>) => {\n const target = event.target as HTMLInputElement;\n const files = Array.from(target.files ?? []);\n validateAndCommit(files);\n trigger(field.name);\n dialogOpenRef.current = false;\n }, [trigger, field.name, validateAndCommit]);\n\n const handleDrop = useCallback((dropped: File[]) => {\n validateAndCommit(dropped);\n trigger(field.name);\n }, [trigger, field.name, validateAndCommit]);\n\n const handleFilesEdited = useCallback((files: File[]) => {\n // No need to validate again as they were already validated\n // Changes may include renaming or removing files\n setFileList(files);\n setValue(field.name, files.length > 0 ? files : null, {\n shouldValidate: true,\n shouldDirty: true,\n shouldTouch: true\n });\n onFilesChange(files);\n }, [field.name, setValue, onFilesChange]);\n\n const wrapperCssClass = `\n formField \n dragAndDropFileUpload \n ${ fileDisplayStyle === 'list' ? 'withFileList' : '' } \n ${ labelStyle || '' }Style \n ${ customCssClasses?.wrapper || '' } \n ${ isTouched ? 'touched' : '' } \n ${ typeof validation !== 'undefined' ? 'withValidation' : '' } \n ${ label?.position === 'inset' ? 'insetLabel' : '' } \n ${ isDragActive ? 'isDragActive' : '' }\n `;\n\n const labelProps = {\n ...label,\n inputId: inputId,\n isRequired: validation && typeof validation.required !== 'undefined',\n customContent\n };\n\n const labelStyleAsButtonClasses = generateButtonClass({\n cssClass: 'button dragAndDropFileUploadButtonLabel',\n buttonStyle: labelAsButtonStyles,\n hideLabel: label.hide\n });\n\n const labelCssClass = `\n ${ labelStyle === 'button' ? labelStyleAsButtonClasses : '' }\n ${ customCssClasses?.label || '' } \n ${ showSpinner ? 'withSpinner' : '' } \n ${ label.hide ? 'hiddenLabel' : '' }\n `;\n\n return (\n <HookFormWrapper>\n <div\n className={ wrapperCssClass }\n onDragOver={ (e) => {\n e.preventDefault();\n if (!isDragActive) setIsDragActive(true);\n } }\n onDragLeave={ (e) => {\n if (e.currentTarget === e.target) setIsDragActive(false);\n } }\n onDrop={ (e) => {\n e.preventDefault();\n setIsDragActive(false);\n const files = Array.from(e.dataTransfer?.files ?? []);\n handleDrop(files);\n } }\n >\n <label\n id={ label.labelId || `${ inputId }_label` }\n className={ labelCssClass }\n htmlFor={ inputId }\n onClick={ () => { dialogOpenRef.current = true; } }\n >\n <span className=\"dragAndDropFileUploadLabel\">\n { labelUploadIcon || null }\n <FormFieldLabel { ...labelProps } />\n { restrictionsTxt && <span className=\"fileRestrictionsText\">{ restrictionsTxt }</span> }\n </span>\n\n <span className=\"inputContainer\">\n <InputFile\n {\n ...{\n label,\n field: {\n ...field,\n type: 'file',\n id: inputId, // ensure we can query it by id\n defaultValue: '',\n multiple,\n accept: supportedFileTypes,\n onInput: (event: FormEvent<HTMLInputElement>) => {\n handleFileInputChange(event);\n }\n },\n validation,\n showSpinner,\n customCssClasses,\n customContent\n }\n }\n />\n </span>\n\n { showSpinner && <Spinner /> }\n\n { fileDisplayStyle === 'names' && activeFileList.length > 0 && (\n <span className=\"uploadedFileNames\">\n { activeFileList.map((file, index) => (\n <small key={ index } className=\"uploadedFileName\">\n { file.name }{ index < activeFileList.length - 1 ? ', ' : '' }\n </small>\n )) }\n </span>\n ) }\n\n <ValidationMessages name={ field.name } validation={ validation } />\n </label>\n\n { fileDisplayStyle === 'list' && activeFileList.length > 0 && (\n <FileAttachmentsList\n customFileListSettings={ fileListSettings }\n files={ activeFileList }\n onFilesRemoved={ handleFilesEdited }\n onFilesEdited={ handleFilesEdited }\n />\n ) }\n </div>\n </HookFormWrapper>\n );\n};\n\nexport default { DragAndDropFileUpload };\n"],"mappings":"AAAA,YAAY;;AAEZ;AACA,OAAOA,KAAK,IAAeC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAC3F,SAASC,kBAAkB,QAAQ,mDAAmD;AACtF,SAASC,OAAO,QAAQ,mDAAmD;AAC3E,SAASC,cAAc,QAAQ,iBAAiB;AAChD,SAASC,eAAe,QAAQ,gDAAgD;AAChF,SAASC,OAAO,QAAQ,0CAA0C;AAClE,SAASC,cAAc,QAAQ,iDAAiD;AAChF,SAASC,SAAS,QAAQ,iDAAiD;AAC3E,SAASC,kBAAkB,QAAQ,8CAA8C;AACjF,SAASC,iBAAiB,QAAQ,q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AAAmC,aAAA,CAACtB,kBAAkB;IAACoD,IAAI,EAAG3C,KAAK,CAAC2C,IAAM;IAACtC,UAAU,EAAGA;EAAY,CAAE,CAC9D,CAAC,EAENH,gBAAgB,KAAK,MAAM,IAAIwB,cAAc,CAACgB,MAAM,GAAG,CAAC,iBACxDhE,KAAA,CAAAmC,aAAA,CAACnB,mBAAmB;IAClB+G,sBAAsB,EAAGtG,gBAAkB;IAC3CsC,KAAK,EAAGf,cAAgB;IACxBgF,cAAc,EAAGhC,iBAAmB;IACpCiC,aAAa,EAAGjC;EAAmB,CACpC,CAEA,CACU,CAAC;AAEtB,CAAC;AAED,eAAe;EAAE5E;AAAsB,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"DragAndDropFileUpload.js","names":["React","useCallback","useEffect","useMemo","useRef","useState","arrowUpFromBracket","SvgIcon","useFormContext","HookFormWrapper","Spinner","FormFieldLabel","InputFile","ValidationMessages","generateButtonClass","FileAttachmentsList","DEFAULT_UPLOAD_FILE_EXTENSIONS","DEFAULT_UPLOAD_FILE_TYPES","BLACKLISTED_FILE_TYPES","DragAndDropFileUpload","props","createElement","formContext","DragAndDropFileUploadField","label","field","showSpinner","fileDisplayStyle","fileListSettings","fileList","validation","customContent","customCssClasses","labelStyle","labelAsButtonStyles","color","variant","labelUploadIcon","svgDefinition","multiple","restrictionsTxt","validFiles","extensions","fileTypes","maxFileCount","maxFileSize","onFilesChange","setValue","trigger","activeFileList","setFileList","isTouched","setIsTouched","isDragActive","setIsDragActive","inputId","id","inputElRef","dialogOpenRef","current","document","getElementById","onFocus","noneSelected","files","length","name","window","addEventListener","removeEventListener","supportedFileTypes","join","validateAndCommit","validated","filter","file","ext","split","pop","toLowerCase","isBlacklisted","includes","isValidExt","isValidSize","size","clipped","slice","shouldValidate","shouldDirty","shouldTouch","handleFileInputChange","event","target","Array","from","handleDrop","dropped","handleFilesEdited","wrapperCssClass","wrapper","position","labelProps","isRequired","required","labelStyleAsButtonClasses","cssClass","buttonStyle","hideLabel","hide","labelCssClass","className","onDragOver","e","preventDefault","onDragLeave","currentTarget","onDrop","dataTransfer","labelId","htmlFor","onClick","type","defaultValue","accept","onInput","map","index","key","customFileListSettings","onFilesRemoved","onFilesEdited"],"sources":["../../../../../../../../../src/components/form/formFields/subComponents/inputs/file/dragAndDrop/DragAndDropFileUpload.tsx"],"sourcesContent":["'use client';\n\nimport React, { FormEvent, useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport { arrowUpFromBracket } from '@x15ventures/x15-ui-library-icons/iconDefinitions';\nimport { SvgIcon } from '@x15ventures/x15-ui-library-icons/svgIcon/SvgIcon';\nimport { useFormContext } from 'react-hook-form';\nimport { HookFormWrapper } from '../../../../../hookFormWrapper/HookFormWrapper';\nimport { Spinner } from '../../../../../../design/spinner/Spinner';\nimport { FormFieldLabel } from '../../../../subComponents/labels/FormFieldLabel';\nimport { InputFile } from '../../../../subComponents/inputs/file/InputFile';\nimport { ValidationMessages } from '../../../../../validation/ValidationMessages';\nimport { generateButtonClass } from '../../../../../buttons/button.helpers';\nimport { FileAttachmentsList } from '../fileAttachmentList/FileAttachmentsList';\nimport { DragAndDropFileUploadProps } from '../fileInputProps';\nimport {\n DEFAULT_UPLOAD_FILE_EXTENSIONS,\n DEFAULT_UPLOAD_FILE_TYPES,\n BLACKLISTED_FILE_TYPES\n} from '../../../../../../../constants';\n\nimport './dragAndDropFileUpload.scss';\n\nexport const DragAndDropFileUpload: React.FC<DragAndDropFileUploadProps> = (props) => (\n <HookFormWrapper formContext={ props.formContext }>\n <DragAndDropFileUploadField { ...props } />\n </HookFormWrapper>\n);\n\nconst DragAndDropFileUploadField: React.FC<DragAndDropFileUploadProps> = (\n {\n label,\n field,\n showSpinner,\n fileDisplayStyle = 'names',\n fileListSettings,\n fileList,\n validation,\n customContent,\n customCssClasses,\n labelStyle = 'dragArea',\n labelAsButtonStyles = { color: 'primary', variant: 'outline' },\n labelUploadIcon = <SvgIcon svgDefinition={ arrowUpFromBracket } />,\n multiple = false,\n restrictionsTxt = '',\n validFiles = {\n extensions: DEFAULT_UPLOAD_FILE_EXTENSIONS,\n fileTypes: DEFAULT_UPLOAD_FILE_TYPES,\n maxFileCount: 5,\n maxFileSize: 52428800 // 50 MB\n },\n onFilesChange = () => {}\n }\n) => {\n const { setValue, trigger } = useFormContext();\n\n const [activeFileList, setFileList] = useState<File[]>(fileList || []);\n const [isTouched, setIsTouched] = useState(false);\n const [isDragActive, setIsDragActive] = useState(false);\n\n const inputId = field.id;\n const inputElRef = useRef<HTMLInputElement | null>(null);\n const dialogOpenRef = useRef(false);\n\n useEffect(() => {\n inputElRef.current = document.getElementById(inputId) as HTMLInputElement | null;\n }, [inputId]);\n\n // Detect “Cancel” -> dialog closes, window regains focus, but input had no change.\n useEffect(() => {\n const onFocus = () => {\n if (!dialogOpenRef.current) { return; }\n dialogOpenRef.current = false;\n const noneSelected = !inputElRef.current?.files?.length;\n if (noneSelected) {\n // Trigger React Hook Form validators (e.g., required)\n trigger(field.name);\n }\n };\n window.addEventListener('focus', onFocus);\n return () => window.removeEventListener('focus', onFocus);\n }, [trigger, field.name]);\n\n const supportedFileTypes = useMemo(\n () => validFiles?.fileTypes?.join(', ') || '',\n [validFiles?.fileTypes]\n );\n\n const validateAndCommit = useCallback(\n (files: File[]) => {\n // basic validations\n const validated = files.filter((file) => {\n const ext = file.name.split('.').pop()?.toLowerCase() || '';\n const isBlacklisted = BLACKLISTED_FILE_TYPES.includes(ext);\n const isValidExt = validFiles.extensions ? validFiles.extensions.includes(ext) : true;\n const isValidSize = validFiles.maxFileSize ? file.size <= validFiles.maxFileSize : true;\n return !isBlacklisted && isValidExt && isValidSize;\n });\n\n const clipped = validFiles.maxFileCount\n ? validated.slice(0, validFiles.maxFileCount)\n : validated;\n\n setFileList(clipped);\n setIsTouched(true);\n\n setValue(field.name, clipped.length ? clipped : null, {\n shouldValidate: true,\n shouldDirty: true,\n shouldTouch: true\n });\n\n onFilesChange(clipped);\n },\n [field.name, onFilesChange, setValue, fileDisplayStyle, validFiles]\n );\n\n const handleFileInputChange = useCallback((event: FormEvent<HTMLInputElement>) => {\n const target = event.target as HTMLInputElement;\n const files = Array.from(target.files ?? []);\n validateAndCommit(files);\n trigger(field.name);\n dialogOpenRef.current = false;\n }, [trigger, field.name, validateAndCommit]);\n\n const handleDrop = useCallback((dropped: File[]) => {\n validateAndCommit(dropped);\n trigger(field.name);\n }, [trigger, field.name, validateAndCommit]);\n\n const handleFilesEdited = useCallback((files: File[]) => {\n // No need to validate again as they were already validated\n // Changes may include renaming or removing files\n setFileList(files);\n setValue(field.name, files.length > 0 ? files : null, {\n shouldValidate: true,\n shouldDirty: true,\n shouldTouch: true\n });\n onFilesChange(files);\n }, [field.name, setValue, onFilesChange]);\n\n const wrapperCssClass = `\n formField \n dragAndDropFileUpload \n ${ fileDisplayStyle === 'list' ? 'withFileList' : '' } \n ${ labelStyle || '' }Style \n ${ customCssClasses?.wrapper || '' } \n ${ isTouched ? 'touched' : '' } \n ${ typeof validation !== 'undefined' ? 'withValidation' : '' } \n ${ label?.position === 'inset' ? 'insetLabel' : '' } \n ${ isDragActive ? 'isDragActive' : '' }\n `;\n\n const labelProps = {\n ...label,\n inputId: inputId,\n isRequired: validation && typeof validation.required !== 'undefined',\n customContent\n };\n\n const labelStyleAsButtonClasses = generateButtonClass({\n cssClass: 'button dragAndDropFileUploadButtonLabel',\n buttonStyle: labelAsButtonStyles,\n hideLabel: label.hide\n });\n\n const labelCssClass = `\n ${ labelStyle === 'button' ? labelStyleAsButtonClasses : '' }\n ${ customCssClasses?.label || '' } \n ${ showSpinner ? 'withSpinner' : '' } \n ${ label.hide ? 'hiddenLabel' : '' }\n `;\n\n return (\n <div\n className={ wrapperCssClass }\n onDragOver={ (e) => {\n e.preventDefault();\n if (!isDragActive) setIsDragActive(true);\n } }\n onDragLeave={ (e) => {\n if (e.currentTarget === e.target) setIsDragActive(false);\n } }\n onDrop={ (e) => {\n e.preventDefault();\n setIsDragActive(false);\n const files = Array.from(e.dataTransfer?.files ?? []);\n handleDrop(files);\n } }\n >\n <label\n id={ label.labelId || `${ inputId }_label` }\n className={ labelCssClass }\n htmlFor={ inputId }\n onClick={ () => { dialogOpenRef.current = true; } }\n >\n <span className=\"dragAndDropFileUploadLabel\">\n { labelUploadIcon || null }\n <FormFieldLabel { ...labelProps } />\n { restrictionsTxt && <span className=\"fileRestrictionsText\">{ restrictionsTxt }</span> }\n </span>\n\n <span className=\"inputContainer\">\n <InputFile\n {\n ...{\n label,\n field: {\n ...field,\n type: 'file',\n id: inputId, // ensure we can query it by id\n defaultValue: '',\n multiple,\n accept: supportedFileTypes,\n onInput: (event: FormEvent<HTMLInputElement>) => {\n handleFileInputChange(event);\n }\n },\n validation,\n showSpinner,\n customCssClasses,\n customContent\n }\n }\n />\n </span>\n\n { showSpinner && <Spinner /> }\n\n { fileDisplayStyle === 'names' && activeFileList.length > 0 && (\n <span className=\"uploadedFileNames\">\n { activeFileList.map((file, index) => (\n <small key={ index } className=\"uploadedFileName\">\n { file.name }{ index < activeFileList.length - 1 ? ', ' : '' }\n </small>\n )) }\n </span>\n ) }\n\n <ValidationMessages name={ field.name } validation={ validation } />\n </label>\n\n { fileDisplayStyle === 'list' && activeFileList.length > 0 && (\n <FileAttachmentsList\n customFileListSettings={ fileListSettings }\n files={ activeFileList }\n onFilesRemoved={ handleFilesEdited }\n onFilesEdited={ handleFilesEdited }\n />\n ) }\n </div>\n );\n};\n\nexport default { DragAndDropFileUpload };\n"],"mappings":"AAAA,YAAY;;AAEZ,OAAOA,KAAK,IAAeC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAC3F,SAASC,kBAAkB,QAAQ,mDAAmD;AACtF,SAASC,OAAO,QAAQ,mDAAmD;AAC3E,SAASC,cAAc,QAAQ,iBAAiB;AAChD,SAASC,eAAe,QAAQ,gDAAgD;AAChF,SAASC,OAAO,QAAQ,0CAA0C;AAClE,SAASC,cAAc,QAA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EAAGD,KAAO;IAAChB,SAAS,EAAC;EAAkB,GAC7CnC,IAAI,CAACT,IAAI,EAAI4D,KAAK,GAAG7E,cAAc,CAACgB,MAAM,GAAG,CAAC,GAAG,IAAI,GAAG,EACrD,CACR,CACG,CACP,eAEDjE,KAAA,CAAAqB,aAAA,CAACR,kBAAkB;IAACqD,IAAI,EAAGzC,KAAK,CAACyC,IAAM;IAACpC,UAAU,EAAGA;EAAY,CAAE,CAC9D,CAAC,EAENH,gBAAgB,KAAK,MAAM,IAAIsB,cAAc,CAACgB,MAAM,GAAG,CAAC,iBACxDjE,KAAA,CAAAqB,aAAA,CAACN,mBAAmB;IAClBiH,sBAAsB,EAAGpG,gBAAkB;IAC3CoC,KAAK,EAAGf,cAAgB;IACxBgF,cAAc,EAAGhC,iBAAmB;IACpCiC,aAAa,EAAGjC;EAAmB,CACpC,CAEA,CAAC;AAEV,CAAC;AAED,eAAe;EAAE9E;AAAsB,CAAC","ignoreList":[]}
|
package/dist/esm/components/form/formFields/subComponents/inputs/radio/styled/StyledRadioGroup.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import _extends from "@babel/runtime/helpers/extends";
|
|
4
|
-
import React, { useRef, useState } from 'react';
|
|
5
|
-
import { useFormContext } from 'react-hook-form';
|
|
4
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
5
|
+
import { useFormContext, useWatch } from 'react-hook-form';
|
|
6
6
|
import { useTabbableInputGroup } from '../../../../../../../hooks';
|
|
7
7
|
import { FormFieldLabel } from '../../../labels/FormFieldLabel';
|
|
8
8
|
import { StyledRadioInput } from './StyledRadioInput';
|
|
@@ -26,11 +26,19 @@ export const StyledRadioGroup = ({
|
|
|
26
26
|
}) => {
|
|
27
27
|
const [isTouched, setIsTouched] = useState(false);
|
|
28
28
|
const {
|
|
29
|
-
|
|
29
|
+
control,
|
|
30
30
|
setValue
|
|
31
31
|
} = useFormContext();
|
|
32
|
-
const
|
|
32
|
+
const groupValue = useWatch({
|
|
33
|
+
control,
|
|
34
|
+
name: groupName
|
|
35
|
+
});
|
|
33
36
|
const radioInputsGroup = useRef(null);
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (typeof defaultGroupValue !== 'undefined') {
|
|
39
|
+
setValue(groupName, defaultGroupValue);
|
|
40
|
+
}
|
|
41
|
+
}, [defaultGroupValue, groupName, setValue]);
|
|
34
42
|
useTabbableInputGroup({
|
|
35
43
|
groupWrappingElementRef: radioInputsGroup
|
|
36
44
|
});
|
|
@@ -39,8 +47,10 @@ export const StyledRadioGroup = ({
|
|
|
39
47
|
target
|
|
40
48
|
} = event;
|
|
41
49
|
const newValue = target.value;
|
|
42
|
-
setValue(groupName, newValue
|
|
43
|
-
|
|
50
|
+
setValue(groupName, newValue, {
|
|
51
|
+
shouldValidate: true,
|
|
52
|
+
shouldDirty: true
|
|
53
|
+
});
|
|
44
54
|
setIsTouched(true);
|
|
45
55
|
onChange(newValue);
|
|
46
56
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StyledRadioGroup.js","names":["_extends","React","useRef","useState","useFormContext","useTabbableInputGroup","FormFieldLabel","StyledRadioInput","ValidationMessages","Spinner","StyledRadioGroup","group","id","name","groupName","value","defaultGroupValue","label","layout","validation","showSpinner","customCssClasses","customContent","onChange","radioInputs","isTouched","setIsTouched","
|
|
1
|
+
{"version":3,"file":"StyledRadioGroup.js","names":["_extends","React","useEffect","useRef","useState","useFormContext","useWatch","useTabbableInputGroup","FormFieldLabel","StyledRadioInput","ValidationMessages","Spinner","StyledRadioGroup","group","id","name","groupName","value","defaultGroupValue","label","layout","validation","showSpinner","customCssClasses","customContent","onChange","radioInputs","isTouched","setIsTouched","control","setValue","groupValue","radioInputsGroup","groupWrappingElementRef","HandleOnChange","event","target","newValue","shouldValidate","shouldDirty","wrapperCssClass","wrapper","position","labelProps","isRequired","required","createElement","onBlur","className","hide","ref","length","map","radioInput","key","field","isChecked","defaultChecked"],"sources":["../../../../../../../../../src/components/form/formFields/subComponents/inputs/radio/styled/StyledRadioGroup.tsx"],"sourcesContent":["'use client';\n\nimport React, { useEffect, useRef, useState } from 'react';\nimport { useFormContext, useWatch } from 'react-hook-form';\nimport { StyledRadioGroupProps } from '../radioInputsProps';\nimport { useTabbableInputGroup } from '../../../../../../../hooks';\nimport { FormFieldLabel } from '../../../labels/FormFieldLabel';\nimport { StyledRadioInput } from './StyledRadioInput';\nimport { ValidationMessages } from '../../../../../validation/ValidationMessages';\nimport { Spinner } from '../../../../../../design/spinner/Spinner';\n\nimport './styledRadioGroup.scss';\n\nexport const StyledRadioGroup: React.FC<StyledRadioGroupProps> = (\n {\n group: {\n id,\n name: groupName,\n value: defaultGroupValue,\n label,\n layout,\n validation,\n showSpinner,\n customCssClasses,\n customContent,\n onChange = () => {}\n },\n radioInputs\n }\n) => {\n const [isTouched, setIsTouched] = useState(false);\n const { control, setValue } = useFormContext();\n const groupValue = useWatch({ control, name: groupName });\n const radioInputsGroup = useRef(null);\n\n useEffect(() => {\n if (typeof defaultGroupValue !== 'undefined') {\n setValue(groupName, defaultGroupValue);\n }\n }, [defaultGroupValue, groupName, setValue]);\n\n useTabbableInputGroup({ groupWrappingElementRef: radioInputsGroup });\n\n const HandleOnChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n const { target } = event;\n const newValue = target.value;\n setValue(groupName, newValue, { shouldValidate: true, shouldDirty: true });\n setIsTouched(true);\n onChange(newValue);\n };\n\n const wrapperCssClass = `formField styledRadiosGroup ${ layout || '' } ${ isTouched ? 'touched' : '' } ${ customCssClasses?.wrapper || '' } ${ label?.position || '' }`;\n\n const labelProps = {\n ...label,\n isRequired: validation && typeof validation.required !== 'undefined',\n customContent\n };\n\n return (\n <fieldset id={ id } onBlur={ () => setIsTouched(true) } className={ wrapperCssClass }>\n <span className=\"sr-only\">\n Screen reader users are advised that this radio group supports\n custom keyboard navigation between radio options via tabbing.\n </span>\n\n <legend className={ label.hide ? 'sr-only' : '' }><FormFieldLabel { ...labelProps } /></legend>\n\n <div ref={ radioInputsGroup } className={ `radioInputs radioInputs_${ radioInputs.length }` }>\n {\n radioInputs.map((radioInput) => (\n <StyledRadioInput\n key={ radioInput.field.id }\n {\n ...{\n ...radioInput,\n label: {\n ...radioInput.label,\n isChecked: groupValue === radioInput.field.value\n },\n field: {\n ...radioInput.field,\n defaultChecked: groupValue === radioInput.field.value,\n groupName,\n onChange: HandleOnChange\n }\n }\n }\n />\n ))\n }\n </div>\n\n {\n showSpinner && <Spinner />\n }\n\n <ValidationMessages name={ groupName } validation={ validation } />\n </fieldset>\n );\n};\n\nexport default StyledRadioGroup;\n"],"mappings":"AAAA,YAAY;;AAAC,OAAAA,QAAA;AAEb,OAAOC,KAAK,IAAIC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAC1D,SAASC,cAAc,EAAEC,QAAQ,QAAQ,iBAAiB;AAE1D,SAASC,qBAAqB,QAAQ,4BAA4B;AAClE,SAASC,cAAc,QAAQ,gCAAgC;AAC/D,SAASC,gBAAgB,QAAQ,oBAAoB;AACrD,SAASC,kBAAkB,QAAQ,8CAA8C;AACjF,SAASC,OAAO,QAAQ,0CAA0C;AAElE,OAAO,yBAAyB;AAEhC,OAAO,MAAMC,gBAAiD,GAAGA,CAC/D;EACEC,KAAK,EAAE;IACLC,EAAE;IACFC,IAAI,EAAEC,SAAS;IACfC,KAAK,EAAEC,iBAAiB;IACxBC,KAAK;IACLC,MAAM;IACNC,UAAU;IACVC,WAAW;IACXC,gBAAgB;IAChBC,aAAa;IACbC,QAAQ,GAAGA,CAAA,KAAM,CAAC;EACpB,CAAC;EACDC;AACF,CAAC,KACE;EACH,MAAM,CAACC,SAAS,EAAEC,YAAY,CAAC,GAAGxB,QAAQ,CAAC,KAAK,CAAC;EACjD,MAAM;IAAEyB,OAAO;IAAEC;EAAS,CAAC,GAAGzB,cAAc,CAAC,CAAC;EAC9C,MAAM0B,UAAU,GAAGzB,QAAQ,C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B,CAAC,eAEP/C,KAAA,CAAA6C,aAAA;IAAQE,SAAS,EAAG7B,KAAK,CAAC8B,IAAI,GAAG,SAAS,GAAG;EAAI,gBAAChD,KAAA,CAAA6C,aAAA,CAACtC,cAAc,EAAMmC,UAAc,CAAS,CAAC,eAE/F1C,KAAA,CAAA6C,aAAA;IAAKI,GAAG,EAAGlB,gBAAkB;IAACgB,SAAS,EAAG,2BAA4BtB,WAAW,CAACyB,MAAM;EAAK,GAEzFzB,WAAW,CAAC0B,GAAG,CAAEC,UAAU,iBACzBpD,KAAA,CAAA6C,aAAA,CAACrC,gBAAgB,EAAAT,QAAA;IACfsD,GAAG,EAAGD,UAAU,CAACE,KAAK,CAACzC;EAAI,GAGpBuC,UAAU;IACblC,KAAK,EAAE;MACL,GAAGkC,UAAU,CAAClC,KAAK;MACnBqC,SAAS,EAAEzB,UAAU,KAAKsB,UAAU,CAACE,KAAK,CAACtC;IAC7C,CAAC;IACDsC,KAAK,EAAE;MACL,GAAGF,UAAU,CAACE,KAAK;MACnBE,cAAc,EAAE1B,UAAU,KAAKsB,UAAU,CAACE,KAAK,CAACtC,KAAK;MACrDD,SAAS;MACTS,QAAQ,EAAES;IACZ;EAAC,EAGN,CACF,CAEA,CAAC,EAGJZ,WAAW,iBAAIrB,KAAA,CAAA6C,aAAA,CAACnC,OAAO,MAAE,CAAC,eAG5BV,KAAA,CAAA6C,aAAA,CAACpC,kBAAkB;IAACK,IAAI,EAAGC,SAAW;IAACK,UAAU,EAAGA;EAAY,CAAE,CAC1D,CAAC;AAEf,CAAC;AAED,eAAeT,gBAAgB","ignoreList":[]}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import { useFormContext } from 'react-hook-form';
|
|
5
|
-
import { NoHookFormContext } from '../../../utilities/formUtilities';
|
|
6
5
|
import { isValidationRuleWithValue } from '../../../../../../helpers/validationHelpers';
|
|
7
6
|
export const InputText = ({
|
|
8
7
|
field: {
|
|
@@ -27,18 +26,19 @@ export const InputText = ({
|
|
|
27
26
|
register,
|
|
28
27
|
getFieldState,
|
|
29
28
|
setValue
|
|
30
|
-
} = useFormContext()
|
|
29
|
+
} = useFormContext();
|
|
31
30
|
const fieldState = getFieldState(name);
|
|
32
31
|
const HandleAutoFill = event => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
32
|
+
// Some browsers trigger onAnimationStart when autofill happens.
|
|
33
|
+
// We need to notify react-hook-form of the new value.
|
|
34
|
+
if (event.animationName === 'onAutoFill') {
|
|
35
|
+
setValue(name, event.currentTarget.value, {
|
|
36
|
+
shouldValidate: true,
|
|
37
|
+
shouldDirty: true
|
|
38
|
+
});
|
|
39
|
+
onChange({
|
|
40
|
+
target: event.currentTarget
|
|
41
|
+
});
|
|
42
42
|
}
|
|
43
43
|
};
|
|
44
44
|
const HandleOnBlur = event => {
|
|
@@ -46,9 +46,14 @@ export const InputText = ({
|
|
|
46
46
|
target
|
|
47
47
|
} = event;
|
|
48
48
|
if (target) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
if (type === 'text' && target.value !== target.value.trim()) {
|
|
50
|
+
const trimmedValue = target.value.trim();
|
|
51
|
+
// Keep the uncontrolled input in step with the trimmed value held in form state.
|
|
52
|
+
target.value = trimmedValue;
|
|
53
|
+
setValue(name, trimmedValue, {
|
|
54
|
+
shouldValidate: true,
|
|
55
|
+
shouldDirty: true
|
|
56
|
+
});
|
|
52
57
|
}
|
|
53
58
|
onTouched();
|
|
54
59
|
onBlur(event);
|
|
@@ -67,6 +72,7 @@ export const InputText = ({
|
|
|
67
72
|
return {};
|
|
68
73
|
};
|
|
69
74
|
const inputProps = {
|
|
75
|
+
...htmlNativeDomProps,
|
|
70
76
|
type,
|
|
71
77
|
id,
|
|
72
78
|
className: cssClass,
|
|
@@ -84,12 +90,12 @@ export const InputText = ({
|
|
|
84
90
|
...addLengthValidatorProps('max'),
|
|
85
91
|
...addLengthValidatorProps('min'),
|
|
86
92
|
...register(name, {
|
|
87
|
-
onChange
|
|
93
|
+
onChange,
|
|
88
94
|
onBlur: HandleOnBlur,
|
|
89
95
|
...validation
|
|
90
96
|
}),
|
|
91
|
-
|
|
92
|
-
|
|
97
|
+
onAnimationStart: HandleAutoFill,
|
|
98
|
+
onKeyDown: HandleKeyEvent
|
|
93
99
|
};
|
|
94
100
|
return /*#__PURE__*/React.createElement(React.Fragment, null, customContent?.preField && /*#__PURE__*/React.createElement("span", {
|
|
95
101
|
className: `preField preField_${type}Input`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InputText.js","names":["React","useFormContext","
|
|
1
|
+
{"version":3,"file":"InputText.js","names":["React","useFormContext","isValidationRuleWithValue","InputText","field","type","id","name","placeholder","defaultValue","disabled","onBlur","onChange","onKeyDown","onTouched","htmlNativeDomProps","validation","showSpinner","customCssClasses","customContent","register","getFieldState","setValue","fieldState","HandleAutoFill","event","animationName","currentTarget","value","shouldValidate","shouldDirty","target","HandleOnBlur","trim","trimmedValue","HandleKeyEvent","cssClass","input","invalid","addLengthValidatorProps","validatorKey","inputProps","className","required","onAnimationStart","createElement","Fragment","preField","postField"],"sources":["../../../../../../../../src/components/form/formFields/subComponents/inputs/text/InputText.tsx"],"sourcesContent":["'use client';\n\nimport React from 'react';\nimport { useFormContext } from 'react-hook-form';\nimport { FormFieldProps, ValidationKey } from '../../../formFieldWrapper/formFieldProps';\nimport { isValidationRuleWithValue } from '../../../../../../helpers/validationHelpers';\n\nexport interface InputTextProps extends FormFieldProps, React.InputHTMLAttributes<HTMLInputElement> { }\n\nexport const InputText: React.FC<InputTextProps> = (\n {\n field: {\n type = 'text',\n id,\n name,\n placeholder,\n defaultValue,\n disabled,\n onBlur = () => { },\n onChange = () => { },\n onKeyDown = () => { },\n onTouched = () => { },\n ...htmlNativeDomProps\n },\n validation,\n showSpinner,\n customCssClasses,\n customContent\n }\n) => {\n const { register, getFieldState, setValue } = useFormContext();\n const fieldState = getFieldState(name);\n\n const HandleAutoFill = (event: React.AnimationEvent<HTMLInputElement>) => {\n // Some browsers trigger onAnimationStart when autofill happens.\n // We need to notify react-hook-form of the new value.\n if (event.animationName === 'onAutoFill') {\n setValue(name, event.currentTarget.value, { shouldValidate: true, shouldDirty: true });\n onChange({ target: event.currentTarget } as unknown as React.ChangeEvent<HTMLInputElement>);\n }\n };\n\n const HandleOnBlur = (event: React.FocusEvent<HTMLInputElement>) => {\n const { target } = event;\n if (target) {\n if (type === 'text' && target.value !== target.value.trim()) {\n const trimmedValue = target.value.trim();\n // Keep the uncontrolled input in step with the trimmed value held in form state.\n target.value = trimmedValue;\n setValue(name, trimmedValue, { shouldValidate: true, shouldDirty: true });\n }\n onTouched();\n onBlur(event);\n }\n };\n\n const HandleKeyEvent = (\n event: React.KeyboardEvent<HTMLInputElement> &\n React.KeyboardEvent<HTMLSelectElement> &\n React.KeyboardEvent<HTMLTextAreaElement>\n ) => {\n onKeyDown(event);\n };\n\n const cssClass = `${ customCssClasses?.input || '' }${ fieldState && fieldState?.invalid ? ' invalidField' : '' }`;\n\n const addLengthValidatorProps = (validatorKey: ValidationKey) => {\n if (\n validation\n && typeof validation[validatorKey] !== 'undefined'\n && isValidationRuleWithValue(validation[validatorKey])\n ) {\n return {\n [validatorKey]: validation[validatorKey]?.value\n };\n }\n return {};\n };\n\n const inputProps = {\n ...htmlNativeDomProps,\n type,\n id,\n className: cssClass,\n placeholder,\n defaultValue,\n disabled,\n ...(showSpinner ? { disabled: true } : {}),\n ...(validation && typeof validation.required !== 'undefined' ? { required: true } : {}),\n ...(addLengthValidatorProps('maxLength')),\n ...(addLengthValidatorProps('minLength')),\n ...(addLengthValidatorProps('max')),\n ...(addLengthValidatorProps('min')),\n ...register(\n name,\n {\n onChange,\n onBlur: HandleOnBlur,\n ...validation\n }\n ),\n onAnimationStart: HandleAutoFill,\n onKeyDown: HandleKeyEvent\n };\n\n return (\n <>\n {\n customContent?.preField\n && <span className={ `preField preField_${ type }Input` }>{ customContent?.preField }</span>\n }\n\n <input { ...inputProps } />\n\n {\n customContent?.postField\n && <span className={ `postField postField_${ type }Input` }>{ customContent?.postField }</span>\n }\n </>\n );\n};\n"],"mappings":"AAAA,YAAY;;AAEZ,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,cAAc,QAAQ,iBAAiB;AAEhD,SAASC,yBAAyB,QAAQ,6CAA6C;AAIvF,OAAO,MAAMC,SAAmC,GAAGA,CACjD;EACEC,KAAK,EAAE;IACLC,IAAI,GAAG,MAAM;IACbC,EAAE;IACFC,IAAI;IACJC,WAAW;IACXC,YAAY;IACZC,QAAQ;IACRC,MAAM,GAAGA,CAAA,KAAM,CAAE,CAAC;IAClBC,QAAQ,GAAGA,CAAA,KAAM,CAAE,CAAC;IACpBC,SAAS,GAAGA,CAAA,KAAM,CAAE,CAAC;IACrBC,SAAS,GAAGA,CAAA,KAAM,CAAE,CAAC;IACrB,GAAGC;EACL,CAAC;EACDC,UAAU;EACVC,WAAW;EACXC,gBAAgB;EAChBC;AACF,CAAC,KACE;EACH,MAAM;IAAEC,QAAQ;IAAEC,aAAa;IAAEC;EAAS,CAAC,GAAGrB,cAAc,CAAC,CAAC;EAC9D,MAAMsB,UAAU,GAAGF,aAAa,CAACd,IAAI,CAAC;EAEtC,MAAMiB,cAAc,GAAIC,KAA6C,IAAK;IACxE;IACA;IACA,IAAIA,KAAK,CAACC,aAAa,KAAK,YAAY,EAAE;MACxCJ,QAAQ,CAACf,IAAI,EAAEkB,KAAK,CAACE,aAAa,CAACC,KAAK,EAAE;QAAEC,cAAc,EAAE,IAAI;QAAEC,WAAW,EAAE;MAAK,CAAC,CAAC;MACtFlB,QAAQ,CAAC;QAAEmB,MAAM,EAAEN,KAAK,CAACE;MAAc,CAAmD,CAAC;IAC7F;EACF,CAAC;EAED,MAAMK,YAAY,GAAIP,KAAyC,IAAK;IAClE,MAAM;M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,OAAOA,UAAU,CAAC2B,QAAQ,KAAK,WAAW,GAAG;MAAEA,QAAQ,EAAE;IAAK,CAAC,GAAG,CAAC,CAAC,CAAC;IACvF,GAAIJ,uBAAuB,CAAC,WAAW,CAAE;IACzC,GAAIA,uBAAuB,CAAC,WAAW,CAAE;IACzC,GAAIA,uBAAuB,CAAC,KAAK,CAAE;IACnC,GAAIA,uBAAuB,CAAC,KAAK,CAAE;IACnC,GAAGnB,QAAQ,CACTb,IAAI,EACJ;MACEK,QAAQ;MACRD,MAAM,EAAEqB,YAAY;MACpB,GAAGhB;IACL,CACF,CAAC;IACD4B,gBAAgB,EAAEpB,cAAc;IAChCX,SAAS,EAAEsB;EACb,CAAC;EAED,oBACEnC,KAAA,CAAA6C,aAAA,CAAA7C,KAAA,CAAA8C,QAAA,QAEI3B,aAAa,EAAE4B,QAAQ,iBACpB/C,KAAA,CAAA6C,aAAA;IAAMH,SAAS,EAAG,qBAAsBrC,IAAI;EAAU,GAAGc,aAAa,EAAE4B,QAAgB,CAAC,eAG9F/C,KAAA,CAAA6C,aAAA,UAAYJ,UAAc,CAAC,EAGzBtB,aAAa,EAAE6B,SAAS,iBACrBhD,KAAA,CAAA6C,aAAA;IAAMH,SAAS,EAAG,uBAAwBrC,IAAI;EAAU,GAAGc,aAAa,EAAE6B,SAAiB,CAEhG,CAAC;AAEP,CAAC","ignoreList":[]}
|
|
@@ -4,8 +4,7 @@ import React from 'react';
|
|
|
4
4
|
import { useFormContext } from 'react-hook-form';
|
|
5
5
|
import { HookFormWrapper } from '../../../hookFormWrapper/HookFormWrapper';
|
|
6
6
|
import { isAnObject } from '../../../../../helpers/objectHelpers';
|
|
7
|
-
|
|
8
|
-
export const Select = ({
|
|
7
|
+
const SelectField = ({
|
|
9
8
|
field: {
|
|
10
9
|
id,
|
|
11
10
|
name,
|
|
@@ -27,7 +26,7 @@ export const Select = ({
|
|
|
27
26
|
const {
|
|
28
27
|
register,
|
|
29
28
|
getFieldState
|
|
30
|
-
} = useFormContext()
|
|
29
|
+
} = useFormContext();
|
|
31
30
|
const fieldState = getFieldState(name);
|
|
32
31
|
const HandleAutoFill = event => {
|
|
33
32
|
const {
|
|
@@ -47,7 +46,6 @@ export const Select = ({
|
|
|
47
46
|
}
|
|
48
47
|
};
|
|
49
48
|
const HandleKeyEvent = event => {
|
|
50
|
-
onTouched();
|
|
51
49
|
onKeyDown(event);
|
|
52
50
|
};
|
|
53
51
|
const cssClass = `${customCssClasses?.input || ''}${fieldState && fieldState?.invalid ? ' invalidField' : ''}`;
|
|
@@ -84,7 +82,7 @@ export const Select = ({
|
|
|
84
82
|
value: option
|
|
85
83
|
}, option);
|
|
86
84
|
};
|
|
87
|
-
return /*#__PURE__*/React.createElement(
|
|
85
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, customContent?.preField && /*#__PURE__*/React.createElement("span", {
|
|
88
86
|
className: "preField"
|
|
89
87
|
}, customContent?.preField), /*#__PURE__*/React.createElement("select", selectProps, includeEmptyOption && /*#__PURE__*/React.createElement("option", {
|
|
90
88
|
value: ""
|
|
@@ -92,4 +90,7 @@ export const Select = ({
|
|
|
92
90
|
className: "postField"
|
|
93
91
|
}, customContent?.postField));
|
|
94
92
|
};
|
|
93
|
+
export const Select = props => /*#__PURE__*/React.createElement(HookFormWrapper, {
|
|
94
|
+
formContext: props.formContext
|
|
95
|
+
}, /*#__PURE__*/React.createElement(SelectField, props));
|
|
95
96
|
//# sourceMappingURL=Select.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Select.js","names":["React","useFormContext","HookFormWrapper","isAnObject","
|
|
1
|
+
{"version":3,"file":"Select.js","names":["React","useFormContext","HookFormWrapper","isAnObject","SelectField","field","id","name","placeholder","defaultValue","onBlur","onChange","onKeyDown","onTouched","includeEmptyOption","emptyOptionLabel","options","validation","showSpinner","customCssClasses","customContent","register","getFieldState","fieldState","HandleAutoFill","event","target","HandleOnBlur","HandleKeyEvent","cssClass","input","invalid","selectProps","className","disabled","required","renderOption","option","typedOption","createElement","key","value","JSON","stringify","label","Fragment","preField","map","postField","Select","props","formContext"],"sources":["../../../../../../../src/components/form/formFields/subComponents/select/Select.tsx"],"sourcesContent":["'use client';\n\nimport React from 'react';\nimport { useFormContext } from 'react-hook-form';\nimport { HookFormWrapper } from '../../../hookFormWrapper/HookFormWrapper';\nimport { isAnObject } from '../../../../../helpers/objectHelpers';\nimport {\n FieldProps,\n FormFieldProps,\n SelectOptionObjectType,\n SelectOptionType,\n} from '../../formFieldWrapper/formFieldProps';\n\nexport interface SelectProps extends React.SelectHTMLAttributes<HTMLSelectElement>, Omit<FormFieldProps, 'field'> {\n field: Omit<FieldProps, 'type'>;\n}\n\nconst SelectField: React.FC<SelectProps> = (\n {\n field: {\n id,\n name,\n placeholder,\n defaultValue,\n onBlur = () => {},\n onChange = () => {},\n onKeyDown = () => {},\n onTouched = () => {},\n includeEmptyOption = true,\n emptyOptionLabel = 'Please select',\n options\n },\n validation,\n showSpinner,\n customCssClasses,\n customContent\n }\n) => {\n const { register, getFieldState } = useFormContext();\n const fieldState = getFieldState(name);\n\n const HandleAutoFill = (event: React.FocusEvent<HTMLInputElement>) => {\n const { target } = event;\n if (target) {\n onChange(event);\n }\n };\n\n const HandleOnBlur = (event: React.FocusEvent<HTMLInputElement>) => {\n const { target } = event;\n if (target) {\n onTouched();\n onBlur(event);\n }\n };\n\n const HandleKeyEvent = (\n event: React.KeyboardEvent<HTMLInputElement> &\n React.KeyboardEvent<HTMLSelectElement> &\n React.KeyboardEvent<HTMLTextAreaElement>\n ) => {\n onKeyDown(event);\n };\n\n const cssClass = `${ customCssClasses?.input || '' }${ fieldState && fieldState?.invalid ? ' invalidField' : '' }`;\n\n const selectProps = {\n id,\n className: cssClass,\n placeholder,\n defaultValue,\n ...(showSpinner ? { disabled: true } : {}),\n ...(validation && typeof validation.required !== 'undefined' ? { required: true } : {}),\n ...register(\n name,\n {\n onChange: HandleAutoFill,\n onBlur: HandleOnBlur,\n ...validation\n }\n ),\n onKeyDown: HandleKeyEvent\n };\n\n const renderOption = (option: SelectOptionType) => {\n if (isAnObject(option)) {\n const typedOption = option as SelectOptionObjectType;\n return (\n <option key={ `${ id }_${ typedOption.value }` } data-option={ JSON.stringify(typedOption) } value={ typedOption.value as string }>\n { typedOption.label }\n </option>\n );\n }\n return (\n <option key={ `${ id }_${ option }` } data-option={ JSON.stringify(option) } value={ option as string }>\n { option as string }\n </option>\n );\n };\n\n return (\n <>\n { customContent?.preField && <span className=\"preField\">{ customContent?.preField }</span> }\n\n <select { ...selectProps }>\n { includeEmptyOption && <option value=\"\">{ emptyOptionLabel }</option> }\n { (options as SelectOptionType[])?.map(renderOption) }\n </select>\n\n { customContent?.postField && <span className=\"postField\">{ customContent?.postField }</span> }\n </>\n );\n};\n\nexport const Select: React.FC<SelectProps> = (props) => (\n <HookFormWrapper formContext={ props.formContext }>\n <SelectField { ...props } />\n </HookFormWrapper>\n);\n"],"mappings":"AAAA,YAAY;;AAEZ,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,cAAc,QAAQ,iBAAiB;AAChD,SAASC,eAAe,QAAQ,0CAA0C;AAC1E,SAASC,UAAU,QAAQ,sCAAsC;AAYjE,MAAMC,WAAkC,GAAGA,CACzC;EACEC,KAAK,EAAE;IACLC,EAAE;IACFC,IAAI;IACJC,WAAW;IACXC,YAAY;IACZC,MAAM,GAAGA,CAAA,KAAM,CAAC,CAAC;IACjBC,QAAQ,GAAGA,CAAA,KAAM,CAAC,CAAC;IACnBC,SAAS,GAAGA,CAAA,KAAM,CAAC,CAAC;IACpBC,SAAS,GAAGA,CAAA,KAAM,CAAC,CAAC;IACpBC,kBAAkB,GAAG,IAAI;IACzBC,gBAAgB,GAAG,eAAe;IAClCC;EACF,CAAC;EACDC,UAAU;EACVC,WAAW;EACXC,gBAAgB;EAChBC;AACF,CAAC,KACE;EACH,MAAM;IAAEC,QAAQ;IAAEC;EAAc,CAAC,GAAGrB,cAAc,CAAC,CAAC;EACpD,MAAMsB,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,EAAE,IAAMgC,WAAW,CAACG,KAAK,EAAK;QAAC,eAAcC,IAAI,CAACC,SAAS,CAACL,WAAW,CAAG;QAACG,KAAK,EAAGH,WAAW,CAACG;MAAiB,GAC9HH,WAAW,CAACM,KACR,CAAC;IAEb;IACA,oBACE5C,KAAA,CAAAuC,aAAA;MAAQC,GAAG,EAAG,GAAIlC,EAAE,IAAM+B,MAAM,EAAK;MAAC,eAAcK,IAAI,CAACC,SAAS,CAACN,MAAM,CAAG;MAACI,KAAK,EAAGJ;IAAkB,GACnGA,MACI,CAAC;EAEb,CAAC;EAED,oBACErC,KAAA,CAAAuC,aAAA,CAAAvC,KAAA,CAAA6C,QAAA,QACIzB,aAAa,EAAE0B,QAAQ,iBAAI9C,KAAA,CAAAuC,aAAA;IAAMN,SAAS,EAAC;EAAU,GAAGb,aAAa,EAAE0B,QAAgB,CAAC,eAE1F9C,KAAA,CAAAuC,aAAA,WAAaP,WAAW,EACpBlB,kBAAkB,iBAAId,KAAA,CAAAuC,aAAA;IAAQE,KAAK,EAAC;EAAE,GAAG1B,gBAA0B,CAAC,EACnEC,OAAO,EAAyB+B,GAAG,CAACX,YAAY,CAC7C,CAAC,EAEPhB,aAAa,EAAE4B,SAAS,iBAAIhD,KAAA,CAAAuC,aAAA;IAAMN,SAAS,EAAC;EAAW,GAAGb,aAAa,EAAE4B,SAAiB,CAC5F,CAAC;AAEP,CAAC;AAED,OAAO,MAAMC,MAA6B,GAAIC,KAAK,iBACjDlD,KAAA,CAAAuC,aAAA,CAACrC,eAAe;EAACiD,WAAW,EAAGD,KAAK,CAACC;AAAa,gBAChDnD,KAAA,CAAAuC,aAAA,CAACnC,WAAW,EAAM8C,KAAS,CACZ,CAClB","ignoreList":[]}
|
|
@@ -3,35 +3,13 @@
|
|
|
3
3
|
import React, { useMemo, useState } from 'react';
|
|
4
4
|
import { useFormContext } from 'react-hook-form';
|
|
5
5
|
import { HookFormWrapper } from '../../../hookFormWrapper/HookFormWrapper';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
function getCharacterCount(value) {
|
|
14
|
-
if (typeof Intl !== 'undefined' && 'Segmenter' in Intl) {
|
|
15
|
-
const segmenter = new Intl.Segmenter(undefined, {
|
|
16
|
-
granularity: 'grapheme'
|
|
17
|
-
});
|
|
18
|
-
return Array.from(segmenter.segment(value)).length;
|
|
19
|
-
}
|
|
20
|
-
return Array.from(value).length;
|
|
21
|
-
}
|
|
22
|
-
function clampToGraphemeMax(value, maxAllowed) {
|
|
23
|
-
if (getCharacterCount(value) <= maxAllowed) {
|
|
24
|
-
return value;
|
|
25
|
-
}
|
|
26
|
-
if (typeof Intl !== 'undefined' && 'Segmenter' in Intl) {
|
|
27
|
-
const segmenter = new Intl.Segmenter(undefined, {
|
|
28
|
-
granularity: 'grapheme'
|
|
29
|
-
});
|
|
30
|
-
return Array.from(segmenter.segment(value)).slice(0, maxAllowed).map(segment => segment.segment).join('');
|
|
31
|
-
}
|
|
32
|
-
return Array.from(value).slice(0, maxAllowed).join('');
|
|
33
|
-
}
|
|
34
|
-
export const Textarea = ({
|
|
6
|
+
import { extractError } from '../../../validation/ValidationMessages';
|
|
7
|
+
import { clampToGraphemeMax, getCharacterCount } from '../../../../../helpers/stringHelpers';
|
|
8
|
+
import './textarea.css';
|
|
9
|
+
export const Textarea = props => /*#__PURE__*/React.createElement(HookFormWrapper, {
|
|
10
|
+
formContext: props.formContext
|
|
11
|
+
}, /*#__PURE__*/React.createElement(TextareaField, props));
|
|
12
|
+
const TextareaField = ({
|
|
35
13
|
field: {
|
|
36
14
|
id,
|
|
37
15
|
name,
|
|
@@ -56,20 +34,16 @@ export const Textarea = ({
|
|
|
56
34
|
formState: {
|
|
57
35
|
errors
|
|
58
36
|
}
|
|
59
|
-
} = useFormContext()
|
|
37
|
+
} = useFormContext();
|
|
60
38
|
const fieldState = getFieldState(name);
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const isInvalid = Boolean(fieldState?.invalid ?? hasFieldError);
|
|
39
|
+
// getFieldState alone does not subscribe to errors, so the direct lookup keeps this in sync.
|
|
40
|
+
const isInvalid = Boolean(fieldState?.invalid || extractError(errors, name));
|
|
41
|
+
const isRequiredError = fieldState?.error?.type === 'required';
|
|
65
42
|
const [count, setCount] = useState(() => getCharacterCount(defaultValue?.toString() || ''));
|
|
66
43
|
const [hasStartedTyping, setHasStartedTyping] = useState(false);
|
|
67
44
|
const hasMaxLength = typeof maxLength === 'number';
|
|
68
45
|
const isAtLimit = hasMaxLength ? count >= maxLength : false;
|
|
69
|
-
|
|
70
|
-
// should show counter instead of error message.
|
|
71
|
-
const isRequiredError = fieldState?.error?.type === 'required';
|
|
72
|
-
const characterCounter = !hasStartedTyping || !hasMaxLength || isRequiredError ? undefined : `${count}/${maxLength}`;
|
|
46
|
+
const showsCharacterCount = hasStartedTyping && hasMaxLength && !isRequiredError;
|
|
73
47
|
const cssClass = `${customCssClasses?.input || ''}${isInvalid ? ' invalidField' : ''}`;
|
|
74
48
|
const normalizedValidation = useMemo(() => {
|
|
75
49
|
if (!validation || typeof validation.maxLength === 'undefined') {
|
|
@@ -115,19 +89,21 @@ export const Textarea = ({
|
|
|
115
89
|
validate: graphemeMaxLengthValidator
|
|
116
90
|
};
|
|
117
91
|
}, [validation]);
|
|
118
|
-
const
|
|
92
|
+
const fieldRegistration = register(name, normalizedValidation);
|
|
119
93
|
|
|
120
94
|
/**
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
* can be treated as multiple characters. We avoid using native maxLength and enforce
|
|
124
|
-
* the limit here instead.
|
|
95
|
+
* Native maxLength counts UTF-16 units, so emojis and composed characters are treated as
|
|
96
|
+
* several characters. The limit is enforced here against grapheme clusters instead.
|
|
125
97
|
*/
|
|
126
98
|
const HandleBeforeInput = event => {
|
|
127
|
-
if (enforceMaxLength !== true || !hasMaxLength)
|
|
99
|
+
if (enforceMaxLength !== true || !hasMaxLength) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
128
102
|
const nativeEvent = event.nativeEvent;
|
|
129
103
|
const inserted = nativeEvent.data ?? '';
|
|
130
|
-
if (!inserted)
|
|
104
|
+
if (!inserted) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
131
107
|
const target = event.currentTarget;
|
|
132
108
|
const start = target.selectionStart ?? target.value.length;
|
|
133
109
|
const end = target.selectionEnd ?? target.value.length;
|
|
@@ -144,8 +120,22 @@ export const Textarea = ({
|
|
|
144
120
|
}
|
|
145
121
|
setHasStartedTyping(true);
|
|
146
122
|
setCount(getCharacterCount(newValue));
|
|
147
|
-
|
|
148
|
-
|
|
123
|
+
onChange(event);
|
|
124
|
+
fieldRegistration?.onChange?.(event);
|
|
125
|
+
};
|
|
126
|
+
const HandleAutoFill = event => {
|
|
127
|
+
// Browsers trigger onAnimationStart when autofill happens.
|
|
128
|
+
// We need to notify react-hook-form of the new value.
|
|
129
|
+
if (event.animationName === 'onAutoFill') {
|
|
130
|
+
const {
|
|
131
|
+
value
|
|
132
|
+
} = event.currentTarget;
|
|
133
|
+
setHasStartedTyping(true);
|
|
134
|
+
setCount(getCharacterCount(value || ''));
|
|
135
|
+
HandleChange({
|
|
136
|
+
target: event.currentTarget
|
|
137
|
+
});
|
|
138
|
+
}
|
|
149
139
|
};
|
|
150
140
|
const HandleOnBlur = event => {
|
|
151
141
|
const {
|
|
@@ -155,17 +145,12 @@ export const Textarea = ({
|
|
|
155
145
|
onTouched();
|
|
156
146
|
onBlur(event);
|
|
157
147
|
}
|
|
148
|
+
fieldRegistration?.onBlur?.(event);
|
|
158
149
|
};
|
|
159
150
|
const HandleKeyEvent = event => {
|
|
160
151
|
onTouched();
|
|
161
|
-
|
|
162
|
-
onTextareaKeyDown?.(event);
|
|
152
|
+
onKeyDown(event);
|
|
163
153
|
};
|
|
164
|
-
const characterCounterId = `${id}_characterCount`;
|
|
165
|
-
const errorsId = `${name}_errors`;
|
|
166
|
-
const existingDescribedBy = typeof htmlNativeDomProps['aria-describedby'] === 'string' ? htmlNativeDomProps['aria-describedby'] : undefined;
|
|
167
|
-
const showsRequiredError = isInvalid && isRequiredError;
|
|
168
|
-
const mergedDescribedBy = showsRequiredError ? [existingDescribedBy, errorsId].filter(Boolean).join(' ') : characterCounter !== undefined ? [existingDescribedBy, characterCounterId].filter(Boolean).join(' ') : existingDescribedBy;
|
|
169
154
|
const textareaProps = {
|
|
170
155
|
id,
|
|
171
156
|
className: cssClass,
|
|
@@ -177,38 +162,25 @@ export const Textarea = ({
|
|
|
177
162
|
...(validation && typeof validation.required !== 'undefined' ? {
|
|
178
163
|
required: true
|
|
179
164
|
} : {}),
|
|
180
|
-
...
|
|
165
|
+
...htmlNativeDomProps,
|
|
166
|
+
...fieldRegistration,
|
|
181
167
|
onBeforeInput: HandleBeforeInput,
|
|
182
|
-
onChange:
|
|
183
|
-
|
|
184
|
-
registered?.onChange?.(event);
|
|
185
|
-
},
|
|
186
|
-
onBlur: event => {
|
|
187
|
-
HandleOnBlur(event);
|
|
188
|
-
registered?.onBlur?.(event);
|
|
189
|
-
},
|
|
168
|
+
onChange: HandleChange,
|
|
169
|
+
onBlur: HandleOnBlur,
|
|
190
170
|
onKeyDown: HandleKeyEvent,
|
|
191
|
-
|
|
192
|
-
'aria-describedby': mergedDescribedBy
|
|
171
|
+
onAnimationStart: HandleAutoFill
|
|
193
172
|
};
|
|
194
|
-
|
|
173
|
+
const containerCssClass = `textareaFieldContainer${showsCharacterCount ? ' withCharacterCount' : ''}`;
|
|
174
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, customContent?.preField && /*#__PURE__*/React.createElement("span", {
|
|
195
175
|
className: "preField"
|
|
196
|
-
}, customContent?.preField), /*#__PURE__*/React.createElement("
|
|
197
|
-
className:
|
|
198
|
-
}, /*#__PURE__*/React.createElement("textarea", textareaProps), /*#__PURE__*/React.createElement("
|
|
199
|
-
className: "textareaFooter"
|
|
200
|
-
}, isInvalid && isRequiredError ? /*#__PURE__*/React.createElement(ValidationMessages, {
|
|
201
|
-
name: name,
|
|
202
|
-
validation: {
|
|
203
|
-
required: validation?.required
|
|
204
|
-
}
|
|
205
|
-
}) : /*#__PURE__*/React.createElement("div", {
|
|
206
|
-
id: characterCounterId,
|
|
176
|
+
}, customContent?.preField), /*#__PURE__*/React.createElement("span", {
|
|
177
|
+
className: containerCssClass
|
|
178
|
+
}, /*#__PURE__*/React.createElement("textarea", textareaProps), showsCharacterCount && /*#__PURE__*/React.createElement("span", {
|
|
207
179
|
className: `textareaCharacterCount ${isAtLimit ? 'textareaCharacterCountExceeded' : ''}`,
|
|
208
180
|
role: isAtLimit ? 'status' : undefined,
|
|
209
181
|
"aria-live": isAtLimit ? 'polite' : undefined,
|
|
210
182
|
"aria-atomic": isAtLimit ? 'true' : undefined
|
|
211
|
-
},
|
|
183
|
+
}, `${count}/${maxLength}`)), customContent?.postField && /*#__PURE__*/React.createElement("span", {
|
|
212
184
|
className: "postField"
|
|
213
185
|
}, customContent?.postField));
|
|
214
186
|
};
|