@react-fabric/form 1.0.0-beta.9 → 1.0.2

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 (215) hide show
  1. package/{src/input/ArrayInput.module.css → css/_arrayInput.css} +8 -8
  2. package/css/_colorPicker.css +95 -0
  3. package/{src/internal/Field.module.css → css/_field.css} +94 -33
  4. package/{src/input/File.module.css → css/_file.css} +21 -6
  5. package/css/styles.css +27 -0
  6. package/dist/cjs/builder/FileField.js +107 -78
  7. package/dist/cjs/builder/FormField.js +60 -39
  8. package/dist/cjs/builder/SchemaEditor.js +72 -0
  9. package/dist/cjs/builder/components/AddSchemaFields.js +64 -0
  10. package/dist/cjs/builder/components/SchemaArrayForm.js +146 -0
  11. package/dist/cjs/builder/components/SchemaField.js +423 -0
  12. package/dist/cjs/form/Controller.js +66 -19
  13. package/dist/cjs/form/Form.js +97 -39
  14. package/dist/cjs/form/useForm.js +32 -0
  15. package/dist/cjs/hooks/useFileUploader.js +74 -45
  16. package/dist/cjs/hooks/useFormBuilder.js +85 -31
  17. package/dist/cjs/i18n/{ar.json.js → ar/form.json.js} +5 -4
  18. package/dist/cjs/i18n/{en.json.js → en/form.json.js} +5 -5
  19. package/dist/cjs/i18n/index.js +4 -4
  20. package/dist/cjs/index.js +41 -2
  21. package/dist/cjs/input/ArrayInput.js +259 -135
  22. package/dist/cjs/input/AvatarInput.js +99 -63
  23. package/dist/cjs/input/Checkbox.js +24 -25
  24. package/dist/cjs/input/ColorInput.js +138 -81
  25. package/dist/cjs/input/ColorPicker.js +78 -95
  26. package/dist/cjs/input/DateInput.js +192 -0
  27. package/dist/cjs/input/Field.js +21 -20
  28. package/dist/cjs/input/File.js +85 -80
  29. package/dist/cjs/input/Hidden.js +27 -13
  30. package/dist/cjs/input/Input.js +49 -48
  31. package/dist/cjs/input/Number.js +46 -44
  32. package/dist/cjs/input/Password.js +51 -49
  33. package/dist/cjs/input/Radio.js +26 -16
  34. package/dist/cjs/input/RadioGroup.js +26 -11
  35. package/dist/cjs/input/{Range.js → RangeSlider.js} +61 -66
  36. package/dist/cjs/input/Search.js +58 -64
  37. package/dist/cjs/input/Slider.js +57 -66
  38. package/dist/cjs/input/Switch.js +29 -27
  39. package/dist/cjs/input/Textarea.js +65 -53
  40. package/dist/cjs/internal/ErrorIcon.js +9 -9
  41. package/dist/cjs/internal/FieldWrapper.js +23 -13
  42. package/dist/cjs/internal/InputWrapper.js +85 -87
  43. package/dist/cjs/ranger/index.js +7 -7
  44. package/dist/cjs/ranger/utils.js +9 -4
  45. package/dist/cjs/select/AutoComplete.js +93 -76
  46. package/dist/cjs/select/DualList.js +235 -154
  47. package/dist/cjs/select/List.js +122 -89
  48. package/dist/cjs/select/Options.js +58 -54
  49. package/dist/cjs/select/Select.js +119 -89
  50. package/dist/cjs/select/helpers.js +5 -5
  51. package/dist/cjs/select/useSelect.js +83 -58
  52. package/dist/cjs/types/schema.js +43 -0
  53. package/dist/cjs/utils/eventHandlers.js +16 -6
  54. package/dist/cjs/utils/getColor.js +6 -6
  55. package/dist/cjs/utils/getProps.js +49 -0
  56. package/dist/esm/builder/FileField.js +109 -80
  57. package/dist/esm/builder/FormField.js +60 -39
  58. package/dist/esm/builder/SchemaEditor.js +72 -0
  59. package/dist/esm/builder/components/AddSchemaFields.js +64 -0
  60. package/dist/esm/builder/components/SchemaArrayForm.js +146 -0
  61. package/dist/esm/builder/components/SchemaField.js +423 -0
  62. package/dist/esm/form/Controller.js +66 -19
  63. package/dist/esm/form/Form.js +97 -39
  64. package/dist/esm/form/useForm.js +32 -0
  65. package/dist/esm/hooks/useFileUploader.js +75 -46
  66. package/dist/esm/hooks/useFormBuilder.js +84 -30
  67. package/dist/esm/i18n/{ar.json.js → ar/form.json.js} +5 -4
  68. package/dist/esm/i18n/{en.json.js → en/form.json.js} +5 -5
  69. package/dist/esm/i18n/index.js +2 -2
  70. package/dist/esm/index.js +36 -1
  71. package/dist/esm/input/ArrayInput.js +260 -136
  72. package/dist/esm/input/AvatarInput.js +99 -63
  73. package/dist/esm/input/Checkbox.js +26 -27
  74. package/dist/esm/input/ColorInput.js +141 -84
  75. package/dist/esm/input/ColorPicker.js +80 -97
  76. package/dist/esm/input/DateInput.js +192 -0
  77. package/dist/esm/input/Field.js +21 -20
  78. package/dist/esm/input/File.js +89 -84
  79. package/dist/esm/input/Hidden.js +28 -14
  80. package/dist/esm/input/Input.js +51 -50
  81. package/dist/esm/input/Number.js +48 -46
  82. package/dist/esm/input/Password.js +54 -52
  83. package/dist/esm/input/Radio.js +27 -17
  84. package/dist/esm/input/RadioGroup.js +27 -12
  85. package/dist/esm/input/{Range.js → RangeSlider.js} +62 -67
  86. package/dist/esm/input/Search.js +61 -67
  87. package/dist/esm/input/Slider.js +58 -67
  88. package/dist/esm/input/Switch.js +31 -29
  89. package/dist/esm/input/Textarea.js +67 -55
  90. package/dist/esm/internal/ErrorIcon.js +11 -11
  91. package/dist/esm/internal/FieldWrapper.js +23 -13
  92. package/dist/esm/internal/InputWrapper.js +88 -90
  93. package/dist/esm/ranger/index.js +7 -7
  94. package/dist/esm/ranger/utils.js +9 -4
  95. package/dist/esm/select/AutoComplete.js +95 -78
  96. package/dist/esm/select/DualList.js +233 -152
  97. package/dist/esm/select/List.js +125 -92
  98. package/dist/esm/select/Options.js +58 -54
  99. package/dist/esm/select/Select.js +122 -92
  100. package/dist/esm/select/helpers.js +5 -5
  101. package/dist/esm/select/useSelect.js +84 -59
  102. package/{src/input/ColorPicker.module.css → dist/esm/types/schema.js} +18 -27
  103. package/dist/esm/utils/eventHandlers.js +16 -6
  104. package/dist/esm/utils/getColor.js +6 -6
  105. package/dist/esm/utils/getProps.js +49 -0
  106. package/dist/types/builder/FileField.d.ts +7 -4
  107. package/dist/types/builder/FormField.d.ts +4 -2
  108. package/dist/types/builder/SchemaEditor.d.ts +6 -0
  109. package/dist/types/builder/components/AddSchemaFields.d.ts +2 -0
  110. package/dist/types/builder/components/SchemaArrayForm.d.ts +2 -0
  111. package/dist/types/builder/components/SchemaField.d.ts +12 -0
  112. package/dist/types/form/Controller.d.ts +45 -3
  113. package/dist/types/form/Form.d.ts +38 -7
  114. package/dist/types/form/useForm.d.ts +6 -0
  115. package/dist/types/hooks/useFileUploader.d.ts +24 -3
  116. package/dist/types/hooks/useFormBuilder.d.ts +41 -3
  117. package/dist/types/index.d.ts +32 -2
  118. package/dist/types/input/ArrayInput.d.ts +68 -13
  119. package/dist/types/input/AvatarInput.d.ts +23 -6
  120. package/dist/types/input/Checkbox.d.ts +12 -10
  121. package/dist/types/input/ColorInput.d.ts +15 -5
  122. package/dist/types/input/ColorPicker.d.ts +10 -2
  123. package/dist/types/input/DateInput.d.ts +21 -0
  124. package/dist/types/input/Field.d.ts +9 -36
  125. package/dist/types/input/File.d.ts +16 -4
  126. package/dist/types/input/Hidden.d.ts +7 -6
  127. package/dist/types/input/Input.d.ts +11 -4
  128. package/dist/types/input/Number.d.ts +9 -4
  129. package/dist/types/input/Password.d.ts +9 -4
  130. package/dist/types/input/Radio.d.ts +9 -4
  131. package/dist/types/input/RadioGroup.d.ts +14 -6
  132. package/dist/types/input/{Range.d.ts → RangeSlider.d.ts} +11 -6
  133. package/dist/types/input/Search.d.ts +14 -4
  134. package/dist/types/input/Slider.d.ts +9 -6
  135. package/dist/types/input/Switch.d.ts +13 -8
  136. package/dist/types/input/Textarea.d.ts +15 -4
  137. package/dist/types/internal/ErrorIcon.d.ts +4 -1
  138. package/dist/types/internal/FieldWrapper.d.ts +10 -1
  139. package/dist/types/internal/InputWrapper.d.ts +19 -1
  140. package/dist/types/ranger/index.d.ts +7 -3
  141. package/dist/types/ranger/utils.d.ts +2 -2
  142. package/dist/types/select/AutoComplete.d.ts +7 -2
  143. package/dist/types/select/DualList.d.ts +11 -37
  144. package/dist/types/select/List.d.ts +7 -2
  145. package/dist/types/select/Options.d.ts +8 -7
  146. package/dist/types/select/Select.d.ts +7 -2
  147. package/dist/types/select/helpers.d.ts +2 -2
  148. package/dist/types/select/useSelect.d.ts +10 -28
  149. package/dist/types/types/index.d.ts +73 -39
  150. package/dist/types/types/schema.d.ts +78 -32
  151. package/dist/types/utils/eventHandlers.d.ts +4 -4
  152. package/dist/types/utils/getColor.d.ts +4 -4
  153. package/dist/types/utils/getProps.d.ts +26 -0
  154. package/dist/types/utils/index.d.ts +1 -0
  155. package/package.json +25 -25
  156. package/src/builder/FileField.tsx +73 -56
  157. package/src/builder/FormField.tsx +66 -58
  158. package/src/builder/SchemaEditor.tsx +78 -0
  159. package/src/builder/components/AddSchemaFields.tsx +64 -0
  160. package/src/builder/components/SchemaArrayForm.tsx +146 -0
  161. package/src/builder/components/SchemaField.tsx +405 -0
  162. package/src/form/Controller.tsx +61 -24
  163. package/src/form/Form.tsx +74 -50
  164. package/src/form/useForm.ts +53 -0
  165. package/src/hooks/useFileUploader.ts +115 -84
  166. package/src/hooks/useFormBuilder.tsx +80 -41
  167. package/src/i18n/{ar.json → ar/form.json} +5 -4
  168. package/src/i18n/{en.json → en/form.json} +5 -5
  169. package/src/i18n/index.ts +2 -2
  170. package/src/index.ts +34 -20
  171. package/src/input/ArrayInput.tsx +255 -173
  172. package/src/input/AvatarInput.tsx +82 -39
  173. package/src/input/Checkbox.tsx +30 -54
  174. package/src/input/ColorInput.tsx +146 -105
  175. package/src/input/ColorPicker.tsx +76 -102
  176. package/src/input/DateInput.tsx +225 -0
  177. package/src/input/Field.tsx +23 -65
  178. package/src/input/File.tsx +76 -98
  179. package/src/input/Hidden.tsx +36 -24
  180. package/src/input/Input.tsx +55 -53
  181. package/src/input/Number.tsx +49 -54
  182. package/src/input/Password.tsx +61 -66
  183. package/src/input/Radio.tsx +28 -37
  184. package/src/input/RadioGroup.tsx +30 -25
  185. package/src/input/{Range.tsx → RangeSlider.tsx} +81 -109
  186. package/src/input/Search.tsx +64 -77
  187. package/src/input/Slider.tsx +80 -109
  188. package/src/input/Switch.tsx +39 -53
  189. package/src/input/Textarea.tsx +72 -59
  190. package/src/internal/ErrorIcon.tsx +22 -21
  191. package/src/internal/FieldWrapper.tsx +33 -23
  192. package/src/internal/InputWrapper.tsx +132 -143
  193. package/src/ranger/index.tsx +37 -117
  194. package/src/ranger/utils.ts +12 -11
  195. package/src/select/AutoComplete.tsx +113 -123
  196. package/src/select/DualList.tsx +218 -204
  197. package/src/select/List.tsx +130 -97
  198. package/src/select/Options.tsx +59 -57
  199. package/src/select/Select.tsx +148 -122
  200. package/src/select/helpers.ts +13 -8
  201. package/src/select/useSelect.tsx +110 -127
  202. package/src/types/index.ts +76 -45
  203. package/src/types/schema.ts +97 -40
  204. package/src/utils/eventHandlers.ts +24 -26
  205. package/src/utils/getColor.ts +9 -8
  206. package/src/utils/getProps.ts +47 -0
  207. package/src/utils/index.ts +1 -0
  208. package/dist/cjs/input/ArrayInput.module.css +0 -1
  209. package/dist/cjs/input/ColorPicker.module.css +0 -1
  210. package/dist/cjs/input/File.module.css +0 -1
  211. package/dist/cjs/internal/Field.module.css +0 -1
  212. package/dist/esm/input/ArrayInput.module.css +0 -1
  213. package/dist/esm/input/ColorPicker.module.css +0 -1
  214. package/dist/esm/input/File.module.css +0 -1
  215. package/dist/esm/internal/Field.module.css +0 -1
