@juspay/svelte-ui-components 2.53.0 → 2.54.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.
- package/dist/Badge/Badge.svelte +50 -6
- package/dist/Badge/properties.d.ts +12 -3
- package/package.json +1 -1
package/dist/Badge/Badge.svelte
CHANGED
|
@@ -1,15 +1,47 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { BadgeProperties } from './properties';
|
|
3
3
|
|
|
4
|
-
let {
|
|
4
|
+
let {
|
|
5
|
+
image,
|
|
6
|
+
alt = '',
|
|
7
|
+
value,
|
|
8
|
+
mode = 'count',
|
|
9
|
+
hidden = false,
|
|
10
|
+
ariaLabel,
|
|
11
|
+
testId,
|
|
12
|
+
classes
|
|
13
|
+
}: BadgeProperties = $props();
|
|
14
|
+
|
|
15
|
+
let showImage = $derived(typeof image === 'string' && image.length > 0);
|
|
16
|
+
let showBadge = $derived(!hidden);
|
|
17
|
+
let isDot = $derived(mode === 'dot');
|
|
18
|
+
|
|
19
|
+
let standaloneRole = $derived(isDot ? 'presentation' : 'status');
|
|
20
|
+
let standaloneAriaLabel = $derived(
|
|
21
|
+
isDot ? null : (ariaLabel ?? (typeof value === 'string' ? value : null))
|
|
22
|
+
);
|
|
5
23
|
</script>
|
|
6
24
|
|
|
7
|
-
|
|
8
|
-
<div class="badge-
|
|
9
|
-
<
|
|
10
|
-
|
|
25
|
+
{#if showImage}
|
|
26
|
+
<div class="badge-icon {classes ?? ''}" data-pw={typeof testId === 'string' ? testId : null}>
|
|
27
|
+
<div class="badge-wrap">
|
|
28
|
+
<img class="icon-img" src={image} {alt} />
|
|
29
|
+
{#if showBadge}
|
|
30
|
+
<div class="badge" class:badge-dot={isDot}>{isDot ? '' : (value ?? '')}</div>
|
|
31
|
+
{/if}
|
|
32
|
+
</div>
|
|
11
33
|
</div>
|
|
12
|
-
|
|
34
|
+
{:else if showBadge}
|
|
35
|
+
<div
|
|
36
|
+
class="badge badge-standalone {classes ?? ''}"
|
|
37
|
+
class:badge-dot={isDot}
|
|
38
|
+
role={standaloneRole}
|
|
39
|
+
aria-label={standaloneAriaLabel}
|
|
40
|
+
data-pw={typeof testId === 'string' ? testId : null}
|
|
41
|
+
>
|
|
42
|
+
{isDot ? '' : (value ?? '')}
|
|
43
|
+
</div>
|
|
44
|
+
{/if}
|
|
13
45
|
|
|
14
46
|
<style>
|
|
15
47
|
.badge-wrap {
|
|
@@ -42,6 +74,18 @@
|
|
|
42
74
|
z-index: 1;
|
|
43
75
|
}
|
|
44
76
|
|
|
77
|
+
.badge-dot {
|
|
78
|
+
width: var(--badge-dot-size, 10px);
|
|
79
|
+
height: var(--badge-dot-size, 10px);
|
|
80
|
+
min-width: unset;
|
|
81
|
+
min-height: unset;
|
|
82
|
+
padding: 0;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.badge-standalone {
|
|
86
|
+
position: var(--badge-standalone-position, static);
|
|
87
|
+
}
|
|
88
|
+
|
|
45
89
|
.icon-img {
|
|
46
90
|
border-radius: var(--badge-img-border-radius, 6px);
|
|
47
91
|
width: var(--badge-img-width, 64px);
|
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
export type
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export type BadgeMode = 'count' | 'dot';
|
|
2
|
+
export type BadgeProperties = MandatoryBadgeProperties & OptionalBadgeProperties & BadgeEventProperties;
|
|
3
|
+
export type MandatoryBadgeProperties = Record<never, never>;
|
|
4
|
+
export type OptionalBadgeProperties = {
|
|
5
|
+
image?: string;
|
|
6
|
+
alt?: string;
|
|
7
|
+
value?: string;
|
|
8
|
+
mode?: BadgeMode;
|
|
9
|
+
hidden?: boolean;
|
|
10
|
+
ariaLabel?: string;
|
|
11
|
+
testId?: string;
|
|
4
12
|
classes?: string;
|
|
5
13
|
};
|
|
14
|
+
export type BadgeEventProperties = Record<never, never>;
|