@cscfi/csc-ui 4.0.0-alpha.26 → 4.0.0-alpha.28
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/dist/csc-ui.js +9514 -7086
- package/dist/custom-elements.json +6934 -4840
- package/dist/docs/c-date-picker/usage.md +190 -0
- package/dist/docs/c-number-field/usage.md +82 -0
- package/dist/docs/c-text-field/usage.md +106 -0
- package/dist/docs/c-time-picker/usage.md +143 -0
- package/dist/styles/css/tailwind-theme.css +1 -0
- package/dist/styles/css/tokens.css +10 -0
- package/dist/vscode.css-custom-data.json +140 -0
- package/dist/vscode.html-custom-data.json +302 -1
- package/dist/web-types.json +1132 -130
- package/dist-types/components/c-date-picker/CDatePicker.vue.d.ts +268 -0
- package/dist-types/components/c-date-picker/dates.d.ts +119 -0
- package/dist-types/components/c-number-field/CNumberField.vue.d.ts +153 -0
- package/dist-types/components/c-number-field/numbers.d.ts +42 -0
- package/dist-types/components/c-slider/CSlider.vue.d.ts +2 -2
- package/dist-types/components/c-text-field/CTextField.vue.d.ts +12 -2
- package/dist-types/components/c-time-picker/CTimePicker.vue.d.ts +199 -0
- package/dist-types/components/c-time-picker/times.d.ts +82 -0
- package/dist-types/index.d.ts +3 -0
- package/dist-types/shared/TypedField.vue.d.ts +40 -0
- package/dist-types/shared/inputMask.d.ts +106 -0
- package/dist-types/shared/useAnchoredPanel.d.ts +5 -2
- package/dist-types/shared/useTypedField.d.ts +103 -0
- package/dist-types/tag-name-map.d.ts +300 -2
- package/package.json +1 -1
|
@@ -0,0 +1,190 @@
|
|
|
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
|
+
## Months
|
|
122
|
+
|
|
123
|
+
With `type="month"` the field picks a year and a month instead of a day. The
|
|
124
|
+
value is an ISO `YYYY-MM` string — `'2026-03'` — or `{ start, end }` of them
|
|
125
|
+
under `range`, like the native `<input type="month">`:
|
|
126
|
+
|
|
127
|
+
```vue
|
|
128
|
+
<c-date-picker v-model="billing" label="Billing month" type="month" />
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
The format is the `format` with its day left out, so one app default serves
|
|
132
|
+
both kinds of field: `dd.MM.yyyy` shows months as `MM.yyyy`, `yyyy-MM-dd` as
|
|
133
|
+
`yyyy-MM`. A `format` with no day, such as `MM/yyyy`, is used as given.
|
|
134
|
+
Typing is as lenient as for dates: `3.2026` and `032026` both commit as
|
|
135
|
+
`03.2026`. A full date bound as the value is shown as its month and emits
|
|
136
|
+
nothing; the next pick or commit emits the month.
|
|
137
|
+
|
|
138
|
+
The panel asks for the month first, then the year. It opens on the twelve
|
|
139
|
+
months under a "Month" label, with the selected month marked and focused.
|
|
140
|
+
Picking one collapses it to a summary row and the years unroll beneath it,
|
|
141
|
+
focused on the selected year — else this year, else the nearest year that can
|
|
142
|
+
be picked. Picking a year commits the month and closes the panel; pressing the
|
|
143
|
+
summary row goes back to the months. Both lists take the arrows, Home and End,
|
|
144
|
+
and Enter or Space to pick.
|
|
145
|
+
|
|
146
|
+
Under `range` the steps run twice, labelled "Start month", "Start year", "End
|
|
147
|
+
month" and "End year". The finished start shows as a summary row and is only
|
|
148
|
+
pending, as in the day grid: nothing is emitted until the end's year completes
|
|
149
|
+
the range, a range picked backwards is swapped, and dismissing the panel
|
|
150
|
+
discards the start.
|
|
151
|
+
|
|
152
|
+
`min` and `max` may be months or full dates; a full date counts by its month,
|
|
153
|
+
so `min="2026-03-15"` still allows March. A month is disabled only when every
|
|
154
|
+
one of its days is — by `min` and `max`, `disabled-dates` or
|
|
155
|
+
`is-date-disabled` — so a "no weekends" predicate disables no month, and a
|
|
156
|
+
span covering all of July disables July. In the month list a month is disabled
|
|
157
|
+
when no allowed year takes it; in the year list a year is disabled when the
|
|
158
|
+
picked month is disabled in it, so no pick leads to an empty list. The
|
|
159
|
+
predicate is asked about each day until one is enabled, so in most months it
|
|
160
|
+
runs once; one that disables nearly every day is asked many times when the
|
|
161
|
+
months open.
|
|
162
|
+
|
|
163
|
+
`change:month` names the displayed month of the day grid, so it is never
|
|
164
|
+
fired in month mode.
|
|
165
|
+
|
|
166
|
+
## Texts
|
|
167
|
+
|
|
168
|
+
Month and weekday names and each day's accessible name come from `texts` when
|
|
169
|
+
given, then from the browser's `Intl` data for the page's `lang`, then from
|
|
170
|
+
the English built-ins — so a page with `<html lang="fi">` gets Finnish names
|
|
171
|
+
without any configuration. The labels of the buttons and the range inputs are
|
|
172
|
+
English unless `texts` replaces them. Weekday arrays are indexed like
|
|
173
|
+
`Date.getDay()`, Sunday first. Set them app-wide with
|
|
174
|
+
`applyDefaults({ 'c-date-picker': { texts } })`.
|
|
175
|
+
|
|
176
|
+
## Narrow viewports
|
|
177
|
+
|
|
178
|
+
On a viewport narrower than 760px the calendar opens as a **fullscreen
|
|
179
|
+
panel**: a heading row with the field's `label` and a close button above the
|
|
180
|
+
calendar. The field stays typeable at every width.
|
|
181
|
+
|
|
182
|
+
## Native date input
|
|
183
|
+
|
|
184
|
+
`c-text-field type="date"` remains the browser's own date input — no custom
|
|
185
|
+
calendar, the browser's format, and no ranges or disabled dates. Reach for
|
|
186
|
+
`c-date-picker` when the format, the calendar's look or those features matter.
|
|
187
|
+
`c-text-field` has no month type: for a year and a month, use
|
|
188
|
+
`type="month"` here.
|
|
189
|
+
|
|
190
|
+
`c-time-picker` is the same typeable field for times of day.
|
|
@@ -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.
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
A time field that takes a typed time, or opens hour and minute columns for picking one, or a start and end time under `range`.
|
|
2
|
+
|
|
3
|
+
## Value
|
|
4
|
+
|
|
5
|
+
The value is a time of day as an ISO `HH:mm` string on a 24-hour clock —
|
|
6
|
+
`'14:05'` — or `null` when the field is empty. It carries no seconds, no date
|
|
7
|
+
and no timezone, and whatever the displayed `format` it keeps this one shape:
|
|
8
|
+
a field showing `14.05` or `2:05 PM` holds `'14:05'`. Bind it with `v-model`,
|
|
9
|
+
or listen for `change`:
|
|
10
|
+
|
|
11
|
+
```vue
|
|
12
|
+
<c-time-picker v-model="time" label="Start time" />
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Under `range` the value becomes `{ start, end }`. Either end may be `null`
|
|
16
|
+
while only one is set — `{ start: '09:00', end: null }` — and a range with
|
|
17
|
+
neither end is `null`.
|
|
18
|
+
|
|
19
|
+
## Typing
|
|
20
|
+
|
|
21
|
+
The field is typeable first: clicking into it or focusing it never opens the
|
|
22
|
+
columns. Text is read when the user presses Enter or leaves the input, never
|
|
23
|
+
per keystroke. The `format` prop sets how times are shown and read — a pattern
|
|
24
|
+
of the tokens `H` or `HH` (a 24-hour hour), `h` or `hh` (a 12-hour hour, which
|
|
25
|
+
needs the period `a`) and `mm`, with any separators. The default is `HH.mm`;
|
|
26
|
+
`HH:mm` and `h:mm a` are common alternatives. The format is an app default, so
|
|
27
|
+
an app can set it once with `applyDefaults({ 'c-time-picker': { format: 'HH:mm' } })`.
|
|
28
|
+
|
|
29
|
+
Typing follows the format as it goes: the separator appears on its own (`930`
|
|
30
|
+
shows `9.30`), an hour closes early when its first digit can start no
|
|
31
|
+
two-digit hour, any of `.`, `:` or a space typed in place of the separator
|
|
32
|
+
shows as the format's own, and in a 12-hour format a typed `a` or `p` fills in
|
|
33
|
+
the whole AM or PM text. Reading is lenient:
|
|
34
|
+
|
|
35
|
+
| Typed | Reads as |
|
|
36
|
+
| ------- | -------------------------------------------- |
|
|
37
|
+
| `9` | `09:00` — a bare hour is on the hour |
|
|
38
|
+
| `930` | `09:30` — three or four digits split |
|
|
39
|
+
| `9.3` | `09:03` — one minute digit is that minute |
|
|
40
|
+
| `2 pm` | `14:00` — a period makes the hour 12-hour |
|
|
41
|
+
| `14.00` | `14:00`, also in a 12-hour field (`2:00 PM`) |
|
|
42
|
+
|
|
43
|
+
In a 12-hour field an hour typed without a period reads as AM.
|
|
44
|
+
|
|
45
|
+
Text that names no time that can be picked — `25.00`, a time outside `min`
|
|
46
|
+
and `max` — is **bad input**: the text stays as the user typed it, the value
|
|
47
|
+
becomes `null`, and the host exposes the `bad-input` custom state and a
|
|
48
|
+
read-only `badInput` property. The component never shows an error of its own;
|
|
49
|
+
deciding whether bad input is an error, and saying so, is the consumer's
|
|
50
|
+
validation:
|
|
51
|
+
|
|
52
|
+
```vue
|
|
53
|
+
<c-time-picker
|
|
54
|
+
v-model="time"
|
|
55
|
+
:error-message="error"
|
|
56
|
+
:valid="!error"
|
|
57
|
+
label="Start time"
|
|
58
|
+
@change:text="error = $event.target.badInput ? 'Enter a time as hh.mm' : ''"
|
|
59
|
+
/>
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Every commit of typed text fires `change:text` with the text as typed
|
|
63
|
+
(`{ start, end }` under `range`), whether or not it changed the value.
|
|
64
|
+
|
|
65
|
+
## The columns
|
|
66
|
+
|
|
67
|
+
The clock button at the field's trailing edge, or Alt+ArrowDown in the input,
|
|
68
|
+
opens the columns: hours and minutes side by side, and an AM/PM column in a
|
|
69
|
+
12-hour format. The panel is a dialog: focus moves onto the hour column —
|
|
70
|
+
the value's hour, or the current hour when the field is empty — and Tab
|
|
71
|
+
cycles through the columns until the panel closes.
|
|
72
|
+
|
|
73
|
+
Every pick commits at once and the panel stays open, so the hour can be fixed
|
|
74
|
+
after the minutes are picked. The selected row rests at the top of its column:
|
|
75
|
+
it opens there and returns there after each pick, and so does a minute a pick
|
|
76
|
+
fills in. Scrolling a column only looks; it never picks. Picking into an empty field fills in the rest:
|
|
77
|
+
minute `00`, and the hour the hour column rests on. Moving in a column is
|
|
78
|
+
picking — each arrow key press commits, so a `change` handler doing network
|
|
79
|
+
work should debounce.
|
|
80
|
+
|
|
81
|
+
| Key | In a column |
|
|
82
|
+
| ------------------- | ------------------------------------------ |
|
|
83
|
+
| ArrowUp / ArrowDown | Previous / next row |
|
|
84
|
+
| Home / End | First / last row |
|
|
85
|
+
| PageUp / PageDown | Five rows up / down |
|
|
86
|
+
| Space | Pick the focused row |
|
|
87
|
+
| Enter | Pick the focused row and close |
|
|
88
|
+
| Escape | Close; what was picked stays |
|
|
89
|
+
| Tab | Next column (the end switch under `range`) |
|
|
90
|
+
|
|
91
|
+
Focus returns to the input when the panel closes.
|
|
92
|
+
|
|
93
|
+
## Minute step
|
|
94
|
+
|
|
95
|
+
`minute-step` spaces the minute column's rows: `15` lists `00`, `15`, `30`
|
|
96
|
+
and `45`. It only shapes the column — a typed `14.07` commits as `14:07` and
|
|
97
|
+
shows as an extra row between `00` and `15`. Require a step with your own
|
|
98
|
+
validation if it matters.
|
|
99
|
+
|
|
100
|
+
## Min and max
|
|
101
|
+
|
|
102
|
+
`min` and `max` are ISO `HH:mm` times. Rows outside them are disabled — an
|
|
103
|
+
hour only when none of its minutes fit — and a typed time outside them is bad
|
|
104
|
+
input. A pick never leaves them: picking hour 9 at `10:15` with `min="09:30"`
|
|
105
|
+
commits `09:30`. A `min` later than `max` is not a range across midnight; it
|
|
106
|
+
is ignored with a console warning.
|
|
107
|
+
|
|
108
|
+
## Ranges
|
|
109
|
+
|
|
110
|
+
With `range` the field holds two inputs, the start and the end, in one field
|
|
111
|
+
box, and the panel shows a Start | End switch above the columns. It opens on
|
|
112
|
+
the end last typed in; each end commits on its own as it is picked.
|
|
113
|
+
|
|
114
|
+
An end earlier than the start is an **overnight range** — `22:00` to `06:00`
|
|
115
|
+
spans midnight — and is kept as it is, never swapped or flagged. Where a range
|
|
116
|
+
must stay within one day, check it in your validation; ISO times compare
|
|
117
|
+
correctly as strings:
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
const sameDay =
|
|
121
|
+
!value || !value.start || !value.end || value.start <= value.end;
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Texts
|
|
125
|
+
|
|
126
|
+
The AM and PM texts come from `texts` when given, then from the browser's
|
|
127
|
+
`Intl` data for the page's `lang`, then from the English built-ins — so a page
|
|
128
|
+
with `<html lang="fi">` shows `ap.` and `ip.` without any configuration. The
|
|
129
|
+
button, column and range labels are English unless `texts` replaces them. Set
|
|
130
|
+
them app-wide with `applyDefaults({ 'c-time-picker': { texts } })`.
|
|
131
|
+
|
|
132
|
+
## Narrow viewports
|
|
133
|
+
|
|
134
|
+
On a viewport narrower than 760px the columns open as a **fullscreen panel**:
|
|
135
|
+
a heading row with the field's `label` and a close button above the columns.
|
|
136
|
+
There the selected row rests in the middle of its column instead of the top.
|
|
137
|
+
The field stays typeable at every width.
|
|
138
|
+
|
|
139
|
+
## Related
|
|
140
|
+
|
|
141
|
+
`c-date-picker` is the same field for calendar dates. `c-text-field
|
|
142
|
+
type="time"` remains the browser's own time input — no columns, the browser's
|
|
143
|
+
format, and no ranges.
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
--color-on-surface: var(--c-on-surface);
|
|
33
33
|
--color-on-surface-muted: var(--c-on-surface-muted);
|
|
34
34
|
--color-on-surface-faint: var(--c-on-surface-faint);
|
|
35
|
+
--color-on-surface-disabled: var(--c-on-surface-disabled);
|
|
35
36
|
--color-on-surface-sunken: var(--c-on-surface-sunken);
|
|
36
37
|
--color-border: var(--c-border);
|
|
37
38
|
--color-border-strong: var(--c-border-strong);
|
|
@@ -170,6 +170,7 @@
|
|
|
170
170
|
--c-on-surface: var(--c-primary-900);
|
|
171
171
|
--c-on-surface-muted: var(--c-tertiary-500);
|
|
172
172
|
--c-on-surface-faint: var(--c-tertiary-500);
|
|
173
|
+
--c-on-surface-disabled: var(--c-tertiary-300);
|
|
173
174
|
--c-on-surface-sunken: var(--c-primary-700);
|
|
174
175
|
--c-border: var(--c-tertiary-200);
|
|
175
176
|
--c-border-strong: var(--c-tertiary-600);
|
|
@@ -268,6 +269,7 @@
|
|
|
268
269
|
--c-on-surface: var(--c-slate-100);
|
|
269
270
|
--c-on-surface-muted: var(--c-slate-300);
|
|
270
271
|
--c-on-surface-faint: var(--c-slate-400);
|
|
272
|
+
--c-on-surface-disabled: var(--c-slate-500);
|
|
271
273
|
--c-on-surface-sunken: var(--c-slate-100);
|
|
272
274
|
--c-border: var(--c-slate-700);
|
|
273
275
|
--c-border-strong: var(--c-slate-400);
|
|
@@ -367,6 +369,7 @@
|
|
|
367
369
|
--c-on-surface: var(--c-slate-100);
|
|
368
370
|
--c-on-surface-muted: var(--c-slate-300);
|
|
369
371
|
--c-on-surface-faint: var(--c-slate-400);
|
|
372
|
+
--c-on-surface-disabled: var(--c-slate-500);
|
|
370
373
|
--c-on-surface-sunken: var(--c-slate-100);
|
|
371
374
|
--c-border: var(--c-slate-700);
|
|
372
375
|
--c-border-strong: var(--c-slate-400);
|
|
@@ -472,6 +475,7 @@
|
|
|
472
475
|
--c-on-surface: var(--c-slate-100);
|
|
473
476
|
--c-on-surface-muted: var(--c-slate-300);
|
|
474
477
|
--c-on-surface-faint: var(--c-slate-400);
|
|
478
|
+
--c-on-surface-disabled: var(--c-slate-500);
|
|
475
479
|
--c-on-surface-sunken: var(--c-slate-100);
|
|
476
480
|
--c-border: var(--c-slate-700);
|
|
477
481
|
--c-border-strong: var(--c-slate-400);
|
|
@@ -571,6 +575,7 @@
|
|
|
571
575
|
--c-on-surface: var(--c-primary-900);
|
|
572
576
|
--c-on-surface-muted: var(--c-tertiary-500);
|
|
573
577
|
--c-on-surface-faint: var(--c-tertiary-500);
|
|
578
|
+
--c-on-surface-disabled: var(--c-tertiary-300);
|
|
574
579
|
--c-on-surface-sunken: var(--c-primary-700);
|
|
575
580
|
--c-border: var(--c-tertiary-200);
|
|
576
581
|
--c-border-strong: var(--c-tertiary-600);
|
|
@@ -675,6 +680,7 @@
|
|
|
675
680
|
--c-on-surface: var(--c-primary-900);
|
|
676
681
|
--c-on-surface-muted: var(--c-tertiary-500);
|
|
677
682
|
--c-on-surface-faint: var(--c-tertiary-500);
|
|
683
|
+
--c-on-surface-disabled: var(--c-tertiary-300);
|
|
678
684
|
--c-on-surface-sunken: var(--c-primary-700);
|
|
679
685
|
--c-border: var(--c-tertiary-200);
|
|
680
686
|
--c-border-strong: var(--c-tertiary-600);
|
|
@@ -774,6 +780,7 @@
|
|
|
774
780
|
--c-on-surface: var(--c-slate-100);
|
|
775
781
|
--c-on-surface-muted: var(--c-slate-300);
|
|
776
782
|
--c-on-surface-faint: var(--c-slate-400);
|
|
783
|
+
--c-on-surface-disabled: var(--c-slate-500);
|
|
777
784
|
--c-on-surface-sunken: var(--c-slate-100);
|
|
778
785
|
--c-border: var(--c-slate-700);
|
|
779
786
|
--c-border-strong: var(--c-slate-400);
|
|
@@ -878,6 +885,7 @@ c-card-title:not(:defined),
|
|
|
878
885
|
c-checkbox:not(:defined),
|
|
879
886
|
c-csc-logo:not(:defined),
|
|
880
887
|
c-data-table:not(:defined),
|
|
888
|
+
c-date-picker:not(:defined),
|
|
881
889
|
c-divider:not(:defined),
|
|
882
890
|
c-dropdown:not(:defined),
|
|
883
891
|
c-icon:not(:defined),
|
|
@@ -901,6 +909,7 @@ c-menu-label:not(:defined),
|
|
|
901
909
|
c-message:not(:defined),
|
|
902
910
|
c-modal:not(:defined),
|
|
903
911
|
c-navigation-button:not(:defined),
|
|
912
|
+
c-number-field:not(:defined),
|
|
904
913
|
c-option:not(:defined),
|
|
905
914
|
c-option-value:not(:defined),
|
|
906
915
|
c-otp-input:not(:defined),
|
|
@@ -931,6 +940,7 @@ c-tabs:not(:defined),
|
|
|
931
940
|
c-tag:not(:defined),
|
|
932
941
|
c-tags:not(:defined),
|
|
933
942
|
c-text-field:not(:defined),
|
|
943
|
+
c-time-picker:not(:defined),
|
|
934
944
|
c-toast:not(:defined),
|
|
935
945
|
c-toasts:not(:defined),
|
|
936
946
|
c-toolbar:not(:defined),
|