Building components settings and refactoring

This commit is contained in:
Conor_Mack 2020-05-19 17:00:53 +01:00
parent 983a1c3718
commit 3cd48773d1
15 changed files with 227 additions and 408 deletions

View File

@ -87,6 +87,7 @@ const css_map = {
}, },
} }
//Only used here
export const generate_rule = ([name, values]) => export const generate_rule = ([name, values]) =>
`${css_map[name].name}: ${css_map[name].generate(values)};` `${css_map[name].name}: ${css_map[name].generate(values)};`
@ -110,6 +111,7 @@ const object_to_css_string = [
join_with("\n"), join_with("\n"),
] ]
//USED BY generate_screen_css
export const generate_css = style => { export const generate_css = style => {
// let cssString = pipe(style, object_to_css_string) // let cssString = pipe(style, object_to_css_string)
let cssString = Object.entries(style).reduce((str, [key, value]) => { let cssString = Object.entries(style).reduce((str, [key, value]) => {
@ -128,6 +130,7 @@ export const generate_css = style => {
const apply_class = (id, name, styles) => `.${name}-${id} {\n${styles}\n}` const apply_class = (id, name, styles) => `.${name}-${id} {\n${styles}\n}`
//USED IN MULTIPLE PLACES IN THE BUILDER STORE
export const generate_screen_css = component_array => { export const generate_screen_css = component_array => {
let styles = "" let styles = ""
let emptyStyles = {} let emptyStyles = {}

View File

@ -46,9 +46,6 @@
? getProps($store.currentPreviewItem, ["name", "favicon"]) ? getProps($store.currentPreviewItem, ["name", "favicon"])
: getProps($store.currentPreviewItem, ["name", "description", "route"]) : getProps($store.currentPreviewItem, ["name", "description", "route"])
// const onStyleChanged = store.setComponentStyle
// const onStyleChanged = store.onStyleChanged
const onStyleChanged = store.setComponentStyle const onStyleChanged = store.setComponentStyle
const onPropChanged = store.setComponentProp const onPropChanged = store.setComponentProp
@ -87,14 +84,11 @@
<div class="component-props-container"> <div class="component-props-container">
{#if selectedCategory.value === 'design'} {#if selectedCategory.value === 'design'}
<DesignView <DesignView {panelDefinition} {componentInstance} {onStyleChanged} />
{panelDefinition}
{componentInstance}
{componentDefinition}
{onStyleChanged} />
{:else if selectedCategory.value === 'settings'} {:else if selectedCategory.value === 'settings'}
<SettingsView <SettingsView
{componentInstance} {componentInstance}
{componentDefinition}
{panelDefinition} {panelDefinition}
onChange={onPropChanged} /> onChange={onPropChanged} />
{/if} {/if}

View File

@ -16,12 +16,15 @@
const joinPath = join("/") const joinPath = join("/")
const normalizedName = name => const normalizedName = name =>
pipe(name, [ pipe(
trimCharsStart("./"), name,
trimCharsStart("~/"), [
trimCharsStart("../"), trimCharsStart("./"),
trimChars(" "), trimCharsStart("~/"),
]) trimCharsStart("../"),
trimChars(" "),
]
)
const lastPartOfName = c => { const lastPartOfName = c => {
if (!c) return "" if (!c) return ""
@ -31,10 +34,10 @@
const isComponentSelected = (current, comp) => current === comp const isComponentSelected = (current, comp) => current === comp
$: _screens = pipe(screens, [ $: _screens = pipe(
map(c => ({ component: c, title: lastPartOfName(c) })), screens,
sortBy("title"), [map(c => ({ component: c, title: lastPartOfName(c) })), sortBy("title")]
]) )
const confirmDeleteComponent = component => { const confirmDeleteComponent = component => {
componentToDelete = component componentToDelete = component
@ -42,6 +45,7 @@
} }
const changeScreen = screen => { const changeScreen = screen => {
debugger
store.setCurrentScreen(screen.title) store.setCurrentScreen(screen.title)
$goto(`./:page/${screen.title}`) $goto(`./:page/${screen.title}`)
} }

View File

@ -22,7 +22,11 @@
const capitalise = s => s.substring(0, 1).toUpperCase() + s.substring(1) const capitalise = s => s.substring(0, 1).toUpperCase() + s.substring(1)
const get_name = s => (!s ? "" : last(s.split("/"))) const get_name = s => (!s ? "" : last(s.split("/")))
const get_capitalised_name = name => pipe(name, [get_name, capitalise]) const get_capitalised_name = name =>
pipe(
name,
[get_name, capitalise]
)
const moveDownComponent = component => { const moveDownComponent = component => {
const c = component const c = component
@ -33,6 +37,7 @@
const selectComponent = component => { const selectComponent = component => {
// Set current component // Set current component
debugger
store.selectComponent(component) store.selectComponent(component)
// Get ID path // Get ID path

View File

@ -6,7 +6,10 @@
export let initialValue = "" export let initialValue = ""
export let styleBindingProperty = "" export let styleBindingProperty = ""
$: bindOptionToStyle = !!styleBindingProperty const handleStyleBind = value =>
!!styleBindingProperty ? { style: `${styleBindingProperty}: ${value}` } : {}
$: isOptionsObject = options.every(o => typeof o === "object")
onMount(() => { onMount(() => {
if (!value && !!initialValue) { if (!value && !!initialValue) {
@ -19,15 +22,15 @@
class="uk-select uk-form-small" class="uk-select uk-form-small"
{value} {value}
on:change={ev => onChange(ev.target.value)}> on:change={ev => onChange(ev.target.value)}>
{#each options as { value, label }} {#if isOptionsObject}
{#if bindOptionToStyle} {#each options as { value, label }}
<option <option {...handleStyleBind(value || label)} value={value || label}>
style={`${styleBindingProperty}: ${value || label};`}
value={value || label}>
{label} {label}
</option> </option>
{:else} {/each}
<option value={value || label}>{label}</option> {:else}
{/if} {#each options as value}
{/each} <option {...handleStyleBind(value)} {value}>{value}</option>
{/each}
{/if}
</select> </select>

View File

@ -3,9 +3,20 @@
export let label = "" export let label = ""
export let control = null export let control = null
export let key = ""
export let value = "" export let value = ""
export let valueType = ""
export let props = {} export let props = {}
export let onChange = () => {} export let onChange = () => {}
function handleChange(key, v) {
!!v.target
? onChange(name, key, valueType ? v.target[valueType] : v.target.value)
: onChange(name, key, v)
}
const handleValueType = value =>
valueType ? { [valueType]: value } : { value }
</script> </script>
<div class="property-control"> <div class="property-control">
@ -13,9 +24,9 @@
<div class="control"> <div class="control">
<svelte:component <svelte:component
this={control} this={control}
{value} {...handleValueType(value)}
on:change={onChange} on:change={val => handleChange(key, val)}
{onChange} onChange={val => handleChange(key, val)}
{...props} /> {...props} />
</div> </div>
</div> </div>

View File

@ -5,37 +5,21 @@
export let name = "" export let name = ""
export let properties = [] export let properties = []
export let componentInstance = {} export let componentInstance = {}
export let componentDefinition = {}
export let onStyleChanged = () => {} export let onStyleChanged = () => {}
export let show = false export let show = false
let showComponentGroup = false
const propExistsOnComponentDef = prop => prop in componentDefinition.props
const capitalize = name => name[0].toUpperCase() + name.slice(1) const capitalize = name => name[0].toUpperCase() + name.slice(1)
function onChange(key, v) { function onChange(key, v) {
console.log("PROPERTY GROUP ON CHANGE")
!!v.target !!v.target
? onStyleChanged(name, key, v.target.value) ? onStyleChanged(name, key, v.target.value)
: onStyleChanged(name, key, v) : onStyleChanged(name, key, v)
} }
$: {
let res = false
let componentProps = Object.keys(componentDefinition.props)
for (let prop in properties) {
if (componentProps.includes(prop)) {
showComponentGroup = true
}
if (showComponentGroup) break
}
}
$: icon = show ? "ri-arrow-down-s-fill" : "ri-arrow-right-s-fill" $: icon = show ? "ri-arrow-down-s-fill" : "ri-arrow-right-s-fill"
</script> </script>
<!-- {#if showComponentGroup} -->
<div class="property-group-container"> <div class="property-group-container">
<div class="property-group-name" on:click={() => (show = !show)}> <div class="property-group-name" on:click={() => (show = !show)}>
<div class="icon"> <div class="icon">
@ -46,18 +30,16 @@
<div class="property-panel" class:show> <div class="property-panel" class:show>
{#each properties as props} {#each properties as props}
<!-- {#if propExistsOnComponentDef(key)} -->
<PropertyControl <PropertyControl
label={props.label} label={props.label}
control={props.control} control={props.control}
value={componentInstance[props.cssKey]} key={props.cssKey}
onChange={value => onChange(props.cssKey, value)} value={componentInstance['_styles'][props.cssKey]}
onChange={onStyleChanged}
props={{ ...excludeProps(props, ['control']) }} /> props={{ ...excludeProps(props, ['control']) }} />
<!-- {/if} -->
{/each} {/each}
</div> </div>
</div> </div>
<!-- {/if} -->
<style> <style>
.property-group-container { .property-group-container {

View File

@ -3,33 +3,26 @@
import InputGroup from "../common/Inputs/InputGroup.svelte" import InputGroup from "../common/Inputs/InputGroup.svelte"
import { excludeProps } from "./propertyCategories.js" import { excludeProps } from "./propertyCategories.js"
export let panelDefinition = {} export let panelDefinition = []
export let componentDefinition = {}
export let componentInstance = {} export let componentInstance = {}
export let onChange = () => {} export let onChange = () => {}
const propExistsOnComponentDef = prop => prop in componentDefinition.props
function handleChange(key, data) { function handleChange(key, data) {
data.target ? onChange(key, data.target.value) : onChange(key, data) data.target ? onChange(key, data.target.value) : onChange(key, data)
} }
const meta = [
{ placeholder: "T" },
{ placeholder: "R" },
{ placeholder: "B" },
{ placeholder: "L" },
]
$: settingsControls = !!panelDefinition ? Object.entries(panelDefinition) : []
</script> </script>
<h4>Settings Panel</h4> {#each panelDefinition as definition}
{#if propExistsOnComponentDef(definition.key)}
<InputGroup label="Testing" {meta} /> <PropertyControl
control={definition.control}
{#each settingsControls as [key, definition]} label={definition.label}
<PropertyControl key={definition.key}
control={definition.control} value={componentInstance[definition.key]}
label={key} {onChange}
value={componentInstance[key]} props={{ ...excludeProps(definition, ['control']) }} />
onChange={value => handleChange(key, value)} {/if}
props={{ ...excludeProps(definition, ['control']) }} />
{/each} {/each}

View File

@ -102,25 +102,13 @@ export const typography = [
label: "Color", label: "Color",
cssKey: "color", cssKey: "color",
control: OptionSelect, control: OptionSelect,
options: [ options: ["black", "red", "white", "blue", "green"],
{ label: "black" },
{ label: "red" },
{ label: "white" },
{ label: "blue" },
{ label: "green" },
],
}, },
{ {
label: "align", label: "align",
cssKey: "text-align", cssKey: "text-align",
control: OptionSelect, control: OptionSelect,
options: [ options: ["initial", "left", "right", "center", "justify"],
{ label: "initial" },
{ label: "left" },
{ label: "right" },
{ label: "center" },
{ label: "justify" },
],
}, //custom }, //custom
{ label: "transform", cssKey: "text-transform", control: Input }, //custom { label: "transform", cssKey: "text-transform", control: Input }, //custom
{ label: "style", cssKey: "font-style", control: Input }, //custom { label: "style", cssKey: "font-style", control: Input }, //custom

View File

@ -1,4 +1,6 @@
import Input from "../common/Input.svelte" import Input from "../common/Input.svelte"
import OptionSelect from "./OptionSelect.svelte"
import Checkbox from "../common/Checkbox.svelte"
import { all } from "./propertyCategories.js" import { all } from "./propertyCategories.js"
@ -24,7 +26,31 @@ export default {
icon: "ri-layout-row-fill", icon: "ri-layout-row-fill",
commonProps: {}, commonProps: {},
children: [], children: [],
properties: { design: { ...all } }, properties: {
design: { ...all },
settings: [
{
key: "type",
label: "Type",
control: OptionSelect,
options: [
{ label: "article" },
{ label: "aside" },
{ label: "details" },
{ label: "div" },
{ label: "figure" },
{ label: "figcaption" },
{ label: "footer" },
{ label: "header" },
{ label: "main" },
{ label: "mark" },
{ label: "nav" },
{ label: "paragraph" },
{ label: "summary" },
],
},
],
},
}, },
{ {
name: "Text", name: "Text",
@ -39,11 +65,19 @@ export default {
icon: "ri-heading", icon: "ri-heading",
properties: { properties: {
design: { ...all }, design: { ...all },
settings: { settings: [
text: { {
key: "text",
label: "Text",
control: Input, control: Input,
}, },
}, {
key: "type",
label: "Type",
control: OptionSelect,
options: ["h1", "h2", "h3", "h4", "h5", "h6"],
},
],
}, },
}, },
{ {
@ -53,11 +87,31 @@ export default {
icon: "ri-paragraph", icon: "ri-paragraph",
properties: { properties: {
design: { ...all }, design: { ...all },
settings: { settings: [
text: { {
label: "Text",
key: "text",
control: Input, control: Input,
}, },
}, {
label: "Type",
key: "type",
control: OptionSelect,
options: [
"none",
"bold",
"strong",
"italic",
"emphasis",
"mark",
"small",
"del",
"ins",
"sub",
"sup",
],
},
],
}, },
}, },
], ],
@ -74,21 +128,38 @@ export default {
description: description:
"A textfield component that allows the user to input text.", "A textfield component that allows the user to input text.",
icon: "ri-edit-box-line", icon: "ri-edit-box-line",
properties: { design: { ...all } }, properties: {
design: { ...all },
settings: [
{ label: "Label", key: "label", control: Input },
{
label: "Type",
key: "type",
control: OptionSelect,
options: ["text", "password"],
},
],
},
}, },
{ {
_component: "@budibase/standard-components/checkbox", _component: "@budibase/standard-components/checkbox",
name: "Checkbox", name: "Checkbox",
description: "A selectable checkbox component", description: "A selectable checkbox component",
icon: "ri-checkbox-line", icon: "ri-checkbox-line",
properties: { design: { ...all } }, properties: {
design: { ...all },
settings: [{ label: "Label", key: "label", control: Input }],
},
}, },
{ {
_component: "@budibase/standard-components/radiobutton", _component: "@budibase/standard-components/radiobutton",
name: "Radiobutton", name: "Radiobutton",
description: "A selectable radiobutton component", description: "A selectable radiobutton component",
icon: "ri-radio-button-line", icon: "ri-radio-button-line",
properties: { design: { ...all } }, properties: {
design: { ...all },
settings: [{ label: "Label", key: "label", control: Input }],
},
}, },
{ {
_component: "@budibase/standard-components/select", _component: "@budibase/standard-components/select",
@ -96,7 +167,10 @@ export default {
description: description:
"A select component for choosing from different options", "A select component for choosing from different options",
icon: "ri-file-list-line", icon: "ri-file-list-line",
properties: { design: { ...all } }, properties: {
design: { ...all },
settings: []
},
}, },
], ],
}, },
@ -106,7 +180,20 @@ export default {
description: "A basic html button that is ready for styling", description: "A basic html button that is ready for styling",
icon: "ri-radio-button-fill", icon: "ri-radio-button-fill",
children: [], children: [],
properties: { design: { ...all } }, properties: {
design: {
...all
},
settings: [
{ label: "Text", key: "text", control: Input },
{
label: "Disabled",
key: "disabled",
valueType: "checked",
control: Checkbox,
},
]
},
}, },
{ {
_component: "@budibase/standard-components/icon", _component: "@budibase/standard-components/icon",

View File

@ -23,35 +23,10 @@
"name": "Button", "name": "Button",
"description": "an html <button />", "description": "an html <button />",
"props": { "props": {
"contentText": { "text": "string",
"type": "string",
"default": "Button"
},
"className": "string", "className": "string",
"disabled": "bool", "disabled": "bool",
"onClick": "event", "onClick": "event"
"background": "string",
"color": "string",
"border": "string",
"padding": "string",
"hoverColor": "string",
"hoverBackground": "string",
"hoverBorder": "string",
"fontFamily": {
"type": "options",
"default": "initial",
"styleBindingProperty": "font-family",
"options": [
"initial",
"Times New Roman",
"Georgia",
"Arial",
"Arial Black",
"Comic Sans MS",
"Impact",
"Lucida Sans Unicode"
]
}
}, },
"tags": [ "tags": [
"layout" "layout"
@ -167,58 +142,7 @@
"children": false, "children": false,
"props": { "props": {
"text": "string", "text": "string",
"color": "string", "type": {"type": "string", "default": "none"}
"fontFamily": {
"type": "options",
"default": "initial",
"styleBindingProperty": "font-family",
"options": [
"initial",
"Times New Roman",
"Georgia",
"Arial",
"Arial Black",
"Comic Sans MS",
"Impact",
"Lucida Sans Unicode"
]
},
"fontSize": "string",
"textAlign": {
"type": "options",
"default": "inline",
"options": [
"left",
"center",
"right"
]
},
"verticalAlign": {
"type": "options",
"default": "inline",
"options": [
"top",
"middle",
"bottom"
]
},
"formattingTag": {
"type": "options",
"default": "none",
"options": [
"none",
"<b> - bold",
"<strong> - important",
"<i> - italic",
"<em> - emphasized",
"<mark> - marked text",
"<small> - small",
"<del> - deleted",
"<ins> - inserted",
"<sub> - subscript",
"<sup> - superscript"
]
}
}, },
"tags": [ "tags": [
"div", "div",
@ -230,6 +154,7 @@
"description": "A component that allows the user to input text.", "description": "A component that allows the user to input text.",
"props": { "props": {
"label": "string", "label": "string",
"type": "string",
"value": "string", "value": "string",
"onchange": "event" "onchange": "event"
} }
@ -383,27 +308,6 @@
"summary" "summary"
], ],
"default": "div" "default": "div"
},
"backgroundColor": "string",
"color": "string",
"height": "string",
"width": "string",
"borderWidth": "string",
"borderColor": "string",
"borderStyle": {
"type": "options",
"options": [
"none",
"solid",
"dotted",
"dashed",
"double",
"groove",
"ridge",
"inset",
"outset"
],
"default": "none"
} }
}, },
"container": true, "container": true,
@ -430,21 +334,6 @@
"h5", "h5",
"h6" "h6"
] ]
},
"fontFamily": {
"type": "options",
"default": "initial",
"styleBindingProperty": "font-family",
"options": [
"initial",
"Times New Roman",
"Georgia",
"Arial",
"Arial Black",
"Comic Sans MS",
"Impact",
"Lucida Sans Unicode"
]
} }
}, },
"tags": [] "tags": []

View File

@ -1,58 +1,15 @@
<script> <script>
import { cssVars, createClasses } from "./cssVars"
import { buildStyle } from "./buildStyle"
export let className = "default" export let className = "default"
export let disabled = false export let disabled = false
export let text export let text
export let onClick export let onClick
export let background
export let color
export let border
export let padding
export let hoverColor
export let hoverBackground
export let hoverBorder
export let fontFamily
export let _bb export let _bb
let theButton let theButton
let cssVariables
let buttonStyles
let customHoverColorClass
let customHoverBorderClass
let customHoverBackClass
let customClasses = ""
$: if (_bb.props._children && _bb.props._children.length > 0) $: if (_bb.props._children && _bb.props._children.length > 0)
theButton && _bb.attachChildren(theButton) theButton && _bb.attachChildren(theButton)
$: {
cssVariables = {
hoverColor,
hoverBorder,
hoverBackground,
background,
color,
border,
}
buttonStyles = buildStyle({
padding,
"font-family": fontFamily,
})
customClasses = createClasses({
hoverColor,
hoverBorder,
hoverBackground,
background,
border,
color,
})
}
const clickHandler = () => { const clickHandler = () => {
_bb.call(onClick) _bb.call(onClick)
} }
@ -60,13 +17,12 @@
<button <button
bind:this={theButton} bind:this={theButton}
use:cssVars={cssVariables}
class="{className} class="{className}
{customClasses}"
disabled={disabled || false} disabled={disabled || false}
on:click={clickHandler} on:click={clickHandler}>
style={buttonStyles}> {#if !_bb.props._children || _bb.props._children.length === 0}
{#if !_bb.props._children || _bb.props._children.length === 0}{text}{/if} {text}
{/if}
</button> </button>
<style> <style>

View File

@ -4,30 +4,12 @@
export let className = "" export let className = ""
export let onLoad export let onLoad
export let type = "div" export let type = "div"
export let backgroundColor
export let color
export let width
export let height
export let borderWidth
export let borderColor
export let borderStyle
export let _bb export let _bb
let containerElement let containerElement
let hasLoaded let hasLoaded
let currentChildren let currentChildren
$: cssVariables = {
backgroundColor,
color,
height,
width,
borderWidth,
borderColor,
borderStyle,
}
$: classes = `${createClasses(cssVariables)} ${className}`
$: { $: {
if (containerElement) { if (containerElement) {
_bb.attachChildren(containerElement) _bb.attachChildren(containerElement)
@ -40,95 +22,29 @@
</script> </script>
{#if type === 'div'} {#if type === 'div'}
<div <div bind:this={containerElement} />
class={classes}
bind:this={containerElement}
use:cssVars={cssVariables} />
{:else if type === 'header'} {:else if type === 'header'}
<header <header bind:this={containerElement} />
class={classes}
bind:this={containerElement}
use:cssVars={cssVariables} />
{:else if type === 'main'} {:else if type === 'main'}
<main <main bind:this={containerElement} />
class={classes}
bind:this={containerElement}
use:cssVars={cssVariables} />
{:else if type === 'footer'} {:else if type === 'footer'}
<footer <footer bind:this={containerElement} />
class={classes}
bind:this={containerElement}
use:cssVars={cssVariables} />
{:else if type === 'aside'} {:else if type === 'aside'}
<aside <aside bind:this={containerElement} />
class={classes}
bind:this={containerElement}
use:cssVars={cssVariables} />
{:else if type === 'summary'} {:else if type === 'summary'}
<summary <summary bind:this={containerElement} />
class={classes}
bind:this={containerElement}
use:cssVars={cssVariables} />
{:else if type === 'details'} {:else if type === 'details'}
<details <details bind:this={containerElement} />
class={classes}
bind:this={containerElement}
use:cssVars={cssVariables} />
{:else if type === 'article'} {:else if type === 'article'}
<article <article bind:this={containerElement} />
class={classes}
bind:this={containerElement}
use:cssVars={cssVariables} />
{:else if type === 'nav'} {:else if type === 'nav'}
<nav <nav bind:this={containerElement} />
class={classes}
bind:this={containerElement}
use:cssVars={cssVariables} />
{:else if type === 'mark'} {:else if type === 'mark'}
<mark <mark bind:this={containerElement} />
class={classes}
bind:this={containerElement}
use:cssVars={cssVariables} />
{:else if type === 'figure'} {:else if type === 'figure'}
<figure <figure bind:this={containerElement} />
class={classes}
bind:this={containerElement}
use:cssVars={cssVariables} />
{:else if type === 'figcaption'} {:else if type === 'figcaption'}
<figcaption <figcaption bind:this={containerElement} />
class={classes}
bind:this={containerElement}
use:cssVars={cssVariables} />
{:else if type === 'paragraph'} {:else if type === 'paragraph'}
<p class={classes} bind:this={containerElement} use:cssVars={cssVariables} /> <p bind:this={containerElement} />
{/if} {/if}
<style>
.backgroundColor {
background-color: var(--backgroundColor);
}
.color {
color: var(--color);
}
.height {
height: var(--height);
}
.width {
width: var(--width);
}
.borderColor {
border-color: var(--borderColor);
}
.borderWidth {
border-width: var(--borderWidth);
}
.borderStyle {
border-style: var(--borderStyle);
}
</style>

View File

@ -2,27 +2,25 @@
import { buildStyle } from "./buildStyle.js" import { buildStyle } from "./buildStyle.js"
export let className = "" export let className = ""
export let type export let type
export let _bb
export let text = "" export let text = ""
export let fontFamily = ""
export let color = "" export let _bb
let containerElement let containerElement
$: containerElement && !text && _bb.attachChildren(containerElement) $: containerElement && !text && _bb.attachChildren(containerElement)
$: style = buildStyle({ "font-family": fontFamily, color })
</script> </script>
{#if type === 'h1'} {#if type === 'h1'}
<h1 class={className} {style} bind:this={containerElement}>{text}</h1> <h1 class={className} bind:this={containerElement}>{text}</h1>
{:else if type === 'h2'} {:else if type === 'h2'}
<h2 class={className} {style} bind:this={containerElement}>{text}</h2> <h2 class={className} bind:this={containerElement}>{text}</h2>
{:else if type === 'h3'} {:else if type === 'h3'}
<h3 class={className} {style} bind:this={containerElement}>{text}</h3> <h3 class={className} bind:this={containerElement}>{text}</h3>
{:else if type === 'h4'} {:else if type === 'h4'}
<h4 class={className} {style} bind:this={containerElement}>{text}</h4> <h4 class={className} bind:this={containerElement}>{text}</h4>
{:else if type === 'h5'} {:else if type === 'h5'}
<h5 class={className} {style} bind:this={containerElement}>{text}</h5> <h5 class={className} bind:this={containerElement}>{text}</h5>
{:else if type === 'h6'} {:else if type === 'h6'}
<h6 class={className} {style} bind:this={containerElement}>{text}</h6> <h6 class={className} bind:this={containerElement}>{text}</h6>
{/if} {/if}

View File

@ -4,45 +4,35 @@
export let text = "" export let text = ""
export let className = "" export let className = ""
export let formattingTag = "" export let type = ""
export let fontFamily = ""
export let fontSize = "1em"
export let textAlign = ""
export let verticalAlign = ""
export let color = ""
export let _bb export let _bb
const isTag = tag => (formattingTag || "").indexOf(tag) > -1 const isTag = tag => type === tag
$: style = buildStyle({
"font-size": fontSize,
"font-family": fontFamily,
color,
})
</script> </script>
{#if isTag('none')} {#if isTag('none')}
<span {style}>{text}</span> <span>{text}</span>
{:else if isTag('<b>')} {:else if isTag('bold')}
<b class={className} {style}>{text}</b> <b class={className}>{text}</b>
{:else if isTag('<strong>')} {:else if isTag('strong')}
<strong class={className} {style}>{text}</strong> <strong class={className}>{text}</strong>
{:else if isTag('<i>')} {:else if isTag('italic')}
<i class={className} {style}>{text}</i> <i class={className}>{text}</i>
{:else if isTag('<em>')} {:else if isTag('emphasis')}
<em class={className} {style}>{text}</em> <em class={className}>{text}</em>
{:else if isTag('<mark>')} {:else if isTag('mark')}
<mark class={className} {style}>{text}</mark> <mark class={className}>{text}</mark>
{:else if isTag('<small>')} {:else if isTag('small')}
<small class={className} {style}>{text}</small> <small class={className}>{text}</small>
{:else if isTag('<del>')} {:else if isTag('del')}
<del class={className} {style}>{text}</del> <del class={className}>{text}</del>
{:else if isTag('<ins>')} {:else if isTag('ins')}
<ins class={className} {style}>{text}</ins> <ins class={className}>{text}</ins>
{:else if isTag('<sub>')} {:else if isTag('sub')}
<sub class={className} {style}>{text}</sub> <sub class={className}>{text}</sub>
{:else if isTag('<sup>')} {:else if isTag('sup')}
<sup class={className} {style}>{text}</sup> <sup class={className}>{text}</sup>
{:else}{text}{/if} {:else}
<span>{text}</span>
{/if}