@pie-qti/i18n 0.1.0 → 0.1.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.
- package/dist/core/I18n.d.ts +3 -2
- package/dist/core/I18n.d.ts.map +1 -1
- package/dist/core/I18n.js +11 -6
- package/dist/core/I18n.js.map +1 -1
- package/dist/locales/ar-SA.d.ts +43 -0
- package/dist/locales/ar-SA.d.ts.map +1 -1
- package/dist/locales/ar-SA.js +44 -0
- package/dist/locales/ar-SA.js.map +1 -1
- package/dist/locales/en-US.d.ts +43 -0
- package/dist/locales/en-US.d.ts.map +1 -1
- package/dist/locales/en-US.js +44 -0
- package/dist/locales/en-US.js.map +1 -1
- package/dist/locales/es-ES.d.ts +43 -0
- package/dist/locales/es-ES.d.ts.map +1 -1
- package/dist/locales/es-ES.js +44 -0
- package/dist/locales/es-ES.js.map +1 -1
- package/dist/locales/fr-FR.d.ts +43 -0
- package/dist/locales/fr-FR.d.ts.map +1 -1
- package/dist/locales/fr-FR.js +44 -0
- package/dist/locales/fr-FR.js.map +1 -1
- package/dist/locales/nl-NL.d.ts +43 -0
- package/dist/locales/nl-NL.d.ts.map +1 -1
- package/dist/locales/nl-NL.js +44 -0
- package/dist/locales/nl-NL.js.map +1 -1
- package/dist/locales/ro-RO.d.ts +43 -0
- package/dist/locales/ro-RO.d.ts.map +1 -1
- package/dist/locales/ro-RO.js +44 -0
- package/dist/locales/ro-RO.js.map +1 -1
- package/dist/locales/th-TH.d.ts +43 -0
- package/dist/locales/th-TH.d.ts.map +1 -1
- package/dist/locales/th-TH.js +44 -0
- package/dist/locales/th-TH.js.map +1 -1
- package/dist/locales/zh-CN.d.ts +43 -0
- package/dist/locales/zh-CN.d.ts.map +1 -1
- package/dist/locales/zh-CN.js +44 -0
- package/dist/locales/zh-CN.js.map +1 -1
- package/dist/providers/SvelteI18nProvider.d.ts +5 -14
- package/dist/providers/SvelteI18nProvider.d.ts.map +1 -1
- package/dist/providers/SvelteI18nProvider.js +7 -47
- package/dist/providers/SvelteI18nProvider.js.map +1 -1
- package/package.json +29 -7
- package/.turbo/turbo-build.log +0 -264
- package/docs/ADVANCED_FEATURES.md +0 -556
- package/docs/COMPONENT_PATTERNS.md +0 -896
- package/docs/INTEGRATION_GUIDE.md +0 -695
- package/scripts/check-translations.ts +0 -289
- package/scripts/scan-hardcoded-strings.ts +0 -266
- package/src/core/I18n.ts +0 -235
- package/src/core/I18nProvider.ts +0 -68
- package/src/core/types.ts +0 -45
- package/src/index.ts +0 -22
- package/src/locales/ar-SA.ts +0 -860
- package/src/locales/en-US.ts +0 -828
- package/src/locales/es-ES.ts +0 -816
- package/src/locales/fr-FR.ts +0 -815
- package/src/locales/nl-NL.ts +0 -815
- package/src/locales/ro-RO.ts +0 -815
- package/src/locales/th-TH.ts +0 -816
- package/src/locales/zh-CN.ts +0 -828
- package/src/providers/SvelteI18nProvider.ts +0 -170
- package/tests/i18n.test.ts +0 -146
- package/tsconfig.json +0 -10
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -1,896 +0,0 @@
|
|
|
1
|
-
# Component Patterns Guide
|
|
2
|
-
|
|
3
|
-
**PIE-QTI I18n Component Patterns**
|
|
4
|
-
|
|
5
|
-
This guide provides standardized patterns for building components with Svelte 5, DaisyUI, and i18n integration.
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## Table of Contents
|
|
10
|
-
|
|
11
|
-
1. [Core Principles](#core-principles)
|
|
12
|
-
2. [Basic Component Structure](#basic-component-structure)
|
|
13
|
-
3. [Button Patterns](#button-patterns)
|
|
14
|
-
4. [Form Patterns](#form-patterns)
|
|
15
|
-
5. [Modal Patterns](#modal-patterns)
|
|
16
|
-
6. [Alert Patterns](#alert-patterns)
|
|
17
|
-
7. [Loading State Patterns](#loading-state-patterns)
|
|
18
|
-
8. [Interaction Component Patterns](#interaction-component-patterns)
|
|
19
|
-
9. [Best Practices](#best-practices)
|
|
20
|
-
|
|
21
|
-
---
|
|
22
|
-
|
|
23
|
-
## Core Principles
|
|
24
|
-
|
|
25
|
-
### 1. Svelte 5 Runes
|
|
26
|
-
|
|
27
|
-
Always use modern Svelte 5 patterns:
|
|
28
|
-
|
|
29
|
-
```typescript
|
|
30
|
-
// ✅ CORRECT - Use $props() for component props
|
|
31
|
-
let { interaction, response, disabled, i18n }: Props = $props();
|
|
32
|
-
|
|
33
|
-
// ✅ CORRECT - Use $state() for reactive state
|
|
34
|
-
let isOpen = $state(false);
|
|
35
|
-
let selectedItem = $state<string | null>(null);
|
|
36
|
-
|
|
37
|
-
// ✅ CORRECT - Use $derived() for computed values
|
|
38
|
-
const isValid = $derived(response !== null && response.length > 0);
|
|
39
|
-
const currentValue = $derived(parsedResponse ?? defaultValue);
|
|
40
|
-
|
|
41
|
-
// ✅ CORRECT - Use $effect() for side effects with cleanup
|
|
42
|
-
$effect(() => {
|
|
43
|
-
const unsubscribe = subscribe();
|
|
44
|
-
return () => unsubscribe(); // Cleanup
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
// ❌ INCORRECT - Don't use onMount/onDestroy
|
|
48
|
-
// ❌ INCORRECT - Don't use $ reactive declarations
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
### 2. Optional i18n with Key Fallbacks
|
|
52
|
-
|
|
53
|
-
```typescript
|
|
54
|
-
import type { I18nProvider } from '@pie-qti/i18n';
|
|
55
|
-
|
|
56
|
-
// ✅ CORRECT - i18n is optional
|
|
57
|
-
let { i18n }: { i18n?: I18nProvider } = $props();
|
|
58
|
-
|
|
59
|
-
// ✅ CORRECT - Reactive translations with key fallbacks
|
|
60
|
-
const translations = $derived({
|
|
61
|
-
label: i18n?.t('component.label') ?? 'component.label',
|
|
62
|
-
help: i18n?.t('component.help') ?? 'component.help',
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
// ❌ INCORRECT - Never use English string fallbacks
|
|
66
|
-
// const label = i18n?.t('component.label') ?? 'Label';
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
### 3. DaisyUI Semantic Classes
|
|
70
|
-
|
|
71
|
-
Use DaisyUI's semantic utility classes consistently:
|
|
72
|
-
|
|
73
|
-
```svelte
|
|
74
|
-
<!-- Buttons -->
|
|
75
|
-
<button class="btn btn-primary">Primary Action</button>
|
|
76
|
-
<button class="btn btn-outline">Secondary Action</button>
|
|
77
|
-
<button class="btn btn-error">Destructive Action</button>
|
|
78
|
-
|
|
79
|
-
<!-- Forms -->
|
|
80
|
-
<div class="form-control">
|
|
81
|
-
<label class="label">
|
|
82
|
-
<span class="label-text">Field Label</span>
|
|
83
|
-
</label>
|
|
84
|
-
<input class="input input-bordered" />
|
|
85
|
-
</div>
|
|
86
|
-
|
|
87
|
-
<!-- Alerts -->
|
|
88
|
-
<div class="alert alert-error">Error message</div>
|
|
89
|
-
<div class="alert alert-warning">Warning message</div>
|
|
90
|
-
<div class="alert alert-info">Info message</div>
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
---
|
|
94
|
-
|
|
95
|
-
## Basic Component Structure
|
|
96
|
-
|
|
97
|
-
### Standard Interaction Component
|
|
98
|
-
|
|
99
|
-
```svelte
|
|
100
|
-
<script lang="ts">
|
|
101
|
-
import type { I18nProvider } from '@pie-qti/i18n';
|
|
102
|
-
|
|
103
|
-
interface Props {
|
|
104
|
-
interaction: InteractionData;
|
|
105
|
-
response: string | null;
|
|
106
|
-
disabled?: boolean;
|
|
107
|
-
i18n?: I18nProvider;
|
|
108
|
-
onChange: (value: string | null) => void;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
let {
|
|
112
|
-
interaction,
|
|
113
|
-
response,
|
|
114
|
-
disabled = false,
|
|
115
|
-
i18n,
|
|
116
|
-
onChange
|
|
117
|
-
}: Props = $props();
|
|
118
|
-
|
|
119
|
-
// Reactive translations
|
|
120
|
-
const translations = $derived({
|
|
121
|
-
label: i18n?.t('interactions.myComponent.label') ?? 'interactions.myComponent.label',
|
|
122
|
-
instruction: i18n?.t('interactions.myComponent.instruction') ?? 'interactions.myComponent.instruction',
|
|
123
|
-
submit: i18n?.t('common.submit') ?? 'common.submit',
|
|
124
|
-
clear: i18n?.t('common.clear') ?? 'common.clear',
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
// Local state
|
|
128
|
-
let internalValue = $state<string | null>(null);
|
|
129
|
-
|
|
130
|
-
// Derived values
|
|
131
|
-
const isValid = $derived(internalValue !== null && internalValue.length > 0);
|
|
132
|
-
|
|
133
|
-
// Effects
|
|
134
|
-
$effect(() => {
|
|
135
|
-
internalValue = response;
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
// Event handlers
|
|
139
|
-
function handleChange(value: string) {
|
|
140
|
-
internalValue = value;
|
|
141
|
-
onChange(value);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function handleClear() {
|
|
145
|
-
internalValue = null;
|
|
146
|
-
onChange(null);
|
|
147
|
-
}
|
|
148
|
-
</script>
|
|
149
|
-
|
|
150
|
-
<div class="space-y-4">
|
|
151
|
-
{#if interaction.prompt}
|
|
152
|
-
<p class="font-semibold">{@html interaction.prompt}</p>
|
|
153
|
-
{/if}
|
|
154
|
-
|
|
155
|
-
<div class="form-control">
|
|
156
|
-
<label class="label">
|
|
157
|
-
<span class="label-text">{translations.label}</span>
|
|
158
|
-
</label>
|
|
159
|
-
<input
|
|
160
|
-
class="input input-bordered"
|
|
161
|
-
class:input-error={!isValid}
|
|
162
|
-
value={internalValue ?? ''}
|
|
163
|
-
oninput={(e) => handleChange(e.currentTarget.value)}
|
|
164
|
-
disabled={disabled}
|
|
165
|
-
placeholder={translations.instruction}
|
|
166
|
-
/>
|
|
167
|
-
</div>
|
|
168
|
-
|
|
169
|
-
<div class="flex gap-2">
|
|
170
|
-
<button
|
|
171
|
-
class="btn btn-primary"
|
|
172
|
-
onclick={handleSubmit}
|
|
173
|
-
disabled={!isValid || disabled}
|
|
174
|
-
>
|
|
175
|
-
{translations.submit}
|
|
176
|
-
</button>
|
|
177
|
-
<button
|
|
178
|
-
class="btn btn-outline"
|
|
179
|
-
onclick={handleClear}
|
|
180
|
-
disabled={!internalValue || disabled}
|
|
181
|
-
>
|
|
182
|
-
{translations.clear}
|
|
183
|
-
</button>
|
|
184
|
-
</div>
|
|
185
|
-
</div>
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
---
|
|
189
|
-
|
|
190
|
-
## Button Patterns
|
|
191
|
-
|
|
192
|
-
### Primary Action Button
|
|
193
|
-
|
|
194
|
-
```svelte
|
|
195
|
-
<script lang="ts">
|
|
196
|
-
const translations = $derived({
|
|
197
|
-
submit: i18n?.t('common.submit') ?? 'common.submit',
|
|
198
|
-
});
|
|
199
|
-
</script>
|
|
200
|
-
|
|
201
|
-
<button
|
|
202
|
-
class="btn btn-primary"
|
|
203
|
-
onclick={handleSubmit}
|
|
204
|
-
disabled={!canSubmit}
|
|
205
|
-
>
|
|
206
|
-
{translations.submit}
|
|
207
|
-
</button>
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
### Secondary Action Button
|
|
211
|
-
|
|
212
|
-
```svelte
|
|
213
|
-
<button
|
|
214
|
-
class="btn btn-outline"
|
|
215
|
-
onclick={handleCancel}
|
|
216
|
-
>
|
|
217
|
-
{translations.cancel}
|
|
218
|
-
</button>
|
|
219
|
-
```
|
|
220
|
-
|
|
221
|
-
### Destructive Action Button
|
|
222
|
-
|
|
223
|
-
```svelte
|
|
224
|
-
<button
|
|
225
|
-
class="btn btn-error"
|
|
226
|
-
onclick={handleDelete}
|
|
227
|
-
>
|
|
228
|
-
{translations.delete}
|
|
229
|
-
</button>
|
|
230
|
-
```
|
|
231
|
-
|
|
232
|
-
### Button with Loading State
|
|
233
|
-
|
|
234
|
-
```svelte
|
|
235
|
-
<script lang="ts">
|
|
236
|
-
let isLoading = $state(false);
|
|
237
|
-
|
|
238
|
-
const translations = $derived({
|
|
239
|
-
submit: i18n?.t('common.submit') ?? 'common.submit',
|
|
240
|
-
loading: i18n?.t('common.loading') ?? 'common.loading',
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
async function handleSubmit() {
|
|
244
|
-
isLoading = true;
|
|
245
|
-
try {
|
|
246
|
-
await submitData();
|
|
247
|
-
} finally {
|
|
248
|
-
isLoading = false;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
</script>
|
|
252
|
-
|
|
253
|
-
<button
|
|
254
|
-
class="btn btn-primary"
|
|
255
|
-
onclick={handleSubmit}
|
|
256
|
-
disabled={isLoading}
|
|
257
|
-
>
|
|
258
|
-
{#if isLoading}
|
|
259
|
-
<span class="loading loading-spinner loading-sm"></span>
|
|
260
|
-
{/if}
|
|
261
|
-
{isLoading ? translations.loading : translations.submit}
|
|
262
|
-
</button>
|
|
263
|
-
```
|
|
264
|
-
|
|
265
|
-
### Icon Button
|
|
266
|
-
|
|
267
|
-
```svelte
|
|
268
|
-
<button
|
|
269
|
-
class="btn btn-sm btn-circle btn-error"
|
|
270
|
-
onclick={handleRemove}
|
|
271
|
-
aria-label={translations.remove}
|
|
272
|
-
title={translations.remove}
|
|
273
|
-
>
|
|
274
|
-
✕
|
|
275
|
-
</button>
|
|
276
|
-
```
|
|
277
|
-
|
|
278
|
-
---
|
|
279
|
-
|
|
280
|
-
## Form Patterns
|
|
281
|
-
|
|
282
|
-
### Text Input
|
|
283
|
-
|
|
284
|
-
```svelte
|
|
285
|
-
<div class="form-control">
|
|
286
|
-
<label class="label" for={inputId}>
|
|
287
|
-
<span class="label-text font-semibold">{translations.label}</span>
|
|
288
|
-
{#if required}
|
|
289
|
-
<span class="label-text-alt text-error">*</span>
|
|
290
|
-
{/if}
|
|
291
|
-
</label>
|
|
292
|
-
<input
|
|
293
|
-
id={inputId}
|
|
294
|
-
type="text"
|
|
295
|
-
class="input input-bordered"
|
|
296
|
-
class:input-error={error}
|
|
297
|
-
value={value}
|
|
298
|
-
oninput={(e) => onChange(e.currentTarget.value)}
|
|
299
|
-
placeholder={translations.placeholder}
|
|
300
|
-
disabled={disabled}
|
|
301
|
-
required={required}
|
|
302
|
-
/>
|
|
303
|
-
{#if error}
|
|
304
|
-
<label class="label">
|
|
305
|
-
<span class="label-text-alt text-error">{error}</span>
|
|
306
|
-
</label>
|
|
307
|
-
{/if}
|
|
308
|
-
</div>
|
|
309
|
-
```
|
|
310
|
-
|
|
311
|
-
### Textarea
|
|
312
|
-
|
|
313
|
-
```svelte
|
|
314
|
-
<div class="form-control">
|
|
315
|
-
<label class="label" for={textareaId}>
|
|
316
|
-
<span class="label-text font-semibold">{translations.label}</span>
|
|
317
|
-
</label>
|
|
318
|
-
<textarea
|
|
319
|
-
id={textareaId}
|
|
320
|
-
class="textarea textarea-bordered"
|
|
321
|
-
class:textarea-error={error}
|
|
322
|
-
rows="4"
|
|
323
|
-
value={value}
|
|
324
|
-
oninput={(e) => onChange(e.currentTarget.value)}
|
|
325
|
-
placeholder={translations.placeholder}
|
|
326
|
-
disabled={disabled}
|
|
327
|
-
></textarea>
|
|
328
|
-
</div>
|
|
329
|
-
```
|
|
330
|
-
|
|
331
|
-
### Select Dropdown
|
|
332
|
-
|
|
333
|
-
```svelte
|
|
334
|
-
<div class="form-control">
|
|
335
|
-
<label class="label" for={selectId}>
|
|
336
|
-
<span class="label-text font-semibold">{translations.label}</span>
|
|
337
|
-
</label>
|
|
338
|
-
<select
|
|
339
|
-
id={selectId}
|
|
340
|
-
class="select select-bordered"
|
|
341
|
-
value={value}
|
|
342
|
-
onchange={(e) => onChange(e.currentTarget.value)}
|
|
343
|
-
disabled={disabled}
|
|
344
|
-
>
|
|
345
|
-
<option value="" disabled>{translations.selectPlaceholder}</option>
|
|
346
|
-
{#each options as option}
|
|
347
|
-
<option value={option.value}>{option.label}</option>
|
|
348
|
-
{/each}
|
|
349
|
-
</select>
|
|
350
|
-
</div>
|
|
351
|
-
```
|
|
352
|
-
|
|
353
|
-
### Checkbox
|
|
354
|
-
|
|
355
|
-
```svelte
|
|
356
|
-
<div class="form-control">
|
|
357
|
-
<label class="label cursor-pointer justify-start gap-4">
|
|
358
|
-
<input
|
|
359
|
-
type="checkbox"
|
|
360
|
-
class="checkbox checkbox-primary"
|
|
361
|
-
checked={checked}
|
|
362
|
-
onchange={(e) => onChange(e.currentTarget.checked)}
|
|
363
|
-
disabled={disabled}
|
|
364
|
-
/>
|
|
365
|
-
<span class="label-text">{translations.label}</span>
|
|
366
|
-
</label>
|
|
367
|
-
</div>
|
|
368
|
-
```
|
|
369
|
-
|
|
370
|
-
### Radio Button Group
|
|
371
|
-
|
|
372
|
-
```svelte
|
|
373
|
-
<div class="space-y-2">
|
|
374
|
-
<div class="font-semibold text-sm">{translations.groupLabel}</div>
|
|
375
|
-
{#each options as option}
|
|
376
|
-
<div class="form-control">
|
|
377
|
-
<label class="label cursor-pointer justify-start gap-4">
|
|
378
|
-
<input
|
|
379
|
-
type="radio"
|
|
380
|
-
name={groupName}
|
|
381
|
-
class="radio radio-primary"
|
|
382
|
-
value={option.value}
|
|
383
|
-
checked={value === option.value}
|
|
384
|
-
onchange={() => onChange(option.value)}
|
|
385
|
-
disabled={disabled}
|
|
386
|
-
/>
|
|
387
|
-
<span class="label-text">{option.label}</span>
|
|
388
|
-
</label>
|
|
389
|
-
</div>
|
|
390
|
-
{/each}
|
|
391
|
-
</div>
|
|
392
|
-
```
|
|
393
|
-
|
|
394
|
-
### Form Validation Display
|
|
395
|
-
|
|
396
|
-
```svelte
|
|
397
|
-
<div class="form-control">
|
|
398
|
-
<label class="label" for={inputId}>
|
|
399
|
-
<span class="label-text font-semibold">{label}</span>
|
|
400
|
-
</label>
|
|
401
|
-
<input
|
|
402
|
-
id={inputId}
|
|
403
|
-
class="input input-bordered"
|
|
404
|
-
class:input-error={error}
|
|
405
|
-
value={value}
|
|
406
|
-
oninput={(e) => handleInput(e.currentTarget.value)}
|
|
407
|
-
/>
|
|
408
|
-
{#if error}
|
|
409
|
-
<div class="alert alert-error py-2 mt-2">
|
|
410
|
-
<span class="text-sm">{error}</span>
|
|
411
|
-
</div>
|
|
412
|
-
{/if}
|
|
413
|
-
{#if hint && !error}
|
|
414
|
-
<label class="label">
|
|
415
|
-
<span class="label-text-alt">{hint}</span>
|
|
416
|
-
</label>
|
|
417
|
-
{/if}
|
|
418
|
-
</div>
|
|
419
|
-
```
|
|
420
|
-
|
|
421
|
-
---
|
|
422
|
-
|
|
423
|
-
## Modal Patterns
|
|
424
|
-
|
|
425
|
-
### Basic Modal
|
|
426
|
-
|
|
427
|
-
```svelte
|
|
428
|
-
<script lang="ts">
|
|
429
|
-
let isOpen = $state(false);
|
|
430
|
-
|
|
431
|
-
const translations = $derived({
|
|
432
|
-
title: i18n?.t('modal.title') ?? 'modal.title',
|
|
433
|
-
content: i18n?.t('modal.content') ?? 'modal.content',
|
|
434
|
-
confirm: i18n?.t('common.confirm') ?? 'common.confirm',
|
|
435
|
-
cancel: i18n?.t('common.cancel') ?? 'common.cancel',
|
|
436
|
-
});
|
|
437
|
-
|
|
438
|
-
function open() {
|
|
439
|
-
isOpen = true;
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
function close() {
|
|
443
|
-
isOpen = false;
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
function handleConfirm() {
|
|
447
|
-
// Do something
|
|
448
|
-
close();
|
|
449
|
-
}
|
|
450
|
-
</script>
|
|
451
|
-
|
|
452
|
-
<button class="btn btn-primary" onclick={open}>
|
|
453
|
-
Open Modal
|
|
454
|
-
</button>
|
|
455
|
-
|
|
456
|
-
{#if isOpen}
|
|
457
|
-
<div class="modal modal-open">
|
|
458
|
-
<div class="modal-box">
|
|
459
|
-
<h3 class="font-bold text-lg">{translations.title}</h3>
|
|
460
|
-
<p class="py-4">{translations.content}</p>
|
|
461
|
-
<div class="modal-action">
|
|
462
|
-
<button class="btn" onclick={close}>
|
|
463
|
-
{translations.cancel}
|
|
464
|
-
</button>
|
|
465
|
-
<button class="btn btn-primary" onclick={handleConfirm}>
|
|
466
|
-
{translations.confirm}
|
|
467
|
-
</button>
|
|
468
|
-
</div>
|
|
469
|
-
</div>
|
|
470
|
-
<div class="modal-backdrop" onclick={close}></div>
|
|
471
|
-
</div>
|
|
472
|
-
{/if}
|
|
473
|
-
```
|
|
474
|
-
|
|
475
|
-
### Modal with Close Button
|
|
476
|
-
|
|
477
|
-
```svelte
|
|
478
|
-
<div class="modal modal-open">
|
|
479
|
-
<div class="modal-box">
|
|
480
|
-
<button
|
|
481
|
-
class="btn btn-sm btn-circle btn-ghost absolute right-2 top-2"
|
|
482
|
-
onclick={close}
|
|
483
|
-
aria-label={translations.close}
|
|
484
|
-
>
|
|
485
|
-
✕
|
|
486
|
-
</button>
|
|
487
|
-
<h3 class="font-bold text-lg">{translations.title}</h3>
|
|
488
|
-
<p class="py-4">{translations.content}</p>
|
|
489
|
-
<div class="modal-action">
|
|
490
|
-
<button class="btn btn-primary" onclick={handleConfirm}>
|
|
491
|
-
{translations.confirm}
|
|
492
|
-
</button>
|
|
493
|
-
</div>
|
|
494
|
-
</div>
|
|
495
|
-
</div>
|
|
496
|
-
```
|
|
497
|
-
|
|
498
|
-
---
|
|
499
|
-
|
|
500
|
-
## Alert Patterns
|
|
501
|
-
|
|
502
|
-
### Error Alert
|
|
503
|
-
|
|
504
|
-
```svelte
|
|
505
|
-
<div class="alert alert-error">
|
|
506
|
-
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current shrink-0 h-6 w-6" fill="none" viewBox="0 0 24 24" aria-hidden="true">
|
|
507
|
-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
|
508
|
-
</svg>
|
|
509
|
-
<span>{errorMessage}</span>
|
|
510
|
-
</div>
|
|
511
|
-
```
|
|
512
|
-
|
|
513
|
-
### Warning Alert
|
|
514
|
-
|
|
515
|
-
```svelte
|
|
516
|
-
<div class="alert alert-warning">
|
|
517
|
-
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current shrink-0 h-6 w-6" fill="none" viewBox="0 0 24 24" aria-hidden="true">
|
|
518
|
-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
|
|
519
|
-
</svg>
|
|
520
|
-
<span>{warningMessage}</span>
|
|
521
|
-
</div>
|
|
522
|
-
```
|
|
523
|
-
|
|
524
|
-
### Info Alert
|
|
525
|
-
|
|
526
|
-
```svelte
|
|
527
|
-
<div class="alert alert-info">
|
|
528
|
-
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="stroke-current shrink-0 w-6 h-6" aria-hidden="true">
|
|
529
|
-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
|
530
|
-
</svg>
|
|
531
|
-
<span>{infoMessage}</span>
|
|
532
|
-
</div>
|
|
533
|
-
```
|
|
534
|
-
|
|
535
|
-
### Success Alert
|
|
536
|
-
|
|
537
|
-
```svelte
|
|
538
|
-
<div class="alert alert-success">
|
|
539
|
-
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current shrink-0 h-6 w-6" fill="none" viewBox="0 0 24 24" aria-hidden="true">
|
|
540
|
-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
|
541
|
-
</svg>
|
|
542
|
-
<span>{successMessage}</span>
|
|
543
|
-
</div>
|
|
544
|
-
```
|
|
545
|
-
|
|
546
|
-
### Dismissible Alert
|
|
547
|
-
|
|
548
|
-
```svelte
|
|
549
|
-
<script lang="ts">
|
|
550
|
-
let visible = $state(true);
|
|
551
|
-
</script>
|
|
552
|
-
|
|
553
|
-
{#if visible}
|
|
554
|
-
<div class="alert alert-info">
|
|
555
|
-
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="stroke-current shrink-0 w-6 h-6" aria-hidden="true">
|
|
556
|
-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
|
557
|
-
</svg>
|
|
558
|
-
<span>{message}</span>
|
|
559
|
-
<button
|
|
560
|
-
class="btn btn-sm btn-circle btn-ghost"
|
|
561
|
-
onclick={() => visible = false}
|
|
562
|
-
aria-label={translations.close}
|
|
563
|
-
>
|
|
564
|
-
✕
|
|
565
|
-
</button>
|
|
566
|
-
</div>
|
|
567
|
-
{/if}
|
|
568
|
-
```
|
|
569
|
-
|
|
570
|
-
---
|
|
571
|
-
|
|
572
|
-
## Loading State Patterns
|
|
573
|
-
|
|
574
|
-
### Loading Spinner
|
|
575
|
-
|
|
576
|
-
```svelte
|
|
577
|
-
<div class="flex justify-center items-center py-8">
|
|
578
|
-
<span class="loading loading-spinner loading-lg"></span>
|
|
579
|
-
</div>
|
|
580
|
-
```
|
|
581
|
-
|
|
582
|
-
### Loading with Message
|
|
583
|
-
|
|
584
|
-
```svelte
|
|
585
|
-
<div class="flex flex-col justify-center items-center gap-4 py-8">
|
|
586
|
-
<span class="loading loading-spinner loading-lg"></span>
|
|
587
|
-
<p class="text-sm text-base-content/70">{translations.loading}</p>
|
|
588
|
-
</div>
|
|
589
|
-
```
|
|
590
|
-
|
|
591
|
-
### Skeleton Loading
|
|
592
|
-
|
|
593
|
-
```svelte
|
|
594
|
-
<div class="space-y-4">
|
|
595
|
-
<div class="skeleton h-4 w-full"></div>
|
|
596
|
-
<div class="skeleton h-4 w-3/4"></div>
|
|
597
|
-
<div class="skeleton h-32 w-full"></div>
|
|
598
|
-
</div>
|
|
599
|
-
```
|
|
600
|
-
|
|
601
|
-
### Progress Bar
|
|
602
|
-
|
|
603
|
-
```svelte
|
|
604
|
-
<progress
|
|
605
|
-
class="progress progress-primary w-full"
|
|
606
|
-
value={progress}
|
|
607
|
-
max="100"
|
|
608
|
-
></progress>
|
|
609
|
-
```
|
|
610
|
-
|
|
611
|
-
---
|
|
612
|
-
|
|
613
|
-
## Interaction Component Patterns
|
|
614
|
-
|
|
615
|
-
### Drag and Drop Component
|
|
616
|
-
|
|
617
|
-
```svelte
|
|
618
|
-
<script lang="ts">
|
|
619
|
-
import { touchDrag } from '../utils/touchDragHelper.js';
|
|
620
|
-
|
|
621
|
-
let draggedItem = $state<string | null>(null);
|
|
622
|
-
let hoveredZone = $state<string | null>(null);
|
|
623
|
-
|
|
624
|
-
const translations = $derived({
|
|
625
|
-
dragInstruction: i18n?.t('interactions.component.dragInstruction') ?? 'interactions.component.dragInstruction',
|
|
626
|
-
dropZone: i18n?.t('interactions.component.dropZone') ?? 'interactions.component.dropZone',
|
|
627
|
-
});
|
|
628
|
-
|
|
629
|
-
function handleDragStart(itemId: string) {
|
|
630
|
-
if (disabled) return;
|
|
631
|
-
draggedItem = itemId;
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
function handleDragEnd() {
|
|
635
|
-
draggedItem = null;
|
|
636
|
-
hoveredZone = null;
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
function handleDrop(event: DragEvent, zoneId: string) {
|
|
640
|
-
if (disabled || !draggedItem) return;
|
|
641
|
-
event.preventDefault();
|
|
642
|
-
|
|
643
|
-
// Process drop
|
|
644
|
-
onChange({ item: draggedItem, zone: zoneId });
|
|
645
|
-
|
|
646
|
-
draggedItem = null;
|
|
647
|
-
hoveredZone = null;
|
|
648
|
-
}
|
|
649
|
-
</script>
|
|
650
|
-
|
|
651
|
-
<!-- Draggable items -->
|
|
652
|
-
<button
|
|
653
|
-
type="button"
|
|
654
|
-
draggable={!disabled}
|
|
655
|
-
use:touchDrag
|
|
656
|
-
ondragstart={() => handleDragStart(item.id)}
|
|
657
|
-
ondragend={handleDragEnd}
|
|
658
|
-
class="btn btn-primary"
|
|
659
|
-
class:opacity-50={draggedItem === item.id}
|
|
660
|
-
aria-label="{item.label}. {translations.dragInstruction}"
|
|
661
|
-
>
|
|
662
|
-
{item.label}
|
|
663
|
-
</button>
|
|
664
|
-
|
|
665
|
-
<!-- Drop zone -->
|
|
666
|
-
<div
|
|
667
|
-
ondragover={(e) => { e.preventDefault(); hoveredZone = zone.id; }}
|
|
668
|
-
ondragleave={() => hoveredZone = null}
|
|
669
|
-
ondrop={(e) => handleDrop(e, zone.id)}
|
|
670
|
-
class="border-2 border-dashed rounded-lg p-4"
|
|
671
|
-
class:border-primary={hoveredZone === zone.id}
|
|
672
|
-
role="button"
|
|
673
|
-
tabindex="0"
|
|
674
|
-
aria-label={translations.dropZone}
|
|
675
|
-
>
|
|
676
|
-
{#if hoveredZone === zone.id}
|
|
677
|
-
<div class="text-primary">{translations.dropHere}</div>
|
|
678
|
-
{:else}
|
|
679
|
-
{zone.label}
|
|
680
|
-
{/if}
|
|
681
|
-
</div>
|
|
682
|
-
```
|
|
683
|
-
|
|
684
|
-
### Keyboard-Accessible Selection
|
|
685
|
-
|
|
686
|
-
```svelte
|
|
687
|
-
<script lang="ts">
|
|
688
|
-
let selectedId = $state<string | null>(null);
|
|
689
|
-
let announceText = $state<string>('');
|
|
690
|
-
|
|
691
|
-
const translations = $derived({
|
|
692
|
-
selected: (item: string) => i18n?.t('common.selected', { item }) ?? `common.selected (${item})`,
|
|
693
|
-
deselected: (item: string) => i18n?.t('common.deselected', { item }) ?? `common.deselected (${item})`,
|
|
694
|
-
});
|
|
695
|
-
|
|
696
|
-
function handleKeyDown(event: KeyboardEvent, itemId: string) {
|
|
697
|
-
if (disabled) return;
|
|
698
|
-
|
|
699
|
-
if (event.key === ' ' || event.key === 'Enter') {
|
|
700
|
-
event.preventDefault();
|
|
701
|
-
|
|
702
|
-
if (selectedId === itemId) {
|
|
703
|
-
selectedId = null;
|
|
704
|
-
announceText = translations.deselected(itemLabel);
|
|
705
|
-
} else {
|
|
706
|
-
selectedId = itemId;
|
|
707
|
-
announceText = translations.selected(itemLabel);
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
if (event.key === 'Escape' && selectedId) {
|
|
712
|
-
event.preventDefault();
|
|
713
|
-
selectedId = null;
|
|
714
|
-
announceText = i18n?.t('common.selectionCancelled') ?? 'common.selectionCancelled';
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
</script>
|
|
718
|
-
|
|
719
|
-
<!-- Screen reader announcements -->
|
|
720
|
-
<div aria-live="polite" aria-atomic="true" class="sr-only">
|
|
721
|
-
{announceText}
|
|
722
|
-
</div>
|
|
723
|
-
|
|
724
|
-
<!-- Selectable item -->
|
|
725
|
-
<button
|
|
726
|
-
type="button"
|
|
727
|
-
onkeydown={(e) => handleKeyDown(e, item.id)}
|
|
728
|
-
onclick={() => handleSelection(item.id)}
|
|
729
|
-
aria-pressed={selectedId === item.id}
|
|
730
|
-
class="btn"
|
|
731
|
-
class:btn-accent={selectedId === item.id}
|
|
732
|
-
class:btn-outline={selectedId !== item.id}
|
|
733
|
-
>
|
|
734
|
-
{item.label}
|
|
735
|
-
</button>
|
|
736
|
-
|
|
737
|
-
<style>
|
|
738
|
-
.sr-only {
|
|
739
|
-
position: absolute;
|
|
740
|
-
width: 1px;
|
|
741
|
-
height: 1px;
|
|
742
|
-
padding: 0;
|
|
743
|
-
margin: -1px;
|
|
744
|
-
overflow: hidden;
|
|
745
|
-
clip: rect(0, 0, 0, 0);
|
|
746
|
-
white-space: nowrap;
|
|
747
|
-
border-width: 0;
|
|
748
|
-
}
|
|
749
|
-
</style>
|
|
750
|
-
```
|
|
751
|
-
|
|
752
|
-
---
|
|
753
|
-
|
|
754
|
-
## Best Practices
|
|
755
|
-
|
|
756
|
-
### 1. Always Use Reactive Translations
|
|
757
|
-
|
|
758
|
-
```typescript
|
|
759
|
-
// ✅ CORRECT - Reactive translations update when locale changes
|
|
760
|
-
const translations = $derived({
|
|
761
|
-
label: i18n?.t('key') ?? 'key',
|
|
762
|
-
});
|
|
763
|
-
|
|
764
|
-
// ❌ INCORRECT - Won't update on locale change
|
|
765
|
-
const label = i18n?.t('key') ?? 'key';
|
|
766
|
-
```
|
|
767
|
-
|
|
768
|
-
### 2. Provide Descriptive Aria Labels
|
|
769
|
-
|
|
770
|
-
```svelte
|
|
771
|
-
<!-- ✅ CORRECT - Full context for screen readers -->
|
|
772
|
-
<button
|
|
773
|
-
aria-label="{item.label}. {translations.dragInstruction}. {translations.status}"
|
|
774
|
-
>
|
|
775
|
-
{item.label}
|
|
776
|
-
</button>
|
|
777
|
-
|
|
778
|
-
<!-- ❌ INCORRECT - Missing context -->
|
|
779
|
-
<button aria-label={item.label}>
|
|
780
|
-
{item.label}
|
|
781
|
-
</button>
|
|
782
|
-
```
|
|
783
|
-
|
|
784
|
-
### 3. Use SVG aria-hidden for Decorative Icons
|
|
785
|
-
|
|
786
|
-
```svelte
|
|
787
|
-
<!-- ✅ CORRECT - Decorative icon hidden from screen readers -->
|
|
788
|
-
<svg aria-hidden="true" class="w-6 h-6">...</svg>
|
|
789
|
-
|
|
790
|
-
<!-- ❌ INCORRECT - Screen reader will try to read the SVG -->
|
|
791
|
-
<svg class="w-6 h-6">...</svg>
|
|
792
|
-
```
|
|
793
|
-
|
|
794
|
-
### 4. Provide Screen Reader Announcements
|
|
795
|
-
|
|
796
|
-
```svelte
|
|
797
|
-
<script lang="ts">
|
|
798
|
-
let announceText = $state<string>('');
|
|
799
|
-
|
|
800
|
-
function handleAction() {
|
|
801
|
-
// Perform action
|
|
802
|
-
announceText = translations.actionCompleted;
|
|
803
|
-
}
|
|
804
|
-
</script>
|
|
805
|
-
|
|
806
|
-
<!-- Live region for announcements -->
|
|
807
|
-
<div aria-live="polite" aria-atomic="true" class="sr-only">
|
|
808
|
-
{announceText}
|
|
809
|
-
</div>
|
|
810
|
-
```
|
|
811
|
-
|
|
812
|
-
### 5. Use Semantic HTML
|
|
813
|
-
|
|
814
|
-
```svelte
|
|
815
|
-
<!-- ✅ CORRECT - Semantic button -->
|
|
816
|
-
<button type="button" onclick={handleClick}>
|
|
817
|
-
{label}
|
|
818
|
-
</button>
|
|
819
|
-
|
|
820
|
-
<!-- ❌ INCORRECT - div with click handler -->
|
|
821
|
-
<div onclick={handleClick}>
|
|
822
|
-
{label}
|
|
823
|
-
</div>
|
|
824
|
-
```
|
|
825
|
-
|
|
826
|
-
### 6. Handle Loading and Error States
|
|
827
|
-
|
|
828
|
-
```svelte
|
|
829
|
-
<script lang="ts">
|
|
830
|
-
let isLoading = $state(false);
|
|
831
|
-
let error = $state<string | null>(null);
|
|
832
|
-
let data = $state<Data | null>(null);
|
|
833
|
-
|
|
834
|
-
$effect(() => {
|
|
835
|
-
loadData();
|
|
836
|
-
});
|
|
837
|
-
|
|
838
|
-
async function loadData() {
|
|
839
|
-
isLoading = true;
|
|
840
|
-
error = null;
|
|
841
|
-
|
|
842
|
-
try {
|
|
843
|
-
data = await fetchData();
|
|
844
|
-
} catch (e) {
|
|
845
|
-
error = translations.loadError;
|
|
846
|
-
} finally {
|
|
847
|
-
isLoading = false;
|
|
848
|
-
}
|
|
849
|
-
}
|
|
850
|
-
</script>
|
|
851
|
-
|
|
852
|
-
{#if isLoading}
|
|
853
|
-
<div class="flex justify-center py-8">
|
|
854
|
-
<span class="loading loading-spinner loading-lg"></span>
|
|
855
|
-
</div>
|
|
856
|
-
{:else if error}
|
|
857
|
-
<div class="alert alert-error">
|
|
858
|
-
<span>{error}</span>
|
|
859
|
-
</div>
|
|
860
|
-
{:else if data}
|
|
861
|
-
<!-- Render data -->
|
|
862
|
-
{/if}
|
|
863
|
-
```
|
|
864
|
-
|
|
865
|
-
### 7. Consistent Spacing
|
|
866
|
-
|
|
867
|
-
```svelte
|
|
868
|
-
<!-- Use consistent spacing utilities -->
|
|
869
|
-
<div class="space-y-4"> <!-- Vertical spacing -->
|
|
870
|
-
<div class="flex gap-2"> <!-- Horizontal spacing -->
|
|
871
|
-
<button class="btn">Button 1</button>
|
|
872
|
-
<button class="btn">Button 2</button>
|
|
873
|
-
</div>
|
|
874
|
-
|
|
875
|
-
<div class="grid gap-4"> <!-- Grid spacing -->
|
|
876
|
-
<div>Item 1</div>
|
|
877
|
-
<div>Item 2</div>
|
|
878
|
-
</div>
|
|
879
|
-
</div>
|
|
880
|
-
```
|
|
881
|
-
|
|
882
|
-
---
|
|
883
|
-
|
|
884
|
-
## Summary
|
|
885
|
-
|
|
886
|
-
- **Always use Svelte 5 runes** (`$props`, `$state`, `$derived`, `$effect`)
|
|
887
|
-
- **i18n is optional** with key fallbacks (never English strings)
|
|
888
|
-
- **Use DaisyUI semantic classes** for consistent styling
|
|
889
|
-
- **Provide full accessibility** (aria-labels, keyboard navigation, screen reader support)
|
|
890
|
-
- **Handle all states** (loading, error, empty, success)
|
|
891
|
-
- **Use reactive translations** with `$derived`
|
|
892
|
-
- **Follow semantic HTML** best practices
|
|
893
|
-
|
|
894
|
-
For more information, see:
|
|
895
|
-
- [I18N_IMPLEMENTATION_PLAN.md](../../../I18N_IMPLEMENTATION_PLAN.md)
|
|
896
|
-
- [I18N_PROGRESS_SUMMARY.md](../../../I18N_PROGRESS_SUMMARY.md)
|