tera-system-ui 0.0.19 → 0.0.20
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.astro +63 -0
- package/dist/components/dialog/Dialog.d.ts +10 -6
- package/dist/components/dialog/Dialog.svelte +109 -107
- package/dist/components/dialog/dialog.scss +115 -112
- package/dist/components/dialog/index.d.ts +1 -0
- package/dist/components/dialog/index.js +1 -0
- 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 -114
- 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.d.ts +1 -0
- package/dist/components/tera-ui-context/TeraUiContext.svelte +28 -28
- package/dist/components/tera-ui-context/global-context-store.d.ts +3 -0
- package/dist/components/tera-ui-context/global-context-store.js +2 -0
- package/dist/components/tera-ui-context/global-context.js +11 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/themes/scrollbar.scss +37 -37
- package/dist/themes/tera-ui-base.css +58 -22
- package/dist/themes/tw-preset.cjs +3 -0
- package/dist/themes/tw-preset.d.cts +4 -0
- package/package.json +96 -95
- package/scripts/add-component-template.js +120 -120
- package/scripts/generate-ts-index.js +136 -136
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import {type LightDarkToggleProps} from "./LightDarkToggle";
|
|
3
|
-
import {Button} from "../button";
|
|
4
|
-
import IconSun from "../icons/IconSun.svelte";
|
|
5
|
-
import IconMoon from "../icons/IconMoon.svelte";
|
|
6
|
-
|
|
7
|
-
let {children, ...props}: LightDarkToggleProps = $props();
|
|
8
|
-
|
|
9
|
-
// $effect(() => {
|
|
10
|
-
// const htmlElement = document.documentElement;
|
|
11
|
-
// // Check for saved theme preference
|
|
12
|
-
// const currentTheme = localStorage.getItem('theme');
|
|
13
|
-
// if (currentTheme === 'dark') {
|
|
14
|
-
// htmlElement.classList.add('dark');
|
|
15
|
-
// } else {
|
|
16
|
-
// htmlElement.classList.remove('dark');
|
|
17
|
-
// }
|
|
18
|
-
// })
|
|
19
|
-
|
|
20
|
-
function toggleLightDarkTheme() {
|
|
21
|
-
const htmlElement = document.documentElement;
|
|
22
|
-
|
|
23
|
-
htmlElement.classList.toggle('dark');
|
|
24
|
-
const theme = htmlElement.classList.contains('dark') ? 'dark' : 'light';
|
|
25
|
-
localStorage.setItem('theme', theme);
|
|
26
|
-
}
|
|
27
|
-
</script>
|
|
28
|
-
|
|
29
|
-
<!--add component here-->
|
|
30
|
-
<Button variant="ghost" icon
|
|
31
|
-
onclick={toggleLightDarkTheme}>
|
|
32
|
-
<!-- Sun icon, animates out when in dark mode -->
|
|
33
|
-
<IconSun class="icon-sun dark:hidden"/>
|
|
34
|
-
<!-- Moon icon, animates in when in dark mode -->
|
|
35
|
-
<IconMoon class="icon-moon hidden dark:block"/>
|
|
36
|
-
</Button>
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import {type LightDarkToggleProps} from "./LightDarkToggle";
|
|
3
|
+
import {Button} from "../button";
|
|
4
|
+
import IconSun from "../icons/IconSun.svelte";
|
|
5
|
+
import IconMoon from "../icons/IconMoon.svelte";
|
|
6
|
+
|
|
7
|
+
let {children, ...props}: LightDarkToggleProps = $props();
|
|
8
|
+
|
|
9
|
+
// $effect(() => {
|
|
10
|
+
// const htmlElement = document.documentElement;
|
|
11
|
+
// // Check for saved theme preference
|
|
12
|
+
// const currentTheme = localStorage.getItem('theme');
|
|
13
|
+
// if (currentTheme === 'dark') {
|
|
14
|
+
// htmlElement.classList.add('dark');
|
|
15
|
+
// } else {
|
|
16
|
+
// htmlElement.classList.remove('dark');
|
|
17
|
+
// }
|
|
18
|
+
// })
|
|
19
|
+
|
|
20
|
+
function toggleLightDarkTheme() {
|
|
21
|
+
const htmlElement = document.documentElement;
|
|
22
|
+
|
|
23
|
+
htmlElement.classList.toggle('dark');
|
|
24
|
+
const theme = htmlElement.classList.contains('dark') ? 'dark' : 'light';
|
|
25
|
+
localStorage.setItem('theme', theme);
|
|
26
|
+
}
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<!--add component here-->
|
|
30
|
+
<Button variant="ghost" icon
|
|
31
|
+
onclick={toggleLightDarkTheme}>
|
|
32
|
+
<!-- Sun icon, animates out when in dark mode -->
|
|
33
|
+
<IconSun class="icon-sun dark:hidden"/>
|
|
34
|
+
<!-- Moon icon, animates in when in dark mode -->
|
|
35
|
+
<IconMoon class="icon-moon hidden dark:block"/>
|
|
36
|
+
</Button>
|
|
@@ -1,137 +1,137 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import {type PopoverProps} from "./Popover";
|
|
3
|
-
import {arrow, autoUpdate, computePosition, flip, offset, shift, size} from "@floating-ui/dom";
|
|
4
|
-
import {cn} from "../../utils/utils";
|
|
5
|
-
|
|
6
|
-
import {clickOutside} from "../../actions/clickOutside"
|
|
7
|
-
import {onDestroy, onMount} from "svelte";
|
|
8
|
-
|
|
9
|
-
let {
|
|
10
|
-
children,
|
|
11
|
-
triggerRef,
|
|
12
|
-
class: className,
|
|
13
|
-
open = $bindable(),
|
|
14
|
-
offset: offsetAmount = 3,
|
|
15
|
-
padding: paddingAmount = 12,
|
|
16
|
-
focusTriggerAfterClose = true,
|
|
17
|
-
flip: enableFlip = false,
|
|
18
|
-
autoTrigger = true,
|
|
19
|
-
...props
|
|
20
|
-
}: PopoverProps = $props();
|
|
21
|
-
|
|
22
|
-
let hasOpenedYet = $state(false)
|
|
23
|
-
|
|
24
|
-
function togglePopover() {
|
|
25
|
-
open = !open;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
function handleClickOutside(e) {
|
|
30
|
-
open = false
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
let popover = $state();
|
|
34
|
-
let arrowElement = $state();
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
function updatePosition() {
|
|
38
|
-
computePosition(triggerRef, popover, {
|
|
39
|
-
placement: 'bottom',
|
|
40
|
-
middleware: [
|
|
41
|
-
offset(offsetAmount),
|
|
42
|
-
size({
|
|
43
|
-
apply({rects, elements}) {
|
|
44
|
-
Object.assign(elements.floating.style, {
|
|
45
|
-
minWidth: `${rects.reference.width}px`,
|
|
46
|
-
});
|
|
47
|
-
},
|
|
48
|
-
}),
|
|
49
|
-
enableFlip ? flip() : undefined,
|
|
50
|
-
shift({padding: paddingAmount}),
|
|
51
|
-
arrow({element: arrowElement}),
|
|
52
|
-
],
|
|
53
|
-
}).then(({x, y, placement, middlewareData}) => {
|
|
54
|
-
Object.assign(popover.style, {
|
|
55
|
-
left: `${x}px`,
|
|
56
|
-
top: `${y}px`,
|
|
57
|
-
});
|
|
58
|
-
//
|
|
59
|
-
// // Accessing the data
|
|
60
|
-
// const {x: arrowX, y: arrowY} = middlewareData.arrow;
|
|
61
|
-
//
|
|
62
|
-
// const staticSide = {
|
|
63
|
-
// top: 'bottom',
|
|
64
|
-
// right: 'left',
|
|
65
|
-
// bottom: 'top',
|
|
66
|
-
// left: 'right',
|
|
67
|
-
// }[placement.split('-')[0]];
|
|
68
|
-
//
|
|
69
|
-
// Object.assign(arrowElement.style, {
|
|
70
|
-
// left: arrowX != null ? `${arrowX}px` : '',
|
|
71
|
-
// top: arrowY != null ? `${arrowY}px` : '',
|
|
72
|
-
// right: '',
|
|
73
|
-
// bottom: '',
|
|
74
|
-
// [staticSide]: '-4px',
|
|
75
|
-
// });
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
onMount(() => {
|
|
80
|
-
if (autoTrigger)
|
|
81
|
-
triggerRef?.addEventListener("click", togglePopover);
|
|
82
|
-
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
onDestroy(() => {
|
|
86
|
-
if (autoTrigger)
|
|
87
|
-
triggerRef?.removeEventListener("click", togglePopover);
|
|
88
|
-
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
$effect(() => {
|
|
92
|
-
let cleanup: any
|
|
93
|
-
|
|
94
|
-
if (open) {
|
|
95
|
-
hasOpenedYet = true
|
|
96
|
-
updatePosition()
|
|
97
|
-
|
|
98
|
-
// Start auto updates.
|
|
99
|
-
cleanup = autoUpdate(
|
|
100
|
-
triggerRef,
|
|
101
|
-
popover,
|
|
102
|
-
updatePosition,
|
|
103
|
-
);
|
|
104
|
-
} else {
|
|
105
|
-
cleanup?.()
|
|
106
|
-
if (focusTriggerAfterClose && hasOpenedYet) {
|
|
107
|
-
try {
|
|
108
|
-
triggerRef.focus()
|
|
109
|
-
} catch (e) {
|
|
110
|
-
console.warn('Trigger element focus after close Popover error', e)
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return () => {
|
|
116
|
-
cleanup?.()
|
|
117
|
-
}
|
|
118
|
-
})
|
|
119
|
-
</script>
|
|
120
|
-
|
|
121
|
-
<!-- Popover Content -->
|
|
122
|
-
{#if open}
|
|
123
|
-
<div bind:this={popover}
|
|
124
|
-
class={cn("overflow-hidden absolute z-10 bg-neutral-token-1 shadow-2xl rounded-container border border-neutral-token-5", className)}
|
|
125
|
-
use:clickOutside={{exceptElement: triggerRef}}
|
|
126
|
-
onclick_outside={handleClickOutside}
|
|
127
|
-
{...props}
|
|
128
|
-
>
|
|
129
|
-
<!-- <div bind:this={arrowElement} class="size-2 absolute rotate-45 bg-inherit"></div>-->
|
|
130
|
-
{@render children?.()}
|
|
131
|
-
</div>
|
|
132
|
-
{/if}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
<style>
|
|
136
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import {type PopoverProps} from "./Popover";
|
|
3
|
+
import {arrow, autoUpdate, computePosition, flip, offset, shift, size} from "@floating-ui/dom";
|
|
4
|
+
import {cn} from "../../utils/utils";
|
|
5
|
+
|
|
6
|
+
import {clickOutside} from "../../actions/clickOutside"
|
|
7
|
+
import {onDestroy, onMount} from "svelte";
|
|
8
|
+
|
|
9
|
+
let {
|
|
10
|
+
children,
|
|
11
|
+
triggerRef,
|
|
12
|
+
class: className,
|
|
13
|
+
open = $bindable(),
|
|
14
|
+
offset: offsetAmount = 3,
|
|
15
|
+
padding: paddingAmount = 12,
|
|
16
|
+
focusTriggerAfterClose = true,
|
|
17
|
+
flip: enableFlip = false,
|
|
18
|
+
autoTrigger = true,
|
|
19
|
+
...props
|
|
20
|
+
}: PopoverProps = $props();
|
|
21
|
+
|
|
22
|
+
let hasOpenedYet = $state(false)
|
|
23
|
+
|
|
24
|
+
function togglePopover() {
|
|
25
|
+
open = !open;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
function handleClickOutside(e) {
|
|
30
|
+
open = false
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let popover = $state();
|
|
34
|
+
let arrowElement = $state();
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
function updatePosition() {
|
|
38
|
+
computePosition(triggerRef, popover, {
|
|
39
|
+
placement: 'bottom',
|
|
40
|
+
middleware: [
|
|
41
|
+
offset(offsetAmount),
|
|
42
|
+
size({
|
|
43
|
+
apply({rects, elements}) {
|
|
44
|
+
Object.assign(elements.floating.style, {
|
|
45
|
+
minWidth: `${rects.reference.width}px`,
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
}),
|
|
49
|
+
enableFlip ? flip() : undefined,
|
|
50
|
+
shift({padding: paddingAmount}),
|
|
51
|
+
arrow({element: arrowElement}),
|
|
52
|
+
],
|
|
53
|
+
}).then(({x, y, placement, middlewareData}) => {
|
|
54
|
+
Object.assign(popover.style, {
|
|
55
|
+
left: `${x}px`,
|
|
56
|
+
top: `${y}px`,
|
|
57
|
+
});
|
|
58
|
+
//
|
|
59
|
+
// // Accessing the data
|
|
60
|
+
// const {x: arrowX, y: arrowY} = middlewareData.arrow;
|
|
61
|
+
//
|
|
62
|
+
// const staticSide = {
|
|
63
|
+
// top: 'bottom',
|
|
64
|
+
// right: 'left',
|
|
65
|
+
// bottom: 'top',
|
|
66
|
+
// left: 'right',
|
|
67
|
+
// }[placement.split('-')[0]];
|
|
68
|
+
//
|
|
69
|
+
// Object.assign(arrowElement.style, {
|
|
70
|
+
// left: arrowX != null ? `${arrowX}px` : '',
|
|
71
|
+
// top: arrowY != null ? `${arrowY}px` : '',
|
|
72
|
+
// right: '',
|
|
73
|
+
// bottom: '',
|
|
74
|
+
// [staticSide]: '-4px',
|
|
75
|
+
// });
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
onMount(() => {
|
|
80
|
+
if (autoTrigger)
|
|
81
|
+
triggerRef?.addEventListener("click", togglePopover);
|
|
82
|
+
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
onDestroy(() => {
|
|
86
|
+
if (autoTrigger)
|
|
87
|
+
triggerRef?.removeEventListener("click", togglePopover);
|
|
88
|
+
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
$effect(() => {
|
|
92
|
+
let cleanup: any
|
|
93
|
+
|
|
94
|
+
if (open) {
|
|
95
|
+
hasOpenedYet = true
|
|
96
|
+
updatePosition()
|
|
97
|
+
|
|
98
|
+
// Start auto updates.
|
|
99
|
+
cleanup = autoUpdate(
|
|
100
|
+
triggerRef,
|
|
101
|
+
popover,
|
|
102
|
+
updatePosition,
|
|
103
|
+
);
|
|
104
|
+
} else {
|
|
105
|
+
cleanup?.()
|
|
106
|
+
if (focusTriggerAfterClose && hasOpenedYet) {
|
|
107
|
+
try {
|
|
108
|
+
triggerRef.focus()
|
|
109
|
+
} catch (e) {
|
|
110
|
+
console.warn('Trigger element focus after close Popover error', e)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return () => {
|
|
116
|
+
cleanup?.()
|
|
117
|
+
}
|
|
118
|
+
})
|
|
119
|
+
</script>
|
|
120
|
+
|
|
121
|
+
<!-- Popover Content -->
|
|
122
|
+
{#if open}
|
|
123
|
+
<div bind:this={popover}
|
|
124
|
+
class={cn("overflow-hidden absolute z-10 bg-neutral-token-1 shadow-2xl rounded-container border border-neutral-token-5", className)}
|
|
125
|
+
use:clickOutside={{exceptElement: triggerRef}}
|
|
126
|
+
onclick_outside={handleClickOutside}
|
|
127
|
+
{...props}
|
|
128
|
+
>
|
|
129
|
+
<!-- <div bind:this={arrowElement} class="size-2 absolute rotate-45 bg-inherit"></div>-->
|
|
130
|
+
{@render children?.()}
|
|
131
|
+
</div>
|
|
132
|
+
{/if}
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
<style>
|
|
136
|
+
|
|
137
137
|
</style>
|
|
@@ -1,88 +1,88 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import {type PopoverResponsiveProps} from "./PopoverResponsive";
|
|
3
|
-
import {Dialog, Popover} from "../..";
|
|
4
|
-
import {onMount} from "svelte";
|
|
5
|
-
import {getScreenWidth, SCREEN_BREAK_POINTS} from "../side-navigation/SideNavigation";
|
|
6
|
-
|
|
7
|
-
let {
|
|
8
|
-
children,
|
|
9
|
-
triggerRef,
|
|
10
|
-
class: className,
|
|
11
|
-
open = $bindable(),
|
|
12
|
-
offset = 3,
|
|
13
|
-
popoverPadding = 12,
|
|
14
|
-
focusTriggerAfterClose = true,
|
|
15
|
-
flip = false,
|
|
16
|
-
...props
|
|
17
|
-
}: PopoverResponsiveProps & {
|
|
18
|
-
dialogPadding?: string,
|
|
19
|
-
popoverPadding?: number,
|
|
20
|
-
offset?: number,
|
|
21
|
-
open?: boolean,
|
|
22
|
-
focusTriggerAfterClose?: boolean,
|
|
23
|
-
flip?: boolean,
|
|
24
|
-
triggerRef?: HTMLElement,
|
|
25
|
-
} = $props();
|
|
26
|
-
|
|
27
|
-
let openPopover = $state(false)
|
|
28
|
-
let openDialog = $state(false)
|
|
29
|
-
|
|
30
|
-
$effect(() => {
|
|
31
|
-
open = openPopover || openDialog
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
$effect(() => {
|
|
35
|
-
toggleOpen(open)
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
function toggleOpen(open?: boolean) {
|
|
39
|
-
if (getScreenWidth() >= SCREEN_BREAK_POINTS.sm) {
|
|
40
|
-
if (open === undefined) {
|
|
41
|
-
openPopover = !(openDialog || openPopover)
|
|
42
|
-
} else {
|
|
43
|
-
openPopover = open
|
|
44
|
-
}
|
|
45
|
-
openDialog = false
|
|
46
|
-
} else {
|
|
47
|
-
if (open === undefined) {
|
|
48
|
-
openDialog = !(openDialog || openPopover)
|
|
49
|
-
} else {
|
|
50
|
-
openDialog = open
|
|
51
|
-
}
|
|
52
|
-
openPopover = false
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
console.log('toggleOpen Responsive Popover', open)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
onMount(() => {
|
|
59
|
-
triggerRef?.addEventListener('click', (e) => {
|
|
60
|
-
e.stopPropagation()
|
|
61
|
-
toggleOpen()
|
|
62
|
-
})
|
|
63
|
-
})
|
|
64
|
-
</script>
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
<Popover bind:open={openPopover}
|
|
68
|
-
triggerRef={triggerRef}
|
|
69
|
-
autoTrigger={false}
|
|
70
|
-
padding={popoverPadding}
|
|
71
|
-
focusTriggerAfterClose={focusTriggerAfterClose}
|
|
72
|
-
offset={offset}
|
|
73
|
-
flip={flip}
|
|
74
|
-
class={className}
|
|
75
|
-
{...props}
|
|
76
|
-
>
|
|
77
|
-
{@render children?.()}
|
|
78
|
-
</Popover>
|
|
79
|
-
|
|
80
|
-
<Dialog bind:open={openDialog}
|
|
81
|
-
position="top"
|
|
82
|
-
padding="none"
|
|
83
|
-
class={className}
|
|
84
|
-
triggerRef={triggerRef}
|
|
85
|
-
focusTriggerAfterClose={focusTriggerAfterClose}
|
|
86
|
-
>
|
|
87
|
-
{@render children?.()}
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import {type PopoverResponsiveProps} from "./PopoverResponsive";
|
|
3
|
+
import {Dialog, Popover} from "../..";
|
|
4
|
+
import {onMount} from "svelte";
|
|
5
|
+
import {getScreenWidth, SCREEN_BREAK_POINTS} from "../side-navigation/SideNavigation";
|
|
6
|
+
|
|
7
|
+
let {
|
|
8
|
+
children,
|
|
9
|
+
triggerRef,
|
|
10
|
+
class: className,
|
|
11
|
+
open = $bindable(),
|
|
12
|
+
offset = 3,
|
|
13
|
+
popoverPadding = 12,
|
|
14
|
+
focusTriggerAfterClose = true,
|
|
15
|
+
flip = false,
|
|
16
|
+
...props
|
|
17
|
+
}: PopoverResponsiveProps & {
|
|
18
|
+
dialogPadding?: string,
|
|
19
|
+
popoverPadding?: number,
|
|
20
|
+
offset?: number,
|
|
21
|
+
open?: boolean,
|
|
22
|
+
focusTriggerAfterClose?: boolean,
|
|
23
|
+
flip?: boolean,
|
|
24
|
+
triggerRef?: HTMLElement,
|
|
25
|
+
} = $props();
|
|
26
|
+
|
|
27
|
+
let openPopover = $state(false)
|
|
28
|
+
let openDialog = $state(false)
|
|
29
|
+
|
|
30
|
+
$effect(() => {
|
|
31
|
+
open = openPopover || openDialog
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
$effect(() => {
|
|
35
|
+
toggleOpen(open)
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
function toggleOpen(open?: boolean) {
|
|
39
|
+
if (getScreenWidth() >= SCREEN_BREAK_POINTS.sm) {
|
|
40
|
+
if (open === undefined) {
|
|
41
|
+
openPopover = !(openDialog || openPopover)
|
|
42
|
+
} else {
|
|
43
|
+
openPopover = open
|
|
44
|
+
}
|
|
45
|
+
openDialog = false
|
|
46
|
+
} else {
|
|
47
|
+
if (open === undefined) {
|
|
48
|
+
openDialog = !(openDialog || openPopover)
|
|
49
|
+
} else {
|
|
50
|
+
openDialog = open
|
|
51
|
+
}
|
|
52
|
+
openPopover = false
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
console.log('toggleOpen Responsive Popover', open)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
onMount(() => {
|
|
59
|
+
triggerRef?.addEventListener('click', (e) => {
|
|
60
|
+
e.stopPropagation()
|
|
61
|
+
toggleOpen()
|
|
62
|
+
})
|
|
63
|
+
})
|
|
64
|
+
</script>
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
<Popover bind:open={openPopover}
|
|
68
|
+
triggerRef={triggerRef}
|
|
69
|
+
autoTrigger={false}
|
|
70
|
+
padding={popoverPadding}
|
|
71
|
+
focusTriggerAfterClose={focusTriggerAfterClose}
|
|
72
|
+
offset={offset}
|
|
73
|
+
flip={flip}
|
|
74
|
+
class={className}
|
|
75
|
+
{...props}
|
|
76
|
+
>
|
|
77
|
+
{@render children?.()}
|
|
78
|
+
</Popover>
|
|
79
|
+
|
|
80
|
+
<Dialog bind:open={openDialog}
|
|
81
|
+
position="top"
|
|
82
|
+
padding="none"
|
|
83
|
+
class={className}
|
|
84
|
+
triggerRef={triggerRef}
|
|
85
|
+
focusTriggerAfterClose={focusTriggerAfterClose}
|
|
86
|
+
>
|
|
87
|
+
{@render children?.()}
|
|
88
88
|
</Dialog>
|