@juspay/svelte-ui-components 2.39.0 → 2.41.0
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.
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { EmptyStateProperties } from './properties';
|
|
3
3
|
|
|
4
|
-
let {
|
|
4
|
+
let {
|
|
5
|
+
title,
|
|
6
|
+
description,
|
|
7
|
+
icon,
|
|
8
|
+
children,
|
|
9
|
+
classes,
|
|
10
|
+
testId,
|
|
11
|
+
titleSnippet,
|
|
12
|
+
descriptionSnippet
|
|
13
|
+
}: EmptyStateProperties = $props();
|
|
5
14
|
</script>
|
|
6
15
|
|
|
7
16
|
<div class="empty-state {classes ?? ''}" data-pw={typeof testId === 'string' ? testId : null}>
|
|
@@ -10,8 +19,18 @@
|
|
|
10
19
|
{@render icon()}
|
|
11
20
|
</div>
|
|
12
21
|
{/if}
|
|
13
|
-
<div class="empty-state-title">
|
|
14
|
-
|
|
22
|
+
<div class="empty-state-title">
|
|
23
|
+
{#if typeof titleSnippet === 'function'}
|
|
24
|
+
{@render titleSnippet()}
|
|
25
|
+
{:else}
|
|
26
|
+
{title}
|
|
27
|
+
{/if}
|
|
28
|
+
</div>
|
|
29
|
+
{#if typeof descriptionSnippet === 'function'}
|
|
30
|
+
<div class="empty-state-description">
|
|
31
|
+
{@render descriptionSnippet()}
|
|
32
|
+
</div>
|
|
33
|
+
{:else if typeof description === 'string' && description.length > 0}
|
|
15
34
|
<div class="empty-state-description">{description}</div>
|
|
16
35
|
{/if}
|
|
17
36
|
{#if typeof children === 'function'}
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
export type EmptyStateProperties = MandatoryEmptyStateProperties & OptionalEmptyStateProperties;
|
|
3
3
|
export type MandatoryEmptyStateProperties = {
|
|
4
|
+
/**
|
|
5
|
+
* Fallback text title rendered when `titleSnippet` is not provided.
|
|
6
|
+
* This prop is required for backward-compatibility. When `titleSnippet` is supplied,
|
|
7
|
+
* `title` is still required by TypeScript but its value is not rendered — the snippet
|
|
8
|
+
* takes priority. Pass an empty string (`title=""`) as the minimal valid value when
|
|
9
|
+
* using `titleSnippet`.
|
|
10
|
+
*/
|
|
4
11
|
title: string;
|
|
5
12
|
};
|
|
6
13
|
export type OptionalEmptyStateProperties = {
|
|
@@ -9,4 +16,17 @@ export type OptionalEmptyStateProperties = {
|
|
|
9
16
|
children?: Snippet;
|
|
10
17
|
classes?: string;
|
|
11
18
|
testId?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Optional snippet that replaces the `title` string at render time.
|
|
21
|
+
* When provided, the mandatory `title` prop is still required for backward-compatibility
|
|
22
|
+
* but its value is not rendered — the snippet takes full priority.
|
|
23
|
+
* Use this when the title needs rich markup (e.g. formatted text, icons inline).
|
|
24
|
+
*/
|
|
25
|
+
titleSnippet?: Snippet;
|
|
26
|
+
/**
|
|
27
|
+
* Optional snippet that replaces the `description` string at render time.
|
|
28
|
+
* When provided, `description` is silently discarded — only one is rendered.
|
|
29
|
+
* Use this when the description needs rich markup (e.g. links, emphasis).
|
|
30
|
+
*/
|
|
31
|
+
descriptionSnippet?: Snippet;
|
|
12
32
|
};
|
package/dist/Gauge/Gauge.svelte
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { GaugeProperties } from './properties';
|
|
3
3
|
|
|
4
|
-
let {
|
|
4
|
+
let {
|
|
5
|
+
value,
|
|
6
|
+
max = 100,
|
|
7
|
+
showLabel = true,
|
|
8
|
+
labelFormatter,
|
|
9
|
+
testId,
|
|
10
|
+
classes
|
|
11
|
+
}: GaugeProperties = $props();
|
|
5
12
|
|
|
6
13
|
const VIEW_BOX = 100;
|
|
7
14
|
const CENTER = VIEW_BOX / 2;
|
|
@@ -9,11 +16,25 @@
|
|
|
9
16
|
const RADIUS = (VIEW_BOX - STROKE) / 2;
|
|
10
17
|
const CIRCUMFERENCE = 2 * Math.PI * RADIUS;
|
|
11
18
|
|
|
12
|
-
|
|
19
|
+
// Guard against max=0 (division by zero yields NaN or Infinity).
|
|
20
|
+
// When max is 0 or negative the gauge renders empty (0%).
|
|
21
|
+
let clamped = $derived(max > 0 ? Math.min(100, Math.max(0, (value / max) * 100)) : 0);
|
|
13
22
|
let offset = $derived(CIRCUMFERENCE - (clamped / 100) * CIRCUMFERENCE);
|
|
23
|
+
// labelFormatter receives the raw (value, max) pair so callers have full
|
|
24
|
+
// context. The built-in fallback shows the computed percentage string
|
|
25
|
+
// (e.g. value=50, max=200 → "25%").
|
|
26
|
+
let labelText = $derived(labelFormatter ? labelFormatter(value, max) : `${Math.round(clamped)}%`);
|
|
14
27
|
</script>
|
|
15
28
|
|
|
16
|
-
<div
|
|
29
|
+
<div
|
|
30
|
+
class="gauge {classes ?? ''}"
|
|
31
|
+
data-pw={typeof testId === 'string' ? testId : null}
|
|
32
|
+
role="progressbar"
|
|
33
|
+
aria-valuenow={clamped}
|
|
34
|
+
aria-valuemin={0}
|
|
35
|
+
aria-valuemax={100}
|
|
36
|
+
aria-label="gauge"
|
|
37
|
+
>
|
|
17
38
|
<svg viewBox="0 0 {VIEW_BOX} {VIEW_BOX}">
|
|
18
39
|
<circle class="track" cx={CENTER} cy={CENTER} r={RADIUS} fill="none" />
|
|
19
40
|
<circle
|
|
@@ -29,7 +50,7 @@
|
|
|
29
50
|
/>
|
|
30
51
|
</svg>
|
|
31
52
|
{#if showLabel}
|
|
32
|
-
<div class="label">{
|
|
53
|
+
<div class="label">{labelText}</div>
|
|
33
54
|
{/if}
|
|
34
55
|
</div>
|
|
35
56
|
|
|
@@ -3,7 +3,21 @@ export type MandatoryGaugeProperties = {
|
|
|
3
3
|
value: number;
|
|
4
4
|
};
|
|
5
5
|
export type OptionalGaugeProperties = {
|
|
6
|
+
/**
|
|
7
|
+
* The maximum value of the gauge. `value` is divided by `max` to compute
|
|
8
|
+
* the fill percentage, so `<Gauge value={50} max={200} />` renders at 25%.
|
|
9
|
+
* Defaults to `100` (making `value` a direct percentage). When `max` is 0
|
|
10
|
+
* or negative the gauge renders empty (0%) to avoid division by zero.
|
|
11
|
+
* @default 100
|
|
12
|
+
*/
|
|
13
|
+
max?: number;
|
|
6
14
|
showLabel?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Custom label renderer called with the raw `(value, max)` pair. Return any
|
|
17
|
+
* string to replace the default `"${Math.round(percentage)}%"` label.
|
|
18
|
+
* Example: `labelFormatter={(v, m) => \`${v} / ${m}\`}` shows "50 / 200".
|
|
19
|
+
*/
|
|
20
|
+
labelFormatter?: (value: number, max: number) => string;
|
|
7
21
|
testId?: string;
|
|
8
22
|
classes?: string;
|
|
9
23
|
};
|