form-input-fields 1.0.6 → 1.0.7
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 +201 -1
- package/dist/controls/FormSwitch/FormSwitch.d.ts +60 -0
- package/dist/controls/FormSwitch/FormSwitch.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.es.js +3186 -3125
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +56 -56
- package/dist/index.js.map +1 -1
- package/dist/test/FormDropDownField.spec.d.ts +2 -0
- package/dist/test/FormDropDownField.spec.d.ts.map +1 -0
- package/dist/test/FormSwitch.spec.d.ts +2 -0
- package/dist/test/FormSwitch.spec.d.ts.map +1 -0
- package/dist/test/FormTextField.spec.d.ts +2 -0
- package/dist/test/FormTextField.spec.d.ts.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -73,7 +73,7 @@ For Internet Explorer 11 support, you'll need to include polyfills. See [Browser
|
|
|
73
73
|
After installation, you can import and use the components in your application:
|
|
74
74
|
|
|
75
75
|
```tsx
|
|
76
|
-
import { FormTextField, FormDateField, FormMaskField } from 'form-input-fields';
|
|
76
|
+
import { FormTextField, FormDateField, FormMaskField, FormSwitch } from 'form-input-fields';
|
|
77
77
|
```
|
|
78
78
|
|
|
79
79
|
### Troubleshooting
|
|
@@ -156,6 +156,14 @@ If you're still experiencing issues, please reach me at vladimir.vorobiev@gmail.
|
|
|
156
156
|
- [Basic Checkbox](#basic-checkbox)
|
|
157
157
|
- [Checkbox with Formik](#checkbox-with-formik)
|
|
158
158
|
- [Custom Styled Checkbox](#custom-styled-checkbox)
|
|
159
|
+
- [FormSwitch](#formswitch)
|
|
160
|
+
- [Features](#features-5)
|
|
161
|
+
- [Basic Usage](#basic-usage-5)
|
|
162
|
+
- [Props](#props-5)
|
|
163
|
+
- [Examples](#examples-5)
|
|
164
|
+
- [Basic Switch](#basic-switch)
|
|
165
|
+
- [Switch with Formik](#switch-with-formik)
|
|
166
|
+
- [Custom Styled Switch](#custom-styled-switch)
|
|
159
167
|
- [FormDateTextField](#formdatetextfield)
|
|
160
168
|
- [Features](#features-3)
|
|
161
169
|
- [Available Date Formats](#available-date-formats-1)
|
|
@@ -809,6 +817,198 @@ function CustomCheckbox() {
|
|
|
809
817
|
}
|
|
810
818
|
```
|
|
811
819
|
|
|
820
|
+
## FormSwitch
|
|
821
|
+
|
|
822
|
+
A customizable switch component with Material-UI and Formik integration, providing consistent styling and behavior for boolean inputs across your application.
|
|
823
|
+
|
|
824
|
+
### Features
|
|
825
|
+
|
|
826
|
+
- **Material-UI Integration**: Consistent styling with Material-UI's design system
|
|
827
|
+
- **Formik Integration**: Seamless form state management with error handling
|
|
828
|
+
- **Flexible Label Placement**: Support for different label positions
|
|
829
|
+
- **TypeScript Support**: Full type safety with exported interfaces
|
|
830
|
+
- **Accessibility**: Built with accessibility in mind, following WAI-ARIA guidelines
|
|
831
|
+
- **Error Handling**: Built-in error state management with Formik
|
|
832
|
+
- **Responsive Design**: Works well on all screen sizes
|
|
833
|
+
|
|
834
|
+
### Basic Usage
|
|
835
|
+
|
|
836
|
+
```tsx
|
|
837
|
+
import { Formik, Field } from 'formik';
|
|
838
|
+
import { FormSwitch } from 'form-input-fields';
|
|
839
|
+
|
|
840
|
+
// Basic usage
|
|
841
|
+
<FormSwitch
|
|
842
|
+
label="Enable Notifications"
|
|
843
|
+
checked={notificationsEnabled}
|
|
844
|
+
onChange={(e, checked) => setNotificationsEnabled(checked)}
|
|
845
|
+
/>
|
|
846
|
+
|
|
847
|
+
// With Formik
|
|
848
|
+
<Formik
|
|
849
|
+
initialValues={{ notifications: false }}
|
|
850
|
+
onSubmit={(values) => console.log(values)}
|
|
851
|
+
>
|
|
852
|
+
<Field
|
|
853
|
+
component={FormSwitch}
|
|
854
|
+
name="notifications"
|
|
855
|
+
label="Enable Notifications"
|
|
856
|
+
helperText="Receive email notifications"
|
|
857
|
+
/>
|
|
858
|
+
</Formik>
|
|
859
|
+
```
|
|
860
|
+
|
|
861
|
+
### Props
|
|
862
|
+
|
|
863
|
+
The FormSwitch component accepts all props from `FormSwitchProps`, `FieldProps` (Formik), and Material-UI's `SwitchProps`.
|
|
864
|
+
|
|
865
|
+
#### FormSwitchProps Interface
|
|
866
|
+
|
|
867
|
+
| Prop | Type | Default | Description |
|
|
868
|
+
| ---------------- | ---------- | ------- | ------------------------------------------------ |
|
|
869
|
+
| `label` | `string` | - | Label text displayed next to the switch |
|
|
870
|
+
| `labelPlacement` | `string` | 'end' | Position of label ('top', 'start', 'bottom', 'end') |
|
|
871
|
+
| `color` | `string` | 'primary'| Switch color ('primary', 'secondary', 'error', 'info', 'success', 'warning', 'default') |
|
|
872
|
+
| `size` | `string` | 'medium'| Switch size ('small' or 'medium') |
|
|
873
|
+
| `disabled` | `boolean` | `false` | Disable the switch |
|
|
874
|
+
| `required` | `boolean` | `false` | Mark the field as required |
|
|
875
|
+
| `onChange` | `function` | - | Custom change handler with context data |
|
|
876
|
+
| `onBlur` | `function` | - | Custom blur handler |
|
|
877
|
+
| `helperText` | `string` | - | Helper text to display below the switch |
|
|
878
|
+
| `error` | `boolean` | `false` | Error state of the switch |
|
|
879
|
+
| `className` | `string` | - | Custom class name for the root element |
|
|
880
|
+
|
|
881
|
+
#### Common Props (from FieldProps & SwitchProps)
|
|
882
|
+
|
|
883
|
+
| Prop | Type | Required | Description |
|
|
884
|
+
|--------------|------------------|----------|-----------------------------------------------|
|
|
885
|
+
| `name` | `string` | Yes | Field name in Formik values |
|
|
886
|
+
| `label` | `string` | No | Field label |
|
|
887
|
+
| `helperText` | `string` | No | Custom helper text |
|
|
888
|
+
| `error` | `boolean` | No | Error state (auto-managed by Formik) |
|
|
889
|
+
| `disabled` | `boolean` | No | Disabled state |
|
|
890
|
+
| `required` | `boolean` | No | Required field indicator |
|
|
891
|
+
| Other | `SwitchProps` | No | All Material-UI Switch props are supported |
|
|
892
|
+
|
|
893
|
+
### Examples
|
|
894
|
+
|
|
895
|
+
#### Basic Switch
|
|
896
|
+
|
|
897
|
+
```tsx
|
|
898
|
+
<FormSwitch
|
|
899
|
+
label="Enable Dark Mode"
|
|
900
|
+
checked={darkModeEnabled}
|
|
901
|
+
onChange={(e, checked) => setDarkModeEnabled(checked)}
|
|
902
|
+
color="secondary"
|
|
903
|
+
size="small"
|
|
904
|
+
/>
|
|
905
|
+
```
|
|
906
|
+
|
|
907
|
+
#### Switch with Formik
|
|
908
|
+
|
|
909
|
+
```tsx
|
|
910
|
+
<Formik
|
|
911
|
+
initialValues={{
|
|
912
|
+
notifications: false,
|
|
913
|
+
darkMode: true,
|
|
914
|
+
autoSave: false
|
|
915
|
+
}}
|
|
916
|
+
onSubmit={(values) => console.log('Form values:', values)}
|
|
917
|
+
>
|
|
918
|
+
<Form>
|
|
919
|
+
<Field
|
|
920
|
+
component={FormSwitch}
|
|
921
|
+
name="notifications"
|
|
922
|
+
label="Enable Notifications"
|
|
923
|
+
helperText="Receive email notifications"
|
|
924
|
+
color="primary"
|
|
925
|
+
/>
|
|
926
|
+
|
|
927
|
+
<Field
|
|
928
|
+
component={FormSwitch}
|
|
929
|
+
name="darkMode"
|
|
930
|
+
label="Dark Mode"
|
|
931
|
+
helperText="Use dark theme"
|
|
932
|
+
color="secondary"
|
|
933
|
+
labelPlacement="start"
|
|
934
|
+
/>
|
|
935
|
+
|
|
936
|
+
<Field
|
|
937
|
+
component={FormSwitch}
|
|
938
|
+
name="autoSave"
|
|
939
|
+
label="Auto Save"
|
|
940
|
+
helperText="Automatically save changes"
|
|
941
|
+
color="success"
|
|
942
|
+
size="small"
|
|
943
|
+
/>
|
|
944
|
+
|
|
945
|
+
<Button type="submit" variant="contained" color="primary">
|
|
946
|
+
Save Settings
|
|
947
|
+
</Button>
|
|
948
|
+
</Form>
|
|
949
|
+
</Formik>
|
|
950
|
+
```
|
|
951
|
+
|
|
952
|
+
#### Custom Styled Switch
|
|
953
|
+
|
|
954
|
+
```tsx
|
|
955
|
+
<FormSwitch
|
|
956
|
+
label="Custom Styled Switch"
|
|
957
|
+
checked={false}
|
|
958
|
+
onChange={(e, checked) => console.log('Switch toggled:', checked)}
|
|
959
|
+
className="custom-switch-class"
|
|
960
|
+
color="warning"
|
|
961
|
+
labelPlacement="top"
|
|
962
|
+
helperText="This is a custom styled switch"
|
|
963
|
+
/>
|
|
964
|
+
```
|
|
965
|
+
|
|
966
|
+
#### Switch with Custom Change Handler
|
|
967
|
+
|
|
968
|
+
```tsx
|
|
969
|
+
<Field
|
|
970
|
+
component={FormSwitch}
|
|
971
|
+
name="advancedMode"
|
|
972
|
+
label="Advanced Mode"
|
|
973
|
+
onChange={(e, checked, context) => {
|
|
974
|
+
console.log('Field name:', context.fieldName);
|
|
975
|
+
console.log('Formik value:', context.formikValue);
|
|
976
|
+
// Custom logic here
|
|
977
|
+
}}
|
|
978
|
+
helperText="Enable advanced features"
|
|
979
|
+
/>
|
|
980
|
+
```
|
|
981
|
+
|
|
982
|
+
#### Switch with Validation
|
|
983
|
+
|
|
984
|
+
```tsx
|
|
985
|
+
<Formik
|
|
986
|
+
initialValues={{ termsAccepted: false }}
|
|
987
|
+
validate={(values) => {
|
|
988
|
+
const errors = {};
|
|
989
|
+
if (!values.termsAccepted) {
|
|
990
|
+
errors.termsAccepted = 'You must accept the terms to continue';
|
|
991
|
+
}
|
|
992
|
+
return errors;
|
|
993
|
+
}}
|
|
994
|
+
onSubmit={(values) => console.log(values)}
|
|
995
|
+
>
|
|
996
|
+
<Form>
|
|
997
|
+
<Field
|
|
998
|
+
component={FormSwitch}
|
|
999
|
+
name="termsAccepted"
|
|
1000
|
+
label="I accept the terms and conditions"
|
|
1001
|
+
helperText="Please read and accept the terms"
|
|
1002
|
+
required
|
|
1003
|
+
/>
|
|
1004
|
+
|
|
1005
|
+
<Button type="submit" variant="contained" color="primary">
|
|
1006
|
+
Continue
|
|
1007
|
+
</Button>
|
|
1008
|
+
</Form>
|
|
1009
|
+
</Formik>
|
|
1010
|
+
```
|
|
1011
|
+
|
|
812
1012
|
## FormDateTextField
|
|
813
1013
|
|
|
814
1014
|
A versatile date input field component that provides a text-based date picker with Formik integration and Material-UI styling.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { FieldProps } from 'formik';
|
|
3
|
+
import { SwitchProps } from '@mui/material/Switch';
|
|
4
|
+
export interface FormSwitchProps {
|
|
5
|
+
/**
|
|
6
|
+
* Label text displayed next to the switch
|
|
7
|
+
*/
|
|
8
|
+
label?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Position of the label relative to the switch
|
|
11
|
+
* @default 'end'
|
|
12
|
+
*/
|
|
13
|
+
labelPlacement?: 'top' | 'start' | 'bottom' | 'end';
|
|
14
|
+
/**
|
|
15
|
+
* Color of the switch when checked
|
|
16
|
+
* @default 'primary'
|
|
17
|
+
*/
|
|
18
|
+
color?: 'primary' | 'secondary' | 'error' | 'info' | 'success' | 'warning' | 'default';
|
|
19
|
+
/**
|
|
20
|
+
* Size of the switch
|
|
21
|
+
* @default 'medium'
|
|
22
|
+
*/
|
|
23
|
+
size?: 'small' | 'medium';
|
|
24
|
+
/**
|
|
25
|
+
* Whether the switch is disabled
|
|
26
|
+
* @default false
|
|
27
|
+
*/
|
|
28
|
+
disabled?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Whether the switch is required
|
|
31
|
+
* @default false
|
|
32
|
+
*/
|
|
33
|
+
required?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Custom onChange handler with additional switch-related data
|
|
36
|
+
*/
|
|
37
|
+
onChange?: (event: React.ChangeEvent<HTMLInputElement>, checked: boolean, context: {
|
|
38
|
+
fieldName: string;
|
|
39
|
+
formikValue: boolean;
|
|
40
|
+
}) => void;
|
|
41
|
+
/**
|
|
42
|
+
* Custom onBlur handler
|
|
43
|
+
*/
|
|
44
|
+
onBlur?: (event: React.FocusEvent<HTMLButtonElement>) => void;
|
|
45
|
+
/**
|
|
46
|
+
* Helper text to display below the switch
|
|
47
|
+
*/
|
|
48
|
+
helperText?: string;
|
|
49
|
+
/**
|
|
50
|
+
* Error state of the switch
|
|
51
|
+
*/
|
|
52
|
+
error?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Custom class name for the root element
|
|
55
|
+
*/
|
|
56
|
+
className?: string;
|
|
57
|
+
}
|
|
58
|
+
export type FormSwitchComponentProps = FieldProps & SwitchProps & FormSwitchProps;
|
|
59
|
+
export declare const FormSwitch: (props: FormSwitchComponentProps) => import("react/jsx-runtime").JSX.Element;
|
|
60
|
+
//# sourceMappingURL=FormSwitch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormSwitch.d.ts","sourceRoot":"","sources":["../../../src/controls/FormSwitch/FormSwitch.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAS,MAAM,QAAQ,CAAC;AAE3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,cAAc,CAAC,EAAE,KAAK,GAAG,OAAO,GAAG,QAAQ,GAAG,KAAK,CAAC;IAEpD;;;OAGG;IACH,KAAK,CAAC,EAAE,SAAS,GAAG,WAAW,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;IAEvF;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;IAE1B;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;OAEG;IACH,QAAQ,CAAC,EAAE,CACT,KAAK,EAAE,KAAK,CAAC,WAAW,CAAC,gBAAgB,CAAC,EAC1C,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE;QACP,SAAS,EAAE,MAAM,CAAC;QAClB,WAAW,EAAE,OAAO,CAAC;KACtB,KACE,IAAI,CAAC;IAEV;;OAEG;IACH,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,iBAAiB,CAAC,KAAK,IAAI,CAAC;IAE9D;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,wBAAwB,GAAG,UAAU,GAAG,WAAW,GAAG,eAAe,CAAC;AAElF,eAAO,MAAM,UAAU,GAAI,OAAO,wBAAwB,4CAyFzD,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,4 +5,5 @@ export { FormCheckboxField, type FormCheckboxFieldProps, } from './controls/Form
|
|
|
5
5
|
export { FormDateTextField, type FormDateTextFieldProps, } from './controls/FormDateTextField/FormDateTextField';
|
|
6
6
|
export { FormTextField, type FormTextFieldProps, } from './controls/FormTextField/FormTextField';
|
|
7
7
|
export { FormDropDownField, type FormDropDownFieldProps, } from './controls/FormDropDownField/FormDropDownField';
|
|
8
|
+
export { FormSwitch, type FormSwitchProps, } from './controls/FormSwitch/FormSwitch';
|
|
8
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,KAAK,kBAAkB,GACxB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EACL,UAAU,EACV,SAAS,EACT,UAAU,EACV,mBAAmB,EACnB,KAAK,UAAU,GAChB,MAAM,6CAA6C,CAAC;AACrD,OAAO,EACL,aAAa,EACb,KAAK,kBAAkB,GACxB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EACL,iBAAiB,EACjB,KAAK,sBAAsB,GAC5B,MAAM,gDAAgD,CAAC;AAExD,OAAO,EACL,iBAAiB,EACjB,KAAK,sBAAsB,GAC5B,MAAM,gDAAgD,CAAC;AACxD,OAAO,EACL,aAAa,EACb,KAAK,kBAAkB,GACxB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EACL,iBAAiB,EACjB,KAAK,sBAAsB,GAC5B,MAAM,gDAAgD,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,KAAK,kBAAkB,GACxB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EACL,UAAU,EACV,SAAS,EACT,UAAU,EACV,mBAAmB,EACnB,KAAK,UAAU,GAChB,MAAM,6CAA6C,CAAC;AACrD,OAAO,EACL,aAAa,EACb,KAAK,kBAAkB,GACxB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EACL,iBAAiB,EACjB,KAAK,sBAAsB,GAC5B,MAAM,gDAAgD,CAAC;AAExD,OAAO,EACL,iBAAiB,EACjB,KAAK,sBAAsB,GAC5B,MAAM,gDAAgD,CAAC;AACxD,OAAO,EACL,aAAa,EACb,KAAK,kBAAkB,GACxB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EACL,iBAAiB,EACjB,KAAK,sBAAsB,GAC5B,MAAM,gDAAgD,CAAC;AACxD,OAAO,EACL,UAAU,EACV,KAAK,eAAe,GACrB,MAAM,kCAAkC,CAAC"}
|