@cscfi/csc-ui 4.0.0-alpha.30 → 4.0.0-alpha.32

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.
@@ -0,0 +1,160 @@
1
+ A colour field that takes any typed CSS colour, or opens a panel for picking one: a colour area, hue and alpha sliders, per-channel inputs and swatches — or swatches alone under `swatches-only`.
2
+
3
+ ## Value
4
+
5
+ The value is a CSS colour string in the field's notation — `'#1f6feb'` by
6
+ default — or `null` when the field is empty. Bind it with `v-model`, or listen
7
+ for `change`:
8
+
9
+ ```vue
10
+ <c-color-picker v-model="color" label="Colour" />
11
+ ```
12
+
13
+ ## Notation
14
+
15
+ `format` sets the notation the value is written in, and every emission with
16
+ it: `hex` (the default) gives `#1f6feb`, `rgb` gives `rgb(31 111 235)` and
17
+ `oklch` gives `oklch(0.5686 0.202 259.7)`. Whichever notation a colour arrives
18
+ in — typed, picked or set from outside — the field shows it, and the value
19
+ carries it, in this one. The notation is an app default, so an app can set it
20
+ once with `applyDefaults({ 'c-color-picker': { format: 'oklch' } })`.
21
+
22
+ Every colour the picker holds is an 8-bit sRGB colour — what `#rrggbb` can
23
+ write — and each notation spells it at the fewest decimals that read back to
24
+ the same colour. Switching `format` therefore never moves the colour, and an
25
+ `oklch()` typed with four decimals can come back with fewer.
26
+
27
+ The HEX | RGB | OKLCH switch inside the panel only chooses which channel
28
+ inputs show. It never changes the value or its notation.
29
+
30
+ ## Typing
31
+
32
+ The field is typeable first: clicking into it or focusing it never opens the
33
+ panel. Text is read when the user presses Enter or leaves the input, never per
34
+ keystroke, and any CSS colour reads: `#fff`, `1f6feb` without its `#`, `red`,
35
+ `hsl(210 80% 50%)`, `rgba(31, 111, 235, 0.5)`, `color(display-p3 1 0 0)`.
36
+ The field then shows the colour in its notation.
37
+
38
+ A colour outside sRGB — `oklch(0.7 0.3 150)`, `rgb(300 0 0)` — is brought into
39
+ it as it is read, keeping its lightness and hue and lowering its chroma, the
40
+ way a browser paints it on an ordinary screen. It is not an error.
41
+
42
+ Text that names no colour — `blurple`, `var(--brand)` — is **bad input**: the
43
+ text stays as the user typed it, the value becomes `null`, and the host
44
+ exposes the `bad-input` custom state and a read-only `badInput` property. The
45
+ component never shows an error of its own; deciding whether bad input is an
46
+ error, and saying so, is the consumer's validation:
47
+
48
+ ```vue
49
+ <c-color-picker
50
+ v-model="color"
51
+ :error-message="error"
52
+ :valid="!error"
53
+ label="Colour"
54
+ @change:text="error = $event.target.badInput ? 'Enter a colour' : ''"
55
+ />
56
+ ```
57
+
58
+ Every commit of typed text fires `change:text` with the text as typed.
59
+
60
+ ## Alpha
61
+
62
+ Colours are opaque unless `alpha` is set. With it the panel gains an alpha
63
+ slider and an A channel, and the value carries alpha whenever it is below 1:
64
+ `#1f6feb80`, `rgb(31 111 235 / 0.5)`. An opaque colour is written the same
65
+ with or without `alpha`. Without it, alpha in typed text is dropped.
66
+
67
+ ## The panel
68
+
69
+ The colour button at the field's trailing edge — painted with the current
70
+ colour — or Alt+ArrowDown in the input opens the panel. It is a dialog: focus
71
+ moves onto the colour area, and Tab cycles through the area, the sliders, the
72
+ original colour, the notation switch, the channel inputs and the swatches until
73
+ the panel closes. Focus returns to the input when it does.
74
+
75
+ | Key | In the colour area |
76
+ | ---------------------- | -------------------------------------------------------------- |
77
+ | ArrowLeft / ArrowRight | Less / more saturation |
78
+ | ArrowUp / ArrowDown | More / less brightness |
79
+ | Shift + arrow | Ten steps |
80
+ | PageUp / PageDown | Ten steps of brightness |
81
+ | Home / End | No / full saturation |
82
+ | Enter | Close |
83
+ | Escape | Close; what was picked stays (the original colour restores it) |
84
+
85
+ A channel input commits on Enter or when it is left, clamped to its range;
86
+ text that is no number reverts. ArrowUp and ArrowDown nudge the channel by one
87
+ step, Shift by ten, and each nudge commits.
88
+
89
+ Every pick commits at once and the panel stays open, so a colour can be
90
+ tuned in several moves (on a narrow viewport picks wait for a Done button
91
+ instead; see [Narrow viewports](#narrow-viewports)). An empty field's panel
92
+ opens on the first swatch, or on white, without committing anything.
93
+
94
+ ## Comparing with the original
95
+
96
+ When the panel opens on a colour, a strip under the sliders shows that
97
+ original colour on the left beside the colour being picked on the right, so
98
+ every change can be judged against where it started. Clicking the original —
99
+ or Enter or Space on it — restores it: in the anchored panel it commits like
100
+ any pick, and in the fullscreen panel it becomes the colour Done commits. An
101
+ empty field's panel has no comparison, and neither has a swatch-only panel.
102
+
103
+ ## Drag events
104
+
105
+ A drag on the colour area or a slider updates the value as it moves: every
106
+ move fires `update:value` and `input`, so `v-model` follows the pointer, and
107
+ `change` fires once, when the pointer is released. Save on `change` to avoid
108
+ work on every move. A click, a key press, a channel entry and a swatch pick
109
+ fire all three at once.
110
+
111
+ ## Swatches
112
+
113
+ `swatches` offers predefined colours under the picker. Each is a CSS colour,
114
+ or a `{ value, name }` object whose name is what assistive technology reads —
115
+ otherwise it reads the colour's spelling. Bind the array as a property:
116
+
117
+ ```vue
118
+ <c-color-picker
119
+ v-model="color"
120
+ :swatches="[
121
+ { value: '#1f6feb', name: 'Ocean' },
122
+ { value: '#e5534b', name: 'Coral' },
123
+ ]"
124
+ label="Tag colour"
125
+ />
126
+ ```
127
+
128
+ The swatches are one Tab stop: the arrow keys move between them without
129
+ picking, and Enter, Space or a click picks. A swatch that names no colour is
130
+ skipped with a console warning.
131
+
132
+ ## Swatches only
133
+
134
+ `swatches-only` limits the choice to the swatches. The field becomes readonly
135
+ and shows the picked swatch's colour and name; a click, Enter or Alt+ArrowDown
136
+ opens a panel of the swatches alone, and a pick commits and closes it, as in
137
+ `c-select`. Name every swatch in this mode — the name is what the field shows,
138
+ and a console warning says so when one is missing. A value set from outside
139
+ that matches no swatch is shown spelled in its notation.
140
+
141
+ ## Texts
142
+
143
+ The panel's labels are English unless `texts` replaces them. Set them app-wide
144
+ with `applyDefaults({ 'c-color-picker': { texts } })`.
145
+
146
+ ## Narrow viewports
147
+
148
+ On a viewport narrower than 760px the panel opens as a **fullscreen panel**: a
149
+ heading row with the field's `label` and a close button above the picker. The
150
+ panel ends in a Done button, and there picks wait in the panel instead of
151
+ committing: nothing is emitted until Done commits the colour and closes the
152
+ panel. The close button and Escape close the panel without a change, and so
153
+ does the window growing past 760px while it is open. Under `swatches-only`
154
+ there is no Done button: a pick commits and closes, as everywhere else.
155
+
156
+ ## Related
157
+
158
+ `c-select` lists named choices of any kind; reach for it when the options are
159
+ not colours. The browser's own `<input type="color">` has no notation, alpha,
160
+ swatches or keyboard-operable panel.
@@ -0,0 +1,189 @@
1
+ A field the user adds files to by dropping them on it or choosing them from a file dialog — and, given an upload function, the place each file's upload shows its progress.
2
+
3
+ ## Value
4
+
5
+ The value is a list of file entries — always a list, even in a field that
6
+ takes one file. Each entry has an `id`, the file's `name`, `size` and
7
+ `type`, and a `status`:
8
+
9
+ | `status` | The entry |
10
+ | ----------- | -------------------------------------------------------- |
11
+ | `local` | holds a file not yet sent — see Uploading later |
12
+ | `queued` | waits for a free upload slot — at most three run at once |
13
+ | `uploading` | is being sent |
14
+ | `done` | was sent, or is a file already on the server |
15
+ | `error` | failed; its `error` holds the text the row shows |
16
+
17
+ A file the user added carries the browser `File` as `file`; once uploaded,
18
+ `result` holds what the upload function resolved to. Bind the list with
19
+ `v-model` — an array, so it is a DOM property — or listen for `change`:
20
+
21
+ ```vue
22
+ <c-file-upload v-model="files" label="Attachments" multiple />
23
+ ```
24
+
25
+ The value events fire when the user adds, removes or retries a file, when
26
+ `startUploads()` starts files, and once when each upload finishes, done or
27
+ failed — never for progress, and never when `value` is set. Each event carries a new list of new entries.
28
+
29
+ Without `multiple` the field holds one file, and choosing another replaces
30
+ it.
31
+
32
+ ## Uploading
33
+
34
+ The field never sends a byte itself. Set `upload` to a function that sends
35
+ one file, and the field calls it for every added file as soon as it is
36
+ added:
37
+
38
+ ```js
39
+ picker.upload = (file, { onProgress, signal }) =>
40
+ new Promise((resolve, reject) => {
41
+ const xhr = new XMLHttpRequest();
42
+
43
+ xhr.upload.onprogress = (e) => onProgress(e.loaded / e.total);
44
+ xhr.onload = () =>
45
+ xhr.status < 300
46
+ ? resolve(JSON.parse(xhr.response))
47
+ : reject(new Error('The server refused the file'));
48
+ xhr.onerror = () => reject(new Error('Network error'));
49
+ signal.addEventListener('abort', () => xhr.abort());
50
+ xhr.open('POST', '/api/files');
51
+ xhr.send(file);
52
+ });
53
+ ```
54
+
55
+ `onProgress` takes a fraction from 0 to 1; until its first call the row's
56
+ bar is indeterminate, so `fetch` — which reports no upload progress — works
57
+ too. The `signal` aborts when the user cancels, removes the entry, or the
58
+ field leaves the page. What the promise resolves to becomes the entry's
59
+ `result`, typically the server's id for the file.
60
+
61
+ When the promise rejects with an `Error`, its `message` is the text the row
62
+ shows, so throw the words the user should read — `new Error('The file
63
+ exceeds your quota')`. Any other rejection, and the browser's own network
64
+ errors, show "Upload failed". Do not rethrow raw server responses.
65
+
66
+ A failed row offers a retry; a queued or uploading one, a cancel.
67
+
68
+ ## Uploading later
69
+
70
+ A `manual` field holds added files as `local` even with an upload function,
71
+ until `startUploads()` queues them — so a form can upload only when the user
72
+ asks:
73
+
74
+ ```vue
75
+ <c-file-upload
76
+ ref="field"
77
+ v-model="files"
78
+ :upload="send"
79
+ label="Attachments"
80
+ manual
81
+ multiple
82
+ />
83
+ <c-button @click="field?.startUploads()">Upload</c-button>
84
+ ```
85
+
86
+ The call starts the files the field holds at that moment and fires the value
87
+ events once. Files added after it wait as `local` for the next call; a failed
88
+ row's retry still sends its file at once. Without an upload function the call
89
+ does nothing.
90
+
91
+ Without `manual`, there is no waiting: an upload function assigned later
92
+ queues every `local` entry at once, and so every file added after it.
93
+
94
+ Or leave `upload` unset and send the files with the rest of the form. The
95
+ field takes no part in a native `<form>` submission; build the `FormData`
96
+ from the value:
97
+
98
+ ```js
99
+ const body = new FormData();
100
+
101
+ for (const entry of files) if (entry.file) body.append('files', entry.file);
102
+ ```
103
+
104
+ ## Files already on the server
105
+
106
+ To show files the user uploaded earlier, set them as entries without a
107
+ `file`, with `status: 'done'` and the server's own `id`:
108
+
109
+ ```js
110
+ picker.value = [
111
+ { id: 'f_12', name: 'contract.pdf', size: 120_400, status: 'done' },
112
+ ];
113
+ ```
114
+
115
+ Removing one only takes it out of the value. Deleting it on the server, if
116
+ it should be, is the consumer's job — on submit, or by comparing the lists.
117
+
118
+ Keep each entry's `id` when the value passes through your own state: the
119
+ field matches entries by `id`, so a list rebuilt without it loses the
120
+ progress and the cancel of the files still uploading.
121
+
122
+ ## Accepted files
123
+
124
+ `accept` takes the native syntax — extensions and media types,
125
+ `.pdf,image/*`. It filters the file dialog, and the field checks a dropped
126
+ file against it too, since a drop bypasses the dialog. `max-size` caps a
127
+ file's size in bytes, and `max-files` the number of entries a `multiple`
128
+ field holds:
129
+
130
+ ```vue
131
+ <c-file-upload
132
+ v-model="files"
133
+ accept=".pdf,image/*"
134
+ hint="PDF or images, up to 10 MB each"
135
+ label="Receipts"
136
+ max-files="5"
137
+ max-size="10000000"
138
+ multiple
139
+ />
140
+ ```
141
+
142
+ Sizes are shown in decimal units — `1 MB` is 1,000,000 bytes, as on most
143
+ phones and Macs — so write `max-size` in decimal bytes. Name the accepted
144
+ types and limits in the `hint`; the field does not generate that text.
145
+
146
+ The field never holds the same file twice: a file already in the list —
147
+ picked again from the same folder, or matching a server file's name and
148
+ size — is refused too, and so is the one file of a field without `multiple`
149
+ when it is picked again.
150
+
151
+ A refused file never joins the value. It shows as a rejected row with the
152
+ reason, and the `reject` event lists every refused file with its reason:
153
+ `type`, `size`, `duplicate`, `count` or `folder`. The rows describe the
154
+ latest add, so the next change to the list — another add, a removal, or a
155
+ value set from outside — clears them, and the user can dismiss each one.
156
+
157
+ ## Compact
158
+
159
+ `compact` shows the drop zone as a row at the shared control height — a
160
+ "Choose files" button and a drop prompt — so the field lines up with the
161
+ fields beside it. `size="small"` makes the row 36px tall:
162
+
163
+ ```vue
164
+ <c-file-upload v-model="cv" compact label="CV" />
165
+ ```
166
+
167
+ The file list sits under the drop zone in both layouts.
168
+
169
+ ## Dropping
170
+
171
+ The whole field takes a drop, not only the drop zone, so a drop that just
172
+ misses the zone still lands. While files are dragged over it, the zone
173
+ highlights and the host exposes the `drag-over` custom state.
174
+
175
+ ## Accessibility
176
+
177
+ Dragging is a pointer-only shortcut: the drop zone is a button that opens
178
+ the file dialog, and on a touch screen its prompt reads "Choose files".
179
+ Each row's buttons are named after the file — "Remove report.pdf", "Cancel
180
+ upload of report.pdf". A polite announcement reports files added, each
181
+ finished or failed upload and each rejected file; progress is never
182
+ announced, but each uploading row's progress bar can be read on demand.
183
+
184
+ ## Texts
185
+
186
+ Every text the field shows or announces is in `texts`, merged over the
187
+ English defaults; set it per field or app-wide with `applyDefaults`. File
188
+ sizes follow the page's `lang` (`1,2 Mt` under `lang="fi"`) and need no
189
+ texts.
@@ -14,7 +14,7 @@ one beneath is dimmed and inert until it becomes topmost again.
14
14
  ## When not to use
15
15
 
16
16
  - Passive notifications — use `c-toasts`, which stays visible and clickable
17
- *above* any open modal.
17
+ _above_ any open modal.
18
18
  - Large multi-step flows — prefer a dedicated page.
19
19
 
20
20
  ## Dismissal
@@ -22,4 +22,4 @@ Slotted center content is presentational to assistive technology (the value is a
22
22
 
23
23
  ## Customization
24
24
 
25
- Restyle via the parts: `::part(track)` and `::part(bar)` accept any stroke colour (the defaults are the muted surface track and the primary arc), and `::part(content)` styles the centered slot wrapper. Keep stroke *width* on the `width` prop — the radius math depends on it.
25
+ Restyle via the parts: `::part(track)` and `::part(bar)` accept any stroke colour (the defaults are the muted surface track and the primary arc), and `::part(content)` styles the centered slot wrapper. Keep stroke _width_ on the `width` prop — the radius math depends on it.
@@ -27,7 +27,7 @@ needs:
27
27
  </c-radio-group>
28
28
  ```
29
29
 
30
- Text placed *next to* a radio instead of inside it renders, but is not
30
+ Text placed _next to_ a radio instead of inside it renders, but is not
31
31
  click-associated or announced — put the label content in the radio's slot.
32
32
 
33
33
  ## Value
@@ -125,7 +125,6 @@
125
125
  --c-warning-950: oklch(0.1989 0.0632 39.4156);
126
126
  --c-white: oklch(1.0000 0.0000 0.0000);
127
127
  --c-white-rgb: 255, 255, 255;
128
- --c-font-family: 'museo-sans', sans-serif;
129
128
  --c-text-body: var(--c-primary-900);
130
129
  --c-text-system: var(--c-tertiary-600);
131
130
  }
@@ -885,11 +884,13 @@ c-card-actions:not(:defined),
885
884
  c-card-content:not(:defined),
886
885
  c-card-title:not(:defined),
887
886
  c-checkbox:not(:defined),
887
+ c-color-picker:not(:defined),
888
888
  c-csc-logo:not(:defined),
889
889
  c-data-table:not(:defined),
890
890
  c-date-picker:not(:defined),
891
891
  c-divider:not(:defined),
892
892
  c-dropdown:not(:defined),
893
+ c-file-upload:not(:defined),
893
894
  c-icon:not(:defined),
894
895
  c-icon-button:not(:defined),
895
896
  c-input:not(:defined),
@@ -2,11 +2,6 @@
2
2
  "$schema": "https://raw.githubusercontent.com/microsoft/vscode-css-languageservice/main/docs/customData.schema.json",
3
3
  "version": 1.1,
4
4
  "properties": [
5
- {
6
- "name": "--c-font-family",
7
- "description": "Font stack applied to the label (native buttons do not inherit it).",
8
- "values": []
9
- },
10
5
  {
11
6
  "name": "--c-main-viewport-height",
12
7
  "description": "Height of the scroll viewport the layout pins against (default `100dvh`); a bounded shell with its own scrollbar sets it to its box height",
@@ -234,6 +229,86 @@
234
229
  "name": "::part(message)",
235
230
  "description": "The hint / error message area below the checkbox (always reserved unless `hide-details`)"
236
231
  },
232
+ {
233
+ "name": "::part(input)",
234
+ "description": "The text input; under `swatches-only` the readonly field"
235
+ },
236
+ {
237
+ "name": "::part(separator)",
238
+ "description": "Unused: the shared typed field's range separator"
239
+ },
240
+ {
241
+ "name": "::part(color-chip)",
242
+ "description": "The colour painted in the colour button, or before the swatch-only field's text"
243
+ },
244
+ {
245
+ "name": "::part(panel)",
246
+ "description": "The top-layer popover container anchored below the field"
247
+ },
248
+ {
249
+ "name": "::part(card)",
250
+ "description": "The dialog surface inside the panel"
251
+ },
252
+ {
253
+ "name": "::part(heading-row)",
254
+ "description": "The top row of the fullscreen panel (narrow viewports): the field label as heading and the close button"
255
+ },
256
+ {
257
+ "name": "::part(heading)",
258
+ "description": "The field label naming the fullscreen panel"
259
+ },
260
+ {
261
+ "name": "::part(close)",
262
+ "description": "The close button of the fullscreen panel"
263
+ },
264
+ {
265
+ "name": "::part(area)",
266
+ "description": "The saturation × brightness square at the current hue"
267
+ },
268
+ {
269
+ "name": "::part(area-thumb)",
270
+ "description": "The marker of the colour in the area"
271
+ },
272
+ { "name": "::part(hue-slider)", "description": "The hue slider" },
273
+ {
274
+ "name": "::part(alpha-slider)",
275
+ "description": "The alpha slider (`alpha`)"
276
+ },
277
+ {
278
+ "name": "::part(comparison)",
279
+ "description": "The strip of the original colour beside the new one, when the panel opened on a colour"
280
+ },
281
+ {
282
+ "name": "::part(original-color)",
283
+ "description": "The colour the panel opened on; a click restores it"
284
+ },
285
+ {
286
+ "name": "::part(new-color)",
287
+ "description": "The colour the panel holds now"
288
+ },
289
+ {
290
+ "name": "::part(notation-switch)",
291
+ "description": "The HEX | RGB | OKLCH row choosing the channel editor"
292
+ },
293
+ {
294
+ "name": "::part(notation)",
295
+ "description": "One button of the notation switch"
296
+ },
297
+ {
298
+ "name": "::part(channels)",
299
+ "description": "The channel editor: the inputs of one notation"
300
+ },
301
+ { "name": "::part(channel)", "description": "One channel input" },
302
+ { "name": "::part(swatches)", "description": "The list of swatches" },
303
+ { "name": "::part(swatch)", "description": "One swatch" },
304
+ {
305
+ "name": "::part(actions)",
306
+ "description": "The row under the panel body in the fullscreen panel (narrow viewports)"
307
+ },
308
+ {
309
+ "name": "::part(done)",
310
+ "description": "The Done button of the fullscreen panel (narrow viewports): commits what the panel holds and closes"
311
+ },
237
312
  {
238
313
  "name": "::part(root)",
239
314
  "description": "The `<svg>` element rendering the CSC logo"
@@ -409,6 +484,29 @@
409
484
  "name": "::part(mark)",
410
485
  "description": "The check glyph inside a row indicator; draws with `currentColor`"
411
486
  },
487
+ {
488
+ "name": "::part(root)",
489
+ "description": "The field: label, drop zone, message line and file list. The whole of it takes a drop"
490
+ },
491
+ { "name": "::part(label)", "description": "The label above the drop zone" },
492
+ {
493
+ "name": "::part(drop-zone)",
494
+ "description": "The dashed drop zone — the large button, or the `compact` row"
495
+ },
496
+ {
497
+ "name": "::part(message)",
498
+ "description": "The hint/error message area under the drop zone (always reserved unless `hide-details`)"
499
+ },
500
+ {
501
+ "name": "::part(list)",
502
+ "description": "The list of file entries and rejected files"
503
+ },
504
+ { "name": "::part(entry)", "description": "One file entry's row" },
505
+ { "name": "::part(rejected)", "description": "One rejected file's row" },
506
+ {
507
+ "name": "::part(progress)",
508
+ "description": "The progress bar along an uploading row's bottom edge"
509
+ },
412
510
  {
413
511
  "name": "::part(root)",
414
512
  "description": "The `<svg>` element rendering the icon"