@@ -21,20 +21,20 @@
21
21
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  */
23
23
 
24
- @layer var {
25
- .arrayInput {
24
+ @layer variants {
25
+ .fabric-arrayInput {
26
26
  & [data-ref="fieldWrapper"] {
27
27
  flex: 1 1 0%;
28
28
  }
29
29
 
30
- & .addButton :global(.buttonInner) {
31
- color: theme(colors.tint.600);
32
- outline: 1px dashed theme(colors.tint.600);
30
+ & .fabric-addButton .fabric-button {
31
+ color: var(--color-tint-600);
32
+ outline: 1px dashed var(--color-tint-600);
33
33
 
34
34
  &[data-invalid="true"] {
35
- color: theme(colors.danger.600);
36
- background-color: theme(colors.danger.100);
37
- outline: 1px dashed theme(colors.danger.600);
35
+ color: var(--color-danger-600);
36
+ background-color: var(--color-danger-100);
37
+ outline: 1px dashed var(--color-danger-600);
38
38
  }
39
39
  }
40
40
  }
@@ -0,0 +1,95 @@
1
+ /*
2
+ * React Fabric
3
+ * @version: 1.0.0
4
+ *
5
+ *
6
+ * The MIT License (MIT)
7
+ * Copyright (c) 2024 Adarsh Pastakia
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
11
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
13
+ * subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
16
+ * portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ @layer components {
25
+ .fabric-colorPicker-container ~ svg {
26
+ fill: var(--color-selected);
27
+ }
28
+
29
+ .fabric-colorPicker {
30
+ --color-shadow: var(--border-color-bright);
31
+
32
+ outline: 2px solid var(--color-selected, var(--border-color-soft)) !important;
33
+
34
+ &.block-picker {
35
+ background-color: var(--bg-color-content) !important;
36
+ box-shadow: 0 0 4px 0 var(--color-shadow) !important;
37
+
38
+ input {
39
+ display: none;
40
+ }
41
+
42
+ & > div:first-child {
43
+ display: none;
44
+ }
45
+
46
+ & > div:last-child > div:first-child {
47
+ display: flex;
48
+ flex-wrap: wrap;
49
+ gap: 5px;
50
+ }
51
+
52
+ & span > div {
53
+ margin: 0 !important;
54
+ box-shadow: 0 0 1px 1px var(--border-color-default) inset !important;
55
+ }
56
+ }
57
+
58
+ & input {
59
+ padding: 0 4px !important;
60
+ border: 1px solid var(--border-color-default);
61
+ border-radius: var(--rounded-sm);
62
+
63
+ line-height: 2;
64
+ color: var(--text-color-default);
65
+
66
+ background-color: var(--bg-color-content);
67
+ box-shadow: none;
68
+
69
+ &:focus {
70
+ border-color: var(--border-primary-500);
71
+ }
72
+ }
73
+
74
+ & label {
75
+ color: var(--text-color-default);
76
+ }
77
+
78
+ & .flexbox-fix {
79
+ justify-content: center;
80
+ border-color: var(--border-color-soft);
81
+
82
+ & > div > div {
83
+ text-align: center;
84
+ }
85
+
86
+ & span > div {
87
+ box-shadow: 0 0 1px 1px var(--border-color-default) inset !important;
88
+ }
89
+ }
90
+
91
+ & .saturation-black ~ div {
92
+ pointer-events: none;
93
+ }
94
+ }
95
+ }
@@ -21,32 +21,27 @@
21
21
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  */
23
23
 
24
- @layer comp {
25
- .fieldWrapper {
26
- /* later */
27
- }
28
- }
29
-
30
- @layer var {
31
- .inputWrapper {
24
+ @layer variants {
25
+ .fabric-inputWrapper {
32
26
  &::after {
33
27
  inset-inline: 50%;
34
28
  transition: all 300ms;
35
29
  transition-delay: 100ms;
36
30
  }
37
31
 
38
- & .decorate:has([data-ref="button"]) {
32
+ & .fabric-decorate:has([data-ref="button"]) {
39
33
  display: flex;
40
34
  align-self: stretch;
41
35
  }
42
36
 
43
37
  &:has(input[disabled], textarea[disabled]) {
44
38
  cursor: not-allowed;
45
- background-color: theme(colors.tint.50);
39
+ background-color: var(--color-tint-50);
46
40
 
47
41
  & input,
48
42
  & textarea {
49
43
  cursor: not-allowed;
44
+ opacity: 0.7;
50
45
  }
51
46
  }
52
47
 
@@ -54,24 +49,26 @@
54
49
  &:has([data-open="true"]) {
55
50
  z-index: 1;
56
51
  background-color: var(--fabric-input-focus);
57
- outline-color: var(--primary);
52
+ outline-color: var(--color-primary);
58
53
 
59
54
  &:not(:has([aria-readonly="true"]:not([hidden])))::after {
60
55
  inset-inline: 0;
61
56
  }
62
57
  }
63
58
 
64
- &:global(.fixed) {
59
+ &.fixed {
65
60
  box-shadow: 0 0 2rem 0.5rem var(--fabric-shadow);
66
61
  }
67
62
 
68
63
  & input,
69
64
  & textarea {
65
+ width: 4rem;
70
66
  max-width: 100%;
67
+ line-height: 1.5;
71
68
  }
72
69
 
73
70
  & > input[type="number"] + .inputClear {
74
- margin-inline: -3rem 2rem;
71
+ margin-inline: -3rem 0;
75
72
  }
76
73
 
77
74
  & input::-ms-clear,
@@ -90,49 +87,113 @@
90
87
  letter-spacing: 2px;
91
88
  }
92
89
 
90
+ & input[type="date"]::-webkit-calendar-picker-indicator,
91
+ & input[type="datetime-local"]::-webkit-calendar-picker-indicator {
92
+ display: none;
93
+ appearance: none;
94
+ }
95
+
96
+ & input[type="date"].empty::-webkit-datetime-edit,
97
+ & input[type="datetime-local"].empty::-webkit-datetime-edit {
98
+ color: var(--color-tint-400);
99
+ }
100
+
93
101
  & input:-webkit-autofill {
94
102
  box-shadow: 0 0 0 999em var(--fabric-input) inset;
95
103
 
96
- -webkit-text-fill-color: theme(colors.accent.700);
104
+ -webkit-text-fill-color: var(--color-accent-700);
97
105
  }
98
106
 
99
107
  & input:-webkit-autofill:focus {
100
108
  box-shadow: 0 0 0 999em var(--fabric-input-focus) inset;
101
109
 
102
- -webkit-text-fill-color: theme(colors.accent.700);
110
+ -webkit-text-fill-color: var(--color-accent-700);
103
111
  }
104
112
 
105
- &.invalidWrapper {
106
- outline-color: theme(colors.danger.500);
113
+ &.fabric-invalidWrapper {
114
+ outline-color: var(--color-danger-500);
107
115
 
108
116
  &::after {
109
- background-color: theme(colors.danger.500);
117
+ background-color: var(--color-danger-500);
110
118
  }
111
119
  }
112
120
  }
113
121
 
114
- .fieldGroup {
122
+ .fabric-fieldGroup {
115
123
  > * {
116
124
  line-height: 1;
117
125
  }
118
126
 
119
- > :not(:first-child) {
120
- &,
121
- & > div,
122
- & > [role="button"],
123
- & > [data-ref="button"] > [role="button"] {
124
- border-start-start-radius: 0;
125
- border-end-start-radius: 0;
127
+ > .fabric-fieldWrapper > .fabric-fieldLabel {
128
+ display: none;
129
+ }
130
+
131
+ > .fabric-fieldWrapper > .fabric-inputWrapper {
132
+ outline: none;
133
+ }
134
+
135
+ &[data-vertical="false"] {
136
+ > * {
137
+ &:not(:last-child) {
138
+ border-inline-end: 1px solid var(--border-color-soft);
139
+ }
140
+ }
141
+
142
+ > :not(:first-child) {
143
+ &,
144
+ & > div,
145
+ & > .fabric-inputWrapper,
146
+ & > [role="button"],
147
+ & > [data-ref="button"] > [role="button"] {
148
+ border-start-start-radius: 0;
149
+ border-end-start-radius: 0;
150
+ }
151
+ }
152
+
153
+ > :not(:last-child) {
154
+ &,
155
+ & > div,
156
+ & > .fabric-inputWrapper,
157
+ & > [role="button"],
158
+ & > [data-ref="button"] > [role="button"] {
159
+ border-start-end-radius: 0;
160
+ border-end-end-radius: 0;
161
+ }
126
162
  }
127
163
  }
128
164
 
129
- > :not(:last-child) {
130
- &,
131
- & > div,
132
- & > [role="button"],
133
- & > [data-ref="button"] > [role="button"] {
134
- border-start-end-radius: 0;
135
- border-end-end-radius: 0;
165
+ &[data-vertical="true"] {
166
+ > * {
167
+ &,
168
+ & > .fabric-inputWrapper {
169
+ border-radius: var(--rounding-cap);
170
+ }
171
+
172
+ &:not(:last-child) {
173
+ border-block-end: 1px solid var(--border-color-soft);
174
+ }
175
+ }
176
+
177
+ > :not(:first-child) {
178
+ &,
179
+ & > div,
180
+ & > .fabric-inputWrapper,
181
+ & > [role="button"],
182
+ & > [data-ref="button"] > [role="button"] {
183
+ border-start-start-radius: 0;
184
+ border-start-end-radius: 0;
185
+ }
186
+ }
187
+
188
+ > :not(:last-child) {
189
+ &,
190
+ & > div,
191
+ & > .fabric-inputWrapper,
192
+ & > [role="button"],
193
+ & > [data-ref="button"] > [role="button"] {
194
+ border-end-start-radius: 0;
195
+ border-end-end-radius: 0;
196
+ }
136
197
  }
137
198
  }
138
199
  }
@@ -21,22 +21,37 @@
21
21
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  */
23
23
 
24
- @layer comp {
25
- .fileInput {
24
+ @layer components {
25
+ .fabric-fileInput {
26
26
  &::-webkit-file-upload-button {
27
- @apply bg-primary-500 opacity-80 hover:opacity-90 text-white rounded border-none py-0 cursor-pointer;
27
+ cursor: pointer;
28
+
29
+ padding-block: 0;
30
+ padding-inline: 4px;
31
+ border: 0;
32
+ border-radius: var(--rounding);
33
+
34
+ color: var(--color-white);
35
+
36
+ opacity: 0.8;
37
+ background-color: var(--color-primary-500);
38
+
39
+ &:hover {
40
+ opacity: 0.9;
41
+ }
28
42
  }
29
43
 
30
44
  &[aria-invalid="true"]::-webkit-file-upload-button {
31
- @apply bg-danger-500;
45
+ background-color: var(--color-danger-500);
32
46
  }
33
47
 
34
48
  &:disabled::-webkit-file-upload-button {
35
- @apply bg-muted pointer-events-none;
49
+ pointer-events: none;
50
+ background-color: var(--bg-color-muted);
36
51
  }
37
52
 
38
53
  &[readOnly] {
39
- @apply pointer-events-none;
54
+ pointer-events: none;
40
55
  }
41
56
  }
42
57
  }
package/css/styles.css ADDED
@@ -0,0 +1,27 @@
1
+ /*
2
+ * React Fabric
3
+ * @version: 1.0.0
4
+ *
5
+ *
6
+ * The MIT License (MIT)
7
+ * Copyright (c) 2025 Adarsh Pastakia
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
11
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
13
+ * subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
16
+ * portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ @import "./_arrayInput.css";
25
+ @import "./_colorPicker.css";
26
+ @import "./_field.css";
27
+ @import "./_file.css";
@@ -7,33 +7,39 @@ var _regeneratorRuntime = require('@babel/runtime/regenerator');
7
7
  var core = require('@react-fabric/core');
8
8
  var utilities = require('@react-fabric/utilities');
9
9
  var react = require('react');
10
+ var reactI18next = require('react-i18next');
10
11
  var useFileUploader = require('../hooks/useFileUploader.js');
11
12
  var Field = require('../input/Field.js');
12
13
  var Hidden = require('../input/Hidden.js');
13
14
  var jsxRuntime = require('react/jsx-runtime');
14
15
 
15
- var _excluded = ["uploadHandler", "inline", "label", "accept", "multiple", "value"];
16
+ var _excluded = ["uploadHandler", "inline", "label", "accept", "value", "onChange", "multiple", "error", "invalid"];
16
17
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
17
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
18
- var FileField = function FileField(_ref) {
18
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
19
+ function FileField(_ref) {
20
+ var _error$values$label;
19
21
  var uploadHandler = _ref.uploadHandler,
20
22
  inline = _ref.inline,
21
23
  label = _ref.label,
22
24
  accept = _ref.accept,
23
- _ref$multiple = _ref.multiple,
24
- multiple = _ref$multiple === void 0 ? false : _ref$multiple,
25
25
  value = _ref.value,
26
+ onChange = _ref.onChange,
27
+ multiple = _ref.multiple,
28
+ error = _ref.error,
29
+ invalid = _ref.invalid,
26
30
  rest = _objectWithoutProperties(_ref, _excluded);
27
- var _useFileUploader = useFileUploader.useFileUploader( /*#__PURE__*/function () {
28
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(data, config) {
29
- return _regeneratorRuntime.wrap(function _callee$(_context) {
31
+ var _useTranslation = reactI18next.useTranslation(),
32
+ t = _useTranslation.t;
33
+ var _useFileUploader = useFileUploader.useFileUploader(/*#__PURE__*/function () {
34
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(data, config) {
35
+ return _regeneratorRuntime.wrap(function (_context) {
30
36
  while (1) switch (_context.prev = _context.next) {
31
37
  case 0:
32
- _context.next = 2;
38
+ _context.next = 1;
33
39
  return uploadHandler === null || uploadHandler === void 0 ? void 0 : uploadHandler(data, config);
34
- case 2:
40
+ case 1:
35
41
  return _context.abrupt("return", _context.sent);
36
- case 3:
42
+ case 2:
37
43
  case "end":
38
44
  return _context.stop();
39
45
  }
@@ -42,90 +48,113 @@ var FileField = function FileField(_ref) {
42
48
  return function (_x, _x2) {
43
49
  return _ref2.apply(this, arguments);
44
50
  };
45
- }(), value, multiple),
51
+ }(), value, {
52
+ multiple: multiple,
53
+ onChange: onChange
54
+ }),
46
55
  pending = _useFileUploader.pending,
47
56
  files = _useFileUploader.files,
48
- list = _useFileUploader.list,
49
57
  upload = _useFileUploader.upload,
50
58
  remove = _useFileUploader.remove;
51
59
  return /*#__PURE__*/jsxRuntime.jsxs(react.Fragment, {
52
- children: [/*#__PURE__*/jsxRuntime.jsxs(Field.Field, {
60
+ children: [/*#__PURE__*/jsxRuntime.jsx(Field.Field, {
53
61
  plain: true,
54
62
  inline: inline,
55
63
  label: label,
56
- className: "inline-block",
57
- children: [/*#__PURE__*/jsxRuntime.jsx(Hidden.HiddenInput, _objectSpread({
58
- hiddenValue: multiple ? list : list === null || list === void 0 ? void 0 : list[0]
59
- }, rest)), /*#__PURE__*/jsxRuntime.jsx("span", {
60
- children: /*#__PURE__*/jsxRuntime.jsx(core.Button, {
61
- badge: pending > 0 ? "".concat(pending) : undefined,
62
- "data-ref": "filebtn",
63
- children: /*#__PURE__*/jsxRuntime.jsxs(react.Fragment, {
64
- children: [/*#__PURE__*/jsxRuntime.jsx("span", {
65
- children: "Add file"
66
- }), /*#__PURE__*/jsxRuntime.jsx("input", {
67
- type: "file",
68
- accept: accept,
69
- multiple: multiple,
70
- className: "absolute inset-0 opacity-0 z-5",
71
- onChange: function onChange(e) {
72
- return [upload(e.target.files), e.target.value = ""];
73
- }
74
- })]
75
- })
64
+ children: /*#__PURE__*/jsxRuntime.jsx(Hidden.HiddenInput, _objectSpread({
65
+ hiddenValue: multiple ? files : files === null || files === void 0 ? void 0 : files[0]
66
+ }, rest))
67
+ }), /*#__PURE__*/jsxRuntime.jsx(core.Tooltip, {
68
+ color: "danger",
69
+ content: utilities.isObject(error) ? t(error.key, utilities.isObject(error.values) ? _objectSpread(_objectSpread({}, error.values), {}, {
70
+ label: t((_error$values$label = error.values.label) !== null && _error$values$label !== void 0 ? _error$values$label : "form:badkey", error.values.path)
71
+ }) : {}) : utilities.isString(error) ? error : "",
72
+ disabled: !error,
73
+ children: /*#__PURE__*/jsxRuntime.jsx(core.Button, {
74
+ altIcon: pending > 0 ? /*#__PURE__*/jsxRuntime.jsx(core.Badge, {
75
+ inline: true,
76
+ children: pending
77
+ }) : undefined,
78
+ color: invalid ? "danger" : undefined,
79
+ variant: invalid ? "soft" : undefined,
80
+ "data-ref": "filebtn",
81
+ children: /*#__PURE__*/jsxRuntime.jsxs(react.Fragment, {
82
+ children: [/*#__PURE__*/jsxRuntime.jsx("span", {
83
+ children: "Add file"
84
+ }), /*#__PURE__*/jsxRuntime.jsx("input", {
85
+ type: "file",
86
+ accept: accept,
87
+ multiple: multiple,
88
+ className: "absolute inset-0 opacity-0 z-5",
89
+ onChange: function onChange(e) {
90
+ return [upload(e.target.files), e.target.value = ""];
91
+ }
92
+ })]
76
93
  })
77
- })]
94
+ })
78
95
  }), /*#__PURE__*/jsxRuntime.jsx("br", {}), /*#__PURE__*/jsxRuntime.jsx("div", {
79
96
  className: "bg-alternate",
80
97
  children: files.map(function (file, idx) {
81
- return /*#__PURE__*/jsxRuntime.jsxs("div", {
82
- className: "px-2 py-1",
83
- children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
84
- className: "flex flex-nowrap gap-1 items-start",
98
+ return (
99
+ /*#__PURE__*/
100
+ // eslint-disable-next-line @eslint-react/no-array-index-key
101
+ jsxRuntime.jsxs("div", {
102
+ className: "px-2 py-1",
85
103
  children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
86
- className: "flex-1 truncate pe-2",
87
- children: [file.filename, /*#__PURE__*/jsxRuntime.jsx("br", {}), /*#__PURE__*/jsxRuntime.jsx("span", {
88
- className: "text-xs",
89
- children: utilities.FileUtil.mime(file.mime)
90
- }), /*#__PURE__*/jsxRuntime.jsx("span", {
91
- className: "text-xs px-1",
92
- children: utilities.Format.bytes(file.size)
104
+ className: "flex flex-nowrap gap-1 items-start",
105
+ children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
106
+ className: "flex-1 truncate pe-2",
107
+ children: [file.filename, /*#__PURE__*/jsxRuntime.jsx("br", {}), /*#__PURE__*/jsxRuntime.jsx("span", {
108
+ className: "text-xs",
109
+ children: utilities.FileUtil.mime(file.mime)
110
+ }), /*#__PURE__*/jsxRuntime.jsx("span", {
111
+ className: "text-xs px-1",
112
+ children: utilities.Format.bytes(file.size)
113
+ })]
114
+ }), /*#__PURE__*/jsxRuntime.jsx("div", {
115
+ className: "flex-initial truncate px-2",
116
+ children: file.error && /*#__PURE__*/jsxRuntime.jsx("span", {
117
+ className: "text-danger-600",
118
+ children: file.error
119
+ })
120
+ }), file.progress && /*#__PURE__*/jsxRuntime.jsx("button", {
121
+ type: "button",
122
+ className: "size-fit leading-0 cursor-pointer",
123
+ onClick: function onClick() {
124
+ var _file$abort;
125
+ return (_file$abort = file.abort) === null || _file$abort === void 0 ? void 0 : _file$abort.call(file);
126
+ },
127
+ children: /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
128
+ icon: "icon-[mdi--stop]",
129
+ bg: "danger",
130
+ color: "white",
131
+ size: "sm",
132
+ className: "p-0.5",
133
+ "aria-label": "abort"
134
+ })
135
+ }), !file.progress && /*#__PURE__*/jsxRuntime.jsx("button", {
136
+ type: "button",
137
+ className: "size-fit leading-0 cursor-pointer",
138
+ onClick: function onClick() {
139
+ return remove(file.key);
140
+ },
141
+ children: /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
142
+ icon: "icon-[mdi--trash-can-outline]",
143
+ color: "danger",
144
+ size: "sm",
145
+ "aria-label": "remove"
146
+ })
93
147
  })]
94
- }), /*#__PURE__*/jsxRuntime.jsx("div", {
95
- className: "flex-initial truncate px-2",
96
- children: file.error && /*#__PURE__*/jsxRuntime.jsx("span", {
97
- className: "text-danger-600",
98
- children: file.error
99
- })
100
- }), file.progress && /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
101
- icon: "mdi mdi-stop-circle",
102
- bg: "danger",
103
- color: "white",
104
- size: "sm",
105
- className: "p-[2px]",
106
- "aria-label": "abort",
107
- onClick: function onClick() {
108
- var _file$abort;
109
- return (_file$abort = file.abort) === null || _file$abort === void 0 ? void 0 : _file$abort.call(file);
110
- }
111
- }), !file.progress && /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
112
- icon: "mdi mdi-trash-can",
113
- color: "danger",
114
- size: "sm",
115
- "aria-label": "remove",
116
- onClick: function onClick() {
117
- return remove(file.key);
118
- }
148
+ }), file.progress && /*#__PURE__*/jsxRuntime.jsx(core.ProgressBar, {
149
+ animate: true,
150
+ value: file.progress * 100,
151
+ size: "xxs"
119
152
  })]
120
- }), file.progress && /*#__PURE__*/jsxRuntime.jsx(core.ProgressBar, {
121
- animate: true,
122
- value: file.progress * 100,
123
- size: "xxs"
124
- })]
125
- }, idx);
153
+ }, idx)
154
+ );
126
155
  })
127
156
  })]
128
157
  });
129
- };
158
+ }
130
159
 
131
160
  exports.FileField = FileField;