envoc-form 4.1.0 → 4.3.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/README.md +5266 -940
- package/es/DatePicker/DatePickerGroup.d.ts +1 -1
- package/es/DatePicker/DatePickerGroup.js +7 -3
- package/es/DateTimePicker/DateTimePickerGroup.d.ts +13 -0
- package/es/DateTimePicker/DateTimePickerGroup.js +90 -0
- package/es/DateTimePicker/DateTimePickerHelper.d.ts +3 -0
- package/es/DateTimePicker/DateTimePickerHelper.js +1 -0
- package/es/DateTimePicker/StringDateTimePickerGroup.d.ts +10 -0
- package/es/DateTimePicker/StringDateTimePickerGroup.js +53 -0
- package/es/Input/PhoneNumberInputGroup.d.ts +10 -0
- package/es/Input/PhoneNumberInputGroup.js +47 -0
- package/es/hooks/index.d.ts +2 -0
- package/es/hooks/index.js +2 -0
- package/es/hooks/useFormValue.d.ts +2 -0
- package/es/hooks/useFormValue.js +7 -0
- package/es/index.d.ts +6 -0
- package/es/index.js +4 -0
- package/lib/DatePicker/DatePickerGroup.d.ts +1 -1
- package/lib/DatePicker/DatePickerGroup.js +7 -3
- package/lib/DateTimePicker/DateTimePickerGroup.d.ts +13 -0
- package/lib/DateTimePicker/DateTimePickerGroup.js +96 -0
- package/lib/DateTimePicker/DateTimePickerHelper.d.ts +3 -0
- package/lib/DateTimePicker/DateTimePickerHelper.js +2 -0
- package/lib/DateTimePicker/StringDateTimePickerGroup.d.ts +10 -0
- package/lib/DateTimePicker/StringDateTimePickerGroup.js +59 -0
- package/lib/Input/PhoneNumberInputGroup.d.ts +10 -0
- package/lib/Input/PhoneNumberInputGroup.js +52 -0
- package/lib/hooks/index.d.ts +2 -0
- package/lib/hooks/index.js +8 -0
- package/lib/hooks/useFormValue.d.ts +2 -0
- package/lib/hooks/useFormValue.js +10 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +8 -1
- package/package.json +5 -4
- package/src/DatePicker/DatePickerGroup.tsx +22 -9
- package/src/DatePicker/__snapshots__/DatePicker.test.tsx.snap +119 -117
- package/src/DateTimePicker/DateTimePicker.test.tsx +243 -0
- package/src/DateTimePicker/DateTimePickerGroup.tsx +128 -0
- package/src/DateTimePicker/DateTimePickerHelper.ts +4 -0
- package/src/DateTimePicker/StringDateTimePickerGroup.tsx +61 -0
- package/src/DateTimePicker/__snapshots__/DateTimePicker.test.tsx.snap +218 -0
- package/src/Input/PhoneNumberInputGroup.tsx +49 -0
- package/src/Input/__Tests__/PhoneNumberInputGroup.test.tsx +37 -0
- package/src/Input/__Tests__/__snapshots__/PhoneNumberInputGroup.test.tsx.snap +33 -0
- package/src/__Tests__/FormTestBase.tsx +1 -0
- package/src/hooks/index.ts +3 -0
- package/src/hooks/useFormValue.ts +16 -0
- package/src/index.ts +10 -0
@@ -0,0 +1,49 @@
|
|
1
|
+
import React, { LegacyRef } from 'react';
|
2
|
+
import classNames from 'classnames';
|
3
|
+
import InputGroup, { InputGroupProps } from './InputGroup';
|
4
|
+
import { FormDefaults } from '../FormDefaults';
|
5
|
+
import { phoneNumber } from '../Normalization/normalizers';
|
6
|
+
|
7
|
+
export interface PhoneNumberInputGroupProps
|
8
|
+
extends Omit<
|
9
|
+
InputGroupProps<string | undefined | null>,
|
10
|
+
'onChange' | 'type' | 'value'
|
11
|
+
> {}
|
12
|
+
|
13
|
+
function PhoneNumberInputGroup(
|
14
|
+
{ className, ...rest }: PhoneNumberInputGroupProps,
|
15
|
+
ref: LegacyRef<HTMLInputElement>
|
16
|
+
) {
|
17
|
+
const { input } = rest;
|
18
|
+
|
19
|
+
return (
|
20
|
+
<InputGroup
|
21
|
+
ref={ref}
|
22
|
+
autoComplete="tel-national"
|
23
|
+
{...rest}
|
24
|
+
type="text"
|
25
|
+
className={classNames(
|
26
|
+
className,
|
27
|
+
FormDefaults.cssClassPrefix + 'phone-number-group'
|
28
|
+
)}
|
29
|
+
value={input.value ?? ''}
|
30
|
+
onChange={(e) => {
|
31
|
+
if (!e.target.value) {
|
32
|
+
input.onChange(undefined);
|
33
|
+
} else {
|
34
|
+
input.onChange(phoneNumber(e.target.value));
|
35
|
+
}
|
36
|
+
}}
|
37
|
+
/>
|
38
|
+
);
|
39
|
+
}
|
40
|
+
|
41
|
+
/**A standard phone number input. Will display to the user in `+XXX XXX-XXX-XXXX` format as the number is being inputted.
|
42
|
+
* The data will get sent in the same format as displayed. Uses `normalizers.phoneNumber`.
|
43
|
+
* @default autoComplete="tel-national"
|
44
|
+
*/
|
45
|
+
const PhoneNumberInputGroupWithRef = React.forwardRef(
|
46
|
+
PhoneNumberInputGroup
|
47
|
+
) as React.ComponentType<PhoneNumberInputGroupProps>;
|
48
|
+
|
49
|
+
export default PhoneNumberInputGroupWithRef;
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { render } from '@testing-library/react';
|
3
|
+
import FormTestBase from '../../__Tests__/FormTestBase';
|
4
|
+
import PhoneNumberInputGroup from '../PhoneNumberInputGroup';
|
5
|
+
|
6
|
+
describe('PhoneNumberInputGroup', () => {
|
7
|
+
it('renders without crashing', () => {
|
8
|
+
render(
|
9
|
+
<FormTestBase>
|
10
|
+
{({ Field }) => (
|
11
|
+
<Field
|
12
|
+
name="phoneNumber"
|
13
|
+
Component={PhoneNumberInputGroup}
|
14
|
+
label="Phone Number"
|
15
|
+
className="something-here"
|
16
|
+
/>
|
17
|
+
)}
|
18
|
+
</FormTestBase>
|
19
|
+
);
|
20
|
+
});
|
21
|
+
|
22
|
+
it('has matching snapshot', () => {
|
23
|
+
const renderResult = render(
|
24
|
+
<FormTestBase>
|
25
|
+
{({ Field }) => (
|
26
|
+
<Field
|
27
|
+
name="phoneNumber"
|
28
|
+
Component={PhoneNumberInputGroup}
|
29
|
+
label="Phone Number"
|
30
|
+
className="something-here"
|
31
|
+
/>
|
32
|
+
)}
|
33
|
+
</FormTestBase>
|
34
|
+
);
|
35
|
+
expect(renderResult.asFragment()).toMatchSnapshot();
|
36
|
+
});
|
37
|
+
});
|
@@ -0,0 +1,33 @@
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
2
|
+
|
3
|
+
exports[`PhoneNumberInputGroup has matching snapshot 1`] = `
|
4
|
+
<DocumentFragment>
|
5
|
+
<form
|
6
|
+
action="#"
|
7
|
+
class="envoc-form-form"
|
8
|
+
>
|
9
|
+
<div
|
10
|
+
class="something-here envoc-form-phone-number-group envoc-form-input-group envoc-form-group"
|
11
|
+
>
|
12
|
+
<div
|
13
|
+
id="phonenumber-error-scroll-target"
|
14
|
+
style="display: none;"
|
15
|
+
/>
|
16
|
+
<label
|
17
|
+
for="phoneNumber"
|
18
|
+
>
|
19
|
+
Phone Number
|
20
|
+
</label>
|
21
|
+
<input
|
22
|
+
aria-invalid="false"
|
23
|
+
autocomplete="tel-national"
|
24
|
+
class="something-here envoc-form-phone-number-group envoc-form-input-group"
|
25
|
+
id="phoneNumber"
|
26
|
+
name="phoneNumber"
|
27
|
+
type="text"
|
28
|
+
value=""
|
29
|
+
/>
|
30
|
+
</div>
|
31
|
+
</form>
|
32
|
+
</DocumentFragment>
|
33
|
+
`;
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { useCallback } from 'react';
|
2
|
+
import { FormBuilderProp } from 'Form/Form';
|
3
|
+
import { useFormikContext } from 'formik';
|
4
|
+
|
5
|
+
export default function useFormValue<
|
6
|
+
TForm extends object,
|
7
|
+
TPropKey extends keyof TForm
|
8
|
+
>(formBuilder: FormBuilderProp<TForm>, fieldName: TPropKey) {
|
9
|
+
const { values, setFieldValue } = useFormikContext<TForm>();
|
10
|
+
const setValue = useCallback(
|
11
|
+
(value: TForm[TPropKey]) => setFieldValue(fieldName as string, value),
|
12
|
+
[fieldName, setFieldValue]
|
13
|
+
);
|
14
|
+
|
15
|
+
return [values[fieldName], setValue] as const;
|
16
|
+
}
|
package/src/index.ts
CHANGED
@@ -27,6 +27,13 @@ export type { StringDatePickerGroupProps } from './DatePicker/StringDatePickerGr
|
|
27
27
|
export { default as StringDateOnlyPickerGroup } from './DatePicker/StringDateOnlyPickerGroup';
|
28
28
|
export type { StringDateOnlyPickerGroupProps } from './DatePicker/StringDateOnlyPickerGroup';
|
29
29
|
|
30
|
+
// DateTime
|
31
|
+
export { default as DateTimePickerGroup } from './DateTimePicker/DateTimePickerGroup';
|
32
|
+
export type { DateTimePickerGroupProps } from './DateTimePicker/DateTimePickerGroup';
|
33
|
+
|
34
|
+
export { default as StringDateTimePickerGroup } from './DateTimePicker/StringDateTimePickerGroup';
|
35
|
+
export type { StringDateTimePickerGroupProps } from './DateTimePicker/StringDateTimePickerGroup';
|
36
|
+
|
30
37
|
// Field
|
31
38
|
export { default as Field } from './Field/Field';
|
32
39
|
export type { FieldProps } from './Field/Field';
|
@@ -92,6 +99,9 @@ export type { MoneyInputGroupProps } from './Input/MoneyInputGroup';
|
|
92
99
|
export { default as NumberInputGroup } from './Input/NumberInputGroup';
|
93
100
|
export type { NumberInputGroupProps } from './Input/NumberInputGroup';
|
94
101
|
|
102
|
+
export { default as PhoneNumberInputGroup } from './Input/PhoneNumberInputGroup';
|
103
|
+
export type { PhoneNumberInputGroupProps } from './Input/PhoneNumberInputGroup';
|
104
|
+
|
95
105
|
export { default as StringInputGroup } from './Input/StringInputGroup';
|
96
106
|
export type { StringInputGroupProps } from './Input/StringInputGroup';
|
97
107
|
|