@r2digisolutions/components 0.21.29 → 0.21.31

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,7 +29,7 @@
29
29
  }: BarChartProps = $props();
30
30
 
31
31
  const W = 420;
32
- const pad = { t: 24, r: 12, b: 32, l: 12 };
32
+ const pad = { t: 24, r: 12, b: 40, l: 12 };
33
33
  const uid = `bc-${Math.random().toString(36).slice(2, 8)}`;
34
34
  const color = 'var(--color-brand-500, #6366f1)';
35
35
 
@@ -66,6 +66,10 @@
66
66
  };
67
67
  });
68
68
 
69
+ function axisLabel(label: string): string {
70
+ return label.length > 14 ? `${label.slice(0, 14)}…` : label;
71
+ }
72
+
69
73
  function select(i: number) {
70
74
  if (!interactive) return;
71
75
  tipIndex = tipIndex === i ? null : i;
@@ -109,8 +113,8 @@
109
113
  {formatTick(b.value, 0)}{unit}
110
114
  </text>
111
115
  {/if}
112
- <text x={b.cx} y={height - 8} text-anchor="middle" class="fill-muted" font-size="10">
113
- {b.label}
116
+ <text x={b.cx} y={height - 8} text-anchor="middle" class="fill-muted" font-size="12">
117
+ {axisLabel(b.label)}
114
118
  </text>
115
119
  {#if interactive}
116
120
  <!-- svelte-ignore a11y_no_static_element_interactions -->
@@ -13,6 +13,8 @@
13
13
  showLegend?: boolean;
14
14
  /** Max tick labels on the X axis (line/bar). */
15
15
  maxLabels?: number;
16
+ /** Draw numeric values on bars / near line points. */
17
+ showValues?: boolean;
16
18
  emptyLabel?: string;
17
19
  class?: string;
18
20
  }
@@ -23,6 +25,7 @@
23
25
  height = 180,
24
26
  showLegend = true,
25
27
  maxLabels = 7,
28
+ showValues = true,
26
29
  emptyLabel = 'No data',
27
30
  class: className = ''
28
31
  }: ChartProps = $props();
@@ -36,6 +39,9 @@
36
39
  '#a855f7'
37
40
  ];
38
41
 
42
+ /** Extra top space so bar value labels are not clipped. */
43
+ const valuePad = 16;
44
+
39
45
  const max = $derived(Math.max(...data.map((d) => d.value), 1));
40
46
  const total = $derived(data.reduce((s, d) => s + d.value, 0));
41
47
  const isEmpty = $derived(data.length === 0 || total === 0);
@@ -46,10 +52,11 @@
46
52
  if (data.length < 2) return '';
47
53
  const w = 320;
48
54
  const h = height - 28;
55
+ const top = showValues && data.length <= 14 ? 12 + valuePad : 12;
49
56
  return data
50
57
  .map((d, i) => {
51
58
  const x = 16 + (i / (data.length - 1)) * (w - 32);
52
- const y = 12 + (1 - d.value / max) * (h - 16);
59
+ const y = top + (1 - d.value / max) * (h - 16 - (top - 12));
53
60
  return `${x},${y}`;
54
61
  })
55
62
  .join(' ');
@@ -63,14 +70,23 @@
63
70
  const denom = total || 1;
