@x33025/sveltely 0.0.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/README.md +65 -0
- package/dist/actions/motion.d.ts +9 -0
- package/dist/actions/motion.js +24 -0
- package/dist/actions/portal.d.ts +12 -0
- package/dist/actions/portal.js +47 -0
- package/dist/components/AnimatedNumber.svelte +18 -0
- package/dist/components/AnimatedNumber.svelte.d.ts +8 -0
- package/dist/components/Dropdown/Dropdown.svelte +86 -0
- package/dist/components/Dropdown/Dropdown.svelte.d.ts +11 -0
- package/dist/components/Dropdown/index.d.ts +1 -0
- package/dist/components/Dropdown/index.js +1 -0
- package/dist/components/GlowEffect.svelte +136 -0
- package/dist/components/GlowEffect.svelte.d.ts +11 -0
- package/dist/components/NavigationStack/NavigationStack.svelte +69 -0
- package/dist/components/NavigationStack/NavigationStack.svelte.d.ts +9 -0
- package/dist/components/NavigationStack/SidebarToggle.svelte +40 -0
- package/dist/components/NavigationStack/SidebarToggle.svelte.d.ts +9 -0
- package/dist/components/NavigationStack/Toolbar.svelte +24 -0
- package/dist/components/NavigationStack/Toolbar.svelte.d.ts +8 -0
- package/dist/components/NavigationStack/index.d.ts +8 -0
- package/dist/components/NavigationStack/index.js +8 -0
- package/dist/components/Portal.svelte +6 -0
- package/dist/components/Portal.svelte.d.ts +20 -0
- package/dist/components/Sheet/Sheet.svelte +66 -0
- package/dist/components/Sheet/Sheet.svelte.d.ts +13 -0
- package/dist/components/Sheet/index.d.ts +1 -0
- package/dist/components/Sheet/index.js +1 -0
- package/dist/components/Spinner.svelte +7 -0
- package/dist/components/Spinner.svelte.d.ts +6 -0
- package/dist/components/TabView/Tab.svelte +52 -0
- package/dist/components/TabView/Tab.svelte.d.ts +11 -0
- package/dist/components/TabView/TabPanel.svelte +32 -0
- package/dist/components/TabView/TabPanel.svelte.d.ts +9 -0
- package/dist/components/TabView/TabView.svelte +38 -0
- package/dist/components/TabView/TabView.svelte.d.ts +10 -0
- package/dist/components/TabView/index.d.ts +8 -0
- package/dist/components/TabView/index.js +7 -0
- package/dist/components/TextShimmer.svelte +60 -0
- package/dist/components/TextShimmer.svelte.d.ts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +10 -0
- package/dist/style/index.css +30 -0
- package/dist/style.css +825 -0
- package/package.json +69 -0
package/README.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Svelte library
|
|
2
|
+
|
|
3
|
+
Everything you need to build a Svelte library, powered by [`sv`](https://npmjs.com/package/sv).
|
|
4
|
+
|
|
5
|
+
Read more about creating a library [in the docs](https://svelte.dev/docs/kit/packaging).
|
|
6
|
+
|
|
7
|
+
## Creating a project
|
|
8
|
+
|
|
9
|
+
If you're seeing this, you've probably already done this step. Congrats!
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
# create a new project in the current directory
|
|
13
|
+
npx sv create
|
|
14
|
+
|
|
15
|
+
# create a new project in my-app
|
|
16
|
+
npx sv create my-app
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
To recreate this project with the same configuration:
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
# recreate this project
|
|
23
|
+
npx sv create --template library --types ts --add prettier eslint tailwindcss="plugins:none" --install npm sveltely
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Developing
|
|
27
|
+
|
|
28
|
+
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
npm run dev
|
|
32
|
+
|
|
33
|
+
# or start the server and open the app in a new browser tab
|
|
34
|
+
npm run dev -- --open
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Everything inside `src/lib` is part of your library, everything inside `src/routes` can be used as a showcase or preview app.
|
|
38
|
+
|
|
39
|
+
## Building
|
|
40
|
+
|
|
41
|
+
To build your library:
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
npm pack
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
To create a production version of your showcase app:
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
npm run build
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
You can preview the production build with `npm run preview`.
|
|
54
|
+
|
|
55
|
+
> To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment.
|
|
56
|
+
|
|
57
|
+
## Publishing
|
|
58
|
+
|
|
59
|
+
Go into the `package.json` and give your package the desired name through the `"name"` option. Also consider adding a `"license"` field and point it to a `LICENSE` file which you can create from a template (one popular option is the [MIT license](https://opensource.org/license/mit/)).
|
|
60
|
+
|
|
61
|
+
To publish your library to [npm](https://www.npmjs.com):
|
|
62
|
+
|
|
63
|
+
```sh
|
|
64
|
+
npm publish
|
|
65
|
+
```
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type AnimationOptions, type DOMKeyframesDefinition } from 'motion';
|
|
2
|
+
import type { Action } from 'svelte/action';
|
|
3
|
+
type MotionParams = {
|
|
4
|
+
keyframes: DOMKeyframesDefinition;
|
|
5
|
+
options?: AnimationOptions;
|
|
6
|
+
};
|
|
7
|
+
export declare const motion: Action<HTMLElement, MotionParams>;
|
|
8
|
+
export declare const hover: Action;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { animate, hover as hoverMotion } from 'motion';
|
|
2
|
+
export const motion = (node, data = { keyframes: { scale: [0, 1] } }) => {
|
|
3
|
+
let animation = animate(node, data.keyframes, data.options);
|
|
4
|
+
return {
|
|
5
|
+
update(next) {
|
|
6
|
+
animation.cancel();
|
|
7
|
+
animation = animate(node, next.keyframes, next.options);
|
|
8
|
+
},
|
|
9
|
+
destroy() {
|
|
10
|
+
animation.cancel();
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export const hover = (node) => {
|
|
15
|
+
const cleanup = hoverMotion(node, (element) => {
|
|
16
|
+
animate(element, { scale: 1.3 }, { type: 'spring', duration: 0.3 });
|
|
17
|
+
return () => animate(element, { scale: 1 }, { type: 'spring' });
|
|
18
|
+
});
|
|
19
|
+
return {
|
|
20
|
+
destroy() {
|
|
21
|
+
cleanup();
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a portal host. Use this on the element that should contain the portaled content.
|
|
3
|
+
*/
|
|
4
|
+
export declare function createPortal(node: HTMLElement, id?: string): {
|
|
5
|
+
destroy(): void;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Portals an element to a named host created with createPortal.
|
|
9
|
+
*/
|
|
10
|
+
export declare function portal(node: HTMLElement, id?: string): {
|
|
11
|
+
destroy: () => void | undefined;
|
|
12
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { tick } from 'svelte';
|
|
2
|
+
const portal_map = new Map();
|
|
3
|
+
/**
|
|
4
|
+
* Creates a portal host. Use this on the element that should contain the portaled content.
|
|
5
|
+
*/
|
|
6
|
+
export function createPortal(node, id = 'default') {
|
|
7
|
+
const key = `$$portal.${id}`;
|
|
8
|
+
if (portal_map.has(key)) {
|
|
9
|
+
throw new Error(`Duplicate portal key "${id}"`);
|
|
10
|
+
}
|
|
11
|
+
portal_map.set(key, node);
|
|
12
|
+
return {
|
|
13
|
+
destroy() {
|
|
14
|
+
portal_map.delete(key);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function mount(node, key) {
|
|
19
|
+
if (!portal_map.has(key)) {
|
|
20
|
+
throw new Error(`Unknown portal target: ${key.replace('$$portal.', '')}`);
|
|
21
|
+
}
|
|
22
|
+
const host = portal_map.get(key);
|
|
23
|
+
host.appendChild(node);
|
|
24
|
+
return () => {
|
|
25
|
+
if (host.contains(node)) {
|
|
26
|
+
host.removeChild(node);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Portals an element to a named host created with createPortal.
|
|
32
|
+
*/
|
|
33
|
+
export function portal(node, id = 'default') {
|
|
34
|
+
let destroy;
|
|
35
|
+
const key = `$$portal.${id}`;
|
|
36
|
+
if (!portal_map.has(key)) {
|
|
37
|
+
tick().then(() => {
|
|
38
|
+
destroy = mount(node, key);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
destroy = mount(node, key);
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
destroy: () => destroy?.()
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { Spring } from 'svelte/motion';
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
value: number;
|
|
6
|
+
class?: string;
|
|
7
|
+
as?: keyof HTMLElementTagNameMap;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
let { value, class: className = '', as = 'span' }: Props = $props();
|
|
11
|
+
|
|
12
|
+
const spring = Spring.of(() => value);
|
|
13
|
+
const display = $derived(Math.round(spring.current).toLocaleString());
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<svelte:element this={as} class="tabular-nums {className}">
|
|
17
|
+
{display}
|
|
18
|
+
</svelte:element>
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import { portal } from '../../actions/portal';
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
trigger: Snippet;
|
|
7
|
+
children: Snippet;
|
|
8
|
+
class?: string;
|
|
9
|
+
align?: 'left' | 'right';
|
|
10
|
+
closeOnSelect?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
let {
|
|
14
|
+
trigger,
|
|
15
|
+
children,
|
|
16
|
+
class: className = '',
|
|
17
|
+
align = 'left',
|
|
18
|
+
closeOnSelect = true
|
|
19
|
+
}: Props = $props();
|
|
20
|
+
|
|
21
|
+
let isOpen = $state(false);
|
|
22
|
+
let triggerEl = $state<HTMLElement | null>(null);
|
|
23
|
+
let menuCoords = $state({ top: 0, left: 0, width: 0 });
|
|
24
|
+
|
|
25
|
+
function open() {
|
|
26
|
+
if (triggerEl) {
|
|
27
|
+
const rect = triggerEl.getBoundingClientRect();
|
|
28
|
+
menuCoords = {
|
|
29
|
+
top: rect.bottom + window.scrollY,
|
|
30
|
+
left: align === 'left' ? rect.left + window.scrollX : rect.right + window.scrollX,
|
|
31
|
+
width: rect.width
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
isOpen = true;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function close() {
|
|
38
|
+
isOpen = false;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function toggle() {
|
|
42
|
+
if (isOpen) {
|
|
43
|
+
close();
|
|
44
|
+
} else {
|
|
45
|
+
open();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function handleOutsideClick(event: MouseEvent) {
|
|
50
|
+
if (!isOpen) return;
|
|
51
|
+
const target = event.target as HTMLElement;
|
|
52
|
+
if (target.closest('.dropdown-container') || target.closest('.dropdown-menu')) return;
|
|
53
|
+
close();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function handleSelect() {
|
|
57
|
+
if (closeOnSelect) close();
|
|
58
|
+
}
|
|
59
|
+
</script>
|
|
60
|
+
|
|
61
|
+
<svelte:window onclick={handleOutsideClick} onscroll={close} onresize={close} />
|
|
62
|
+
|
|
63
|
+
<div class="dropdown-container relative inline-block text-left {className}">
|
|
64
|
+
<div bind:this={triggerEl}>
|
|
65
|
+
<button type="button" onclick={toggle} aria-expanded={isOpen} aria-haspopup="true">
|
|
66
|
+
{@render trigger()}
|
|
67
|
+
</button>
|
|
68
|
+
</div>
|
|
69
|
+
|
|
70
|
+
{#if isOpen}
|
|
71
|
+
<div
|
|
72
|
+
use:portal
|
|
73
|
+
class="dropdown-menu fixed z-50 rounded-md border border-gray-200 bg-white shadow-lg focus:outline-none"
|
|
74
|
+
style="top: {menuCoords.top}px; {align === 'left'
|
|
75
|
+
? `left: ${menuCoords.left}px;`
|
|
76
|
+
: `right: ${window.innerWidth - menuCoords.left}px;`}"
|
|
77
|
+
role="menu"
|
|
78
|
+
aria-orientation="vertical"
|
|
79
|
+
tabindex="-1"
|
|
80
|
+
>
|
|
81
|
+
<div class="overflow-auto p-1" role="none" onclick={handleSelect}>
|
|
82
|
+
{@render children()}
|
|
83
|
+
</div>
|
|
84
|
+
</div>
|
|
85
|
+
{/if}
|
|
86
|
+
</div>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
interface Props {
|
|
3
|
+
trigger: Snippet;
|
|
4
|
+
children: Snippet;
|
|
5
|
+
class?: string;
|
|
6
|
+
align?: 'left' | 'right';
|
|
7
|
+
closeOnSelect?: boolean;
|
|
8
|
+
}
|
|
9
|
+
declare const Dropdown: import("svelte").Component<Props, {}, "">;
|
|
10
|
+
type Dropdown = ReturnType<typeof Dropdown>;
|
|
11
|
+
export default Dropdown;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './Dropdown.svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './Dropdown.svelte';
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
interface Props {
|
|
3
|
+
class?: string;
|
|
4
|
+
colors?: string[];
|
|
5
|
+
mode?: 'breathe' | 'colorShift';
|
|
6
|
+
blur?: number | 'softest' | 'soft' | 'medium' | 'strong' | 'stronger' | 'strongest' | 'none';
|
|
7
|
+
scale?: number;
|
|
8
|
+
duration?: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
let {
|
|
12
|
+
class: className = '',
|
|
13
|
+
colors = ['#FF5733', '#33FF57', '#3357FF', '#F1C40F'],
|
|
14
|
+
mode = 'breathe',
|
|
15
|
+
blur = 'medium',
|
|
16
|
+
scale = 1,
|
|
17
|
+
duration = 5
|
|
18
|
+
}: Props = $props();
|
|
19
|
+
|
|
20
|
+
const getBlurClass = (blurValue: Props['blur']) => {
|
|
21
|
+
if (typeof blurValue === 'number') return `blur-[${blurValue}px]`;
|
|
22
|
+
const presets = {
|
|
23
|
+
softest: 'blur-xs',
|
|
24
|
+
soft: 'blur-sm',
|
|
25
|
+
medium: 'blur-md',
|
|
26
|
+
strong: 'blur-lg',
|
|
27
|
+
stronger: 'blur-xl',
|
|
28
|
+
strongest: 'blur-2xl',
|
|
29
|
+
none: 'blur-none'
|
|
30
|
+
};
|
|
31
|
+
return presets[blurValue as keyof typeof presets] || 'blur-md';
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const getBackground = () => {
|
|
35
|
+
if (mode === 'colorShift') {
|
|
36
|
+
return `conic-gradient(from 0deg at 50% 50%, var(--glow-color-1) 0%, var(--glow-color-2) 50%, var(--glow-color-1) 100%)`;
|
|
37
|
+
}
|
|
38
|
+
return `radial-gradient(circle at 50% 50%, ${colors[0]} 0%, transparent 100%)`;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const getAnimationClass = () => {
|
|
42
|
+
if (mode === 'colorShift') return 'animate-glow-rotate animate-glow-colors';
|
|
43
|
+
if (mode === 'breathe') return 'animate-glow-breathe';
|
|
44
|
+
return '';
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const background = $derived(getBackground());
|
|
48
|
+
const animationClass = $derived(getAnimationClass());
|
|
49
|
+
const colorDuration = $derived(`${duration * colors.length}s`);
|
|
50
|
+
</script>
|
|
51
|
+
|
|
52
|
+
<div
|
|
53
|
+
class="pointer-events-none absolute inset-0 -z-10 h-full w-full overflow-hidden rounded-full {getBlurClass(
|
|
54
|
+
blur
|
|
55
|
+
)} {className}"
|
|
56
|
+
style:isolation="isolate"
|
|
57
|
+
style:transform-origin="center"
|
|
58
|
+
>
|
|
59
|
+
<div
|
|
60
|
+
class="absolute transform-gpu {animationClass}"
|
|
61
|
+
style="
|
|
62
|
+
left: 50%;
|
|
63
|
+
top: 50%;
|
|
64
|
+
width: 200%;
|
|
65
|
+
height: 200%;
|
|
66
|
+
translate: -50% -50%;
|
|
67
|
+
scale: {scale};
|
|
68
|
+
background: {background};
|
|
69
|
+
will-change: transform;
|
|
70
|
+
backface-visibility: hidden;
|
|
71
|
+
--glow-color-1: {colors[0]};
|
|
72
|
+
--glow-color-2: {colors[1] || colors[0]};
|
|
73
|
+
--c1: {colors[0]};
|
|
74
|
+
--c2: {colors[1] || colors[0]};
|
|
75
|
+
--c3: {colors[2] || colors[0]};
|
|
76
|
+
--c4: {colors[3] || colors[0]};
|
|
77
|
+
--rotation-duration: {duration}s;
|
|
78
|
+
--color-duration: {colorDuration};
|
|
79
|
+
"
|
|
80
|
+
></div>
|
|
81
|
+
</div>
|
|
82
|
+
|
|
83
|
+
<style>
|
|
84
|
+
@property --glow-color-1 {
|
|
85
|
+
syntax: '<color>';
|
|
86
|
+
inherits: false;
|
|
87
|
+
initial-value: #ff5733;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
@property --glow-color-2 {
|
|
91
|
+
syntax: '<color>';
|
|
92
|
+
inherits: false;
|
|
93
|
+
initial-value: #33ff57;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
@keyframes glow-colors {
|
|
97
|
+
0% {
|
|
98
|
+
--glow-color-1: var(--c1);
|
|
99
|
+
--glow-color-2: var(--c2);
|
|
100
|
+
}
|
|
101
|
+
25% {
|
|
102
|
+
--glow-color-1: var(--c2);
|
|
103
|
+
--glow-color-2: var(--c3);
|
|
104
|
+
}
|
|
105
|
+
50% {
|
|
106
|
+
--glow-color-1: var(--c3);
|
|
107
|
+
--glow-color-2: var(--c4);
|
|
108
|
+
}
|
|
109
|
+
75% {
|
|
110
|
+
--glow-color-1: var(--c4);
|
|
111
|
+
--glow-color-2: var(--c1);
|
|
112
|
+
}
|
|
113
|
+
100% {
|
|
114
|
+
--glow-color-1: var(--c1);
|
|
115
|
+
--glow-color-2: var(--c2);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
@keyframes glow-breathe {
|
|
120
|
+
0%,
|
|
121
|
+
100% {
|
|
122
|
+
scale: 1;
|
|
123
|
+
}
|
|
124
|
+
50% {
|
|
125
|
+
scale: 1.05;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.animate-glow-colors {
|
|
130
|
+
animation: glow-colors var(--color-duration, 20s) linear infinite;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.animate-glow-breathe {
|
|
134
|
+
animation: glow-breathe var(--rotation-duration, 5s) ease-in-out infinite;
|
|
135
|
+
}
|
|
136
|
+
</style>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
class?: string;
|
|
3
|
+
colors?: string[];
|
|
4
|
+
mode?: 'breathe' | 'colorShift';
|
|
5
|
+
blur?: number | 'softest' | 'soft' | 'medium' | 'strong' | 'stronger' | 'strongest' | 'none';
|
|
6
|
+
scale?: number;
|
|
7
|
+
duration?: number;
|
|
8
|
+
}
|
|
9
|
+
declare const GlowEffect: import("svelte").Component<Props, {}, "">;
|
|
10
|
+
type GlowEffect = ReturnType<typeof GlowEffect>;
|
|
11
|
+
export default GlowEffect;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { setContext, getContext } from 'svelte';
|
|
3
|
+
import type { Snippet } from 'svelte';
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
left?: Snippet;
|
|
7
|
+
right?: Snippet;
|
|
8
|
+
children?: Snippet;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
let { left, right, children }: Props = $props();
|
|
12
|
+
|
|
13
|
+
const existingContext = getContext<{
|
|
14
|
+
leftOpen?: boolean;
|
|
15
|
+
rightOpen?: boolean;
|
|
16
|
+
}>('navigationStack');
|
|
17
|
+
|
|
18
|
+
let leftOpen = $state(existingContext?.leftOpen ?? true);
|
|
19
|
+
let rightOpen = $state(existingContext?.rightOpen ?? true);
|
|
20
|
+
|
|
21
|
+
function toggleLeft() {
|
|
22
|
+
leftOpen = !leftOpen;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function toggleRight() {
|
|
26
|
+
rightOpen = !rightOpen;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
setContext('navigationStack', {
|
|
30
|
+
get leftOpen() {
|
|
31
|
+
return leftOpen;
|
|
32
|
+
},
|
|
33
|
+
get rightOpen() {
|
|
34
|
+
return rightOpen;
|
|
35
|
+
},
|
|
36
|
+
toggleLeft,
|
|
37
|
+
toggleRight
|
|
38
|
+
});
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
<div class="hstack size-full">
|
|
42
|
+
{#if left}
|
|
43
|
+
<div
|
|
44
|
+
class="h-full overflow-hidden border-r border-gray-200 transition-all duration-300 ease-in-out"
|
|
45
|
+
style="width: {leftOpen ? '16rem' : '0'}; opacity: {leftOpen ? '1' : '0'}"
|
|
46
|
+
>
|
|
47
|
+
<div class="vstack h-full w-64 overflow-auto bg-gray-50 p-4">
|
|
48
|
+
{@render left()}
|
|
49
|
+
</div>
|
|
50
|
+
</div>
|
|
51
|
+
{/if}
|
|
52
|
+
|
|
53
|
+
<div class="vstack">
|
|
54
|
+
{#if children}
|
|
55
|
+
{@render children()}
|
|
56
|
+
{/if}
|
|
57
|
+
</div>
|
|
58
|
+
|
|
59
|
+
{#if right}
|
|
60
|
+
<div
|
|
61
|
+
class="h-full overflow-hidden border-l border-gray-200 transition-all duration-300 ease-in-out"
|
|
62
|
+
style="width: {rightOpen ? '16rem' : '0'}; opacity: {rightOpen ? '1' : '0'}"
|
|
63
|
+
>
|
|
64
|
+
<div class="vstack h-full w-64 overflow-auto bg-gray-50 p-4">
|
|
65
|
+
{@render right()}
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
68
|
+
{/if}
|
|
69
|
+
</div>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
interface Props {
|
|
3
|
+
left?: Snippet;
|
|
4
|
+
right?: Snippet;
|
|
5
|
+
children?: Snippet;
|
|
6
|
+
}
|
|
7
|
+
declare const NavigationStack: import("svelte").Component<Props, {}, "">;
|
|
8
|
+
type NavigationStack = ReturnType<typeof NavigationStack>;
|
|
9
|
+
export default NavigationStack;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { getContext } from 'svelte';
|
|
3
|
+
import type { Snippet } from 'svelte';
|
|
4
|
+
import { PanelLeft, PanelRight } from '@lucide/svelte';
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
side: 'left' | 'right';
|
|
8
|
+
children?: Snippet;
|
|
9
|
+
class?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
let { side, children, class: className = '' }: Props = $props();
|
|
13
|
+
|
|
14
|
+
const ctx = getContext<{
|
|
15
|
+
toggleLeft: () => void;
|
|
16
|
+
toggleRight: () => void;
|
|
17
|
+
}>('navigationStack');
|
|
18
|
+
|
|
19
|
+
function handleClick() {
|
|
20
|
+
if (side === 'left') {
|
|
21
|
+
ctx?.toggleLeft();
|
|
22
|
+
} else {
|
|
23
|
+
ctx?.toggleRight();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
<button
|
|
29
|
+
onclick={handleClick}
|
|
30
|
+
class="rounded p-1.5 hover:bg-zinc-100 {className}"
|
|
31
|
+
title="Toggle {side} sidebar"
|
|
32
|
+
>
|
|
33
|
+
{#if children}
|
|
34
|
+
{@render children()}
|
|
35
|
+
{:else if side === 'left'}
|
|
36
|
+
<PanelLeft class="h-5 w-5" />
|
|
37
|
+
{:else}
|
|
38
|
+
<PanelRight class="h-5 w-5" />
|
|
39
|
+
{/if}
|
|
40
|
+
</button>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
interface Props {
|
|
3
|
+
side: 'left' | 'right';
|
|
4
|
+
children?: Snippet;
|
|
5
|
+
class?: string;
|
|
6
|
+
}
|
|
7
|
+
declare const SidebarToggle: import("svelte").Component<Props, {}, "">;
|
|
8
|
+
type SidebarToggle = ReturnType<typeof SidebarToggle>;
|
|
9
|
+
export default SidebarToggle;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
header?: Snippet;
|
|
6
|
+
children?: Snippet;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
let { header, children }: Props = $props();
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<div class="vstack h-full">
|
|
13
|
+
{#if header}
|
|
14
|
+
<div class="flex items-center gap-2 border-b border-zinc-200 bg-white p-2">
|
|
15
|
+
{@render header()}
|
|
16
|
+
</div>
|
|
17
|
+
{/if}
|
|
18
|
+
|
|
19
|
+
<div class="vstack">
|
|
20
|
+
{#if children}
|
|
21
|
+
{@render children()}
|
|
22
|
+
{/if}
|
|
23
|
+
</div>
|
|
24
|
+
</div>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import NavigationStackComponent from './NavigationStack.svelte';
|
|
2
|
+
import Toolbar from './Toolbar.svelte';
|
|
3
|
+
import SidebarToggle from './SidebarToggle.svelte';
|
|
4
|
+
declare const NavigationStack: typeof NavigationStackComponent & {
|
|
5
|
+
Toolbar: typeof Toolbar;
|
|
6
|
+
SidebarToggle: typeof SidebarToggle;
|
|
7
|
+
};
|
|
8
|
+
export default NavigationStack;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import NavigationStackComponent from './NavigationStack.svelte';
|
|
2
|
+
import Toolbar from './Toolbar.svelte';
|
|
3
|
+
import SidebarToggle from './SidebarToggle.svelte';
|
|
4
|
+
// Attach subcomponents for NavigationStack.Toolbar/SidebarToggle syntax
|
|
5
|
+
const NavigationStack = NavigationStackComponent;
|
|
6
|
+
NavigationStack.Toolbar = Toolbar;
|
|
7
|
+
NavigationStack.SidebarToggle = SidebarToggle;
|
|
8
|
+
export default NavigationStack;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
2
|
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
3
|
+
$$bindings?: Bindings;
|
|
4
|
+
} & Exports;
|
|
5
|
+
(internal: unknown, props: Props & {
|
|
6
|
+
$$events?: Events;
|
|
7
|
+
$$slots?: Slots;
|
|
8
|
+
}): Exports & {
|
|
9
|
+
$set?: any;
|
|
10
|
+
$on?: any;
|
|
11
|
+
};
|
|
12
|
+
z_$$bindings?: Bindings;
|
|
13
|
+
}
|
|
14
|
+
declare const Portal: $$__sveltets_2_IsomorphicComponent<{
|
|
15
|
+
name?: string;
|
|
16
|
+
}, {
|
|
17
|
+
[evt: string]: CustomEvent<any>;
|
|
18
|
+
}, {}, {}, string>;
|
|
19
|
+
type Portal = InstanceType<typeof Portal>;
|
|
20
|
+
export default Portal;
|