@r2digisolutions/components 0.25.11 → 0.25.13

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.
@@ -1,4 +1,7 @@
1
1
  <script lang="ts">
2
+ import { i18n } from '../../../utils/i18n.svelte.js';
3
+ import { getDictionary, type MessageKey } from '../../../utils/i18n.js';
4
+
2
5
  export type CalendarMode = 'single' | 'multiple' | 'range';
3
6
 
4
7
  export type CalendarDot = string | { date: string; color?: string };
@@ -59,6 +62,9 @@
59
62
  onchange
60
63
  }: CalendarProps = $props();
61
64
 
65
+ // The calendar's locale names its controls; without one, the shared i18n store does.
66
+ const localMessages = $derived(locale && locale !== 'en' ? getDictionary(locale) : null);
67
+ const message = (key: MessageKey) => localMessages?.[key] ?? i18n.t(key);
62
68
  const today = new Date();
63
69
  const todayIso = `${today.getFullYear()}-${String(today.getMonth() + 1).padStart(2, '0')}-${String(today.getDate()).padStart(2, '0')}`;
64
70
 
@@ -75,8 +81,16 @@
75
81
  return value;
76
82
  }
77
83
 
84
+ /** First selectable month when it is in the future (e.g. an end date after a start). */
85
+ function minMonth() {
86
+ return min && min.slice(0, 10) > todayIso ? monthFromIso(min) : null;
87
+ }
88
+
89
+ // Without a selection, open on the first selectable month.
78
90
  let view = $state(
79
- monthFromIso(selectionIso()) ?? new Date(today.getFullYear(), today.getMonth(), 1)
91
+ monthFromIso(selectionIso()) ??
92
+ minMonth() ??
93
+ new Date(today.getFullYear(), today.getMonth(), 1)
80
94
  );
81
95
  let panel = $state<Panel>('days');
82
96
  /** Which month column owns the month/year picker when months=2. */
@@ -426,7 +440,7 @@
426
440
  type="button"
427
441
  onclick={() => shift(-1)}
428
442
  class="rounded-lg p-1.5 text-secondary hover:bg-surface-overlay hover:text-primary"
429
- aria-label="Previous month"
443
+ aria-label={message('previousMonth')}
430
444
  >
431
445
  <svg class="h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
432
446
  <path stroke-linecap="round" stroke-linejoin="round" d="M15 19l-7-7 7-7" />
@@ -458,7 +472,7 @@
458
472
  type="button"
459
473
  onclick={() => shift(1)}
460
474
  class="rounded-lg p-1.5 text-secondary hover:bg-surface-overlay hover:text-primary"
461
- aria-label="Next month"
475
+ aria-label={message('nextMonth')}
462
476
  >
463
477
  <svg class="h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
464
478
  <path stroke-linecap="round" stroke-linejoin="round" d="M9 5l7 7-7 7" />
@@ -525,7 +539,7 @@
525
539
  type="button"
526
540
  onclick={() => shift(-1)}
527
541
  class="rounded-lg p-1.5 text-secondary hover:bg-surface-overlay hover:text-primary"
528
- aria-label={panel === 'years' ? 'Previous years' : 'Previous year'}
542
+ aria-label={message(panel === 'years' ? 'previousYears' : 'previousYear')}
529
543
  >
530
544
  <svg class="h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
531
545
  <path stroke-linecap="round" stroke-linejoin="round" d="M15 19l-7-7 7-7" />
@@ -550,7 +564,7 @@
550
564
  type="button"
551
565
  onclick={() => shift(1)}
552
566
  class="rounded-lg p-1.5 text-secondary hover:bg-surface-overlay hover:text-primary"
553
- aria-label={panel === 'years' ? 'Next years' : 'Next year'}
567
+ aria-label={message(panel === 'years' ? 'nextYears' : 'nextYear')}
554
568
  >
555
569
  <svg class="h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
556
570
  <path stroke-linecap="round" stroke-linejoin="round" d="M9 5l7 7-7 7" />
