@uqds/form 0.0.5-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # @uqds/form
2
+
3
+ > Styles for HTML form elements and form validation.
4
+
5
+ ## Usage
6
+
7
+ ### Installation
8
+
9
+ With Yarn:
10
+ ```shell
11
+ yarn add @uqds/form
12
+ ```
13
+
14
+ With NPM:
15
+ ```shell
16
+ npm i @uqds/form
17
+ ```
18
+
19
+ ---
20
+
21
+ ## Dependencies
22
+
23
+ ```
24
+ @uqds/form
25
+ └─ @uqds/core
26
+ ```
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@uqds/form",
3
+ "version": "0.0.5-alpha.0",
4
+ "description": "Form element style rules",
5
+ "keywords": [
6
+ "uqds",
7
+ "uq",
8
+ "University of Queensland",
9
+ "design system",
10
+ "scss",
11
+ "sass",
12
+ "css",
13
+ "form"
14
+ ],
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "author": {
19
+ "name": "University of Queensland",
20
+ "email": "webservices@uq.edu.au",
21
+ "url": "https://uq.edu.au"
22
+ },
23
+ "homepage": "https://github.com/uq-its-ss/design-system#readme",
24
+ "license": "ISC",
25
+ "directories": {
26
+ "lib": "src"
27
+ },
28
+ "files": [
29
+ "dist/*",
30
+ "src/*"
31
+ ],
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/uq-its-ss/design-system.git"
35
+ },
36
+ "scripts": {
37
+ "build-icons": "node script/build-icons.js",
38
+ "build": "node script/build-icons.js"
39
+ },
40
+ "bugs": {
41
+ "url": "https://github.com/uq-its-ss/design-system/issues"
42
+ },
43
+ "dependencies": {
44
+ "@uqds/core": "^0.0.5-alpha.0"
45
+ },
46
+ "devDependencies": {
47
+ "@svgdotjs/svg.js": "^3.0.16",
48
+ "chalk": "^4.1.0",
49
+ "glob": "^7.1.6",
50
+ "js-yaml": "^3.14.0",
51
+ "mini-svg-data-uri": "^1.2.3",
52
+ "svgdom": "^0.1.8",
53
+ "svgo": "^1.3.2"
54
+ },
55
+ "gitHead": "0d2250c3ff44460d2902ea08102e6423b3fcc3aa"
56
+ }
@@ -0,0 +1,3 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16">
2
+ <path d="M5.6 9.6L2.4 6.4 0 8.8l5.6 5.6L16 4l-2.4-2.4z" />
3
+ </svg>
@@ -0,0 +1,3 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16">
2
+ <path d="M14.285 5.145l-6 6.167a.41.41 0 01-.598 0L1.715 5.145" fill="none" stroke="#000" stroke-width=".75" stroke-linecap="round" stroke-linejoin="round"/>
3
+ </svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svgjs="http://svgjs.com/svgjs" viewBox="0 0 140 140" width="140" height="140"><g transform="matrix(10,0,0,10,0,0)"><path d="M13.842,11.829l-5.5-11a1.5,1.5,0,0,0-2.684,0l-5.5,11A1.5,1.5,0,0,0,1.5,14h11a1.5,1.5,0,0,0,1.342-2.171ZM6.25,5a.75.75,0,0,1,1.5,0V8a.75.75,0,0,1-1.5,0ZM7,12a1,1,0,1,1,1-1A1,1,0,0,1,7,12Z" fill="#000000" stroke="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="0"></path></g></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svgjs="http://svgjs.com/svgjs" viewBox="0 0 140 140" width="140" height="140"><g transform="matrix(10,0,0,10,0,0)"><path d="M7,0a7,7,0,1,0,7,7A7.008,7.008,0,0,0,7,0Zm3.6,5.9L6.624,9.874a1,1,0,0,1-1.415,0L3.4,8.068A1,1,0,0,1,4.818,6.654l1.1,1.1L9.182,4.487A1,1,0,0,1,10.6,5.9Z" fill="#000000" stroke="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="0"></path></g></svg>
@@ -0,0 +1,503 @@
1
+ @use '@uqds/core/src/scss/global' as core;
2
+ @use '@uqds/icon/src/scss/global' as icon;
3
+ @use 'global' as *;
4
+ @use 'icons' as *;
5
+
6
+ $use-encapsulation: false !default;
7
+
8
+ @mixin form-styles {
9
+ form,
10
+ fieldset,
11
+ legend,
12
+ label,
13
+ input,
14
+ select,
15
+ textarea,
16
+ .uq-error-summary,
17
+ .uq-error-message,
18
+ .uq-success-message,
19
+ .uq-inline-help {
20
+ box-sizing: border-box;
21
+ font-family: core.$font-body;
22
+ }
23
+
24
+ fieldset,
25
+ legend,
26
+ label,
27
+ input,
28
+ select,
29
+ textarea {
30
+ &::before, &::after,
31
+ *, *::before, *::after {
32
+ box-sizing: border-box;
33
+ }
34
+ }
35
+
36
+ fieldset {
37
+ border: 0;
38
+ padding: 0;
39
+ margin: 0;
40
+ }
41
+
42
+ label,
43
+ legend {
44
+ color: $form-text-color;
45
+ display: block;
46
+ font-size: $form-label-size;
47
+ font-weight: core.$font-weight-bold;
48
+ }
49
+
50
+ legend {
51
+ margin-bottom: $form-spacing;
52
+ line-height: core.$line-height-h;
53
+ padding: 0;
54
+
55
+ &.uq-legend--error {
56
+ color: $form-color-error;
57
+ }
58
+
59
+ .uq-legend__required {
60
+ color: $form-color-error;
61
+ }
62
+ }
63
+
64
+ label {
65
+ cursor: pointer;
66
+ line-height: core.$line-height-ui;
67
+
68
+ &.uq-label {
69
+ &--inline {
70
+ align-items: center;
71
+ display: inline-flex;
72
+ font-size: core.$font-size;
73
+ line-height: core.$line-height;
74
+ margin-bottom: core.$space-m;
75
+
76
+ input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]),
77
+ select,
78
+ textarea,
79
+ + input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]),
80
+ + select,
81
+ + textarea {
82
+ max-width: none;
83
+ min-width: 200px;
84
+ margin-left: core.$space;
85
+ margin-right: core.$space-m;
86
+ width: auto;
87
+ }
88
+
89
+ input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]),
90
+ select,
91
+ textarea {
92
+ margin-top: 0;
93
+ margin-bottom: core.$space-none;
94
+ }
95
+ }
96
+
97
+ &--disabled,
98
+ &--readonly {
99
+ color: $form-text-disabled-color;
100
+ }
101
+
102
+ &--disabled {
103
+ cursor: not-allowed;
104
+ }
105
+
106
+ &--error {
107
+ color: $form-color-error;
108
+ }
109
+
110
+ &--success {
111
+ color: $form-color-success;
112
+ }
113
+ }
114
+
115
+ input:not([type="checkbox"]):not([type="radio"]),
116
+ select,
117
+ textarea,
118
+ + input:not([type="checkbox"]):not([type="radio"]),
119
+ + select,
120
+ + textarea {
121
+ margin-top: core.$space-s;
122
+ }
123
+
124
+ input[type="radio"],
125
+ input[type="checkbox"] {
126
+ + *:not(input):not(select):not(textarea) {
127
+ display: inline-block;
128
+ font-size: core.$font-size;
129
+ font-weight: core.$font-weight-normal;
130
+ line-height: $form-checkbox-size;
131
+ margin-bottom: core.$space;
132
+ margin-left: core.$space-s;
133
+ margin-right: $form-spacing;
134
+ padding-top: core.$space-xs;
135
+ padding-left: core.$space-m;
136
+ vertical-align: top;
137
+ }
138
+
139
+ &[disabled] {
140
+ + *:not(input):not(select):not(textarea) {
141
+ color: $form-text-disabled-color;
142
+ }
143
+ }
144
+ }
145
+
146
+ .uq-label__required {
147
+ color: $form-color-error;
148
+ }
149
+ }
150
+
151
+ input,
152
+ select,
153
+ textarea {
154
+ &[disabled] {
155
+ cursor: not-allowed;
156
+ }
157
+ }
158
+
159
+ input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]),
160
+ select,
161
+ textarea {
162
+ background-color: core.$uq-white;
163
+ max-width: 100%;
164
+ min-width: 100%;
165
+ padding: ($form-spacing - core.$space-xs) $form-spacing;
166
+ border: $form-border-width solid $form-border-color;
167
+ border-radius: $form-border-radius;
168
+ font-size: $form-text-size;
169
+ color: $form-text-color;
170
+ line-height: core.$line-height-ui;
171
+ margin-bottom: core.$space-m;
172
+
173
+ &:focus {
174
+ border-color: $form-border-color-focus;
175
+ box-shadow: 0 0 0 1px $form-border-color-focus inset;
176
+ outline: none;
177
+ }
178
+
179
+ &[disabled] {
180
+ color: $form-placeholder-color;
181
+ }
182
+
183
+ &[readonly] {
184
+ &:focus {
185
+ border-color: $form-border-color;
186
+ box-shadow: 0 0 0 1px $form-border-color inset;
187
+ }
188
+ }
189
+
190
+ &::placeholder {
191
+ color: $form-placeholder-color;
192
+ }
193
+
194
+ &.uq-input--error,
195
+ &.uq-input--success {
196
+ border-radius: $form-border-radius;
197
+
198
+ &:focus {
199
+ border-color: $form-border-color-focus;
200
+ box-shadow: 0 2px 0 0 $form-border-color-focus,
201
+ 0 0 0 1px $form-border-color-focus inset;
202
+ }
203
+ }
204
+
205
+ &.uq-input--error {
206
+ border-color: $form-color-error;
207
+ box-shadow: 0 2px 0 0 $form-color-error;
208
+ }
209
+
210
+ &.uq-input--success {
211
+ border-color: $form-color-success;
212
+ box-shadow: 0 2px 0 0 $form-color-success;
213
+ }
214
+
215
+ &.uq-input--large {
216
+ padding: 1.15625rem core.$space-m;
217
+ border-radius: core.$space-xs;
218
+ }
219
+
220
+ + .uq-error-message,
221
+ + .uq-success-message {
222
+ margin-top: -(core.$space-m);
223
+ border-radius: 0 0 $form-border-radius $form-border-radius;
224
+ }
225
+ }
226
+
227
+ select {
228
+ appearance: none;
229
+ background-image: url(icon.get-icon('standard--chevron-down-sml', $form-select-icon));
230
+ background-repeat: no-repeat;
231
+ background-position: right core.$space-xs center;
232
+ padding-right: 2.5rem;
233
+ cursor: pointer;
234
+ line-height: 1.2;
235
+ width: 100%;
236
+
237
+ &:focus {
238
+ background-image: url(icon.get-icon('standard--chevron-down-sml', $form-focus-color));
239
+ }
240
+
241
+ &[multiple] {
242
+ height: auto;
243
+ background-image: none;
244
+
245
+ &:focus {
246
+ background-image: none;
247
+ }
248
+ }
249
+
250
+ &[disabled] {
251
+ background-image: url(icon.get-icon('standard--chevron-down-sml', $form-select-icon-disabled));
252
+ }
253
+ }
254
+
255
+ textarea {
256
+ height: 4 * $form-element-height;
257
+ }
258
+
259
+ input[type="radio"],
260
+ input[type="checkbox"] {
261
+ appearance: none;
262
+ display: inline-block;
263
+ border: $form-checkbox-border-width solid $form-border-color;
264
+ cursor: pointer;
265
+ height: $form-checkbox-size;
266
+ width: $form-checkbox-size;
267
+ vertical-align: top;
268
+ position: absolute;
269
+
270
+ &:focus {
271
+ border-color: $form-focus-color;
272
+ box-shadow: 0 0 0 1px $form-focus-color;
273
+ outline: none;
274
+ }
275
+
276
+ + label {
277
+ display: inline-block;
278
+ font-size: core.$font-size;
279
+ font-weight: core.$font-weight-normal;
280
+ line-height: core.$line-height-h;
281
+ margin-bottom: core.$space;
282
+ margin-left: core.$space-s;
283
+ margin-right: $form-spacing;
284
+ padding-top: core.$space-compressed-xs;
285
+ padding-left: core.$space-m;
286
+ vertical-align: top;
287
+ }
288
+
289
+ &:checked {
290
+ border-color: core.$link;
291
+
292
+ &:focus {
293
+ border-color: $form-focus-color;
294
+ box-shadow: 0 0 0 1px $form-focus-color;
295
+ }
296
+ }
297
+
298
+ &.uq-input--error {
299
+ border-color: $form-color-error;
300
+
301
+ &:focus {
302
+ border-color: $form-focus-color;
303
+ box-shadow: 0 0 0 1px $form-focus-color;
304
+ }
305
+
306
+ &:checked {
307
+ border-color: $form-color-error;
308
+
309
+ &:focus {
310
+ border-color: $form-focus-color;
311
+ box-shadow: 0 0 0 1px $form-focus-color;
312
+ }
313
+ }
314
+ }
315
+
316
+ &[disabled] {
317
+ cursor: not-allowed;
318
+ border-color: $form-border-color;
319
+ background-color: core.$uq-neutral-light80;
320
+
321
+ + label {
322
+ color: $form-text-disabled-color;
323
+ }
324
+
325
+ &:checked {
326
+ background-color: core.$uq-neutral-light20;
327
+ }
328
+ }
329
+ }
330
+
331
+ input[type="checkbox"] {
332
+ border-radius: $form-checkbox-border-radius;
333
+
334
+ &::after {
335
+ content: "";
336
+ display: block;
337
+ position: absolute;
338
+ background-repeat: no-repeat;
339
+ background-position: center center;
340
+ top: 1px;
341
+ left: 1px;
342
+ height: $form-checkbox-check-size;
343
+ width: $form-checkbox-check-size;
344
+ }
345
+
346
+ &:checked {
347
+ background-color: core.$link;
348
+
349
+ &::after {
350
+ background-image: url(icon.get-icon('standard--check', $form-checkbox-check-color));
351
+ padding: 0px;
352
+ }
353
+ }
354
+
355
+ &.uq-input--error {
356
+ &:checked {
357
+ background-color: $form-color-error;
358
+ }
359
+ }
360
+ }
361
+
362
+ input[type="radio"] {
363
+ border-radius: 50%;
364
+
365
+ &:checked {
366
+ border-width: 2px;
367
+
368
+ &::after {
369
+ border-radius: 50%;
370
+ background-color: core.$link;
371
+ content: "";
372
+ display: block;
373
+ position: absolute;
374
+ top: 3px;
375
+ left: 3px;
376
+ height: $form-checkbox-size - 10px;
377
+ width: $form-checkbox-size - 10px;
378
+ }
379
+ }
380
+
381
+ &[disabled] {
382
+ &:checked {
383
+ background-color: core.$uq-neutral-light80;
384
+ &::after {
385
+ background-color: core.$uq-neutral-light20;
386
+ }
387
+ }
388
+ }
389
+
390
+ &.uq-input--error {
391
+ &:checked {
392
+ border-color: $form-color-error;
393
+
394
+ &::after {
395
+ background-color: $form-color-error;
396
+ }
397
+ }
398
+ }
399
+ }
400
+
401
+ [type="submit"] {
402
+ appearance: none;
403
+ }
404
+
405
+ .uq-error-summary {
406
+ background-color: lighten(core.$alert-light, 10%);
407
+ border: 1px solid core.$alert;
408
+ border-left-width: core.$space-xs;
409
+ padding: core.$space;
410
+ margin-bottom: core.$space-m;
411
+
412
+ &__title {
413
+ color: core.$text;
414
+ font-size: core.$font-size-m;
415
+ font-weight: core.$font-weight-bold;
416
+ line-height: core.$line-height-h;
417
+ margin: core.$space-none core.$space-none core.$space core.$space-none;
418
+ }
419
+
420
+ &_body {
421
+ color: core.$text;
422
+ font-size: core.$space;
423
+ }
424
+
425
+ &__list {
426
+ color: core.$text;
427
+ font-size: core.$space;
428
+ margin: core.$space-none;
429
+
430
+ &__item {
431
+ margin-bottom: core.$space-xs;
432
+ line-height: core.$line-height;
433
+ }
434
+
435
+ a {
436
+ color: core.$alert;
437
+ text-decoration: underline;
438
+ font-weight: core.$font-weight-normal;
439
+ &:hover, &:focus {
440
+ color: darken(core.$alert, 5%);
441
+ }
442
+ }
443
+ }
444
+ }
445
+
446
+ .uq-error-message,
447
+ .uq-success-message {
448
+ color: core.$uq-white;
449
+ display: block;
450
+ font-size: core.$font-size;
451
+ font-style: normal;
452
+ font-weight: core.$font-weight-normal;
453
+ line-height: core.$line-height;
454
+ margin-bottom: core.$space-m;
455
+ padding: calc(#{core.$space-s} - 1px) core.$space core.$space-s core.$space-xxl;
456
+ position: relative;
457
+
458
+ &::before {
459
+ content: '';
460
+ display: block;
461
+ background-position: center;
462
+ background-repeat: no-repeat;
463
+ background-size: contain;
464
+ height: core.$space-compressed-xl;
465
+ left: core.$space;
466
+ margin-right: core.$space-s;
467
+ margin-top: calc(#{-(core.$space-compressed-xl) * 0.5} - 1px);
468
+ position: absolute;
469
+ top: 50%;
470
+ width: core.$space-compressed-xl;
471
+ }
472
+ }
473
+
474
+ .uq-error-message {
475
+ background-color: $form-color-error;
476
+
477
+ &::before {
478
+ background-image: url(icon.get-icon('standard--alert-triangle', core.$uq-white));
479
+ }
480
+ }
481
+
482
+ .uq-success-message {
483
+ background-color: $form-color-success;
484
+
485
+ &::before {
486
+ background-image: url(icon.get-icon('standard--success-circle', core.$uq-white));
487
+ }
488
+ }
489
+
490
+ .uq-inline-help {
491
+ display: block;
492
+ font-size: $form-description-size;
493
+ margin: 0 0 $form-spacing;
494
+ }
495
+ }
496
+
497
+ @if $use-encapsulation {
498
+ .uq {
499
+ @include form-styles;
500
+ }
501
+ } @else {
502
+ @include form-styles;
503
+ }
@@ -0,0 +1,28 @@
1
+ @use '@uqds/core/src/scss/global' as core;
2
+
3
+ $form-border-color-focus: core.$link;
4
+ $form-border-color: core.$uq-neutral-light40;
5
+ $form-border-radius: 2px;
6
+ $form-border-width: 1px;
7
+ $form-color-error: core.$alert;
8
+ $form-color-success: core.$success;
9
+ $form-description-size: core.$font-size-xs;
10
+ $form-element-height: core.$space-xl;
11
+ $form-focus-color: core.$link;
12
+ $form-label-size: core.$font-size-s;
13
+ $form-placeholder-color: core.$uq-neutral-dark40;
14
+ $form-spacing: core.$space;
15
+ $form-text-color: core.$text;
16
+ $form-text-disabled-color: core.$uq-neutral-dark20;
17
+ $form-text-size: core.$font-size;
18
+
19
+ // Select
20
+ $form-select-icon: core.$uq-purple;
21
+ $form-select-icon-disabled: $form-border-color;
22
+
23
+ // Checkbox/Radio buttons
24
+ $form-checkbox-border-radius: 4px;
25
+ $form-checkbox-border-width: 1px;
26
+ $form-checkbox-check-color: core.$uq-white;
27
+ $form-checkbox-size: 20px;
28
+ $form-checkbox-check-size: 16px;
@@ -0,0 +1,33 @@
1
+ $-icons: (
2
+ "form-checkbox-check": "data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='~~COLOR~~'%3e%3cpath d='M5.6 9.6L2.4 6.4 0 8.8l5.6 5.6L16 4l-2.4-2.4z'%3e%3c/path%3e%3c/svg%3e",
3
+ "form-chevron-down": "data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='~~COLOR~~'%3e%3cpath d='M14.285 5.145l-6 6.167a.41.41 0 01-.598 0L1.715 5.145' fill='none' stroke='~~COLOR~~' stroke-width='.75' stroke-linecap='round' stroke-linejoin='round'%3e%3c/path%3e%3c/svg%3e",
4
+ "form-error": "data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 140 140' width='140' height='140' fill='~~COLOR~~'%3e%3cpath d='M138.42 118.29l-55-110a15 15 0 00-26.84 0l-55 110A15 15 0 0015 140h110a15 15 0 0013.42-21.71zM62.5 50a7.5 7.5 0 0115 0v30a7.5 7.5 0 01-15 0zm7.5 70a10 10 0 1110-10 10 10 0 01-10 10z'%3e%3c/path%3e%3c/svg%3e",
5
+ "form-success": "data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 140 140' width='140' height='140' fill='~~COLOR~~'%3e%3cpath d='M70 0a70 70 0 1070 70A70.08 70.08 0 0070 0zm36 59L66.24 98.74a10 10 0 01-14.15 0L34 80.68a10.013 10.013 0 0114.18-14.14l11 11 32.64-32.67A10.01 10.01 0 01106 59z'%3e%3c/path%3e%3c/svg%3e",
6
+ );
7
+
8
+ @function -str-replace($string, $search, $replace: '') {
9
+ $index: str-index($string, $search);
10
+
11
+ @if $index {
12
+ @return str-slice( $string, 1, $index - 1 ) + $replace + -str-replace( str-slice( $string, $index + str-length( $search ) ), $search, $replace);
13
+ }
14
+
15
+ @return $string;
16
+ }
17
+
18
+ @function get-icon($icon, $color: #2b2b2b) {
19
+ @if type-of($color) != 'color' and $color != 'none' {
20
+ @warn 'The requested color - "' + $color + '" - was not recognized as a Sass color value.';
21
+ @return null;
22
+ }
23
+
24
+ @if map-has-key($-icons, $icon) {
25
+ $icon: map-get($-icons, $icon);
26
+ $data-uri: -str-replace($icon, '~~COLOR~~', $color);
27
+
28
+ @return -str-replace( $data-uri, '#', '%23' );
29
+ }
30
+
31
+ @warn 'The requested icon - "' + $icon + '" - is not defined in the $icons map.';
32
+ @return null;
33
+ }