@r2digisolutions/components 0.21.18 → 0.21.20

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.
@@ -28,6 +28,10 @@
28
28
  label?: string;
29
29
  showLabel?: boolean;
30
30
  showFlags?: boolean;
31
+ /**
32
+ * Compact header style: language name on top, code underneath (no code badge on the right).
33
+ */
34
+ stacked?: boolean;
31
35
  align?: 'start' | 'end';
32
36
  class?: string;
33
37
  onchange?: (code: string, locale: LocaleOption) => void;
@@ -55,6 +59,7 @@
55
59
  label = 'Language',
56
60
  showLabel = false,
57
61
  showFlags = true,
62
+ stacked = false,
58
63
  align = 'end',
59
64
  class: className = '',
60
65
  onchange
@@ -67,7 +72,17 @@
67
72
  const shortCode = $derived((current?.code ?? value).split('-')[0]?.toUpperCase() ?? '—');
68
73
 
69
74
  const triggerSize = $derived(
70
- size === 'sm' ? 'h-8 gap-1.5 px-2.5 text-xs' : size === 'lg' ? 'h-11 gap-2.5 px-3.5 text-sm' : 'h-9 gap-2 px-3 text-sm'
75
+ stacked
76
+ ? size === 'sm'
77
+ ? 'min-h-9 gap-1.5 px-2.5 py-1'
78
+ : size === 'lg'
79
+ ? 'min-h-11 gap-2.5 px-3.5 py-1.5'
80
+ : 'min-h-10 gap-2 px-3 py-1'
81
+ : size === 'sm'
82
+ ? 'h-8 gap-1.5 px-2.5 text-xs'
83
+ : size === 'lg'
84
+ ? 'h-11 gap-2.5 px-3.5 text-sm'
85
+ : 'h-9 gap-2 px-3 text-sm'
71
86
  );
72
87
 
