Add alignment setting

This commit is contained in:
Andrew Kingston 2025-02-21 09:38:37 +00:00
parent 67f857565c
commit 73e4fc3813
No known key found for this signature in database
2 changed files with 58 additions and 10 deletions

View File

@ -7990,7 +7990,7 @@
"textv2": { "textv2": {
"name": "Text", "name": "Text",
"description": "A component for displaying text", "description": "A component for displaying text",
"icon": "TextParagraph", "icon": "Text",
"size": { "size": {
"width": 400, "width": 400,
"height": 24 "height": 24
@ -7998,14 +7998,51 @@
"settings": [ "settings": [
{ {
"type": "text/multiline", "type": "text/multiline",
"label": "Text", "label": "Text (Markdown supported)",
"key": "text" "key": "text",
"wide": true
}, },
{ {
"type": "color", "type": "color",
"label": "Color", "label": "Color",
"key": "color", "key": "color",
"showInBar": true "showInBar": true,
"wide": true
},
{
"type": "select",
"label": "Alignment",
"key": "align",
"defaultValue": "left",
"showInBar": true,
"wide": true,
"barStyle": "buttons",
"options": [
{
"label": "Left",
"value": "left",
"barIcon": "TextAlignLeft",
"barTitle": "Align left"
},
{
"label": "Center",
"value": "center",
"barIcon": "TextAlignCenter",
"barTitle": "Align center"
},
{
"label": "Right",
"value": "right",
"barIcon": "TextAlignRight",
"barTitle": "Align right"
},
{
"label": "Justify",
"value": "justify",
"barIcon": "TextAlignJustify",
"barTitle": "Justify text"
}
]
} }
] ]
} }

View File

@ -4,22 +4,30 @@
export let text: string = "" export let text: string = ""
export let color: string | undefined = undefined export let color: string | undefined = undefined
export let align: "left" | "center" | "right" | "justify" = "left"
const component = getContext("component") const component = getContext("component")
const { styleable } = getContext("sdk") const { styleable } = getContext("sdk")
// Add in certain settings to styles // Add in certain settings to styles
$: styles = enrichStyles($component.styles, color) $: styles = enrichStyles($component.styles, color, align)
const enrichStyles = (styles: any, color: string | undefined) => { const enrichStyles = (
if (!color) { styles: any,
return styles colorStyle: typeof color,
alignStyle: typeof align
) => {
let additions: Record<string, string> = {
"text-align": alignStyle,
}
if (colorStyle) {
additions.color = colorStyle
} }
return { return {
...styles, ...styles,
normal: { normal: {
...styles?.normal, ...styles.normal,
color, ...additions,
}, },
} }
} }
@ -30,4 +38,7 @@
</div> </div>
<style> <style>
div :global(img) {
max-width: 100%;
}
</style> </style>