Refactored SegmentedControl
Visual Changes
This commit is contained in:
parent
5a0ffe20df
commit
62f7ac7301
4 changed files with 164 additions and 105 deletions
|
|
@ -45,6 +45,6 @@ export function createBlock(type: BlockType): ContentBlock {
|
|||
base.data = { height: 64 };
|
||||
break;
|
||||
}
|
||||
base.data._background = { type: 'none', color: '', imageUrl: '', attachment: 'scroll', overlay: false, overlayOpacity: 40 };
|
||||
base.data._background = { type: 'none', color: '', attachment: 'scroll', overlay: false, overlayOpacity: 40 };
|
||||
return base;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
import { blockLabels } from '$lib/admin/blockDefaults';
|
||||
import RichTextEditor from './RichTextEditor.svelte';
|
||||
import ImageUploader from './ImageUploader.svelte';
|
||||
import SegmentedControl from './SegmentedControl.svelte';
|
||||
import SpacerBlock from '../../blocks/SpacerBlock.svelte';
|
||||
|
||||
let { block, onChange = (block: ContentBlock) => {} } = $props<{
|
||||
block: ContentBlock | null;
|
||||
|
|
@ -62,12 +64,22 @@
|
|||
{/each}
|
||||
<button class="btn" type="button" onclick={() => addArrayItem('items', { year: '', title: '', description: '' })}>Add item</button>
|
||||
{:else if block.type === 'hero'}
|
||||
{#each ['heading', 'subheading', 'buttonLabel', 'buttonUrl', 'backgroundImage'] as field}
|
||||
<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 })} />
|
||||
<div class="label"><span class="label-text">Heading</span></div>
|
||||
<input class="input input-bordered w-full" value={block.data.heading || ''} oninput={(e) => updateData({ heading: e.currentTarget.value })} />
|
||||
</label>
|
||||
<label class="form-control w-full mt-3">
|
||||
<div class="label"><span class="label-text">Subheading</span></div>
|
||||
<input class="input input-bordered w-full" value={block.data.subheading || ''} oninput={(e) => updateData({ subheading: e.currentTarget.value })} />
|
||||
</label>
|
||||
<label class="form-control w-full mt-3">
|
||||
<div class="label"><span class="label-text">Button label</span></div>
|
||||
<input class="input input-bordered w-full" value={block.data.buttonLabel || ''} oninput={(e) => updateData({ buttonLabel: e.currentTarget.value })} />
|
||||
</label>
|
||||
<label class="form-control w-full mt-3">
|
||||
<div class="label"><span class="label-text">Button URL</span></div>
|
||||
<input class="input input-bordered w-full" value={block.data.buttonUrl || ''} oninput={(e) => updateData({ buttonUrl: e.currentTarget.value })} />
|
||||
</label>
|
||||
{/each}
|
||||
{:else if block.type === 'button'}
|
||||
<div class="space-y-4">
|
||||
<label class="form-control w-full">
|
||||
|
|
@ -79,34 +91,30 @@
|
|||
<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>
|
||||
<SegmentedControl
|
||||
label="Variant"
|
||||
options={['primary', 'secondary']}
|
||||
value={block.data.variant || 'primary'}
|
||||
onChange={(v) => updateData({ variant: v })}
|
||||
/>
|
||||
</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>
|
||||
<SegmentedControl
|
||||
label="Alignment"
|
||||
options={['left', 'center', 'right']}
|
||||
value={block.data.alignment || 'left'}
|
||||
onChange={(v) => updateData({ alignment: v })}
|
||||
formatLabel={(v) => v.charAt(0).toUpperCase() + v.slice(1)}
|
||||
/>
|
||||
</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>
|
||||
<SegmentedControl
|
||||
label="Size"
|
||||
options={['xs', 'sm', 'md', 'lg']}
|
||||
value={block.data.size || 'md'}
|
||||
onChange={(v) => updateData({ size: v })}
|
||||
formatLabel={(v) => ({ xs: 'Extra Small', sm: 'Small', md: 'Medium', lg: 'Large' }[v] || v)}
|
||||
/>
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<div class="flex items-center justify-between">
|
||||
|
|
@ -127,80 +135,93 @@
|
|||
</div>
|
||||
{/if}
|
||||
|
||||
<hr class="my-6" />
|
||||
<div class="rounded-box border border-base-300 p-4 mt-4">
|
||||
|
||||
<details class="rounded-box border border-base-300 p-3">
|
||||
<summary class="cursor-pointer font-semibold text-base-content/70">Background settings</summary>
|
||||
<div class="mt-4 space-y-3">
|
||||
<label class="form-control">
|
||||
<span class="label-text">Background type</span>
|
||||
<select class="select select-bordered" value={block.data._background?.type || 'none'} onchange={(e) => updateData({ _background: { ...(block.data._background || {}), type: e.currentTarget.value } })}>
|
||||
<option value="none">None</option>
|
||||
<option value="color">Solid color</option>
|
||||
<option value="image">Image</option>
|
||||
</select>
|
||||
</label>
|
||||
|
||||
{#if (block.data._background?.type) === 'color'}
|
||||
<label class="form-control">
|
||||
<span class="label-text">Color</span>
|
||||
<input class="input input-bordered" type="color" value={block.data._background?.color || '#66755d'} oninput={(e) => updateData({ _background: { ...(block.data._background || {}), color: e.currentTarget.value } })} />
|
||||
</label>
|
||||
<label class="form-control">
|
||||
<span class="label-text">Or type a CSS color</span>
|
||||
<input class="input input-bordered" placeholder="#66755d or rgba(…) or sage" value={block.data._background?.color || ''} oninput={(e) => updateData({ _background: { ...(block.data._background || {}), color: e.currentTarget.value } })} />
|
||||
</label>
|
||||
{/if}
|
||||
|
||||
{#if (block.data._background?.type) === 'image'}
|
||||
<label class="form-control">
|
||||
<span class="label-text">Image URL</span>
|
||||
<input class="input input-bordered" placeholder="https://…" value={block.data._background?.imageUrl || ''} oninput={(e) => updateData({ _background: { ...(block.data._background || {}), imageUrl: e.currentTarget.value } })} />
|
||||
</label>
|
||||
<label class="form-control">
|
||||
<span class="label-text">Attachment</span>
|
||||
<select class="select select-bordered" value={block.data._background?.attachment || 'scroll'} onchange={(e) => updateData({ _background: { ...(block.data._background || {}), attachment: e.currentTarget.value } })}>
|
||||
<option value="scroll">Scroll with page</option>
|
||||
<option value="fixed">Fixed (parallax)</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="form-control">
|
||||
<span class="label-text">Dark overlay</span>
|
||||
<select class="select select-bordered" value={block.data._background?.overlay ? 'yes' : 'no'} onchange={(e) => updateData({ _background: { ...(block.data._background || {}), overlay: e.currentTarget.value === 'yes' } })}>
|
||||
<option value="no">No</option>
|
||||
<option value="yes">Yes</option>
|
||||
</select>
|
||||
</label>
|
||||
{#if block.data._background?.overlay}
|
||||
<label class="form-control">
|
||||
<span class="label-text">Overlay opacity ({block.data._background?.overlayOpacity ?? 40}%)</span>
|
||||
<input class="range range-sm" type="range" min="0" max="100" value={block.data._background?.overlayOpacity ?? 40} oninput={(e) => updateData({ _background: { ...(block.data._background || {}), overlayOpacity: Number(e.currentTarget.value) } })} />
|
||||
</label>
|
||||
{/if}
|
||||
{/if}
|
||||
<!-- Background Type Selector -->
|
||||
<div class="mb-4">
|
||||
<SegmentedControl
|
||||
label="Background"
|
||||
labelStyle="font-weight: 1000;"
|
||||
options={['none', 'color', 'image']}
|
||||
value={block.data._background?.type || 'none'}
|
||||
onChange={(v) => updateData({ _background: { ...(block.data._background || {}), type: v } })}
|
||||
/>
|
||||
</div>
|
||||
</details>
|
||||
|
||||
<details class="mt-3 rounded-box border border-base-300 p-3">
|
||||
<summary class="cursor-pointer font-semibold text-base-content/70">Foreground settings</summary>
|
||||
<div class="mt-4 space-y-3">
|
||||
{#if block.data._background?.type === 'color'}
|
||||
<div class="space-y-3">
|
||||
<label class="form-control">
|
||||
<span class="label-text">Heading color</span>
|
||||
<input class="input input-bordered w-full" type="color" value={block.data._foreground?.headingColor || '#2c2c2c'} oninput={(e) => updateData({ _foreground: { ...(block.data._foreground || {}), headingColor: e.currentTarget.value } })} />
|
||||
</label>
|
||||
<label class="form-control">
|
||||
<span class="label-text">Or type a CSS color</span>
|
||||
<input class="input input-bordered" placeholder="#2c2c2c or rgba(…) or charcoal" value={block.data._foreground?.headingColor || ''} oninput={(e) => updateData({ _foreground: { ...(block.data._foreground || {}), headingColor: e.currentTarget.value } })} />
|
||||
</label>
|
||||
<label class="form-control">
|
||||
<span class="label-text">Body text color</span>
|
||||
<input class="input input-bordered w-full" type="color" value={block.data._foreground?.bodyColor || '#2c2c2c'} oninput={(e) => updateData({ _foreground: { ...(block.data._foreground || {}), bodyColor: e.currentTarget.value } })} />
|
||||
</label>
|
||||
<label class="form-control">
|
||||
<span class="label-text">Or type a CSS color</span>
|
||||
<input class="input input-bordered" placeholder="#2c2c2c or rgba(…) or charcoal" value={block.data._foreground?.bodyColor || ''} oninput={(e) => updateData({ _foreground: { ...(block.data._foreground || {}), bodyColor: e.currentTarget.value } })} />
|
||||
<span class="label-text text-sm">Color</span>
|
||||
<div class="flex items-center gap-2">
|
||||
<input class="input input-bordered w-12 h-10 p-1 cursor-pointer" type="color" value={block.data._background?.color || '#66755d'} oninput={(e) => updateData({ _background: { ...(block.data._background || {}), color: e.currentTarget.value } })} />
|
||||
<input class="input input-bordered flex-1" placeholder="#66755d or sage" value={block.data._background?.color || ''} oninput={(e) => updateData({ _background: { ...(block.data._background || {}), color: e.currentTarget.value } })} />
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
</details>
|
||||
{/if}
|
||||
|
||||
{#if block.data._background?.type === 'image'}
|
||||
<div class="space-y-4">
|
||||
<ImageUploader url={block.data._background?.imageUrl || ''} alt={block.data._background?.imageAlt || ''} onChange={(image) => updateData({ _background: { ...(block.data._background || {}), imageUrl: image.url, imageAlt: image.alt } })} />
|
||||
|
||||
<SegmentedControl
|
||||
label="Attachment"
|
||||
options={['scroll', 'fixed']}
|
||||
value={block.data._background?.attachment || 'scroll'}
|
||||
onChange={(v) => updateData({ _background: { ...(block.data._background || {}), attachment: v } })}
|
||||
/>
|
||||
|
||||
<SegmentedControl
|
||||
label="Overlay"
|
||||
options={[0, 10, 20, 30, 40, 50, 60, 70, 80, 90]}
|
||||
value={block.data._background?.overlayOpacity ?? 0}
|
||||
onChange={(v) => updateData({ _background: { ...(block.data._background || {}), overlay: true, overlayOpacity: v } })}
|
||||
formatLabel={(v) => `${v}%`}
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<hr class="border-base-content/10 my-4" />
|
||||
|
||||
<SegmentedControl
|
||||
label="Foreground"
|
||||
labelStyle="font-weight: 1000;"
|
||||
options={['default', 'custom']}
|
||||
value={block.data._foreground?.mode || 'default'}
|
||||
onChange={(v) => updateData({ _foreground: { ...(block.data._foreground || {}), mode: v } })}
|
||||
/>
|
||||
|
||||
{#if block.data._foreground?.mode === 'custom'}
|
||||
<div class="mt-4 space-y-3">
|
||||
<div class="form-control">
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="label-text w-24">Heading</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._foreground?.headingColor || '#2c2c2c'} oninput={(e) => updateData({ _foreground: { ...(block.data._foreground || {}), headingColor: e.currentTarget.value } })} />
|
||||
<input class="input input-bordered flex-1" placeholder="#2c2c2c" value={block.data._foreground?.headingColor || ''} oninput={(e) => updateData({ _foreground: { ...(block.data._foreground || {}), headingColor: e.currentTarget.value } })} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="label-text w-24">Sub heading</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._foreground?.subheadingColor || '#2c2c2c'} oninput={(e) => updateData({ _foreground: { ...(block.data._foreground || {}), subheadingColor: e.currentTarget.value } })} />
|
||||
<input class="input input-bordered flex-1" placeholder="#2c2c2c" value={block.data._foreground?.subheadingColor || ''} oninput={(e) => updateData({ _foreground: { ...(block.data._foreground || {}), subheadingColor: e.currentTarget.value } })} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="label-text w-24">Text</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._foreground?.textColor || '#2c2c2c'} oninput={(e) => updateData({ _foreground: { ...(block.data._foreground || {}), textColor: e.currentTarget.value } })} />
|
||||
<input class="input input-bordered flex-1" placeholder="#2c2c2c" value={block.data._foreground?.textColor || ''} oninput={(e) => updateData({ _foreground: { ...(block.data._foreground || {}), textColor: e.currentTarget.value } })} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@
|
|||
<div class="grid grid-cols-[1fr_1.5fr] gap-4">
|
||||
<!-- Drop zone / upload area -->
|
||||
<div
|
||||
class="flex min-h-28 cursor-pointer flex-col items-center justify-center rounded-box border-2 border-dashed p-3 transition-colors hover:border-primary {localUrl ? 'border-success/40' : 'border-base-300'}"
|
||||
class="flex h-32 cursor-pointer flex-col items-center justify-center rounded-box border-2 border-dashed p-3 transition-colors hover:border-primary {localUrl ? 'border-success/40' : 'border-base-300'}"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
onclick={() => fileInput?.click()}
|
||||
|
|
@ -61,7 +61,7 @@
|
|||
<p class="mt-3 text-sm text-base-content/60">Uploading…</p>
|
||||
{:else if localUrl}
|
||||
<div class="relative w-full">
|
||||
<img class="max-h-40 w-full rounded-box object-cover shadow" src={localUrl} alt={localAlt} />
|
||||
<img class="max-h-28 w-full rounded-box object-cover shadow" src={localUrl} alt={localAlt} />
|
||||
<button
|
||||
class="btn btn-circle btn-error btn-outline btn-xs absolute right-1 top-1"
|
||||
type="button"
|
||||
|
|
|
|||
38
app/src/lib/admin/editors/SegmentedControl.svelte
Normal file
38
app/src/lib/admin/editors/SegmentedControl.svelte
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<script lang="ts">
|
||||
let {
|
||||
label,
|
||||
options,
|
||||
value,
|
||||
onChange,
|
||||
formatLabel = (v: string | number) => String(v),
|
||||
labelStyle = '',
|
||||
class: className = ''
|
||||
}: {
|
||||
label?: string;
|
||||
options: (string | number)[];
|
||||
value: string | number;
|
||||
onChange: (value: string | number) => void;
|
||||
formatLabel?: (value: string | number) => string;
|
||||
labelStyle?: string;
|
||||
class?: string;
|
||||
} = $props();
|
||||
</script>
|
||||
|
||||
<div class="form-control {className}">
|
||||
<div class="flex items-center justify-between">
|
||||
{#if label}
|
||||
<span class="label-text w-24" style={labelStyle}>{label}</span>
|
||||
{/if}
|
||||
<div class="grid flex-1" style="grid-template-columns: repeat({options.length}, 1fr)">
|
||||
{#each options as option, i}
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-sm {i === 0 ? 'rounded-r-none' : ''} {i === options.length - 1 ? 'rounded-l-none' : ''} {value === option ? 'btn-active' : ''}"
|
||||
onclick={() => onChange(option)}
|
||||
>
|
||||
{formatLabel(option)}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
Loading…
Add table
Add a link
Reference in a new issue