@cscfi/csc-ui 4.0.0-alpha.26 → 4.0.0-alpha.27

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,141 @@
1
+ A date field that takes a typed date, or opens a calendar panel for picking one, or a start and end date under `range`.
2
+
3
+ ## Value
4
+
5
+ The value is a calendar date as an ISO `YYYY-MM-DD` string — `'2026-09-28'` —
6
+ or `null` when the field is empty. It carries no time and no timezone, so it
7
+ round-trips through attributes, JSON and forms unchanged, and whatever the
8
+ displayed `format`, the value keeps this one shape. Bind it with `v-model`, or
9
+ listen for `change`:
10
+
11
+ ```vue
12
+ <c-date-picker v-model="date" label="Start date" />
13
+ ```
14
+
15
+ Under `range` the value becomes `{ start, end }`. Picking in the calendar
16
+ always yields a complete range; typing can commit one end before the other, so
17
+ either end may be `null` — `{ start: '2026-09-01', end: null }` — and a range
18
+ with neither end is `null`.
19
+
20
+ ## Typing
21
+
22
+ The field is typeable first: clicking into it or focusing it never opens the
23
+ calendar. Text is read when the user presses Enter or leaves the input, never
24
+ per keystroke. The `format` prop sets how dates are shown and read — a pattern
25
+ of the tokens `d`, `dd`, `M`, `MM` and `yyyy` with any separators, `dd.MM.yyyy`
26
+ by default. Reading is lenient: a day or a month may have one or two digits
27
+ whatever the token, and any of `.`, `/`, `-` or a space separates the parts,
28
+ so `1.9.2026` and `1/9/2026` both commit as `01.09.2026` under the default. The
29
+ year needs all four digits. The format is an app default, so an app can set it
30
+ once with `applyDefaults({ 'c-date-picker': { format: 'yyyy-MM-dd' } })`.
31
+
32
+ Typing follows the format as it goes: the separators appear on their own
33
+ (`01012031` shows `01.01.2031`), a day or month closes early when a separator
34
+ is typed or when its first digit can start no two-digit value (`4` for a day,
35
+ `2` for a month), any of `.`, `/`, `-` or a space typed in place of a
36
+ separator shows as the format's own, and other characters are dropped. Pasted
37
+ text is kept as it is and read when committed.
38
+
39
+ Text that names no date that can be picked — `31.02.2026`, a disabled date, a
40
+ date outside `min` and `max` — is **bad input**: the text stays as the user
41
+ typed it, the value becomes `null`, and the host exposes the `bad-input` custom
42
+ state and a read-only `badInput` property. The component never shows an error
43
+ of its own; deciding whether bad input is an error, and saying so, is the
44
+ consumer's validation:
45
+
46
+ ```vue
47
+ <c-date-picker
48
+ v-model="date"
49
+ :error-message="error"
50
+ :valid="!error"
51
+ label="Start date"
52
+ @change:text="
53
+ error = $event.target.badInput ? 'Enter a date as dd.mm.yyyy' : ''
54
+ "
55
+ />
56
+ ```
57
+
58
+ Every commit of typed text fires `change:text` with the text as typed
59
+ (`{ start, end }` under `range`), whether or not it changed the value — the
60
+ moment to read `badInput`, as above.
61
+
62
+ ## The calendar
63
+
64
+ The calendar button at the field's trailing edge, or Alt+ArrowDown in the
65
+ input, opens the calendar panel. It is a dialog: focus moves onto the selected
66
+ day, else today, else the nearest day that can be picked, and Tab cycles
67
+ through the month and year controls and the grid until the panel closes.
68
+ Picking a day commits it and closes the panel; Escape closes it without a
69
+ change. Focus returns to the input either way.
70
+
71
+ | Key | In the day grid |
72
+ | ----------------------- | ------------------------------------- |
73
+ | ArrowLeft / ArrowRight | Previous / next day |
74
+ | ArrowUp / ArrowDown | Same day of the previous / next week |
75
+ | Home / End | First / last day of the week |
76
+ | PageUp / PageDown | Same day of the previous / next month |
77
+ | Shift+PageUp / PageDown | Same day of the previous / next year |
78
+ | Enter / Space | Pick the day |
79
+
80
+ The month and year buttons in the header swap the grid for a list of months
81
+ or years; picking one returns to the grid. The year list reaches a hundred
82
+ years either side of today unless `min` and `max` narrow it. The displayed
83
+ month is announced to the consumer as `change:month` (`'YYYY-MM'`) whenever it
84
+ changes and when the panel opens.
85
+
86
+ The week starts on Monday; set `first-day-of-week` to another day, numbered
87
+ like `Date.getDay()` (`0` for Sunday). `show-week-numbers` adds ISO 8601 week
88
+ numbers beside the rows. With a week start other than Monday a row spans two
89
+ ISO weeks and shows the one holding most of its days, so a week split across
90
+ two months carries the same number in both.
91
+
92
+ ## Ranges
93
+
94
+ With `range` the field holds two inputs, the start and the end, in one field
95
+ box. In the calendar the first day picked is only pending — it is shown and
96
+ announced, the band follows the pointer or the focused day, and nothing is
97
+ emitted — until the second pick completes the range and closes the panel.
98
+ Dismissing the panel in between discards the pending day. Picking the end
99
+ before the start swaps them, and so does typing a start later than the end.
100
+
101
+ ## Disabling dates
102
+
103
+ Three rules decide which dates cannot be picked; a date any of them rules out
104
+ is disabled:
105
+
106
+ - `min` and `max` — ISO dates bounding the calendar itself: the arrows and the
107
+ keyboard stop there.
108
+ - `disabled-dates` — a list of ISO dates and inclusive `{ start, end }` spans.
109
+ - `is-date-disabled` — a predicate receiving an ISO date, for rules such as
110
+ "no weekends".
111
+
112
+ The list and the predicate have no attribute form, so bind them as DOM
113
+ properties. A disabled day can still be focused in the grid — the arrows keep
114
+ their meaning — and is announced as unavailable, but it cannot be picked. A
115
+ range may span disabled days: only its start and end must be enabled.
116
+
117
+ Availability that comes from a server can follow the calendar: load the
118
+ disabled dates of the month `change:month` names and assign `disabled-dates`
119
+ again.
120
+
121
+ ## Texts
122
+
123
+ Month and weekday names and each day's accessible name come from `texts` when
124
+ given, then from the browser's `Intl` data for the page's `lang`, then from
125
+ the English built-ins — so a page with `<html lang="fi">` gets Finnish names
126
+ without any configuration. The labels of the buttons and the range inputs are
127
+ English unless `texts` replaces them. Weekday arrays are indexed like
128
+ `Date.getDay()`, Sunday first. Set them app-wide with
129
+ `applyDefaults({ 'c-date-picker': { texts } })`.
130
+
131
+ ## Narrow viewports
132
+
133
+ On a viewport narrower than 760px the calendar opens as a **fullscreen
134
+ panel**: a heading row with the field's `label` and a close button above the
135
+ calendar. The field stays typeable at every width.
136
+
137
+ ## Native date input
138
+
139
+ `c-text-field type="date"` remains the browser's own date input — no custom
140
+ calendar, the browser's format, and no ranges or disabled dates. Reach for
141
+ `c-date-picker` when the format, the calendar's look or those features matter.
@@ -0,0 +1,82 @@
1
+ A field for a number — an integer, or one with decimals — shown with thousands separators as it is typed.
2
+
3
+ ## Value
4
+
5
+ The value is a number, or `null` while the field holds no digit. What the
6
+ field shows is grouped text — `1 234 567,89` — but the value is always the
7
+ plain number (`1234567.89`), so it needs no parsing. Bind it with `v-model`,
8
+ or listen for `change`:
9
+
10
+ ```vue
11
+ <c-number-field v-model="amount" label="Amount" />
12
+ ```
13
+
14
+ The value follows the text on every keystroke: typing `1234,` gives `1234`,
15
+ a lone `-` gives `null`. Only typing emits; setting `value` shows the number
16
+ without emitting it.
17
+
18
+ Unlike `c-text-field type="number"`, the native number input, the field shows
19
+ separators, never shows spin buttons, and does not change the number on a
20
+ scroll or an arrow key.
21
+
22
+ ## Separators
23
+
24
+ The thousands and decimal separators follow the page's `lang`: a space and
25
+ `,` under `lang="fi"`, `,` and `.` under `lang="en"`. Set `group-separator`
26
+ and `decimal-separator` to fix them for one field, or for the whole app with
27
+ `applyDefaults({ 'c-number-field': { groupSeparator: ' ', decimalSeparator: ',' } })`.
28
+
29
+ The field inserts the group separators itself, and typed or pasted ones are
30
+ ignored. Either `.` or `,` typed is read as the decimal separator — unless
31
+ it is the group separator — so the decimal key of any keyboard works. A
32
+ pasted `1,234.56` or `1.234,56` reads as `1234.56` either way.
33
+
34
+ ## Decimals
35
+
36
+ `decimals` is the most fraction digits the field takes. By default it is
37
+ `0`, an integer field that ignores the decimal key:
38
+
39
+ ```vue
40
+ <c-number-field
41
+ v-model="price"
42
+ :decimals="2"
43
+ fixed-decimals
44
+ label="Price"
45
+ min="0"
46
+ >
47
+ <span slot="post">€</span>
48
+ </c-number-field>
49
+ ```
50
+
51
+ Typing never pads the fraction. With `fixed-decimals` the field pads it to
52
+ exactly `decimals` digits when the user leaves it — `12,5` shows as `12,50` —
53
+ while the value stays `12.5`. A value set with more fraction digits than
54
+ `decimals` is shown rounded.
55
+
56
+ The integer part takes up to 15 digits, the most a JavaScript number holds
57
+ exactly.
58
+
59
+ ## Range
60
+
61
+ `min` and `max` never change what the user typed. A number outside them is
62
+ kept and emitted, and the host exposes the `out-of-range` custom state and a
63
+ read-only `outOfRange` property. The field shows no error of its own:
64
+
65
+ ```vue
66
+ <c-number-field
67
+ v-model="count"
68
+ :error-message="error"
69
+ :valid="!error"
70
+ label="Participants"
71
+ max="50"
72
+ min="1"
73
+ @change="error = $event.target.outOfRange ? 'Enter 1 to 50' : ''"
74
+ />
75
+ ```
76
+
77
+ With `min` at `0` or above, the minus key is ignored. Such a field also asks
78
+ for the numeric keyboard on a phone (a decimal one when `decimals` is set);
79
+ a field that takes negative numbers keeps the regular keyboard, because
80
+ numeric keyboards on iOS have no minus key.
81
+
82
+ Use the `pre` and `post` slots for a currency sign or a unit.
@@ -0,0 +1,106 @@
1
+ A text field for a single line of text, or several lines under `rows`, with a label, a hint and an error message.
2
+
3
+ ## Value
4
+
5
+ The value is the text in the field as a string. Bind it with `v-model`, or
6
+ listen for `update:value`:
7
+
8
+ ```vue
9
+ <c-text-field v-model="name" label="Name" />
10
+ ```
11
+
12
+ `type` maps to the native input type: `password` adds a toggle that reveals
13
+ the text, and `number` honours `min`, `max` and `step`. Setting `rows` above
14
+ `1` renders a textarea.
15
+
16
+ ## Input mask
17
+
18
+ `mask` makes the typed text follow a pattern, such as a phone number, a postal
19
+ code or an account number. In the pattern, `#` stands for a digit, `A` for a
20
+ letter and `*` for a letter or a digit; every other character is a literal the
21
+ field inserts itself, and `\` makes the next character a literal (`\#`).
22
+
23
+ ```vue
24
+ <c-text-field v-model="phone" label="Phone" mask="+358 ## ### ####" />
25
+ ```
26
+
27
+ | Token | Takes |
28
+ | ----- | ----------------- |
29
+ | `#` | A digit |
30
+ | `A` | A letter |
31
+ | `*` | A letter or digit |
32
+ | `\x` | `x` as a literal |
33
+ | `[…]` | Optional section |
34
+
35
+ Characters a token does not take are dropped as they are typed or pasted.
36
+ A literal appears only once the next character arrives, so typing `40` into
37
+ the mask above shows `+358 40`, an empty field stays empty, and Backspace
38
+ never gets stuck on a separator. Typing or pasting the literals yourself
39
+ works too: `+358401234567` fills the field the same way. A mask of digits
40
+ only brings up the numeric keyboard.
41
+
42
+ While the user types, a faint **mask guide** behind the text shows the rest
43
+ of the pattern — `+358 __ ___ ____` in an empty field, `_ ___ ____` once
44
+ `4` is typed — so it is clear what is still asked for. It is never part of
45
+ the value and screen readers do not announce it; describe the format in the
46
+ `hint` for them. It shows wherever a placeholder would: while the field is
47
+ focused or holds text, and always with `label-on-top` or without a `label`.
48
+ A `placeholder` replaces the guide — set one to write your own example
49
+ (`placeholder="+358 40 123 4567"`); the `mask-guide` part styles the guide.
50
+
51
+ ### Optional sections
52
+
53
+ A pattern may end in **optional sections** in square brackets for formats of
54
+ varying length. Every token inside may be left unfilled, one by one, and the
55
+ literals inside appear only when a character after them is typed:
56
+
57
+ ```vue
58
+ <!-- 5 to 12 digits after the country code -->
59
+ <c-text-field v-model="phone" label="Phone" mask="+358 #####[#######]" />
60
+
61
+ <!-- A ZIP code with an optional -#### -->
62
+ <c-text-field v-model="zip" label="ZIP code" mask="#####[-####]" />
63
+ ```
64
+
65
+ The field is complete once every token outside the sections is filled, and
66
+ the guide draws only those: `+358 _____` in the empty phone field, nothing
67
+ once five digits are in. A section may stop part-way (`12345-67` is complete),
68
+ so check the length of `unmaskedValue` where an all-or-nothing part matters.
69
+
70
+ Sections come last — after the first one only further sections may follow
71
+ (`## ###[ ####][###]`) — and do not nest. A mask that breaks these rules is
72
+ ignored with a console warning, and the field takes any text. Write `\[` and
73
+ `\]` for literal brackets.
74
+
75
+ A phone mask with fixed groups fits only some numbers: Finnish numbers group
76
+ differently by area code (`+358 9 …`, `+358 40 …`), so an ungrouped run
77
+ like `+358 #####[#######]` suits them all.
78
+
79
+ The value is the text as shown, literals included — `'+358 40 123 4567'`.
80
+ The read-only `unmaskedValue` property holds only the characters that fill
81
+ the tokens (`'401234567'`). Give the field masked values: a value set from
82
+ code is shown through the mask, but the field does not rewrite or emit it.
83
+
84
+ Text that leaves some token unfilled is kept as typed. The read-only
85
+ `maskComplete` property tells whether every token is filled, and a field
86
+ holding such partial text exposes the `incomplete` custom state. The field
87
+ shows no error of its own; whether an incomplete value is an error is the
88
+ consumer's validation:
89
+
90
+ ```vue
91
+ <c-text-field
92
+ v-model="phone"
93
+ :error-message="error"
94
+ :valid="!error"
95
+ label="Phone"
96
+ mask="+358 ## ### ####"
97
+ @change="
98
+ error = $event.target.matches(':state(incomplete)')
99
+ ? 'Enter the whole number'
100
+ : ''
101
+ "
102
+ />
103
+ ```
104
+
105
+ A mask applies to a single-line field of type `text`, `tel` or `search`;
106
+ other types (and a textarea) ignore it.
@@ -878,6 +878,7 @@ c-card-title:not(:defined),
878
878
  c-checkbox:not(:defined),
