@pareto-engineering/design-system 4.2.1 → 4.2.3

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.
Files changed (55) hide show
  1. package/dist/cjs/f/FormInput/FormInput.js +6 -0
  2. package/dist/cjs/f/common/utils/index.js +8 -1
  3. package/dist/cjs/f/common/utils/validators.js +17 -0
  4. package/dist/cjs/f/fields/ChoicesInput/common/Choice/Choice.js +3 -2
  5. package/dist/cjs/f/fields/FileUpload/FileUpload.js +228 -0
  6. package/dist/cjs/f/fields/FileUpload/common/FilePreview/FilePreview.js +90 -0
  7. package/dist/cjs/f/fields/FileUpload/common/FilePreview/index.js +13 -0
  8. package/dist/cjs/f/fields/FileUpload/common/FilePreview/styles.scss +92 -0
  9. package/dist/cjs/f/fields/FileUpload/common/index.js +12 -0
  10. package/dist/cjs/f/fields/FileUpload/fileUploadOptions.js +31 -0
  11. package/dist/cjs/f/fields/FileUpload/index.js +20 -0
  12. package/dist/cjs/f/fields/FileUpload/styles.scss +73 -0
  13. package/dist/cjs/f/fields/index.js +14 -1
  14. package/dist/cjs/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.js +34 -7
  15. package/dist/cjs/g/FormBuilder/common/Builder/common/InputBuilder/styles.scss +11 -0
  16. package/dist/cjs/g/FormBuilder/common/Renderer/Renderer.js +9 -3
  17. package/dist/cjs/g/FormBuilder/common/Renderer/common/Section/Section.js +2 -2
  18. package/dist/es/f/FormInput/FormInput.js +7 -1
  19. package/dist/es/f/common/utils/index.js +2 -1
  20. package/dist/es/f/common/utils/validators.js +10 -0
  21. package/dist/es/f/fields/ChoicesInput/common/Choice/Choice.js +3 -2
  22. package/dist/es/f/fields/FileUpload/FileUpload.js +218 -0
  23. package/dist/es/f/fields/FileUpload/common/FilePreview/FilePreview.js +80 -0
  24. package/dist/es/f/fields/FileUpload/common/FilePreview/index.js +2 -0
  25. package/dist/es/f/fields/FileUpload/common/FilePreview/styles.scss +92 -0
  26. package/dist/es/f/fields/FileUpload/common/index.js +2 -0
  27. package/dist/es/f/fields/FileUpload/fileUploadOptions.js +25 -0
  28. package/dist/es/f/fields/FileUpload/index.js +3 -0
  29. package/dist/es/f/fields/FileUpload/styles.scss +73 -0
  30. package/dist/es/f/fields/index.js +2 -1
  31. package/dist/es/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.js +35 -8
  32. package/dist/es/g/FormBuilder/common/Builder/common/InputBuilder/styles.scss +11 -0
  33. package/dist/es/g/FormBuilder/common/Renderer/Renderer.js +9 -3
  34. package/dist/es/g/FormBuilder/common/Renderer/common/Section/Section.js +2 -1
  35. package/package.json +3 -3
  36. package/src/stories/f/FileUpload.stories.jsx +55 -0
  37. package/src/stories/g/FormBuilder.stories.jsx +19 -97
  38. package/src/ui/f/FormInput/FormInput.jsx +11 -0
  39. package/src/ui/f/common/utils/index.js +1 -0
  40. package/src/ui/f/common/utils/validators.js +10 -0
  41. package/src/ui/f/fields/ChoicesInput/common/Choice/Choice.jsx +2 -0
  42. package/src/ui/f/fields/FileUpload/FileUpload.jsx +277 -0
  43. package/src/ui/f/fields/FileUpload/common/FilePreview/FilePreview.jsx +115 -0
  44. package/src/ui/f/fields/FileUpload/common/FilePreview/index.js +2 -0
  45. package/src/ui/f/fields/FileUpload/common/FilePreview/styles.scss +92 -0
  46. package/src/ui/f/fields/FileUpload/common/index.js +2 -0
  47. package/src/ui/f/fields/FileUpload/fileUploadOptions.js +32 -0
  48. package/src/ui/f/fields/FileUpload/index.js +3 -0
  49. package/src/ui/f/fields/FileUpload/styles.scss +73 -0
  50. package/src/ui/f/fields/index.js +1 -0
  51. package/src/ui/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.jsx +53 -11
  52. package/src/ui/g/FormBuilder/common/Builder/common/InputBuilder/styles.scss +11 -0
  53. package/src/ui/g/FormBuilder/common/Renderer/Renderer.jsx +13 -3
  54. package/src/ui/g/FormBuilder/common/Renderer/common/Section/Section.jsx +7 -2
  55. package/tests/__snapshots__/Storyshots.test.js.snap +163 -159
