button and spacer block
visual changes
This commit is contained in:
parent
1b3ef17800
commit
5a0ffe20df
11 changed files with 190 additions and 22 deletions
|
|
@ -14,6 +14,31 @@
|
||||||
--color-terracotta: #c9825f;
|
--color-terracotta: #c9825f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@keyframes shrink {
|
||||||
|
from { scale: 0 1; }
|
||||||
|
to { scale: 1 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
.delete-fill {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
background: transparent;
|
||||||
|
transform-origin: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.delete-fill.animating {
|
||||||
|
animation: shrink 1s ease-in-out forwards;
|
||||||
|
background: var(--error, #f43f5e);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn.delete-holding {
|
||||||
|
color: white !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn.delete-holding .text-error {
|
||||||
|
color: white !important;
|
||||||
|
}
|
||||||
|
|
||||||
:root {
|
:root {
|
||||||
--fg-heading: #2c2c2c;
|
--fg-heading: #2c2c2c;
|
||||||
--fg-body: #2c2c2c;
|
--fg-body: #2c2c2c;
|
||||||
|
|
|
||||||
|
|
@ -11,15 +11,33 @@
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
let dragIndex = $state<number | null>(null);
|
let dragIndex = $state<number | null>(null);
|
||||||
|
let holdingId = $state('');
|
||||||
|
let holdTimer: ReturnType<typeof setTimeout> | null = null;
|
||||||
|
|
||||||
|
function startHold(id: string) {
|
||||||
|
holdingId = id;
|
||||||
|
holdTimer = setTimeout(() => {
|
||||||
|
const idx = blocks.findIndex((b) => b.id === id);
|
||||||
|
onDelete(id);
|
||||||
|
onSelect(blocks[idx + 1]?.id || blocks[idx - 1]?.id || '');
|
||||||
|
holdingId = '';
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
function endHold() {
|
||||||
|
if (holdTimer) clearTimeout(holdTimer);
|
||||||
|
holdingId = '';
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="space-y-3">
|
<div class="space-y-3">
|
||||||
{#each blocks as block, i (block.id)}
|
{#each blocks as block, i (block.id)}
|
||||||
<div
|
<div
|
||||||
role="listitem"
|
role="listitem"
|
||||||
class="rounded-box border bg-base-100 p-3 shadow-sm"
|
class="rounded-box border bg-base-100 p-3 shadow-sm cursor-pointer"
|
||||||
class:border-primary={selectedId === block.id}
|
class:border-primary={selectedId === block.id}
|
||||||
draggable="true"
|
draggable="true"
|
||||||
|
onclick={() => onSelect(block.id)}
|
||||||
ondragstart={() => (dragIndex = i)}
|
ondragstart={() => (dragIndex = i)}
|
||||||
ondragover={(e) => e.preventDefault()}
|
ondragover={(e) => e.preventDefault()}
|
||||||
ondrop={() => { if (dragIndex !== null && dragIndex !== i) onMove(dragIndex, i); dragIndex = null; }}
|
ondrop={() => { if (dragIndex !== null && dragIndex !== i) onMove(dragIndex, i); dragIndex = null; }}
|
||||||
|
|
@ -27,8 +45,18 @@
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<span class="cursor-grab text-xl text-base-content/40">☰</span>
|
<span class="cursor-grab text-xl text-base-content/40">☰</span>
|
||||||
<div class="flex-1 font-semibold">{blockLabels[block.type as BlockType]}</div>
|
<div class="flex-1 font-semibold">{blockLabels[block.type as BlockType]}</div>
|
||||||
<button class="btn btn-xs" type="button" onclick={() => onSelect(block.id)}>Edit</button>
|
<button
|
||||||
<button class="btn btn-xs btn-error btn-outline" type="button" onclick={() => onDelete(block.id)}>Delete</button>
|
class="btn btn-xs btn-error btn-outline relative overflow-hidden"
|
||||||
|
class:btn-disabled={holdingId && holdingId !== block.id}
|
||||||
|
class:delete-holding={holdingId === block.id}
|
||||||
|
type="button"
|
||||||
|
onpointerdown={() => startHold(block.id)}
|
||||||
|
onpointerup={endHold}
|
||||||
|
onpointerleave={endHold}
|
||||||
|
>
|
||||||
|
<span class="delete-fill" class:animating={holdingId === block.id}></span>
|
||||||
|
<span class="relative z-10 text-error">Delete</span>
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,9 @@ export const blockLabels: Record<BlockType, string> = {
|
||||||
text: 'Text',
|
text: 'Text',
|
||||||
image_text: 'Image + Text',
|
image_text: 'Image + Text',
|
||||||
timeline: 'Timeline',
|
timeline: 'Timeline',
|
||||||
hero: 'Hero'
|
hero: 'Hero',
|
||||||
|
button: 'Button',
|
||||||
|
spacer: 'Spacer'
|
||||||
};
|
};
|
||||||
|
|
||||||
export const blockTypes = Object.keys(blockLabels) as BlockType[];
|
export const blockTypes = Object.keys(blockLabels) as BlockType[];
|
||||||
|
|
@ -27,10 +29,21 @@ export function createBlock(type: BlockType): ContentBlock {
|
||||||
heading: 'Holistic and Experiential Learning about Happiness',
|
heading: 'Holistic and Experiential Learning about Happiness',
|
||||||
subheading: 'Individual sessions, workshops and events in Oslo',
|
subheading: 'Individual sessions, workshops and events in Oslo',
|
||||||
buttonLabel: 'BOOK NOW',
|
buttonLabel: 'BOOK NOW',
|
||||||
buttonUrl: '/book',
|
buttonUrl: '/book'
|
||||||
backgroundImage: ''
|
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
|
case 'button':
|
||||||
|
base.data = {
|
||||||
|
label: 'Learn More',
|
||||||
|
href: '/',
|
||||||
|
variant: 'primary',
|
||||||
|
size: 'md',
|
||||||
|
alignment: 'center'
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 'spacer':
|
||||||
|
base.data = { height: 64 };
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
base.data._background = { type: 'none', color: '', imageUrl: '', attachment: 'scroll', overlay: false, overlayOpacity: 40 };
|
base.data._background = { type: 'none', color: '', imageUrl: '', attachment: 'scroll', overlay: false, overlayOpacity: 40 };
|
||||||
return base;
|
return base;
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,13 @@
|
||||||
<RichTextEditor value={block.data.content} onChange={(content) => updateData({ content })} />
|
<RichTextEditor value={block.data.content} onChange={(content) => updateData({ content })} />
|
||||||
{:else if block.type === 'image_text'}
|
{:else if block.type === 'image_text'}
|
||||||
<ImageUploader url={block.data.url} alt={block.data.alt} onChange={(image) => updateData(image)} />
|
<ImageUploader url={block.data.url} alt={block.data.alt} onChange={(image) => updateData(image)} />
|
||||||
<label class="form-control mt-3"><span class="label-text">Image position</span><select class="select select-bordered" value={block.data.imagePosition || 'left'} onchange={(e) => updateData({ imagePosition: e.currentTarget.value })}><option value="left">Left</option><option value="right">Right</option></select></label>
|
<div class="form-control mt-3">
|
||||||
|
<label class="label cursor-pointer justify-start gap-3">
|
||||||
|
<span class="label-text">Image position</span>
|
||||||
|
<input type="checkbox" class="toggle toggle-primary" checked={block.data.imagePosition === 'right'} onchange={(e) => updateData({ imagePosition: e.currentTarget.checked ? 'right' : 'left' })} />
|
||||||
|
<span class="text-sm text-base-content/60">{block.data.imagePosition === 'right' ? 'Right' : 'Left'}</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
<div class="mt-3"><RichTextEditor value={block.data.content} onChange={(content) => updateData({ content })} /></div>
|
<div class="mt-3"><RichTextEditor value={block.data.content} onChange={(content) => updateData({ content })} /></div>
|
||||||
{:else if block.type === 'timeline'}
|
{:else if block.type === 'timeline'}
|
||||||
{#each block.data.items || [] as item, i}
|
{#each block.data.items || [] as item, i}
|
||||||
|
|
@ -57,8 +63,68 @@
|
||||||
<button class="btn" type="button" onclick={() => addArrayItem('items', { year: '', title: '', description: '' })}>Add item</button>
|
<button class="btn" type="button" onclick={() => addArrayItem('items', { year: '', title: '', description: '' })}>Add item</button>
|
||||||
{:else if block.type === 'hero'}
|
{:else if block.type === 'hero'}
|
||||||
{#each ['heading', 'subheading', 'buttonLabel', 'buttonUrl', 'backgroundImage'] as field}
|
{#each ['heading', 'subheading', 'buttonLabel', 'buttonUrl', 'backgroundImage'] as field}
|
||||||
<label class="form-control"><span class="label-text capitalize">{field.replace(/([A-Z])/g, ' $1')}</span><input class="input input-bordered" value={block.data[field] || ''} oninput={(e) => updateData({ [field]: e.currentTarget.value })} /></label>
|
<label class="form-control w-full">
|
||||||
|
<div class="label"><span class="label-text">{field}</span></div>
|
||||||
|
<input class="input input-bordered w-full" value={block.data[field] || ''} oninput={(e) => updateData({ [field]: e.currentTarget.value })} />
|
||||||
|
</label>
|
||||||
{/each}
|
{/each}
|
||||||
|
{:else if block.type === 'button'}
|
||||||
|
<div class="space-y-4">
|
||||||
|
<label class="form-control w-full">
|
||||||
|
<div class="label"><span class="label-text">Button label</span></div>
|
||||||
|
<input class="input input-bordered w-full" value={block.data.label || ''} oninput={(e) => updateData({ label: e.currentTarget.value })} />
|
||||||
|
</label>
|
||||||
|
<label class="form-control w-full">
|
||||||
|
<div class="label"><span class="label-text">URL</span></div>
|
||||||
|
<input class="input input-bordered w-full" value={block.data.href || ''} oninput={(e) => updateData({ href: e.currentTarget.value })} />
|
||||||
|
</label>
|
||||||
|
<div class="form-control mt-5">
|
||||||
|
<div class="flex items-center justify-between">
|
||||||
|
<span class="label-text w-24">Variant</span>
|
||||||
|
<div class="grid flex-1" style="grid-template-columns: repeat(2, 1fr)">
|
||||||
|
<button type="button" class="btn btn-sm rounded-r-none {block.data.variant === 'primary' ? 'btn-active' : ''}" onclick={() => updateData({ variant: 'primary' })}>Primary</button>
|
||||||
|
<button type="button" class="btn btn-sm rounded-l-none {block.data.variant === 'secondary' ? 'btn-active' : ''}" onclick={() => updateData({ variant: 'secondary' })}>Secondary</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-control">
|
||||||
|
<div class="flex items-center justify-between">
|
||||||
|
<span class="label-text w-24">Alignment</span>
|
||||||
|
<div class="grid flex-1" style="grid-template-columns: repeat(3, 1fr)">
|
||||||
|
<button type="button" class="btn btn-sm rounded-r-none {block.data.alignment === 'left' ? 'btn-active' : ''}" onclick={() => updateData({ alignment: 'left' })}>Left</button>
|
||||||
|
<button type="button" class="btn btn-sm rounded-l-none rounded-r-none {block.data.alignment === 'center' ? 'btn-active' : ''}" onclick={() => updateData({ alignment: 'center' })}>Center</button>
|
||||||
|
<button type="button" class="btn btn-sm rounded-l-none {block.data.alignment === 'right' ? 'btn-active' : ''}" onclick={() => updateData({ alignment: 'right' })}>Right</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-control">
|
||||||
|
<div class="flex items-center justify-between">
|
||||||
|
<span class="label-text w-24">Size</span>
|
||||||
|
<div class="grid flex-1" style="grid-template-columns: repeat(4, 1fr)">
|
||||||
|
<button type="button" class="btn btn-sm rounded-r-none {block.data.size === 'xs' ? 'btn-active' : ''}" onclick={() => updateData({ size: 'xs' })}>Extra Small</button>
|
||||||
|
<button type="button" class="btn btn-sm rounded-l-none rounded-r-none {block.data.size === 'sm' ? 'btn-active' : ''}" onclick={() => updateData({ size: 'sm' })}>Small</button>
|
||||||
|
<button type="button" class="btn btn-sm rounded-l-none rounded-r-none {block.data.size === 'md' ? 'btn-active' : ''}" onclick={() => updateData({ size: 'md' })}>Medium</button>
|
||||||
|
<button type="button" class="btn btn-sm rounded-l-none {block.data.size === 'lg' ? 'btn-active' : ''}" onclick={() => updateData({ size: 'lg' })}>Large</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-control">
|
||||||
|
<div class="flex items-center justify-between">
|
||||||
|
<span class="label-text w-24">Color</span>
|
||||||
|
<div class="flex flex-1 items-center gap-2">
|
||||||
|
<input class="input input-bordered w-10 h-10 p-1 cursor-pointer" type="color" value={block.data.color || '#66755d'} oninput={(e) => updateData({ color: e.currentTarget.value })} />
|
||||||
|
<input class="input input-bordered flex-1" placeholder="#66755d or color name" value={block.data.color || ''} oninput={(e) => updateData({ color: e.currentTarget.value })} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{:else if block.type === 'spacer'}
|
||||||
|
<div class="space-y-4">
|
||||||
|
<label class="form-control w-full">
|
||||||
|
<div class="label"><span class="label-text">Height (px)</span></div>
|
||||||
|
<input type="number" class="input input-bordered w-full" value={block.data.height || 64} oninput={(e) => updateData({ height: parseInt(e.currentTarget.value) || 64 })} />
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<hr class="my-6" />
|
<hr class="my-6" />
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@
|
||||||
import ImageTextBlock from './ImageTextBlock.svelte';
|
import ImageTextBlock from './ImageTextBlock.svelte';
|
||||||
import TimelineBlock from './TimelineBlock.svelte';
|
import TimelineBlock from './TimelineBlock.svelte';
|
||||||
import HeroBlock from './HeroBlock.svelte';
|
import HeroBlock from './HeroBlock.svelte';
|
||||||
|
import ButtonBlock from './ButtonBlock.svelte';
|
||||||
|
import SpacerBlock from './SpacerBlock.svelte';
|
||||||
|
|
||||||
let { blocks = [] } = $props<{ blocks: ContentBlock[] }>();
|
let { blocks = [] } = $props<{ blocks: ContentBlock[] }>();
|
||||||
|
|
||||||
|
|
@ -27,6 +29,10 @@
|
||||||
<TimelineBlock data={block.data} />
|
<TimelineBlock data={block.data} />
|
||||||
{:else if block.type === 'hero'}
|
{:else if block.type === 'hero'}
|
||||||
<HeroBlock data={block.data} />
|
<HeroBlock data={block.data} />
|
||||||
|
{:else if block.type === 'button'}
|
||||||
|
<ButtonBlock data={block.data} />
|
||||||
|
{:else if block.type === 'spacer'}
|
||||||
|
<SpacerBlock data={block.data} />
|
||||||
{/if}
|
{/if}
|
||||||
</BackgroundWrapper>
|
</BackgroundWrapper>
|
||||||
{/each}
|
{/each}
|
||||||
|
|
|
||||||
26
app/src/lib/blocks/ButtonBlock.svelte
Normal file
26
app/src/lib/blocks/ButtonBlock.svelte
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
<script lang="ts">
|
||||||
|
let { data } = $props<{ data: Record<string, any> }>();
|
||||||
|
|
||||||
|
const alignmentClasses: Record<string, string> = {
|
||||||
|
left: 'justify-start',
|
||||||
|
center: 'justify-center',
|
||||||
|
right: 'justify-end'
|
||||||
|
};
|
||||||
|
|
||||||
|
const sizeClasses: Record<string, string> = {
|
||||||
|
xs: 'btn-xs',
|
||||||
|
sm: 'btn-sm',
|
||||||
|
md: '',
|
||||||
|
lg: 'btn-lg'
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="flex {alignmentClasses[data.alignment] || 'justify-center'}">
|
||||||
|
<a
|
||||||
|
href={data.href || '#'}
|
||||||
|
class="btn btn-{data.variant || 'primary'} {sizeClasses[data.size] || ''}"
|
||||||
|
style={data.color ? `background-color: ${data.color}; border-color: ${data.color};` : ''}
|
||||||
|
>
|
||||||
|
{data.label || 'Button'}
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
@ -5,16 +5,11 @@
|
||||||
subheading?: string;
|
subheading?: string;
|
||||||
buttonLabel?: string;
|
buttonLabel?: string;
|
||||||
buttonUrl?: string;
|
buttonUrl?: string;
|
||||||
backgroundImage?: string;
|
|
||||||
};
|
};
|
||||||
}>();
|
}>();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<section class="relative flex min-h-[80vh] items-center justify-center overflow-hidden px-6 py-20 md:min-h-[90vh]">
|
<section class="relative flex min-h-[80vh] items-center justify-center overflow-hidden px-6 py-20 md:min-h-[90vh]">
|
||||||
{#if data.backgroundImage}
|
|
||||||
<img class="absolute inset-0 h-full w-full object-cover" src={data.backgroundImage} alt="" />
|
|
||||||
<div class="absolute inset-0 bg-charcoal/50"></div>
|
|
||||||
{/if}
|
|
||||||
<div class="relative z-10 mx-auto max-w-4xl text-center">
|
<div class="relative z-10 mx-auto max-w-4xl text-center">
|
||||||
<h1 class="animate-fade-in text-5xl leading-tight md:text-7xl lg:text-8xl" style="font-family: 'Playfair Display', Georgia, serif;">
|
<h1 class="animate-fade-in text-5xl leading-tight md:text-7xl lg:text-8xl" style="font-family: 'Playfair Display', Georgia, serif;">
|
||||||
{data.heading || 'Holistic and Experiential Learning about Happiness'}
|
{data.heading || 'Holistic and Experiential Learning about Happiness'}
|
||||||
|
|
|
||||||
7
app/src/lib/blocks/SpacerBlock.svelte
Normal file
7
app/src/lib/blocks/SpacerBlock.svelte
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
<script lang="ts">
|
||||||
|
let { data } = $props<{ data: Record<string, any> }>();
|
||||||
|
|
||||||
|
const height = $derived(data.height ?? 64);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div style="height: {height}px;" class="w-full"></div>
|
||||||
|
|
@ -2,7 +2,9 @@ export type BlockType =
|
||||||
| 'text'
|
| 'text'
|
||||||
| 'image_text'
|
| 'image_text'
|
||||||
| 'timeline'
|
| 'timeline'
|
||||||
| 'hero';
|
| 'hero'
|
||||||
|
| 'button'
|
||||||
|
| 'spacer';
|
||||||
|
|
||||||
export type BlockBackground = {
|
export type BlockBackground = {
|
||||||
type: 'none' | 'color' | 'image';
|
type: 'none' | 'color' | 'image';
|
||||||
|
|
|
||||||
|
|
@ -49,13 +49,13 @@
|
||||||
<dialog id="new-page" class="modal">
|
<dialog id="new-page" class="modal">
|
||||||
<form class="modal-box" method="POST" action="?/create">
|
<form class="modal-box" method="POST" action="?/create">
|
||||||
<h2 class="text-2xl font-bold">Create page</h2>
|
<h2 class="text-2xl font-bold">Create page</h2>
|
||||||
<label class="form-control mt-4">
|
<label class="form-control w-full mt-4">
|
||||||
<span class="label-text">Slug</span>
|
<div class="label"><span class="label-text">Slug</span></div>
|
||||||
<input class="input input-bordered" name="slug" placeholder="about" required />
|
<input class="input input-bordered w-full" name="slug" placeholder="about" required />
|
||||||
</label>
|
</label>
|
||||||
<label class="form-control">
|
<label class="form-control w-full">
|
||||||
<span class="label-text">Title</span>
|
<div class="label"><span class="label-text">Title</span></div>
|
||||||
<input class="input input-bordered" name="title" placeholder="About" required />
|
<input class="input input-bordered w-full" name="title" placeholder="About" required />
|
||||||
</label>
|
</label>
|
||||||
<div class="modal-action">
|
<div class="modal-action">
|
||||||
<button class="btn" type="button" onclick={() => (document.getElementById('new-page') as HTMLDialogElement)?.close()}>Cancel</button>
|
<button class="btn" type="button" onclick={() => (document.getElementById('new-page') as HTMLDialogElement)?.close()}>Cancel</button>
|
||||||
|
|
|
||||||
|
|
@ -69,8 +69,8 @@
|
||||||
{#if form?.message}<div class="alert alert-error">{form.message}</div>{/if}
|
{#if form?.message}<div class="alert alert-error">{form.message}</div>{/if}
|
||||||
|
|
||||||
<div class="grid gap-4 md:grid-cols-2">
|
<div class="grid gap-4 md:grid-cols-2">
|
||||||
<label class="form-control"><span class="label-text">Slug</span><input class="input input-bordered" name="slug" bind:value={page.slug} /></label>
|
<label class="form-control w-full"><div class="label"><span class="label-text">Slug</span></div><input class="input input-bordered w-full" name="slug" bind:value={page.slug} /></label>
|
||||||
<label class="form-control"><span class="label-text">Title</span><input class="input input-bordered" name="title" bind:value={page.title} /></label>
|
<label class="form-control w-full"><div class="label"><span class="label-text">Title</span></div><input class="input input-bordered w-full" name="title" bind:value={page.title} /></label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="grid gap-6 lg:grid-cols-[22rem_1fr]">
|
<div class="grid gap-6 lg:grid-cols-[22rem_1fr]">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue