1
0
Fork 0
mirror of synced 2024-06-17 09:55:09 +12:00

Add rich text field to form components

This commit is contained in:
Andrew Kingston 2021-01-28 18:03:44 +00:00
parent 9791e52a10
commit c9ab20726d
9 changed files with 84 additions and 39 deletions

View file

@ -13,7 +13,7 @@
"numberfield",
"optionsfield",
"booleanfield",
"richtext",
"longformfield",
"datepicker"
]
},

View file

@ -0,0 +1,5 @@
<script>
import FormFieldSelect from "./FormFieldSelect.svelte"
</script>
<FormFieldSelect {...$$props} type="longform" />

View file

@ -21,6 +21,7 @@
import NumberFieldSelect from "./PropertyControls/NumberFieldSelect.svelte"
import OptionsFieldSelect from "./PropertyControls/OptionsFieldSelect.svelte"
import BooleanFieldSelect from "./PropertyControls/BooleanFieldSelect.svelte"
import LongFormFieldSelect from "./PropertyControls/LongFormFieldSelect.svelte"
export let componentDefinition = {}
export let componentInstance = {}
@ -66,6 +67,7 @@
"field/number": NumberFieldSelect,
"field/options": OptionsFieldSelect,
"field/boolean": BooleanFieldSelect,
"field/longform": LongFormFieldSelect,
}
const getControl = type => {

View file

@ -114,13 +114,6 @@
}
]
},
"richtext": {
"name": "Rich Text",
"description": "A component that allows the user to enter long form text.",
"icon": "ri-edit-box-line",
"styleable": true,
"bindable": true
},
"datepicker": {
"name": "Date Picker",
"description": "A basic date picker component",
@ -1241,5 +1234,28 @@
"key": "text"
}
]
},
"longformfield": {
"name": "Rich Text",
"icon": "ri-edit-box-line",
"styleable": true,
"settings": [
{
"type": "field/longform",
"label": "Field",
"key": "field"
},
{
"type": "text",
"label": "Label",
"key": "label"
},
{
"type": "text",
"label": "Placeholder",
"key": "placeholder",
"placeholder": "Type something..."
}
]
}
}

View file

@ -1,29 +0,0 @@
<script>
import { getContext } from "svelte"
import { RichText } from "@budibase/bbui"
const { styleable } = getContext("sdk")
const component = getContext("component")
export let value = ""
// Need to determine what options we want to expose.
let options = {
modules: {
toolbar: [
[
{
header: [1, 2, 3, false],
},
],
["bold", "italic", "underline", "strike"],
],
},
placeholder: "Type something...",
theme: "snow",
}
</script>
<div use:styleable={$component.styles}>
<RichText bind:value {options} />
</div>

View file

@ -49,7 +49,7 @@
setContext("form", { formApi, formState })
// Creates an API for a specific field
const makeFieldApi = (field, componentId, validate) => {
const makeFieldApi = (field, validate) => {
return {
setValue: value => {
const { fieldState } = fieldMap[field]

View file

@ -0,0 +1,51 @@
<script>
import { RichText } from "@budibase/bbui"
import "@spectrum-css/checkbox/dist/index-vars.css"
import SpectrumField from "./SpectrumField.svelte"
export let field
export let label
export let placeholder
let fieldState
let fieldApi
let value
$: fieldApi?.setValue(value)
// Options for rich text component
const options = {
modules: {
toolbar: [
[
{
header: [1, 2, 3, false],
},
],
["bold", "italic", "underline", "strike"],
],
},
placeholder: placeholder || "Type something...",
theme: "snow",
}
</script>
<SpectrumField {label} {field} bind:fieldState bind:fieldApi>
{#if fieldState}
<div>
<RichText bind:value {options} />
</div>
{/if}
</SpectrumField>
<style>
div {
background-color: white;
}
div :global(.ql-snow.ql-toolbar:after, .ql-snow .ql-toolbar:after) {
display: none;
}
div :global(.ql-snow .ql-formats:after) {
display: none;
}
</style>

View file

@ -4,3 +4,4 @@ export { default as stringfield } from "./StringField.svelte"
export { default as numberfield } from "./NumberField.svelte"
export { default as optionsfield } from "./OptionsField.svelte"
export { default as booleanfield } from "./BooleanField.svelte"
export { default as longformfield } from "./LongFormField.svelte"

View file

@ -16,7 +16,6 @@ export { default as container } from "./Container.svelte"
export { default as datagrid } from "./grid/Component.svelte"
export { default as screenslot } from "./ScreenSlot.svelte"
export { default as button } from "./Button.svelte"
export { default as richtext } from "./RichText.svelte"
export { default as list } from "./List.svelte"
export { default as stackedlist } from "./StackedList.svelte"
export { default as card } from "./Card.svelte"