@weareconceptstudio/form 0.0.3 → 0.0.4

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 (77) hide show
  1. package/dist/FormConfig.d.ts +5 -0
  2. package/dist/FormConfig.js +19 -0
  3. package/dist/checkbox/BaseCheckbox.d.ts +3 -0
  4. package/dist/checkbox/BaseCheckbox.js +51 -0
  5. package/dist/checkbox/index.js +15 -4
  6. package/dist/color-picker/index.d.ts +4 -1
  7. package/dist/color-picker/index.js +4 -4
  8. package/dist/date-picker/index.d.ts +6 -1
  9. package/dist/date-picker/index.js +4 -4
  10. package/dist/error-message/index.js +2 -2
  11. package/dist/form/BaseForm.d.ts +22 -20
  12. package/dist/form/BaseForm.js +38 -55
  13. package/dist/form/Builder/index.d.ts +9 -0
  14. package/dist/form/Builder/index.js +46 -0
  15. package/dist/form/Builder/style.d.ts +2 -0
  16. package/dist/form/Builder/style.js +3 -0
  17. package/dist/form/Item/index.d.ts +12 -10
  18. package/dist/form/Item/index.js +25 -18
  19. package/dist/form/hooks/rules.d.ts +3 -0
  20. package/dist/form/hooks/rules.js +44 -0
  21. package/dist/form/hooks/useEvent.d.ts +1 -0
  22. package/dist/form/hooks/useEvent.js +12 -0
  23. package/dist/form/hooks/useFormInstance.js +3 -0
  24. package/dist/form/hooks/useInput.d.ts +12 -0
  25. package/dist/form/hooks/useInput.js +46 -0
  26. package/dist/form/index.d.ts +6 -17
  27. package/dist/form/index.js +3 -2
  28. package/dist/index.d.ts +3 -0
  29. package/dist/index.js +4 -0
  30. package/dist/input/BaseInput/index.d.ts +4 -2
  31. package/dist/input/BaseInput/index.js +13 -31
  32. package/dist/input/Input.d.ts +4 -1
  33. package/dist/input/Input.js +15 -16
  34. package/dist/input/Number/index.d.ts +4 -1
  35. package/dist/input/Number/index.js +27 -4
  36. package/dist/input/Password/icons.d.ts +1 -1
  37. package/dist/input/Password/icons.js +6 -6
  38. package/dist/input/Password/index.d.ts +4 -1
  39. package/dist/input/Password/index.js +5 -5
  40. package/dist/input/TextArea/index.d.ts +4 -1
  41. package/dist/input/TextArea/index.js +8 -9
  42. package/dist/input/index.d.ts +10 -1
  43. package/dist/input/index.js +6 -4
  44. package/dist/phone-number/index.d.ts +7 -0
  45. package/dist/phone-number/index.js +13 -0
  46. package/dist/radio/BaseRadio.js +18 -5
  47. package/dist/radio/Group.js +19 -2
  48. package/dist/radio/index.js +2 -2
  49. package/dist/select/icons.d.ts +3 -0
  50. package/dist/select/icons.js +6 -0
  51. package/dist/select/index.d.ts +4 -1
  52. package/dist/select/index.js +57 -20
  53. package/dist/styles/formStyle.d.ts +2 -0
  54. package/dist/styles/formStyle.js +585 -0
  55. package/dist/styles/theme.d.ts +2 -0
  56. package/dist/styles/theme.js +113 -0
  57. package/dist/styles/variables.d.ts +2 -0
  58. package/dist/styles/variables.js +246 -0
  59. package/dist/translations/en.d.ts +52 -0
  60. package/dist/translations/en.js +52 -0
  61. package/dist/translations/index.d.ts +54 -0
  62. package/dist/translations/index.js +2 -0
  63. package/dist/upload/UploadButton/index.d.ts +3 -0
  64. package/dist/upload/UploadButton/index.js +41 -0
  65. package/dist/upload/UploadButton/style.d.ts +2 -0
  66. package/dist/upload/UploadButton/style.js +24 -0
  67. package/dist/upload/UploadList/ListItem/index.d.ts +5 -0
  68. package/dist/upload/UploadList/ListItem/index.js +11 -0
  69. package/dist/upload/UploadList/index.d.ts +3 -0
  70. package/dist/upload/UploadList/index.js +11 -0
  71. package/dist/upload/UploadList/style.d.ts +2 -0
  72. package/dist/upload/UploadList/style.js +13 -0
  73. package/dist/upload/index.d.ts +4 -1
  74. package/dist/upload/index.js +15 -5
  75. package/dist/upload/utils.d.ts +9 -0
  76. package/dist/upload/utils.js +64 -0
  77. package/package.json +31 -34
