@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.
@@ -1,15 +1,47 @@
1
1
  <script lang="ts">
2
2
  import type { BadgeProperties } from './properties';
3
3
 
4
- let { image, value, classes }: BadgeProperties = $props();
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
- <div class="badge-icon {classes ?? ''}">
8
- <div class="badge-wrap">
9
- <img class="icon-img" src={image} alt="" />
10
- <div class="badge">{value}</div>
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
- </div>
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 BadgeProperties = {
2
- image: string;
3
- value: string;
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>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juspay/svelte-ui-components",
3
- "version": "2.53.0",
3
+ "version": "2.54.0",
4
4
  "description": "A themeable Svelte 5 UI component library with CSS custom property driven styling",
5
5
  "keywords": [
6
6
  "svelte",