@juspay/svelte-ui-components 2.38.0 → 2.40.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,21 +1,60 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { AccordionProperties } from './properties';
|
|
3
3
|
|
|
4
|
-
let {
|
|
4
|
+
let {
|
|
5
|
+
expand = $bindable(false),
|
|
6
|
+
children,
|
|
7
|
+
trigger,
|
|
8
|
+
ontoggle,
|
|
9
|
+
triggerClasses,
|
|
10
|
+
classes,
|
|
11
|
+
testId
|
|
12
|
+
}: AccordionProperties = $props();
|
|
13
|
+
|
|
14
|
+
function handleTriggerClick(): void {
|
|
15
|
+
expand = !expand;
|
|
16
|
+
ontoggle?.(expand);
|
|
17
|
+
}
|
|
5
18
|
</script>
|
|
6
19
|
|
|
7
|
-
|
|
20
|
+
{#if trigger}
|
|
21
|
+
<div
|
|
22
|
+
class="accordion-trigger {triggerClasses ?? ''}"
|
|
23
|
+
role="button"
|
|
24
|
+
tabindex="0"
|
|
25
|
+
aria-expanded={expand}
|
|
26
|
+
onclick={handleTriggerClick}
|
|
27
|
+
onkeydown={(event) => {
|
|
28
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
29
|
+
event.preventDefault();
|
|
30
|
+
handleTriggerClick();
|
|
31
|
+
}
|
|
32
|
+
}}
|
|
33
|
+
>
|
|
34
|
+
{@render trigger({ expanded: expand })}
|
|
35
|
+
</div>
|
|
36
|
+
{/if}
|
|
37
|
+
|
|
38
|
+
<div
|
|
39
|
+
class="accordion {classes ?? ''}"
|
|
40
|
+
class:expanded={expand}
|
|
41
|
+
data-pw={typeof testId === 'string' ? testId : null}
|
|
42
|
+
>
|
|
8
43
|
<div class="accordion-content">
|
|
9
44
|
{@render children?.()}
|
|
10
45
|
</div>
|
|
11
46
|
</div>
|
|
12
47
|
|
|
13
48
|
<style>
|
|
49
|
+
.accordion-trigger {
|
|
50
|
+
cursor: var(--accordion-trigger-cursor, pointer);
|
|
51
|
+
}
|
|
52
|
+
|
|
14
53
|
.accordion {
|
|
15
54
|
display: grid;
|
|
16
55
|
grid-template-rows: 0fr;
|
|
17
56
|
overflow: hidden;
|
|
18
|
-
transition: grid-template-rows 0.2s ease-out;
|
|
57
|
+
transition: grid-template-rows var(--accordion-transition, 0.2s ease-out);
|
|
19
58
|
}
|
|
20
59
|
|
|
21
60
|
.accordion.expanded {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { AccordionProperties } from './properties';
|
|
2
|
-
declare const Accordion: import("svelte").Component<AccordionProperties, {}, "">;
|
|
2
|
+
declare const Accordion: import("svelte").Component<AccordionProperties, {}, "expand">;
|
|
3
3
|
type Accordion = ReturnType<typeof Accordion>;
|
|
4
4
|
export default Accordion;
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
|
-
export type AccordionProperties =
|
|
2
|
+
export type AccordionProperties = OptionalAccordionProperties & AccordionEventProperties;
|
|
3
|
+
export type OptionalAccordionProperties = {
|
|
3
4
|
expand?: boolean;
|
|
4
5
|
children?: Snippet;
|
|
6
|
+
trigger?: Snippet<[{
|
|
7
|
+
expanded: boolean;
|
|
8
|
+
}]>;
|
|
9
|
+
triggerClasses?: string;
|
|
5
10
|
classes?: string;
|
|
11
|
+
testId?: string;
|
|
12
|
+
};
|
|
13
|
+
export type AccordionEventProperties = {
|
|
14
|
+
ontoggle?: (expanded: boolean) => void;
|
|
6
15
|
};
|
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
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -78,6 +78,7 @@ export type * from './Toolbar/properties';
|
|
|
78
78
|
export type * from './Carousel/properties';
|
|
79
79
|
export type * from './Badge/properties';
|
|
80
80
|
export type * from './Banner/properties';
|
|
81
|
+
export type * from './Accordion/properties';
|
|
81
82
|
export type * from './Table/properties';
|
|
82
83
|
export type * from './Stepper/properties';
|
|
83
84
|
export type * from './Toast/properties';
|