73
88
  const segmentSize = $derived(
@@ -194,15 +209,32 @@
194
209
  onclick={() => (open = !open)}
195
210
  >
196
211
  {#if showFlags && current?.flag}
197
- <span class="text-base leading-none" aria-hidden="true">{current.flag}</span>
212
+ <span class={['leading-none', stacked ? 'text-sm' : 'text-base']} aria-hidden="true"
213
+ >{current.flag}</span
214
+ >
198
215
  {:else}
199
- <Globe class="h-4 w-4 text-muted" />
216
+ <Globe class="h-4 w-4 shrink-0 text-muted" />
217
+ {/if}
218
+ {#if stacked}
219
+ <span class="min-w-0 max-w-28 flex-1 text-left leading-tight" dir={current?.dir ?? 'ltr'}>
220
+ <span class="text-primary block truncate text-xs font-medium"
221
+ >{current?.label ?? value}</span
222
+ >
223
+ <span class="text-secondary block truncate text-[10px] font-semibold tracking-wide"
224
+ >{shortCode}</span
225
+ >
226
+ </span>
227
+ {:else}
228
+ <span class="max-w-36 truncate text-xs" dir={current?.dir ?? 'ltr'}
229
+ >{current?.label ?? value}</span
230
+ >
231
+ <span
232
+ class="rounded-md bg-surface-overlay px-1.5 py-0.5 text-[10px] font-semibold tracking-wide text-muted"
233
+ >
234
+ {shortCode}
235
+ </span>
200
236
  {/if}
201
- <span class="max-w-36 truncate" dir={current?.dir ?? 'ltr'}>{current?.label ?? value}</span>
202
- <span class="rounded-md bg-surface-overlay px-1.5 py-0.5 text-[10px] font-semibold tracking-wide text-muted">
203
- {shortCode}
204
- </span>
205
- <ChevronDown class={['h-3.5 w-3.5 text-muted transition', open && 'rotate-180']} />
237
+ <ChevronDown class={['h-3.5 w-3.5 shrink-0 text-muted transition', open && 'rotate-180']} />
206
238
  </button>
207
239
 
208
240
  {#if open}
@@ -20,6 +20,10 @@ interface LocaleSwitcherProps {
20
20
  label?: string;
21
21
  showLabel?: boolean;
22
22
  showFlags?: boolean;
23
+ /**
24
+ * Compact header style: language name on top, code underneath (no code badge on the right).
25
+ */
26
+ stacked?: boolean;
23
27
  align?: 'start' | 'end';
24
28
  class?: string;
25
29
  onchange?: (code: string, locale: LocaleOption) => void;
@@ -370,7 +370,7 @@
370
370
  (highlighted === index
371
371
  ? 'bg-surface-overlay text-primary'
372
372
  : isSelected
373
- ? 'bg-brand-500/10 font-medium text-primary'
373
+ ? 'font-medium text-primary'
374
374
  : 'text-primary hover:bg-surface-overlay')
375
375
  ]}
376
376
  >
@@ -1,8 +1,11 @@
1
1
  <script lang="ts">
2
+ import type { Component } from 'svelte';
3
+
2
4
  export interface SegmentItem {
3
5
  id: string;
4
6
  label: string;
5
7
  disabled?: boolean;
8
+ icon?: Component<{ class?: string; size?: number | string; strokeWidth?: number | string }>;
6
9
  }
7
10
 
8
11
  interface SegmentedControlProps {
@@ -30,9 +33,15 @@
30
33
  }
31
34
 
32
35
  const sizeClasses = {
33
- sm: 'h-7 px-2.5 text-xs',
34
- md: 'h-9 px-3 text-sm',
35
- lg: 'h-10 px-4 text-sm'
36
+ sm: 'h-7 gap-1 px-2.5 text-xs',
37
+ md: 'h-9 gap-1.5 px-3 text-sm',
38
+ lg: 'h-10 gap-1.5 px-4 text-sm'
39
+ };
40
+
41
+ const iconSize = {
42
+ sm: 12,
43
+ md: 14,
44
+ lg: 16
36
45
  };
37
46
 
38
47
  function select(id: string, disabled?: boolean) {
@@ -52,6 +61,7 @@
52
61
  >
53
62
  {#each items as item (item.id)}
54
63
  {@const isActive = getActive() === item.id}
64
+ {@const Icon = item.icon}
55
65
  <button
56
66
  type="button"
57
67
  role="radio"
@@ -59,7 +69,7 @@
59
69
  disabled={item.disabled}
60
70
  onclick={() => select(item.id, item.disabled)}
61
71
  class={[
62
- 'rounded-lg font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand-500/30',
72
+ 'inline-flex items-center justify-center rounded-lg font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand-500/30',
63
73
  sizeClasses[size],
64
74
  fullWidth && 'flex-1',
65
75
  isActive
@@ -68,7 +78,10 @@
68
78
  item.disabled && 'cursor-not-allowed opacity-40'
69
79
  ]}
70
80
  >
71
- {item.label}
81
+ {#if Icon}
82
+ <Icon class="shrink-0" size={iconSize[size]} strokeWidth={2.25} />
83
+ {/if}
84
+ <span>{item.label}</span>
72
85
  </button>
73
86
  {/each}
74
87
  </div>
@@ -1,7 +1,13 @@
1
+ import type { Component } from 'svelte';
1
2
  export interface SegmentItem {
2
3
  id: string;
3
4
  label: string;
4
5
  disabled?: boolean;
6
+ icon?: Component<{
7
+ class?: string;
8
+ size?: number | string;
9
+ strokeWidth?: number | string;
10
+ }>;
5
11
  }
6
12
  interface SegmentedControlProps {
7
13
  items?: SegmentItem[];
@@ -11,6 +17,6 @@ interface SegmentedControlProps {
11
17
  class?: string;
12
18
  onchange?: (id: string) => void;
13
19
  }
14
- declare const SegmentedControl: import("svelte").Component<SegmentedControlProps, {}, "value">;
20
+ declare const SegmentedControl: Component<SegmentedControlProps, {}, "value">;
15
21
  type SegmentedControl = ReturnType<typeof SegmentedControl>;
16
22
  export default SegmentedControl;
@@ -664,7 +664,7 @@
664
664
  isHighlighted && !option.disabled
665
665
  ? 'bg-brand-500 text-white shadow-sm'
666
666
  : isSelected && !option.disabled
667
- ? 'bg-brand-500/10 font-medium text-primary'
667
+ ? 'font-medium text-primary'
668
668
  : 'text-primary hover:bg-surface-overlay'
669
669
  ]}
670
670
  >
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@r2digisolutions/components",
3
- "version": "0.21.18",
3
+ "version": "0.21.20",
4
4
  "private": false,
5
5
  "description": "R2DigiSolutions Svelte 5 component library — Atomic Design, Tailwind 4, Light/Dark mode",
6
6
  "license": "MIT",