Add a customisable shadow to canvas boxes
Test and deploy / test (push) Successful in 2m11s
Test and deploy / deploy (push) Successful in 1m21s
Weekly Maintenance / maintenance (push) Successful in 6m55s

A box can now cast a shadow, independent of its frame: ticking "Shadow" in
the box editor gives a hard offset shadow, and Hard/Soft/Glow presets or any
typed CSS box-shadow value customise it. The value is stored on Box and
Component and carried through duplicates, components and layouts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-23 23:18:35 +01:00
co-authored by Claude Opus 5.5
parent e764078aaf
commit 8bf70c98e8
15 changed files with 243 additions and 19 deletions
+2 -1
View File
@@ -36,6 +36,7 @@ const BOX_FIELDS = `
h
z
framed
shadow
hideOnMobile
adminOnly
componentId
@@ -45,7 +46,7 @@ const BOX_FIELDS = `
// same box — or componentId, which keeps a copy of a linked box linked;
// geometry is offset so the copy is visibly separate.
const COPIED = [
"page", "kind", "widget", "html", "title", "w", "h", "framed", "hideOnMobile", "adminOnly", "componentId",
"page", "kind", "widget", "html", "title", "w", "h", "framed", "shadow", "hideOnMobile", "adminOnly", "componentId",
];
const stores = new Map();
+3 -1
View File
@@ -28,6 +28,7 @@ const COMPONENT_FIELDS = `
w
h
framed
shadow
adminOnly
uses
`;
@@ -35,7 +36,7 @@ const COMPONENT_FIELDS = `
// Matches BOX_FIELDS in stores/boxes.js, for the mutations that answer with
// a box.
const BOX_FIELDS = `
id page kind widget html title x y w h z framed hideOnMobile adminOnly componentId
id page kind widget html title x y w h z framed shadow hideOnMobile adminOnly componentId
`;
export const useComponentsStore = createCrudStore("components", {
@@ -110,6 +111,7 @@ export const useComponentsStore = createCrudStore("components", {
w: component.w,
h: component.h,
framed: component.framed,
shadow: component.shadow,
adminOnly: component.adminOnly,
...at,
};
+1 -1
View File
@@ -459,7 +459,7 @@ function toggleEdit() {
:key="box.id"
class="stack-item"
:class="{ framed: box.framed, 'admin-only': box.adminOnly }"
:style="{ height: `${box.h}px` }"
:style="{ height: `${box.h}px`, boxShadow: box.shadow || undefined }"
>
<WidgetBox v-if="box.kind === 'widget'" :name="box.widget" />
<HtmlBox v-else :html="box.html" :title="box.title" />
+63 -1
View File
@@ -3,7 +3,7 @@
* Side panel for the selected box in edit mode.
*
* Two save rhythms, matching how each kind of field is used:
* - Settings (title, geometry, frame, mobile, widget) save as soon as they
* - Settings (title, geometry, frame, shadow, mobile, widget) save as soon as they
* change — on blur/Enter for numbers, on change for the rest — the same
* "instant" model as dragging.
* - HTML is a draft. Typing updates the box on the canvas live (through the
@@ -102,6 +102,19 @@ watch(draftHtml, (html) => {
previewTimer = setTimeout(() => emit("preview", dirty.value ? html : null), 300);
});
// Starting points for a box's shadow, which is any CSS box-shadow value.
// Ticking "Shadow" uses the first; the text field takes anything else.
const SHADOWS = {
Hard: "6px 6px 0 var(--color-quaternary)",
Soft: "0 6px 18px rgb(0 0 0 / 0.5)",
Glow: "0 0 14px var(--color-primary)",
};
function saveShadow(event) {
const value = event.target.value.trim();
if (value !== props.box.shadow) save({ shadow: value });
}
async function save(patch) {
try {
await store.update(props.box.id, patch);
@@ -292,6 +305,14 @@ function resizeByKey(event) {
<input type="checkbox" :checked="box.framed" @change="save({ framed: $event.target.checked })" />
Frame
</label>
<label class="check">
<input
type="checkbox"
:checked="!!box.shadow"
@change="save({ shadow: $event.target.checked ? SHADOWS.Hard : '' })"
/>
Shadow
</label>
<label class="check">
<input
type="checkbox"
@@ -306,6 +327,27 @@ function resizeByKey(event) {
</label>
</div>
<div v-if="box.shadow" class="shadow">
<button
v-for="(value, name) in SHADOWS"
:key="name"
type="button"
class="save small"
:class="{ active: box.shadow === value }"
@click="save({ shadow: value })"
>
{{ name }}
</button>
<input
type="text"
:value="box.shadow"
spellcheck="false"
title="Any CSS box-shadow value, e.g. 4px 4px 0 red, 0 0 10px #0f0"
@change="saveShadow"
@keydown.enter="$event.target.blur()"
/>
</div>
<template v-if="box.kind === 'html'">
<CodeEditor
ref="codeEditor"
@@ -496,6 +538,26 @@ function resizeByKey(event) {
font-size: 0.95rem;
}
.shadow {
display: flex;
align-items: center;
gap: 0.4rem;
}
.shadow .active {
color: var(--color-tertiary);
border-color: var(--color-tertiary);
}
.shadow input {
flex: 1;
min-width: 0;
padding: 3px 5px;
font-family: monospace;
font-size: 0.85rem;
color: var(--color-secondary);
background: var(--color-surface-deep);
border: 1px solid var(--color-quaternary);
}
.linked {
display: flex;
align-items: center;
+2
View File
@@ -90,6 +90,8 @@ const style = computed(() => ({
// handles sit just outside its edges, where an overlapping neighbour with a
// higher z would otherwise cover them and take the press.
zIndex: props.selected ? 100000 : props.box.z,
// Applied inline because it is any CSS box-shadow value the admin typed.
boxShadow: props.box.shadow || undefined,
}));
</script>