@ttoss/forms 0.17.0 → 0.17.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +674 -0
- package/dist/esm/index.js +88 -33
- package/dist/index.d.ts +12 -5
- package/dist/index.js +90 -33
- package/package.json +13 -13
- package/src/FormFieldInput.tsx +7 -5
- package/src/FormFieldPassword.tsx +67 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { ErrorMessage } from './ErrorMessage';
|
|
2
|
+
import { FieldPath, FieldValues, useController } from 'react-hook-form';
|
|
3
|
+
import {
|
|
4
|
+
Flex,
|
|
5
|
+
InputPassword,
|
|
6
|
+
type InputPasswordProps,
|
|
7
|
+
Label,
|
|
8
|
+
type LabelProps,
|
|
9
|
+
} from '@ttoss/ui';
|
|
10
|
+
|
|
11
|
+
export type FormFieldPasswordProps<TName> = {
|
|
12
|
+
label?: string;
|
|
13
|
+
name: TName;
|
|
14
|
+
} & InputPasswordProps &
|
|
15
|
+
Pick<LabelProps, 'tooltip' | 'onTooltipClick'>;
|
|
16
|
+
|
|
17
|
+
export const FormFieldPassword = <
|
|
18
|
+
TFieldValues extends FieldValues = FieldValues,
|
|
19
|
+
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>
|
|
20
|
+
>({
|
|
21
|
+
label,
|
|
22
|
+
name,
|
|
23
|
+
tooltip,
|
|
24
|
+
onTooltipClick,
|
|
25
|
+
sx,
|
|
26
|
+
...inputProps
|
|
27
|
+
}: FormFieldPasswordProps<TName>) => {
|
|
28
|
+
const {
|
|
29
|
+
field: { onChange, onBlur, value, ref },
|
|
30
|
+
formState: { errors },
|
|
31
|
+
} = useController<any>({
|
|
32
|
+
name,
|
|
33
|
+
defaultValue: '',
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const id = `form-field-password-${name}`;
|
|
37
|
+
|
|
38
|
+
const hasError = !!errors[name]?.message;
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<Flex sx={{ flexDirection: 'column', width: '100%', ...sx }}>
|
|
42
|
+
{label && (
|
|
43
|
+
<Label
|
|
44
|
+
aria-disabled={inputProps.disabled}
|
|
45
|
+
htmlFor={id}
|
|
46
|
+
tooltip={tooltip}
|
|
47
|
+
onTooltipClick={onTooltipClick}
|
|
48
|
+
>
|
|
49
|
+
{label}
|
|
50
|
+
</Label>
|
|
51
|
+
)}
|
|
52
|
+
|
|
53
|
+
<InputPassword
|
|
54
|
+
ref={ref}
|
|
55
|
+
onChange={onChange}
|
|
56
|
+
className={hasError ? 'error' : ''}
|
|
57
|
+
onBlur={onBlur}
|
|
58
|
+
value={value}
|
|
59
|
+
name={name}
|
|
60
|
+
id={id}
|
|
61
|
+
{...inputProps}
|
|
62
|
+
/>
|
|
63
|
+
|
|
64
|
+
<ErrorMessage name={name} />
|
|
65
|
+
</Flex>
|
|
66
|
+
);
|
|
67
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ export { Form } from './Form';
|
|
|
6
6
|
export { FormField } from './FormField';
|
|
7
7
|
export { FormFieldCheckbox } from './FormFieldCheckbox';
|
|
8
8
|
export { FormFieldInput } from './FormFieldInput';
|
|
9
|
+
export { FormFieldPassword } from './FormFieldPassword';
|
|
9
10
|
export { FormFieldRadio } from './FormFieldRadio';
|
|
10
11
|
export { FormFieldSelect } from './FormFieldSelect';
|
|
11
12
|
export { FormFieldTextarea } from './FormFieldTextarea';
|