Add a customisable shadow to canvas boxes
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:
+1
-1
@@ -271,7 +271,7 @@ renders any page's boxes.
|
||||
component's html in its `html` (`fillLinked` in
|
||||
`backend/graph/component_helpers.go`), and saving the html in `BoxEditor`
|
||||
saves the component, so every linked box on every page changes. Only the
|
||||
html is shared; title, geometry, frame and visibility stay each box's own.
|
||||
html is shared; title, geometry, frame, shadow and visibility stay each box's own.
|
||||
"Save as component" in the editor makes a component from an html box and
|
||||
links it; "Detach" gives a linked box its own copy. Deleting a component
|
||||
detaches its boxes first, so no page changes. A layout keeps both the link
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -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" />
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user