@juspay/svelte-ui-components 2.21.0 → 2.22.1
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/Card/Card.svelte +34 -2
- package/dist/Card/properties.d.ts +9 -0
- package/dist/Tabs/Tabs.svelte +61 -14
- package/dist/Tabs/Tabs.svelte.d.ts +1 -1
- package/dist/Tabs/properties.d.ts +10 -1
- package/package.json +1 -1
package/dist/Card/Card.svelte
CHANGED
|
@@ -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
|
-
|
|
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/dist/Tabs/Tabs.svelte
CHANGED
|
@@ -1,20 +1,45 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import type { TabsProperties } from './properties';
|
|
2
|
+
import type { TabItem, TabsProperties } from './properties';
|
|
3
3
|
import chevronLeftSvg from '../assets/chevron-left.svg?raw';
|
|
4
4
|
import chevronRightSvg from '../assets/chevron-right.svg?raw';
|
|
5
5
|
|
|
6
6
|
let {
|
|
7
7
|
items,
|
|
8
|
-
activeIndex = 0,
|
|
8
|
+
activeIndex = $bindable(0),
|
|
9
|
+
activeKey,
|
|
9
10
|
disabled = false,
|
|
10
11
|
testId,
|
|
11
12
|
scrollLeftIcon,
|
|
12
13
|
scrollRightIcon,
|
|
13
14
|
tab,
|
|
14
15
|
classes,
|
|
15
|
-
onchange
|
|
16
|
+
onchange,
|
|
17
|
+
onkeychange
|
|
16
18
|
}: TabsProperties = $props();
|
|
17
19
|
|
|
20
|
+
const isObjectMode = $derived(items.length > 0 && typeof items.at(0) === 'object');
|
|
21
|
+
|
|
22
|
+
function toTabItem(item: string | TabItem): TabItem | null {
|
|
23
|
+
return typeof item === 'object' ? item : null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function toStringLabel(item: string | TabItem): string {
|
|
27
|
+
return typeof item === 'string' ? item : item.label;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const resolvedActiveIndex = $derived(
|
|
31
|
+
isObjectMode
|
|
32
|
+
? items.findIndex((item) => {
|
|
33
|
+
const tabItem = toTabItem(item);
|
|
34
|
+
return tabItem !== null && tabItem.key === activeKey;
|
|
35
|
+
})
|
|
36
|
+
: activeIndex
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
function isActiveItem(index: number): boolean {
|
|
40
|
+
return index === resolvedActiveIndex;
|
|
41
|
+
}
|
|
42
|
+
|
|
18
43
|
let scrollContainer: HTMLDivElement | null = null;
|
|
19
44
|
let canScrollLeft = $state(false);
|
|
20
45
|
let canScrollRight = $state(false);
|
|
@@ -40,11 +65,30 @@
|
|
|
40
65
|
}
|
|
41
66
|
|
|
42
67
|
function handleTabClick(index: number): void {
|
|
43
|
-
if (disabled
|
|
68
|
+
if (disabled) {
|
|
44
69
|
return;
|
|
45
70
|
}
|
|
46
|
-
|
|
47
|
-
|
|
71
|
+
if (isObjectMode) {
|
|
72
|
+
const rawItem = items.at(index);
|
|
73
|
+
if (typeof rawItem !== 'object') {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const tabItem = toTabItem(rawItem)!;
|
|
77
|
+
if (tabItem.key === activeKey) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
onkeychange?.(tabItem.key);
|
|
81
|
+
} else {
|
|
82
|
+
if (index === activeIndex) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const rawLabel = items.at(index);
|
|
86
|
+
if (typeof rawLabel !== 'string') {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
activeIndex = index;
|
|
90
|
+
onchange?.(index, rawLabel);
|
|
91
|
+
}
|
|
48
92
|
}
|
|
49
93
|
|
|
50
94
|
function handleKeydown(event: KeyboardEvent, index: number): void {
|
|
@@ -90,23 +134,26 @@
|
|
|
90
134
|
use:initOverflow
|
|
91
135
|
onscroll={updateOverflow}
|
|
92
136
|
>
|
|
93
|
-
{#each items as
|
|
137
|
+
{#each items as item, index (isObjectMode ? (toTabItem(item)?.key ?? index) : index)}
|
|
138
|
+
{@const tabItem = toTabItem(item)}
|
|
139
|
+
{@const label = toStringLabel(item)}
|
|
94
140
|
<div
|
|
95
141
|
class="tabs-item"
|
|
96
|
-
class:active={index
|
|
142
|
+
class:active={isActiveItem(index)}
|
|
97
143
|
role="tab"
|
|
98
|
-
aria-selected={index
|
|
144
|
+
aria-selected={isActiveItem(index)}
|
|
99
145
|
aria-disabled={disabled ? true : null}
|
|
100
|
-
tabindex={index
|
|
146
|
+
tabindex={isActiveItem(index) ? 0 : -1}
|
|
147
|
+
data-pw={tabItem?.testId}
|
|
101
148
|
onclick={() => handleTabClick(index)}
|
|
102
|
-
onkeydown={(
|
|
149
|
+
onkeydown={(event) => handleKeydown(event, index)}
|
|
103
150
|
>
|
|
104
|
-
{#if tab}
|
|
105
|
-
{@render tab({ label, index, active: index
|
|
151
|
+
{#if typeof tab === 'function'}
|
|
152
|
+
{@render tab({ label, index, active: isActiveItem(index), subtitle: tabItem?.subtitle })}
|
|
106
153
|
{:else}
|
|
107
154
|
{label}
|
|
108
155
|
{/if}
|
|
109
|
-
{#if index
|
|
156
|
+
{#if isActiveItem(index)}
|
|
110
157
|
<span class="tabs-indicator"></span>
|
|
111
158
|
{/if}
|
|
112
159
|
</div>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { TabsProperties } from './properties';
|
|
2
|
-
declare const Tabs: import("svelte").Component<TabsProperties, {}, "">;
|
|
2
|
+
declare const Tabs: import("svelte").Component<TabsProperties, {}, "activeIndex">;
|
|
3
3
|
type Tabs = ReturnType<typeof Tabs>;
|
|
4
4
|
export default Tabs;
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
|
+
export type TabItem = {
|
|
3
|
+
key: string;
|
|
4
|
+
label: string;
|
|
5
|
+
testId?: string;
|
|
6
|
+
subtitle?: string;
|
|
7
|
+
};
|
|
2
8
|
export type TabsProperties = MandatoryTabsProperties & OptionalTabsProperties & TabsEventProperties;
|
|
3
9
|
export type MandatoryTabsProperties = {
|
|
4
|
-
items: string[];
|
|
10
|
+
items: string[] | TabItem[];
|
|
5
11
|
};
|
|
6
12
|
export type OptionalTabsProperties = {
|
|
7
13
|
activeIndex?: number;
|
|
14
|
+
activeKey?: string;
|
|
8
15
|
disabled?: boolean;
|
|
9
16
|
testId?: string;
|
|
10
17
|
scrollLeftIcon?: Snippet;
|
|
@@ -13,9 +20,11 @@ export type OptionalTabsProperties = {
|
|
|
13
20
|
label: string;
|
|
14
21
|
index: number;
|
|
15
22
|
active: boolean;
|
|
23
|
+
subtitle?: string;
|
|
16
24
|
}]>;
|
|
17
25
|
classes?: string;
|
|
18
26
|
};
|
|
19
27
|
export type TabsEventProperties = {
|
|
20
28
|
onchange?: (index: number, label: string) => void;
|
|
29
|
+
onkeychange?: (key: string) => void;
|
|
21
30
|
};
|