@juspay/svelte-ui-components 4.55.4 → 4.57.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/Accordion/Accordion.svelte +66 -34
- package/dist/Accordion/Accordion.svelte.d.ts +1 -1
- package/dist/Accordion/properties.d.ts +11 -0
- package/dist/Avatar/Avatar.svelte +20 -6
- package/dist/Button/Button.svelte +34 -19
- package/dist/Button/Button.svelte.d.ts +1 -1
- package/dist/Button/properties.d.ts +10 -0
- package/dist/Card/Card.svelte +31 -18
- package/dist/Card/properties.d.ts +7 -0
- package/dist/Dialog/Dialog.svelte +186 -0
- package/dist/Dialog/Dialog.svelte.d.ts +4 -0
- package/dist/Dialog/properties.d.ts +23 -0
- package/dist/Dialog/properties.js +1 -0
- package/dist/DockPanel/DockPanel.svelte.d.ts +1 -1
- package/dist/EmptyState/EmptyState.svelte +58 -33
- package/dist/EmptyState/properties.d.ts +4 -0
- package/dist/FileInput/FileInput.svelte +130 -31
- package/dist/FileInput/FileInput.svelte.d.ts +1 -1
- package/dist/FileInput/properties.d.ts +9 -0
- package/dist/Icon/Icon.svelte +99 -21
- package/dist/Icon/properties.d.ts +8 -0
- package/dist/IframeViewer/IframeViewer.svelte +29 -5
- package/dist/IframeViewer/IframeViewer.svelte.d.ts +1 -1
- package/dist/IframeViewer/properties.d.ts +9 -0
- package/dist/Img/Img.svelte +31 -11
- package/dist/Img/Img.svelte.d.ts +1 -1
- package/dist/Img/properties.d.ts +13 -0
- package/dist/Input/Input.svelte +260 -170
- package/dist/Input/Input.svelte.d.ts +1 -1
- package/dist/Input/properties.d.ts +10 -0
- package/dist/Link/Link.svelte +33 -0
- package/dist/Link/Link.svelte.d.ts +4 -0
- package/dist/Link/properties.d.ts +14 -0
- package/dist/Link/properties.js +1 -0
- package/dist/Loader/Loader.svelte +50 -5
- package/dist/Loader/properties.d.ts +4 -0
- package/dist/MediaPlayer/MediaPlayer.svelte +223 -161
- package/dist/MediaPlayer/MediaPlayer.svelte.d.ts +1 -1
- package/dist/MediaPlayer/properties.d.ts +13 -0
- package/dist/Modal/Modal.svelte +52 -3
- package/dist/Modal/properties.d.ts +11 -0
- package/dist/NativeFileInput/NativeFileInput.svelte +52 -0
- package/dist/NativeFileInput/NativeFileInput.svelte.d.ts +6 -0
- package/dist/NativeFileInput/properties.d.ts +6 -0
- package/dist/NativeFileInput/properties.js +1 -0
- package/dist/Pill/Pill.svelte +7 -3
- package/dist/Pill/properties.d.ts +4 -0
- package/dist/Progress/Progress.svelte +46 -7
- package/dist/Progress/properties.d.ts +4 -0
- package/dist/Resizable/Resizable.svelte.d.ts +1 -1
- package/dist/Select/Select.svelte +535 -354
- package/dist/Select/Select.svelte.d.ts +1 -1
- package/dist/Select/dropdownPosition.d.ts +2 -0
- package/dist/Select/dropdownPosition.js +3 -2
- package/dist/Select/properties.d.ts +11 -0
- package/dist/ThemeSwitcher/ThemeSwitcher.svelte +5 -0
- package/dist/_chart/ChartContainer.svelte.d.ts +1 -1
- package/dist/_field/form-reset.d.ts +2 -0
- package/dist/_field/form-reset.js +34 -0
- package/dist/_interaction/dismissal.d.ts +2 -0
- package/dist/_interaction/dismissal.js +7 -1
- package/dist/_interaction/focus.d.ts +1 -1
- package/dist/_interaction/focus.js +66 -3
- package/dist/index.d.ts +6 -0
- package/dist/index.js +3 -0
- package/dist/styles/theme-dark.css +4 -0
- package/dist-codemod/codemod/migration-assets/legacy-display.css +5 -2
- package/dist-codemod/codemod/migration-assets/legacy-palette.css +4 -1
- package/dist-codemod/codemod/migration-assets/wc-display.json +15 -0
- package/dist-wc/index.js +5301 -3252
- package/package.json +2 -2
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
import type { AccordionProperties } from './properties';
|
|
3
3
|
|
|
4
4
|
let {
|
|
5
|
+
native = false,
|
|
6
|
+
attachment,
|
|
7
|
+
nativeAttrs,
|
|
8
|
+
summaryAttrs,
|
|
9
|
+
element = $bindable(),
|
|
5
10
|
expand = $bindable(false),
|
|
6
11
|
children,
|
|
7
12
|
trigger,
|
|
@@ -48,39 +53,65 @@
|
|
|
48
53
|
}
|
|
49
54
|
</script>
|
|
50
55
|
|
|
51
|
-
{#if
|
|
52
|
-
<
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
aria-disabled={disabled}
|
|
61
|
-
onclick={handleTriggerClick}
|
|
62
|
-
onkeydown={(event) => {
|
|
63
|
-
if (event.key === 'Enter' || event.key === ' ') {
|
|
64
|
-
event.preventDefault();
|
|
65
|
-
handleTriggerClick();
|
|
66
|
-
}
|
|
67
|
-
}}
|
|
56
|
+
{#if native}
|
|
57
|
+
<details
|
|
58
|
+
{@attach attachment}
|
|
59
|
+
{...nativeAttrs}
|
|
60
|
+
bind:open={expand}
|
|
61
|
+
bind:this={element}
|
|
62
|
+
class={classes ?? ''}
|
|
63
|
+
data-pw={testId}
|
|
64
|
+
ontoggle={(event) => ontoggle?.(event.currentTarget.open)}
|
|
68
65
|
>
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
{
|
|
66
|
+
<summary
|
|
67
|
+
{...summaryAttrs}
|
|
68
|
+
class={triggerClasses ?? ''}
|
|
69
|
+
aria-disabled={disabled || null}
|
|
70
|
+
tabindex={disabled ? -1 : null}
|
|
71
|
+
onclick={(event) => {
|
|
72
|
+
if (disabled) {
|
|
73
|
+
event.preventDefault();
|
|
74
|
+
}
|
|
75
|
+
}}
|
|
76
|
+
>
|
|
77
|
+
{@render trigger?.({ expanded: expand })}
|
|
78
|
+
</summary>
|
|
79
|
+
{@render children?.()}
|
|
80
|
+
</details>
|
|
81
|
+
{:else}
|
|
82
|
+
{#if trigger}
|
|
83
|
+
<div
|
|
84
|
+
class="accordion-trigger {triggerClasses ?? ''}"
|
|
85
|
+
class:disabled
|
|
86
|
+
id={triggerId}
|
|
87
|
+
role="button"
|
|
88
|
+
tabindex={disabled ? -1 : 0}
|
|
89
|
+
aria-expanded={expand}
|
|
90
|
+
aria-controls={effectivePanelId}
|
|
91
|
+
aria-disabled={disabled}
|
|
92
|
+
onclick={handleTriggerClick}
|
|
93
|
+
onkeydown={(event) => {
|
|
94
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
95
|
+
event.preventDefault();
|
|
96
|
+
handleTriggerClick();
|
|
97
|
+
}
|
|
98
|
+
}}
|
|
99
|
+
>
|
|
100
|
+
{@render trigger({ expanded: expand })}
|
|
101
|
+
</div>
|
|
102
|
+
{/if}
|
|
72
103
|
|
|
73
|
-
<div
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
>
|
|
83
|
-
|
|
104
|
+
<div
|
|
105
|
+
id={effectivePanelId}
|
|
106
|
+
role={trigger ? 'region' : null}
|
|
107
|
+
aria-labelledby={trigger ? triggerId : null}
|
|
108
|
+
class="accordion {classes ?? ''}"
|
|
109
|
+
class:expanded={expand}
|
|
110
|
+
inert={lazy && !expand}
|
|
111
|
+
data-pw={typeof testId === 'string' ? testId : null}
|
|
112
|
+
testID={typeof testId === 'string' ? testId : null}
|
|
113
|
+
>
|
|
114
|
+
<!-- `inert` while collapsed, lazy only: a lazy panel's content stays mounted
|
|
84
115
|
(not torn down) between opens, so without this its links/buttons would
|
|
85
116
|
stay in the tab order and the accessibility tree while clipped to 0px
|
|
86
117
|
and invisible. A non-lazy panel never reaches this state: `mounted` is
|
|
@@ -89,10 +120,11 @@
|
|
|
89
120
|
The children are chosen by a conditional snippet, not an {#if}: an {#if} would be a
|
|
90
121
|
new block around them, so a local transition inside would stop following the outer
|
|
91
122
|
block that adds or removes the Accordion. This stays the bare render tag it was. -->
|
|
92
|
-
|
|
93
|
-
|
|
123
|
+
<div class="accordion-content">
|
|
124
|
+
{@render (mounted ? children : null)?.()}
|
|
125
|
+
</div>
|
|
94
126
|
</div>
|
|
95
|
-
|
|
127
|
+
{/if}
|
|
96
128
|
|
|
97
129
|
<style>
|
|
98
130
|
.accordion-trigger {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { AccordionProperties } from './properties';
|
|
2
|
-
declare const Accordion: import("svelte").Component<AccordionProperties, {}, "expand">;
|
|
2
|
+
declare const Accordion: import("svelte").Component<AccordionProperties, {}, "element" | "expand">;
|
|
3
3
|
type Accordion = ReturnType<typeof Accordion>;
|
|
4
4
|
export default Accordion;
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { Attachment } from 'svelte/attachments';
|
|
3
|
+
import type { HTMLDetailsAttributes, HTMLAttributes } from 'svelte/elements';
|
|
2
4
|
export type AccordionProperties = OptionalAccordionProperties & AccordionEventProperties;
|
|
3
5
|
export type OptionalAccordionProperties = {
|
|
6
|
+
/** Use native details/summary semantics, including before hydration. */
|
|
7
|
+
native?: boolean;
|
|
8
|
+
/** Native details attachment for host-owned motion/measurement. */
|
|
9
|
+
attachment?: Attachment<HTMLDetailsElement>;
|
|
10
|
+
/** Attributes on the native details element. */
|
|
11
|
+
nativeAttrs?: Omit<HTMLDetailsAttributes, 'open' | 'class' | 'ontoggle'>;
|
|
12
|
+
/** Attributes on the native summary element. */
|
|
13
|
+
summaryAttrs?: HTMLAttributes<HTMLElement>;
|
|
14
|
+
element?: HTMLDetailsElement | null;
|
|
4
15
|
expand?: boolean;
|
|
5
16
|
children?: Snippet;
|
|
6
17
|
trigger?: Snippet<[{
|
|
@@ -2,11 +2,19 @@
|
|
|
2
2
|
import type { AvatarProperties } from './properties';
|
|
3
3
|
import Img from '../Img/Img.svelte';
|
|
4
4
|
|
|
5
|
-
let {
|
|
5
|
+
let {
|
|
6
|
+
src,
|
|
7
|
+
alt = '',
|
|
8
|
+
name,
|
|
9
|
+
size = 'medium',
|
|
10
|
+
testId,
|
|
11
|
+
onclick,
|
|
12
|
+
classes
|
|
13
|
+
}: AvatarProperties = $props();
|
|
6
14
|
|
|
7
|
-
let
|
|
15
|
+
let failedSource = $state<string | null>(null);
|
|
8
16
|
|
|
9
|
-
let showImage = $derived(typeof src === 'string' && src.length > 0 &&
|
|
17
|
+
let showImage = $derived(typeof src === 'string' && src.length > 0 && failedSource !== src);
|
|
10
18
|
|
|
11
19
|
let initials = $derived.by(() => {
|
|
12
20
|
if (typeof name !== 'string' || name.trim().length === 0) {
|
|
@@ -27,7 +35,7 @@
|
|
|
27
35
|
});
|
|
28
36
|
|
|
29
37
|
function handleImageError(): void {
|
|
30
|
-
|
|
38
|
+
failedSource = src ?? null;
|
|
31
39
|
}
|
|
32
40
|
</script>
|
|
33
41
|
|
|
@@ -55,8 +63,9 @@
|
|
|
55
63
|
{:else}
|
|
56
64
|
<div
|
|
57
65
|
class="avatar avatar-{size} {classes ?? ''}"
|
|
58
|
-
role=
|
|
59
|
-
aria-label={alt}
|
|
66
|
+
role={alt.length > 0 ? 'img' : null}
|
|
67
|
+
aria-label={alt.length > 0 ? alt : null}
|
|
68
|
+
aria-hidden={alt.length === 0 ? 'true' : null}
|
|
60
69
|
data-pw={testId}
|
|
61
70
|
testID={testId}
|
|
62
71
|
>
|
|
@@ -126,4 +135,9 @@
|
|
|
126
135
|
.avatar-large .avatar-initials {
|
|
127
136
|
font-size: var(--avatar-large-font-size, 20px);
|
|
128
137
|
}
|
|
138
|
+
@layer svelte-ui-avatar {
|
|
139
|
+
:where(.avatar) {
|
|
140
|
+
background-image: var(--avatar-background-image, revert-layer);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
129
143
|
</style>
|
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
import type { ButtonProperties } from './properties';
|
|
4
4
|
|
|
5
5
|
let {
|
|
6
|
+
unstyled = false,
|
|
7
|
+
nativeAttrs,
|
|
8
|
+
element = $bindable(),
|
|
9
|
+
elementClasses,
|
|
6
10
|
text,
|
|
7
11
|
variant = 'primary',
|
|
8
12
|
size = 'md',
|
|
@@ -70,20 +74,14 @@
|
|
|
70
74
|
}
|
|
71
75
|
</script>
|
|
72
76
|
|
|
73
|
-
|
|
74
|
-
class="button-container variant-{variant} size-{size} {classes ?? ''}"
|
|
75
|
-
class:icon-only={iconOnly}
|
|
76
|
-
class:full-width={fullWidth}
|
|
77
|
-
class:button-shrinkable={shrinkable}
|
|
78
|
-
style={style ?? null}
|
|
79
|
-
>
|
|
80
|
-
{#if showProgressBar}
|
|
81
|
-
<div class="button-progress-bar"></div>
|
|
82
|
-
{/if}
|
|
77
|
+
{#snippet control()}
|
|
83
78
|
<svelte:element
|
|
84
79
|
this={href ? 'a' : 'button'}
|
|
85
|
-
|
|
86
|
-
|
|
80
|
+
{...nativeAttrs}
|
|
81
|
+
bind:this={element}
|
|
82
|
+
class={unstyled ? (classes ?? '') : `button-el ${elementClasses ?? ''}`}
|
|
83
|
+
style={unstyled ? (style ?? null) : null}
|
|
84
|
+
class:disabled={isDisabled && !unstyled}
|
|
87
85
|
onclick={handleButtonClick}
|
|
88
86
|
{onkeydown}
|
|
89
87
|
{onkeyup}
|
|
@@ -109,7 +107,7 @@
|
|
|
109
107
|
target={href ? target : null}
|
|
110
108
|
rel={href ? resolvedRel : null}
|
|
111
109
|
aria-disabled={href && isDisabled ? 'true' : null}
|
|
112
|
-
tabindex={href && isDisabled ? -1 : null}
|
|
110
|
+
tabindex={href && isDisabled ? -1 : (nativeAttrs?.tabindex ?? null)}
|
|
113
111
|
>
|
|
114
112
|
{#if showCircularLoader}
|
|
115
113
|
<div class="button-loader"><Loader /></div>
|
|
@@ -129,12 +127,29 @@
|
|
|
129
127
|
{@render children()}
|
|
130
128
|
{/if}
|
|
131
129
|
</svelte:element>
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
130
|
+
{/snippet}
|
|
131
|
+
|
|
132
|
+
{#if unstyled}
|
|
133
|
+
{@render control()}
|
|
134
|
+
{:else}
|
|
135
|
+
<div
|
|
136
|
+
class="button-container variant-{variant} size-{size} {classes ?? ''}"
|
|
137
|
+
class:icon-only={iconOnly}
|
|
138
|
+
class:full-width={fullWidth}
|
|
139
|
+
class:button-shrinkable={shrinkable}
|
|
140
|
+
style={style ?? null}
|
|
141
|
+
>
|
|
142
|
+
{#if showProgressBar}
|
|
143
|
+
<div class="button-progress-bar"></div>
|
|
144
|
+
{/if}
|
|
145
|
+
{@render control()}
|
|
146
|
+
{#if typeof statusText === 'string'}
|
|
147
|
+
<div class="button-status" role="status" aria-live="polite" data-pw={statusTestId ?? null}>
|
|
148
|
+
{statusText}
|
|
149
|
+
</div>
|
|
150
|
+
{/if}
|
|
151
|
+
</div>
|
|
152
|
+
{/if}
|
|
138
153
|
|
|
139
154
|
<style>
|
|
140
155
|
.button-container {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { ButtonProperties } from './properties';
|
|
2
|
-
declare const Button: import("svelte").Component<ButtonProperties, {}, "showProgressBar">;
|
|
2
|
+
declare const Button: import("svelte").Component<ButtonProperties, {}, "element" | "showProgressBar">;
|
|
3
3
|
type Button = ReturnType<typeof Button>;
|
|
4
4
|
export default Button;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLAnchorAttributes, HTMLButtonAttributes } from 'svelte/elements';
|
|
2
3
|
export type LoaderType = 'Circular' | 'ProgressBar';
|
|
3
4
|
/** Visual style of the button. Maps to a built-in palette via `--button-*` variables. */
|
|
4
5
|
export type ButtonVariant = 'primary' | 'secondary' | 'ghost' | 'destructive' | 'brand';
|
|
@@ -6,6 +7,15 @@ export type ButtonVariant = 'primary' | 'secondary' | 'ghost' | 'destructive' |
|
|
|
6
7
|
export type ButtonSize = 'sm' | 'md' | 'lg';
|
|
7
8
|
export type ButtonProperties = OptionalButtonProperties & ButtonEventProperties;
|
|
8
9
|
export type OptionalButtonProperties = {
|
|
10
|
+
/** Render only the native element, without component appearance or layout wrappers. */
|
|
11
|
+
unstyled?: boolean;
|
|
12
|
+
/** Extra native attributes on the actual control, never the wrapper.
|
|
13
|
+
* Dedicated props retain precedence for managed behavior and accessibility. */
|
|
14
|
+
nativeAttrs?: Omit<HTMLButtonAttributes & HTMLAnchorAttributes, 'class' | 'onclick' | 'disabled' | 'href' | 'type' | 'target' | 'rel'>;
|
|
15
|
+
/** Bindable reference to the actual button or anchor. */
|
|
16
|
+
element?: HTMLButtonElement | HTMLAnchorElement | null;
|
|
17
|
+
/** Class names applied to the actual control rather than its wrapper. */
|
|
18
|
+
elementClasses?: string;
|
|
9
19
|
text?: string;
|
|
10
20
|
/**
|
|
11
21
|
* Visual style: `primary` (default, filled), `secondary` (outlined), `ghost`
|
package/dist/Card/Card.svelte
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
import { CARD_MANAGED_ATTRS, discardedAttrWarnings } from '../attrs-discard';
|
|
4
4
|
|
|
5
5
|
let {
|
|
6
|
+
unstyled = false,
|
|
7
|
+
interactive = false,
|
|
8
|
+
nativeAttrs,
|
|
9
|
+
onkeydown,
|
|
6
10
|
children,
|
|
7
11
|
title,
|
|
8
12
|
description,
|
|
@@ -65,7 +69,7 @@
|
|
|
65
69
|
// drop the interactive-div keyboard shim (role/tabindex/onkeydown) with no
|
|
66
70
|
// native behaviour to replace it.
|
|
67
71
|
const isAnchor = $derived(rootTag === 'a' && typeof href === 'string' && href.length > 0);
|
|
68
|
-
const isInteractive = $derived(isAnchor || typeof onclick === 'function');
|
|
72
|
+
const isInteractive = $derived(interactive || isAnchor || typeof onclick === 'function');
|
|
69
73
|
// HTML target values are ASCII case-insensitive (e.g. "_BLANK" opens a new
|
|
70
74
|
// context identically to "_blank"), so the comparison must normalize case
|
|
71
75
|
// to keep the noopener/noreferrer default from being silently skipped.
|
|
@@ -82,10 +86,14 @@
|
|
|
82
86
|
);
|
|
83
87
|
|
|
84
88
|
const handleKeydown = (event: KeyboardEvent): void => {
|
|
89
|
+
onkeydown?.(event);
|
|
90
|
+
if (event.defaultPrevented || event.target !== event.currentTarget) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
85
93
|
if (event.key === 'Enter' || event.key === ' ') {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
94
|
+
// A synchronous action can move focus into a dialog. Suppress the
|
|
95
|
+
// original key's default activation so it cannot click the new focus.
|
|
96
|
+
event.preventDefault();
|
|
89
97
|
if (event.currentTarget instanceof HTMLElement) {
|
|
90
98
|
event.currentTarget.click();
|
|
91
99
|
}
|
|
@@ -95,9 +103,10 @@
|
|
|
95
103
|
|
|
96
104
|
<svelte:element
|
|
97
105
|
this={rootTag}
|
|
106
|
+
{...nativeAttrs}
|
|
98
107
|
{...attrs ?? {}}
|
|
99
|
-
class=
|
|
100
|
-
class:card-interactive={isInteractive}
|
|
108
|
+
class={unstyled ? (classes ?? '') : `card ${classes ?? ''}`}
|
|
109
|
+
class:card-interactive={isInteractive && !unstyled}
|
|
101
110
|
class:card-stretch={stretch}
|
|
102
111
|
class:card-has-scroll={scrollable}
|
|
103
112
|
style={styleAttr}
|
|
@@ -109,7 +118,7 @@
|
|
|
109
118
|
target={isAnchor ? target : null}
|
|
110
119
|
rel={isAnchor ? resolvedRel : null}
|
|
111
120
|
onclick={onclick ?? null}
|
|
112
|
-
onkeydown={!isAnchor && isInteractive ? handleKeydown :
|
|
121
|
+
onkeydown={!isAnchor && isInteractive ? handleKeydown : onkeydown}
|
|
113
122
|
>
|
|
114
123
|
{#if (typeof title === 'string' && title.length > 0) || typeof titleSnippet === 'function' || typeof headerRight === 'function'}
|
|
115
124
|
<div class="card-header" class:card-header-split={typeof headerRight === 'function'}>
|
|
@@ -132,17 +141,21 @@
|
|
|
132
141
|
{/if}
|
|
133
142
|
</div>
|
|
134
143
|
{/if}
|
|
135
|
-
{#if
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
144
|
+
{#if unstyled}
|
|
145
|
+
{@render children?.()}
|
|
146
|
+
{:else}
|
|
147
|
+
{#if typeof children === 'function'}
|
|
148
|
+
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
|
149
|
+
<div
|
|
150
|
+
class="card-content"
|
|
151
|
+
class:card-content-scrollable={scrollable}
|
|
152
|
+
role={scrollable ? 'region' : null}
|
|
153
|
+
aria-label={scrollable ? 'Scrollable card content' : null}
|
|
154
|
+
tabindex={scrollable ? 0 : null}
|
|
155
|
+
>
|
|
156
|
+
{@render children()}
|
|
157
|
+
</div>
|
|
158
|
+
{/if}
|
|
146
159
|
{/if}
|
|
147
160
|
{#if typeof footer === 'function'}
|
|
148
161
|
<footer class="card-footer">
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
2
3
|
import type { AttrsEscapeHatch, LegacyAttrs } from '../types';
|
|
3
4
|
export type CardProperties = OptionalCardProperties;
|
|
4
5
|
/**
|
|
@@ -49,6 +50,12 @@ type CardManagedAttrs = {
|
|
|
49
50
|
export type CardStrictAttrs = AttrsEscapeHatch<Extract<keyof CardManagedAttrs, string>>;
|
|
50
51
|
export type MandatoryCardProperties = Record<string, never>;
|
|
51
52
|
export type OptionalCardProperties = {
|
|
53
|
+
/** Keep host-authored card composition without default appearance/content wrappers. */
|
|
54
|
+
unstyled?: boolean;
|
|
55
|
+
/** Explicitly keyboard-interactive even when interaction is focus/key driven. */
|
|
56
|
+
interactive?: boolean;
|
|
57
|
+
nativeAttrs?: Omit<HTMLAttributes<HTMLElement>, 'class' | 'style' | 'role' | 'tabindex' | 'onclick' | 'onkeydown'>;
|
|
58
|
+
onkeydown?: (event: KeyboardEvent) => void;
|
|
52
59
|
/**
|
|
53
60
|
* Main content body of the card. Rendered inside the `.card-content` container.
|
|
54
61
|
*/
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onDestroy, tick } from 'svelte';
|
|
3
|
+
import { focusEntryPoint, focusTrapTabTarget, getActiveElement } from '../_interaction/focus';
|
|
4
|
+
import { acquireScrollLock } from '../utils';
|
|
5
|
+
import { isTopmostDismissible, registerDismissible } from '../_interaction/dismissal';
|
|
6
|
+
import type { DialogProperties } from './properties';
|
|
7
|
+
|
|
8
|
+
let {
|
|
9
|
+
open = $bindable(false),
|
|
10
|
+
modal = true,
|
|
11
|
+
lockScroll = true,
|
|
12
|
+
returnFocusTo,
|
|
13
|
+
// eslint-disable-next-line no-useless-assignment -- Bindable output is assigned by the mounted DOM reference.
|
|
14
|
+
element = $bindable(),
|
|
15
|
+
classes,
|
|
16
|
+
testId,
|
|
17
|
+
nativeAttrs,
|
|
18
|
+
children,
|
|
19
|
+
onclose,
|
|
20
|
+
oncancel,
|
|
21
|
+
onclick,
|
|
22
|
+
onkeydown
|
|
23
|
+
}: DialogProperties = $props();
|
|
24
|
+
|
|
25
|
+
let dialogElement = $state<HTMLDialogElement | null>(null);
|
|
26
|
+
const assignDialogElement = (node: HTMLDialogElement | null) => {
|
|
27
|
+
dialogElement = node;
|
|
28
|
+
element = node;
|
|
29
|
+
};
|
|
30
|
+
let opener: HTMLElement | null = null;
|
|
31
|
+
let destroyed = false;
|
|
32
|
+
let focusPending = false;
|
|
33
|
+
let shownModal: boolean | null = null;
|
|
34
|
+
const containsComposed = (node: Node | null): boolean => {
|
|
35
|
+
let current = node;
|
|
36
|
+
while (current) {
|
|
37
|
+
if (current === dialogElement) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
current =
|
|
41
|
+
current instanceof Element && current.assignedSlot
|
|
42
|
+
? current.assignedSlot
|
|
43
|
+
: (current.parentNode ?? (current instanceof ShadowRoot ? current.host : null));
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// A real native browser API must run after mount; an open attribute would
|
|
49
|
+
// create a non-modal dialog and lose top-layer focus/background isolation.
|
|
50
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
51
|
+
$effect(() => {
|
|
52
|
+
if (!dialogElement) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const dialog = dialogElement;
|
|
56
|
+
const releaseLayer = open && modal ? registerDismissible({ element: () => dialog }) : null;
|
|
57
|
+
if (open && (!dialog.open || shownModal !== modal)) {
|
|
58
|
+
const active = getActiveElement(dialog);
|
|
59
|
+
const switchingMode = dialog.open && focusPending;
|
|
60
|
+
if (!switchingMode) {
|
|
61
|
+
opener = active instanceof HTMLElement ? active : null;
|
|
62
|
+
focusPending = true;
|
|
63
|
+
}
|
|
64
|
+
const preserveFocus = switchingMode && containsComposed(active) ? active : null;
|
|
65
|
+
try {
|
|
66
|
+
if (dialog.open) {
|
|
67
|
+
dialog.close();
|
|
68
|
+
}
|
|
69
|
+
if (modal) {
|
|
70
|
+
dialog.showModal();
|
|
71
|
+
} else {
|
|
72
|
+
dialog.show();
|
|
73
|
+
}
|
|
74
|
+
shownModal = modal;
|
|
75
|
+
if (preserveFocus instanceof HTMLElement && preserveFocus.isConnected) {
|
|
76
|
+
preserveFocus.focus({ preventScroll: true });
|
|
77
|
+
}
|
|
78
|
+
} catch (error) {
|
|
79
|
+
releaseLayer?.();
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
void tick().then(() => {
|
|
83
|
+
const active = getActiveElement(dialog);
|
|
84
|
+
if (
|
|
85
|
+
!destroyed &&
|
|
86
|
+
dialog.open &&
|
|
87
|
+
(!modal || isTopmostDismissible(dialog)) &&
|
|
88
|
+
!dialog.hasAttribute('autofocus') &&
|
|
89
|
+
(active === dialog || active === null || active === dialog.ownerDocument.body)
|
|
90
|
+
) {
|
|
91
|
+
// Firefox/WebKit do not initially focus projected light-DOM controls.
|
|
92
|
+
// Keep a browser-selected descendant, including an autofocus target.
|
|
93
|
+
focusEntryPoint(dialog, true);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
} else if (!open) {
|
|
97
|
+
if (dialog.open) {
|
|
98
|
+
dialog.close();
|
|
99
|
+
}
|
|
100
|
+
shownModal = null;
|
|
101
|
+
}
|
|
102
|
+
if (releaseLayer) {
|
|
103
|
+
return releaseLayer;
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
108
|
+
$effect(() => {
|
|
109
|
+
if (open && modal && lockScroll && dialogElement) {
|
|
110
|
+
return acquireScrollLock(dialogElement.ownerDocument.body);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
const restoreFocus = () => {
|
|
115
|
+
if (!focusPending) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
focusPending = false;
|
|
119
|
+
const target = returnFocusTo ?? opener;
|
|
120
|
+
opener = null;
|
|
121
|
+
if (target?.isConnected) {
|
|
122
|
+
target.focus({ preventScroll: true });
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
onDestroy(() => {
|
|
127
|
+
destroyed = true;
|
|
128
|
+
const wasOpen = dialogElement?.open ?? false;
|
|
129
|
+
if (wasOpen) {
|
|
130
|
+
dialogElement?.close();
|
|
131
|
+
}
|
|
132
|
+
restoreFocus();
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const handleKeydown = (event: KeyboardEvent) => {
|
|
136
|
+
onkeydown?.(event);
|
|
137
|
+
if (
|
|
138
|
+
event.key !== 'Tab' ||
|
|
139
|
+
event.defaultPrevented ||
|
|
140
|
+
!modal ||
|
|
141
|
+
!isTopmostDismissible(dialogElement)
|
|
142
|
+
) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const target = focusTrapTabTarget({
|
|
146
|
+
container: dialogElement,
|
|
147
|
+
activeElement: getActiveElement(dialogElement),
|
|
148
|
+
shiftKey: event.shiftKey
|
|
149
|
+
});
|
|
150
|
+
if (target) {
|
|
151
|
+
event.preventDefault();
|
|
152
|
+
target.focus();
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const handleCancel = (event: Event) => {
|
|
157
|
+
oncancel?.(event);
|
|
158
|
+
if (!event.defaultPrevented) {
|
|
159
|
+
open = false;
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const handleClose = (event: Event) => {
|
|
164
|
+
if (destroyed || dialogElement?.open) {
|
|
165
|
+
return;
|
|
166
|
+
} // ignore a stale close notification after reopening
|
|
167
|
+
open = false;
|
|
168
|
+
restoreFocus();
|
|
169
|
+
onclose?.(event);
|
|
170
|
+
};
|
|
171
|
+
</script>
|
|
172
|
+
|
|
173
|
+
<!-- The native dialog supplies focus management and modal semantics. Content
|
|
174
|
+
owns its accessible name through nativeAttrs and its own heading/labels. -->
|
|
175
|
+
<dialog
|
|
176
|
+
{...nativeAttrs}
|
|
177
|
+
bind:this={() => dialogElement, assignDialogElement}
|
|
178
|
+
class={classes ?? ''}
|
|
179
|
+
data-pw={testId}
|
|
180
|
+
onkeydown={handleKeydown}
|
|
181
|
+
oncancel={handleCancel}
|
|
182
|
+
onclose={handleClose}
|
|
183
|
+
{onclick}
|
|
184
|
+
>
|
|
185
|
+
{@render children?.()}
|
|
186
|
+
</dialog>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLDialogAttributes } from 'svelte/elements';
|
|
3
|
+
export type DialogProperties = {
|
|
4
|
+
/** Bindable visibility. A modal uses showModal(), preserving the browser top layer. */
|
|
5
|
+
open?: boolean;
|
|
6
|
+
/** Use native modal isolation; false permits a non-modal dialog. Default true. */
|
|
7
|
+
modal?: boolean;
|
|
8
|
+
/** Lock the page scroll while modal and open. Default true. */
|
|
9
|
+
lockScroll?: boolean;
|
|
10
|
+
/** Explicit trigger to refocus on close, including pointer browsers that do not focus buttons. */
|
|
11
|
+
returnFocusTo?: HTMLElement | null;
|
|
12
|
+
/** Bindable native element for integration with existing controllers. */
|
|
13
|
+
element?: HTMLDialogElement | null;
|
|
14
|
+
classes?: string;
|
|
15
|
+
testId?: string;
|
|
16
|
+
nativeAttrs?: Omit<HTMLDialogAttributes, 'open' | 'class' | 'onclose' | 'oncancel' | 'onclick'>;
|
|
17
|
+
children?: Snippet;
|
|
18
|
+
onclose?: (event: Event) => void;
|
|
19
|
+
/** Prevent the event's default to keep the dialog open. */
|
|
20
|
+
oncancel?: (event: Event) => void;
|
|
21
|
+
onclick?: (event: MouseEvent) => void;
|
|
22
|
+
onkeydown?: (event: KeyboardEvent) => void;
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { DockPanelProperties } from './properties';
|
|
2
|
-
declare const DockPanel: import("svelte").Component<DockPanelProperties, {}, "
|
|
2
|
+
declare const DockPanel: import("svelte").Component<DockPanelProperties, {}, "width" | "state" | "reservedWidth">;
|
|
3
3
|
type DockPanel = ReturnType<typeof DockPanel>;
|
|
4
4
|
export default DockPanel;
|