@@ -5,6 +5,7 @@
5
5
  import type { CalendarDot } from '../Calendar/Calendar.svelte';
6
6
  import type { TimeFormat } from '../TimePicker/TimePicker.svelte';
7
7
  import { i18n } from '../../../utils/i18n.svelte.js';
8
+ import { getDictionary, resolveLocaleTag, type MessageKey } from '../../../utils/i18n.js';
8
9
  import { createId } from '../../../utils/id.js';
9
10
  import { popoverInvokerToggle } from '../../../utils/popoverInvoker.js';
10
11
 
@@ -32,6 +33,12 @@
32
33
  closeOnSelect?: boolean;
33
34
  cancelLabel?: string;
34
35
  saveLabel?: string;
36
+ /** BCP 47 locale for the calendar and displayed date. Defaults to the components i18n locale. */
37
+ locale?: string;
38
+ /** Heading of the time column. Defaults to the locale's "Time". */
39
+ timeLabel?: string;
40
+ /** Accessible name of the clear button. Defaults to the locale's "Clear". */
41
+ clearLabel?: string;
35
42
  class?: string;
36
43
  onchange?: (detail: { date: string; time: string; value: string }) => void;
37
44
  }
@@ -43,7 +50,7 @@
43
50
  open = $bindable(false),
44
51
  disabled = false,
45
52
  label = '',
46
- placeholder = 'Select date & time',
53
+ placeholder,
47
54
  min,
48
55
  max,
49
56
  disabledDates = [],
@@ -53,6 +60,9 @@
53
60
  closeOnSelect = false,
54
61
  cancelLabel,
55
62
  saveLabel,
63
+ locale,
64
+ timeLabel,
65
+ clearLabel,
56
66
  class: className = '',
57
67
  onchange
58
68
  }: DateTimePickerProps = $props();
@@ -66,8 +76,13 @@
66
76
  let draftDate = $state('');
67
77
  let draftTime = $state('');
68
78
 
69
- const resolvedCancelLabel = $derived(cancelLabel ?? i18n.t('cancel'));
70
- const resolvedSaveLabel = $derived(saveLabel ?? i18n.t('save'));
79
+ const dateLocale = $derived(locale || resolveLocaleTag(i18n.locale));
80
+ // An explicit locale wins over the shared i18n store (e.g. apps with their own i18n).
81
+ const localMessages = $derived(locale ? getDictionary(locale) : null);
82
+ const message = (key: MessageKey) => localMessages?.[key] ?? i18n.t(key);
83
+ const resolvedCancelLabel = $derived(cancelLabel ?? message('cancel'));
84
+ const resolvedSaveLabel = $derived(saveLabel ?? message('save'));
85
+ const resolvedPlaceholder = $derived(placeholder ?? message('selectDateTime'));
71
86
  const confirmMode = $derived(!closeOnSelect);
72
87
  const panelDate = $derived(confirmMode ? draftDate : date);
73
88
  const panelTime = $derived(confirmMode ? draftTime : time);
