@r2digisolutions/components 0.23.1 โ 0.24.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/dist/components/atoms/BrandMark/BrandMark.svelte +47 -7
- package/dist/components/atoms/BrandMark/BrandMark.svelte.d.ts +4 -0
- package/dist/components/atoms/Slider/Slider.svelte +19 -15
- package/dist/components/atoms/Slider/Slider.svelte.d.ts +2 -0
- package/dist/components/atoms/VerifiedBadge/VerifiedBadge.svelte +76 -0
- package/dist/components/atoms/VerifiedBadge/VerifiedBadge.svelte.d.ts +12 -0
- package/dist/components/molecules/AuthCard/AuthCard.svelte +19 -4
- package/dist/components/molecules/AuthCard/AuthCard.svelte.d.ts +4 -0
- package/dist/components/molecules/CanvasElementsPanel/CanvasElementsPanel.svelte +90 -26
- package/dist/components/molecules/CanvasInspector/CanvasInspector.svelte +176 -5
- package/dist/components/molecules/Combobox/Combobox.svelte +2 -2
- package/dist/components/molecules/DateTimePicker/DateTimePicker.svelte +121 -33
- package/dist/components/molecules/FormSection/FormSection.svelte +25 -28
- package/dist/components/molecules/ImageEditor/ImageEditor.svelte +183 -0
- package/dist/components/molecules/ImageEditor/ImageEditor.svelte.d.ts +19 -0
- package/dist/components/molecules/LocaleSwitcher/LocaleSwitcher.svelte +58 -35
- package/dist/components/molecules/MediaLayerItem/MediaLayerItem.svelte +293 -39
- package/dist/components/molecules/MediaLayerItem/MediaLayerItem.svelte.d.ts +6 -1
- package/dist/components/molecules/MediaStage/MediaStage.svelte +302 -245
- package/dist/components/molecules/MentionInput/MentionInput.svelte +332 -120
- package/dist/components/molecules/MentionInput/MentionInput.svelte.d.ts +13 -2
- package/dist/components/molecules/Select/Select.svelte +14 -1
- package/dist/components/molecules/Select/Select.svelte.d.ts +3 -0
- package/dist/components/molecules/UserMenu/UserMenu.svelte +30 -27
- package/dist/components/molecules/WidgetFrame/WidgetFrame.svelte +200 -17
- package/dist/components/molecules/WidgetFrame/WidgetFrame.svelte.d.ts +14 -0
- package/dist/components/organisms/AppShell/AppShell.svelte +7 -1
- package/dist/components/organisms/AppShell/AppShell.svelte.d.ts +2 -0
- package/dist/components/organisms/AuthShell/AuthShell.svelte +61 -29
- package/dist/components/organisms/AuthShell/AuthShell.svelte.d.ts +4 -0
- package/dist/components/organisms/CanvasEditor/CanvasEditor.svelte +156 -7
- package/dist/components/organisms/CanvasEditor/CanvasEditor.svelte.d.ts +5 -0
- package/dist/components/organisms/Navbar/Navbar.svelte +2 -2
- package/dist/components/organisms/ProfileHeaderUploader/ProfileHeaderUploader.svelte +343 -140
- package/dist/components/organisms/ProfileHeaderUploader/ProfileHeaderUploader.svelte.d.ts +25 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +3 -1
- package/dist/styles.css +17 -0
- package/dist/utils/canvasDocument.d.ts +56 -4
- package/dist/utils/canvasDocument.js +91 -2
- package/dist/utils/canvasExport.d.ts +1 -1
- package/dist/utils/canvasExport.js +15 -25
- package/package.json +1 -1
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
{#if badge}
|
|
84
84
|
<span
|
|
85
85
|
class={[
|
|
86
|
-
'
|
|
86
|
+
'rounded-md px-1.5 py-0.5 font-semibold tracking-wide inline-flex border text-[10px] uppercase',
|
|
87
87
|
badgeToneClass[badgeTone]
|
|
88
88
|
]}
|
|
89
89
|
>
|
|
@@ -96,8 +96,8 @@
|
|
|
96
96
|
{#if icon}
|
|
97
97
|
<span
|
|
98
98
|
class={[
|
|
99
|
-
'
|
|
100
|
-
'ring-
|
|
99
|
+
'rounded-lg bg-brand-50 text-brand-600 flex shrink-0 items-center justify-center',
|
|
100
|
+
'ring-brand-500/10 dark:bg-brand-950/50 dark:text-brand-300 ring-1',
|
|
101
101
|
size === 'sm' ? 'h-7 w-7' : 'h-9 w-9'
|
|
102
102
|
]}
|
|
103
103
|
>
|
|
@@ -107,7 +107,7 @@
|
|
|
107
107
|
{/snippet}
|
|
108
108
|
|
|
109
109
|
{#snippet titleRow()}
|
|
110
|
-
<div class="
|
|
110
|
+
<div class="min-w-0 gap-2 flex flex-wrap items-center">
|
|
111
111
|
<h2 class="text-sm font-semibold tracking-tight text-primary">{title}</h2>
|
|
112
112
|
{@render badgeEl()}
|
|
113
113
|
</div>
|
|
@@ -117,8 +117,8 @@
|
|
|
117
117
|
class={[
|
|
118
118
|
'w-full',
|
|
119
119
|
variant === 'card' &&
|
|
120
|
-
'
|
|
121
|
-
variant === 'inset' && '
|
|
120
|
+
'rounded-2xl border-border bg-surface-elevated shadow-sm overflow-hidden border',
|
|
121
|
+
variant === 'inset' && 'rounded-2xl border-border/80 bg-surface/70 overflow-hidden border',
|
|
122
122
|
className
|
|
123
123
|
]}
|
|
124
124
|
>
|
|
@@ -127,17 +127,17 @@
|
|
|
127
127
|
<button
|
|
128
128
|
type="button"
|
|
129
129
|
class={[
|
|
130
|
-
'flex w-full items-center
|
|
130
|
+
'gap-3 flex w-full items-center text-left transition-colors outline-none',
|
|
131
131
|
'hover:bg-surface-overlay/60 focus-visible:bg-surface-overlay/60',
|
|
132
|
-
'focus-visible:ring-
|
|
132
|
+
'focus-visible:ring-brand-500/30 focus-visible:ring-2 focus-visible:ring-inset',
|
|
133
133
|
isCard ? 'px-4 py-3.5 sm:px-5' : 'py-3',
|
|
134
|
-
open && isCard && 'border-
|
|
134
|
+
open && isCard && 'border-border border-b'
|
|
135
135
|
]}
|
|
136
136
|
aria-expanded={open}
|
|
137
137
|
onclick={toggle}
|
|
138
138
|
>
|
|
139
139
|
<span
|
|
140
|
-
class="
|
|
140
|
+
class="h-6 w-6 rounded-md text-muted inline-flex shrink-0 items-center justify-center"
|
|
141
141
|
aria-hidden="true"
|
|
142
142
|
>
|
|
143
143
|
<ChevronRight
|
|
@@ -148,15 +148,15 @@
|
|
|
148
148
|
|
|
149
149
|
{@render iconEl('sm')}
|
|
150
150
|
|
|
151
|
-
<span class="min-w-0
|
|
151
|
+
<span class="min-w-0 space-y-1 flex-1">
|
|
152
152
|
{#if eyebrow}
|
|
153
|
-
<span class="block text-[10px]
|
|
153
|
+
<span class="font-semibold text-muted block text-[10px] tracking-[0.14em] uppercase"
|
|
154
154
|
>{eyebrow}</span
|
|
155
155
|
>
|
|
156
156
|
{/if}
|
|
157
157
|
{@render titleRow()}
|
|
158
158
|
{#if description}
|
|
159
|
-
<span class="
|
|
159
|
+
<span class="text-xs leading-relaxed text-secondary block">{description}</span>
|
|
160
160
|
{/if}
|
|
161
161
|
</span>
|
|
162
162
|
</button>
|
|
@@ -170,12 +170,12 @@
|
|
|
170
170
|
!isCard && 'pb-0'
|
|
171
171
|
]}
|
|
172
172
|
>
|
|
173
|
-
<div class="flex items-start justify-between
|
|
174
|
-
<div class="
|
|
173
|
+
<div class="gap-3 flex items-start justify-between">
|
|
174
|
+
<div class="min-w-0 gap-3 flex flex-1 items-start">
|
|
175
175
|
{@render iconEl('md')}
|
|
176
|
-
<div class="min-w-0 space-y-
|
|
176
|
+
<div class="min-w-0 space-y-1">
|
|
177
177
|
{#if eyebrow}
|
|
178
|
-
<p class="text-[10px]
|
|
178
|
+
<p class="font-semibold text-muted text-[10px] tracking-[0.14em] uppercase">
|
|
179
179
|
{eyebrow}
|
|
180
180
|
</p>
|
|
181
181
|
{/if}
|
|
@@ -186,14 +186,14 @@
|
|
|
186
186
|
</div>
|
|
187
187
|
</div>
|
|
188
188
|
{#if actions}
|
|
189
|
-
<div class="flex shrink-0 flex-wrap items-center
|
|
189
|
+
<div class="gap-2 flex shrink-0 flex-wrap items-center">
|
|
190
190
|
{@render actions()}
|
|
191
191
|
</div>
|
|
192
192
|
{/if}
|
|
193
193
|
</div>
|
|
194
194
|
|
|
195
195
|
{#if divided && layout === 'stack'}
|
|
196
|
-
<div class={['mt-3 border-
|
|
196
|
+
<div class={['mt-3 border-border border-b', isCard && '-mx-4 sm:-mx-5']}></div>
|
|
197
197
|
{/if}
|
|
198
198
|
</div>
|
|
199
199
|
{/if}
|
|
@@ -203,20 +203,20 @@
|
|
|
203
203
|
class={[
|
|
204
204
|
isCard && divided && 'px-4 py-4 sm:px-5 sm:py-5',
|
|
205
205
|
isCard && !divided && 'px-4 pt-2 pb-4 sm:px-5 sm:pb-5',
|
|
206
|
-
!isCard &&
|
|
206
|
+
!isCard && layout === 'stack' && 'pt-4',
|
|
207
207
|
useSplit &&
|
|
208
208
|
'lg:grid lg:grid-cols-[minmax(12rem,17rem)_minmax(0,1fr)] lg:items-start lg:gap-10'
|
|
209
209
|
]}
|
|
210
210
|
>
|
|
211
211
|
{#if useSplit}
|
|
212
|
-
<aside class="mb-4
|
|
212
|
+
<aside class="mb-4 min-w-0 lg:mb-0 lg:block hidden">
|
|
213
213
|
<div class="space-y-2 lg:sticky lg:top-4">
|
|
214
214
|
{#if eyebrow}
|
|
215
|
-
<p class="text-[10px]
|
|
215
|
+
<p class="font-semibold text-muted text-[10px] tracking-[0.14em] uppercase">
|
|
216
216
|
{eyebrow}
|
|
217
217
|
</p>
|
|
218
218
|
{/if}
|
|
219
|
-
<div class="flex flex-wrap items-center
|
|
219
|
+
<div class="gap-2 flex flex-wrap items-center">
|
|
220
220
|
{@render iconEl('sm')}
|
|
221
221
|
{@render titleRow()}
|
|
222
222
|
</div>
|
|
@@ -224,7 +224,7 @@
|
|
|
224
224
|
<p class="max-w-sm text-xs leading-relaxed text-secondary">{description}</p>
|
|
225
225
|
{/if}
|
|
226
226
|
{#if actions}
|
|
227
|
-
<div class="
|
|
227
|
+
<div class="gap-2 pt-1 flex flex-wrap">
|
|
228
228
|
{@render actions()}
|
|
229
229
|
</div>
|
|
230
230
|
{/if}
|
|
@@ -243,10 +243,7 @@
|
|
|
243
243
|
|
|
244
244
|
{#if footer}
|
|
245
245
|
<div
|
|
246
|
-
class={[
|
|
247
|
-
'border-t border-border',
|
|
248
|
-
isCard ? 'bg-surface/40 px-4 py-3 sm:px-5' : 'mt-4 pt-3'
|
|
249
|
-
]}
|
|
246
|
+
class={['border-border border-t', isCard ? 'bg-surface/40 px-4 py-3 sm:px-5' : 'mt-4 pt-3']}
|
|
250
247
|
>
|
|
251
248
|
{@render footer()}
|
|
252
249
|
</div>
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import Slider from '../../atoms/Slider/Slider.svelte';
|
|
3
|
+
|
|
4
|
+
export type ImageEditorFormat = 'image/jpeg' | 'image/png' | 'image/webp';
|
|
5
|
+
|
|
6
|
+
interface ImageEditorProps {
|
|
7
|
+
src?: string;
|
|
8
|
+
/** Viewport width / height. Default `3` (wide cover). */
|
|
9
|
+
aspect?: number;
|
|
10
|
+
minZoom?: number;
|
|
11
|
+
maxZoom?: number;
|
|
12
|
+
zoomLabel?: string;
|
|
13
|
+
outputFormat?: ImageEditorFormat;
|
|
14
|
+
outputQuality?: number;
|
|
15
|
+
/** Exported width in px. Height follows `aspect`. */
|
|
16
|
+
outputWidth?: number;
|
|
17
|
+
class?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let {
|
|
21
|
+
src = '',
|
|
22
|
+
aspect = 3,
|
|
23
|
+
minZoom = 1,
|
|
24
|
+
maxZoom = 3,
|
|
25
|
+
zoomLabel = 'Zoom',
|
|
26
|
+
outputFormat = 'image/jpeg',
|
|
27
|
+
outputQuality = 0.92,
|
|
28
|
+
outputWidth = 1600,
|
|
29
|
+
class: className = ''
|
|
30
|
+
}: ImageEditorProps = $props();
|
|
31
|
+
|
|
32
|
+
let frameEl = $state<HTMLDivElement | null>(null);
|
|
33
|
+
let imgEl = $state<HTMLImageElement | null>(null);
|
|
34
|
+
let zoom = $state(1);
|
|
35
|
+
let panX = $state(0);
|
|
36
|
+
let panY = $state(0);
|
|
37
|
+
let frameW = $state(0);
|
|
38
|
+
let frameH = $state(0);
|
|
39
|
+
let naturalW = $state(0);
|
|
40
|
+
let naturalH = $state(0);
|
|
41
|
+
let dragging = $state(false);
|
|
42
|
+
let exportError = $state('');
|
|
43
|
+
|
|
44
|
+
let pointerStart = { x: 0, y: 0, panX: 0, panY: 0 };
|
|
45
|
+
|
|
46
|
+
const fitted = $derived.by(() => {
|
|
47
|
+
if (!frameW || !frameH || !naturalW || !naturalH) return { w: 0, h: 0 };
|
|
48
|
+
const scale = Math.min(frameW / naturalW, frameH / naturalH) * zoom;
|
|
49
|
+
return { w: naturalW * scale, h: naturalH * scale };
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const offset = $derived({
|
|
53
|
+
x: (frameW - fitted.w) / 2 + panX,
|
|
54
|
+
y: (frameH - fitted.h) / 2 + panY
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
$effect(() => {
|
|
58
|
+
src;
|
|
59
|
+
zoom = 1;
|
|
60
|
+
panX = 0;
|
|
61
|
+
panY = 0;
|
|
62
|
+
exportError = '';
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
$effect(() => {
|
|
66
|
+
const frame = frameEl;
|
|
67
|
+
if (!frame) return;
|
|
68
|
+
measure();
|
|
69
|
+
const observer = new ResizeObserver(() => measure());
|
|
70
|
+
observer.observe(frame);
|
|
71
|
+
return () => observer.disconnect();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
function measure() {
|
|
75
|
+
if (!frameEl) return;
|
|
76
|
+
frameW = frameEl.clientWidth;
|
|
77
|
+
frameH = frameEl.clientHeight;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function onImageLoad() {
|
|
81
|
+
if (!imgEl) return;
|
|
82
|
+
naturalW = imgEl.naturalWidth;
|
|
83
|
+
naturalH = imgEl.naturalHeight;
|
|
84
|
+
measure();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function onPointerDown(event: PointerEvent) {
|
|
88
|
+
if (!fitted.w) return;
|
|
89
|
+
dragging = true;
|
|
90
|
+
pointerStart = { x: event.clientX, y: event.clientY, panX, panY };
|
|
91
|
+
(event.currentTarget as HTMLElement).setPointerCapture(event.pointerId);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function onPointerMove(event: PointerEvent) {
|
|
95
|
+
if (!dragging) return;
|
|
96
|
+
panX = pointerStart.panX + (event.clientX - pointerStart.x);
|
|
97
|
+
panY = pointerStart.panY + (event.clientY - pointerStart.y);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function onPointerUp(event: PointerEvent) {
|
|
101
|
+
dragging = false;
|
|
102
|
+
const target = event.currentTarget as HTMLElement;
|
|
103
|
+
if (target.hasPointerCapture(event.pointerId)) target.releasePointerCapture(event.pointerId);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function onWheel(event: WheelEvent) {
|
|
107
|
+
event.preventDefault();
|
|
108
|
+
const next = zoom + (event.deltaY < 0 ? 0.08 : -0.08);
|
|
109
|
+
zoom = Math.min(maxZoom, Math.max(minZoom, Number(next.toFixed(2))));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export async function exportFile(filename = 'image.jpg'): Promise<File> {
|
|
113
|
+
exportError = '';
|
|
114
|
+
if (!imgEl || !frameW || !frameH || !fitted.w) {
|
|
115
|
+
throw new Error('Image is not ready');
|
|
116
|
+
}
|
|
117
|
+
const canvas = document.createElement('canvas');
|
|
118
|
+
canvas.width = outputWidth;
|
|
119
|
+
canvas.height = Math.max(1, Math.round(outputWidth / aspect));
|
|
120
|
+
const ctx = canvas.getContext('2d');
|
|
121
|
+
if (!ctx) throw new Error('Canvas is not available');
|
|
122
|
+
const scale = canvas.width / frameW;
|
|
123
|
+
ctx.fillStyle = '#0a0a0a';
|
|
124
|
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
125
|
+
ctx.drawImage(imgEl, offset.x * scale, offset.y * scale, fitted.w * scale, fitted.h * scale);
|
|
126
|
+
const blob = await new Promise<Blob | null>((resolve) => {
|
|
127
|
+
canvas.toBlob(resolve, outputFormat, outputQuality);
|
|
128
|
+
});
|
|
129
|
+
if (!blob) {
|
|
130
|
+
exportError = 'Could not export this image';
|
|
131
|
+
throw new Error(exportError);
|
|
132
|
+
}
|
|
133
|
+
const ext =
|
|
134
|
+
outputFormat === 'image/png' ? 'png' : outputFormat === 'image/webp' ? 'webp' : 'jpg';
|
|
135
|
+
const base = filename.replace(/\.[a-z0-9]+$/i, '') || 'image';
|
|
136
|
+
return new File([blob], `${base}.${ext}`, { type: outputFormat });
|
|
137
|
+
}
|
|
138
|
+
</script>
|
|
139
|
+
|
|
140
|
+
<div class={['gap-3 flex w-full flex-col', className]}>
|
|
141
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
142
|
+
<div
|
|
143
|
+
bind:this={frameEl}
|
|
144
|
+
class="rounded-xl bg-neutral-950 relative w-full touch-none overflow-hidden"
|
|
145
|
+
style:aspect-ratio={aspect}
|
|
146
|
+
aria-label={zoomLabel}
|
|
147
|
+
onpointerdown={onPointerDown}
|
|
148
|
+
onpointermove={onPointerMove}
|
|
149
|
+
onpointerup={onPointerUp}
|
|
150
|
+
onpointercancel={onPointerUp}
|
|
151
|
+
onwheel={onWheel}
|
|
152
|
+
>
|
|
153
|
+
{#if src}
|
|
154
|
+
<img
|
|
155
|
+
bind:this={imgEl}
|
|
156
|
+
{src}
|
|
157
|
+
alt=""
|
|
158
|
+
crossorigin="anonymous"
|
|
159
|
+
draggable="false"
|
|
160
|
+
class="pointer-events-none absolute max-w-none select-none"
|
|
161
|
+
style:width="{fitted.w}px"
|
|
162
|
+
style:height="{fitted.h}px"
|
|
163
|
+
style:left="{offset.x}px"
|
|
164
|
+
style:top="{offset.y}px"
|
|
165
|
+
onload={onImageLoad}
|
|
166
|
+
/>
|
|
167
|
+
{/if}
|
|
168
|
+
</div>
|
|
169
|
+
<Slider
|
|
170
|
+
label={zoomLabel}
|
|
171
|
+
min={minZoom}
|
|
172
|
+
max={maxZoom}
|
|
173
|
+
step={0.05}
|
|
174
|
+
bind:value={zoom}
|
|
175
|
+
showValue
|
|
176
|
+
valuePosition="inline"
|
|
177
|
+
unit="ร"
|
|
178
|
+
form=""
|
|
179
|
+
/>
|
|
180
|
+
{#if exportError}
|
|
181
|
+
<p class="text-xs text-danger">{exportError}</p>
|
|
182
|
+
{/if}
|
|
183
|
+
</div>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type ImageEditorFormat = 'image/jpeg' | 'image/png' | 'image/webp';
|
|
2
|
+
interface ImageEditorProps {
|
|
3
|
+
src?: string;
|
|
4
|
+
/** Viewport width / height. Default `3` (wide cover). */
|
|
5
|
+
aspect?: number;
|
|
6
|
+
minZoom?: number;
|
|
7
|
+
maxZoom?: number;
|
|
8
|
+
zoomLabel?: string;
|
|
9
|
+
outputFormat?: ImageEditorFormat;
|
|
10
|
+
outputQuality?: number;
|
|
11
|
+
/** Exported width in px. Height follows `aspect`. */
|
|
12
|
+
outputWidth?: number;
|
|
13
|
+
class?: string;
|
|
14
|
+
}
|
|
15
|
+
declare const ImageEditor: import("svelte").Component<ImageEditorProps, {
|
|
16
|
+
exportFile: (filename?: string) => Promise<File>;
|
|
17
|
+
}, "">;
|
|
18
|
+
type ImageEditor = ReturnType<typeof ImageEditor>;
|
|
19
|
+
export default ImageEditor;
|
|
@@ -39,16 +39,35 @@
|
|
|
39
39
|
|
|
40
40
|
const defaultLocales: LocaleOption[] = [
|
|
41
41
|
{ code: 'en', label: 'English', englishLabel: 'English', flag: '๐ฌ๐ง', region: 'United Kingdom' },
|
|
42
|
-
{
|
|
42
|
+
{
|
|
43
|
+
code: 'en-US',
|
|
44
|
+
label: 'English',
|
|
45
|
+
englishLabel: 'English (US)',
|
|
46
|
+
flag: '๐บ๐ธ',
|
|
47
|
+
region: 'United States'
|
|
48
|
+
},
|
|
43
49
|
{ code: 'es', label: 'Espaรฑol', englishLabel: 'Spanish', flag: '๐ช๐ธ', region: 'Spain' },
|
|
44
50
|
{ code: 'es-MX', label: 'Espaรฑol', englishLabel: 'Spanish (MX)', flag: '๐ฒ๐ฝ', region: 'Mexico' },
|
|
45
51
|
{ code: 'fr', label: 'Franรงais', englishLabel: 'French', flag: '๐ซ๐ท', region: 'France' },
|
|
46
52
|
{ code: 'de', label: 'Deutsch', englishLabel: 'German', flag: '๐ฉ๐ช', region: 'Germany' },
|
|
47
53
|
{ code: 'pt', label: 'Portuguรชs', englishLabel: 'Portuguese', flag: '๐ต๐น', region: 'Portugal' },
|
|
48
|
-
{
|
|
54
|
+
{
|
|
55
|
+
code: 'pt-BR',
|
|
56
|
+
label: 'Portuguรชs',
|
|
57
|
+
englishLabel: 'Portuguese (BR)',
|
|
58
|
+
flag: '๐ง๐ท',
|
|
59
|
+
region: 'Brazil'
|
|
60
|
+
},
|
|
49
61
|
{ code: 'it', label: 'Italiano', englishLabel: 'Italian', flag: '๐ฎ๐น', region: 'Italy' },
|
|
50
62
|
{ code: 'ja', label: 'ๆฅๆฌ่ช', englishLabel: 'Japanese', flag: '๐ฏ๐ต', region: 'Japan' },
|
|
51
|
-
{
|
|
63
|
+
{
|
|
64
|
+
code: 'ar',
|
|
65
|
+
label: 'ุงูุนุฑุจูุฉ',
|
|
66
|
+
englishLabel: 'Arabic',
|
|
67
|
+
flag: '๐ธ๐ฆ',
|
|
68
|
+
region: 'Saudi Arabia',
|
|
69
|
+
dir: 'rtl'
|
|
70
|
+
}
|
|
52
71
|
];
|
|
53
72
|
|
|
54
73
|
let {
|
|
@@ -74,9 +93,9 @@
|
|
|
74
93
|
const triggerSize = $derived(
|
|
75
94
|
stacked
|
|
76
95
|
? size === 'sm'
|
|
77
|
-
? 'h-
|
|
96
|
+
? 'h-9 gap-2 px-3'
|
|
78
97
|
: size === 'lg'
|
|
79
|
-
? 'h-
|
|
98
|
+
? 'h-12 gap-2.5 px-3.5'
|
|
80
99
|
: 'h-10 gap-2 px-3'
|
|
81
100
|
: size === 'sm'
|
|
82
101
|
? 'h-8 gap-1.5 px-2.5 text-xs'
|
|
@@ -86,7 +105,11 @@
|
|
|
86
105
|
);
|
|
87
106
|
|
|
88
107
|
const segmentSize = $derived(
|
|
89
|
-
size === 'sm'
|
|
108
|
+
size === 'sm'
|
|
109
|
+
? 'h-7 px-2.5 text-xs'
|
|
110
|
+
: size === 'lg'
|
|
111
|
+
? 'h-10 px-3.5 text-sm'
|
|
112
|
+
: 'h-9 px-3 text-sm'
|
|
90
113
|
);
|
|
91
114
|
|
|
92
115
|
function select(locale: LocaleOption) {
|
|
@@ -108,11 +131,11 @@
|
|
|
108
131
|
<svelte:window onclick={onDocClick} onkeydown={onKeydown} />
|
|
109
132
|
|
|
110
133
|
{#if variant === 'segmented'}
|
|
111
|
-
<div class={['inline-flex flex-col
|
|
134
|
+
<div class={['gap-1.5 inline-flex flex-col', className]} role="group" aria-label={label}>
|
|
112
135
|
{#if showLabel}
|
|
113
136
|
<span class="text-xs font-medium text-secondary">{label}</span>
|
|
114
137
|
{/if}
|
|
115
|
-
<div class="
|
|
138
|
+
<div class="rounded-xl border-border bg-surface-overlay p-1 inline-flex border">
|
|
116
139
|
{#each locales as locale (locale.code)}
|
|
117
140
|
<button
|
|
118
141
|
type="button"
|
|
@@ -120,7 +143,7 @@
|
|
|
120
143
|
aria-checked={value === locale.code}
|
|
121
144
|
onclick={() => select(locale)}
|
|
122
145
|
class={[
|
|
123
|
-
'
|
|
146
|
+
'gap-1.5 rounded-lg font-medium focus-visible:ring-brand-500/30 inline-flex items-center justify-center transition-colors focus-visible:ring-2 focus-visible:outline-none',
|
|
124
147
|
segmentSize,
|
|
125
148
|
value === locale.code
|
|
126
149
|
? 'bg-surface-elevated text-primary shadow-sm'
|
|
@@ -139,20 +162,20 @@
|
|
|
139
162
|
{:else if variant === 'list'}
|
|
140
163
|
<div
|
|
141
164
|
class={[
|
|
142
|
-
'
|
|
165
|
+
'rounded-2xl border-border bg-surface-elevated w-full overflow-hidden border',
|
|
143
166
|
className
|
|
144
167
|
]}
|
|
145
168
|
role="listbox"
|
|
146
169
|
aria-label={label}
|
|
147
170
|
>
|
|
148
|
-
<div class="
|
|
171
|
+
<div class="gap-2 border-border px-4 py-3 flex items-center border-b">
|
|
149
172
|
<Languages class="h-4 w-4 text-muted" />
|
|
150
173
|
<div class="min-w-0">
|
|
151
174
|
<p class="text-sm font-medium text-primary">{label}</p>
|
|
152
175
|
<p class="text-xs text-muted">Choose how the product is displayed</p>
|
|
153
176
|
</div>
|
|
154
177
|
</div>
|
|
155
|
-
<ul class="divide-
|
|
178
|
+
<ul class="divide-border divide-y">
|
|
156
179
|
{#each locales as locale (locale.code)}
|
|
157
180
|
<li>
|
|
158
181
|
<button
|
|
@@ -161,28 +184,28 @@
|
|
|
161
184
|
aria-selected={value === locale.code}
|
|
162
185
|
onclick={() => select(locale)}
|
|
163
186
|
class={[
|
|
164
|
-
'
|
|
187
|
+
'gap-3 px-4 py-3 focus-visible:ring-brand-500/30 flex w-full items-center text-left transition-colors focus-visible:ring-2 focus-visible:outline-none focus-visible:ring-inset',
|
|
165
188
|
value === locale.code ? 'bg-brand-500/5' : 'hover:bg-surface-overlay'
|
|
166
189
|
]}
|
|
167
190
|
>
|
|
168
191
|
{#if showFlags}
|
|
169
192
|
<span
|
|
170
|
-
class="
|
|
193
|
+
class="h-10 w-10 rounded-xl bg-surface-overlay text-xl flex shrink-0 items-center justify-center"
|
|
171
194
|
aria-hidden="true"
|
|
172
195
|
>
|
|
173
196
|
{locale.flag ?? '๐'}
|
|
174
197
|
</span>
|
|
175
198
|
{/if}
|
|
176
199
|
<span class="min-w-0 flex-1" dir={locale.dir ?? 'ltr'}>
|
|
177
|
-
<span class="
|
|
178
|
-
<span class="
|
|
200
|
+
<span class="text-sm font-medium text-primary block">{locale.label}</span>
|
|
201
|
+
<span class="text-xs text-muted block truncate">
|
|
179
202
|
{locale.englishLabel ?? locale.code}
|
|
180
203
|
{#if locale.region}ยท {locale.region}{/if}
|
|
181
204
|
</span>
|
|
182
205
|
</span>
|
|
183
206
|
{#if value === locale.code}
|
|
184
207
|
<span
|
|
185
|
-
class="
|
|
208
|
+
class="h-6 w-6 bg-brand-500 text-white flex items-center justify-center rounded-full"
|
|
186
209
|
>
|
|
187
210
|
<Check class="h-3.5 w-3.5" />
|
|
188
211
|
</span>
|
|
@@ -193,14 +216,14 @@
|
|
|
193
216
|
</ul>
|
|
194
217
|
</div>
|
|
195
218
|
{:else}
|
|
196
|
-
<div bind:this={rootEl} class={['relative inline-flex flex-col
|
|
219
|
+
<div bind:this={rootEl} class={['gap-1.5 relative inline-flex flex-col', className]}>
|
|
197
220
|
{#if showLabel}
|
|
198
221
|
<span class="text-xs font-medium text-secondary">{label}</span>
|
|
199
222
|
{/if}
|
|
200
223
|
<button
|
|
201
224
|
type="button"
|
|
202
225
|
class={[
|
|
203
|
-
'
|
|
226
|
+
'rounded-xl border-border bg-surface-elevated font-medium text-primary shadow-sm hover:bg-surface-overlay focus-visible:ring-brand-500/30 inline-flex items-center border transition focus-visible:ring-2 focus-visible:outline-none',
|
|
204
227
|
triggerSize
|
|
205
228
|
]}
|
|
206
229
|
aria-haspopup="listbox"
|
|
@@ -213,43 +236,43 @@
|
|
|
213
236
|
>{current.flag}</span
|
|
214
237
|
>
|
|
215
238
|
{:else}
|
|
216
|
-
<Globe class="h-4 w-4 shrink-0
|
|
239
|
+
<Globe class="h-4 w-4 text-muted shrink-0" />
|
|
217
240
|
{/if}
|
|
218
241
|
{#if stacked}
|
|
219
|
-
<span class="min-w-0 max-w-
|
|
220
|
-
<span class="text-primary
|
|
242
|
+
<span class="min-w-0 max-w-36 leading-tight flex-1 text-left" dir={current?.dir ?? 'ltr'}>
|
|
243
|
+
<span class="text-primary text-xs font-medium block truncate"
|
|
221
244
|
>{current?.label ?? value}</span
|
|
222
245
|
>
|
|
223
|
-
<span class="text-muted
|
|
246
|
+
<span class="text-muted font-medium tracking-wide block truncate text-[11px]"
|
|
224
247
|
>{shortCode}</span
|
|
225
248
|
>
|
|
226
249
|
</span>
|
|
227
250
|
{:else}
|
|
228
|
-
<span class="max-w-36
|
|
251
|
+
<span class="max-w-36 text-xs truncate" dir={current?.dir ?? 'ltr'}
|
|
229
252
|
>{current?.label ?? value}</span
|
|
230
253
|
>
|
|
231
254
|
<span
|
|
232
|
-
class="rounded-md bg-surface-overlay px-1.5 py-0.5
|
|
255
|
+
class="rounded-md bg-surface-overlay px-1.5 py-0.5 font-semibold tracking-wide text-muted text-[10px]"
|
|
233
256
|
>
|
|
234
257
|
{shortCode}
|
|
235
258
|
</span>
|
|
236
259
|
{/if}
|
|
237
|
-
<ChevronDown class={['h-3.5 w-3.5 shrink-0
|
|
260
|
+
<ChevronDown class={['h-3.5 w-3.5 text-muted shrink-0 transition', open && 'rotate-180']} />
|
|
238
261
|
</button>
|
|
239
262
|
|
|
240
263
|
{#if open}
|
|
241
264
|
<div
|
|
242
265
|
class={[
|
|
243
|
-
'
|
|
266
|
+
'w-72 rounded-2xl border-border bg-surface-elevated py-1 shadow-xl absolute top-[calc(100%+0.35rem)] z-50 overflow-hidden border',
|
|
244
267
|
align === 'end' ? 'end-0' : 'start-0'
|
|
245
268
|
]}
|
|
246
269
|
role="listbox"
|
|
247
270
|
aria-label={label}
|
|
248
271
|
>
|
|
249
|
-
<div class="border-
|
|
250
|
-
<p class="
|
|
272
|
+
<div class="border-border px-3 py-2 border-b">
|
|
273
|
+
<p class="font-semibold tracking-wide text-muted text-[11px] uppercase">{label}</p>
|
|
251
274
|
</div>
|
|
252
|
-
<ul class="max-h-72 overflow-auto
|
|
275
|
+
<ul class="max-h-72 py-1 overflow-auto">
|
|
253
276
|
{#each locales as locale (locale.code)}
|
|
254
277
|
<li>
|
|
255
278
|
<button
|
|
@@ -258,24 +281,24 @@
|
|
|
258
281
|
aria-selected={value === locale.code}
|
|
259
282
|
onclick={() => select(locale)}
|
|
260
283
|
class={[
|
|
261
|
-
'
|
|
284
|
+
'gap-2.5 px-3 py-2 focus-visible:bg-surface-overlay flex w-full items-center text-left transition-colors focus-visible:outline-none',
|
|
262
285
|
value === locale.code ? 'bg-brand-500/5' : 'hover:bg-surface-overlay'
|
|
263
286
|
]}
|
|
264
287
|
>
|
|
265
288
|
{#if showFlags}
|
|
266
|
-
<span class="w-6 text-
|
|
289
|
+
<span class="w-6 text-base text-center leading-none" aria-hidden="true">
|
|
267
290
|
{locale.flag ?? '๐'}
|
|
268
291
|
</span>
|
|
269
292
|
{/if}
|
|
270
293
|
<span class="min-w-0 flex-1" dir={locale.dir ?? 'ltr'}>
|
|
271
|
-
<span class="
|
|
272
|
-
<span class="block truncate text-[11px]
|
|
294
|
+
<span class="text-sm font-medium text-primary block">{locale.label}</span>
|
|
295
|
+
<span class="text-muted block truncate text-[11px]">
|
|
273
296
|
{locale.englishLabel ?? locale.code}
|
|
274
297
|
{#if locale.region}ยท {locale.region}{/if}
|
|
275
298
|
</span>
|
|
276
299
|
</span>
|
|
277
300
|
{#if value === locale.code}
|
|
278
|
-
<Check class="h-4 w-4
|
|
301
|
+
<Check class="h-4 w-4 text-brand-600 dark:text-brand-400 shrink-0" />
|
|
279
302
|
{/if}
|
|
280
303
|
</button>
|
|
281
304
|
</li>
|