form-input-fields 1.0.5 → 1.0.6

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
@@ -32,7 +32,7 @@ yarn add @your-org/form-fields @mui/material @emotion/react @emotion/styled form
32
32
  ### Using pnpm
33
33
 
34
34
  ```bash
35
- pnpm add @your-org/form-fields @mui/material @emotion/react @emotion/styled formik @mui/x-date-pickers dayjs
35
+ pnpm add form-input-fields @mui/material @emotion/react @emotion/styled formik @mui/x-date-pickers dayjs
36
36
  ```
37
37
 
38
38
  ### Peer Dependencies
@@ -41,7 +41,7 @@ Make sure your project includes these peer dependencies:
41
41
 
42
42
  ```json
43
43
  {
44
- "peerDependencies": {
44
+ "devDependencies": {
45
45
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0",
46
46
  "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0",
47
47
  "@mui/material": "^5.0.0",
@@ -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 '@your-org/form-fields';
76
+ import { FormTextField, FormDateField, FormMaskField } from 'form-input-fields';
77
77
  ```
78
78
 
79
79
  ### Troubleshooting
@@ -100,7 +100,7 @@ If you encounter any issues during installation, try the following:
100
100
  pnpm install
101
101
  ```
102
102
 
103
- If you're still experiencing issues, please [open an issue](https://github.com/your-org/form-fields/issues) with details about your environment and the error message you're seeing.
103
+ If you're still experiencing issues, please reach me at vladimir.vorobiev@gmail.com with details about your environment and the error message you're seeing.
104
104
 
105
105
 
106
106
  ## Table of Contents
@@ -113,6 +113,14 @@ If you're still experiencing issues, please [open an issue](https://github.com/y
113
113
  - [Basic Text Input](#basic-text-input)
114
114
  - [Text Field with Formik](#text-field-with-formik)
115
115
  - [Custom Validation](#custom-validation)
116
+ - [FormDropDownField](#formdropdownfield)
117
+ - [Features](#features-4)
118
+ - [Basic Usage](#basic-usage-4)
119
+ - [Props](#props-4)
120
+ - [Examples](#examples-4)
121
+ - [Basic Dropdown](#basic-dropdown)
122
+ - [Dropdown with Default Selection](#dropdown-with-default-selection)
123
+ - [Required Dropdown with Validation](#required-dropdown-with-validation)
116
124
  - [FormDateField](#formdatefield)
117
125
  - [Features](#features)
118
126
  - [Available Date Formats](#available-date-formats)
@@ -280,6 +288,131 @@ The FormTextField component accepts all props from `FormTextFieldProps`, `FieldP
280
288
 
281
289
  ---
282
290
 
291
+ ## FormDropDownField
292
+
293
+ A customizable dropdown/select component that integrates Material-UI's Select with Formik form handling.
294
+
295
+ ### Features
296
+
297
+ - **Seamless Formik Integration**: Automatically handles form state, validation, and error messages
298
+ - **Material-UI Styling**: Consistent look and feel with Material Design
299
+ - **TypeScript Support**: Fully typed component with proper type definitions
300
+ - **Flexible Data Binding**: Works with array of objects with `id` and `description` properties
301
+ - **Optional Default Selection**: Add a default "Select" option with customizable text
302
+ - **Form Validation**: Built-in error state management with Formik
303
+ - **Responsive Design**: Works well across different screen sizes
304
+
305
+ ### Basic Usage
306
+
307
+ ```tsx
308
+ import { Formik, Field } from 'formik';
309
+ import { FormDropDownField } from 'form-input-fields';
310
+
311
+ const items = [
312
+ { id: '1', description: 'Option 1' },
313
+ { id: '2', description: 'Option 2' },
314
+ { id: '3', description: 'Option 3' },
315
+ ];
316
+
317
+ <Formik
318
+ initialValues={{ category: '' }}
319
+ onSubmit={(values) => console.log(values)}
320
+ >
321
+ <Field
322
+ component={FormDropDownField}
323
+ name="category"
324
+ label="Category"
325
+ items={items}
326
+ addInputSelect={true}
327
+ />
328
+ </Formik>
329
+ ```
330
+
331
+ ### Props
332
+
333
+ The FormDropDownField component accepts all props from `FormDropDownFieldProps`, `FieldProps` (Formik), and Material-UI's `TextFieldProps` (with some exceptions).
334
+
335
+ #### FormDropDownFieldProps Interface
336
+
337
+ | Prop | Type | Default | Description |
338
+ |------|------|---------|-------------|
339
+ | `items` | `Array<{ id: string | number; description: string }>` | `[]` | Array of items to display in the dropdown |
340
+ | `addInputSelect` | `boolean` | `false` | Whether to show a default "Select" option as the first item |
341
+ | `selectText` | `string` | `'Select'` | Text to display for the default "Select" option |
342
+ | `required` | `boolean` | `false` | Whether the field is required |
343
+ | `disabled` | `boolean` | `false` | Whether the field is disabled |
344
+ | `className` | `string` | - | Custom class name for the root element |
345
+ | `helperText` | `string` | - | Helper text to display below the field |
346
+ | `error` | `boolean` | - | Error state of the field (overrides Formik error state) |
347
+ | `onChange` | `(value: any) => void` | - | Custom change handler |
348
+ | `onBlur` | `(event: React.FocusEvent<HTMLInputElement>) => void` | - | Custom blur handler |
349
+
350
+ ### Examples
351
+
352
+ #### Basic Dropdown
353
+
354
+ ```tsx
355
+ const items = [
356
+ { id: 'us', description: 'United States' },
357
+ { id: 'ca', description: 'Canada' },
358
+ { id: 'uk', description: 'United Kingdom' },
359
+ ];
360
+
361
+ <Field
362
+ component={FormDropDownField}
363
+ name="country"
364
+ label="Country"
365
+ items={items}
366
+ fullWidth
367
+ />
368
+ ```
369
+
370
+ #### Dropdown with Default Selection
371
+
372
+ ```tsx
373
+ <Field
374
+ component={FormDropDownField}
375
+ name="category"
376
+ label="Category"
377
+ items={categories}
378
+ addInputSelect={true}
379
+ selectText="Select a category"
380
+ helperText="Please select a category from the list"
381
+ />
382
+ ```
383
+
384
+ #### Required Dropdown with Validation
385
+
386
+ ```tsx
387
+ <Formik
388
+ initialValues={{ department: '' }}
389
+ validationSchema={Yup.object({
390
+ department: Yup.string().required('Department is required'),
391
+ })}
392
+ onSubmit={(values) => console.log(values)}
393
+ >
394
+ {({ errors, touched }) => (
395
+ <Form>
396
+ <Field
397
+ component={FormDropDownField}
398
+ name="department"
399
+ label="Department"
400
+ items={departments}
401
+ addInputSelect={true}
402
+ required
403
+ error={touched.department && Boolean(errors.department)}
404
+ helperText={touched.department && errors.department}
405
+ />
406
+ <Button type="submit" variant="contained" color="primary">
407
+ Submit
408
+ </Button>
409
+ </Form>
410
+ )}
411
+ </Formik>
412
+ ```
413
+
414
+ ---
415
+
283
416
  ## FormDateField
