1
0
Fork 0
mirror of synced 2024-07-28 17:46:09 +12:00

Add in-preview editing for all field labels

This commit is contained in:
Andrew Kingston 2021-10-28 16:31:22 +01:00
parent c48a56b997
commit 04bbbd7873
2 changed files with 23 additions and 2 deletions

View file

@ -1844,6 +1844,7 @@
"icon": "Text", "icon": "Text",
"illegalChildren": ["section"], "illegalChildren": ["section"],
"styles": ["size"], "styles": ["size"],
"editable": true,
"settings": [ "settings": [
{ {
"type": "field/string", "type": "field/string",
@ -1882,6 +1883,7 @@
"name": "Number Field", "name": "Number Field",
"icon": "123", "icon": "123",
"styles": ["size"], "styles": ["size"],
"editable": true,
"illegalChildren": ["section"], "illegalChildren": ["section"],
"settings": [ "settings": [
{ {
@ -1921,6 +1923,7 @@
"name": "Password Field", "name": "Password Field",
"icon": "LockClosed", "icon": "LockClosed",
"styles": ["size"], "styles": ["size"],
"editable": true,
"illegalChildren": ["section"], "illegalChildren": ["section"],
"settings": [ "settings": [
{ {
@ -1960,6 +1963,7 @@
"name": "Options Picker", "name": "Options Picker",
"icon": "ViewList", "icon": "ViewList",
"styles": ["size"], "styles": ["size"],
"editable": true,
"illegalChildren": ["section"], "illegalChildren": ["section"],
"settings": [ "settings": [
{ {
@ -2083,6 +2087,7 @@
"name": "Multi-select Picker", "name": "Multi-select Picker",
"icon": "ViewList", "icon": "ViewList",
"styles": ["size"], "styles": ["size"],
"editable": true,
"illegalChildren": ["section"], "illegalChildren": ["section"],
"settings": [ "settings": [
{ {
@ -2184,6 +2189,7 @@
"booleanfield": { "booleanfield": {
"name": "Checkbox", "name": "Checkbox",
"icon": "Checkmark", "icon": "Checkmark",
"editable": true,
"illegalChildren": ["section"], "illegalChildren": ["section"],
"settings": [ "settings": [
{ {
@ -2247,6 +2253,7 @@
"name": "Rich Text", "name": "Rich Text",
"icon": "TextParagraph", "icon": "TextParagraph",
"styles": ["size"], "styles": ["size"],
"editable": true,
"illegalChildren": ["section"], "illegalChildren": ["section"],
"settings": [ "settings": [
{ {
@ -2287,6 +2294,7 @@
"name": "Date Picker", "name": "Date Picker",
"icon": "DateInput", "icon": "DateInput",
"styles": ["size"], "styles": ["size"],
"editable": true,
"illegalChildren": ["section"], "illegalChildren": ["section"],
"settings": [ "settings": [
{ {
@ -2332,6 +2340,7 @@
"name": "Attachment", "name": "Attachment",
"icon": "Attach", "icon": "Attach",
"styles": ["size"], "styles": ["size"],
"editable": true,
"illegalChildren": ["section"], "illegalChildren": ["section"],
"settings": [ "settings": [
{ {
@ -2361,6 +2370,7 @@
"name": "Relationship Picker", "name": "Relationship Picker",
"icon": "TaskList", "icon": "TaskList",
"styles": ["size"], "styles": ["size"],
"editable": true,
"illegalChildren": ["section"], "illegalChildren": ["section"],
"settings": [ "settings": [
{ {

View file

@ -17,7 +17,7 @@
const formContext = getContext("form") const formContext = getContext("form")
const formStepContext = getContext("form-step") const formStepContext = getContext("form-step")
const fieldGroupContext = getContext("field-group") const fieldGroupContext = getContext("field-group")
const { styleable } = getContext("sdk") const { styleable, builderStore } = getContext("sdk")
const component = getContext("component") const component = getContext("component")
// Register field with form // Register field with form
@ -32,6 +32,10 @@
formStepContext || 1 formStepContext || 1
) )
// Focus label when editing
let labelNode
$: $component.editing && labelNode?.focus()
// Update form properties in parent component on every store change // Update form properties in parent component on every store change
const unsubscribe = formField?.subscribe(value => { const unsubscribe = formField?.subscribe(value => {
fieldState = value?.fieldState fieldState = value?.fieldState
@ -55,11 +59,18 @@
const updateDisabled = disabled => { const updateDisabled = disabled => {
fieldApi?.setDisabled(disabled) fieldApi?.setDisabled(disabled)
} }
const updateLabel = e => {
builderStore.actions.updateProp("label", e.target.textContent)
}
</script> </script>
<FieldGroupFallback> <FieldGroupFallback>
<div class="spectrum-Form-item" use:styleable={$component.styles}> <div class="spectrum-Form-item" use:styleable={$component.styles}>
<label <label
bind:this={labelNode}
contenteditable={$component.editing}
on:blur={$component.editing ? updateLabel : null}
class:hidden={!label} class:hidden={!label}
for={fieldState?.fieldId} for={fieldState?.fieldId}
class={`spectrum-FieldLabel spectrum-FieldLabel--sizeM spectrum-Form-itemLabel ${labelClass}`} class={`spectrum-FieldLabel spectrum-FieldLabel--sizeM spectrum-Form-itemLabel ${labelClass}`}