@maif/react-forms 1.1.3 → 1.2.1

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
@@ -88,9 +88,9 @@ export const Example = () => {
88
88
  ```
89
89
  - **isMulti**: if `select` format is choosen, `isMulti` property is to render a multiselect component
90
90
  - **defaultKeyValue**: if `object` format is choosen, this default key/value is set for all added entries
91
- - **visible**: a boolean option to hide/display form field. It can be an object with `ref` property to get a value by reference an a key `test` as a function to test it. if there is no `test` key, it's base just on boolean value of the reference.
92
- - **disabled**: A boolean option to enable/disable form field
93
- - **label**: The label of form field (you can pass `null` to not render a label)
91
+ - **visible**: a boolean or [functional boolean](#functional-properties) option to hide/display form field.
92
+ - **disabled**: A boolean or [functional boolean](#functional-properties) option to enable/disable form field
93
+ - **label**: A string or [functional string](#functional-properties) to labelize of form field (you can pass `null` to not render a label)
94
94
  - **placeholder**: the placeholder of form field
95
95
  - **defaultValue**: A default value to fill field by default
96
96
  - **help**: the text display hover a help button
@@ -114,11 +114,11 @@ export const Example = () => {
114
114
  - entry [string] is the updated entry of schema
115
115
  - value [any] is the actual value of your entry
116
116
  - previousValue [any] is the previous value of your entry
117
- - rawValues [any] is the actual value of antire form
117
+ - rawValues [any] is the actual value of entire form
118
118
  - getValue [function] is a function to get value of a form entry
119
119
  - setValue [function] is a function to set value of a form entry
120
120
  - onSave [function] is a function to update actual entry
121
- - informations [Information] is an object to get information about the actual entry (path, index and parent informations)
121
+ - informations [Information] is an object to get informations about the actual entry (path, index and parent informations)
122
122
 
123
123
  - **render**: a function to completely custom the rendering of form field
124
124
  ```javascript
@@ -189,6 +189,14 @@ export const Example = () => {
189
189
  ```
190
190
  - **constraints**: a JSON array of constraints. see [constraints section](#constraints)
191
191
 
192
+ ### Functional properties
193
+ Some schema properties can be basic value or function which return basic value. This function has an object as param with these following properties :
194
+ - **rawValues**: the actual value of antire form
195
+ - **value**: the actual value of the actual entry
196
+ - **error**: the error of the entry (undefined if there is no error)
197
+ - **informations**: an object to get informations about the actual entry (path, index and parent informations)
198
+ - **getValue**: a function to get value of a form entry
199
+
192
200
 
193
201
  ## Form properties
194
202
  - **schema** (required): the form schema
@@ -229,15 +237,19 @@ httpClient = {(url, method) => fetch(url, {
229
237
  - **actions**: an object to parameter footer buttons key. By default just `submit` button is displayed.
230
238
  ```javascript
231
239
  <Form
232
- actions={
233
- reset: {
234
- display: false (value by default)
235
- label: 'reset' (value by default)
236
- },
237
- submit: {
238
- display: true (value by default)
239
- label: "save" (value by default)
240
- }
240
+ options={
241
+ autosubmit: true,
242
+ showErrorsOnStart: true,
243
+ actions={
244
+ reset: {
245
+ display: false (value by default)
246
+ label: 'reset' (value by default)
247
+ },
248
+ submit: {
249
+ display: true (value by default)
250
+ label: "save" (value by default)
251
+ }
252
+ }
241
253
  }
242
254
  />
243
255
  ```
package/lib/index.css CHANGED
@@ -294,6 +294,10 @@
294
294
  margin-left: 5px;
295
295
  }
296
296
 
297
+ .mrf-content_switch {
298
+ appearance: none;
299
+ }
300
+
297
301
  .mrf-content_switch_button_on {
298
302
  width: 35px;
299
303
  height: 22px;
@@ -305,6 +309,16 @@
305
309
  justify-content: flex-end;
306
310
  }
307
311
 
312
+ .mrf-content_switch_button_on::before {
313
+ content: "";
314
+ cursor: pointer;
315
+ width: 21px;
316
+ height: 21px;
317
+ background-color: var(--form-bg-color, #fff);
318
+ border-radius: 20px;
319
+ box-shadow: 1px 0px 5px 0px rgba(0, 0, 0, 0.3);
320
+ }
321
+
308
322
  .mrf-content_switch_button_off {
309
323
  width: 35px;
310
324
  height: 22px;
@@ -316,6 +330,16 @@
316
330
  justify-content: flex-start;
317
331
  }
318
332
 
333
+ .mrf-content_switch_button_off::before {
334
+ content: "";
335
+ background-color: var(--form-bg-color, #fff);
336
+ border-radius: 20px;
337
+ cursor: pointer;
338
+ width: 21px;
339
+ height: 21px;
340
+ box-shadow: 1px 0px 5px 0px rgba(0, 0, 0, 0.3);
341
+ }
342
+
319
343
  .mrf-content_switch_button_null {
320
344
  width: 35px;
321
345
  height: 22px;
@@ -327,34 +351,12 @@
327
351
  justify-content: flex-start;
328
352
  }
329
353
 
330
- .mrf-switch_button_on {
331
- cursor: pointer;
332
- width: 20px;
333
- height: 20px;
334
- background-color: var(--form-bg-color, #fff);
335
- border-radius: 20px;
336
- border: 1px solid var(--success-hover-color, #1e7e34);
337
- box-shadow: 1px 0px 5px 0px rgba(0, 0, 0, 0.3);
338
- }
339
-
340
- .mrf-switch_button_off {
354
+ .mrf-content_switch_button_null::before {
355
+ content: "";
341
356
  background-color: var(--form-bg-color, #fff);
342
357
  border-radius: 20px;
343
358
  cursor: pointer;
344
- width: 20px;
345
- height: 20px;
346
- border: 1px solid var(--error-hover-color, #bd2130);
347
- box-shadow: 1px 0px 5px 0px rgba(0, 0, 0, 0.3);
348
- }
349
-
350
- .mrf-switch_button_null {
351
- background-color: var(--form-bg-color, #fff);
352
- border-radius: 20px;
353
- cursor: pointer;
354
- width: 22px;
355
- height: 22px;
356
- margin-top: -1px;
357
- margin-left: -1px;
358
- border: 1px solid var(--neutral-hover-color, #5c636a);
359
+ width: 21px;
360
+ height: 21px;
359
361
  box-shadow: 1px 0px 5px 0px rgba(0, 0, 0, 0.3);
360
362
  }
package/lib/index.d.ts CHANGED
@@ -31,8 +31,10 @@ declare const format: {
31
31
  readonly form: "form";
32
32
  readonly buttonsSelect: "buttons";
33
33
  readonly singleLineCode: "singleLineCode";
34
+ readonly datetime: "datetime-local";
35
+ readonly time: "time";
34
36
  };
35
- declare let formatValues: ("markdown" | "email" | "array" | "select" | "code" | "textarea" | "password" | "hidden" | "form" | "buttons" | "singleLineCode")[];
37
+ declare let formatValues: ("markdown" | "email" | "array" | "select" | "code" | "textarea" | "password" | "hidden" | "form" | "buttons" | "singleLineCode" | "datetime-local" | "time")[];
36
38
  declare type Format = typeof formatValues[number];
37
39
 
38
40
  declare type Constraint = (resolver: any, key: string, dependencies: any[]) => AnySchema;
@@ -118,8 +120,10 @@ interface PropType {
118
120
  onChange?: (v: boolean) => void;
119
121
  value?: boolean;
120
122
  readOnly?: boolean;
123
+ className?: string;
124
+ errorDisplayed?: boolean;
121
125
  }
122
- declare const BooleanInput: React.ForwardRefExoticComponent<PropType & React.RefAttributes<HTMLInputElement>>;
126
+ declare const BooleanInput: ({ onChange, value, readOnly, className, errorDisplayed }: PropType) => JSX.Element;
123
127
 
124
128
  declare const Collapse: (props: {
125
129
  initCollapsed?: boolean;
@@ -184,7 +188,7 @@ declare const ObjectInput: (props: {
184
188
 
185
189
  declare type LanguageMode = "javascript" | "css" | "json" | "html" | "markdown";
186
190
 
187
- declare function CodeInput({ onChange, value, mode, tabSize, readOnly, showLinesNumber, highlightLine, themeStyle, setRef }: {
191
+ declare function CodeInput({ onChange, value, mode, tabSize, readOnly, showLinesNumber, highlightLine, themeStyle, className, setRef }: {
188
192
  onChange?: (v: string) => void;
189
193
  value?: string;
190
194
  mode?: LanguageMode;
@@ -200,6 +204,7 @@ declare function CodeInput({ onChange, value, mode, tabSize, readOnly, showLines
200
204
  minWidth: string;
201
205
  maxWidth: string;
202
206
  };
207
+ className?: string;
203
208
  setRef?: (editor: any) => void;
204
209
  }): JSX.Element;
205
210
 
@@ -248,13 +253,14 @@ interface Option {
248
253
  interface Schema {
249
254
  [key: string]: SchemaEntry;
250
255
  }
251
- declare type SchemaRenderType = ({ rawValues, value, onChange, error, setValue, parent }: {
256
+ declare type SchemaRenderType = ({ rawValues, value, onChange, error, setValue, getValue, informations }: {
252
257
  rawValues?: any;
253
258
  value?: any;
254
259
  onChange?: (param: object) => void;
255
260
  error?: boolean;
256
- parent?: string;
257
- setValue?: (data: any) => void;
261
+ getValue: (entry: string) => any;
262
+ informations?: Informations;
263
+ setValue?: (key: string, data: any) => void;
258
264
  }) => JSX.Element;
259
265
  interface ConditionnalSchemaElement {
260
266
  default?: boolean;
@@ -280,21 +286,26 @@ interface SchemaEntry {
280
286
  onCreateOption?: (option: string) => any;
281
287
  isMulti?: boolean;
282
288
  defaultKeyValue?: object;
283
- visible?: boolean | {
284
- ref: string;
285
- test: (b: any, idx?: number) => boolean;
286
- };
289
+ visible?: boolean | ((prop: {
290
+ rawValues: {
291
+ [x: string]: any;
292
+ };
293
+ value: any;
294
+ informations?: Informations;
295
+ }) => boolean);
287
296
  disabled?: boolean | ((prop: {
288
297
  rawValues: {
289
298
  [x: string]: any;
290
299
  };
291
300
  value: any;
301
+ informations?: Informations;
292
302
  }) => boolean);
293
303
  label?: React.ReactNode | ((prop: {
294
304
  rawValues: {
295
305
  [x: string]: any;
296
306
  };
297
307
  value: any;
308
+ informations?: Informations;
298
309
  }) => React.ReactNode);
299
310
  placeholder?: string;
300
311
  defaultValue?: any;
@@ -352,7 +363,9 @@ declare const Form: React.ForwardRefExoticComponent<{
352
363
  flow: Array<string | FlowObject>;
353
364
  value?: object | undefined;
354
365
  inputWrapper?: ((props: object) => JSX.Element) | undefined;
355
- onSubmit: (obj: object) => void;
366
+ onSubmit: (obj: {
367
+ [x: string]: any;
368
+ }) => void;
356
369
  onError?: (() => void) | undefined;
357
370
  footer?: ((props: {
358
371
  reset: () => void;
@@ -364,4 +377,4 @@ declare const Form: React.ForwardRefExoticComponent<{
364
377
  nostyle: boolean;
365
378
  } & React.RefAttributes<unknown>>;
366
379
 
367
- export { BooleanInput, CodeInput, Collapse, ConditionnalSchema, Flow, Form, Format, MarkdownInput, ObjectInput, Schema, SchemaEntry, SelectInput, SelectOption, SingleLineCode, Type, constraints_d as constraints, format, type, validate };
380
+ export { BooleanInput, CodeInput, Collapse, ConditionnalSchema, Flow, Form, Format, Informations, MarkdownInput, ObjectInput, Schema, SchemaEntry, SchemaRenderType, SelectInput, SelectOption, SingleLineCode, Type, constraints_d as constraints, format, type, validate };