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": {
"name": "Text",
"description": "A component for displaying text",
"icon": "TextParagraph",
"icon": "Text",
"size": {
"width": 400,
"height": 24
@ -7998,14 +7998,51 @@
"settings": [
{
"type": "text/multiline",
"label": "Text",
"key": "text"
"label": "Text (Markdown supported)",
"key": "text",
"wide": true
},
{
"type": "color",
"label": "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 color: string | undefined = undefined
export let align: "left" | "center" | "right" | "justify" = "left"
const component = getContext("component")
const { styleable } = getContext("sdk")
// Add in certain settings to styles
$: styles = enrichStyles($component.styles, color)
$: styles = enrichStyles($component.styles, color, align)
const enrichStyles = (styles: any, color: string | undefined) => {
if (!color) {
return styles
const enrichStyles = (
styles: any,
colorStyle: typeof color,
alignStyle: typeof align
) => {
let additions: Record<string, string> = {
"text-align": alignStyle,
}
if (colorStyle) {
additions.color = colorStyle
}
return {
...styles,
normal: {
...styles?.normal,
color,
...styles.normal,
...additions,
},
}
}
@ -30,4 +38,7 @@
</div>
<style>
div :global(img) {
max-width: 100%;
}
</style>