|
|
|
@ -22,41 +22,43 @@ |
|
|
|
$: componentText = getComponentText(text, $builderStore, $component) |
|
|
|
|
|
|
|
const getComponentText = (text, builderState, componentState) => { |
|
|
|
if (!builderState.inBuilder || componentState.editing) { |
|
|
|
if (componentState.editing) { |
|
|
|
return text || " " |
|
|
|
} |
|
|
|
return text || componentState.name || "Placeholder text" |
|
|
|
} |
|
|
|
|
|
|
|
const updateText = e => { |
|
|
|
builderStore.actions.updateProp("text", e.target.textContent.trim()) |
|
|
|
builderStore.actions.updateProp("text", e.target.textContent) |
|
|
|
} |
|
|
|
</script> |
|
|
|
|
|
|
|
<button |
|
|
|
class={`spectrum-Button spectrum-Button--size${size} spectrum-Button--${type}`} |
|
|
|
class:spectrum-Button--quiet={quiet} |
|
|
|
{disabled} |
|
|
|
use:styleable={$component.styles} |
|
|
|
on:click={onClick} |
|
|
|
contenteditable={$component.editing && !icon} |
|
|
|
on:blur={$component.editing ? updateText : null} |
|
|
|
bind:this={node} |
|
|
|
class:active |
|
|
|
> |
|
|
|
{#if icon} |
|
|
|
<svg |
|
|
|
class:hasText={componentText?.length > 0} |
|
|
|
class="spectrum-Icon spectrum-Icon--size{size.toUpperCase()}" |
|
|
|
focusable="false" |
|
|
|
aria-hidden="true" |
|
|
|
aria-label={icon} |
|
|
|
> |
|
|
|
<use xlink:href="#spectrum-icon-18-{icon}" /> |
|
|
|
</svg> |
|
|
|
{/if} |
|
|
|
{componentText} |
|
|
|
</button> |
|
|
|
{#key $component.editing} |
|
|
|
<button |
|
|
|
class={`spectrum-Button spectrum-Button--size${size} spectrum-Button--${type}`} |
|
|
|
class:spectrum-Button--quiet={quiet} |
|
|
|
{disabled} |
|
|
|
use:styleable={$component.styles} |
|
|
|
on:click={onClick} |
|
|
|
contenteditable={$component.editing && !icon} |
|
|
|
on:blur={$component.editing ? updateText : null} |
|
|
|
bind:this={node} |
|
|
|
class:active |
|
|
|
> |
|
|
|
{#if icon} |
|
|
|
<svg |
|
|
|
class:hasText={componentText?.length > 0} |
|
|
|
class="spectrum-Icon spectrum-Icon--size{size.toUpperCase()}" |
|
|
|
focusable="false" |
|
|
|
aria-hidden="true" |
|
|
|
aria-label={icon} |
|
|
|
> |
|
|
|
<use xlink:href="#spectrum-icon-18-{icon}" /> |
|
|
|
</svg> |
|
|
|
{/if} |
|
|
|
{componentText} |
|
|
|
</button> |
|
|
|
{/key} |
|
|
|
|
|
|
|
<style> |
|
|
|
button { |
|
|
|
|