@@ -9,7 +9,9 @@ import { FieldArray, useFormikContext } from 'formik'
9
9
 
10
10
  import styleNames from '@pareto-engineering/bem/exports'
11
11
 
12
- import { SelectInput, TextInput } from 'ui/f'
12
+ import {
13
+ ChoicesInput, SelectInput, TextInput, integerAndGreaterThanZero, fileUploadOptions,
14
+ } from 'ui/f'
13
15
 
14
16
  import { ToggleSwitch } from 'ui/a'
15
17
 
@@ -23,6 +25,12 @@ const baseClassName = styleNames.base
23
25
 
24
26
  const componentClassName = 'input-builder'
25
27
 
28
+ const getToggleSwitchStyles = (condition) => (
29
+ condition
30
+ ? { '--slider-background-color': 'var(--disabled)' }
31
+ : {}
32
+ )
33
+
26
34
  /**
27
35
  * This is the component description.
28
36
  */
@@ -43,15 +51,6 @@ const InputBuilder = ({
43
51
  setFieldValue(`sections.${sectionIndex}.inputs.${inputIndex}.required`, !input?.required)
44
52
  }
45
53
 
46
- const toggleSwitchStyles = {
47
- ...(!input?.required
48
- ? {
49
- '--slider-background-color':'var(--disabled)',
50
- }
51
- : {}
52
- ),
53
- }
54
-
55
54
  const [hasDescription, setHasDescription] = useState(false)
56
55
 
57
56
  // TODO: handle nav logic
@@ -72,6 +71,12 @@ const InputBuilder = ({
72
71
  setFieldValue(`sections.${sectionIndex}.inputs.${inputIndex}.options.${optionIndex}.label`, value)
73
72
  }
74
73
 
74
+ const isFile = input?.type === 'file'
75
+
76
+ const handleToggleShowSpecificFileTypes = () => {
77
+ setFieldValue(`sections.${sectionIndex}.inputs.${inputIndex}.showSpecificFileTypes`, !input.showSpecificFileTypes)
78
+ }
79
+
75
80
  return (
76
81
  <div
77
82
  id={id}
@@ -121,6 +126,10 @@ const InputBuilder = ({
121
126
  value:'choices',
122
127
  label:'Radio buttons',
123
128
  },
129
+ {
130
+ value:'file',
131
+ label:'File upload',
132
+ },
124
133
  ]}
125
134
  />
126
135
  <div className="controls">
@@ -138,7 +147,7 @@ const InputBuilder = ({
138
147
  <ToggleSwitch
139
148
  handleOnChange={handleToggleRequired}
140
149
  checked={input?.required}
141
- style={toggleSwitchStyles}
150
+ style={getToggleSwitchStyles(!input?.required)}
142
151
  inputId={`sections_${sectionIndex}_inputs.${inputIndex}_toggle`}
143
152
  />
144
153
  </div>
@@ -231,6 +240,39 @@ const InputBuilder = ({
231
240
  )}
232
241
  </FieldArray>
233
242
  )}
243
+
244
+ {isFile && (
245
+ <div className="input-file-options">
246
+ <TextInput
247
+ label="Maximum number of files"
248
+ name={`sections.${sectionIndex}.inputs.${inputIndex}.maxCount`}
249
+ placeholder="1"
250
+ type="number"
251
+ min="0"
252
+ validate={integerAndGreaterThanZero}
253
+ />
254
+ <div className="specific-file-types">
255
+ <ToggleSwitch
256
+ handleOnChange={handleToggleShowSpecificFileTypes}
257
+ checked={input?.showSpecificFileTypes}
258
+ style={getToggleSwitchStyles(!input?.showSpecificFileTypes)}
259
+ inputId={`sections_${sectionIndex}_inputs.${inputIndex}_show_specific_file_types`}
260
+ />
261
+ <span className="s0">
262
+ Allow only specific file types
263
+ </span>
264
+ </div>
265
+ {input?.showSpecificFileTypes && (
266
+ <>
267
+ <ChoicesInput
268
+ name={`sections.${sectionIndex}.inputs.${inputIndex}.accept`}
269
+ options={fileUploadOptions}
270
+ multiple
271
+ />
272
+ </>
273
+ )}
274
+ </div>
275
+ )}
234
276
  </div>
235
277
  </div>
236
278
  )
@@ -137,6 +137,17 @@ $default-list-width: var(--action-button-width, 18rem);
137
137
  }