@@ -0,0 +1,246 @@
1
+ import { createGlobalStyle, css } from 'styled-components';
2
+ const FormVariables = createGlobalStyle `${css `
3
+ :root {
4
+ //! Fonts
5
+ --form_Font: ${(props) => `var(--${props.fontFamily})` || `var(--core_Font)`};
6
+
7
+ //! Transition
8
+ --form_trTime: 0.2s;
9
+
10
+ //! Line Height
11
+ --form_lineHeight: 1.5;
12
+
13
+ //! Box Shadow
14
+ --form_boxShadowColor: ${(props) => props.theme.form.colors.boxShadowColor};
15
+
16
+ //! Empty Text Color
17
+ --form_emptyTextColor: ${(props) => props.theme.form.colors.emptyTextColor};
18
+
19
+ //! Message colors
20
+ --form_errorMessageColor: ${(props) => props.theme.form.colors.errorMessageColor};
21
+ --form_errorMessageBorderColor: ${(props) => props.theme.form.colors.errorMessageBorderColor};
22
+ --form_errorMessageBgColor: ${(props) => props.theme.form.colors.errorMessageBgColor};
23
+ --form_successMessageColor: ${(props) => props.theme.form.colors.successMessageColor};
24
+ --form_successMessageBorderColor: ${(props) => props.theme.form.colors.successMessageBorderColor};
25
+ --form_successMessageBgColor: ${(props) => props.theme.form.colors.successMessageBgColor};
26
+
27
+ /* //! Label */
28
+ --form_labelColor: ${(props) => props.theme.form.colors.labelColor};
29
+ --form_labelHoverColor: ${(props) => props.theme.form.colors.labelHoverColor};
30
+ --form_labelFocusColor: ${(props) => props.theme.form.colors.labelFocusColor};
31
+ --form_labelActiveColor: ${(props) => props.theme.form.colors.labelActiveColor};
32
+ --form_labelErrorColor: ${(props) => props.theme.form.colors.labelErrorColor};
33
+ --form_labelDisabledColor: ${(props) => props.theme.form.colors.labelDisabledColor};
34
+
35
+ /* //! Input */
36
+ --form_inputColor: ${(props) => props.theme.form.colors.inputColor};
37
+ --form_inputHoverColor: ${(props) => props.theme.form.colors.inputHoverColor};
38
+ --form_inputFocusColor: ${(props) => props.theme.form.colors.inputFocusColor};
39
+ --form_inputActiveColor: ${(props) => props.theme.form.colors.inputActiveColor};
40
+ --form_inputErrorColor: ${(props) => props.theme.form.colors.inputErrorColor};
41
+ --form_inputDisabledColor: ${(props) => props.theme.form.colors.inputDisabledColor};
42
+
43
+ --form_inputPlaceholderColor: ${(props) => props.theme.form.colors.inputPlaceholderColor};
44
+ --form_inputPlaceholderHoverColor: ${(props) => props.theme.form.colors.inputPlaceholderHoverColor};
45
+ --form_inputPlaceholderFocusColor: ${(props) => props.theme.form.colors.inputPlaceholderFocusColor};
46
+ --form_inputPlaceholderActiveColor: ${(props) => props.theme.form.colors.inputPlaceholderActiveColor};
47
+ --form_inputPlaceholderErrorColor: ${(props) => props.theme.form.colors.inputPlaceholderErrorColor};
48
+ --form_inputPlaceholderDisabledColor: ${(props) => props.theme.form.colors.inputPlaceholderDisabledColor};
49
+
50
+ --form_inputBorderColor: ${(props) => props.theme.form.colors.inputBorderColor};
51
+ --form_inputBorderHoverColor: ${(props) => props.theme.form.colors.inputBorderHoverColor};
52
+ --form_inputBorderFocusColor: ${(props) => props.theme.form.colors.inputBorderFocusColor};
53
+ --form_inputBorderActiveColor: ${(props) => props.theme.form.colors.inputBorderActiveColor};
54
+ --form_inputBorderErrorColor: ${(props) => props.theme.form.colors.inputBorderErrorColor};
55
+ --form_inputBorderDisabledColor: ${(props) => props.theme.form.colors.inputBorderDisabledColor};
56
+
57
+ --form_inputBgColor: ${(props) => props.theme.form.colors.inputBgColor};
58
+ --form_inputHoverBgColor: ${(props) => props.theme.form.colors.inputHoverBgColor};
59
+ --form_inputFocusBgColor: ${(props) => props.theme.form.colors.inputFocusBgColor};
60
+ --form_inputActiveBgColor: ${(props) => props.theme.form.colors.inputActiveBgColor};
61
+ --form_inputErrorBgColor: ${(props) => props.theme.form.colors.inputErrorBgColor};
62
+ --form_inputDisabledBgColor: ${(props) => props.theme.form.colors.inputDisabledBgColor};
63
+
64
+ /* //! Select */
65
+ --form_selectColor: ${(props) => props.theme.form.colors.selectColor};
66
+ --form_selectHoverColor: ${(props) => props.theme.form.colors.selectHoverColor};
67
+ --form_selectFocusColor: ${(props) => props.theme.form.colors.selectFocusColor};
68
+ --form_selectActiveColor: ${(props) => props.theme.form.colors.selectActiveColor};
69
+ --form_selectErrorColor: ${(props) => props.theme.form.colors.selectErrorColor};
70
+ --form_selectDisabledColor: ${(props) => props.theme.form.colors.selectDisabledColor};
71
+
72
+ --form_selectPlaceholderColor: ${(props) => props.theme.form.colors.selectPlaceholderColor};
73
+ --form_selectPlaceholderHoverColor: ${(props) => props.theme.form.colors.selectPlaceholderHoverColor};
74
+ --form_selectPlaceholderFocusColor: ${(props) => props.theme.form.colors.selectPlaceholderFocusColor};
75
+ --form_selectPlaceholderActiveColor: ${(props) => props.theme.form.colors.selectPlaceholderActiveColor};
76
+ --form_selectPlaceholderErrorColor: ${(props) => props.theme.form.colors.selectPlaceholderErrorColor};
77
+ --form_selectPlaceholderDisabledColor: ${(props) => props.theme.form.colors.selectPlaceholderDisabledColor};
78
+
79
+ --form_selectBorderColor: ${(props) => props.theme.form.colors.selectBorderColor};
80
+ --form_selectBorderHoverColor: ${(props) => props.theme.form.colors.selectBorderHoverColor};
81
+ --form_selectBorderFocusColor: ${(props) => props.theme.form.colors.selectBorderFocusColor};
82
+ --form_selectBorderActiveColor: ${(props) => props.theme.form.colors.selectBorderActiveColor};
83
+ --form_selectBorderErrorColor: ${(props) => props.theme.form.colors.selectBorderErrorColor};
84
+ --form_selectBorderDisabledColor: ${(props) => props.theme.form.colors.selectBorderDisabledColor};
85
+
86
+ --form_selectBgColor: ${(props) => props.theme.form.colors.selectBgColor};
87
+ --form_selectHoverBgColor: ${(props) => props.theme.form.colors.selectHoverBgColor};
88
+ --form_selectFocusBgColor: ${(props) => props.theme.form.colors.selectFocusBgColor};
89
+ --form_selectActiveBgColor: ${(props) => props.theme.form.colors.selectActiveBgColor};
90
+ --form_selectErrorBgColor: ${(props) => props.theme.form.colors.selectErrorBgColor};
91
+ --form_selectDisabledBgColor: ${(props) => props.theme.form.colors.selectDisabledBgColor};
92
+
93
+ --form_selectOptionColor: ${(props) => props.theme.form.colors.selectOptionColor};
94
+ --form_selectOptionHoverColor: ${(props) => props.theme.form.colors.selectOptionHoverColor};
95
+ --form_selectOptionFocusColor: ${(props) => props.theme.form.colors.selectOptionFocusColor};
96
+ --form_selectOptionActiveColor: ${(props) => props.theme.form.colors.selectOptionActiveColor};
97
+ --form_selectOptionErrorColor: ${(props) => props.theme.form.colors.selectOptionErrorColor};
98
+ --form_selectOptionDisabledColor: ${(props) => props.theme.form.colors.selectOptionDisabledColor};
99
+
100
+ --form_selectOptionBgColor: ${(props) => props.theme.form.colors.selectOptionBgColor};
101
+ --form_selectOptionHoverBgColor: ${(props) => props.theme.form.colors.selectOptionHoverBgColor};
102
+ --form_selectOptionFocusBgColor: ${(props) => props.theme.form.colors.selectOptionFocusBgColor};
103
+ --form_selectOptionActiveBgColor: ${(props) => props.theme.form.colors.selectOptionActiveBgColor};
104
+ --form_selectOptionErrorBgColor: ${(props) => props.theme.form.colors.selectOptionErrorBgColor};
105
+ --form_selectOptionDisabledBgColor: ${(props) => props.theme.form.colors.selectOptionDisabledBgColor};
106
+
107
+ /* //! Radio */
108
+ --form_radioBorderColor: ${(props) => props.theme.form.colors.radioBorderColor};
109
+ --form_radioBorderActiveColor: ${(props) => props.theme.form.colors.radioBorderActiveColor};
110
+ --form_radioBgColor: ${(props) => props.theme.form.colors.radioBgColor};
111
+ --form_radioActiveBgColor: ${(props) => props.theme.form.colors.radioActiveBgColor};
112
+
113
+ /* //! Upload */
114
+ --form_uploadBgColor: ${(props) => props.theme.form.colors.uploadBgColor};
115
+ --form_uploadBorderColor: ${(props) => props.theme.form.colors.uploadBorderColor};
116
+ }
117
+
118
+ /* //! 2560 */
119
+ @media only screen and (min-width: ${(props) => props.theme.form.mediaQuery.form_DesktopSizeXL}) {
120
+ :root {
121
+ --form_p1: 32px;
122
+ --form_p2: 24px;
123
+ --form_p3: 20px;
124
+ --form_p4: 18px;
125
+ --form_p5: 12px;
126
+
127
+ //! Global error sizes
128
+ --form_globalErrorPad: var(--sp4x);
129
+ --form_errorItemMTop: var(--sp1-5x);
130
+ --form_globalErrorWrapMarTB: var(--sp7x);
131
+ }
132
+ }
133
+
134
+ /* //! 2559 - 1920 */
135
+ @media only screen and (max-width: ${(props) => props.theme.form.mediaQuery.form_DesktopSizeXLMin}) and (min-width: ${(props) => props.theme.form.mediaQuery.form_DesktopSizeL}) {
136
+ :root {
137
+ --form_p1: 24px;
138
+ --form_p2: 20px;
139
+ --form_p3: 16px;
140
+ --form_p4: 16px;
141
+ --form_p5: 10px;
142
+
143
+ //! Global error sizes
144
+ --form_globalErrorPad: var(--sp3x);
145
+ --form_errorItemMTop: var(--sp1x);
146
+ --form_globalErrorWrapMarTB: var(--sp5x);
147
+ }
148
+ }
149
+
150
+ /* //! 1919 - 1510 */
151
+ @media only screen and (max-width: ${(props) => props.theme.form.mediaQuery.form_DesktopSizeLMin}) and (min-width: ${(props) => props.theme.form.mediaQuery.form_DesktopSizeM}) {
152
+ :root {
153
+ --form_p1: 20px;
154
+ --form_p2: 18px;
155
+ --form_p3: 16px;
156
+ --form_p4: 14px;
157
+ --form_p5: 10px;
158
+
159
+ //! Global error sizes
160
+ --form_globalErrorPad: var(--sp2-5x);
161
+ --form_errorItemMTop: var(--sp1-5x);
162
+ --form_globalErrorWrapMarTB: var(--sp4x);
163
+ }
164
+ }
165
+
166
+ /* //! 1509 - 1440 */
167
+ @media only screen and (max-width: ${(props) => props.theme.form.mediaQuery.form_DesktopSizeMMin}) and (min-width: ${(props) => props.theme.form.mediaQuery.form_DesktopSizeS}) {
168
+ :root {
169
+ --form_p1: 20px;
170
+ --form_p2: 18px;
171
+ --form_p3: 16px;
172
+ --form_p4: 14px;
173
+ --form_p5: 10px;
174
+
175
+ //! Global error sizes
176
+ --form_globalErrorPad: var(--sp2x);
177
+ --form_errorItemMTop: var(--sp0-5x);
178
+ --form_globalErrorWrapMarTB: var(--sp4x);
179
+ }
180
+ }
181
+
182
+ /* //! 1439 - 1280 */
183
+ @media only screen and (max-width: ${(props) => props.theme.form.mediaQuery.form_DesktopSizeSMin}) and (min-width: ${(props) => props.theme.form.mediaQuery.form_DesktopSizeXS}) {
184
+ :root {
185
+ --form_p1: 20px;
186
+ --form_p2: 16px;
187
+ --form_p3: 16px;
188
+ --form_p4: 12px;
189
+ --form_p5: 8px;
190
+
191
+ //! Global error sizes
192
+ --form_globalErrorPad: var(--sp2x);
193
+ --form_errorItemMTop: var(--sp1x);
194
+ --form_globalErrorWrapMarTB: var(--sp3x);
195
+ }
196
+ }
197
+
198
+ /* //! 1279 - 1024 */
199
+ @media only screen and (max-width: ${(props) => props.theme.form.mediaQuery.form_DesktopSizeXSMin}) and (min-width: ${(props) => props.theme.form.mediaQuery.form_TabletSize}) {
200
+ :root {
201
+ --form_p1: 18px;
202
+ --form_p2: 16px;
203
+ --form_p3: 16px;
204
+ --form_p4: 12px;
205
+ --form_p5: 8px;
206
+
207
+ //! Global error sizes
208
+ --form_globalErrorPad: var(--sp2x);
209
+ --form_errorItemMTop: var(--sp1x);
210
+ --form_globalErrorWrapMarTB: var(--sp3x);
211
+ }
212
+ }
213
+
214
+ /* //! 1023 - 768 */
215
+ @media only screen and (max-width: ${(props) => props.theme.form.mediaQuery.form_TabletSizeMin}) and (min-width: ${(props) => props.theme.form.mediaQuery.form_TabletSizeS}) {
216
+ :root {
217
+ --form_p1: 18px;
218
+ --form_p2: 16px;
219
+ --form_p3: 16px;
220
+ --form_p4: 12px;
221
+ --form_p5: 8px;
222
+
223
+ //! Global error sizes
224
+ --form_globalErrorPad: var(--sp2x);
225
+ --form_errorItemMTop: var(--sp1x);
226
+ --form_globalErrorWrapMarTB: var(--sp3x);
227
+ }
228
+ }
229
+
230
+ /* //! 767 */
231
+ @media only screen and (max-width: ${(props) => props.theme.form.mediaQuery.form_TabletSizeSMin}) {
232
+ :root {
233
+ --form_p1: 16px;
234
+ --form_p2: 16px;
235
+ --form_p3: 16px;
236
+ --form_p4: 12px;
237
+ --form_p5: 8px;
238
+
239
+ //! Global error sizes
240
+ --form_globalErrorPad: var(--sp2x);
241
+ --form_errorItemMTop: var(--sp1x);
242
+ --form_globalErrorWrapMarTB: var(--sp3x);
243
+ }
244
+ }
245
+ `}`;
246
+ export default FormVariables;
@@ -0,0 +1,52 @@
1
+ declare const _default: {
2
+ serverError: string;
3
+ globalError: string;
4
+ validateMessages: {
5
+ default: string;
6
+ required: string;
7
+ enum: string;
8
+ whitespace: string;
9
+ date: {
10
+ format: string;
11
+ parse: string;
12
+ invalid: string;
13
+ };
14
+ types: {
15
+ string: string;
16
+ method: string;
17
+ array: string;
18
+ object: string;
19
+ number: string;
20
+ date: string;
21
+ boolean: string;
22
+ integer: string;
23
+ float: string;
24
+ regexp: string;
25
+ email: string;
26
+ url: string;
27
+ hex: string;
28
+ };
29
+ string: {
30
+ len: string;
31
+ min: string;
32
+ max: string;
33
+ range: string;
34
+ };
35
+ number: {
36
+ len: string;
37
+ min: string;
38
+ max: string;
39
+ range: string;
40
+ };
41
+ array: {
42
+ len: string;
43
+ min: string;
44
+ max: string;
45
+ range: string;
46
+ };
47
+ pattern: {
48
+ mismatch: string;
49
+ };
50
+ };
51
+ };
52
+ export default _default;
@@ -0,0 +1,52 @@
1
+ const typeTemplate = '{errorKey} is not a valid {type}';
2
+ export default {
3
+ serverError: 'Ups! there is something wrong with the website administration.',
4
+ globalError: 'Please double-check the required fields and confirm again.',
5
+ validateMessages: {
6
+ default: 'Validation error on field {errorKey}',
7
+ required: 'Please enter your {errorKey}',
8
+ enum: '{errorKey} must be one of [{enum}]',
9
+ whitespace: '{errorKey} cannot be empty',
10
+ date: {
11
+ format: '{errorKey} is invalid for format date',
12
+ parse: '{errorKey} could not be parsed as date',
13
+ invalid: '{errorKey} is invalid date',
14
+ },
15
+ types: {
16
+ string: typeTemplate,
17
+ method: typeTemplate,
18
+ array: typeTemplate,
19
+ object: typeTemplate,
20
+ number: typeTemplate,
21
+ date: typeTemplate,
22
+ boolean: typeTemplate,
23
+ integer: typeTemplate,
24
+ float: typeTemplate,
25
+ regexp: typeTemplate,
26
+ email: typeTemplate,
27
+ url: typeTemplate,
28
+ hex: typeTemplate,
29
+ },
30
+ string: {
31
+ len: '{errorKey} must be exactly {len} characters',
32
+ min: '{errorKey} must be at least {min} characters',
33
+ max: '{errorKey} cannot be longer than ${max} characters',
34
+ range: '{errorKey} must be between {min} and {max} characters',
35
+ },
36
+ number: {
37
+ len: '{errorKey} must equal {len}',
38
+ min: '{errorKey} cannot be less than {min}',
39
+ max: '{errorKey} cannot be greater than {max}',
40
+ range: '{errorKey} must be between {min} and {max}',
41
+ },
42
+ array: {
43
+ len: '{errorKey} must be exactly {len} in length',
44
+ min: '{errorKey} cannot be less than {min} in length',
45
+ max: '{errorKey} cannot be greater than {max} in length',
46
+ range: '{errorKey} must be between {min} and {max} in length',
47
+ },
48
+ pattern: {
49
+ mismatch: '{errorKey} does not match pattern {pattern}',
50
+ },
51
+ },
52
+ };
@@ -0,0 +1,54 @@
1
+ declare const _default: {
2
+ en: {
3
+ serverError: string;
4
+ globalError: string;
5
+ validateMessages: {
6
+ default: string;
7
+ required: string;
8
+ enum: string;
9
+ whitespace: string;
10
+ date: {
11
+ format: string;
12
+ parse: string;
13
+ invalid: string;
14
+ };
15
+ types: {
16
+ string: string;
17
+ method: string;
18
+ array: string;
19
+ object: string;
20
+ number: string;
21
+ date: string;
22
+ boolean: string;
23
+ integer: string;
24
+ float: string;
25
+ regexp: string;
26
+ email: string;
27
+ url: string;
28
+ hex: string;
29
+ };
30
+ string: {
31
+ len: string;
32
+ min: string;
33
+ max: string;
34
+ range: string;
35
+ };
36
+ number: {
37
+ len: string;
38
+ min: string;
39
+ max: string;
40
+ range: string;
41
+ };
42
+ array: {
43
+ len: string;
44
+ min: string;
45
+ max: string;
46
+ range: string;
47
+ };
48
+ pattern: {
49
+ mismatch: string;
50
+ };
51
+ };
52
+ };
53
+ };
54
+ export default _default;
@@ -0,0 +1,2 @@
1
+ import en from './en';
2
+ export default { en };
@@ -0,0 +1,3 @@
1
+ export default UploadButton;
2
+ declare function UploadButton(props: any): React.JSX.Element;
3
+ import React from 'react';
@@ -0,0 +1,41 @@
1
+ import React, { useRef } from 'react';
2
+ import { rawFileToAsset } from '../utils';
3
+ import UploadButtonStyle from './style';
4
+ const UploadButton = (props) => {
5
+ const { accept, disabled, multiple, setFileList } = props;
6
+ const inputRef = useRef();
7
+ const handleFiles = async (files) => {
8
+ const newFiles = [];
9
+ for (let i = 0; i < files.length; i++) {
10
+ const file = files.item(i);
11
+ const newFile = await rawFileToAsset({ rawFile: file });
12
+ newFiles.push(newFile);
13
+ }
14
+ setFileList(newFiles);
15
+ };
16
+ const onChange = () => {
17
+ handleFiles(inputRef.current.files);
18
+ };
19
+ const clickHandler = () => {
20
+ inputRef.current.click();
21
+ };
22
+ const dragOverHandler = (e) => {
23
+ e.preventDefault();
24
+ };
25
+ const onDragEnter = (e) => {
26
+ e.preventDefault();
27
+ };
28
+ const dropHandler = (e) => {
29
+ e.preventDefault();
30
+ if (e?.dataTransfer?.files) {
31
+ handleFiles(e.dataTransfer.files);
32
+ }
33
+ };
34
+ return (React.createElement(UploadButtonStyle, { className: 'upload-wrapper', onDrop: dropHandler, onDragOver: dragOverHandler, onDragEnter: onDragEnter, onClick: clickHandler },
35
+ React.createElement("span", { className: 'upload' },
36
+ React.createElement("input", { style: { display: 'none' }, ref: inputRef, type: 'file', accept: accept, disabled: disabled, multiple: multiple, onClick: (e) => e.stopPropagation(), onChange: onChange }),
37
+ React.createElement("button", { type: 'button' },
38
+ React.createElement("span", null, "x"),
39
+ React.createElement("div", null, "Upload")))));
40
+ };
41
+ export default UploadButton;
@@ -0,0 +1,2 @@
1
+ export default UploadButtonStyle;
2
+ declare const UploadButtonStyle: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
@@ -0,0 +1,24 @@
1
+ import styled from 'styled-components';
2
+ const UploadButtonStyle = styled.div `
3
+ width: 100px;
4
+ height: 100px;
5
+ text-align: center;
6
+ background-color: var(--form_uploadBgColor);
7
+ border: 1px dashed var(--form_uploadBorderColor);
8
+ border-radius: 8px;
9
+ cursor: pointer;
10
+
11
+ .upload {
12
+ display: flex;
13
+ align-items: center;
14
+ justify-content: center;
15
+ height: 100%;
16
+ text-align: center;
17
+ }
18
+
19
+ button {
20
+ border: 0px;
21
+ background: none;
22
+ }
23
+ `;
24
+ export default UploadButtonStyle;
@@ -0,0 +1,5 @@
1
+ export default ListItem;
2
+ declare function ListItem({ item }: {
3
+ item: any;
4
+ }): React.JSX.Element;
5
+ import React from 'react';
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import { Image } from '@weareconceptstudio/core';
3
+ const ListItem = ({ item }) => {
4
+ let element;
5
+ const isImageFileType = (type) => type.indexOf('image/') === 0;
6
+ if (isImageFileType(item.mime_type)) {
7
+ element = React.createElement(Image, { src: item.url });
8
+ }
9
+ return React.createElement("span", { className: 'list-item-container' }, element);
10
+ };
11
+ export default ListItem;
@@ -0,0 +1,3 @@
1
+ export default UploadList;
2
+ declare function UploadList(props: any): React.JSX.Element;
3
+ import React from 'react';
@@ -0,0 +1,11 @@
1
+ import React, { useMemo } from 'react';
2
+ import ListItem from './ListItem';
3
+ import UploadListItemStyle from './style';
4
+ const UploadList = (props) => {
5
+ const { items } = props;
6
+ const renderItems = useMemo(() => {
7
+ return items.map((item, index) => (React.createElement(ListItem, { key: index, item: item })));
8
+ }, [items]);
9
+ return React.createElement(UploadListItemStyle, null, renderItems);
10
+ };
11
+ export default UploadList;
@@ -0,0 +1,2 @@
1
+ export default UploadListItemStyle;
2
+ declare const UploadListItemStyle: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
@@ -0,0 +1,13 @@
1
+ import styled from 'styled-components';
2
+ const UploadListItemStyle = styled.div `
3
+ .list-item-container {
4
+ display: inline-block;
5
+ width: 100px;
6
+ height: 100px;
7
+
8
+ .image-cont {
9
+ padding-top: 100%;
10
+ }
11
+ }
12
+ `;
13
+ export default UploadListItemStyle;
@@ -1,3 +1,6 @@
1
1
  export default Upload;
