Add position option to background image

This commit is contained in:
Andrew Kingston 2021-03-01 14:05:54 +00:00
parent e7f4b9c241
commit a3e959daa8
2 changed files with 56 additions and 2 deletions

View File

@ -304,6 +304,50 @@
"type": "text",
"label": "URL",
"key": "url"
},
{
"type": "select",
"label": "Position",
"key": "position",
"defaultValue": "center center",
"options": [
{
"label": "Center Top",
"value": "center top"
},
{
"label": "Center",
"value": "center center"
},
{
"label": "Center Bottom",
"value": "center bottom"
},
{
"label": "Left Top",
"value": "left top"
},
{
"label": "Left Center",
"value": "left center"
},
{
"label": "Left Bottom",
"value": "left bottom"
},
{
"label": "Right Top",
"value": "right top"
},
{
"label": "Right Center",
"value": "right center"
},
{
"label": "Right Bottom",
"value": "right bottom"
}
]
}
]
},

View File

@ -4,8 +4,18 @@
const { styleable } = getContext("sdk")
const component = getContext("component")
export let url = ""
$: style = url ? `background-image: url("${url}")` : ""
export let url
export let position
let style = ""
$: {
if (url) {
style += `background-image: url("${url}");`
}
if (position) {
style += `background-position: ${position};`
}
}
</script>
<div class="outer" use:styleable={$component.styles}>