@@ -191,7 +206,7 @@
191
206
  function formatIso(iso: string) {
192
207
  if (!iso) return '';
193
208
  const [y, m, d] = iso.split('-').map(Number);
194
- return new Date(y, m - 1, d).toLocaleDateString('en', {
209
+ return new Date(y, m - 1, d).toLocaleDateString(dateLocale, {
195
210
  month: 'short',
196
211
  day: 'numeric',
197
212
  year: 'numeric'
@@ -207,7 +222,7 @@
207
222
  }
208
223
 
209
224
  const fieldLabel = $derived.by(() => {
210
- if (!date && !time) return placeholder;
225
+ if (!date && !time) return resolvedPlaceholder;
211
226
  if (date && time) return `${formatIso(date)} · ${formatTimeDisplay(time)}`;
212
227
  if (date) return `${formatIso(date)} · …`;
213
228
  return formatTimeDisplay(time);
@@ -466,7 +481,7 @@
466
481
  type="button"
467
482
  onclick={clear}
468
483
  class="px-3 text-muted hover:bg-surface-overlay hover:text-primary h-full"
469
- aria-label="Clear"
484
+ aria-label={clearLabel ?? message('clear')}
470
485
  >
471
486
  <svg
472
487
  class="h-3.5 w-3.5"
@@ -486,7 +501,7 @@
486
501
  id={panelId}
487
502
  popover="auto"
488
503
  role="dialog"
489
- aria-label="Choose date and time"
504
+ aria-label={message('chooseDateTime')}
490
505
  onbeforetoggle={handleBeforeToggle}
491
506
  ontoggle={handleToggle}
492
507
  data-placed={placed ? true : undefined}
@@ -503,6 +518,7 @@
503
518
  disabledDates={calendarDisabled}
504
519
  {dots}
505
520
  framed={false}
521
+ locale={dateLocale}
506
522
  class="w-full"
507
523
  onchange={handleDateChange}
508
524
  />
@@ -513,14 +529,14 @@
513
529
  <span
514
530
  class="border-border px-3 py-2.5 font-medium tracking-wide text-muted shrink-0 border-b text-center text-[11px] uppercase"
515
531
  >
516
- Time
532
+ {timeLabel ?? message('time')}
517
533
  </span>
518
534
  <div class="min-h-0 divide-border grid flex-1 grid-cols-2 divide-x">
519
535
  <div
520
536
  bind:this={hourListEl}
521
537
  class="p-1.5 h-[18.5rem] overflow-y-auto"
522
538
  role="listbox"
523
- aria-label="Hours"
539
+ aria-label={message('hours')}
524
540
  >
525
541
  {#each hours24 as h (h)}
526
542
  <button
@@ -546,7 +562,7 @@
546
562
  bind:this={minuteListEl}
547
563
  class="p-1.5 h-[18.5rem] overflow-y-auto"
548
564
  role="listbox"
549
- aria-label="Minutes"
565
+ aria-label={message('minutes')}
550
566
  >
551
567
  {#each minutes as m (m)}
552
568
  <button
@@ -24,6 +24,12 @@ interface DateTimePickerProps {
24
24
  closeOnSelect?: boolean;
25
25
  cancelLabel?: string;
26
26
  saveLabel?: string;
27
+ /** BCP 47 locale for the calendar and displayed date. Defaults to the components i18n locale. */
28
+ locale?: string;
29
+ /** Heading of the time column. Defaults to the locale's "Time". */
30
+ timeLabel?: string;
31
+ /** Accessible name of the clear button. Defaults to the locale's "Clear". */
32
+ clearLabel?: string;
27
33
  class?: string;
28
34
  onchange?: (detail: {
29
35
  date: string;
@@ -19,6 +19,8 @@
19
19
  errorMessage?: string;
20
20
  disabled?: boolean;
21
21
  bindData?: boolean;
22
+ /** BCP 47 locale for the calendar and displayed date. */
23
+ locale?: string;
22
24
  class?: string;
23
25
  onchange?: (value: string) => void;
24
26
  }
@@ -34,6 +36,7 @@
34
36
  errorMessage,
35
37
  disabled = false,
36
38
  bindData = false,
39
+ locale,
37
40
  class: className = '',
38
41
  onchange
39
42
  }: FormDatePickerProps = $props();
@@ -71,6 +74,7 @@
71
74
  {placeholder}
72
75
  {min}
73
76
  {max}
77
+ {locale}
74
78
  disabled={resolved.disabled}
75
79
  bind:value
76
80
  onchange={handleChange}
@@ -9,6 +9,8 @@ interface FormDatePickerProps {
9
9
  errorMessage?: string;
10
10
  disabled?: boolean;
11
11
  bindData?: boolean;
12
+ /** BCP 47 locale for the calendar and displayed date. */
13
+ locale?: string;
12
14
  class?: string;
13
15
  onchange?: (value: string) => void;
14
16
  }
@@ -21,6 +21,11 @@
21
21
  errorMessage?: string;
22
22
  disabled?: boolean;
23
23
  bindData?: boolean;
24
+ /** BCP 47 locale for the calendar, displayed date and built-in labels. */
25
+ locale?: string;
26
+ cancelLabel?: string;
27
+ saveLabel?: string;
28
+ minuteStep?: number;
24
29
  class?: string;
25
30
  onchange?: (detail: { date: string; time: string; value: string }) => void;
26
31
  }
@@ -28,7 +33,7 @@
28
33
  let {
29
34
  name,
30
35
  label,
31
- placeholder = 'Select date & time',
36
+ placeholder,
32
37
  value = $bindable(''),
33
38
  date = $bindable(''),
34
39
  time = $bindable(''),
@@ -38,6 +43,10 @@
38
43
  errorMessage,
39
44
  disabled = false,
40
45
  bindData = false,
46
+ locale,
47
+ cancelLabel,
48
+ saveLabel,
49
+ minuteStep,
41
50
  class: className = '',
42
51
  onchange
43
52
  }: FormDateTimePickerProps = $props();
@@ -77,6 +86,10 @@
77
86
  {placeholder}
78
87
  {min}
79
88
  {max}
89
+ {locale}
90
+ {cancelLabel}
91
+ {saveLabel}
92
+ {minuteStep}
80
93
  disabled={resolved.disabled}
81
94
  bind:value
82
95
  bind:date
@@ -11,6 +11,11 @@ interface FormDateTimePickerProps {
11
11
  errorMessage?: string;
12
12
  disabled?: boolean;
13
13
  bindData?: boolean;
14
+ /** BCP 47 locale for the calendar, displayed date and built-in labels. */
15
+ locale?: string;
16
+ cancelLabel?: string;
17
+ saveLabel?: string;
18
+ minuteStep?: number;
14
19
  class?: string;
15
20
  onchange?: (detail: {
16
21
  date: string;
@@ -7,6 +7,19 @@ export interface UiMessages {
7
7
  reset: string;
8
8
  submit: string;
9
9
  close: string;
10
+ /** Date & time pickers */
11
+ time: string;
12
+ clear: string;
13
+ selectDateTime: string;
14
+ chooseDateTime: string;
15
+ hours: string;
16
+ minutes: string;
17
+ previousMonth: string;
18
+ nextMonth: string;
19
+ previousYear: string;
20
+ nextYear: string;
21
+ previousYears: string;
22
+ nextYears: string;
10
23
  optional: string;
11
24
  required: string;
12
25
  loading: string;
@@ -5,6 +5,18 @@ const en = {
5
5
  reset: 'Reset',
6
6
  submit: 'Submit',
7
7
  close: 'Close',
8
+ time: 'Time',
9
+ clear: 'Clear',
10
+ selectDateTime: 'Select date & time',
11
+ chooseDateTime: 'Choose date and time',
12
+ hours: 'Hours',
13
+ minutes: 'Minutes',
14
+ previousMonth: 'Previous month',
15
+ nextMonth: 'Next month',
16
+ previousYear: 'Previous year',
17
+ nextYear: 'Next year',
18
+ previousYears: 'Previous years',
19
+ nextYears: 'Next years',
8
20
  optional: 'Optional',
9
21
  required: 'Required',
10
22
  loading: 'Loading…',
@@ -52,6 +64,18 @@ const es = {
52
64
  reset: 'Restablecer',
53
65
  submit: 'Enviar',
54
66
  close: 'Cerrar',
67
+ time: 'Hora',
68
+ clear: 'Borrar',
69
+ selectDateTime: 'Selecciona fecha y hora',
70
+ chooseDateTime: 'Elegir fecha y hora',
71
+ hours: 'Horas',
72
+ minutes: 'Minutos',
73
+ previousMonth: 'Mes anterior',
74
+ nextMonth: 'Mes siguiente',
75
+ previousYear: 'Año anterior',
76
+ nextYear: 'Año siguiente',
77
+ previousYears: 'Años anteriores',
78
+ nextYears: 'Años siguientes',
55
79
  optional: 'Opcional',
56
80
  required: 'Obligatorio',
57
81
  loading: 'Cargando…',
@@ -99,6 +123,18 @@ const pt = {
99
123
  reset: 'Repor',
100
124
  submit: 'Enviar',
101
125
  close: 'Fechar',
126
+ time: 'Hora',
127
+ clear: 'Limpar',
128
+ selectDateTime: 'Selecione data e hora',
129
+ chooseDateTime: 'Escolher data e hora',
130
+ hours: 'Horas',
131
+ minutes: 'Minutos',
132
+ previousMonth: 'Mês anterior',
133
+ nextMonth: 'Mês seguinte',
134
+ previousYear: 'Ano anterior',
135
+ nextYear: 'Ano seguinte',
136
+ previousYears: 'Anos anteriores',
137
+ nextYears: 'Anos seguintes',
102
138
  optional: 'Opcional',
103
139
  required: 'Obrigatório',
104
140
  loading: 'A carregar…',
@@ -146,6 +182,18 @@ const fr = {
146
182
  reset: 'Réinitialiser',
147
183
  submit: 'Envoyer',
148
184
  close: 'Fermer',
185
+ time: 'Heure',
186
+ clear: 'Effacer',
187
+ selectDateTime: 'Choisir la date et l’heure',
188
+ chooseDateTime: 'Choisir la date et l’heure',
189
+ hours: 'Heures',
190
+ minutes: 'Minutes',
191
+ previousMonth: 'Mois précédent',
192
+ nextMonth: 'Mois suivant',
193
+ previousYear: 'Année précédente',
194
+ nextYear: 'Année suivante',
195
+ previousYears: 'Années précédentes',
196
+ nextYears: 'Années suivantes',
149
197
  optional: 'Facultatif',
150
198
  required: 'Obligatoire',
151
199
  loading: 'Chargement…',
@@ -193,6 +241,18 @@ const de = {
193
241
  reset: 'Zurücksetzen',
194
242
  submit: 'Senden',
195
243
  close: 'Schließen',
244
+ time: 'Uhrzeit',
245
+ clear: 'Löschen',
246
+ selectDateTime: 'Datum und Uhrzeit wählen',
247
+ chooseDateTime: 'Datum und Uhrzeit wählen',
248
+ hours: 'Stunden',
249
+ minutes: 'Minuten',
250
+ previousMonth: 'Vorheriger Monat',
251
+ nextMonth: 'Nächster Monat',
252
+ previousYear: 'Vorheriges Jahr',
253
+ nextYear: 'Nächstes Jahr',
254
+ previousYears: 'Vorherige Jahre',
255
+ nextYears: 'Nächste Jahre',
196
256
  optional: 'Optional',
197
257
  required: 'Pflichtfeld',
198
258
  loading: 'Wird geladen…',
@@ -240,6 +300,18 @@ const ca = {
240
300
  reset: 'Restablir',
241
301
  submit: 'Enviar',
242
302
  close: 'Tancar',
303
+ time: 'Hora',
304
+ clear: 'Esborra',
305
+ selectDateTime: 'Tria data i hora',
306
+ chooseDateTime: 'Tria data i hora',
307
+ hours: 'Hores',
308
+ minutes: 'Minuts',
309
+ previousMonth: 'Mes anterior',
310
+ nextMonth: 'Mes següent',
311
+ previousYear: 'Any anterior',
312
+ nextYear: 'Any següent',
313
+ previousYears: 'Anys anteriors',
314
+ nextYears: 'Anys següents',
243
315
  optional: 'Opcional',
244
316
  required: 'Obligatori',
245
317
  loading: 'S’està carregant…',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@r2digisolutions/components",
3
- "version": "0.25.11",
3
+ "version": "0.25.13",
4
4
  "private": false,
5
5
  "description": "R2DigiSolutions Svelte 5 component library — Atomic Design, Tailwind 4, Light/Dark mode",
6
6
  "license": "MIT",