-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathButton.svelte
More file actions
49 lines (43 loc) · 1.61 KB
/
Button.svelte
File metadata and controls
49 lines (43 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<script>
import { getContext } from 'svelte';
import { Node, AnnotatedTextProperty } from 'svedit';
const svedit = getContext('svedit');
let { path } = $props();
let node = $derived(svedit.session.get(path));
let render_as_link = $derived(!svedit.editable && node.href);
let layout = $derived(node.layout || 1);
</script>
{#snippet layout_1()}
<svelte:element
this={render_as_link ? 'a' : 'div'}
href={render_as_link ? node.href : undefined}
target={render_as_link ? node.target : undefined}
class="ew-button font-medium flex items-center justify-center px-4 py-3 min-w-[calc(1lh+24px)] bg-(--accent) text-(--accent-foreground) rounded-(--button-border-radius) outline-1 outline-transparent focus-visible:outline-1 focus-visible:outline-(--svedit-editing-stroke) focus-visible:outline-offset-1"
class:hover:opacity-80={render_as_link}
>
<AnnotatedTextProperty
path={[...path, 'label']}
placeholder="Label"
/>
</svelte:element>
{/snippet}
{#snippet layout_2()}
<svelte:element
this={render_as_link ? 'a' : 'div'}
href={render_as_link ? node.href : undefined}
target={render_as_link ? node.target : undefined}
class="ew-button font-medium flex items-center justify-center px-4 py-3 -outline-offset-2 outline-2 outline-(--foreground) text-(--foreground) rounded-(--button-border-radius) focus-visible:outline-(--svedit-editing-stroke) {render_as_link ? 'hover:bg-(--foreground)/10' : ''}"
>
<AnnotatedTextProperty
path={[...path, 'label']}
placeholder="Label"
/>
</svelte:element>
{/snippet}
<Node {path}>
{#if layout === 2}
{@render layout_2()}
{:else}
{@render layout_1()}
{/if}
</Node>