@lilydesignsystem/angular-time-zone-picker 0.0.0-stage → 0.1.1
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 +111 -2
- package/fesm2022/lilydesignsystem-angular-time-zone-picker.mjs +931 -0
- package/fesm2022/lilydesignsystem-angular-time-zone-picker.mjs.map +1 -0
- package/package.json +45 -3
- package/types/lilydesignsystem-angular-time-zone-picker.d.ts +257 -0
- package/types/lilydesignsystem-angular-time-zone-picker.d.ts.map +1 -0
package/README.md
CHANGED
|
@@ -1,3 +1,112 @@
|
|
|
1
|
-
#
|
|
1
|
+
# TimeZonePicker (Angular helper)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A reusable Angular headless **time zone picker**: an icon button that opens a WAI-ARIA APG listbox of time
|
|
4
|
+
zones, each shown as its UTC offset and its full name (`UTC+05:30 – India Standard Time`), **ordered by offset**
|
|
5
|
+
from west to east. On every change it sets `data-time-zone="{IANA id}"` on a target element (default
|
|
6
|
+
`document.documentElement`), optionally persisting the choice to `localStorage`. Ships no CSS.
|
|
7
|
+
|
|
8
|
+
The value is an IANA zone id (`Asia/Kolkata`), which is what `Intl.DateTimeFormat({ timeZone })` and every
|
|
9
|
+
date library take. The offsets and names are not a table in this package: they are computed with `Intl` for the
|
|
10
|
+
`locale` you pass, on the `date` you pass (default now), so the same zone reads `UTC-05:00 – Eastern Standard
|
|
11
|
+
Time` in January and `UTC-04:00 – Eastern Daylight Time` in July, and `Central European Standard Time` becomes
|
|
12
|
+
`heure normale d’Europe centrale` for `fr`.
|
|
13
|
+
|
|
14
|
+
```js
|
|
15
|
+
// What the app does with the choice:
|
|
16
|
+
new Intl.DateTimeFormat(locale, { timeZone: document.documentElement.dataset.timeZone }).format(
|
|
17
|
+
date,
|
|
18
|
+
);
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { Component } from "@angular/core";
|
|
25
|
+
import { TimeZonePicker } from "@lilydesignsystem/angular-time-zone-picker";
|
|
26
|
+
|
|
27
|
+
@Component({
|
|
28
|
+
selector: "app-example",
|
|
29
|
+
standalone: true,
|
|
30
|
+
imports: [TimeZonePicker],
|
|
31
|
+
template: `<lily-time-zone-picker
|
|
32
|
+
label="Time zone"
|
|
33
|
+
locale="en-GB"
|
|
34
|
+
[(value)]="zone"
|
|
35
|
+
storageKey="lily-time-zone"
|
|
36
|
+
/>`,
|
|
37
|
+
})
|
|
38
|
+
export class Example {
|
|
39
|
+
zone = "";
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Angular idioms: the selector is `lily-time-zone-picker`; inputs are signal inputs (`[(value)]` and `[(open)]` are two-way models), the extra class is `className`, `zoneChange` is the output fired once per applied change, and a projected `<ng-template lilyTimeZonePickerIcon let-args>` replaces the icon (`args.infoFor(args.value)?.offset`).
|
|
44
|
+
|
|
45
|
+
## Props
|
|
46
|
+
|
|
47
|
+
| Prop | Type | Required | Description |
|
|
48
|
+
| -------------- | ---------------------------- | -------- | -------------------------------------------------------------------------------------------------------------- |
|
|
49
|
+
| `label` | `string` | yes | Accessible name for the button and the listbox; also the tooltip text. |
|
|
50
|
+
| `locale` | `string` | yes | BCP 47 tag the zone names are written in. No default: the picker never picks a language for you. |
|
|
51
|
+
| `zones` | `readonly string[]` | no | IANA ids to offer. Default `DEFAULT_ZONES` (55 representative zones). Shown by offset, not in the order given. |
|
|
52
|
+
| `date` | `Date` | no | The moment offsets and names are worked out for. Default: now, read once. |
|
|
53
|
+
| `value` | `string` | no | Selected IANA id. Two-way bindable. |
|
|
54
|
+
| `defaultValue` | `string` | no | Initial zone when nothing else is supplied. |
|
|
55
|
+
| `storageKey` | `string` | no | If set, persist the zone to `localStorage`. |
|
|
56
|
+
| `name` | `string` | no | `name` of the hidden input (default `"time-zone"`). |
|
|
57
|
+
| `target` | `HTMLElement \| null` | no | Element to receive `data-time-zone`. Default `<html>`. |
|
|
58
|
+
| `labelFor` | `(zone: ZoneInfo) => string` | no | Builds an option's text. Default `UTC+01:00 – Central European Standard Time`. |
|
|
59
|
+
| `names` | `ZoneNames` | no | Zone names by IANA id (a name, or `[standard, daylight]`) that win over `Intl`: the CLDR packs, below. |
|
|
60
|
+
| `children` | `Snippet<[ChildArgs]>` | no | Replaces the clock icon. |
|
|
61
|
+
| `onChange` | `(zone: string) => void` | no | Called once after a new zone is applied. |
|
|
62
|
+
| `open` | `boolean` | no | Is the popup open? Bindable. |
|
|
63
|
+
| `onOpenChange` | `(open: boolean) => void` | no | Fires whenever the open state changes. |
|
|
64
|
+
| `disabled` | `boolean` | no | Disables the button. |
|
|
65
|
+
| `className` | `string` | no | Extra CSS class on the root. |
|
|
66
|
+
|
|
67
|
+
The pure functions are exported too: `orderedZones`, `zoneInfo`, `offsetMinutes`, `formatOffset`, `zoneName`,
|
|
68
|
+
`matchZone`, `systemZone`, `defaultLabel`.
|
|
69
|
+
|
|
70
|
+
## Zone names from Unicode CLDR
|
|
71
|
+
|
|
72
|
+
By default the full names come from `Intl`, so they are whatever ICU data the browser or server carries. For the same
|
|
73
|
+
name in every runtime, pass the Unicode CLDR names that `@lilydesignsystem/angular-locale-translations` ships, one pack
|
|
74
|
+
per label-pack locale (all 64), with the pack's own locale tag as the picker's `locale`:
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
import { zoneNamesFrom } from "@lilydesignsystem/angular-locale-translations";
|
|
78
|
+
import fr from "@lilydesignsystem/angular-locale-translations/zone-names/fr-001";
|
|
79
|
+
|
|
80
|
+
// in the component class: names = zoneNamesFrom(fr);
|
|
81
|
+
// in its template:
|
|
82
|
+
// <lily-time-zone-picker label="Fuseau horaire" locale="fr" [names]="names" />
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
A pack names about 425 zones, with the daylight name where a zone has one. A zone CLDR has no name for in that language
|
|
86
|
+
is not in the pack and falls back to `Intl`, never to another language. Cornish, Scots and Wu have no CLDR zone names, so
|
|
87
|
+
their packs are empty. See [spec/zone-names](../spec/zone-names/index.md).
|
|
88
|
+
|
|
89
|
+
## Behaviour
|
|
90
|
+
|
|
91
|
+
- **Order**: by UTC offset ascending (`UTC-11:00` first, `UTC+14:00` last); ties by name (compared in `locale`),
|
|
92
|
+
then by id. An id the runtime does not know is left out; a repeated id appears once.
|
|
93
|
+
- **Initial value**: `value` > stored zone (only if still offered) > `defaultValue` > the reader's own zone when
|
|
94
|
+
listed, or its listed twin (same offset and name: `Europe/Berlin` → `Europe/Paris`) > `UTC` > the first zone.
|
|
95
|
+
- **Date**: offsets are fixed for the picker's `date` (read once when none is given) so an open list never
|
|
96
|
+
re-sorts under the pointer. Pass a `date` to show the offsets for a specific day.
|
|
97
|
+
- SSR-safe: all DOM writes happen inside an effect; the zone list is computed without the DOM.
|
|
98
|
+
|
|
99
|
+
## Accessibility
|
|
100
|
+
|
|
101
|
+
- WCAG 2.2 AAA target.
|
|
102
|
+
- APG listbox keyboard contract: ArrowDown / ArrowUp / Enter / Space open; arrows clamp; `Home` / `End`;
|
|
103
|
+
`PageUp` / `PageDown` by ten; typeahead over the option text (type `UTC+05` to reach it); `Escape` closes
|
|
104
|
+
without changing the value; `Tab` closes and moves on.
|
|
105
|
+
- The offset is written in ASCII (`UTC+05:30`, hyphen-minus), so typeahead and screen readers read it the same
|
|
106
|
+
everywhere; the zone name comes from `Intl` in the reader's language.
|
|
107
|
+
- A tooltip repeats the label on hover and focus, dismissable with `Escape`, and is not linked with
|
|
108
|
+
`aria-describedby`.
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
Lily™ and Lily Design System™ are trademarks.
|