@juspay/svelte-ui-components 2.40.0 → 2.42.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 { title, description, icon, children, classes, testId }: EmptyStateProperties = $props();
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">{title}</div>
14
- {#if typeof description === 'string' && description.length > 0}
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
  };
@@ -17,9 +17,12 @@
17
17
  testId,
18
18
  itemTestId,
19
19
  onchange,
20
+ onopen,
21
+ onclose,
20
22
  classes,
21
23
  open = $bindable(false),
22
- dropdownAlign = 'left'
24
+ dropdownAlign = 'left',
25
+ hierarchy = 'default'
23
26
  }: SelectProperties = $props();
24
27
 
25
28
  function normalizeItems(source: SelectItem[] | string[]): SelectItem[] {
@@ -65,6 +68,7 @@
65
68
  return;
66
69
  }
67
70
  open = true;
71
+ onopen?.();
68
72
  highlightedIndex = -1;
69
73
  query = '';
70
74
  if (searchable) {
@@ -77,6 +81,7 @@
77
81
 
78
82
  function close(): void {
79
83
  open = false;
84
+ onclose?.();
80
85
  query = '';
81
86
  highlightedIndex = -1;
82
87
  }
@@ -208,7 +213,7 @@
208
213
  }
209
214
  query = event.target.value;
210
215
  if (!open) {
211
- open = true;
216
+ openDropdown();
212
217
  }
213
218
  highlightedIndex = -1;
214
219
  }
@@ -233,6 +238,9 @@
233
238
  document.addEventListener('click', handleClickOutside);
234
239
  return () => {
235
240
  document.removeEventListener('click', handleClickOutside);
241
+ if (open) {
242
+ onclose?.();
243
+ }
236
244
  };
237
245
  });
238
246
  </script>
@@ -241,6 +249,7 @@
241
249
  class="select {classes ?? ''}"
242
250
  class:open
243
251
  class:disabled
252
+ class:ghost={hierarchy === 'ghost'}
244
253
  bind:this={containerEl}
245
254
  {...typeof testId === 'string' ? { 'data-pw': testId } : {}}
246
255
  >
@@ -552,4 +561,22 @@
552
561
  --pill-padding: var(--select-pill-padding, 2px 8px);
553
562
  --pill-font-size: var(--select-pill-font-size, 13px);
554
563
  }
564
+
565
+ /* Ghost hierarchy: transparent, borderless trigger */
566
+ .select.ghost .select-trigger {
567
+ background: var(--select-ghost-trigger-background, transparent);
568
+ border-color: var(--select-ghost-trigger-border-color, transparent);
569
+ box-shadow: none;
570
+ }
571
+
572
+ .select.ghost .select-trigger:hover:not(.disabled .select-trigger) {
573
+ border-color: var(--select-ghost-trigger-hover-border-color, transparent);
574
+ background: var(--select-ghost-trigger-hover-background, rgba(0, 0, 0, 0.04));
575
+ }
576
+
577
+ .select.ghost.open .select-trigger {
578
+ border-color: var(--select-ghost-trigger-open-border-color, transparent);
579
+ background: var(--select-ghost-trigger-open-background, rgba(0, 0, 0, 0.06));
580
+ box-shadow: none;
581
+ }
555
582
  </style>
@@ -9,6 +9,7 @@ export type SelectItem = {
9
9
  export type MandatorySelectProperties = {
10
10
  items: SelectItem[] | string[];
11
11
  };
12
+ export type SelectHierarchy = 'default' | 'ghost';
12
13
  export type OptionalSelectProperties = {
13
14
  value?: string[];
14
15
  multiple?: boolean;
@@ -32,7 +33,11 @@ export type OptionalSelectProperties = {
32
33
  value: string[];
33
34
  items: SelectItem[];
34
35
  }]>;
36
+ /** Visual hierarchy of the trigger. `'ghost'` renders a transparent, borderless trigger — useful when the Select is embedded in a toolbar or header where a full bordered input would be visually heavy. Defaults to `'default'`. */
37
+ hierarchy?: SelectHierarchy;
35
38
  };
36
39
  export type SelectEventProperties = {
37
40
  onchange?: (value: string[]) => void;
41
+ onopen?: () => void;
42
+ onclose?: () => void;
38
43
  };
@@ -1,20 +1,33 @@
1
1
  <script lang="ts">
2
2
  import type { ToggleProperties } from './properties';
3
3
 
4
- let { checked = false, text = '', classes, onclick }: ToggleProperties = $props();
4
+ let {
5
+ checked = false,
6
+ text = '',
7
+ disabled = false,
8
+ testId,
9
+ classes,
10
+ onclick
11
+ }: ToggleProperties = $props();
5
12
 
6
- function handleCheckboxClick(e: MouseEvent): void {
13
+ const handleCheckboxClick = (e: MouseEvent): void => {
7
14
  if (e.target instanceof HTMLInputElement && typeof e.target.checked === 'boolean') {
8
15
  checked = e.target.checked;
9
16
  }
10
17
  onclick?.(checked);
11
- }
18
+ };
12
19
  </script>
13
20
 
14
- <div class="container {classes ?? ''}">
21
+ <div class="container {classes ?? ''}" class:disabled aria-disabled={disabled} data-pw={testId}>
15
22
  <div class="text" hidden={text.length === 0}>{text}</div>
16
23
  <label class="switch">
17
- <input class="input-checkbox" type="checkbox" {checked} onclick={handleCheckboxClick} />
24
+ <input
25
+ class="input-checkbox"
26
+ type="checkbox"
27
+ {checked}
28
+ {disabled}
29
+ onclick={handleCheckboxClick}
30
+ />
18
31
  <span class="slider round"></span>
19
32
  </label>
20
33
  </div>
@@ -26,6 +39,12 @@
26
39
  gap: var(--toggle-container-gap, 8px);
27
40
  }
28
41
 
42
+ .container.disabled {
43
+ opacity: var(--toggle-disabled-opacity, 0.4);
44
+ cursor: not-allowed;
45
+ pointer-events: none;
46
+ }
47
+
29
48
  .text {
30
49
  font-size: var(--toggle-text-font-size, 14px);
31
50
  font-weight: var(--toggle-text-font-weight, 400);
@@ -1,6 +1,9 @@
1
- export type ToggleProperties = ToggleEventProperties & {
1
+ export type ToggleProperties = OptionalToggleProperties & ToggleEventProperties;
2
+ export type OptionalToggleProperties = {
3
+ text?: string;
2
4
  checked?: boolean;
3
- text: string;
5
+ disabled?: boolean;
6
+ testId?: string;
4
7
  classes?: string;
5
8
  };
6
9
  export type ToggleEventProperties = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juspay/svelte-ui-components",
3
- "version": "2.40.0",
3
+ "version": "2.42.0",
4
4
  "description": "A themeable Svelte 5 UI component library with CSS custom property driven styling",
5
5
  "keywords": [
6
6
  "svelte",