@r2digisolutions/components 0.8.3 → 0.8.4

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.
@@ -29,6 +29,8 @@
29
29
  dots?: CalendarDot[];
30
30
  /** Show border/shadow chrome. */
31
31
  framed?: boolean;
32
+ /** BCP 47 locale for weekday and month names. */
33
+ locale?: string;
32
34
  class?: string;
33
35
  onchange?: (detail: {
34
36
  mode: CalendarMode;
@@ -52,6 +54,7 @@
52
54
  enabledDates,
53
55
  dots = [],
54
56
  framed = true,
57
+ locale = 'en',
55
58
  class: className = '',
56
59
  onchange
57
60
  }: CalendarProps = $props();
@@ -64,9 +67,15 @@
64
67
  /** Which month column owns the month/year picker when months=2. */
65
68
  let pickerOffset = $state(0);
66
69
 
67
- const weekDays = ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su'];
68
- const monthNames = Array.from({ length: 12 }, (_, i) =>
69
- new Date(2000, i, 1).toLocaleString('en', { month: 'short' })
70
+ const weekDays = $derived(
71
+ Array.from({ length: 7 }, (_, i) =>
72
+ new Date(2024, 0, 1 + i).toLocaleDateString(locale, { weekday: 'short' })
73
+ )
74
+ );
75
+ const monthNames = $derived(
76
+ Array.from({ length: 12 }, (_, i) =>
77
+ new Date(2000, i, 1).toLocaleString(locale, { month: 'short' })
78
+ )
70
79
  );
71
80
 
72
81
  const viewYear = $derived(view.getFullYear());
@@ -27,6 +27,8 @@ interface CalendarProps {
27
27
  dots?: CalendarDot[];
28
28
  /** Show border/shadow chrome. */
29
29
  framed?: boolean;
30
+ /** BCP 47 locale for weekday and month names. */
31
+ locale?: string;
30
32
  class?: string;
31
33
  onchange?: (detail: {
32
34
  mode: CalendarMode;
@@ -3,6 +3,8 @@
3
3
  type CalendarDot,
4
4
  type CalendarMode
5
5
  } from '../Calendar/Calendar.svelte';
6
+ import { i18n } from '../../../utils/i18n.svelte.js';
7
+ import { resolveLocaleTag } from '../../../utils/i18n.js';
6
8
 
7
9
  export type DatePickerPlacement =
8
10
  | 'auto'
@@ -43,6 +45,8 @@
43
45
  * alignment from available viewport space.
44
46
  */
45
47
  placement?: DatePickerPlacement;
48
+ /** BCP 47 locale for displayed dates. Defaults to the components i18n locale. */
49
+ locale?: string;
46
50
  class?: string;
47
51
  onchange?: (detail: {
48
52
  mode: CalendarMode;
@@ -76,10 +80,13 @@
76
80
  variant = 'field',
77
81
  closeOnSelect = true,
78
82
  placement = 'auto',
83
+ locale,
79
84
  class: className = '',
80
85
  onchange
81
86
  }: DatePickerProps = $props();
82
87
 
88
+ const dateLocale = $derived(locale || resolveLocaleTag(i18n.locale));
89
+
83
90
  let rootEl = $state<HTMLDivElement | null>(null);
84
91
  let panelEl = $state<HTMLDivElement | null>(null);
85
92
  let activeField = $state<'start' | 'end' | 'value'>('value');
@@ -92,9 +99,9 @@
92
99
  if (!iso) return '';
93
100
  const [y, m, d] = iso.split('-').map(Number);
94
101
  const date = new Date(y, m - 1, d);
95
- return date.toLocaleDateString('en', {
96
- month: 'short',
102
+ return date.toLocaleDateString(dateLocale, {
97
103
  day: 'numeric',
104
+ month: 'short',
98
105
  year: 'numeric'
99
106
  });
100
107
  }
@@ -277,7 +284,11 @@
277
284
  <div
278
285
  class={[
279
286
  'relative',
280
- months === 2 ? 'w-full max-w-xl' : 'w-full min-w-[18rem] max-w-[20rem]',
287
+ variant === 'split'
288
+ ? 'w-full'
289
+ : months === 2
290
+ ? 'w-full max-w-xl'
291
+ : 'w-full min-w-[18rem] max-w-[20rem]',
281
292
  className
282
293
  ]}
283
294
  bind:this={rootEl}
@@ -330,7 +341,7 @@
330
341
  type="button"
331
342
  onclick={clear}
332
343
  class="px-3 text-muted hover:text-primary"
333
- aria-label="Clear dates"
344
+ aria-label={i18n.t('clearAll')}
334
345
  >
335
346
  <svg class="h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
336
347
  <path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
@@ -409,6 +420,7 @@
409
420
  {enabledDates}
410
421
  {dots}
411
422
  framed={false}
423
+ locale={dateLocale}
412
424
  onchange={handleChange}
413
425
  />
414
426
  {:else if mode === 'multiple'}
@@ -422,6 +434,7 @@
422
434
  {enabledDates}
423
435
  {dots}
424
436
  framed={false}
437
+ locale={dateLocale}
425
438
  onchange={handleChange}
426
439
  />
427
440
  {:else}
@@ -436,6 +449,7 @@
436
449
  {enabledDates}
437
450
  {dots}
438
451
  framed={false}
452
+ locale={dateLocale}
439
453
  onchange={handleChange}
440
454
  />
441
455
  {/if}
@@ -30,6 +30,8 @@ interface DatePickerProps {
30
30
  * alignment from available viewport space.
31
31
  */
32
32
  placement?: DatePickerPlacement;
33
+ /** BCP 47 locale for displayed dates. Defaults to the components i18n locale. */
34
+ locale?: string;
33
35
  class?: string;
34
36
  onchange?: (detail: {
35
37
  mode: CalendarMode;
@@ -23,6 +23,7 @@
23
23
  variant?: 'field' | 'split';
24
24
  closeOnSelect?: boolean;
25
25
  placement?: DatePickerPlacement;
26
+ locale?: string;
26
27
  class?: string;
27
28
  onchange?: (detail: { start: string; end: string }) => void;
28
29
  }
@@ -47,6 +48,7 @@
47
48
  variant = 'split',
48
49
  closeOnSelect = true,
49
50
  placement = 'auto',
51
+ locale,
50
52
  class: className = '',
51
53
  onchange
52
54
  }: DateRangePickerProps = $props();
@@ -73,6 +75,7 @@
73
75
  {variant}
74
76
  {closeOnSelect}
75
77
  {placement}
78
+ {locale}
76
79
  class={className}
77
80
  onchange={(detail) => onchange?.({ start: detail.start, end: detail.end })}
78
81
  />
@@ -21,6 +21,7 @@ interface DateRangePickerProps {
21
21
  variant?: 'field' | 'split';
22
22
  closeOnSelect?: boolean;
23
23
  placement?: DatePickerPlacement;
24
+ locale?: string;
24
25
  class?: string;
25
26
  onchange?: (detail: {
26
27
  start: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@r2digisolutions/components",
3
- "version": "0.8.3",
3
+ "version": "0.8.4",
4
4
  "private": false,
5
5
  "description": "R2DigiSolutions Svelte 5 component library — Atomic Design, Tailwind 4, Light/Dark mode",
6
6
  "license": "MIT",