Mark individual styles as changed if they have been changed

This commit is contained in:
Andrew Kingston 2021-01-05 11:59:19 +00:00
parent 57d69d1c9a
commit 207eaed27b
1 changed files with 14 additions and 12 deletions

View File

@ -10,25 +10,27 @@
export let onStyleChanged = () => {}
export let open = false
const hasPropChanged = prop => {
if (prop.initialValue !== undefined) {
return style[prop.key] !== prop.initialValue
}
return style[prop.key] != null && style[prop.key] !== ""
}
$: style = componentInstance["_styles"][styleCategory] || {}
$: changed = properties.some(
prop =>
style[prop.key] != null &&
style[prop.key] !== "" &&
style[prop.key] !== prop.initialValue
)
$: changed = properties.some(prop => hasPropChanged(prop))
</script>
<DetailSummary name={`${name}${changed ? ' *' : ''}`} on:open show={open} thin>
<div>
{#each properties as props}
{#each properties as prop}
<PropertyControl
label={props.label}
control={props.control}
key={props.key}
value={style[props.key]}
label={`${prop.label}${hasPropChanged(prop) ? ' *' : ''}`}
control={prop.control}
key={prop.key}
value={style[prop.key]}
onChange={(key, value) => onStyleChanged(styleCategory, key, value)}
props={{ ...excludeProps(props, ['control', 'label']) }} />
props={{ ...excludeProps(prop, ['control', 'label']) }} />
{/each}
</div>
</DetailSummary>