@r2digisolutions/components 0.21.6 → 0.21.8

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.
@@ -11,6 +11,9 @@
11
11
  data?: ChartPoint[];
12
12
  height?: number;
13
13
  showLegend?: boolean;
14
+ /** Max tick labels on the X axis (line/bar). */
15
+ maxLabels?: number;
16
+ emptyLabel?: string;
14
17
  class?: string;
15
18
  }
16
19
 
@@ -19,6 +22,8 @@
19
22
  data = [],
20
23
  height = 180,
21
24
  showLegend = true,
25
+ maxLabels = 7,
26
+ emptyLabel = 'No data',
22
27
  class: className = ''
23
28
  }: ChartProps = $props();
24
29
 
@@ -32,16 +37,19 @@
32
37
  ];
33
38
 
34
39
  const max = $derived(Math.max(...data.map((d) => d.value), 1));
35
- const total = $derived(data.reduce((s, d) => s + d.value, 0) || 1);
40
+ const total = $derived(data.reduce((s, d) => s + d.value, 0));
41
+ const isEmpty = $derived(data.length === 0 || total === 0);
42
+
43
+ const labelStep = $derived(Math.max(1, Math.ceil(data.length / maxLabels)));
36
44
 
37
45
  const linePoints = $derived.by(() => {
38
46
  if (data.length < 2) return '';
39
47
  const w = 320;
40
- const h = height - 24;
48
+ const h = height - 28;
41
49
  return data
42
50
  .map((d, i) => {
43
51
  const x = 16 + (i / (data.length - 1)) * (w - 32);
44
- const y = 8 + (1 - d.value / max) * (h - 16);
52
+ const y = 12 + (1 - d.value / max) * (h - 16);
45
53
  return `${x},${y}`;
46
54
  })
47
55
  .join(' ');
@@ -52,8 +60,9 @@
52
60
  const cy = 90;
53
61
  const r = 70;
54
62
  let angle = -Math.PI / 2;
63
+ const denom = total || 1;
55
64
  return data.map((d, i) => {
56
- const slice = (d.value / total) * Math.PI * 2;
65
+ const slice = (d.value / denom) * Math.PI * 2;
57
66
  const x1 = cx + r * Math.cos(angle);
58
67
  const y1 = cy + r * Math.sin(angle);
59
68
  angle += slice;
@@ -68,21 +77,33 @@
68
77
  };
69
78
  });
70
79
  });
80
+
81
+ function showLabel(i: number): boolean {
82
+ if (data.length <= maxLabels) return true;
83
+ return i % labelStep === 0 || i === data.length - 1;
84
+ }
71
85
  </script>
72
86
 
