@juspay/svelte-ui-components 2.21.0 → 2.22.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,10 +1,32 @@
1
1
  <script lang="ts">
2
2
  import type { CardProperties } from './properties';
3
3
 
4
- let { children, title, description, classes }: CardProperties = $props();
4
+ let { children, title, description, classes, testId, onclick }: CardProperties = $props();
5
+
6
+ const isInteractive = $derived(typeof onclick === 'function');
7
+
8
+ function handleKeydown(event: KeyboardEvent): void {
9
+ if (event.key === 'Enter' || event.key === ' ') {
10
+ if (event.key === ' ') {
11
+ event.preventDefault();
12
+ }
13
+ if (event.currentTarget instanceof HTMLElement) {
14
+ event.currentTarget.click();
15
+ }
16
+ }
17
+ }
5
18
  </script>
6
19
 
7
- <div class="card {classes ?? ''}">
20
+ <!-- svelte-ignore a11y_no_noninteractive_tabindex -->
21
+ <div
22
+ class="card {classes ?? ''}"
23
+ class:card-interactive={isInteractive}
24
+ data-pw={typeof testId === 'string' ? testId : null}
25
+ role={isInteractive ? 'button' : null}
26
+ tabindex={isInteractive ? 0 : null}
27
+ onclick={isInteractive ? onclick : null}
28
+ onkeydown={isInteractive ? handleKeydown : null}
29
+ >
8
30
  {#if typeof title === 'string' && title.length > 0}
9
31
  <div class="card-header">
10
32
  <div class="card-title">{title}</div>
@@ -25,6 +47,16 @@
25
47
  border-radius: var(--card-border-radius, 8px);
26
48
  overflow: var(--card-overflow, hidden);
27
49
  color: inherit;
50
+ cursor: var(--card-cursor, inherit);
51
+ }
52
+
53
+ .card-interactive {
54
+ cursor: var(--card-cursor, pointer);
55
+ }
56
+
57
+ .card-interactive:focus-visible {
58
+ outline: var(--card-focus-outline, 2px solid currentColor);
59
+ outline-offset: var(--card-focus-outline-offset, 2px);
28
60
  }
29
61
 
30
62
  .card-header {
@@ -7,4 +7,13 @@ export type OptionalCardProperties = {
7
7
  title?: string;
8
8
  description?: string;
9
9
  classes?: string;
10
+ /** Renders as `data-pw` on the root element for Playwright test selection. */
11
+ testId?: string;
12
+ /**
13
+ * When provided the root element becomes interactive:
14
+ * `role="button"`, `tabindex=0`, and keydown (Enter/Space) triggers the handler.
15
+ * When omitted the root is a plain `<div>` with no interactive attributes,
16
+ * so existing consumers see zero behaviour change.
17
+ */
18
+ onclick?: (event: MouseEvent) => void;
10
19
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juspay/svelte-ui-components",
3
- "version": "2.21.0",
3
+ "version": "2.22.0",
4
4
  "description": "A themeable Svelte 5 UI component library with CSS custom property driven styling",
5
5
  "keywords": [
6
6
  "svelte",