2
- declare const Upload: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
2
+ declare function Upload(props: any): React.JSX.Element;
3
+ declare namespace Upload {
4
+ let displayName: string;
5
+ }
3
6
  import React from 'react';
@@ -1,8 +1,18 @@
1
- import React, { forwardRef } from 'react';
2
- const Upload = forwardRef((props, forwardRef) => {
3
- return (React.createElement("div", null,
4
- React.createElement("input", { type: 'file', ...forwardRef })));
5
- });
1
+ import React, { useState } from 'react';
2
+ import UploadButton from './UploadButton';
3
+ import UploadList from './UploadList';
4
+ const Upload = (props) => {
5
+ const { accept, disabled, multiple } = props;
6
+ const [fileList, setFileList] = useState([]);
7
+ const uploadProps = {
8
+ accept,
9
+ disabled,
10
+ multiple,
11
+ };
12
+ return (React.createElement("span", null,
13
+ React.createElement(UploadButton, { ...uploadProps, setFileList: setFileList }),
14
+ React.createElement(UploadList, { items: fileList })));
15
+ };
6
16
  if (process.env.NODE_ENV !== 'production') {
7
17
  Upload.displayName = 'Upload';
8
18
  }
@@ -0,0 +1,9 @@
1
+ export function typeFromMime(mime: any): "document" | "image" | "video" | "audio" | "pdf";
2
+ export function rawFileToAsset({ rawFile, isReplace }: {
3
+ rawFile: any;
4
+ isReplace?: boolean;
5
+ }): Promise<{
6
+ replace: boolean;
7
+ upload: boolean;
8
+ filename: any;
9
+ }>;
@@ -0,0 +1,64 @@
1
+ export const typeFromMime = (mime) => {
2
+ if (mime.includes('image')) {
3
+ return 'image';
4
+ }
5
+ if (mime.includes('video')) {
6
+ return 'video';
7
+ }
8
+ if (mime.includes('audio')) {
9
+ return 'audio';
10
+ }
11
+ if (mime.includes('pdf')) {
12
+ return 'pdf';
13
+ }
14
+ return 'document';
15
+ };
16
+ export const rawFileToAsset = async ({ rawFile, isReplace = false }) => {
17
+ const fileName = rawFile.name.split('.').shift();
18
+ const aggregate_type = typeFromMime(rawFile.type);
19
+ let data = {};
20
+ let dimensions = '';
21
+ if (aggregate_type == 'image') {
22
+ dimensions = await imageDimensions(rawFile);
23
+ }
24
+ data = {
25
+ size: rawFile.size,
26
+ createdAt: new Date().toLocaleDateString('fr'),
27
+ aggregate_type: aggregate_type,
28
+ url: URL.createObjectURL(rawFile),
29
+ extension: rawFile.name.split('.').pop(),
30
+ mime_type: rawFile.type,
31
+ dimensions: dimensions,
32
+ alt: fileName,
33
+ caption: fileName,
34
+ rawFile,
35
+ replace: false,
36
+ upload: true,
37
+ };
38
+ if (isReplace) {
39
+ data.replace = true;
40
+ data.upload = false;
41
+ }
42
+ else {
43
+ data.filename = fileName;
44
+ data.replace = false;
45
+ data.upload = true;
46
+ }
47
+ return data;
48
+ };
49
+ const imageDimensions = (file) => new Promise((resolve, reject) => {
50
+ const img = new Image();
51
+ img.onload = () => {
52
+ const { naturalWidth: width, naturalHeight: height } = img;
53
+ resolve(`${width}x${height}`);
54
+ };
55
+ img.onerror = () => {
56
+ useNotification({
57
+ type: 'warning',
58
+ message: 'Error',
59
+ description: 'There was some problem with the image.',
60
+ });
61
+ reject('There was some problem with the image.');
62
+ };
63
+ img.src = URL.createObjectURL(file);
64
+ });