73
- <div class={['w-full space-y-3', className]}>
74
- {#if type === 'bar'}
87
+ <div class={['relative w-full space-y-3', className]}>
88
+ {#if isEmpty && type !== 'donut'}
89
+ <div
90
+ class="border-border bg-surface-overlay/40 text-muted flex items-center justify-center rounded-xl border border-dashed text-sm"
91
+ style:height={`${height}px`}
92
+ >
93
+ {emptyLabel}
94
+ </div>
95
+ {:else if type === 'bar'}
75
96
  <svg
76
97
  viewBox={`0 0 320 ${height}`}
77
- preserveAspectRatio="none"
98
+ preserveAspectRatio="xMidYMid meet"
78
99
  class="block w-full"
79
100
  style:height={`${height}px`}
80
101
  role="img"
81
102
  aria-label="Bar chart"
82
103
  >
83
104
  {#each data as d, i}
84
- {@const bw = Math.max(12, (320 - 32) / data.length - 8)}
85
- {@const x = 16 + i * ((320 - 32) / data.length)}
105
+ {@const bw = Math.max(8, (320 - 32) / Math.max(data.length, 1) - 6)}
106
+ {@const x = 16 + i * ((320 - 32) / Math.max(data.length, 1))}
86
107
  {@const bh = ((d.value / max) * (height - 36)) || 0}
87
108
  {@const y = height - 20 - bh}
88
109
  <rect
@@ -90,37 +111,58 @@
90
111
  {y}
91
112
  width={bw}
92
113
  height={bh}
93
- rx="6"
114
+ rx="4"
94
115
  fill={d.color ?? palette[i % palette.length]}
95
116
  opacity="0.9"
96
117
  />
97
- <text x={x + bw / 2} y={height - 6} text-anchor="middle" class="fill-muted text-[10px]">
98
- {d.label}
99
- </text>
118
+ {#if showLabel(i)}
119
+ <text
120
+ x={x + bw / 2}
121
+ y={height - 6}
122
+ text-anchor="middle"
123
+ class="fill-muted text-[9px]"
124
+ >
125
+ {d.label}
126
+ </text>
127
+ {/if}
100
128
  {/each}
101
129
  </svg>
102
130
  {:else if type === 'line'}
103
131
  <svg
104
132
  viewBox={`0 0 320 ${height}`}
105
- preserveAspectRatio="none"
133
+ preserveAspectRatio="xMidYMid meet"
106
134
  class="block w-full"
107
135
  style:height={`${height}px`}
108
136
  role="img"
109
137
  aria-label="Line chart"
110
138
  >
139
+ <!-- baseline -->
140
+ <line
141
+ x1="16"
142
+ y1={height - 16}
143
+ x2="304"
144
+ y2={height - 16}
145
+ stroke="currentColor"
146
+ class="text-border"
147
+ stroke-width="1"
148
+ />
111
149
  <polyline
112
150
  points={linePoints}
113
151
  fill="none"
114
152
  stroke={palette[0]}
115
- stroke-width="2.5"
153
+ stroke-width="2"
116
154
  stroke-linecap="round"
117
155
  stroke-linejoin="round"
118
156
  />
119
157
  {#each data as d, i}
120
158
  {@const x = 16 + (i / Math.max(data.length - 1, 1)) * 288}
121
- {@const y = 8 + (1 - d.value / max) * (height - 40)}
122
- <circle cx={x} cy={y} r="3.5" fill={palette[0]} />
123
- <text x={x} y={height - 4} text-anchor="middle" class="fill-muted text-[10px]">{d.label}</text>
159
+ {@const y = 12 + (1 - d.value / max) * (height - 44)}
160
+ {#if data.length <= 14}
161
+ <circle cx={x} cy={y} r="2.5" fill={palette[0]} />
162
+ {/if}
163
+ {#if showLabel(i)}
164
+ <text x={x} y={height - 4} text-anchor="middle" class="fill-muted text-[9px]">{d.label}</text>
165
+ {/if}
124
166
  {/each}
125
167
  </svg>
126
168
  {:else}
@@ -138,17 +180,17 @@
138
180
  </div>
139
181
  {/if}
140
182
 
141
- {#if showLegend}
183
+ {#if showLegend && !isEmpty}
142
184
  <ul class="flex flex-wrap gap-3">
143
185
  {#each data as d, i}
144
- <li class="inline-flex items-center gap-1.5 text-xs text-secondary">
186
+ <li class="text-secondary inline-flex items-center gap-1.5 text-xs">
145
187
  <span
146
188
  class="h-2.5 w-2.5 rounded-full"
147
189
  style:background={d.color ?? palette[i % palette.length]}
148
190
  aria-hidden="true"
149
191
  ></span>
150
192
  {d.label}
151
- <span class="font-medium text-primary">{d.value}</span>
193
+ <span class="text-primary font-medium">{d.value}</span>
152
194
  </li>
153
195
  {/each}
154
196
  </ul>
@@ -9,6 +9,9 @@ interface ChartProps {
9
9
  data?: ChartPoint[];
10
10
  height?: number;
11
11
  showLegend?: boolean;
12
+ /** Max tick labels on the X axis (line/bar). */
13
+ maxLabels?: number;
14
+ emptyLabel?: string;
12
15
  class?: string;
13
16
  }
14
17
  declare const Chart: import("svelte").Component<ChartProps, {}, "">;
@@ -166,7 +166,17 @@
166
166
  }
167
167
 
168
168
  function handleSubmit(e: SubmitEvent) {
169
- if (isRemote) {
169
+ e.preventDefault();
170
+ submitted = true;
171
+ onsubmit?.(e);
172
+ }
173
+
174
+ let formEl = $state<HTMLFormElement | null>(null);
175
+
176
+ $effect(() => {
177
+ const el = formEl;
178
+ if (!el || !isRemote) return;
179
+ const onSubmit = () => {
170
180
  submitted = true;
171
181
  queueMicrotask(() => {
172
182
  const check = () => {
@@ -178,22 +188,13 @@
178
188
  };
179
189
  check();
180
190
  });
181
- // Do not preventDefault — Kit remote attachment owns progressive enhancement.
182
- return;
183
- }
184
- e.preventDefault();
185
- submitted = true;
186
- onsubmit?.(e);
187
- }
191
+ };
192
+ el.addEventListener('submit', onSubmit);
193
+ return () => el.removeEventListener('submit', onSubmit);
194
+ });
188
195
  </script>
189
196
 
190
- <form
191
- {...(remote as object | null)}
192
- class={['w-full', gaps[gap], className]}
193
- onsubmit={handleSubmit}
194
- novalidate
195
- aria-busy={busy || undefined}
196
- >
197
+ {#snippet fields()}
197
198
  {#if header}
198
199
  {@render header()}
199
200
  {:else if title || description}
@@ -230,4 +231,25 @@
230
231
  {@render footer()}
231
232
  </div>
232
233
  {/if}
233
- </form>
234
+ {/snippet}
235
+
236
+ {#if isRemote}
237
+ <form
238
+ bind:this={formEl}
239
+ {...(remote as object)}
240
+ class={['w-full', gaps[gap], className]}
241
+ novalidate
242
+ aria-busy={busy || undefined}
243
+ >
244
+ {@render fields()}
245
+ </form>
246
+ {:else}
247
+ <form
248
+ class={['w-full', gaps[gap], className]}
249
+ onsubmit={handleSubmit}
250
+ novalidate
251
+ aria-busy={busy || undefined}
252
+ >
253
+ {@render fields()}
254
+ </form>
255
+ {/if}
@@ -23,7 +23,11 @@
23
23
  onchange
24
24
  }: SegmentedControlProps = $props();
25
25
 
26
- const active = $derived(value || items.find((i) => !i.disabled)?.id || '');
26
+ /** Avoid `$derived` here: SSR with async parent snippets has flaked on `$.derived` (undefined). */
27
+ function getActive() {
28
+ const list = Array.isArray(items) ? items : [];
29
+ return value || list.find((i) => !i.disabled)?.id || '';
30
+ }
27
31
 
28
32
  const sizeClasses = {
29
33
  sm: 'h-7 px-2.5 text-xs',
@@ -47,17 +51,18 @@
47
51
  role="radiogroup"
48
52
  >
49
53
  {#each items as item (item.id)}
54
+ {@const isActive = getActive() === item.id}
50
55
  <button
51
56
  type="button"
52
57
  role="radio"
53
- aria-checked={active === item.id}
58
+ aria-checked={isActive}
54
59
  disabled={item.disabled}
55
60
  onclick={() => select(item.id, item.disabled)}
56
61
  class={[
57
62
  'rounded-lg font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand-500/30',
58
63
  sizeClasses[size],
59
64
  fullWidth && 'flex-1',
60
- active === item.id
65
+ isActive
61
66
  ? 'bg-brand-500 text-white shadow-sm'
62
67
  : 'text-secondary hover:bg-surface-elevated/70 hover:text-primary',
63
68
  item.disabled && 'cursor-not-allowed opacity-40'
@@ -162,7 +162,7 @@
162
162
  emptyTitle = 'No analytics yet',
163
163
  emptyDescription = 'Connect a data source or wait for traffic to populate this page.',
164
164
  class: className = '',
165
- actions,
165
+ actions: actionsProp,
166
166
  onperiodchange,
167
167
  onexport
168
168
  }: AnalyticsPageProps = $props();
@@ -204,8 +204,8 @@
204
204
  Export
205
205
  </Button>
206
206
  {/if}
207
- {#if actions}
208
- {@render actions()}
207
+ {#if actionsProp}
208
+ {@render actionsProp()}
209
209
  {/if}
210
210
  </div>
211
211
  {/snippet}
@@ -67,7 +67,7 @@
67
67
  emptyDescription = 'Try another search term or upload new files.',
68
68
  showSelectedBar = true,
69
69
  class: className = '',
70
- actions,
70
+ actions: actionsProp,
71
71
  emptyAction,
72
72
  onconfirm,
73
73
  oncancel,
@@ -151,8 +151,8 @@
151
151
  <div class={['mx-auto flex w-full max-w-3xl flex-col gap-5', className]}>
152
152
  <PageHeader {title} description={subtitle}>
153
153
  {#snippet actions()}
154
- {#if actions}
155
- {@render actions()}
154
+ {#if actionsProp}
155
+ {@render actionsProp()}
156
156
  {:else if onupload}
157
157
  <Button size="sm" variant="secondary" onclick={() => onupload?.()}>Upload</Button>
158
158
  {/if}
@@ -119,7 +119,7 @@
119
119
  { id: 'delete', label: 'Delete', variant: 'destructive', confirm: true }
120
120
  ],
121
121
  class: className = '',
122
- actions,
122
+ actions: actionsProp,
123
123
  toolbar,
124
124
  sidebar,
125
125
  emptyAction,
@@ -246,8 +246,8 @@
246
246
  <div class={['relative mx-auto w-full max-w-6xl space-y-5 pb-16', className]}>
247
247
  <PageHeader {title} {description} {breadcrumbs}>
248
248
  {#snippet actions()}
249
- {#if actions}
250
- {@render actions()}
249
+ {#if actionsProp}
250
+ {@render actionsProp()}
251
251
  {:else}
252
252
  <Button size="sm" variant="secondary" onclick={() => onadd?.()}>{addLabel}</Button>
253
253
  {/if}
@@ -57,7 +57,7 @@
57
57
  emptyTitle = 'Nothing here yet',
58
58
  emptyDescription = 'Connect a data source to populate this dashboard.',
59
59
  class: className = '',
60
- actions,
60
+ actions: actionsProp,
61
61
  primary,
62
62
  secondary,
63
63
  footer,
@@ -90,8 +90,8 @@
90
90
  onchange={(id) => onperiodchange?.(id)}
91
91
  />
92
92
  {/if}
93
- {#if actions}
94
- {@render actions()}
93
+ {#if actionsProp}
94
+ {@render actionsProp()}
95
95
  {/if}
96
96
  </div>
97
97
  {/snippet}
@@ -59,7 +59,7 @@
59
59
  searchPlaceholder = 'Search…',
60
60
  framed = true,
61
61
  class: className = '',
62
- actions,
62
+ actions: actionsProp,
63
63
  toolbar,
64
64
  children,
65
65
  emptyAction,
@@ -78,8 +78,8 @@
78
78
  <div class={['mx-auto w-full max-w-6xl space-y-6', className]}>
79
79
  <PageHeader {title} {description} {breadcrumbs}>
80
80
  {#snippet actions()}
81
- {#if actions}
82
- {@render actions()}
81
+ {#if actionsProp}
82
+ {@render actionsProp()}
83
83
  {/if}
84
84
  {/snippet}
85
85
  </PageHeader>
@@ -108,7 +108,7 @@
108
108
  emptyTitle = 'Start exploring',
109
109
  emptyDescription = 'Search above or pick a recent query to discover content.',
110
110
  class: className = '',
111
- actions,
111
+ actions: actionsProp,
112
112
  emptyAction,
113
113
  onsearch,
114
114
  onselect,
@@ -206,8 +206,8 @@
206
206
  <div class={['mx-auto w-full max-w-5xl space-y-5', className]}>
207
207
  <PageHeader {title} {description} {breadcrumbs}>
208
208
  {#snippet actions()}
209
- {#if actions}
210
- {@render actions()}
209
+ {#if actionsProp}
210
+ {@render actionsProp()}
211
211
  {/if}
212
212
  {/snippet}
213
213
  </PageHeader>
@@ -80,7 +80,7 @@
80
80
  query = $bindable(''),
81
81
  showLegend = true,
82
82
  class: className = '',
83
- actions,
83
+ actions: actionsProp,
84
84
  onchange,
85
85
  onreset
86
86
  }: PermissionsMatrixProps = $props();
@@ -172,8 +172,8 @@
172
172
  {#if onreset}
173
173
  <Button size="sm" variant="ghost" onclick={() => onreset?.()}>Reset</Button>
174
174
  {/if}
175
- {#if actions}
176
- {@render actions()}
175
+ {#if actionsProp}
176
+ {@render actionsProp()}
177
177
  {/if}
178
178
  </div>
179
179
  {/snippet}
@@ -131,7 +131,7 @@
131
131
  emptyTasksTitle = 'No tasks yet',
132
132
  emptyTasksDescription = 'Create work items to track progress on this project.',
133
133
  class: className = '',
134
- actions,
134
+ actions: actionsProp,
135
135
  sidebar,
136
136
  ontoggleTask,
137
137
  onclickTask,
@@ -197,8 +197,8 @@
197
197
  </div>
198
198
  {/snippet}
199
199
  {#snippet actions()}
200
- {#if actions}
201
- {@render actions()}
200
+ {#if actionsProp}
201
+ {@render actionsProp()}
202
202
  {:else}
203
203
  {#if members.length}
204
204
  <AvatarGroup items={avatarItems} max={4} size="sm" />
@@ -207,7 +207,7 @@
207
207
  maxDate,
208
208
  locale = 'en',
209
209
  class: className = '',
210
- actions,
210
+ actions: actionsProp,
211
211
  ondatechange,
212
212
  onrangechange,
213
213
  ondurationchange,
@@ -431,8 +431,8 @@
431
431
  <div class={['mx-auto w-full max-w-6xl space-y-5', className]}>
432
432
  <PageHeader {title} {description}>
433
433
  {#snippet actions()}
434
- {#if actions}
435
- {@render actions()}
434
+ {#if actionsProp}
435
+ {@render actionsProp()}
436
436
  {/if}
437
437
  {/snippet}
438
438
  </PageHeader>
@@ -40,7 +40,7 @@
40
40
  query = $bindable(''),
41
41
  empty = false,
42
42
  class: className = '',
43
- actions,
43
+ actions: actionsProp,
44
44
  oninvite,
45
45
  onmember
46
46
  }: TeamPageProps = $props();
@@ -60,8 +60,8 @@
60
60
  <div class={['w-full space-y-5', className]}>
61
61
  <PageHeader {title} {description} {breadcrumbs}>
62
62
  {#snippet actions()}
63
- {#if actions}
64
- {@render actions()}
63
+ {#if actionsProp}
64
+ {@render actionsProp()}
65
65
  {:else}
66
66
  <Button size="sm" onclick={() => oninvite?.()}>Invite</Button>
67
67
  {/if}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@r2digisolutions/components",
3
- "version": "0.21.6",
3
+ "version": "0.21.8",
4
4
  "private": false,
5
5
  "description": "R2DigiSolutions Svelte 5 component library — Atomic Design, Tailwind 4, Light/Dark mode",
6
6
  "license": "MIT",