@ea-lab/reactive-json-docs 1.2.0 → 1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ea-lab/reactive-json-docs",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Complete documentation for Reactive-JSON - Components, examples and LLM-parsable guides",
5
5
  "main": "public/rjbuild/docs/index.yaml",
6
6
  "files": [
@@ -26,7 +26,7 @@
26
26
  "private": false,
27
27
  "devDependencies": {
28
28
  "@craco/craco": "^7.1.0",
29
- "@ea-lab/reactive-json": "^1.1.0",
29
+ "@ea-lab/reactive-json": "^1.2.0",
30
30
  "@ea-lab/reactive-json-chartjs": "^1.0.0",
31
31
  "@npmcli/fs": "^4.0.0",
32
32
  "@reduxjs/toolkit": "^2.6.1",
@@ -0,0 +1,364 @@
1
+ # CheckBoxField
2
+
3
+ The `CheckBoxField` component provides checkbox and radio button groups with automatic data synchronization. It supports single selection (radio buttons or single checkbox), multiple selection (multiple checkboxes), and flexible data storage formats.
4
+
5
+ ## Basic Syntax
6
+
7
+ ```yaml
8
+ - type: CheckBoxField
9
+ dataLocation: ~.preferences
10
+ label: "Select your preferences:"
11
+ options:
12
+ - label: "Option 1"
13
+ value: "opt1"
14
+ - label: "Option 2"
15
+ value: "opt2"
16
+ - label: "Option 3"
17
+ value: "opt3"
18
+ ```
19
+
20
+ ## Properties
21
+
22
+ - `dataLocation` (string, optional): Path to bind the field value in the data context.
23
+ - `defaultFieldValue` (any, optional): Default value when no data is present.
24
+ - `label` (string or View props, optional): Field label text (supports template evaluation and View component rendering).
25
+ - `options` (array, optional): Static array of option objects, each with:
26
+ - `label` (string, optional): Display text for the option (supports template evaluation).
27
+ - `value` (any, required): Value stored when this option is selected.
28
+ - `attributes` (object, optional): Attributes applied to the option's container div.
29
+ - `dynamicOptions` (string, optional): Template path to dynamic options array (e.g., `~.availableItems`). Takes precedence over `options` if both are provided.
30
+ - `controlType` (string, optional): Type of control - `"checkbox"` (default) or `"radio"`.
31
+ - `multiple` (boolean, optional): Whether multiple selections are allowed. Defaults to `true` if more than one option exists, `false` otherwise. For radio buttons, this is automatically `false`.
32
+ - `attributes` (object, optional): Attributes applied to the wrapper div (or container div if no wrapper).
33
+ - `inputAttributes` (object, optional): Attributes applied directly to each input element.
34
+ - `labelAttributes` (object, optional): Attributes applied to the main label (htmlFor is automatically managed).
35
+ - `forceWrapper` (boolean, optional): Forces the presence (true) or absence (false) of the wrapper div. If omitted, wrapper is automatic only if label is present.
36
+ - `actions` (array, optional): Actions to execute based on field state.
37
+
38
+ ## Data Management
39
+
40
+ The component automatically synchronizes its value with the global data context. The data format depends on the selection mode:
41
+
42
+ - **Radio buttons**: Stores a single value (the selected option's value).
43
+ - **Single checkbox**: Stores a boolean (`true`) or the option's value when checked, `false` when unchecked.
44
+ - **Multiple checkboxes**: Stores an array of selected option values.
45
+
46
+ When `dataLocation` is used, the value is stored at the specified path. Without `dataLocation`, the value is stored in the template context using the component's `datafield`.
47
+
48
+ ## Selection Modes
49
+
50
+ ### Radio Buttons (Single Selection)
51
+
52
+ Radio buttons allow only one selection at a time. Set `controlType: "radio"`:
53
+
54
+ ```yaml
55
+ - type: CheckBoxField
56
+ dataLocation: ~.paymentMethod
57
+ label: "Payment Method:"
58
+ controlType: "radio"
59
+ options:
60
+ - label: "Credit Card"
61
+ value: "credit"
62
+ - label: "PayPal"
63
+ value: "paypal"
64
+ - label: "Bank Transfer"
65
+ value: "bank"
66
+ ```
67
+
68
+ **Data stored**: Single value (e.g., `"credit"`)
69
+
70
+ ### Single Checkbox
71
+
72
+ A single checkbox stores a boolean or the option's value:
73
+
74
+ ```yaml
75
+ - type: CheckBoxField
76
+ dataLocation: ~.agreeToTerms
77
+ label: "Terms and Conditions:"
78
+ multiple: false
79
+ options:
80
+ - label: "I agree to the terms and conditions"
81
+ value: true
82
+ ```
83
+
84
+ **Data stored**: `true` when checked, `false` when unchecked (or the option's value if different from `true`)
85
+
86
+ ### Multiple Checkboxes
87
+
88
+ Multiple checkboxes allow selecting several options simultaneously:
89
+
90
+ ```yaml
91
+ - type: CheckBoxField
92
+ dataLocation: ~.interests
93
+ label: "Select your interests:"
94
+ options:
95
+ - label: "Technology"
96
+ value: "tech"
97
+ - label: "Sports"
98
+ value: "sports"
99
+ - label: "Music"
100
+ value: "music"
101
+ ```
102
+
103
+ **Data stored**: Array of selected values (e.g., `["tech", "music"]`)
104
+
105
+ ## Wrapper Control
106
+
107
+ The component uses a flexible wrapper system similar to `Input`, adapting based on the presence of a label and the `forceWrapper` property.
108
+
109
+ ### Default Behavior
110
+
111
+ When no `forceWrapper` is specified, the component automatically determines whether to use a wrapper div. If a label is present, the component wraps both the label and checkbox elements in a div container. If no label is present, the checkboxes are rendered in a container div without an outer wrapper.
112
+
113
+ ### Explicit Control with `forceWrapper`
114
+
115
+ You can override the default behavior using the `forceWrapper` property. Setting `forceWrapper: true` will always create a wrapper div, even without a label. Setting `forceWrapper: false` will never create a wrapper, even when a label is present.
116
+
117
+ ### HTML Output Examples
118
+
119
+ **With label (automatic wrapper):**
120
+ ```html
121
+ <div>
122
+ <label>Select options:</label>
123
+ <div>
124
+ <div>
125
+ <input type="checkbox" id="checkbox-abc123-0" value="opt1" />
126
+ <label htmlFor="checkbox-abc123-0">Option 1</label>
127
+ </div>
128
+ <div>
129
+ <input type="checkbox" id="checkbox-abc123-1" value="opt2" />
130
+ <label htmlFor="checkbox-abc123-1">Option 2</label>
131
+ </div>
132
+ </div>
133
+ </div>
134
+ ```
135
+
136
+ **Without label (container div only):**
137
+ ```html
138
+ <div>
139
+ <div>
140
+ <input type="checkbox" id="checkbox-xyz789-0" value="opt1" />
141
+ <label htmlFor="checkbox-xyz789-0">Option 1</label>
142
+ </div>
143
+ </div>
144
+ ```
145
+
146
+ ## Label Support
147
+
148
+ The `label` property supports both simple strings and View component rendering, allowing for dynamic and complex label content:
149
+
150
+ ```yaml
151
+ - type: CheckBoxField
152
+ dataLocation: ~.options
153
+ label:
154
+ type: div
155
+ content:
156
+ - "Select options ("
157
+ - type: strong
158
+ content: ~.requiredCount
159
+ - " required):"
160
+ options:
161
+ - label: "Option 1"
162
+ value: "opt1"
163
+ ```
164
+
165
+ ## Option Attributes
166
+
167
+ Each option can have its own attributes applied to its container div:
168
+
169
+ ```yaml
170
+ - type: CheckBoxField
171
+ dataLocation: ~.features
172
+ options:
173
+ - label: "Premium Feature"
174
+ value: "premium"
175
+ attributes:
176
+ class: "premium-option"
177
+ style:
178
+ backgroundColor: "#ffd700"
179
+ - label: "Standard Feature"
180
+ value: "standard"
181
+ attributes:
182
+ class: "standard-option"
183
+ ```
184
+
185
+ ## ID Management
186
+
187
+ The component automatically generates unique IDs for each checkbox/radio button. If you provide an `id` in `inputAttributes`, it will be used as the base ID, and each option will have an index appended (e.g., `"my-id-0"`, `"my-id-1"`).
188
+
189
+ ## Empty Options Handling
190
+
191
+ If `options` is empty or not an array, the component returns `null` and renders nothing. This is useful for conditional rendering scenarios.
192
+
193
+ ## Examples
194
+
195
+ ### Basic Checkbox Group
196
+
197
+ ```yaml
198
+ renderView:
199
+ - type: CheckBoxField
200
+ dataLocation: ~.preferences
201
+ label: "Select your preferences:"
202
+ options:
203
+ - label: "Email notifications"
204
+ value: "email"
205
+ - label: "SMS notifications"
206
+ value: "sms"
207
+ - label: "Push notifications"
208
+ value: "push"
209
+
210
+ data:
211
+ preferences: []
212
+ ```
213
+
214
+ ### Radio Button Group
215
+
216
+ ```yaml
217
+ renderView:
218
+ - type: CheckBoxField
219
+ dataLocation: ~.size
220
+ label: "Select size:"
221
+ controlType: "radio"
222
+ options:
223
+ - label: "Small"
224
+ value: "small"
225
+ - label: "Medium"
226
+ value: "medium"
227
+ - label: "Large"
228
+ value: "large"
229
+
230
+ data:
231
+ size: ""
232
+ ```
233
+
234
+ ### Single Checkbox (Agreement)
235
+
236
+ ```yaml
237
+ renderView:
238
+ - type: CheckBoxField
239
+ dataLocation: ~.agreeToTerms
240
+ label: "Terms:"
241
+ multiple: false
242
+ options:
243
+ - label: "I agree to the terms and conditions"
244
+ value: true
245
+
246
+ data:
247
+ agreeToTerms: false
248
+ ```
249
+
250
+ ### Custom Styling
251
+
252
+ ```yaml
253
+ renderView:
254
+ - type: CheckBoxField
255
+ dataLocation: ~.categories
256
+ label: "Select categories:"
257
+ attributes:
258
+ class: "checkbox-group"
259
+ style:
260
+ border: "1px solid #ccc"
261
+ padding: "10px"
262
+ borderRadius: "5px"
263
+ inputAttributes:
264
+ style:
265
+ marginRight: "5px"
266
+ labelAttributes:
267
+ style:
268
+ fontWeight: "bold"
269
+ marginBottom: "10px"
270
+ options:
271
+ - label: "Category 1"
272
+ value: "cat1"
273
+ - label: "Category 2"
274
+ value: "cat2"
275
+
276
+ data:
277
+ categories: []
278
+ ```
279
+
280
+ ### Dynamic Options
281
+
282
+ ```yaml
283
+ renderView:
284
+ - type: CheckBoxField
285
+ dataLocation: ~.selectedItems
286
+ label: "Select items:"
287
+ dynamicOptions: ~.availableItems
288
+
289
+ data:
290
+ availableItems:
291
+ - label: "Item 1"
292
+ value: "item1"
293
+ - label: "Item 2"
294
+ value: "item2"
295
+ - label: "Item 3"
296
+ value: "item3"
297
+ selectedItems: []
298
+ ```
299
+
300
+ ### With Actions
301
+
302
+ ```yaml
303
+ renderView:
304
+ - type: CheckBoxField
305
+ dataLocation: ~.notifications
306
+ label: "Notification preferences:"
307
+ options:
308
+ - label: "Email"
309
+ value: "email"
310
+ - label: "SMS"
311
+ value: "sms"
312
+ actions:
313
+ - what: setData
314
+ when: ~.notifications
315
+ isArray: true
316
+ path: ~.hasNotifications
317
+ value: true
318
+
319
+ data:
320
+ notifications: []
321
+ hasNotifications: false
322
+ ```
323
+
324
+ ### Conditional Rendering
325
+
326
+ ```yaml
327
+ renderView:
328
+ - type: CheckBoxField
329
+ dataLocation: ~.features
330
+ label: "Select features:"
331
+ dynamicOptions: ~.availableFeatures
332
+ actions:
333
+ - what: hide
334
+ when: ~.availableFeatures
335
+ isEmpty: true
336
+
337
+ data:
338
+ availableFeatures:
339
+ - label: "Feature A"
340
+ value: "a"
341
+ - label: "Feature B"
342
+ value: "b"
343
+ features: []
344
+ ```
345
+
346
+ ## Advantages
347
+
348
+ - **Flexible selection modes**: Supports radio buttons, single checkbox, and multiple checkboxes
349
+ - **Automatic data synchronization**: Values are automatically stored in the correct format
350
+ - **Dynamic options**: Options can be provided via template evaluation using `dynamicOptions`
351
+ - **Per-option customization**: Each option can have its own attributes
352
+ - **Label flexibility**: Supports both simple strings and View component rendering
353
+ - **Wrapper control**: Flexible wrapper system for styling control
354
+ - **Accessibility**: Automatic label association with htmlFor attributes
355
+ - **Empty state handling**: Gracefully handles empty options
356
+
357
+ ## Limitations
358
+
359
+ - No built-in validation beyond HTML5 checkbox/radio validation
360
+ - No support for option grouping (use multiple CheckBoxField components)
361
+ - Styling must be provided via external CSS or style attributes
362
+ - Options must be provided as an array; empty arrays result in no rendering
363
+ - For radio buttons, `multiple` is automatically set to `false` regardless of the `multiple` property
364
+
@@ -0,0 +1,222 @@
1
+ renderView:
2
+ - type: Markdown
3
+ content: |
4
+ # CheckBoxField
5
+
6
+ The `CheckBoxField` component provides checkbox and radio button groups with automatic data synchronization. It supports single selection (radio buttons or single checkbox), multiple selection (multiple checkboxes), and flexible data storage formats.
7
+
8
+ - type: Markdown
9
+ content: |
10
+ ## Basic Syntax
11
+
12
+ ```yaml
13
+ - type: CheckBoxField
14
+ dataLocation: ~.preferences
15
+ label: "Select your preferences:"
16
+ options:
17
+ - label: "Option 1"
18
+ value: "opt1"
19
+ - label: "Option 2"
20
+ value: "opt2"
21
+ - label: "Option 3"
22
+ value: "opt3"
23
+ ```
24
+
25
+ ## Properties
26
+
27
+ - type: DefinitionList
28
+ content:
29
+ - term:
30
+ code: dataLocation
31
+ after: "(string, optional)"
32
+ details: "Path to bind the field value in the data context."
33
+ - term:
34
+ code: defaultFieldValue
35
+ after: "(any, optional)"
36
+ details: "Default value when no data is present."
37
+ - term:
38
+ code: label
39
+ after: "(string or View props, optional)"
40
+ details: "Field label text (supports template evaluation and View component rendering)."
41
+ - term:
42
+ code: options
43
+ after: "(array, optional)"
44
+ details:
45
+ type: Markdown
46
+ content: |
47
+ Static array of option objects, each with:
48
+ - `label` (string, optional): Display text for the option (supports template evaluation)
49
+ - `value` (any, required): Value stored when this option is selected
50
+ - `attributes` (object, optional): Attributes applied to the option's container div
51
+ - term:
52
+ code: dynamicOptions
53
+ after: "(string, optional)"
54
+ details:
55
+ type: Markdown
56
+ content: "Template path to dynamic options array (e.g., `~.availableItems`). Takes precedence over `options` if both are provided."
57
+ - term:
58
+ code: controlType
59
+ after: "(string, optional)"
60
+ details: "Type of control - `\"checkbox\"` (default) or `\"radio\"`."
61
+ - term:
62
+ code: multiple
63
+ after: "(boolean, optional)"
64
+ details: "Whether multiple selections are allowed. Defaults to `true` if more than one option exists, `false` otherwise. For radio buttons, this is automatically `false`."
65
+ - term:
66
+ code: attributes
67
+ after: "(object, optional)"
68
+ details: "Attributes applied to the wrapper div (or container div if no wrapper)."
69
+ - term:
70
+ code: inputAttributes
71
+ after: "(object, optional)"
72
+ details: "Attributes applied directly to each input element."
73
+ - term:
74
+ code: labelAttributes
75
+ after: "(object, optional)"
76
+ details: "Attributes applied to the main label (htmlFor is automatically managed)."
77
+ - term:
78
+ code: forceWrapper
79
+ after: "(boolean, optional)"
80
+ details: "Forces the presence (true) or absence (false) of the wrapper div. If omitted, wrapper is automatic only if label is present."
81
+ - term:
82
+ code: actions
83
+ after: "(array, optional)"
84
+ details: "Actions to execute based on field state."
85
+
86
+ - type: Markdown
87
+ content: |
88
+ ## Data Management
89
+
90
+ The component automatically synchronizes its value with the global data context. The data format depends on the selection mode:
91
+
92
+ - **Radio buttons**: Stores a single value (the selected option's value)
93
+ - **Single checkbox**: Stores a boolean (`true`) or the option's value when checked, `false` when unchecked
94
+ - **Multiple checkboxes**: Stores an array of selected option values
95
+
96
+ When `dataLocation` is used, the value is stored at the specified path. Without `dataLocation`, the value is stored in the template context using the component's `datafield`.
97
+
98
+ ## Selection Modes
99
+
100
+ ### Radio Buttons (Single Selection)
101
+
102
+ Radio buttons allow only one selection at a time. Set `controlType: "radio"`:
103
+
104
+ **Data stored**: Single value (e.g., `"credit"`)
105
+
106
+ ### Single Checkbox
107
+
108
+ A single checkbox stores a boolean or the option's value:
109
+
110
+ **Data stored**: `true` when checked, `false` when unchecked (or the option's value if different from `true`)
111
+
112
+ ### Multiple Checkboxes
113
+
114
+ Multiple checkboxes allow selecting several options simultaneously:
115
+
116
+ **Data stored**: Array of selected values (e.g., `["tech", "music"]`)
117
+
118
+ - type: RjBuildDescriber
119
+ title: "Basic Checkbox Group"
120
+ description: "Simple multiple selection checkbox group"
121
+ toDescribe:
122
+ renderView:
123
+ - type: CheckBoxField
124
+ dataLocation: ~.preferences
125
+ label: "Select your preferences:"
126
+ options:
127
+ - label: "Email notifications"
128
+ value: "email"
129
+ - label: "SMS notifications"
130
+ value: "sms"
131
+ - label: "Push notifications"
132
+ value: "push"
133
+ - type: div
134
+ attributes:
135
+ style:
136
+ marginTop: "20px"
137
+ padding: "10px"
138
+ borderRadius: "5px"
139
+ content:
140
+ - type: strong
141
+ content: "Selected: "
142
+ - ~.preferences
143
+ data:
144
+ preferences: []
145
+
146
+ - type: RjBuildDescriber
147
+ title: "Radio Button Group"
148
+ description: "Single selection using radio buttons"
149
+ toDescribe:
150
+ renderView:
151
+ - type: CheckBoxField
152
+ dataLocation: ~.size
153
+ label: "Select size:"
154
+ controlType: "radio"
155
+ options:
156
+ - label: "Small"
157
+ value: "small"
158
+ - label: "Medium"
159
+ value: "medium"
160
+ - label: "Large"
161
+ value: "large"
162
+ - label: "Extra Large"
163
+ value: "xl"
164
+ - type: div
165
+ attributes:
166
+ style:
167
+ marginTop: "20px"
168
+ padding: "10px"
169
+ borderRadius: "5px"
170
+ content:
171
+ - type: strong
172
+ content: "Selected size: "
173
+ - ~.size
174
+ data:
175
+ size: ""
176
+
177
+ - type: RjBuildDescriber
178
+ title: "Dynamic Options"
179
+ description: "Options provided via template evaluation using dynamicOptions"
180
+ toDescribe:
181
+ renderView:
182
+ - type: CheckBoxField
183
+ dataLocation: ~.selectedItems
184
+ label: "Select items:"
185
+ dynamicOptions: ~.availableItems
186
+ data:
187
+ availableItems:
188
+ - label: "Item 1"
189
+ value: "item1"
190
+ - label: "Item 2"
191
+ value: "item2"
192
+ - label: "Item 3"
193
+ value: "item3"
194
+ - label: "Item 4"
195
+ value: "item4"
196
+ selectedItems: []
197
+
198
+
199
+ - type: Markdown
200
+ content: |
201
+ ## Advantages
202
+
203
+ - **Flexible selection modes**: Supports radio buttons, single checkbox, and multiple checkboxes
204
+ - **Automatic data synchronization**: Values are automatically stored in the correct format
205
+ - **Dynamic options**: Options can be provided via template evaluation using `dynamicOptions`
206
+ - **Per-option customization**: Each option can have its own attributes
207
+ - **Label flexibility**: Supports both simple strings and View component rendering
208
+ - **Wrapper control**: Flexible wrapper system for styling control
209
+ - **Accessibility**: Automatic label association with htmlFor attributes
210
+ - **Empty state handling**: Gracefully handles empty options
211
+
212
+ ## Limitations
213
+
214
+ - No built-in validation beyond HTML5 checkbox/radio validation
215
+ - No support for option grouping (use multiple CheckBoxField components)
216
+ - Styling must be provided via external CSS or style attributes
217
+ - Options must be provided as an array; empty arrays result in no rendering
218
+ - For radio buttons, `multiple` is automatically set to `false` regardless of the `multiple` property
219
+
220
+ templates: {}
221
+ data: {}
222
+