64
71
  return data.map((d, i) => {
65
72
  const slice = (d.value / denom) * Math.PI * 2;
66
- const x1 = cx + r * Math.cos(angle);
67
- const y1 = cy + r * Math.sin(angle);
73
+ const start = angle;
74
+ const x1 = cx + r * Math.cos(start);
75
+ const y1 = cy + r * Math.sin(start);
68
76
  angle += slice;
69
77
  const x2 = cx + r * Math.cos(angle);
70
78
  const y2 = cy + r * Math.sin(angle);
71
79
  const large = slice > Math.PI ? 1 : 0;
80
+ // Full circle: start===end so a single arc is invisible — use two semicircles.
81
+ const full = slice >= Math.PI * 2 - 1e-6;
82
+ const mid = start + Math.PI;
83
+ const xMid = cx + r * Math.cos(mid);
84
+ const yMid = cy + r * Math.sin(mid);
85
+ const dPath = full
86
+ ? `M ${cx} ${cy} L ${x1} ${y1} A ${r} ${r} 0 1 1 ${xMid} ${yMid} A ${r} ${r} 0 1 1 ${x1} ${y1} Z`
87
+ : `M ${cx} ${cy} L ${x1} ${y1} A ${r} ${r} 0 ${large} 1 ${x2} ${y2} Z`;
72
88
  return {
73
- d: `M ${cx} ${cy} L ${x1} ${y1} A ${r} ${r} 0 ${large} 1 ${x2} ${y2} Z`,
89
+ d: dPath,
74
90
  color: d.color ?? palette[i % palette.length],
75
91
  label: d.label,
76
92
  value: d.value
@@ -82,6 +98,10 @@
82
98
  if (data.length <= maxLabels) return true;
83
99
  return i % labelStep === 0 || i === data.length - 1;
84
100
  }
101
+
102
+ function axisLabel(label: string): string {
103
+ return label.length > 12 ? `${label.slice(0, 11)}…` : label;
104
+ }
85
105
  </script>
86
106
 
87
107
  <div class={['relative w-full space-y-3', className]}>
@@ -101,10 +121,10 @@
101
121
  role="img"
102
122
  aria-label="Bar chart"
103
123
  >
104
- {#each data as d, i}
124
+ {#each data as d, i (i)}
105
125
  {@const bw = Math.max(8, (320 - 32) / Math.max(data.length, 1) - 6)}
106
126
  {@const x = 16 + i * ((320 - 32) / Math.max(data.length, 1))}
107
- {@const bh = ((d.value / max) * (height - 36)) || 0}
127
+ {@const bh = (d.value / max) * (height - 36 - valuePad) || 0}
108
128
  {@const y = height - 20 - bh}
109
129
  <rect
110
130
  {x}
@@ -115,6 +135,16 @@
115
135
  fill={d.color ?? palette[i % palette.length]}
116
136
  opacity="0.9"
117
137
  />
138
+ {#if showValues}
139
+ <text
140
+ x={x + bw / 2}
141
+ y={y - 4}
142
+ text-anchor="middle"
143
+ class="fill-secondary text-[10px] font-semibold"
144
+ >
145
+ {d.value}
146
+ </text>
147
+ {/if}
118
148
  {#if showLabel(i)}
119
149
  <text
120
150
  x={x + bw / 2}
@@ -122,7 +152,7 @@
122
152
  text-anchor="middle"
123
153
  class="fill-muted text-[9px]"
124
154
  >
125
- {d.label}
155
+ {axisLabel(d.label)}
126
156
  </text>
127
157
  {/if}
128
158
  {/each}
@@ -154,21 +184,34 @@
154
184
  stroke-linecap="round"
155
185
  stroke-linejoin="round"
156
186
  />
157
- {#each data as d, i}
187
+ {#each data as d, i (i)}
188
+ {@const top = showValues && data.length <= 14 ? 12 + valuePad : 12}
158
189
  {@const x = 16 + (i / Math.max(data.length - 1, 1)) * 288}
159
- {@const y = 12 + (1 - d.value / max) * (height - 44)}
190
+ {@const y = top + (1 - d.value / max) * (height - 32 - top)}
160
191
  {#if data.length <= 14}
161
192
  <circle cx={x} cy={y} r="2.5" fill={palette[0]} />
162
193
  {/if}
194
+ {#if showValues && data.length <= 14}
195
+ <text
196
+ x={x}
197
+ y={y - 8}
198
+ text-anchor="middle"
199
+ class="fill-secondary text-[10px] font-semibold"
200
+ >
201
+ {d.value}
202
+ </text>
203
+ {/if}
163
204
  {#if showLabel(i)}
164
- <text x={x} y={height - 4} text-anchor="middle" class="fill-muted text-[9px]">{d.label}</text>
205
+ <text x={x} y={height - 4} text-anchor="middle" class="fill-muted text-[9px]"
206
+ >{axisLabel(d.label)}</text
207
+ >
165
208
  {/if}
166
209
  {/each}
167
210
  </svg>
168
211
  {:else}
169
212
  <div class="flex flex-wrap items-center gap-4">
170
213
  <svg viewBox="0 0 180 180" class="h-44 w-44" role="img" aria-label="Donut chart">
171
- {#each arcs as a}
214
+ {#each arcs as a (a.label)}
172
215
  <path d={a.d} fill={a.color} />
173
216
  {/each}
174
217
  <circle cx="90" cy="90" r="42" class="fill-surface-elevated" />
@@ -182,7 +225,7 @@
182
225
 
183
226
  {#if showLegend && !isEmpty}
184
227
  <ul class="flex flex-wrap gap-3">
185
- {#each data as d, i}
228
+ {#each data as d, i (i)}
186
229
  <li class="text-secondary inline-flex items-center gap-1.5 text-xs">
187
230
  <span
188
231
  class="h-2.5 w-2.5 rounded-full"
@@ -11,6 +11,8 @@ interface ChartProps {
11
11
  showLegend?: boolean;
12
12
  /** Max tick labels on the X axis (line/bar). */
13
13
  maxLabels?: number;
14
+ /** Draw numeric values on bars / near line points. */
15
+ showValues?: boolean;
14
16
  emptyLabel?: string;
15
17
  class?: string;
16
18
  }
@@ -64,16 +64,33 @@
64
64
  const iy1 = cy + innerR * Math.sin(angle);
65
65
  const ix2 = cx + innerR * Math.cos(start);
66
66
  const iy2 = cy + innerR * Math.sin(start);
67
+ // Full circle: start===end so a single arc is invisible — use two semicircles.
68
+ const full = slice >= Math.PI * 2 - 1e-6;
69
+ const mid = start + Math.PI;
70
+ const oxMid = cx + r * Math.cos(mid);
71
+ const oyMid = cy + r * Math.sin(mid);
72
+ const ixMid = cx + innerR * Math.cos(mid);
73
+ const iyMid = cy + innerR * Math.sin(mid);
67
74
  const path =
68
75
  slice <= 0
69
76
  ? ''
70
- : [
71
- `M ${x1} ${y1}`,
72
- `A ${r} ${r} 0 ${large} 1 ${x2} ${y2}`,
73
- `L ${ix1} ${iy1}`,
74
- `A ${innerR} ${innerR} 0 ${large} 0 ${ix2} ${iy2}`,
75
- 'Z'
76
- ].join(' ');
77
+ : full
78
+ ? [
79
+ `M ${x1} ${y1}`,
80
+ `A ${r} ${r} 0 1 1 ${oxMid} ${oyMid}`,
81
+ `A ${r} ${r} 0 1 1 ${x1} ${y1}`,
82
+ `L ${ix2} ${iy2}`,
83
+ `A ${innerR} ${innerR} 0 1 0 ${ixMid} ${iyMid}`,
84
+ `A ${innerR} ${innerR} 0 1 0 ${ix2} ${iy2}`,
85
+ 'Z'
86
+ ].join(' ')
87
+ : [
88
+ `M ${x1} ${y1}`,
89
+ `A ${r} ${r} 0 ${large} 1 ${x2} ${y2}`,
90
+ `L ${ix1} ${iy1}`,
91
+ `A ${innerR} ${innerR} 0 ${large} 0 ${ix2} ${iy2}`,
92
+ 'Z'
93
+ ].join(' ');
77
94
  return {
78
95
  ...d,
79
96
  value,
@@ -4,7 +4,8 @@
4
4
  >
5
5
  import type { Snippet } from 'svelte';
6
6
  import { setContext, untrack } from 'svelte';
7
- import type { RemoteFormInput } from '@sveltejs/kit';
7
+ import type { ClassValue } from 'svelte/elements';
8
+ import type { RemoteFormInput, RemoteQueryUpdate } from '@sveltejs/kit';
8
9
  import Alert from '../Alert/Alert.svelte';
9
10
  import {
10
11
  FORM_CONTEXT_KEY,
@@ -35,6 +36,24 @@
35
36
  * @default true
36
37
  */
37
38
  syncRemoteIssues?: boolean;
39
+ /**
40
+ * When `false`, skip Kit's default `invalidateAll()` after a successful remote form
41
+ * (via `submit().updates()`). Prefer {@link updates} to refresh specific queries.
42
+ * @default true
43
+ */
44
+ invalidateAll?: boolean;
45
+ /**
46
+ * Single-flight query refreshes. Passing this (even `[]`) opts out of `invalidateAll`.
47
+ * @see https://svelte.dev/docs/kit/remote-functions#Single-flight-mutations
48
+ */
49
+ updates?: RemoteQueryUpdate[];
50
+ onSuccess?: (result?: any) => void | Promise<void>;
51
+ onError?: (error: string) => void;
52
+ beforeSubmit?: () => void | Promise<void>;
53
+ /** Bind the underlying `<form>` (e.g. Dialog footer `formRef.requestSubmit()`). */
54
+ formRef?: HTMLFormElement | null;
55
+ id?: string;
56
+ enctype?: 'application/x-www-form-urlencoded' | 'multipart/form-data' | 'text/plain';
38
57
  /** Optional bag for submit/remote result exposed in context */
39
58
  result?: TOutput;
40
59
  title?: string;
@@ -43,7 +62,7 @@
43
62
  showErrorSummary?: boolean;
44
63
  errorSummaryTitle?: string;
45
64
  gap?: 'sm' | 'md' | 'lg';
46
- class?: string;
65
+ class?: ClassValue;
47
66
  children?: Snippet;
48
67
  header?: Snippet;
49
68
  footer?: Snippet;
@@ -54,10 +73,18 @@
54
73
  let {
55
74
  data = $bindable<TData>({} as TData),
56
75
  errors = $bindable<FormErrors>({}),
57
- loading = false,
76
+ loading = $bindable(false),
58
77
  disabled = false,
59
78
  remote = null,
60
79
  syncRemoteIssues = true,
80
+ invalidateAll = true,
81
+ updates,
82
+ onSuccess,
83
+ onError,
84
+ beforeSubmit,
85
+ formRef = $bindable<HTMLFormElement | null>(null),
86
+ id,
87
+ enctype,
61
88
  result = $bindable<TOutput | undefined>(undefined),
62
89
  title,
63
90
  description,
@@ -93,6 +120,9 @@
93
120
  lg: 'space-y-6'
94
121
  } as const;
95
122
 
123
+ /** Client-side ceiling so a hung remote cannot leave Save spinning forever. */
124
+ const SUBMIT_TIMEOUT_MS = 90_000;
125
+
96
126
  function setError(name: string, message: string) {
97
127
  errors = { ...errors, [name]: message };
98
128
  }
@@ -153,10 +183,12 @@
153
183
  getData
154
184
  } satisfies FormContext<TData, TOutput>);
155
185
 
156
- if (kitForm && !didInitRemoteFormId) {
186
+ $effect(() => {
187
+ const form = kitForm;
188
+ if (!form || didInitRemoteFormId) return;
157
189
  didInitRemoteFormId = true;
158
- remoteFormId = untrack(() => getRemoteFormId(kitForm.action));
159
- }
190
+ remoteFormId = untrack(() => getRemoteFormId(form.action));
191
+ });
160
192
 
161
193
  function syncRemoteIssuesNow() {
162
194
  if (!kitForm || !syncRemoteIssues) return;
@@ -173,6 +205,10 @@
173
205
 
174
206
  let formEl = $state<HTMLFormElement | null>(null);
175
207
 
208
+ $effect(() => {
209
+ formRef = formEl;
210
+ });
211
+
176
212
  $effect(() => {
177
213
  const el = formEl;
178
214
  if (!el || !isRemote) return;
@@ -192,6 +228,130 @@
192
228
  el.addEventListener('submit', onSubmit);
193
229
  return () => el.removeEventListener('submit', onSubmit);
194
230
  });
231
+
232
+ function isKitRedirect(err: unknown): boolean {
233
+ return Boolean(err && typeof err === 'object' && 'location' in err && 'status' in err);
234
+ }
235
+
236
+ function formatValidationIssues(): string {
237
+ if (!kitForm) return '';
238
+ const issues = kitForm.fields.allIssues?.();
239
+ if (!issues?.length) return '';
240
+ return issues
241
+ .map((issue) => {
242
+ const path = issue.path?.length ? issue.path.join('.') : 'formulario';
243
+ return `${path}: ${issue.message}`;
244
+ })
245
+ .join(' · ');
246
+ }
247
+
248
+ function withTimeout<T>(promise: Promise<T>, ms: number, message: string): Promise<T> {
249
+ return new Promise<T>((resolve, reject) => {
250
+ const timer = setTimeout(() => reject(new Error(message)), ms);
251
+ promise.then(
252
+ (value) => {
253
+ clearTimeout(timer);
254
+ resolve(value);
255
+ },
256
+ (err) => {
257
+ clearTimeout(timer);
258
+ reject(err);
259
+ }
260
+ );
261
+ });
262
+ }
263
+
264
+ /** Kit: `submit().updates(...)` (even empty) prevents the default invalidateAll waterfall. */
265
+ function runSubmit(
266
+ submit: () => Promise<boolean> & {
267
+ updates: (...args: RemoteQueryUpdate[]) => Promise<boolean>;
268
+ }
269
+ ) {
270
+ if (updates) return submit().updates(...updates);
271
+ if (!invalidateAll) return submit().updates();
272
+ return submit();
273
+ }
274
+
275
+ function reportError(message: string) {
276
+ submitted = true;
277
+ setError('_form', message);
278
+ onError?.(message);
279
+ }
280
+
281
+ async function handleRemoteEnhance(submit: () => Promise<boolean> & {
282
+ updates: (...args: RemoteQueryUpdate[]) => Promise<boolean>;
283
+ }) {
284
+ if (!kitForm) return;
285
+ try {
286
+ loading = true;
287
+ clearErrors();
288
+ await beforeSubmit?.();
289
+ const ok = await withTimeout(
290
+ runSubmit(submit),
291
+ SUBMIT_TIMEOUT_MS,
292
+ 'La operación ha tardado demasiado. Comprueba la conexión e inténtalo de nuevo.'
293
+ );
294
+ const results = kitForm.result;
295
+ result = results as TOutput | undefined;
296
+ if (!ok) {
297
+ syncRemoteIssuesNow();
298
+ const issueSummary = formatValidationIssues();
299
+ const message = issueSummary || 'Revisa los errores del formulario.';
300
+ submitted = true;
301
+ // Field issues already land in `errors`; only use `_form` when none were mapped.
302
+ if (!issueSummary) setError('_form', message);
303
+ onError?.(message);
304
+ } else if (results && typeof results === 'object' && 'error' in results && results.error) {
305
+ const err = results.error;
306
+ const message =
307
+ typeof err === 'string'
308
+ ? err
309
+ : err instanceof Error
310
+ ? err.message
311
+ : typeof err === 'object' && err !== null && 'message' in err
312
+ ? String((err as { message?: unknown }).message)
313
+ : 'Ha ocurrido un error al guardar.';
314
+ reportError(message);
315
+ } else {
316
+ // Clear busy UI before onSuccess — invalidateAll/refresh must not leave Save spinning.
317
+ loading = false;
318
+ try {
319
+ await onSuccess?.(results);
320
+ } catch (successErr) {
321
+ console.error('[Form] onSuccess failed', successErr);
322
+ }
323
+ }
324
+ } catch (e) {
325
+ if (isKitRedirect(e)) throw e;
326
+ const raw = e instanceof Error ? e.message : '';
327
+ let message: string;
328
+ if (/413|Payload Too Large|BODY_SIZE_LIMIT|exceeds limit|Content-length/i.test(raw)) {
329
+ message = 'El archivo es demasiado grande. Prueba con una imagen de menos de 8 MB.';
330
+ } else if (/502|504|Bad Gateway|Gateway Timeout|Failed to fetch|NetworkError/i.test(raw)) {
331
+ message =
332
+ 'No se pudo completar la subida (error de red o servidor). Prueba de nuevo en unos segundos.';
333
+ } else if (!raw || /unexpected error/i.test(raw)) {
334
+ message = 'Ha ocurrido un error inesperado. Inténtalo de nuevo.';
335
+ } else {
336
+ message = raw;
337
+ }
338
+ reportError(message);
339
+ } finally {
340
+ loading = false;
341
+ }
342
+ }
343
+
344
+ /**
345
+ * Full Kit `RemoteForm` → own `.enhance` (invalidateAll / updates / callbacks).
346
+ * Already-enhanced spread → caller owns enhance; pass through unchanged.
347
+ */
348
+ function remoteFormAttrs(): object {
349
+ if (!remote) return {};
350
+ if (!kitForm) return remote as object;
351
+ return kitForm.enhance(async ({ submit }) => {
352
+ await handleRemoteEnhance(submit);
353
+ }) as object;
354
+ }
195
355
  </script>
196
356
 
197
357
  {#snippet fields()}
@@ -236,7 +396,9 @@
236
396
  {#if isRemote}
237
397
  <form
238
398
  bind:this={formEl}
239
- {...(remote as object)}
399
+ {...remoteFormAttrs()}
400
+ {id}
401
+ {enctype}
240
402
  class={['w-full', gaps[gap], className]}
241
403
  novalidate
242
404
  aria-busy={busy || undefined}
@@ -245,6 +407,9 @@
245
407
  </form>
246
408
  {:else}
247
409
  <form
410
+ bind:this={formEl}
411
+ {id}
412
+ {enctype}
248
413
  class={['w-full', gaps[gap], className]}
249
414
  onsubmit={handleSubmit}
250
415
  novalidate
@@ -1,5 +1,6 @@
1
1
  import type { Snippet } from 'svelte';
2
- import type { RemoteFormInput } from '@sveltejs/kit';
2
+ import type { ClassValue } from 'svelte/elements';
3
+ import type { RemoteFormInput, RemoteQueryUpdate } from '@sveltejs/kit';
3
4
  import { type FormDataValues, type FormErrors, type FormRemote } from '../../../utils/formContext.js';
4
5
  declare function $$render<TData extends FormDataValues = FormDataValues, TInput extends RemoteFormInput | void = RemoteFormInput, TOutput = unknown>(): {
5
6
  props: {
@@ -19,6 +20,24 @@ declare function $$render<TData extends FormDataValues = FormDataValues, TInput
19
20
  * @default true
20
21
  */
21
22
  syncRemoteIssues?: boolean;
23
+ /**
24
+ * When `false`, skip Kit's default `invalidateAll()` after a successful remote form
25
+ * (via `submit().updates()`). Prefer {@link updates} to refresh specific queries.
26
+ * @default true
27
+ */
28
+ invalidateAll?: boolean;
29
+ /**
30
+ * Single-flight query refreshes. Passing this (even `[]`) opts out of `invalidateAll`.
31
+ * @see https://svelte.dev/docs/kit/remote-functions#Single-flight-mutations
32
+ */
33
+ updates?: RemoteQueryUpdate[];
34
+ onSuccess?: (result?: any) => void | Promise<void>;
35
+ onError?: (error: string) => void;
36
+ beforeSubmit?: () => void | Promise<void>;
37
+ /** Bind the underlying `<form>` (e.g. Dialog footer `formRef.requestSubmit()`). */
38
+ formRef?: HTMLFormElement | null;
39
+ id?: string;
40
+ enctype?: "application/x-www-form-urlencoded" | "multipart/form-data" | "text/plain";
22
41
  /** Optional bag for submit/remote result exposed in context */
23
42
  result?: TOutput;
24
43
  title?: string;
@@ -27,7 +46,7 @@ declare function $$render<TData extends FormDataValues = FormDataValues, TInput
27
46
  showErrorSummary?: boolean;
28
47
  errorSummaryTitle?: string;
29
48
  gap?: "sm" | "md" | "lg";
30
- class?: string;
49
+ class?: ClassValue;
31
50
  children?: Snippet;
32
51
  header?: Snippet;
33
52
  footer?: Snippet;
@@ -35,7 +54,7 @@ declare function $$render<TData extends FormDataValues = FormDataValues, TInput
35
54
  onsubmit?: (e: SubmitEvent) => void;
36
55
  };
37
56
  exports: {};
38
- bindings: "data" | "errors" | "result";
57
+ bindings: "loading" | "data" | "errors" | "formRef" | "result";
39
58
  slots: {};
40
59
  events: {};
41
60
  };
@@ -43,7 +62,7 @@ declare class __sveltets_Render<TData extends FormDataValues = FormDataValues, T
43
62
  props(): ReturnType<typeof $$render<TData, TInput, TOutput>>['props'];
44
63
  events(): ReturnType<typeof $$render<TData, TInput, TOutput>>['events'];
45
64
  slots(): ReturnType<typeof $$render<TData, TInput, TOutput>>['slots'];
46
- bindings(): "data" | "errors" | "result";
65
+ bindings(): "loading" | "data" | "errors" | "formRef" | "result";
47
66
  exports(): {};
48
67
  }
49
68
  interface $$IsomorphicComponent {
@@ -11,6 +11,8 @@
11
11
  data?: HBarPoint[];
12
12
  /** Bar track width in viewBox units */
13
13
  barWidth?: number;
14
+ /** Left label column width in viewBox units */
15
+ labelWidth?: number;
14
16
  rowHeight?: number;
15
17
  interactive?: boolean;
16
18
  showValues?: boolean;
@@ -21,6 +23,7 @@
21
23
  const {
22
24
  data = [],
23
25
  barWidth = 280,
26
+ labelWidth = 88,
24
27
  rowHeight = 36,
25
28
  interactive = true,
26
29
  showValues = true,
@@ -29,10 +32,10 @@
29
32
  }: HorizontalBarChartProps = $props();
30
33
 
31
34
  const color = 'var(--color-brand-500, #6366f1)';
32
- const labelW = 88;
33
35
  const padR = 48;
34
- const W = $derived(labelW + barWidth + padR);
36
+ const W = $derived(labelWidth + barWidth + padR);
35
37
  const H = $derived(Math.max(data.length, 1) * rowHeight + 8);
38
+ const maxLabelChars = $derived(Math.floor(labelWidth / 6.5));
36
39
 
37
40
  let tipIndex = $state<number | null>(null);
38
41
 
@@ -47,6 +50,12 @@
47
50
  })
48
51
  );
49
52
 
53
+ function displayLabel(label: string): string {
54
+ const maxChars = maxLabelChars;
55
+ if (label.length <= maxChars) return label;
56
+ return `${label.slice(0, Math.max(0, maxChars - 1))}…`;
57
+ }
58
+
50
59
  function select(i: number) {
51
60
  if (!interactive) return;
52
61
  tipIndex = tipIndex === i ? null : i;
@@ -60,18 +69,18 @@
60
69
  role="img"
61
70
  aria-label="Horizontal bar chart"
62
71
  >
63
- {#each rows as r, i}
72
+ {#each rows as r, i (i)}
64
73
  <text
65
- x={labelW - 8}
74
+ x={labelWidth - 8}
66
75
  y={r.midY + 4}
67
76
  text-anchor="end"
68
77
  class="fill-secondary"
69
78
  font-size="11"
70
79
  >
71
- {r.label}
80
+ {displayLabel(r.label)}
72
81
  </text>
73
82
  <rect
74
- x={labelW}
83
+ x={labelWidth}
75
84
  y={r.y + 4}
76
85
  width={barWidth}
77
86
  height={rowHeight - 14}
@@ -80,7 +89,7 @@
80
89
  opacity="0.6"
81
90
  />
82
91
  <rect
83
- x={labelW}
92
+ x={labelWidth}
84
93
  y={r.y + 4}
85
94
  width={r.bw}
86
95
  height={rowHeight - 14}
@@ -91,7 +100,7 @@
91
100
  />
92
101
  {#if showValues}
93
102
  <text
94
- x={labelW + r.bw + 6}
103
+ x={labelWidth + r.bw + 6}
95
104
  y={r.midY + 4}
96
105
  class="fill-muted"
97
106
  font-size="10"
@@ -102,6 +111,7 @@
102
111
  {/if}
103
112
  {#if interactive}
104
113
  <!-- svelte-ignore a11y_no_static_element_interactions -->
114
+ <!-- svelte-ignore a11y_click_events_have_key_events -->
105
115
  <rect
106
116
  x={0}
107
117
  y={r.y}
@@ -119,7 +129,7 @@
119
129
  {@const t = rows[tipIndex]}
120
130
  <div
121
131
  class="pointer-events-none absolute z-10 rounded-lg border border-border bg-surface-elevated px-2.5 py-1.5 shadow-lg"
122
- style:left={`${((labelW + t.bw) / W) * 100}%`}
132
+ style:left={`${((labelWidth + t.bw) / W) * 100}%`}
123
133
  style:top={`${(t.y / H) * 100}%`}
124
134
  role="status"
125
135
  >
@@ -7,6 +7,8 @@ interface HorizontalBarChartProps {
7
7
  data?: HBarPoint[];
8
8
  /** Bar track width in viewBox units */
9
9
  barWidth?: number;
10
+ /** Left label column width in viewBox units */
11
+ labelWidth?: number;
10
12
  rowHeight?: number;
11
13
  interactive?: boolean;
12
14
  showValues?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@r2digisolutions/components",
3
- "version": "0.21.29",
3
+ "version": "0.21.31",
4
4
  "private": false,
5
5
  "description": "R2DigiSolutions Svelte 5 component library — Atomic Design, Tailwind 4, Light/Dark mode",
6
6
  "license": "MIT",