Spaces:
Running
Running
File size: 631 Bytes
18f7b1e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
from dataclasses import fields
import mesop as me
def merge_styles(default: me.Style, overrides: me.Style | None = None) -> me.Style:
"""Merges two styles together.
Args:
default: The starting style
overrides: Any set styles will override styles in default
"""
if not overrides:
overrides = me.Style()
default_fields = {field.name: getattr(default, field.name) for field in fields(me.Style)}
override_fields = {
field.name: getattr(overrides, field.name)
for field in fields(me.Style)
if getattr(overrides, field.name) is not None
}
return me.Style(**default_fields | override_fields)
|