284
417
 
285
418
  A date input field component with Material-UI and Formik integration, powered by MUI X Date Pickers.
@@ -0,0 +1,56 @@
1
+ import { FieldProps } from 'formik';
2
+ import { TextFieldProps } from '@mui/material';
3
+ export interface FormDropDownFieldProps {
4
+ /**
5
+ * Array of items to display in the dropdown
6
+ * Each item should have an `id` and `description` property
7
+ */
8
+ items: Array<{
9
+ id: string | number;
10
+ description: string;
11
+ }>;
12
+ /**
13
+ * Whether to show a default "Select" option as the first item
14
+ * @default false
15
+ */
16
+ addInputSelect?: boolean;
17
+ /**
18
+ * Text to display for the default "Select" option
19
+ * @default 'Select'
20
+ */
21
+ selectText?: string;
22
+ /**
23
+ * Whether the field is required
24
+ * @default false
25
+ */
26
+ required?: boolean;
27
+ /**
28
+ * Whether the field is disabled
29
+ * @default false
30
+ */
31
+ disabled?: boolean;
32
+ /**
33
+ * Custom class name for the root element
34
+ */
35
+ className?: string;
36
+ /**
37
+ * Helper text to display below the field
38
+ */
39
+ helperText?: string;
40
+ /**
41
+ * Error state of the field
42
+ */
43
+ error?: boolean;
44
+ /**
45
+ * Custom onChange handler
46
+ */
47
+ onChange?: (value: any) => void;
48
+ /**
49
+ * Custom onBlur handler
50
+ */
51
+ onBlur?: (event: React.FocusEvent<HTMLInputElement>) => void;
52
+ }
53
+ type FormDropDownFieldComponentProps = FormDropDownFieldProps & FieldProps & Omit<TextFieldProps, 'value' | 'onChange' | 'onBlur' | 'name' | 'defaultValue' | 'onError' | 'onFocus' | 'InputProps' | 'select' | 'SelectProps'>;
54
+ export declare const FormDropDownField: ({ field, form, items, addInputSelect, selectText, required, disabled, className, helperText, error, onChange, onBlur, ...props }: FormDropDownFieldComponentProps) => import("react/jsx-runtime").JSX.Element;
55
+ export {};
56
+ //# sourceMappingURL=FormDropDownField.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormDropDownField.d.ts","sourceRoot":"","sources":["../../../src/controls/FormDropDownField/FormDropDownField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAS,MAAM,QAAQ,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAoC,MAAM,eAAe,CAAC;AAGjF,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,KAAK,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAE3D;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;OAEG;IACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;IAEhC;;OAEG;IACH,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAC;CAC9D;AAED,KAAK,+BAA+B,GAAG,sBAAsB,GAC3D,UAAU,GACV,IAAI,CACF,cAAc,EACZ,OAAO,GACP,UAAU,GACV,QAAQ,GACR,MAAM,GACN,cAAc,GACd,SAAS,GACT,SAAS,GACT,YAAY,GACZ,QAAQ,GACR,aAAa,CAChB,CAAC;AAEJ,eAAO,MAAM,iBAAiB,GAAI,kIAc/B,+BAA+B,4CAiEjC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const useStyles: (props?: any) => import('@mui/styles').ClassNameMap<"margin" | "inputSelect">;
2
+ //# sourceMappingURL=styles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../src/controls/FormDropDownField/styles.tsx"],"names":[],"mappings":"AAIA,eAAO,MAAM,SAAS,+EAYrB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -4,4 +4,5 @@ export { FormDateField, type FormDateFieldProps, } from './controls/FormDateFiel
4
4
  export { FormCheckboxField, type FormCheckboxFieldProps, } from './controls/FormCheckboxField/FormCheckboxField';
5
5
  export { FormDateTextField, type FormDateTextFieldProps, } from './controls/FormDateTextField/FormDateTextField';
6
6
  export { FormTextField, type FormTextFieldProps, } from './controls/FormTextField/FormTextField';
7
+ export { FormDropDownField, type FormDropDownFieldProps, } from './controls/FormDropDownField/FormDropDownField';
7
8
  //# 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"}
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"}