form-input-fields 1.0.6 → 1.0.8

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 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,42 @@
1
+ export interface FormSwitchProps {
2
+ id: string;
3
+ checked: boolean;
4
+ /**
5
+ * Label text displayed next to the switch
6
+ */
7
+ label?: string;
8
+ /**
9
+ * Color of the switch when checked
10
+ * @default 'primary'
11
+ */
12
+ color?: 'primary' | 'secondary' | 'error' | 'info' | 'success' | 'warning' | 'default';
13
+ /**
14
+ * Whether the switch is disabled
15
+ * @default false
16
+ */
17
+ disabled?: boolean;
18
+ /**
19
+ * Whether the switch is required
20
+ * @default false
21
+ */
22
+ required?: boolean;
23
+ /**
24
+ * Custom onChange handler with additional switch-related data
25
+ */
26
+ onChange: () => void;
27
+ /**
28
+ * Helper text to display below the switch
29
+ */
30
+ helperText?: string;
31
+ /**
32
+ * Error state of the switch
33
+ */
34
+ error?: boolean;
35
+ /**
36
+ * Custom class name for the root element
37
+ */
38
+ className?: string;
39
+ }
40
+ export type FormSwitchComponentProps = FormSwitchProps;
41
+ export declare const FormSwitch: (props: FormSwitchComponentProps) => import("react/jsx-runtime").JSX.Element;
42
+ //# sourceMappingURL=FormSwitch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormSwitch.d.ts","sourceRoot":"","sources":["../../../src/controls/FormSwitch/FormSwitch.tsx"],"names":[],"mappings":"AAgBA,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IAEX,OAAO,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,KAAK,CAAC,EAAE,SAAS,GAAG,WAAW,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;IAEvF;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;OAEG;IACH,QAAQ,EAAE,MAAM,IAAI,CAAC;IAErB;;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,GAAI,eAAe,CAAC;AAExD,eAAO,MAAM,UAAU,GAAI,OAAO,wBAAwB,4CAgCzD,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
@@ -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"}