879
879
  c-csc-logo:not(:defined),
880
880
  c-data-table:not(:defined),
881
+ c-date-picker:not(:defined),
881
882
  c-divider:not(:defined),
882
883
  c-dropdown:not(:defined),
883
884
  c-icon:not(:defined),
@@ -901,6 +902,7 @@ c-menu-label:not(:defined),
901
902
  c-message:not(:defined),
902
903
  c-modal:not(:defined),
903
904
  c-navigation-button:not(:defined),
905
+ c-number-field:not(:defined),
904
906
  c-option:not(:defined),
905
907
  c-option-value:not(:defined),
906
908
  c-otp-input:not(:defined),
@@ -233,6 +233,91 @@
233
233
  "name": "::part(pagination)",
234
234
  "description": "The pagination bar below the table"
235
235
  },
236
+ {
237
+ "name": "::part(input)",
238
+ "description": "The text input; under `range` both the start and the end input"
239
+ },
240
+ {
241
+ "name": "::part(separator)",
242
+ "description": "The dash between the start and end inputs under `range`"
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 holding the header and the calendar body"
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(header)",
266
+ "description": "The row of month and year controls above the calendar body"
267
+ },
268
+ {
269
+ "name": "::part(previous-month)",
270
+ "description": "The arrow to the previous month"
271
+ },
272
+ {
273
+ "name": "::part(next-month)",
274
+ "description": "The arrow to the next month"
275
+ },
276
+ {
277
+ "name": "::part(month-button)",
278
+ "description": "The button showing the displayed month that opens the month list"
279
+ },
280
+ {
281
+ "name": "::part(previous-year)",
282
+ "description": "The arrow to the same month a year earlier"
283
+ },
284
+ {
285
+ "name": "::part(next-year)",
286
+ "description": "The arrow to the same month a year later"
287
+ },
288
+ {
289
+ "name": "::part(year-button)",
290
+ "description": "The button showing the displayed year that opens the year list"
291
+ },
292
+ {
293
+ "name": "::part(grid)",
294
+ "description": "The day grid of the displayed month"
295
+ },
296
+ {
297
+ "name": "::part(weekday)",
298
+ "description": "A weekday column head in the grid"
299
+ },
300
+ {
301
+ "name": "::part(week-number)",
302
+ "description": "An ISO week number beside a grid row (`show-week-numbers`)"
303
+ },
304
+ { "name": "::part(cell)", "description": "One day's cell in the grid" },
305
+ {
306
+ "name": "::part(day)",
307
+ "description": "The circle showing a day's number inside its cell"
308
+ },
309
+ {
310
+ "name": "::part(range-band)",
311
+ "description": "The strip joining a range's days behind their circles"
312
+ },
313
+ {
314
+ "name": "::part(list)",
315
+ "description": "The month or year list swapped in for the grid"
316
+ },
317
+ {
318
+ "name": "::part(option)",
319
+ "description": "One month or year in the list"
320
+ },
236
321
  {
237
322
  "name": "::part(root)",
238
323
  "description": "The separator line element itself"
@@ -432,6 +517,7 @@
432
517
  "name": "::part(root)",
433
518
  "description": "The inner c-icon-button carrying the menu icon"
434
519
  },
520
+ { "name": "::part(input)", "description": "The text input" },
435
521
  {
436
522
  "name": "::part(root)",
437
523
  "description": "The wrapper laying out the label, the digit inputs and the message"
@@ -738,6 +824,10 @@
738
824
  "name": "::part(items)",
739
825
  "description": "The wrapping row that lays out the slotted tags"
740
826
  },
827
+ {
828
+ "name": "::part(mask-guide)",
829
+ "description": "The faint rest of the input mask, shown behind the typed text"
830
+ },
741
831
  {
742
832
  "name": "::part(root)",
743
833
  "description": "The toast's outer box: the inverted-surface pill carrying the shadow"