@kbgarcia8/react-dynamic-form 1.1.3 → 1.1.26
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 +422 -1
- package/dist/components/atoms/Label/Label.d.ts.map +1 -1
- package/dist/components/atoms/Label/Label.styles.d.ts +1 -0
- package/dist/components/atoms/Label/Label.styles.d.ts.map +1 -1
- package/dist/components/molecules/FormActionButtons/FormActionButtons.d.ts +1 -1
- package/dist/components/molecules/FormActionButtons/FormActionButtons.d.ts.map +1 -1
- package/dist/components/molecules/LabeledInput/LabeledInput.d.ts +2 -2
- package/dist/components/molecules/LabeledInput/LabeledInput.d.ts.map +1 -1
- package/dist/components/organisms/DynamicForm/DynamicForm.d.ts +1 -1
- package/dist/components/organisms/DynamicForm/DynamicForm.d.ts.map +1 -1
- package/dist/context/ThemeContext.d.ts +1 -1
- package/dist/context/ThemeContext.d.ts.map +1 -1
- package/dist/context/ThemeContextWrapper.d.ts +5 -1
- package/dist/context/ThemeContextWrapper.d.ts.map +1 -1
- package/dist/hooks/useTheme.d.ts +1 -1
- package/dist/hooks/useTheme.d.ts.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/react-dynamic-form.cjs.js +72 -66
- package/dist/react-dynamic-form.es.js +395 -390
- package/dist/styles/styled.d.ts +7 -0
- package/dist/styles/styled.d.ts.map +1 -0
- package/dist/type/propTypes.d.ts +41 -31
- package/dist/type/propTypes.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,2 +1,423 @@
|
|
|
1
1
|
# react-dynamic-form
|
|
2
|
-
|
|
2
|
+
Reusable React dynamic form showcasing editable, expandable and flexible inputs
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@kbgarcia8/react-dynamic-form)
|
|
7
|
+
[](https://www.npmjs.com/package/@kbgarcia8/react-dynamic-form)
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Table of Contents
|
|
12
|
+
<!-- TOC start (generated with https://github.com/derlin/bitdowntoc) -->
|
|
13
|
+
|
|
14
|
+
- [Features](#features)
|
|
15
|
+
- [Installation](#installation)
|
|
16
|
+
- [Usage](#usage)
|
|
17
|
+
* [Case 1: Using fieldsets prop](#case-1-using-fieldsets-prop)
|
|
18
|
+
+ [Supports multi-section forms that allows multiple groups of related inputs](#supports-multi-section-forms-that-allows-multiple-groups-of-related-inputs)
|
|
19
|
+
- [<u>Example Scenario:</u>](#example-scenario)
|
|
20
|
+
* [Case 2: Using formInputs prop](#case-2-using-forminputs-prop)
|
|
21
|
+
+ [Supports single-section form that only needs one group of information](#supports-single-section-form-that-only-needs-one-group-of-information)
|
|
22
|
+
- [<u>Example Scenario:</u>](#example-scenario-1)
|
|
23
|
+
- [API](#api)
|
|
24
|
+
* [Dynamic Form Props](#dynamic-form-props)
|
|
25
|
+
* [Additional Props information](#additional-props-information)
|
|
26
|
+
+ [For editable input element of formInputs or inputs if fieldsets is used. Declared via inputEntryShape[] as NestedEditableOptionProps](#for-editable-input-element-of-forminputs-or-inputs-if-fieldsets-is-used-declared-via-inputentryshape-as-nestededitableoptionprops)
|
|
27
|
+
+ [For editableInformation object inside editable input. Declared as EditableInformation interface. Below is the properties needed:](#for-editableinformation-object-inside-editable-input-declared-as-editableinformation-interface-below-is-the-properties-needed)
|
|
28
|
+
+ [For more information on props types see:](#for-more-information-on-props-types-see)
|
|
29
|
+
- [Customization](#customization)
|
|
30
|
+
* [Theme Support via styled components](#theme-support-via-styled-components)
|
|
31
|
+
+ [Option 1: Users want theming via default Theme provided](#option-1-users-want-theming-via-default-theme-provided)
|
|
32
|
+
+ [Option 2: Users want custom theme](#option-2-users-want-custom-theme)
|
|
33
|
+
- [Reminder for custom theme override:](#reminder-for-custom-theme-override)
|
|
34
|
+
+ [Example usage of theme using styled-components](#example-usage-of-theme-using-styled-components)
|
|
35
|
+
+ [Example usage of theme toggle inside component](#example-usage-of-theme-toggle-inside-component)
|
|
36
|
+
* [Styling components via styled-components](#styling-components-via-styled-components)
|
|
37
|
+
+ [Available Default Class Names](#available-default-class-names)
|
|
38
|
+
- [Local Development](#local-development)
|
|
39
|
+
* [License](#license)
|
|
40
|
+
|
|
41
|
+
<!-- TOC end -->
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
<!-- TOC --><a name="features"></a>
|
|
45
|
+
## Features
|
|
46
|
+
- 🖌️ Themeing support via styled components
|
|
47
|
+
- 🆗 Typescript support
|
|
48
|
+
- ↔️ Expandable and editable via nested form structure
|
|
49
|
+
- 🧩 Ease of integration in any React project
|
|
50
|
+
---
|
|
51
|
+
<!-- TOC --><a name="installation"></a>
|
|
52
|
+
## Installation
|
|
53
|
+
```bash
|
|
54
|
+
npm install @kbgarcia8/react-dynamic-form
|
|
55
|
+
# or
|
|
56
|
+
yarn add @kbgarcia8/react-dynamic-form
|
|
57
|
+
```
|
|
58
|
+
---
|
|
59
|
+
<!-- TOC --><a name="usage"></a>
|
|
60
|
+
## Usage
|
|
61
|
+
|
|
62
|
+
<!-- TOC --><a name="case-1-using-fieldsets-prop"></a>
|
|
63
|
+
### Case 1: Using fieldsets prop
|
|
64
|
+
<!-- TOC --><a name="supports-multi-section-forms-that-allows-multiple-groups-of-related-inputs"></a>
|
|
65
|
+
#### Supports multi-section forms that allows multiple groups of related inputs
|
|
66
|
+
|
|
67
|
+
This is designed for scenarios where your for needs to be split into <b>multiple groups of input</b> each representing <b>different types of information</b>
|
|
68
|
+
|
|
69
|
+
<!-- TOC --><a name="example-scenario"></a>
|
|
70
|
+
##### <u>Example Scenario:</u>
|
|
71
|
+
Cart Logic
|
|
72
|
+
|
|
73
|
+
- Payment method information
|
|
74
|
+
- Billing address
|
|
75
|
+
- Shipping address
|
|
76
|
+
- Contact details
|
|
77
|
+
|
|
78
|
+
Each of these becomes its own fieldset inside a single DynamicForm.
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
```tsx
|
|
82
|
+
import { DynamicForm } from '@kbgarcia8/react-dynamic-form'
|
|
83
|
+
import type { FieldsetShape } from '@kbgarcia8/react-dynamic-form'
|
|
84
|
+
|
|
85
|
+
const addressInputsArray = [
|
|
86
|
+
{
|
|
87
|
+
//Input Props
|
|
88
|
+
type: ... as const, id: ..., isRequired: ...,
|
|
89
|
+
//dataAttributes is obtained through map
|
|
90
|
+
disabled: ..., name: ..., value: ..., placeholderText: ...,
|
|
91
|
+
//Start of Label Props
|
|
92
|
+
textLabel: ..., additionalInfo: ..., $labelFlexDirection: ... as const, svg: <.../>,
|
|
93
|
+
//Start of EditableInputProps
|
|
94
|
+
labelClass: ..., inputClass: ..., isEditable: ...,
|
|
95
|
+
//Additional in inputEntryShape
|
|
96
|
+
editIcon: <.../>, //=>editIcon in EditableInputProps
|
|
97
|
+
deleteIcon: <.../>,
|
|
98
|
+
editing: ...,
|
|
99
|
+
//These are informations editable within radio input acting as selection
|
|
100
|
+
editableInformation: [
|
|
101
|
+
{
|
|
102
|
+
name: ...,
|
|
103
|
+
info: ...,
|
|
104
|
+
type: ... as const
|
|
105
|
+
}
|
|
106
|
+
],
|
|
107
|
+
//onClick functions obtained through map
|
|
108
|
+
}
|
|
109
|
+
];
|
|
110
|
+
|
|
111
|
+
const fieldsets:FieldsetShape[] = [
|
|
112
|
+
{
|
|
113
|
+
legend: "Address Informations",
|
|
114
|
+
inputs: addressInputsArray.map((address, index) => ({
|
|
115
|
+
...address,
|
|
116
|
+
id: `${address.id}-${index}`,
|
|
117
|
+
onChange: ...,
|
|
118
|
+
onClickEdit: ...,
|
|
119
|
+
onClickDelete: ...,
|
|
120
|
+
onClickSave: ...,
|
|
121
|
+
onClickCancel: ...,
|
|
122
|
+
dataAttributes: {
|
|
123
|
+
"data-index": index
|
|
124
|
+
}
|
|
125
|
+
})),
|
|
126
|
+
isExpandable: true
|
|
127
|
+
},
|
|
128
|
+
];
|
|
129
|
+
|
|
130
|
+
function App() {
|
|
131
|
+
return (
|
|
132
|
+
<DynamicForm
|
|
133
|
+
className={'with-fieldsets'}
|
|
134
|
+
fieldsets={fieldsets}
|
|
135
|
+
id="address"
|
|
136
|
+
isExpandable={true}
|
|
137
|
+
{...props}
|
|
138
|
+
/>
|
|
139
|
+
)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
<!-- TOC --><a name="case-2-using-forminputs-prop"></a>
|
|
145
|
+
### Case 2: Using formInputs prop
|
|
146
|
+
<!-- TOC --><a name="supports-single-section-form-that-only-needs-one-group-of-information"></a>
|
|
147
|
+
#### Supports single-section form that only needs one group of information
|
|
148
|
+
|
|
149
|
+
A legend text is optional in this part. This is a common/basic form scenario. It only needs an array of inputs which is rendered as a single form
|
|
150
|
+
|
|
151
|
+
<!-- TOC --><a name="example-scenario-1"></a>
|
|
152
|
+
##### <u>Example Scenario:</u>
|
|
153
|
+
- Profile information
|
|
154
|
+
- Login form
|
|
155
|
+
- Address form
|
|
156
|
+
- Single purpose editable section
|
|
157
|
+
|
|
158
|
+
```tsx
|
|
159
|
+
import { DynamicForm } from '@kbgarcia8/react-dynamic-form'
|
|
160
|
+
import type { FieldsetShape } from '@kbgarcia8/react-dynamic-form'
|
|
161
|
+
|
|
162
|
+
const addressInputsArray = [
|
|
163
|
+
{
|
|
164
|
+
//Input Props
|
|
165
|
+
type: ... as const, id: ..., isRequired: ...,
|
|
166
|
+
//dataAttributes is obtained through map
|
|
167
|
+
disabled: ..., name: ..., value: ..., placeholderText: ...,
|
|
168
|
+
//Start of Label Props
|
|
169
|
+
textLabel: ..., additionalInfo: ..., $labelFlexDirection: ... as const, svg: <.../>,
|
|
170
|
+
//Start of EditableInputProps
|
|
171
|
+
labelClass: ..., inputClass: ..., isEditable: ...,
|
|
172
|
+
//Additional in inputEntryShape
|
|
173
|
+
editIcon: <.../>, //=>editIcon in EditableInputProps
|
|
174
|
+
deleteIcon: <.../>,
|
|
175
|
+
editing: ...,
|
|
176
|
+
//These are informations editable within radio input acting as selection
|
|
177
|
+
editableInformation: [
|
|
178
|
+
{
|
|
179
|
+
name: ...,
|
|
180
|
+
info: ...,
|
|
181
|
+
type: ... as const
|
|
182
|
+
}
|
|
183
|
+
],
|
|
184
|
+
//onClick functions obtained through map
|
|
185
|
+
}
|
|
186
|
+
];
|
|
187
|
+
|
|
188
|
+
const addressInputs = addressInputsArray.map((address, index) => ({
|
|
189
|
+
...address,
|
|
190
|
+
id: `${address.id}-${index}`,
|
|
191
|
+
onChange: ...,
|
|
192
|
+
onClickEdit: ...,
|
|
193
|
+
onClickDelete: ...,
|
|
194
|
+
onClickSave: ...,
|
|
195
|
+
onClickCancel: ...,
|
|
196
|
+
dataAttributes: {
|
|
197
|
+
"data-index": index
|
|
198
|
+
}
|
|
199
|
+
})),
|
|
200
|
+
|
|
201
|
+
function App() {
|
|
202
|
+
return (
|
|
203
|
+
<DynamicForm
|
|
204
|
+
className={'with-fieldsets'}
|
|
205
|
+
legendText={'Address Information'}
|
|
206
|
+
formInputs={addressInputs}
|
|
207
|
+
id="address"
|
|
208
|
+
isExpandable={true}
|
|
209
|
+
{...props}
|
|
210
|
+
/>
|
|
211
|
+
)
|
|
212
|
+
}
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
<!-- TOC --><a name="api"></a>
|
|
216
|
+
## API
|
|
217
|
+
<!-- TOC --><a name="dynamic-form-props"></a>
|
|
218
|
+
### Dynamic Form Props
|
|
219
|
+
| Prop | Type | Default | Description |
|
|
220
|
+
| --------- | ------------ | -------- | ------------------------------- |
|
|
221
|
+
| `fieldsets` | `FieldsetShape[]` | `null` | Used in multi-section form containing inputs divided into information groups<br><br>If used, legendText and formInputs is no longer needed |
|
|
222
|
+
| `legendText` | `string` | — | |
|
|
223
|
+
| `formInputs` | `inputEntryShape[]` | — | If no fieldsets is provided, this is an object containing information for label and inputs of a single-section form |
|
|
224
|
+
| `isExpandable` | `boolean` | `false` | If inputs are used as options commonly in type: checkbox/radio, this is to enabale a button for entry adding. If fieldset is null this is default to false |
|
|
225
|
+
| `id` | `string` | — | Form tag id |
|
|
226
|
+
| `labelAndInputContainerClass` | `string` | — | className for `<LabeledInput/>` component inside `<DynamicForm/>` |
|
|
227
|
+
| `labelClass` | `string` | — | className for `<Label/>` component inside `<LabeledInput/>` component inside `<DynamicForm/>` |
|
|
228
|
+
| `inputClass` | `string` | — | className for `<Input/>` component inside `<LabeledInput/>` component inside `<DynamicForm/>` |
|
|
229
|
+
| `handleEditableInputEntryChange` | `(e:React.ChangeEvent<HTMLInputElement\|HTMLTextAreaElement>) => void` | — | Function to handle onChange of editable inputs |
|
|
230
|
+
| `handleAddingInputEntry` | `(e:React.MouseEvent<HTMLButtonElement>) => void` | — | Function to add input entry. If isExpandable is false this is not enabled |
|
|
231
|
+
| `hasSubmit` | `boolean` | `false` | This is to enable submit button for `<DynamicForm/>` |
|
|
232
|
+
| `submitText` | `string` | `Submit` | Text inside submit button for `<DynamicForm/>` |
|
|
233
|
+
| `handleSubmit` | `(e:React.MouseEvent<HTMLButtonElement>) => void` | — | Function to handle submit logic for `<DynamicForm/>` |
|
|
234
|
+
| `hasReset` | `boolean` | `false` | This is to enable reset button for `<DynamicForm/>` |
|
|
235
|
+
| `resetText` | `string` | `Reset` | Text inside reset button for `<DynamicForm/>` |
|
|
236
|
+
| `handleReset` | `(e:React.MouseEvent<HTMLButtonElement>) => void` | — | Function to handle reset logic for `<DynamicForm/>` |
|
|
237
|
+
| `hasCancel` | `boolean` | `false` | This is to cancel submit button for `<DynamicForm/>` |
|
|
238
|
+
| `cancelText` | `string` | `Cancel` | Text inside cancel button for `<DynamicForm/>` |
|
|
239
|
+
| `handleCancel` | `(e:React.MouseEvent<HTMLButtonElement>) => void` | — | Function to handle cancel logic for `<DynamicForm/>` |
|
|
240
|
+
| `handleSubmitForm` | `(e:React.FormEvent<HTMLFormElement>) => void` | — | Function to handle form submit logic for `<DynamicForm/>` |
|
|
241
|
+
| `className` | `string` | — | className for `<DynamicForm/>` |
|
|
242
|
+
| `children` | `React.ReactNode` | — | React node/s or component placed after `<FormActionButtons/>` inside `<DynamicForm/>` |
|
|
243
|
+
|
|
244
|
+
<!-- TOC --><a name="additional-props-information"></a>
|
|
245
|
+
### Additional Props information
|
|
246
|
+
<!-- TOC --><a name="for-editable-input-element-of-forminputs-or-inputs-if-fieldsets-is-used-declared-via-inputentryshape-as-nestededitableoptionprops"></a>
|
|
247
|
+
#### For editable input element of formInputs or inputs if fieldsets is used. Declared via inputEntryShape[] as NestedEditableOptionProps
|
|
248
|
+
| Prop | Type | Default | Description |
|
|
249
|
+
| --------- | ------------ | -------- | ------------------------------- |
|
|
250
|
+
| `uniqueClass` | `string` | — | className to uniquely select/distinguish a LabeledInput container |
|
|
251
|
+
| `isEditable` | `boolean` | — | To determine if an input is editable or not<br>If false, all props below are automatically not needed |
|
|
252
|
+
| `editing` | `boolean` | — | To identify if an editable input is being modified<br>Can be used in open/close dialogs |
|
|
253
|
+
| `onClickEdit` | `(e:React.MouseEvent<HTMLButtonElement>) => void` | — | Function to handle edit logic of editable input |
|
|
254
|
+
| `editIcon` | `React.ReactNode` | — | TSX/JSX svg component that will serve as an icon for edit button of editable input |
|
|
255
|
+
| `onClickDelete` | `(e:React.MouseEvent<HTMLButtonElement>) => void` | — | Function to handle delete logic of editable input |
|
|
256
|
+
| `deleteIcon` | `React.ReactNode` | — | TSX/JSX svg component that will serve as an icon for delete button of editable input |
|
|
257
|
+
| `onClickSave` | `(e:React.MouseEvent<HTMLButtonElement>) => void` | — | Function to handle save logic of editable input |
|
|
258
|
+
| `onClickCancel` | `(e:React.MouseEvent<HTMLButtonElement>) => void` | — | Function to handle cancel logic of editable input |
|
|
259
|
+
|
|
260
|
+
<!-- TOC --><a name="for-editableinformation-object-inside-editable-input-declared-as-editableinformation-interface-below-is-the-properties-needed"></a>
|
|
261
|
+
#### For editableInformation object inside editable input. Declared as EditableInformation interface. Below is the properties needed:
|
|
262
|
+
| Property | Type | Description |
|
|
263
|
+
| --------- | ------------ | ------------------------------- |
|
|
264
|
+
| `name` | `string` | Serves as placeholder text for editable input |
|
|
265
|
+
| `info` | `string` | Serves as value for editable input |
|
|
266
|
+
| `type` | `string` | Input type of editable input |
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
<!-- TOC --><a name="for-more-information-on-props-types-see"></a>
|
|
270
|
+
#### For more information on props types see:
|
|
271
|
+
[](https://www.npmjs.com/package/@kbgarcia8/react-dynamic-form?activeTab=code)
|
|
273
|
+
|
|
274
|
+
Note that types/interfaces are also exported via npm package and can be imported as shown below:
|
|
275
|
+
|
|
276
|
+
```tsx
|
|
277
|
+
import type { FieldsetShape, inputEntryShape } from '@kbgarcia8/react-dynamic-form'
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
<!-- TOC --><a name="customization"></a>
|
|
281
|
+
## Customization
|
|
282
|
+
<!-- TOC --><a name="theme-support-via-styled-components"></a>
|
|
283
|
+
### Theme Support via styled components
|
|
284
|
+
|
|
285
|
+
<!-- TOC --><a name="option-1-users-want-theming-via-default-theme-provided"></a>
|
|
286
|
+
#### Option 1: Users want theming via default Theme provided
|
|
287
|
+
```tsx
|
|
288
|
+
import { StrictMode } from 'react'
|
|
289
|
+
import { createRoot } from 'react-dom/client'
|
|
290
|
+
import { ThemeContextProvider } from '@kbgarcia8/react-dynamic-form'
|
|
291
|
+
import './index.css'
|
|
292
|
+
import App from './App.tsx'
|
|
293
|
+
|
|
294
|
+
createRoot(document.getElementById('root')!).render(
|
|
295
|
+
<StrictMode>
|
|
296
|
+
<ThemeContextProvider>
|
|
297
|
+
<App />
|
|
298
|
+
</ThemeContextProvider>
|
|
299
|
+
</StrictMode>,
|
|
300
|
+
)
|
|
301
|
+
```
|
|
302
|
+
<!-- TOC --><a name="option-2-users-want-custom-theme"></a>
|
|
303
|
+
#### Option 2: Users want custom theme
|
|
304
|
+
You allow overriding currentTheme:
|
|
305
|
+
```tsx
|
|
306
|
+
<ThemeContextProvider initialTheme={myCustomLightTheme} secondTheme={myCustomDarkTheme}>
|
|
307
|
+
<DynamicForm />
|
|
308
|
+
</ThemeContextProvider>
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
<!-- TOC --><a name="reminder-for-custom-theme-override"></a>
|
|
312
|
+
##### Reminder for custom theme override:
|
|
313
|
+
|
|
314
|
+
Below is the supported format for creating a theme object. Usually consisting of light and dark theme
|
|
315
|
+
|
|
316
|
+
asColor function is used to ensure that color to be supplied in color properties are colors (e.g. hexcode and rgb code). Note that keys of colors are changeable since it has type ``
|
|
317
|
+
|
|
318
|
+
```tsx
|
|
319
|
+
import { asColor } from '@kbgarcia8/react-dynamic-form'
|
|
320
|
+
|
|
321
|
+
export const lightTheme:Theme = {
|
|
322
|
+
name: 'light',
|
|
323
|
+
colors: {
|
|
324
|
+
text: asColor('#333446'),
|
|
325
|
+
bg: asColor('#EEEEEE'),
|
|
326
|
+
...
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export const darkTheme:Theme = {
|
|
331
|
+
name: 'dark',
|
|
332
|
+
colors: {
|
|
333
|
+
bg: asColor('#333446'),
|
|
334
|
+
text: asColor('#EEEEEE'),
|
|
335
|
+
...
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
<!-- TOC --><a name="example-usage-of-theme-using-styled-components"></a>
|
|
341
|
+
#### Example usage of theme using styled-components
|
|
342
|
+
Inside \<Component\>.styles.[ts | js]
|
|
343
|
+
```tsx
|
|
344
|
+
export const DefaultButton = styled.button`
|
|
345
|
+
color: ${({theme})=> theme.colors.bg || 'white'};
|
|
346
|
+
`
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
<!-- TOC --><a name="example-usage-of-theme-toggle-inside-component"></a>
|
|
350
|
+
#### Example usage of theme toggle inside component
|
|
351
|
+
```tsx
|
|
352
|
+
import useTheme from '@kbgarcia8/react-dynamic-form'
|
|
353
|
+
|
|
354
|
+
const ThemeToggleButton = () => {
|
|
355
|
+
const { currentTheme, toggleTheme } = useTheme();
|
|
356
|
+
|
|
357
|
+
const isDark = currentTheme.name === 'dark' ? true : false;
|
|
358
|
+
|
|
359
|
+
return (
|
|
360
|
+
<Styled.Root
|
|
361
|
+
checked={isDark}
|
|
362
|
+
onCheckedChange={toggleTheme}
|
|
363
|
+
>
|
|
364
|
+
<Styled.Thumb $isDark={isDark}>
|
|
365
|
+
{isDark ? <Moon size={20} /> : <Sun size={20} />}
|
|
366
|
+
</Styled.Thumb>
|
|
367
|
+
</Styled.Root>
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
<!-- TOC --><a name="styling-components-via-styled-components"></a>
|
|
373
|
+
### Styling components via styled-components
|
|
374
|
+
<!-- TOC --><a name="available-default-class-names"></a>
|
|
375
|
+
#### Available Default Class Names
|
|
376
|
+
Every renderable part of the form receives predictable classes or id:
|
|
377
|
+
| Component | Default class name | Notes |
|
|
378
|
+
| ---------------------------- | ----------------------------------------------------- | --------------------------- |
|
|
379
|
+
| **Form** | `${id}-form` | Root form container |
|
|
380
|
+
| **Fieldset Wrapper** | `${id}-fieldset-wrapper` | One per fieldset |
|
|
381
|
+
| **Fieldset** | `${legend}-fieldset` | Based on fieldset legend |
|
|
382
|
+
| **Legend** | `${legend}-legend` | Based on fieldset legend |
|
|
383
|
+
| **LabeledInput container** | `${labelAndInputContainerClass} ${input.uniqueClass}` | User-controlled |
|
|
384
|
+
| **Label** | `${inputClass}` | User-controlled (inside LabeledInput) |
|
|
385
|
+
| **Input** | `${labelAndInputContainerClass} ${input.uniqueClass}` | User-controlled (inside LabeledInput) |
|
|
386
|
+
| **Add Entry Button** | `add-input-entry` | Used when `isExpandable` |
|
|
387
|
+
| **Add Entry Button Wrapper** | `add-input-button-space` | |
|
|
388
|
+
| **No Entry Message** | *default styled component* | Target using parent wrapper |
|
|
389
|
+
| **Children Container** | `children-container` | |
|
|
390
|
+
|
|
391
|
+
```ts
|
|
392
|
+
import styled from "styled-components";
|
|
393
|
+
import { DynamicForm } from "@kbgarcia8/react-dynamic-form";
|
|
394
|
+
|
|
395
|
+
const StyledMyForm = styled(DynamicForm)`
|
|
396
|
+
&.address-form {...}
|
|
397
|
+
|
|
398
|
+
.address-fieldset-wrapper {...}
|
|
399
|
+
|
|
400
|
+
.add-input-entry {...}
|
|
401
|
+
|
|
402
|
+
.children-container {...}
|
|
403
|
+
|
|
404
|
+
.<labelInputContainerClass> {...}
|
|
405
|
+
|
|
406
|
+
.<inputClass> {...}
|
|
407
|
+
|
|
408
|
+
.<labelClass> {...}
|
|
409
|
+
`;
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
<!-- TOC --><a name="local-development"></a>
|
|
413
|
+
## Local Development
|
|
414
|
+
```bash
|
|
415
|
+
git clone https://github.com/kbgarcia8/react-dynamic-form
|
|
416
|
+
cd react-dynamic-form
|
|
417
|
+
npm install
|
|
418
|
+
npm run dev
|
|
419
|
+
```
|
|
420
|
+
<!-- TOC --><a name="license"></a>
|
|
421
|
+
### License
|
|
422
|
+
[](https://github.com/kbgarcia8/react-dynamic-form/blob/main/LICENSE)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Label.d.ts","sourceRoot":"","sources":["../../../../src/components/atoms/Label/Label.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAE1D,QAAA,MAAM,KAAK,GAAI,+FASZ,KAAK,CAAC,iBAAiB,CAAC,UAAU,CAAC,
|
|
1
|
+
{"version":3,"file":"Label.d.ts","sourceRoot":"","sources":["../../../../src/components/atoms/Label/Label.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAE1D,QAAA,MAAM,KAAK,GAAI,+FASZ,KAAK,CAAC,iBAAiB,CAAC,UAAU,CAAC,4CAarC,CAAA;AAED,eAAe,KAAK,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { LabelProps } from "../../../type/propTypes";
|
|
2
2
|
export declare const DefaultLabel: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").LabelHTMLAttributes<HTMLLabelElement>, HTMLLabelElement>, Pick<LabelProps, "$labelFlexDirection">>> & string;
|
|
3
|
+
export declare const LabelTextContainer: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
|
|
3
4
|
export declare const MainLabelText: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, never>> & string;
|
|
4
5
|
export declare const LabelIconContainer: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
|
|
5
6
|
export declare const LabelAdditionalInfo: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, never>> & string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Label.styles.d.ts","sourceRoot":"","sources":["../../../../src/components/atoms/Label/Label.styles.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAE1D,eAAO,MAAM,YAAY,qRAiBxB,CAAC;AAEF,eAAO,MAAM,aAAa,+NAEzB,CAAC;AAEF,eAAO,MAAM,kBAAkB,6NAI9B,CAAC;AAEF,eAAO,MAAM,mBAAmB,+NAE/B,CAAC"}
|
|
1
|
+
{"version":3,"file":"Label.styles.d.ts","sourceRoot":"","sources":["../../../../src/components/atoms/Label/Label.styles.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAE1D,eAAO,MAAM,YAAY,qRAiBxB,CAAC;AAEF,eAAO,MAAM,kBAAkB,6NAM9B,CAAC;AAEF,eAAO,MAAM,aAAa,+NAEzB,CAAC;AAEF,eAAO,MAAM,kBAAkB,6NAI9B,CAAC;AAEF,eAAO,MAAM,mBAAmB,+NAE/B,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { FormActionButtonsProps } from "../../../type/propTypes";
|
|
2
|
-
declare const FormActionButtons: ({ id, hasSubmit, submitText, handleSubmit,
|
|
2
|
+
declare const FormActionButtons: ({ id, hasSubmit, submitText, handleSubmit, hasReset, resetText, handleReset, hasCancel, cancelText, handleCancel, }: FormActionButtonsProps) => import("react/jsx-runtime").JSX.Element;
|
|
3
3
|
export default FormActionButtons;
|
|
4
4
|
//# sourceMappingURL=FormActionButtons.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormActionButtons.d.ts","sourceRoot":"","sources":["../../../../src/components/molecules/FormActionButtons/FormActionButtons.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAEtE,QAAA,MAAM,iBAAiB,GAAI,
|
|
1
|
+
{"version":3,"file":"FormActionButtons.d.ts","sourceRoot":"","sources":["../../../../src/components/molecules/FormActionButtons/FormActionButtons.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAEtE,QAAA,MAAM,iBAAiB,GAAI,qHAWzB,sBAAsB,4CAQvB,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import type {
|
|
3
|
-
declare const LabeledInput: (props: React.PropsWithChildren<
|
|
2
|
+
import type { LabeledCheckboxOrRadio, LabeledTextLike } from "../../../type/propTypes";
|
|
3
|
+
declare const LabeledInput: (props: React.PropsWithChildren<LabeledCheckboxOrRadio | LabeledTextLike>) => import("react/jsx-runtime").JSX.Element;
|
|
4
4
|
export default LabeledInput;
|
|
5
5
|
//# sourceMappingURL=LabeledInput.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LabeledInput.d.ts","sourceRoot":"","sources":["../../../../src/components/molecules/LabeledInput/LabeledInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"LabeledInput.d.ts","sourceRoot":"","sources":["../../../../src/components/molecules/LabeledInput/LabeledInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B,OAAO,KAAK,EAAE,sBAAsB,EAAE,eAAe,EAAgB,MAAM,yBAAyB,CAAC;AAErG,QAAA,MAAM,YAAY,GAAI,OAAM,KAAK,CAAC,iBAAiB,CAAC,sBAAsB,GAAG,eAAe,CAAC,4CA8F5F,CAAA;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { DynamicFormProps } from "../../../type/propTypes";
|
|
3
|
-
declare const DynamicForm: ({ fieldsets, legendText, isExpandable, id, formInputs, labelAndInputContainerClass, labelClass, inputClass,
|
|
3
|
+
declare const DynamicForm: ({ fieldsets, legendText, isExpandable, id, formInputs, labelAndInputContainerClass, labelClass, inputClass, onChangeOfEditableOption, handleAddingInputEntry, hasSubmit, submitText, handleSubmit, hasReset, resetText, handleReset, hasCancel, cancelText, handleCancel, handleSubmitForm, className, children }: React.PropsWithChildren<DynamicFormProps>) => import("react/jsx-runtime").JSX.Element;
|
|
4
4
|
export default DynamicForm;
|
|
5
5
|
//# sourceMappingURL=DynamicForm.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DynamicForm.d.ts","sourceRoot":"","sources":["../../../../src/components/organisms/DynamicForm/DynamicForm.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAM1B,OAAO,KAAK,EAAgB,gBAAgB,EAA+D,MAAM,yBAAyB,CAAC;AAE3I,QAAA,MAAM,WAAW,GAAI,
|
|
1
|
+
{"version":3,"file":"DynamicForm.d.ts","sourceRoot":"","sources":["../../../../src/components/organisms/DynamicForm/DynamicForm.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAM1B,OAAO,KAAK,EAAgB,gBAAgB,EAA+D,MAAM,yBAAyB,CAAC;AAE3I,QAAA,MAAM,WAAW,GAAI,mTAuBnB,KAAK,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,4CAkJ1C,CAAA;AAGD,eAAe,WAAW,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { themeContextValue } from "../type/propTypes";
|
|
2
|
-
declare const ThemeContext: import("react").Context<themeContextValue
|
|
2
|
+
declare const ThemeContext: import("react").Context<themeContextValue>;
|
|
3
3
|
export default ThemeContext;
|
|
4
4
|
//# sourceMappingURL=ThemeContext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeContext.d.ts","sourceRoot":"","sources":["../../src/context/ThemeContext.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAI3D,QAAA,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"ThemeContext.d.ts","sourceRoot":"","sources":["../../src/context/ThemeContext.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAI3D,QAAA,MAAM,YAAY,4CAA4D,CAAC;AAE/E,eAAe,YAAY,CAAC"}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import type { Theme } from "../type/constantTypes";
|
|
1
2
|
import type { ChildrenProp } from "../type/propTypes";
|
|
2
|
-
export declare const ThemeContextProvider: ({ children }: ChildrenProp
|
|
3
|
+
export declare const ThemeContextProvider: ({ children, initialTheme, secondTheme }: ChildrenProp & {
|
|
4
|
+
initialTheme?: Theme;
|
|
5
|
+
secondTheme?: Theme;
|
|
6
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
3
7
|
//# sourceMappingURL=ThemeContextWrapper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeContextWrapper.d.ts","sourceRoot":"","sources":["../../src/context/ThemeContextWrapper.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ThemeContextWrapper.d.ts","sourceRoot":"","sources":["../../src/context/ThemeContextWrapper.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAUtD,eAAO,MAAM,oBAAoB,GAAI,yCAInC,YAAY,GAAG;IAAC,YAAY,CAAC,EAAC,KAAK,CAAC;IAAC,WAAW,CAAC,EAAC,KAAK,CAAA;CAAC,4CAYzD,CAAA"}
|
package/dist/hooks/useTheme.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTheme.d.ts","sourceRoot":"","sources":["../../src/hooks/useTheme.ts"],"names":[],"mappings":"AAGA,QAAA,MAAM,QAAQ,
|
|
1
|
+
{"version":3,"file":"useTheme.d.ts","sourceRoot":"","sources":["../../src/hooks/useTheme.ts"],"names":[],"mappings":"AAGA,QAAA,MAAM,QAAQ,sCAAyC,CAAC;AAExD,eAAe,QAAQ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import "./styles/styled";
|
|
1
2
|
export { default as DynamicForm } from "./components/organisms/DynamicForm";
|
|
2
3
|
export { ThemeContextProvider } from "./context/ThemeContextWrapper";
|
|
3
4
|
export { default as ThemeContext } from "./context/ThemeContext";
|
|
4
5
|
export { default as useTheme } from "./hooks/useTheme";
|
|
5
6
|
export * from "./styles/theme";
|
|
6
|
-
export type { FieldsetShape, inputEntryShape, DynamicFormProps,
|
|
7
|
+
export type { FieldsetShape, inputEntryShape, DynamicFormProps, LabeledCheckboxOrRadio, LabeledTextLike, FormActionButtonsProps, CheckedInput, GeneralInput, TextAreaInput, EditableInformation, NestedEditableOptionProps, ButtonProps, LabelProps, BaseInput, InputProps, ChildrenProp, themeContextValue } from './type/propTypes';
|
|
7
8
|
//# 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,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACvD,cAAc,gBAAgB,CAAC;AAC/B,YAAY,EACV,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,CAAC;AAEzB,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACvD,cAAc,gBAAgB,CAAC;AAC/B,YAAY,EACV,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,sBAAsB,EACtB,eAAe,EACf,sBAAsB,EACtB,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,mBAAmB,EACnB,yBAAyB,EACzB,WAAW,EACX,UAAU,EACV,SAAS,EACT,UAAU,EACV,YAAY,EACZ,iBAAiB,EAClB,MAAM,kBAAkB,CAAC"}
|