@spark-web/field 4.0.0-rc.2 → 4.0.0-rc.21
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/CHANGELOG.md +323 -0
- package/dist/spark-web-field.cjs.d.ts +2 -2
- package/dist/spark-web-field.cjs.js +15 -6
- package/package.json +9 -9
- package/dist/declarations/src/context.d.ts +0 -15
- package/dist/declarations/src/field.d.ts +0 -51
- package/dist/declarations/src/index.d.ts +0 -4
- package/dist/spark-web-field.cjs.dev.js +0 -205
- package/dist/spark-web-field.cjs.prod.js +0 -205
- package/dist/spark-web-field.esm.js +0 -197
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,328 @@
|
|
|
1
1
|
# @spark-web/field
|
|
2
2
|
|
|
3
|
+
## 4.0.0-rc.21
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Introduce global theming provider to set global default theme
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies []:
|
|
12
|
+
- @spark-web/stack@2.0.0-rc.21
|
|
13
|
+
- @spark-web/theme@4.0.0-rc.21
|
|
14
|
+
- @spark-web/utils@2.0.0-rc.21
|
|
15
|
+
- @spark-web/a11y@2.0.0-rc.21
|
|
16
|
+
- @spark-web/icon@2.0.0-rc.21
|
|
17
|
+
- @spark-web/text@2.0.0-rc.21
|
|
18
|
+
- @spark-web/box@2.0.0-rc.21
|
|
19
|
+
|
|
20
|
+
## 4.0.0-rc.20
|
|
21
|
+
|
|
22
|
+
### Minor Changes
|
|
23
|
+
|
|
24
|
+
- Support for component-level theming; button-level theming
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- Updated dependencies []:
|
|
29
|
+
- @spark-web/stack@2.0.0-rc.20
|
|
30
|
+
- @spark-web/theme@4.0.0-rc.20
|
|
31
|
+
- @spark-web/utils@2.0.0-rc.20
|
|
32
|
+
- @spark-web/a11y@2.0.0-rc.20
|
|
33
|
+
- @spark-web/icon@2.0.0-rc.20
|
|
34
|
+
- @spark-web/text@2.0.0-rc.20
|
|
35
|
+
- @spark-web/box@2.0.0-rc.20
|
|
36
|
+
|
|
37
|
+
## 4.0.0-rc.19
|
|
38
|
+
|
|
39
|
+
### Major Changes
|
|
40
|
+
|
|
41
|
+
- test
|
|
42
|
+
|
|
43
|
+
### Patch Changes
|
|
44
|
+
|
|
45
|
+
- Updated dependencies []:
|
|
46
|
+
- @spark-web/stack@2.0.0-rc.19
|
|
47
|
+
- @spark-web/theme@4.0.0-rc.19
|
|
48
|
+
- @spark-web/utils@2.0.0-rc.19
|
|
49
|
+
- @spark-web/a11y@2.0.0-rc.19
|
|
50
|
+
- @spark-web/icon@2.0.0-rc.19
|
|
51
|
+
- @spark-web/text@2.0.0-rc.19
|
|
52
|
+
- @spark-web/box@2.0.0-rc.19
|
|
53
|
+
|
|
54
|
+
## 4.0.0-rc.18
|
|
55
|
+
|
|
56
|
+
### Major Changes
|
|
57
|
+
|
|
58
|
+
- tests
|
|
59
|
+
|
|
60
|
+
### Patch Changes
|
|
61
|
+
|
|
62
|
+
- Updated dependencies []:
|
|
63
|
+
- @spark-web/stack@2.0.0-rc.18
|
|
64
|
+
- @spark-web/theme@4.0.0-rc.18
|
|
65
|
+
- @spark-web/utils@2.0.0-rc.18
|
|
66
|
+
- @spark-web/a11y@2.0.0-rc.18
|
|
67
|
+
- @spark-web/icon@2.0.0-rc.18
|
|
68
|
+
- @spark-web/text@2.0.0-rc.18
|
|
69
|
+
- @spark-web/box@2.0.0-rc.18
|
|
70
|
+
|
|
71
|
+
## 4.0.0-rc.17
|
|
72
|
+
|
|
73
|
+
### Major Changes
|
|
74
|
+
|
|
75
|
+
- test
|
|
76
|
+
|
|
77
|
+
### Patch Changes
|
|
78
|
+
|
|
79
|
+
- Updated dependencies []:
|
|
80
|
+
- @spark-web/stack@2.0.0-rc.17
|
|
81
|
+
- @spark-web/theme@4.0.0-rc.17
|
|
82
|
+
- @spark-web/utils@2.0.0-rc.17
|
|
83
|
+
- @spark-web/a11y@2.0.0-rc.17
|
|
84
|
+
- @spark-web/icon@2.0.0-rc.17
|
|
85
|
+
- @spark-web/text@2.0.0-rc.17
|
|
86
|
+
- @spark-web/box@2.0.0-rc.17
|
|
87
|
+
|
|
88
|
+
## 4.0.0-rc.16
|
|
89
|
+
|
|
90
|
+
### Major Changes
|
|
91
|
+
|
|
92
|
+
- test
|
|
93
|
+
|
|
94
|
+
### Patch Changes
|
|
95
|
+
|
|
96
|
+
- Updated dependencies []:
|
|
97
|
+
- @spark-web/stack@2.0.0-rc.16
|
|
98
|
+
- @spark-web/theme@4.0.0-rc.16
|
|
99
|
+
- @spark-web/utils@2.0.0-rc.16
|
|
100
|
+
- @spark-web/a11y@2.0.0-rc.16
|
|
101
|
+
- @spark-web/icon@2.0.0-rc.16
|
|
102
|
+
- @spark-web/text@2.0.0-rc.16
|
|
103
|
+
- @spark-web/box@2.0.0-rc.16
|
|
104
|
+
|
|
105
|
+
## 4.0.0-rc.15
|
|
106
|
+
|
|
107
|
+
### Major Changes
|
|
108
|
+
|
|
109
|
+
- test
|
|
110
|
+
|
|
111
|
+
### Patch Changes
|
|
112
|
+
|
|
113
|
+
- Updated dependencies []:
|
|
114
|
+
- @spark-web/stack@2.0.0-rc.15
|
|
115
|
+
- @spark-web/theme@4.0.0-rc.15
|
|
116
|
+
- @spark-web/utils@2.0.0-rc.15
|
|
117
|
+
- @spark-web/a11y@2.0.0-rc.15
|
|
118
|
+
- @spark-web/icon@2.0.0-rc.15
|
|
119
|
+
- @spark-web/text@2.0.0-rc.15
|
|
120
|
+
- @spark-web/box@2.0.0-rc.15
|
|
121
|
+
|
|
122
|
+
## 4.0.0-rc.14
|
|
123
|
+
|
|
124
|
+
### Major Changes
|
|
125
|
+
|
|
126
|
+
- test
|
|
127
|
+
|
|
128
|
+
### Patch Changes
|
|
129
|
+
|
|
130
|
+
- Updated dependencies []:
|
|
131
|
+
- @spark-web/stack@2.0.0-rc.14
|
|
132
|
+
- @spark-web/theme@4.0.0-rc.14
|
|
133
|
+
- @spark-web/utils@2.0.0-rc.14
|
|
134
|
+
- @spark-web/a11y@2.0.0-rc.14
|
|
135
|
+
- @spark-web/icon@2.0.0-rc.14
|
|
136
|
+
- @spark-web/text@2.0.0-rc.14
|
|
137
|
+
- @spark-web/box@2.0.0-rc.14
|
|
138
|
+
|
|
139
|
+
## 4.0.0-rc.13
|
|
140
|
+
|
|
141
|
+
### Major Changes
|
|
142
|
+
|
|
143
|
+
- test
|
|
144
|
+
|
|
145
|
+
### Patch Changes
|
|
146
|
+
|
|
147
|
+
- Updated dependencies []:
|
|
148
|
+
- @spark-web/stack@2.0.0-rc.13
|
|
149
|
+
- @spark-web/theme@4.0.0-rc.13
|
|
150
|
+
- @spark-web/utils@2.0.0-rc.13
|
|
151
|
+
- @spark-web/a11y@2.0.0-rc.13
|
|
152
|
+
- @spark-web/icon@2.0.0-rc.13
|
|
153
|
+
- @spark-web/text@2.0.0-rc.13
|
|
154
|
+
- @spark-web/box@2.0.0-rc.13
|
|
155
|
+
|
|
156
|
+
## 4.0.0-rc.12
|
|
157
|
+
|
|
158
|
+
### Major Changes
|
|
159
|
+
|
|
160
|
+
- test
|
|
161
|
+
|
|
162
|
+
### Patch Changes
|
|
163
|
+
|
|
164
|
+
- Updated dependencies []:
|
|
165
|
+
- @spark-web/stack@2.0.0-rc.12
|
|
166
|
+
- @spark-web/theme@4.0.0-rc.12
|
|
167
|
+
- @spark-web/utils@2.0.0-rc.12
|
|
168
|
+
- @spark-web/a11y@2.0.0-rc.12
|
|
169
|
+
- @spark-web/icon@2.0.0-rc.12
|
|
170
|
+
- @spark-web/text@2.0.0-rc.12
|
|
171
|
+
- @spark-web/box@2.0.0-rc.12
|
|
172
|
+
|
|
173
|
+
## 4.0.0-rc.11
|
|
174
|
+
|
|
175
|
+
### Major Changes
|
|
176
|
+
|
|
177
|
+
- test
|
|
178
|
+
|
|
179
|
+
### Patch Changes
|
|
180
|
+
|
|
181
|
+
- Updated dependencies []:
|
|
182
|
+
- @spark-web/stack@2.0.0-rc.11
|
|
183
|
+
- @spark-web/theme@4.0.0-rc.11
|
|
184
|
+
- @spark-web/utils@2.0.0-rc.11
|
|
185
|
+
- @spark-web/a11y@2.0.0-rc.11
|
|
186
|
+
- @spark-web/icon@2.0.0-rc.11
|
|
187
|
+
- @spark-web/text@2.0.0-rc.11
|
|
188
|
+
- @spark-web/box@2.0.0-rc.11
|
|
189
|
+
|
|
190
|
+
## 4.0.0-rc.10
|
|
191
|
+
|
|
192
|
+
### Major Changes
|
|
193
|
+
|
|
194
|
+
- test
|
|
195
|
+
|
|
196
|
+
### Patch Changes
|
|
197
|
+
|
|
198
|
+
- Updated dependencies []:
|
|
199
|
+
- @spark-web/stack@2.0.0-rc.10
|
|
200
|
+
- @spark-web/theme@4.0.0-rc.10
|
|
201
|
+
- @spark-web/utils@2.0.0-rc.10
|
|
202
|
+
- @spark-web/a11y@2.0.0-rc.10
|
|
203
|
+
- @spark-web/icon@2.0.0-rc.10
|
|
204
|
+
- @spark-web/text@2.0.0-rc.10
|
|
205
|
+
- @spark-web/box@2.0.0-rc.10
|
|
206
|
+
|
|
207
|
+
## 4.0.0-rc.9
|
|
208
|
+
|
|
209
|
+
### Major Changes
|
|
210
|
+
|
|
211
|
+
- test
|
|
212
|
+
|
|
213
|
+
### Patch Changes
|
|
214
|
+
|
|
215
|
+
- Updated dependencies []:
|
|
216
|
+
- @spark-web/stack@2.0.0-rc.9
|
|
217
|
+
- @spark-web/theme@4.0.0-rc.9
|
|
218
|
+
- @spark-web/utils@2.0.0-rc.9
|
|
219
|
+
- @spark-web/a11y@2.0.0-rc.9
|
|
220
|
+
- @spark-web/icon@2.0.0-rc.9
|
|
221
|
+
- @spark-web/text@2.0.0-rc.9
|
|
222
|
+
- @spark-web/box@2.0.0-rc.9
|
|
223
|
+
|
|
224
|
+
## 4.0.0-rc.8
|
|
225
|
+
|
|
226
|
+
### Major Changes
|
|
227
|
+
|
|
228
|
+
- test
|
|
229
|
+
|
|
230
|
+
### Patch Changes
|
|
231
|
+
|
|
232
|
+
- Updated dependencies []:
|
|
233
|
+
- @spark-web/stack@2.0.0-rc.8
|
|
234
|
+
- @spark-web/theme@4.0.0-rc.8
|
|
235
|
+
- @spark-web/utils@2.0.0-rc.8
|
|
236
|
+
- @spark-web/a11y@2.0.0-rc.8
|
|
237
|
+
- @spark-web/icon@2.0.0-rc.8
|
|
238
|
+
- @spark-web/text@2.0.0-rc.8
|
|
239
|
+
- @spark-web/box@2.0.0-rc.8
|
|
240
|
+
|
|
241
|
+
## 4.0.0-rc.7
|
|
242
|
+
|
|
243
|
+
### Major Changes
|
|
244
|
+
|
|
245
|
+
- test
|
|
246
|
+
|
|
247
|
+
### Patch Changes
|
|
248
|
+
|
|
249
|
+
- Updated dependencies []:
|
|
250
|
+
- @spark-web/stack@2.0.0-rc.7
|
|
251
|
+
- @spark-web/theme@4.0.0-rc.7
|
|
252
|
+
- @spark-web/utils@2.0.0-rc.7
|
|
253
|
+
- @spark-web/a11y@2.0.0-rc.7
|
|
254
|
+
- @spark-web/icon@2.0.0-rc.7
|
|
255
|
+
- @spark-web/text@2.0.0-rc.7
|
|
256
|
+
- @spark-web/box@2.0.0-rc.7
|
|
257
|
+
|
|
258
|
+
## 4.0.0-rc.6
|
|
259
|
+
|
|
260
|
+
### Major Changes
|
|
261
|
+
|
|
262
|
+
- test
|
|
263
|
+
|
|
264
|
+
### Patch Changes
|
|
265
|
+
|
|
266
|
+
- Updated dependencies []:
|
|
267
|
+
- @spark-web/stack@2.0.0-rc.6
|
|
268
|
+
- @spark-web/theme@4.0.0-rc.6
|
|
269
|
+
- @spark-web/utils@2.0.0-rc.6
|
|
270
|
+
- @spark-web/a11y@2.0.0-rc.6
|
|
271
|
+
- @spark-web/icon@2.0.0-rc.6
|
|
272
|
+
- @spark-web/text@2.0.0-rc.6
|
|
273
|
+
- @spark-web/box@2.0.0-rc.6
|
|
274
|
+
|
|
275
|
+
## 4.0.0-rc.5
|
|
276
|
+
|
|
277
|
+
### Major Changes
|
|
278
|
+
|
|
279
|
+
- test
|
|
280
|
+
|
|
281
|
+
### Patch Changes
|
|
282
|
+
|
|
283
|
+
- Updated dependencies []:
|
|
284
|
+
- @spark-web/stack@2.0.0-rc.5
|
|
285
|
+
- @spark-web/theme@4.0.0-rc.5
|
|
286
|
+
- @spark-web/utils@2.0.0-rc.5
|
|
287
|
+
- @spark-web/a11y@2.0.0-rc.5
|
|
288
|
+
- @spark-web/icon@2.0.0-rc.5
|
|
289
|
+
- @spark-web/text@2.0.0-rc.5
|
|
290
|
+
- @spark-web/box@2.0.0-rc.5
|
|
291
|
+
|
|
292
|
+
## 4.0.0-rc.4
|
|
293
|
+
|
|
294
|
+
### Major Changes
|
|
295
|
+
|
|
296
|
+
- bug
|
|
297
|
+
|
|
298
|
+
### Patch Changes
|
|
299
|
+
|
|
300
|
+
- Updated dependencies []:
|
|
301
|
+
- @spark-web/stack@2.0.0-rc.4
|
|
302
|
+
- @spark-web/theme@4.0.0-rc.4
|
|
303
|
+
- @spark-web/utils@2.0.0-rc.4
|
|
304
|
+
- @spark-web/a11y@2.0.0-rc.4
|
|
305
|
+
- @spark-web/icon@2.0.0-rc.4
|
|
306
|
+
- @spark-web/text@2.0.0-rc.4
|
|
307
|
+
- @spark-web/box@2.0.0-rc.4
|
|
308
|
+
|
|
309
|
+
## 4.0.0-rc.3
|
|
310
|
+
|
|
311
|
+
### Major Changes
|
|
312
|
+
|
|
313
|
+
- upgrade package
|
|
314
|
+
|
|
315
|
+
### Patch Changes
|
|
316
|
+
|
|
317
|
+
- Updated dependencies []:
|
|
318
|
+
- @spark-web/stack@2.0.0-rc.3
|
|
319
|
+
- @spark-web/theme@4.0.0-rc.3
|
|
320
|
+
- @spark-web/utils@2.0.0-rc.3
|
|
321
|
+
- @spark-web/a11y@2.0.0-rc.3
|
|
322
|
+
- @spark-web/icon@2.0.0-rc.3
|
|
323
|
+
- @spark-web/text@2.0.0-rc.3
|
|
324
|
+
- @spark-web/box@2.0.0-rc.3
|
|
325
|
+
|
|
3
326
|
## 4.0.0-rc.2
|
|
4
327
|
|
|
5
328
|
### Major Changes
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "
|
|
2
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,
|
|
1
|
+
export * from "../src/index";
|
|
2
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3Bhcmstd2ViLWZpZWxkLmNqcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBIn0=
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
// this file might look strange and you might be wondering what it's for
|
|
3
|
+
// it's lets you import your source files by importing this entrypoint
|
|
4
|
+
// as you would import it if it was built with preconstruct build
|
|
5
|
+
// this file is slightly different to some others though
|
|
6
|
+
// it has a require hook which compiles your code with Babel
|
|
7
|
+
// this means that you don't have to set up @babel/register or anything like that
|
|
8
|
+
// but you can still require this module and it'll be compiled
|
|
2
9
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
10
|
+
// this bit of code imports the require hook and registers it
|
|
11
|
+
let unregister = require("../../../node_modules/@preconstruct/hook").___internalHook(typeof __dirname === 'undefined' ? undefined : __dirname, "../../..", "..");
|
|
12
|
+
|
|
13
|
+
// this re-exports the source file
|
|
14
|
+
module.exports = require("../src/index.ts");
|
|
15
|
+
|
|
16
|
+
unregister();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spark-web/field",
|
|
3
|
-
"version": "4.0.0-rc.
|
|
3
|
+
"version": "4.0.0-rc.21",
|
|
4
4
|
"homepage": "https://github.com/brighte-labs/spark-web#readme",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,14 +16,14 @@
|
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@babel/runtime": "^7.25.0",
|
|
19
|
-
"@emotion/react": "^11.
|
|
20
|
-
"@spark-web/a11y": "^2.0.0-rc.
|
|
21
|
-
"@spark-web/box": "^2.0.0-rc.
|
|
22
|
-
"@spark-web/icon": "^2.0.0-rc.
|
|
23
|
-
"@spark-web/stack": "^2.0.0-rc.
|
|
24
|
-
"@spark-web/text": "^2.0.0-rc.
|
|
25
|
-
"@spark-web/theme": "^4.0.0-rc.
|
|
26
|
-
"@spark-web/utils": "^2.0.0-rc.
|
|
19
|
+
"@emotion/react": "^11.14.0",
|
|
20
|
+
"@spark-web/a11y": "^2.0.0-rc.21",
|
|
21
|
+
"@spark-web/box": "^2.0.0-rc.21",
|
|
22
|
+
"@spark-web/icon": "^2.0.0-rc.21",
|
|
23
|
+
"@spark-web/stack": "^2.0.0-rc.21",
|
|
24
|
+
"@spark-web/text": "^2.0.0-rc.21",
|
|
25
|
+
"@spark-web/theme": "^4.0.0-rc.21",
|
|
26
|
+
"@spark-web/utils": "^2.0.0-rc.21"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/react": "^18.2.0",
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
export declare type FieldState = {
|
|
3
|
-
disabled: boolean;
|
|
4
|
-
invalid: boolean;
|
|
5
|
-
};
|
|
6
|
-
export declare type InputPropsDerivedFromField = {
|
|
7
|
-
'aria-describedby'?: string;
|
|
8
|
-
'aria-invalid': true | undefined;
|
|
9
|
-
id: string;
|
|
10
|
-
};
|
|
11
|
-
export declare type FieldContextType = [FieldState, InputPropsDerivedFromField];
|
|
12
|
-
export declare const FieldContext: import("react").Context<FieldContextType | null>;
|
|
13
|
-
export declare const FieldContextProvider: import("react").Provider<FieldContextType | null>;
|
|
14
|
-
export declare const FIELD_CONTEXT_ERROR_MESSAGE = "Input components must be inside a `Field`.";
|
|
15
|
-
export declare function useFieldContext(): FieldContextType;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { DataAttributeMap } from '@spark-web/utils/internal';
|
|
2
|
-
import type { ReactElement, ReactNode } from 'react';
|
|
3
|
-
export declare type Tone = keyof typeof messageToneMap;
|
|
4
|
-
export declare type FieldProps = {
|
|
5
|
-
/** Sets a unique identifier for the component. */
|
|
6
|
-
id?: string;
|
|
7
|
-
/** Sets data attributes on the component. */
|
|
8
|
-
data?: DataAttributeMap;
|
|
9
|
-
/** Optionally provide a utility or contextual hint, related to the field. */
|
|
10
|
-
adornment?: ReactElement;
|
|
11
|
-
/** Input component */
|
|
12
|
-
children: ReactNode;
|
|
13
|
-
/**
|
|
14
|
-
* Indicates that the field is perceivable but disabled, so it is not editable
|
|
15
|
-
* or otherwise operable.
|
|
16
|
-
*/
|
|
17
|
-
disabled?: boolean;
|
|
18
|
-
/** Provide additional information that will aid user input. */
|
|
19
|
-
description?: string;
|
|
20
|
-
/** Concisely label the field. */
|
|
21
|
-
label: string;
|
|
22
|
-
/**
|
|
23
|
-
* The label must always be provided for assistive technology, but you may
|
|
24
|
-
* hide it from sighted users when the intent can be inferred from context.
|
|
25
|
-
*/
|
|
26
|
-
labelVisibility?: 'hidden' | 'reserve-space' | 'visible';
|
|
27
|
-
/** Provide a message, informing the user about changes in state. */
|
|
28
|
-
message?: string;
|
|
29
|
-
/** Additional context, typically used to indicate that the field is optional. */
|
|
30
|
-
secondaryLabel?: string;
|
|
31
|
-
/** Provide a tone to influence elements of the field, and its input. */
|
|
32
|
-
tone?: Tone;
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* Using a [context](https://reactjs.org/docs/context.html), the field
|
|
36
|
-
* component connects the label, description, and message to the input element.
|
|
37
|
-
*/
|
|
38
|
-
export declare const Field: import("react").ForwardRefExoticComponent<FieldProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
39
|
-
export declare function useFieldIds(id?: string): {
|
|
40
|
-
descriptionId: string;
|
|
41
|
-
inputId: string;
|
|
42
|
-
messageId: string;
|
|
43
|
-
};
|
|
44
|
-
declare const messageToneMap: {
|
|
45
|
-
readonly critical: "critical";
|
|
46
|
-
readonly neutral: "muted";
|
|
47
|
-
readonly positive: "positive";
|
|
48
|
-
};
|
|
49
|
-
declare type FieldMessageProps = Required<Pick<FieldProps, 'message' | 'id' | 'tone'>>;
|
|
50
|
-
export declare const FieldMessage: ({ message, id, tone }: FieldMessageProps) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
51
|
-
export {};
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { FieldContextProvider, useFieldContext } from "./context.js";
|
|
2
|
-
export { Field, FieldMessage, useFieldIds } from "./field.js";
|
|
3
|
-
export type { FieldContextType, FieldState, InputPropsDerivedFromField, } from "./context.js";
|
|
4
|
-
export type { FieldProps, Tone } from "./field.js";
|
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var react = require('react');
|
|
6
|
-
var react$1 = require('@emotion/react');
|
|
7
|
-
var a11y = require('@spark-web/a11y');
|
|
8
|
-
var box = require('@spark-web/box');
|
|
9
|
-
var icon = require('@spark-web/icon');
|
|
10
|
-
var stack = require('@spark-web/stack');
|
|
11
|
-
var text = require('@spark-web/text');
|
|
12
|
-
var theme = require('@spark-web/theme');
|
|
13
|
-
var jsxRuntime = require('@emotion/react/jsx-runtime');
|
|
14
|
-
|
|
15
|
-
var FieldContext = /*#__PURE__*/react.createContext(null);
|
|
16
|
-
var FieldContextProvider = FieldContext.Provider;
|
|
17
|
-
var FIELD_CONTEXT_ERROR_MESSAGE = 'Input components must be inside a `Field`.';
|
|
18
|
-
function useFieldContext() {
|
|
19
|
-
var ctx = react.useContext(FieldContext);
|
|
20
|
-
if (!ctx) {
|
|
21
|
-
throw new Error(FIELD_CONTEXT_ERROR_MESSAGE);
|
|
22
|
-
}
|
|
23
|
-
return ctx;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Using a [context](https://reactjs.org/docs/context.html), the field
|
|
28
|
-
* component connects the label, description, and message to the input element.
|
|
29
|
-
*/
|
|
30
|
-
var Field = /*#__PURE__*/react.forwardRef(function (_ref, forwardedRef) {
|
|
31
|
-
var children = _ref.children,
|
|
32
|
-
idProp = _ref.id,
|
|
33
|
-
data = _ref.data,
|
|
34
|
-
description = _ref.description,
|
|
35
|
-
_ref$disabled = _ref.disabled,
|
|
36
|
-
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
37
|
-
label = _ref.label,
|
|
38
|
-
adornment = _ref.adornment,
|
|
39
|
-
_ref$labelVisibility = _ref.labelVisibility,
|
|
40
|
-
labelVisibility = _ref$labelVisibility === void 0 ? 'visible' : _ref$labelVisibility,
|
|
41
|
-
message = _ref.message,
|
|
42
|
-
secondaryLabel = _ref.secondaryLabel,
|
|
43
|
-
_ref$tone = _ref.tone,
|
|
44
|
-
tone = _ref$tone === void 0 ? 'neutral' : _ref$tone;
|
|
45
|
-
var _useFieldIds = useFieldIds(idProp),
|
|
46
|
-
descriptionId = _useFieldIds.descriptionId,
|
|
47
|
-
inputId = _useFieldIds.inputId,
|
|
48
|
-
messageId = _useFieldIds.messageId;
|
|
49
|
-
|
|
50
|
-
// field context
|
|
51
|
-
var invalid = Boolean(message && tone === 'critical');
|
|
52
|
-
var fieldContext = react.useMemo(function () {
|
|
53
|
-
return [{
|
|
54
|
-
disabled: disabled,
|
|
55
|
-
invalid: invalid
|
|
56
|
-
}, {
|
|
57
|
-
'aria-describedby': a11y.mergeIds(message && messageId, description && descriptionId),
|
|
58
|
-
'aria-invalid': invalid || undefined,
|
|
59
|
-
id: inputId
|
|
60
|
-
}];
|
|
61
|
-
}, [description, descriptionId, disabled, inputId, invalid, message, messageId]);
|
|
62
|
-
|
|
63
|
-
// label prep
|
|
64
|
-
var hiddenLabel = jsxRuntime.jsxs(a11y.VisuallyHidden, {
|
|
65
|
-
as: "label",
|
|
66
|
-
htmlFor: inputId,
|
|
67
|
-
children: [label, " ", secondaryLabel]
|
|
68
|
-
});
|
|
69
|
-
var labelElement = {
|
|
70
|
-
hidden: hiddenLabel,
|
|
71
|
-
visible: jsxRuntime.jsx(box.Box, {
|
|
72
|
-
as: "label",
|
|
73
|
-
htmlFor: inputId,
|
|
74
|
-
children: jsxRuntime.jsxs(text.Text, {
|
|
75
|
-
tone: disabled ? 'disabled' : 'neutral',
|
|
76
|
-
weight: "semibold",
|
|
77
|
-
children: [label, ' ', secondaryLabel && jsxRuntime.jsx(text.Text, {
|
|
78
|
-
inline: true,
|
|
79
|
-
tone: disabled ? 'disabled' : 'muted',
|
|
80
|
-
weight: "regular",
|
|
81
|
-
children: secondaryLabel
|
|
82
|
-
})]
|
|
83
|
-
})
|
|
84
|
-
}),
|
|
85
|
-
'reserve-space': jsxRuntime.jsxs(react.Fragment, {
|
|
86
|
-
children: [hiddenLabel, jsxRuntime.jsx(text.Text, {
|
|
87
|
-
"aria-hidden": true,
|
|
88
|
-
children: "\xA0"
|
|
89
|
-
})]
|
|
90
|
-
})
|
|
91
|
-
};
|
|
92
|
-
var LabelWrapper = labelVisibility === 'hidden' ? react.Fragment : FieldLabelWrapper;
|
|
93
|
-
return jsxRuntime.jsx(FieldContextProvider, {
|
|
94
|
-
value: fieldContext,
|
|
95
|
-
children: jsxRuntime.jsxs(stack.Stack, {
|
|
96
|
-
ref: forwardedRef,
|
|
97
|
-
data: data,
|
|
98
|
-
gap: "medium",
|
|
99
|
-
children: [jsxRuntime.jsxs(LabelWrapper, {
|
|
100
|
-
children: [labelElement[labelVisibility], adornment]
|
|
101
|
-
}), description && jsxRuntime.jsx(text.Text, {
|
|
102
|
-
tone: "muted",
|
|
103
|
-
size: "small",
|
|
104
|
-
id: descriptionId,
|
|
105
|
-
children: description
|
|
106
|
-
}), children, message && jsxRuntime.jsx(FieldMessage, {
|
|
107
|
-
tone: tone,
|
|
108
|
-
id: messageId,
|
|
109
|
-
message: message
|
|
110
|
-
})]
|
|
111
|
-
})
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
Field.displayName = 'Field';
|
|
115
|
-
|
|
116
|
-
// Utils
|
|
117
|
-
// ------------------------------
|
|
118
|
-
|
|
119
|
-
function useFieldIds(id) {
|
|
120
|
-
var inputId = a11y.useId(id);
|
|
121
|
-
var descriptionId = a11y.composeId(inputId, 'description');
|
|
122
|
-
var messageId = a11y.composeId(inputId, 'message');
|
|
123
|
-
return {
|
|
124
|
-
descriptionId: descriptionId,
|
|
125
|
-
inputId: inputId,
|
|
126
|
-
messageId: messageId
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// Styled components
|
|
131
|
-
// ------------------------------
|
|
132
|
-
function FieldLabelWrapper(_ref2) {
|
|
133
|
-
var children = _ref2.children;
|
|
134
|
-
return jsxRuntime.jsx(box.Box, {
|
|
135
|
-
display: "flex",
|
|
136
|
-
alignItems: "center",
|
|
137
|
-
justifyContent: "spaceBetween",
|
|
138
|
-
gap: "large",
|
|
139
|
-
children: children
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
var messageToneMap = {
|
|
143
|
-
critical: 'critical',
|
|
144
|
-
neutral: 'muted',
|
|
145
|
-
positive: 'positive'
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
// NOTE: use icons in addition to color for folks with visions issues
|
|
149
|
-
var messageIconMap = {
|
|
150
|
-
critical: icon.ExclamationCircleIcon,
|
|
151
|
-
neutral: null,
|
|
152
|
-
positive: icon.CheckCircleIcon
|
|
153
|
-
};
|
|
154
|
-
var FieldMessage = function FieldMessage(_ref3) {
|
|
155
|
-
var message = _ref3.message,
|
|
156
|
-
id = _ref3.id,
|
|
157
|
-
tone = _ref3.tone;
|
|
158
|
-
var textTone = messageToneMap[tone];
|
|
159
|
-
var Icon = messageIconMap[tone];
|
|
160
|
-
return jsxRuntime.jsxs(box.Box, {
|
|
161
|
-
display: "flex",
|
|
162
|
-
gap: "xsmall",
|
|
163
|
-
children: [Icon ? jsxRuntime.jsx(IndicatorContainer, {
|
|
164
|
-
children: jsxRuntime.jsx(Icon, {
|
|
165
|
-
size: "xxsmall",
|
|
166
|
-
tone: tone
|
|
167
|
-
})
|
|
168
|
-
}) : null, jsxRuntime.jsx(text.Text, {
|
|
169
|
-
tone: textTone,
|
|
170
|
-
size: "small",
|
|
171
|
-
id: id,
|
|
172
|
-
children: message
|
|
173
|
-
})]
|
|
174
|
-
});
|
|
175
|
-
};
|
|
176
|
-
function IndicatorContainer(_ref4) {
|
|
177
|
-
var children = _ref4.children;
|
|
178
|
-
var theme$1 = theme.useTheme();
|
|
179
|
-
var _theme$typography$tex = theme$1.typography.text.small,
|
|
180
|
-
mobile = _theme$typography$tex.mobile,
|
|
181
|
-
tablet = _theme$typography$tex.tablet;
|
|
182
|
-
var responsiveStyles = theme$1.utils.responsiveStyles({
|
|
183
|
-
mobile: {
|
|
184
|
-
height: mobile.capHeight
|
|
185
|
-
},
|
|
186
|
-
tablet: {
|
|
187
|
-
height: tablet.capHeight
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
return jsxRuntime.jsx(box.Box, {
|
|
191
|
-
display: "flex",
|
|
192
|
-
alignItems: "center",
|
|
193
|
-
"aria-hidden": true,
|
|
194
|
-
cursor: "default",
|
|
195
|
-
flexShrink: 0,
|
|
196
|
-
css: react$1.css(responsiveStyles),
|
|
197
|
-
children: children
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
exports.Field = Field;
|
|
202
|
-
exports.FieldContextProvider = FieldContextProvider;
|
|
203
|
-
exports.FieldMessage = FieldMessage;
|
|
204
|
-
exports.useFieldContext = useFieldContext;
|
|
205
|
-
exports.useFieldIds = useFieldIds;
|
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var react = require('react');
|
|
6
|
-
var react$1 = require('@emotion/react');
|
|
7
|
-
var a11y = require('@spark-web/a11y');
|
|
8
|
-
var box = require('@spark-web/box');
|
|
9
|
-
var icon = require('@spark-web/icon');
|
|
10
|
-
var stack = require('@spark-web/stack');
|
|
11
|
-
var text = require('@spark-web/text');
|
|
12
|
-
var theme = require('@spark-web/theme');
|
|
13
|
-
var jsxRuntime = require('@emotion/react/jsx-runtime');
|
|
14
|
-
|
|
15
|
-
var FieldContext = /*#__PURE__*/react.createContext(null);
|
|
16
|
-
var FieldContextProvider = FieldContext.Provider;
|
|
17
|
-
var FIELD_CONTEXT_ERROR_MESSAGE = 'Input components must be inside a `Field`.';
|
|
18
|
-
function useFieldContext() {
|
|
19
|
-
var ctx = react.useContext(FieldContext);
|
|
20
|
-
if (!ctx) {
|
|
21
|
-
throw new Error(FIELD_CONTEXT_ERROR_MESSAGE);
|
|
22
|
-
}
|
|
23
|
-
return ctx;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Using a [context](https://reactjs.org/docs/context.html), the field
|
|
28
|
-
* component connects the label, description, and message to the input element.
|
|
29
|
-
*/
|
|
30
|
-
var Field = /*#__PURE__*/react.forwardRef(function (_ref, forwardedRef) {
|
|
31
|
-
var children = _ref.children,
|
|
32
|
-
idProp = _ref.id,
|
|
33
|
-
data = _ref.data,
|
|
34
|
-
description = _ref.description,
|
|
35
|
-
_ref$disabled = _ref.disabled,
|
|
36
|
-
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
37
|
-
label = _ref.label,
|
|
38
|
-
adornment = _ref.adornment,
|
|
39
|
-
_ref$labelVisibility = _ref.labelVisibility,
|
|
40
|
-
labelVisibility = _ref$labelVisibility === void 0 ? 'visible' : _ref$labelVisibility,
|
|
41
|
-
message = _ref.message,
|
|
42
|
-
secondaryLabel = _ref.secondaryLabel,
|
|
43
|
-
_ref$tone = _ref.tone,
|
|
44
|
-
tone = _ref$tone === void 0 ? 'neutral' : _ref$tone;
|
|
45
|
-
var _useFieldIds = useFieldIds(idProp),
|
|
46
|
-
descriptionId = _useFieldIds.descriptionId,
|
|
47
|
-
inputId = _useFieldIds.inputId,
|
|
48
|
-
messageId = _useFieldIds.messageId;
|
|
49
|
-
|
|
50
|
-
// field context
|
|
51
|
-
var invalid = Boolean(message && tone === 'critical');
|
|
52
|
-
var fieldContext = react.useMemo(function () {
|
|
53
|
-
return [{
|
|
54
|
-
disabled: disabled,
|
|
55
|
-
invalid: invalid
|
|
56
|
-
}, {
|
|
57
|
-
'aria-describedby': a11y.mergeIds(message && messageId, description && descriptionId),
|
|
58
|
-
'aria-invalid': invalid || undefined,
|
|
59
|
-
id: inputId
|
|
60
|
-
}];
|
|
61
|
-
}, [description, descriptionId, disabled, inputId, invalid, message, messageId]);
|
|
62
|
-
|
|
63
|
-
// label prep
|
|
64
|
-
var hiddenLabel = jsxRuntime.jsxs(a11y.VisuallyHidden, {
|
|
65
|
-
as: "label",
|
|
66
|
-
htmlFor: inputId,
|
|
67
|
-
children: [label, " ", secondaryLabel]
|
|
68
|
-
});
|
|
69
|
-
var labelElement = {
|
|
70
|
-
hidden: hiddenLabel,
|
|
71
|
-
visible: jsxRuntime.jsx(box.Box, {
|
|
72
|
-
as: "label",
|
|
73
|
-
htmlFor: inputId,
|
|
74
|
-
children: jsxRuntime.jsxs(text.Text, {
|
|
75
|
-
tone: disabled ? 'disabled' : 'neutral',
|
|
76
|
-
weight: "semibold",
|
|
77
|
-
children: [label, ' ', secondaryLabel && jsxRuntime.jsx(text.Text, {
|
|
78
|
-
inline: true,
|
|
79
|
-
tone: disabled ? 'disabled' : 'muted',
|
|
80
|
-
weight: "regular",
|
|
81
|
-
children: secondaryLabel
|
|
82
|
-
})]
|
|
83
|
-
})
|
|
84
|
-
}),
|
|
85
|
-
'reserve-space': jsxRuntime.jsxs(react.Fragment, {
|
|
86
|
-
children: [hiddenLabel, jsxRuntime.jsx(text.Text, {
|
|
87
|
-
"aria-hidden": true,
|
|
88
|
-
children: "\xA0"
|
|
89
|
-
})]
|
|
90
|
-
})
|
|
91
|
-
};
|
|
92
|
-
var LabelWrapper = labelVisibility === 'hidden' ? react.Fragment : FieldLabelWrapper;
|
|
93
|
-
return jsxRuntime.jsx(FieldContextProvider, {
|
|
94
|
-
value: fieldContext,
|
|
95
|
-
children: jsxRuntime.jsxs(stack.Stack, {
|
|
96
|
-
ref: forwardedRef,
|
|
97
|
-
data: data,
|
|
98
|
-
gap: "medium",
|
|
99
|
-
children: [jsxRuntime.jsxs(LabelWrapper, {
|
|
100
|
-
children: [labelElement[labelVisibility], adornment]
|
|
101
|
-
}), description && jsxRuntime.jsx(text.Text, {
|
|
102
|
-
tone: "muted",
|
|
103
|
-
size: "small",
|
|
104
|
-
id: descriptionId,
|
|
105
|
-
children: description
|
|
106
|
-
}), children, message && jsxRuntime.jsx(FieldMessage, {
|
|
107
|
-
tone: tone,
|
|
108
|
-
id: messageId,
|
|
109
|
-
message: message
|
|
110
|
-
})]
|
|
111
|
-
})
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
Field.displayName = 'Field';
|
|
115
|
-
|
|
116
|
-
// Utils
|
|
117
|
-
// ------------------------------
|
|
118
|
-
|
|
119
|
-
function useFieldIds(id) {
|
|
120
|
-
var inputId = a11y.useId(id);
|
|
121
|
-
var descriptionId = a11y.composeId(inputId, 'description');
|
|
122
|
-
var messageId = a11y.composeId(inputId, 'message');
|
|
123
|
-
return {
|
|
124
|
-
descriptionId: descriptionId,
|
|
125
|
-
inputId: inputId,
|
|
126
|
-
messageId: messageId
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// Styled components
|
|
131
|
-
// ------------------------------
|
|
132
|
-
function FieldLabelWrapper(_ref2) {
|
|
133
|
-
var children = _ref2.children;
|
|
134
|
-
return jsxRuntime.jsx(box.Box, {
|
|
135
|
-
display: "flex",
|
|
136
|
-
alignItems: "center",
|
|
137
|
-
justifyContent: "spaceBetween",
|
|
138
|
-
gap: "large",
|
|
139
|
-
children: children
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
var messageToneMap = {
|
|
143
|
-
critical: 'critical',
|
|
144
|
-
neutral: 'muted',
|
|
145
|
-
positive: 'positive'
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
// NOTE: use icons in addition to color for folks with visions issues
|
|
149
|
-
var messageIconMap = {
|
|
150
|
-
critical: icon.ExclamationCircleIcon,
|
|
151
|
-
neutral: null,
|
|
152
|
-
positive: icon.CheckCircleIcon
|
|
153
|
-
};
|
|
154
|
-
var FieldMessage = function FieldMessage(_ref3) {
|
|
155
|
-
var message = _ref3.message,
|
|
156
|
-
id = _ref3.id,
|
|
157
|
-
tone = _ref3.tone;
|
|
158
|
-
var textTone = messageToneMap[tone];
|
|
159
|
-
var Icon = messageIconMap[tone];
|
|
160
|
-
return jsxRuntime.jsxs(box.Box, {
|
|
161
|
-
display: "flex",
|
|
162
|
-
gap: "xsmall",
|
|
163
|
-
children: [Icon ? jsxRuntime.jsx(IndicatorContainer, {
|
|
164
|
-
children: jsxRuntime.jsx(Icon, {
|
|
165
|
-
size: "xxsmall",
|
|
166
|
-
tone: tone
|
|
167
|
-
})
|
|
168
|
-
}) : null, jsxRuntime.jsx(text.Text, {
|
|
169
|
-
tone: textTone,
|
|
170
|
-
size: "small",
|
|
171
|
-
id: id,
|
|
172
|
-
children: message
|
|
173
|
-
})]
|
|
174
|
-
});
|
|
175
|
-
};
|
|
176
|
-
function IndicatorContainer(_ref4) {
|
|
177
|
-
var children = _ref4.children;
|
|
178
|
-
var theme$1 = theme.useTheme();
|
|
179
|
-
var _theme$typography$tex = theme$1.typography.text.small,
|
|
180
|
-
mobile = _theme$typography$tex.mobile,
|
|
181
|
-
tablet = _theme$typography$tex.tablet;
|
|
182
|
-
var responsiveStyles = theme$1.utils.responsiveStyles({
|
|
183
|
-
mobile: {
|
|
184
|
-
height: mobile.capHeight
|
|
185
|
-
},
|
|
186
|
-
tablet: {
|
|
187
|
-
height: tablet.capHeight
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
return jsxRuntime.jsx(box.Box, {
|
|
191
|
-
display: "flex",
|
|
192
|
-
alignItems: "center",
|
|
193
|
-
"aria-hidden": true,
|
|
194
|
-
cursor: "default",
|
|
195
|
-
flexShrink: 0,
|
|
196
|
-
css: react$1.css(responsiveStyles),
|
|
197
|
-
children: children
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
exports.Field = Field;
|
|
202
|
-
exports.FieldContextProvider = FieldContextProvider;
|
|
203
|
-
exports.FieldMessage = FieldMessage;
|
|
204
|
-
exports.useFieldContext = useFieldContext;
|
|
205
|
-
exports.useFieldIds = useFieldIds;
|
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import { createContext, useContext, forwardRef, useMemo, Fragment } from 'react';
|
|
2
|
-
import { css } from '@emotion/react';
|
|
3
|
-
import { mergeIds, VisuallyHidden, useId, composeId } from '@spark-web/a11y';
|
|
4
|
-
import { Box } from '@spark-web/box';
|
|
5
|
-
import { ExclamationCircleIcon, CheckCircleIcon } from '@spark-web/icon';
|
|
6
|
-
import { Stack } from '@spark-web/stack';
|
|
7
|
-
import { Text } from '@spark-web/text';
|
|
8
|
-
import { useTheme } from '@spark-web/theme';
|
|
9
|
-
import { jsxs, jsx } from '@emotion/react/jsx-runtime';
|
|
10
|
-
|
|
11
|
-
var FieldContext = /*#__PURE__*/createContext(null);
|
|
12
|
-
var FieldContextProvider = FieldContext.Provider;
|
|
13
|
-
var FIELD_CONTEXT_ERROR_MESSAGE = 'Input components must be inside a `Field`.';
|
|
14
|
-
function useFieldContext() {
|
|
15
|
-
var ctx = useContext(FieldContext);
|
|
16
|
-
if (!ctx) {
|
|
17
|
-
throw new Error(FIELD_CONTEXT_ERROR_MESSAGE);
|
|
18
|
-
}
|
|
19
|
-
return ctx;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Using a [context](https://reactjs.org/docs/context.html), the field
|
|
24
|
-
* component connects the label, description, and message to the input element.
|
|
25
|
-
*/
|
|
26
|
-
var Field = /*#__PURE__*/forwardRef(function (_ref, forwardedRef) {
|
|
27
|
-
var children = _ref.children,
|
|
28
|
-
idProp = _ref.id,
|
|
29
|
-
data = _ref.data,
|
|
30
|
-
description = _ref.description,
|
|
31
|
-
_ref$disabled = _ref.disabled,
|
|
32
|
-
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
33
|
-
label = _ref.label,
|
|
34
|
-
adornment = _ref.adornment,
|
|
35
|
-
_ref$labelVisibility = _ref.labelVisibility,
|
|
36
|
-
labelVisibility = _ref$labelVisibility === void 0 ? 'visible' : _ref$labelVisibility,
|
|
37
|
-
message = _ref.message,
|
|
38
|
-
secondaryLabel = _ref.secondaryLabel,
|
|
39
|
-
_ref$tone = _ref.tone,
|
|
40
|
-
tone = _ref$tone === void 0 ? 'neutral' : _ref$tone;
|
|
41
|
-
var _useFieldIds = useFieldIds(idProp),
|
|
42
|
-
descriptionId = _useFieldIds.descriptionId,
|
|
43
|
-
inputId = _useFieldIds.inputId,
|
|
44
|
-
messageId = _useFieldIds.messageId;
|
|
45
|
-
|
|
46
|
-
// field context
|
|
47
|
-
var invalid = Boolean(message && tone === 'critical');
|
|
48
|
-
var fieldContext = useMemo(function () {
|
|
49
|
-
return [{
|
|
50
|
-
disabled: disabled,
|
|
51
|
-
invalid: invalid
|
|
52
|
-
}, {
|
|
53
|
-
'aria-describedby': mergeIds(message && messageId, description && descriptionId),
|
|
54
|
-
'aria-invalid': invalid || undefined,
|
|
55
|
-
id: inputId
|
|
56
|
-
}];
|
|
57
|
-
}, [description, descriptionId, disabled, inputId, invalid, message, messageId]);
|
|
58
|
-
|
|
59
|
-
// label prep
|
|
60
|
-
var hiddenLabel = jsxs(VisuallyHidden, {
|
|
61
|
-
as: "label",
|
|
62
|
-
htmlFor: inputId,
|
|
63
|
-
children: [label, " ", secondaryLabel]
|
|
64
|
-
});
|
|
65
|
-
var labelElement = {
|
|
66
|
-
hidden: hiddenLabel,
|
|
67
|
-
visible: jsx(Box, {
|
|
68
|
-
as: "label",
|
|
69
|
-
htmlFor: inputId,
|
|
70
|
-
children: jsxs(Text, {
|
|
71
|
-
tone: disabled ? 'disabled' : 'neutral',
|
|
72
|
-
weight: "semibold",
|
|
73
|
-
children: [label, ' ', secondaryLabel && jsx(Text, {
|
|
74
|
-
inline: true,
|
|
75
|
-
tone: disabled ? 'disabled' : 'muted',
|
|
76
|
-
weight: "regular",
|
|
77
|
-
children: secondaryLabel
|
|
78
|
-
})]
|
|
79
|
-
})
|
|
80
|
-
}),
|
|
81
|
-
'reserve-space': jsxs(Fragment, {
|
|
82
|
-
children: [hiddenLabel, jsx(Text, {
|
|
83
|
-
"aria-hidden": true,
|
|
84
|
-
children: "\xA0"
|
|
85
|
-
})]
|
|
86
|
-
})
|
|
87
|
-
};
|
|
88
|
-
var LabelWrapper = labelVisibility === 'hidden' ? Fragment : FieldLabelWrapper;
|
|
89
|
-
return jsx(FieldContextProvider, {
|
|
90
|
-
value: fieldContext,
|
|
91
|
-
children: jsxs(Stack, {
|
|
92
|
-
ref: forwardedRef,
|
|
93
|
-
data: data,
|
|
94
|
-
gap: "medium",
|
|
95
|
-
children: [jsxs(LabelWrapper, {
|
|
96
|
-
children: [labelElement[labelVisibility], adornment]
|
|
97
|
-
}), description && jsx(Text, {
|
|
98
|
-
tone: "muted",
|
|
99
|
-
size: "small",
|
|
100
|
-
id: descriptionId,
|
|
101
|
-
children: description
|
|
102
|
-
}), children, message && jsx(FieldMessage, {
|
|
103
|
-
tone: tone,
|
|
104
|
-
id: messageId,
|
|
105
|
-
message: message
|
|
106
|
-
})]
|
|
107
|
-
})
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
Field.displayName = 'Field';
|
|
111
|
-
|
|
112
|
-
// Utils
|
|
113
|
-
// ------------------------------
|
|
114
|
-
|
|
115
|
-
function useFieldIds(id) {
|
|
116
|
-
var inputId = useId(id);
|
|
117
|
-
var descriptionId = composeId(inputId, 'description');
|
|
118
|
-
var messageId = composeId(inputId, 'message');
|
|
119
|
-
return {
|
|
120
|
-
descriptionId: descriptionId,
|
|
121
|
-
inputId: inputId,
|
|
122
|
-
messageId: messageId
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// Styled components
|
|
127
|
-
// ------------------------------
|
|
128
|
-
function FieldLabelWrapper(_ref2) {
|
|
129
|
-
var children = _ref2.children;
|
|
130
|
-
return jsx(Box, {
|
|
131
|
-
display: "flex",
|
|
132
|
-
alignItems: "center",
|
|
133
|
-
justifyContent: "spaceBetween",
|
|
134
|
-
gap: "large",
|
|
135
|
-
children: children
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
var messageToneMap = {
|
|
139
|
-
critical: 'critical',
|
|
140
|
-
neutral: 'muted',
|
|
141
|
-
positive: 'positive'
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
// NOTE: use icons in addition to color for folks with visions issues
|
|
145
|
-
var messageIconMap = {
|
|
146
|
-
critical: ExclamationCircleIcon,
|
|
147
|
-
neutral: null,
|
|
148
|
-
positive: CheckCircleIcon
|
|
149
|
-
};
|
|
150
|
-
var FieldMessage = function FieldMessage(_ref3) {
|
|
151
|
-
var message = _ref3.message,
|
|
152
|
-
id = _ref3.id,
|
|
153
|
-
tone = _ref3.tone;
|
|
154
|
-
var textTone = messageToneMap[tone];
|
|
155
|
-
var Icon = messageIconMap[tone];
|
|
156
|
-
return jsxs(Box, {
|
|
157
|
-
display: "flex",
|
|
158
|
-
gap: "xsmall",
|
|
159
|
-
children: [Icon ? jsx(IndicatorContainer, {
|
|
160
|
-
children: jsx(Icon, {
|
|
161
|
-
size: "xxsmall",
|
|
162
|
-
tone: tone
|
|
163
|
-
})
|
|
164
|
-
}) : null, jsx(Text, {
|
|
165
|
-
tone: textTone,
|
|
166
|
-
size: "small",
|
|
167
|
-
id: id,
|
|
168
|
-
children: message
|
|
169
|
-
})]
|
|
170
|
-
});
|
|
171
|
-
};
|
|
172
|
-
function IndicatorContainer(_ref4) {
|
|
173
|
-
var children = _ref4.children;
|
|
174
|
-
var theme = useTheme();
|
|
175
|
-
var _theme$typography$tex = theme.typography.text.small,
|
|
176
|
-
mobile = _theme$typography$tex.mobile,
|
|
177
|
-
tablet = _theme$typography$tex.tablet;
|
|
178
|
-
var responsiveStyles = theme.utils.responsiveStyles({
|
|
179
|
-
mobile: {
|
|
180
|
-
height: mobile.capHeight
|
|
181
|
-
},
|
|
182
|
-
tablet: {
|
|
183
|
-
height: tablet.capHeight
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
return jsx(Box, {
|
|
187
|
-
display: "flex",
|
|
188
|
-
alignItems: "center",
|
|
189
|
-
"aria-hidden": true,
|
|
190
|
-
cursor: "default",
|
|
191
|
-
flexShrink: 0,
|
|
192
|
-
css: css(responsiveStyles),
|
|
193
|
-
children: children
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
export { Field, FieldContextProvider, FieldMessage, useFieldContext, useFieldIds };
|