From 387831b799db2acdf4b5d4481d6479ff5d88c49b Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 28 Oct 2021 15:29:48 +0100 Subject: [PATCH] Add in-preview editing of buttons and add settings bar for buttons --- packages/client/manifest.json | 13 +++++++++- .../client/src/components/app/Button.svelte | 25 ++++++++++++++++--- .../client/src/components/app/Heading.svelte | 13 +++------- .../client/src/components/app/Link.svelte | 10 +------- .../client/src/components/app/Text.svelte | 13 +++------- .../src/components/preview/SettingsBar.svelte | 4 +-- 6 files changed, 45 insertions(+), 33 deletions(-) diff --git a/packages/client/manifest.json b/packages/client/manifest.json index 74e28e688c..47c79df6bb 100644 --- a/packages/client/manifest.json +++ b/packages/client/manifest.json @@ -245,7 +245,9 @@ "name": "Button", "description": "A basic html button that is ready for styling", "icon": "Button", + "editable": true, "illegalChildren": ["section"], + "showSettingsBar": true, "settings": [ { "type": "text", @@ -254,6 +256,7 @@ }, { "type": "select", + "showInBar": true, "label": "Variant", "key": "type", "options": [ @@ -282,6 +285,7 @@ { "type": "select", "label": "Size", + "showInBar": true, "key": "size", "options": [ { @@ -306,11 +310,18 @@ { "type": "boolean", "label": "Quiet", - "key": "quiet" + "key": "quiet", + "showInBar": true, + "barIcon": "VisibilityOff", + "barTitle": "Quiet variant", + "barSeparator": false }, { "type": "boolean", "label": "Disabled", + "showInBar": true, + "barIcon": "NoEdit", + "barTitle": "Disable button", "key": "disabled" }, { diff --git a/packages/client/src/components/app/Button.svelte b/packages/client/src/components/app/Button.svelte index 9900c740d2..3fbdcf6744 100644 --- a/packages/client/src/components/app/Button.svelte +++ b/packages/client/src/components/app/Button.svelte @@ -2,7 +2,7 @@ import { getContext } from "svelte" import "@spectrum-css/button/dist/index-vars.css" - const { styleable } = getContext("sdk") + const { styleable, builderStore } = getContext("sdk") const component = getContext("component") export let disabled = false @@ -11,16 +11,35 @@ export let size = "M" export let type = "primary" export let quiet = false + + let node + + $: $component.editing && node?.focus() + $: componentText = getComponentText(text, $builderStore, $component) + + const getComponentText = (text, builderState, componentState) => { + if (!builderState.inBuilder || componentState.editing) { + return text || " " + } + return text || componentState.name || "Placeholder text" + } + + const updateText = e => { + builderStore.actions.updateProp("text", e.target.textContent) + }