138
138
  }
139
139
  }
140
+
141
+ > .input-file-options {
142
+ display: flex;
143
+ flex-direction: column;
144
+ gap: var(--gap);
145
+ margin-bottom: $default-margin;
146
+
147
+ > .specific-file-types {
148
+ display: flex;
149
+ }
150
+ }
140
151
  }
141
152
  }
142
153
 
@@ -23,9 +23,14 @@ const componentClassName = 'renderer'
23
23
 
24
24
  const reconstructFormDataWithValues = (formData, values) => {
25
25
  const newData = { ...formData }
26
- Object.keys(values).forEach((key) => {
26
+ Object.keys(values).forEach(async (key) => {
27
27
  const [sectionIdx, inputIdx] = key.match(/\d+/g).map(Number)
28
- newData.sections[sectionIdx].inputs[inputIdx].value = values[key]
28
+ if (key.includes('files')) {
29
+ const files = values[key].map((file) => URL.createObjectURL(file))
30
+ newData.sections[sectionIdx].inputs[inputIdx].files = files
31
+ } else {
32
+ newData.sections[sectionIdx].inputs[inputIdx].value = values[key]
33
+ }
29
34
  })
30
35
  return newData
31
36
  }
@@ -144,7 +149,12 @@ const Renderer = ({
144
149
  <Form>
145
150
  {updatedFormData.sections.map((section, sectionIndex) => (
146
151
  sectionIndex === currentSectionIndex && (
147
- <Section key={`${section.title}`} {...section} readOnly={readOnly} />
152
+ <Section
153
+ key={`${section.title}`}
154
+ {...section}
155
+ readOnly={readOnly}
156
+ setUpdatedFormData={setUpdatedFormData}
157
+ />
148
158
  )
149
159
  ))}
150
160
  <div className="navigator-container">
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-alert */
1
2
  /* @pareto-engineering/generator-front 1.1.1-alpha.2 */
2
3
  import * as React from 'react'
3
4
 
@@ -46,8 +47,12 @@ const Section = ({
46
47
  nodes={description}
47
48
  name="instructions"
48
49
  />
49
- {inputs.map((input) => (
50
- <FormInput key={input.name} {...input} disabled={readOnly} />
50
+ {inputs?.map((input) => (
51
+ <FormInput
52
+ key={input.name}
53
+ {...input}
54
+ disabled={readOnly}
55
+ />
51
56
  ))}
52
57
  </div>
53
58
  )
@@ -27478,6 +27478,119 @@ exports[`Storyshots f/fields/EditorInput Optional 1`] = `
27478
27478
  </form>
27479
27479
  `;
27480
27480
 
27481
+ exports[`Storyshots f/fields/FileUpload Base 1`] = `
27482
+ <form
27483
+ action="#"
27484
+ onReset={[Function]}
27485
+ onSubmit={[Function]}
27486
+ >
27487
+ <div
27488
+ className="base file-upload preview-bottom y-paragraph"
27489
+ >
27490
+ <p>
27491
+ The file upload
27492
+ </p>
27493
+ <label
27494
+ className="base form-label x-paragraph"
27495
+ htmlFor="section_0_input_0"
27496
+ >
27497
+ <input
27498
+ accept=".mp4,.ogg,.webm,video/mp4,video/ogg,video/webm,.pdf,application/pdf"
27499
+ className="file"
27500
+ disabled={false}
27501
+ id="section_0_input_0"
27502
+ onChange={[Function]}
27503
+ type="file"
27504
+ />
27505
+ <span
27506
+ className="ai-icon"
27507
+ >
27508
+ U
27509
+ </span>
27510
+ <span>
27511
+ Attach file
27512
+ </span>
27513
+ </label>
27514
+ </div>
27515
+ </form>
27516
+ `;
27517
+
27518
+ exports[`Storyshots f/fields/FileUpload Multiple 1`] = `
27519
+ <form
27520
+ action="#"
27521
+ onReset={[Function]}
27522
+ onSubmit={[Function]}
27523
+ >
27524
+ <div
27525
+ className="base file-upload preview-bottom y-paragraph"
27526
+ >
27527
+ <p>
27528
+ The file upload
27529
+ </p>
27530
+ <label
27531
+ className="base form-label x-paragraph"
27532
+ htmlFor="section_0_input_0"
27533
+ >
27534
+ <input
27535
+ accept=".mp4,.ogg,.webm,video/mp4,video/ogg,video/webm,.pdf,application/pdf"
27536
+ className="file"
27537
+ disabled={false}
27538
+ id="section_0_input_0"
27539
+ multiple={true}
27540
+ onChange={[Function]}
27541
+ type="file"
27542
+ />
27543
+ <span
27544
+ className="ai-icon"
27545
+ >
27546
+ U
27547
+ </span>
27548
+ <span>
27549
+ Attach file
27550
+ </span>
27551
+ </label>
27552
+ </div>
27553
+ </form>
27554
+ `;
27555
+
27556
+ exports[`Storyshots f/fields/FileUpload With Limited Count 1`] = `
27557
+ <form
27558
+ action="#"
27559
+ onReset={[Function]}
27560
+ onSubmit={[Function]}
27561
+ >
27562
+ <div
27563
+ className="base file-upload preview-bottom y-paragraph"
27564
+ >
27565
+ <p>
27566
+ The file upload
27567
+ </p>
27568
+ <label
27569
+ className="base form-label x-paragraph"
27570
+ htmlFor="section_0_input_0"
27571
+ >
27572
+ <input
27573
+ accept=".mp4,.ogg,.webm,video/mp4,video/ogg,video/webm,.pdf,application/pdf"
27574
+ className="file"
27575
+ disabled={false}
27576
+ id="section_0_input_0"
27577
+ multiple={true}
27578
+ onChange={[Function]}
27579
+ type="file"
27580
+ />
27581
+ <span
27582
+ className="ai-icon"
27583
+ >
27584
+ U
27585
+ </span>
27586
+ <span>
27587
+ Attach file
27588
+ </span>
27589
+ </label>
27590
+ </div>
27591
+ </form>
27592
+ `;
27593
+
27481
27594
  exports[`Storyshots f/fields/LinkInput Base 1`] = `
27482
27595
  <form
27483
27596
  action="#"
@@ -32643,7 +32756,7 @@ exports[`Storyshots g/FormBuilder Renderer 1`] = `
32643
32756
  <p
32644
32757
  className="h3"
32645
32758
  >
32646
- This is a survey of some of the best LLM models out there
32759
+ Hello
32647
32760
  </p>
32648
32761
  <div
32649
32762
  className="base expandable-lexical-preview y-paragraph"
@@ -32682,58 +32795,33 @@ exports[`Storyshots g/FormBuilder Renderer 1`] = `
32682
32795
  </button>
32683
32796
  </div>
32684
32797
  <div
32685
- className="base text-input form-input y-paragraph "
32686
- style={{}}
32798
+ className="base file-upload form-input preview-bottom y-paragraph"
32687
32799
  >
32800
+ <p>
32801
+ The file upload
32802
+ </p>
32688
32803
  <label
32689
32804
  className="base form-label x-paragraph"
32690
32805
  htmlFor="section_0_input_0"
32691
32806
  >
32692
- Name the Model
32693
- </label>
32694
- <input
32695
- className="input"
32696
- conditionalLogic={null}
32697
- disabled={false}
32698
- id="section_0_input_0"
32699
- name="section_0_input_0"
32700
- onBlur={[Function]}
32701
- onChange={[Function]}
32702
- options={[]}
32703
- required={true}
32704
- type="text"
32705
- value=""
32706
- />
32707
- </div>
32708
- <div
32709
- className="base text-area-input form-input y-paragraph"
32710
- >
32711
- <label
32712
- className="base form-label x-paragraph"
32713
- htmlFor="section_0_input_1"
32714
- >
32715
- Describe the Model in detail
32807
+ <input
32808
+ accept=".mp4,.ogg,.webm,video/mp4,video/ogg,video/webm,.pdf,application/pdf"
32809
+ className="file"
32810
+ disabled={false}
32811
+ id="section_0_input_0"
32812
+ multiple={true}
32813
+ onChange={[Function]}
32814
+ type="file"
32815
+ />
32816
+ <span
32817
+ className="ai-icon"
32818
+ >
32819
+ U
32820
+ </span>
32821
+ <span>
32822
+ Attach file
32823
+ </span>
32716
32824
  </label>
32717
- <textarea
32718
- className="textarea"
32719
- disabled={false}
32720
- id="section_0_input_1"
32721
- name="section_0_input_1"
32722
- onBlur={[Function]}
32723
- onChange={[Function]}
32724
- rows={10}
32725
- style={
32726
- {
32727
- "resize": "vertical",
32728
- }
32729
- }
32730
- value=""
32731
- />
32732
- <div
32733
- className="base description s-1 x-metadata"
32734
- >
32735
- brief model description
32736
- </div>
32737
32825
  </div>
32738
32826
  </div>
32739
32827
  <div
@@ -32747,12 +32835,6 @@ exports[`Storyshots g/FormBuilder Renderer 1`] = `
32747
32835
  >
32748
32836
  Previous
32749
32837
  </button>
32750
- <button
32751
- className="base button x-interactive modifierGradient"
32752
- type="submit"
32753
- >
32754
- Next
32755
- </button>
32756
32838
  </div>
32757
32839
  </form>
32758
32840
  </div>
@@ -32782,7 +32864,7 @@ exports[`Storyshots g/FormBuilder Renderer With Disabled 1`] = `
32782
32864
  <p
32783
32865
  className="h3"
32784
32866
  >
32785
- This is a survey of some of the best LLM models out there
32867
+ Hello
32786
32868
  </p>
32787
32869
  <div
32788
32870
  className="base expandable-lexical-preview y-paragraph"
@@ -32821,58 +32903,11 @@ exports[`Storyshots g/FormBuilder Renderer With Disabled 1`] = `
32821
32903
  </button>
32822
32904
  </div>
32823
32905
  <div
32824
- className="base text-input form-input y-paragraph "
32825
- style={{}}
32906
+ className="base file-upload form-input preview-bottom y-paragraph"
32826
32907
  >
32827
- <label
32828
- className="base form-label x-paragraph"
32829
- htmlFor="section_0_input_0"
32830
- >
32831
- Name the Model
32832
- </label>
32833
- <input
32834
- className="input"
32835
- conditionalLogic={null}
32836
- disabled={true}
32837
- id="section_0_input_0"
32838
- name="section_0_input_0"
32839
- onBlur={[Function]}
32840
- onChange={[Function]}
32841
- options={[]}
32842
- required={true}
32843
- type="text"
32844
- value=""
32845
- />
32846
- </div>
32847
- <div
32848
- className="base text-area-input form-input y-paragraph"
32849
- >
32850
- <label
32851
- className="base form-label x-paragraph"
32852
- htmlFor="section_0_input_1"
32853
- >
32854
- Describe the Model in detail
32855
- </label>
32856
- <textarea
32857
- className="textarea"
32858
- disabled={true}
32859
- id="section_0_input_1"
32860
- name="section_0_input_1"
32861
- onBlur={[Function]}
32862
- onChange={[Function]}
32863
- rows={10}
32864
- style={
32865
- {
32866
- "resize": "vertical",
32867
- }
32868
- }
32869
- value=""
32870
- />
32871
- <div
32872
- className="base description s-1 x-metadata"
32873
- >
32874
- brief model description
32875
- </div>
32908
+ <p>
32909
+ The file upload
32910
+ </p>
32876
32911
  </div>
32877
32912
  </div>
32878
32913
  <div
@@ -32886,12 +32921,6 @@ exports[`Storyshots g/FormBuilder Renderer With Disabled 1`] = `
32886
32921
  >
32887
32922
  Previous
32888
32923
  </button>
32889
- <button
32890
- className="base button x-interactive modifierGradient"
32891
- type="submit"
32892
- >
32893
- Next
32894
- </button>
32895
32924
  </div>
32896
32925
  </form>
32897
32926
  </div>
@@ -32921,7 +32950,7 @@ exports[`Storyshots g/FormBuilder Renderer With Submit 1`] = `
32921
32950
  <p
32922
32951
  className="h3"
32923
32952
  >
32924
- This is a survey of some of the best LLM models out there
32953
+ Hello
32925
32954
  </p>
32926
32955
  <div
32927
32956
  className="base expandable-lexical-preview y-paragraph"
@@ -32960,58 +32989,33 @@ exports[`Storyshots g/FormBuilder Renderer With Submit 1`] = `
32960
32989
  </button>
32961
32990
  </div>
32962
32991
  <div
32963
- className="base text-input form-input y-paragraph "
32964
- style={{}}
32992
+ className="base file-upload form-input preview-bottom y-paragraph"
32965
32993
  >
32994
+ <p>
32995
+ The file upload
32996
+ </p>
32966
32997
  <label
32967
32998
  className="base form-label x-paragraph"
32968
32999
  htmlFor="section_0_input_0"
32969
33000
  >
32970
- Name the Model
32971
- </label>
32972
- <input
32973
- className="input"
32974
- conditionalLogic={null}
32975
- disabled={false}
32976
- id="section_0_input_0"
32977
- name="section_0_input_0"
32978
- onBlur={[Function]}
32979
- onChange={[Function]}
32980
- options={[]}
32981
- required={true}
32982
- type="text"
32983
- value=""
32984
- />
32985
- </div>
32986
- <div
32987
- className="base text-area-input form-input y-paragraph"
32988
- >
32989
- <label
32990
- className="base form-label x-paragraph"
32991
- htmlFor="section_0_input_1"
32992
- >
32993
- Describe the Model in detail
33001
+ <input
33002
+ accept=".mp4,.ogg,.webm,video/mp4,video/ogg,video/webm,.pdf,application/pdf"
33003
+ className="file"
33004
+ disabled={false}
33005
+ id="section_0_input_0"
33006
+ multiple={true}
33007
+ onChange={[Function]}
33008
+ type="file"
33009
+ />
33010
+ <span
33011
+ className="ai-icon"
33012
+ >
33013
+ U
33014
+ </span>
33015
+ <span>
33016
+ Attach file
33017
+ </span>
32994
33018
  </label>
32995
- <textarea
32996
- className="textarea"
32997
- disabled={false}
32998
- id="section_0_input_1"
32999
- name="section_0_input_1"
33000
- onBlur={[Function]}
33001
- onChange={[Function]}
33002
- rows={10}
33003
- style={
33004
- {
33005
- "resize": "vertical",
33006
- }
33007
- }
33008
- value=""
33009
- />
33010
- <div
33011
- className="base description s-1 x-metadata"
33012
- >
33013
- brief model description
33014
- </div>
33015
33019
  </div>
33016
33020
  </div>
33017
33021
  <div
@@ -33029,7 +33033,7 @@ exports[`Storyshots g/FormBuilder Renderer With Submit 1`] = `
33029
33033
  className="base button x-interactive modifierGradient"
33030
33034
  type="submit"
33031
33035
  >
33032
- Next
33036
+ Submit
33033
33037
  </button>
33034
33038
  </div>
33035
33039
  </form>