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