@r2digisolutions/components 0.25.11 → 0.25.12

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.
@@ -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"
@@ -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,7 +529,7 @@
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
@@ -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,10 @@ 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;
10
14
  optional: string;
11
15
  required: string;
12
16
  loading: string;
@@ -5,6 +5,9 @@ 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',
8
11
  optional: 'Optional',
9
12
  required: 'Required',
10
13
  loading: 'Loading…',
@@ -52,6 +55,9 @@ const es = {
52
55
  reset: 'Restablecer',
53
56
  submit: 'Enviar',
54
57
  close: 'Cerrar',
58
+ time: 'Hora',
59
+ clear: 'Borrar',
60
+ selectDateTime: 'Selecciona fecha y hora',
55
61
  optional: 'Opcional',
56
62
  required: 'Obligatorio',
57
63
  loading: 'Cargando…',
@@ -99,6 +105,9 @@ const pt = {
99
105
  reset: 'Repor',
100
106
  submit: 'Enviar',
101
107
  close: 'Fechar',
108
+ time: 'Hora',
109
+ clear: 'Limpar',
110
+ selectDateTime: 'Selecione data e hora',
102
111
  optional: 'Opcional',
103
112
  required: 'Obrigatório',
104
113
  loading: 'A carregar…',
@@ -146,6 +155,9 @@ const fr = {
146
155
  reset: 'Réinitialiser',
147
156
  submit: 'Envoyer',
148
157
  close: 'Fermer',
158
+ time: 'Heure',
159
+ clear: 'Effacer',
160
+ selectDateTime: 'Choisir la date et l’heure',
149
161
  optional: 'Facultatif',
150
162
  required: 'Obligatoire',
151
163
  loading: 'Chargement…',
@@ -193,6 +205,9 @@ const de = {
193
205
  reset: 'Zurücksetzen',
194
206
  submit: 'Senden',
195
207
  close: 'Schließen',
208
+ time: 'Uhrzeit',
209
+ clear: 'Löschen',
210
+ selectDateTime: 'Datum und Uhrzeit wählen',
196
211
  optional: 'Optional',
197
212
  required: 'Pflichtfeld',
198
213
  loading: 'Wird geladen…',
@@ -240,6 +255,9 @@ const ca = {
240
255
  reset: 'Restablir',
241
256
  submit: 'Enviar',
242
257
  close: 'Tancar',
258
+ time: 'Hora',
259
+ clear: 'Esborra',
260
+ selectDateTime: 'Tria data i hora',
243
261
  optional: 'Opcional',
244
262
  required: 'Obligatori',
245
263
  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.12",
4
4
  "private": false,
5
5
  "description": "R2DigiSolutions Svelte 5 component library — Atomic Design, Tailwind 4, Light/Dark mode",
6
6
  "license": "MIT",