tera-system-ui 0.0.15 → 0.0.17
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/components/brand-logo/BrandLogo.svelte +31 -31
- package/dist/components/button/Button.svelte +49 -49
- package/dist/components/combobox/Combobox.svelte +8 -8
- package/dist/components/command/command.scss +72 -72
- package/dist/components/command/components/Command.svelte +120 -120
- package/dist/components/command/components/CommandEmpty.svelte +30 -30
- package/dist/components/command/components/CommandGroup.svelte +110 -110
- package/dist/components/command/components/CommandInput.svelte +92 -92
- package/dist/components/command/components/CommandItem.svelte +110 -110
- package/dist/components/command/components/CommandList.svelte +56 -56
- package/dist/components/command/components/CommandLoading.svelte +28 -28
- package/dist/components/command/components/CommandSeparator.svelte +21 -21
- package/dist/components/dialog/Dialog.svelte +107 -107
- package/dist/components/dialog/dialog.scss +112 -112
- package/dist/components/header/Header.svelte +36 -36
- package/dist/components/header/header.scss +19 -19
- package/dist/components/icons/IconArrowBigRightFilled.svelte +10 -10
- package/dist/components/icons/IconBook.svelte +10 -10
- package/dist/components/icons/IconBookmarkPlus.svelte +10 -10
- package/dist/components/icons/IconCalculator.svelte +10 -10
- package/dist/components/icons/IconCheck.svelte +10 -10
- package/dist/components/icons/IconChevronDown.svelte +10 -10
- package/dist/components/icons/IconCopy.svelte +10 -10
- package/dist/components/icons/IconCopyCheckFilled.svelte +10 -10
- package/dist/components/icons/IconHamburger.svelte +10 -10
- package/dist/components/icons/IconLanguage.svelte +10 -10
- package/dist/components/icons/IconLoader2.svelte +10 -10
- package/dist/components/icons/IconMoon.svelte +10 -10
- package/dist/components/icons/IconPointFilled.svelte +10 -10
- package/dist/components/icons/IconSearch.svelte +10 -10
- package/dist/components/icons/IconSun.svelte +10 -10
- package/dist/components/icons/IconSwitchHorizontal.svelte +10 -10
- package/dist/components/icons/IconSwitchVertical.svelte +10 -10
- package/dist/components/icons/IconTransform.svelte +10 -10
- package/dist/components/icons/IconX.svelte +10 -10
- package/dist/components/input/Input.svelte +24 -24
- package/dist/components/language-picker-button/LanguagePickerButton.svelte +109 -109
- package/dist/components/light-dark-toggle/LightDarkToggle.svelte +36 -36
- package/dist/components/popover/Popover.svelte +136 -136
- package/dist/components/popover-responsive/PopoverResponsive.svelte +87 -87
- package/dist/components/side-navigation/SideNavigation.svelte +114 -113
- package/dist/components/side-navigation/SideNavigationItem.svelte +17 -17
- package/dist/components/side-navigation/SideNavigationLayout.svelte +19 -19
- package/dist/components/side-navigation/sidenav.scss +149 -149
- package/dist/components/tera-ui-context/TeraUiContext.svelte +28 -28
- package/dist/paraglide/.prettierignore +3 -0
- package/dist/paraglide/messages/de.d.ts +4 -0
- package/dist/paraglide/messages/de.js +42 -0
- package/dist/paraglide/messages/en.d.ts +4 -0
- package/dist/paraglide/messages/en.js +42 -0
- package/dist/paraglide/messages/es.d.ts +4 -0
- package/dist/paraglide/messages/es.js +42 -0
- package/dist/paraglide/messages/fr.d.ts +4 -0
- package/dist/paraglide/messages/fr.js +42 -0
- package/dist/paraglide/messages/it.d.ts +4 -0
- package/dist/paraglide/messages/it.js +42 -0
- package/dist/paraglide/messages/pt.d.ts +4 -0
- package/dist/paraglide/messages/pt.js +42 -0
- package/dist/paraglide/messages/ru.d.ts +4 -0
- package/dist/paraglide/messages/ru.js +42 -0
- package/dist/paraglide/messages/vi.d.ts +4 -0
- package/dist/paraglide/messages/vi.js +42 -0
- package/dist/paraglide/messages.d.ts +12 -0
- package/dist/paraglide/messages.js +122 -0
- package/dist/paraglide/runtime.d.ts +52 -0
- package/dist/paraglide/runtime.js +141 -0
- package/dist/themes/scrollbar.scss +37 -37
- package/package.json +95 -94
- package/scripts/add-component-template.js +120 -120
- package/scripts/generate-ts-index.js +136 -136
|
@@ -1,110 +1,110 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import {addEventListener, executeCallbacks, generateId, isUndefined} from '../../../internal/index.js';
|
|
3
|
-
import {getCtx, getGroup, getState, VALUE_ATTR} from '../command.js';
|
|
4
|
-
import type {ItemProps} from '../types.js';
|
|
5
|
-
import {derived} from 'svelte/store';
|
|
6
|
-
import {onMount} from "svelte";
|
|
7
|
-
|
|
8
|
-
type $$Props = ItemProps
|
|
9
|
-
let {
|
|
10
|
-
children,
|
|
11
|
-
childrenWithProps,
|
|
12
|
-
id = generateId(),
|
|
13
|
-
alwaysRender = false,
|
|
14
|
-
onSelect,
|
|
15
|
-
value = '',
|
|
16
|
-
disabled = false,
|
|
17
|
-
...restProps
|
|
18
|
-
}: $$Props = $props()
|
|
19
|
-
|
|
20
|
-
const groupContext = getGroup();
|
|
21
|
-
const context = getCtx();
|
|
22
|
-
const commandState = getState();
|
|
23
|
-
|
|
24
|
-
const trueAlwaysRender = alwaysRender ?? groupContext?.alwaysRender;
|
|
25
|
-
|
|
26
|
-
const render = derived(commandState, ($state) => {
|
|
27
|
-
if (trueAlwaysRender || context.filter() === false || !$commandState.search) return true;
|
|
28
|
-
const currentScore = $commandState.filtered.items.get(id);
|
|
29
|
-
if (isUndefined(currentScore)) return false;
|
|
30
|
-
return currentScore > 0;
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
const selected = derived(commandState, ($state) => $commandState.value === value);
|
|
34
|
-
|
|
35
|
-
let isFirstRender = $state(true);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
let attrs = derived(selected, ($selected) => (
|
|
39
|
-
{
|
|
40
|
-
'aria-disabled': disabled ? true : undefined,
|
|
41
|
-
'data-disabled': disabled ? true : undefined,
|
|
42
|
-
'aria-selected': $selected ? true : undefined,
|
|
43
|
-
'data-selected': $selected ? true : undefined,
|
|
44
|
-
'data-cmdk-item': '',
|
|
45
|
-
'data-value': value,
|
|
46
|
-
role: 'option',
|
|
47
|
-
id
|
|
48
|
-
}
|
|
49
|
-
));
|
|
50
|
-
|
|
51
|
-
onMount(() => {
|
|
52
|
-
isFirstRender = false;
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
onMount(() => {
|
|
57
|
-
let unsub
|
|
58
|
-
unsub = context.item(id, groupContext?.id);
|
|
59
|
-
return unsub;
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
function action(node: HTMLElement) {
|
|
64
|
-
if (!value && node.textContent) {
|
|
65
|
-
value = node.textContent.trim().toLowerCase();
|
|
66
|
-
}
|
|
67
|
-
context.value(id, value);
|
|
68
|
-
node.setAttribute(VALUE_ATTR, value);
|
|
69
|
-
|
|
70
|
-
const unsubEvents = executeCallbacks(
|
|
71
|
-
addEventListener(node, 'pointerenter', () => {
|
|
72
|
-
if (disabled) return;
|
|
73
|
-
select();
|
|
74
|
-
}),
|
|
75
|
-
addEventListener(node, 'click', () => {
|
|
76
|
-
if (disabled) return;
|
|
77
|
-
handleItemClick();
|
|
78
|
-
})
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
return {
|
|
82
|
-
destroy() {
|
|
83
|
-
unsubEvents();
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function handleItemClick() {
|
|
89
|
-
select();
|
|
90
|
-
onSelect?.(value);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function select() {
|
|
94
|
-
commandState.updateState('value', value, true);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
</script>
|
|
98
|
-
|
|
99
|
-
{#if $render || isFirstRender}
|
|
100
|
-
<div {...$attrs} use:action {...restProps}>
|
|
101
|
-
<!--{@render childrenWithProps?.(-->
|
|
102
|
-
<!-- {-->
|
|
103
|
-
<!-- attrs: attrs,-->
|
|
104
|
-
<!-- action: action-->
|
|
105
|
-
<!-- }-->
|
|
106
|
-
<!--)-->
|
|
107
|
-
<!--}-->
|
|
108
|
-
{@render children?.()}
|
|
109
|
-
</div>
|
|
110
|
-
{/if}
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import {addEventListener, executeCallbacks, generateId, isUndefined} from '../../../internal/index.js';
|
|
3
|
+
import {getCtx, getGroup, getState, VALUE_ATTR} from '../command.js';
|
|
4
|
+
import type {ItemProps} from '../types.js';
|
|
5
|
+
import {derived} from 'svelte/store';
|
|
6
|
+
import {onMount} from "svelte";
|
|
7
|
+
|
|
8
|
+
type $$Props = ItemProps
|
|
9
|
+
let {
|
|
10
|
+
children,
|
|
11
|
+
childrenWithProps,
|
|
12
|
+
id = generateId(),
|
|
13
|
+
alwaysRender = false,
|
|
14
|
+
onSelect,
|
|
15
|
+
value = '',
|
|
16
|
+
disabled = false,
|
|
17
|
+
...restProps
|
|
18
|
+
}: $$Props = $props()
|
|
19
|
+
|
|
20
|
+
const groupContext = getGroup();
|
|
21
|
+
const context = getCtx();
|
|
22
|
+
const commandState = getState();
|
|
23
|
+
|
|
24
|
+
const trueAlwaysRender = alwaysRender ?? groupContext?.alwaysRender;
|
|
25
|
+
|
|
26
|
+
const render = derived(commandState, ($state) => {
|
|
27
|
+
if (trueAlwaysRender || context.filter() === false || !$commandState.search) return true;
|
|
28
|
+
const currentScore = $commandState.filtered.items.get(id);
|
|
29
|
+
if (isUndefined(currentScore)) return false;
|
|
30
|
+
return currentScore > 0;
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const selected = derived(commandState, ($state) => $commandState.value === value);
|
|
34
|
+
|
|
35
|
+
let isFirstRender = $state(true);
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
let attrs = derived(selected, ($selected) => (
|
|
39
|
+
{
|
|
40
|
+
'aria-disabled': disabled ? true : undefined,
|
|
41
|
+
'data-disabled': disabled ? true : undefined,
|
|
42
|
+
'aria-selected': $selected ? true : undefined,
|
|
43
|
+
'data-selected': $selected ? true : undefined,
|
|
44
|
+
'data-cmdk-item': '',
|
|
45
|
+
'data-value': value,
|
|
46
|
+
role: 'option',
|
|
47
|
+
id
|
|
48
|
+
}
|
|
49
|
+
));
|
|
50
|
+
|
|
51
|
+
onMount(() => {
|
|
52
|
+
isFirstRender = false;
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
onMount(() => {
|
|
57
|
+
let unsub
|
|
58
|
+
unsub = context.item(id, groupContext?.id);
|
|
59
|
+
return unsub;
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
function action(node: HTMLElement) {
|
|
64
|
+
if (!value && node.textContent) {
|
|
65
|
+
value = node.textContent.trim().toLowerCase();
|
|
66
|
+
}
|
|
67
|
+
context.value(id, value);
|
|
68
|
+
node.setAttribute(VALUE_ATTR, value);
|
|
69
|
+
|
|
70
|
+
const unsubEvents = executeCallbacks(
|
|
71
|
+
addEventListener(node, 'pointerenter', () => {
|
|
72
|
+
if (disabled) return;
|
|
73
|
+
select();
|
|
74
|
+
}),
|
|
75
|
+
addEventListener(node, 'click', () => {
|
|
76
|
+
if (disabled) return;
|
|
77
|
+
handleItemClick();
|
|
78
|
+
})
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
destroy() {
|
|
83
|
+
unsubEvents();
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function handleItemClick() {
|
|
89
|
+
select();
|
|
90
|
+
onSelect?.(value);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function select() {
|
|
94
|
+
commandState.updateState('value', value, true);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
</script>
|
|
98
|
+
|
|
99
|
+
{#if $render || isFirstRender}
|
|
100
|
+
<div {...$attrs} use:action {...restProps}>
|
|
101
|
+
<!--{@render childrenWithProps?.(-->
|
|
102
|
+
<!-- {-->
|
|
103
|
+
<!-- attrs: attrs,-->
|
|
104
|
+
<!-- action: action-->
|
|
105
|
+
<!-- }-->
|
|
106
|
+
<!--)-->
|
|
107
|
+
<!--}-->
|
|
108
|
+
{@render children?.()}
|
|
109
|
+
</div>
|
|
110
|
+
{/if}
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import {isHTMLElement} from '../../../internal/index.js';
|
|
3
|
-
import {getCtx, getState} from '../command.js';
|
|
4
|
-
import type {ListProps} from '../types.js';
|
|
5
|
-
|
|
6
|
-
const {ids} = getCtx();
|
|
7
|
-
const commandState = getState();
|
|
8
|
-
|
|
9
|
-
type $$Props = ListProps;
|
|
10
|
-
|
|
11
|
-
let {children, el, ...restProps} = $props()
|
|
12
|
-
|
|
13
|
-
function sizerAction(node: HTMLElement) {
|
|
14
|
-
let animationFrame: number;
|
|
15
|
-
const listEl = node.closest('[data-cmdk-list]');
|
|
16
|
-
if (!isHTMLElement(listEl)) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const observer = new ResizeObserver(() => {
|
|
21
|
-
animationFrame = requestAnimationFrame(() => {
|
|
22
|
-
const height = node.offsetHeight;
|
|
23
|
-
listEl.style.setProperty('--cmdk-list-height', height.toFixed(1) + 'px');
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
observer.observe(node);
|
|
28
|
-
return {
|
|
29
|
-
destroy() {
|
|
30
|
-
cancelAnimationFrame(animationFrame);
|
|
31
|
-
observer.unobserve(node);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const listAttrs = {
|
|
37
|
-
'data-cmdk-list': '',
|
|
38
|
-
role: 'listbox',
|
|
39
|
-
'aria-label': 'Suggestions',
|
|
40
|
-
id: ids.list,
|
|
41
|
-
'aria-labelledby': ids.input
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const sizerAttrs = {
|
|
45
|
-
'data-cmdk-list-sizer': ''
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
</script>
|
|
49
|
-
|
|
50
|
-
<div {...listAttrs} bind:this={el} {...restProps}>
|
|
51
|
-
<div {...sizerAttrs} use:sizerAction>
|
|
52
|
-
{#key $commandState.search === ''}
|
|
53
|
-
{@render children()}
|
|
54
|
-
{/key}
|
|
55
|
-
</div>
|
|
56
|
-
</div>
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import {isHTMLElement} from '../../../internal/index.js';
|
|
3
|
+
import {getCtx, getState} from '../command.js';
|
|
4
|
+
import type {ListProps} from '../types.js';
|
|
5
|
+
|
|
6
|
+
const {ids} = getCtx();
|
|
7
|
+
const commandState = getState();
|
|
8
|
+
|
|
9
|
+
type $$Props = ListProps;
|
|
10
|
+
|
|
11
|
+
let {children, el, ...restProps} = $props()
|
|
12
|
+
|
|
13
|
+
function sizerAction(node: HTMLElement) {
|
|
14
|
+
let animationFrame: number;
|
|
15
|
+
const listEl = node.closest('[data-cmdk-list]');
|
|
16
|
+
if (!isHTMLElement(listEl)) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const observer = new ResizeObserver(() => {
|
|
21
|
+
animationFrame = requestAnimationFrame(() => {
|
|
22
|
+
const height = node.offsetHeight;
|
|
23
|
+
listEl.style.setProperty('--cmdk-list-height', height.toFixed(1) + 'px');
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
observer.observe(node);
|
|
28
|
+
return {
|
|
29
|
+
destroy() {
|
|
30
|
+
cancelAnimationFrame(animationFrame);
|
|
31
|
+
observer.unobserve(node);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const listAttrs = {
|
|
37
|
+
'data-cmdk-list': '',
|
|
38
|
+
role: 'listbox',
|
|
39
|
+
'aria-label': 'Suggestions',
|
|
40
|
+
id: ids.list,
|
|
41
|
+
'aria-labelledby': ids.input
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const sizerAttrs = {
|
|
45
|
+
'data-cmdk-list-sizer': ''
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
</script>
|
|
49
|
+
|
|
50
|
+
<div {...listAttrs} bind:this={el} {...restProps}>
|
|
51
|
+
<div {...sizerAttrs} use:sizerAction>
|
|
52
|
+
{#key $commandState.search === ''}
|
|
53
|
+
{@render children()}
|
|
54
|
+
{/key}
|
|
55
|
+
</div>
|
|
56
|
+
</div>
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import type { LoadingProps } from '../types.js';
|
|
3
|
-
import type {Snippet} from "svelte";
|
|
4
|
-
|
|
5
|
-
type $$Props = LoadingProps;
|
|
6
|
-
|
|
7
|
-
let {childrenWithProps, progress, ...restProps} : $$Props & {
|
|
8
|
-
childrenWithProps: Snippet<[any]>
|
|
9
|
-
} = $props()
|
|
10
|
-
|
|
11
|
-
let attrs = $state<any>()
|
|
12
|
-
|
|
13
|
-
$effect(() => {
|
|
14
|
-
attrs = {
|
|
15
|
-
'data-cmdk-loading': '',
|
|
16
|
-
role: 'progressbar',
|
|
17
|
-
'aria-valuenow': progress,
|
|
18
|
-
'aria-valuemin': 0,
|
|
19
|
-
'aria-valuemax': 100,
|
|
20
|
-
'aria-label': 'Loading...'
|
|
21
|
-
};
|
|
22
|
-
})
|
|
23
|
-
</script>
|
|
24
|
-
|
|
25
|
-
<div {...attrs} {...restProps}>
|
|
26
|
-
<div aria-hidden>
|
|
27
|
-
{@render childrenWithProps(attrs)}
|
|
28
|
-
</div>
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { LoadingProps } from '../types.js';
|
|
3
|
+
import type {Snippet} from "svelte";
|
|
4
|
+
|
|
5
|
+
type $$Props = LoadingProps;
|
|
6
|
+
|
|
7
|
+
let {childrenWithProps, progress, ...restProps} : $$Props & {
|
|
8
|
+
childrenWithProps: Snippet<[any]>
|
|
9
|
+
} = $props()
|
|
10
|
+
|
|
11
|
+
let attrs = $state<any>()
|
|
12
|
+
|
|
13
|
+
$effect(() => {
|
|
14
|
+
attrs = {
|
|
15
|
+
'data-cmdk-loading': '',
|
|
16
|
+
role: 'progressbar',
|
|
17
|
+
'aria-valuenow': progress,
|
|
18
|
+
'aria-valuemin': 0,
|
|
19
|
+
'aria-valuemax': 100,
|
|
20
|
+
'aria-label': 'Loading...'
|
|
21
|
+
};
|
|
22
|
+
})
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<div {...attrs} {...restProps}>
|
|
26
|
+
<div aria-hidden>
|
|
27
|
+
{@render childrenWithProps(attrs)}
|
|
28
|
+
</div>
|
|
29
29
|
</div>
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { derived } from 'svelte/store';
|
|
3
|
-
import { getState } from '../command.js';
|
|
4
|
-
import type { SeparatorProps } from '../types.js';
|
|
5
|
-
|
|
6
|
-
type $$Props = SeparatorProps;
|
|
7
|
-
|
|
8
|
-
let {alwaysRender,...restProps} :$$Props= $props()
|
|
9
|
-
|
|
10
|
-
const commandState = getState();
|
|
11
|
-
const render = derived(commandState, ($state) => !$commandState.search);
|
|
12
|
-
|
|
13
|
-
const attrs = {
|
|
14
|
-
'data-cmdk-separator': '',
|
|
15
|
-
role: 'separator'
|
|
16
|
-
};
|
|
17
|
-
</script>
|
|
18
|
-
|
|
19
|
-
{#if $render || alwaysRender}
|
|
20
|
-
<div {...attrs} {...restProps}></div>
|
|
21
|
-
{/if}
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { derived } from 'svelte/store';
|
|
3
|
+
import { getState } from '../command.js';
|
|
4
|
+
import type { SeparatorProps } from '../types.js';
|
|
5
|
+
|
|
6
|
+
type $$Props = SeparatorProps;
|
|
7
|
+
|
|
8
|
+
let {alwaysRender,...restProps} :$$Props= $props()
|
|
9
|
+
|
|
10
|
+
const commandState = getState();
|
|
11
|
+
const render = derived(commandState, ($state) => !$commandState.search);
|
|
12
|
+
|
|
13
|
+
const attrs = {
|
|
14
|
+
'data-cmdk-separator': '',
|
|
15
|
+
role: 'separator'
|
|
16
|
+
};
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
{#if $render || alwaysRender}
|
|
20
|
+
<div {...attrs} {...restProps}></div>
|
|
21
|
+
{/if}
|
|
@@ -1,108 +1,108 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import {type DialogProps, styles} from "./Dialog";
|
|
3
|
-
import IconX from "../icons/IconX.svelte";
|
|
4
|
-
import {Button} from "../button";
|
|
5
|
-
import './dialog.scss'
|
|
6
|
-
import {sleep} from "../../internal/helpers/sleep";
|
|
7
|
-
|
|
8
|
-
let {
|
|
9
|
-
children, open = $bindable(),
|
|
10
|
-
closeOnClickOutside = true,
|
|
11
|
-
closeButton = true,
|
|
12
|
-
size = 'sm',
|
|
13
|
-
header,
|
|
14
|
-
footer,
|
|
15
|
-
class: className,
|
|
16
|
-
position = 'center',
|
|
17
|
-
padding,
|
|
18
|
-
staticRender = false,
|
|
19
|
-
triggerRef,
|
|
20
|
-
focusTriggerAfterClose,
|
|
21
|
-
...props
|
|
22
|
-
}: DialogProps = $props();
|
|
23
|
-
|
|
24
|
-
let dialog;
|
|
25
|
-
|
|
26
|
-
let hasOpened = $state(false);
|
|
27
|
-
|
|
28
|
-
// Watch for prop changes to open/close the dialog
|
|
29
|
-
$effect(() => {
|
|
30
|
-
if (open) {
|
|
31
|
-
stillAnimating = open
|
|
32
|
-
dialog?.showModal();
|
|
33
|
-
|
|
34
|
-
if (!hasOpened)
|
|
35
|
-
hasOpened = true
|
|
36
|
-
} else {
|
|
37
|
-
dialog?.close()
|
|
38
|
-
sleep(200).then(() => {
|
|
39
|
-
stillAnimating = open
|
|
40
|
-
console.log('stillAnimating', stillAnimating)
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
if (focusTriggerAfterClose && hasOpened && triggerRef) {
|
|
44
|
-
triggerRef.focus()
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
// Close dialog on clicking outside (optional)
|
|
50
|
-
function handleClickOutside(e) {
|
|
51
|
-
if (closeOnClickOutside && e.target === dialog) {
|
|
52
|
-
dialog?.close();
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Emit close event when dialog is closed
|
|
57
|
-
function handleClose() {
|
|
58
|
-
open = false;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// onmousedown={closeOnClickOutside ? 'event.target==this && this.close()' : ''}
|
|
62
|
-
|
|
63
|
-
const {base, dialog: dialogStyle, dialogContainer, header: headerStyle, body, footer: footerStyle} = styles({
|
|
64
|
-
size,
|
|
65
|
-
padding
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
let stillAnimating = $state()
|
|
69
|
-
|
|
70
|
-
</script>
|
|
71
|
-
|
|
72
|
-
{#if staticRender || (!staticRender && (open || stillAnimating))}
|
|
73
|
-
<dialog class={dialogStyle() + ` ${className}`}
|
|
74
|
-
data-position={position}
|
|
75
|
-
bind:this={dialog}
|
|
76
|
-
onclose={handleClose}
|
|
77
|
-
onmousedown={handleClickOutside}
|
|
78
|
-
size={size}
|
|
79
|
-
>
|
|
80
|
-
<button class=""></button>
|
|
81
|
-
{#if (closeButton)}
|
|
82
|
-
<form method="dialog">
|
|
83
|
-
<Button class="absolute right-1 top-1 [&>svg]:opacity-45 [&>svg]:hover:opacity-90 z-10" icon
|
|
84
|
-
variant="ghost"
|
|
85
|
-
size="sm">
|
|
86
|
-
<IconX/>
|
|
87
|
-
</Button>
|
|
88
|
-
</form>
|
|
89
|
-
{/if}
|
|
90
|
-
|
|
91
|
-
<div class={"dialog-box " + dialogContainer()}>
|
|
92
|
-
{#if header}
|
|
93
|
-
<header class={headerStyle()}>
|
|
94
|
-
{@render header?.()}
|
|
95
|
-
</header>
|
|
96
|
-
{/if}
|
|
97
|
-
|
|
98
|
-
<main class={body()}>
|
|
99
|
-
{@render children?.()}
|
|
100
|
-
</main>
|
|
101
|
-
{#if footer}
|
|
102
|
-
<footer class={footerStyle()}>
|
|
103
|
-
{@render footer?.()}
|
|
104
|
-
</footer>
|
|
105
|
-
{/if}
|
|
106
|
-
</div>
|
|
107
|
-
</dialog>
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import {type DialogProps, styles} from "./Dialog";
|
|
3
|
+
import IconX from "../icons/IconX.svelte";
|
|
4
|
+
import {Button} from "../button";
|
|
5
|
+
import './dialog.scss'
|
|
6
|
+
import {sleep} from "../../internal/helpers/sleep";
|
|
7
|
+
|
|
8
|
+
let {
|
|
9
|
+
children, open = $bindable(),
|
|
10
|
+
closeOnClickOutside = true,
|
|
11
|
+
closeButton = true,
|
|
12
|
+
size = 'sm',
|
|
13
|
+
header,
|
|
14
|
+
footer,
|
|
15
|
+
class: className,
|
|
16
|
+
position = 'center',
|
|
17
|
+
padding,
|
|
18
|
+
staticRender = false,
|
|
19
|
+
triggerRef,
|
|
20
|
+
focusTriggerAfterClose,
|
|
21
|
+
...props
|
|
22
|
+
}: DialogProps = $props();
|
|
23
|
+
|
|
24
|
+
let dialog;
|
|
25
|
+
|
|
26
|
+
let hasOpened = $state(false);
|
|
27
|
+
|
|
28
|
+
// Watch for prop changes to open/close the dialog
|
|
29
|
+
$effect(() => {
|
|
30
|
+
if (open) {
|
|
31
|
+
stillAnimating = open
|
|
32
|
+
dialog?.showModal();
|
|
33
|
+
|
|
34
|
+
if (!hasOpened)
|
|
35
|
+
hasOpened = true
|
|
36
|
+
} else {
|
|
37
|
+
dialog?.close()
|
|
38
|
+
sleep(200).then(() => {
|
|
39
|
+
stillAnimating = open
|
|
40
|
+
console.log('stillAnimating', stillAnimating)
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
if (focusTriggerAfterClose && hasOpened && triggerRef) {
|
|
44
|
+
triggerRef.focus()
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
// Close dialog on clicking outside (optional)
|
|
50
|
+
function handleClickOutside(e) {
|
|
51
|
+
if (closeOnClickOutside && e.target === dialog) {
|
|
52
|
+
dialog?.close();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Emit close event when dialog is closed
|
|
57
|
+
function handleClose() {
|
|
58
|
+
open = false;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// onmousedown={closeOnClickOutside ? 'event.target==this && this.close()' : ''}
|
|
62
|
+
|
|
63
|
+
const {base, dialog: dialogStyle, dialogContainer, header: headerStyle, body, footer: footerStyle} = styles({
|
|
64
|
+
size,
|
|
65
|
+
padding
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
let stillAnimating = $state()
|
|
69
|
+
|
|
70
|
+
</script>
|
|
71
|
+
|
|
72
|
+
{#if staticRender || (!staticRender && (open || stillAnimating))}
|
|
73
|
+
<dialog class={dialogStyle() + ` ${className}`}
|
|
74
|
+
data-position={position}
|
|
75
|
+
bind:this={dialog}
|
|
76
|
+
onclose={handleClose}
|
|
77
|
+
onmousedown={handleClickOutside}
|
|
78
|
+
size={size}
|
|
79
|
+
>
|
|
80
|
+
<button class=""></button>
|
|
81
|
+
{#if (closeButton)}
|
|
82
|
+
<form method="dialog">
|
|
83
|
+
<Button class="absolute right-1 top-1 [&>svg]:opacity-45 [&>svg]:hover:opacity-90 z-10" icon
|
|
84
|
+
variant="ghost"
|
|
85
|
+
size="sm">
|
|
86
|
+
<IconX/>
|
|
87
|
+
</Button>
|
|
88
|
+
</form>
|
|
89
|
+
{/if}
|
|
90
|
+
|
|
91
|
+
<div class={"dialog-box " + dialogContainer()}>
|
|
92
|
+
{#if header}
|
|
93
|
+
<header class={headerStyle()}>
|
|
94
|
+
{@render header?.()}
|
|
95
|
+
</header>
|
|
96
|
+
{/if}
|
|
97
|
+
|
|
98
|
+
<main class={body()}>
|
|
99
|
+
{@render children?.()}
|
|
100
|
+
</main>
|
|
101
|
+
{#if footer}
|
|
102
|
+
<footer class={footerStyle()}>
|
|
103
|
+
{@render footer?.()}
|
|
104
|
+
</footer>
|
|
105
|
+
{/if}
|
|
106
|
+
</div>
|
|
107
|
+
</dialog>
|
|
108
108
|
{/if}
|