Add class name property to component (#545)
This commit is contained in:
parent
b36680fefd
commit
7fa1a85d91
@ -47,6 +47,9 @@ class Component(Base, ABC):
|
|||||||
# The id for the component.
|
# The id for the component.
|
||||||
id: Any = None
|
id: Any = None
|
||||||
|
|
||||||
|
# The class name for the component.
|
||||||
|
class_name: Any = None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def __init_subclass__(cls, **kwargs):
|
def __init_subclass__(cls, **kwargs):
|
||||||
"""Set default properties.
|
"""Set default properties.
|
||||||
@ -145,6 +148,11 @@ class Component(Base, ABC):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Convert class_name to str if it's list
|
||||||
|
class_name = kwargs.get("class_name", "")
|
||||||
|
if isinstance(class_name, (List, tuple)):
|
||||||
|
kwargs["class_name"] = " ".join(class_name)
|
||||||
|
|
||||||
# Construct the component.
|
# Construct the component.
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
@ -370,7 +378,11 @@ class Component(Base, ABC):
|
|||||||
tag = self._render()
|
tag = self._render()
|
||||||
return str(
|
return str(
|
||||||
tag.add_props(
|
tag.add_props(
|
||||||
**self.event_triggers, key=self.key, sx=self.style, id=self.id
|
**self.event_triggers,
|
||||||
|
key=self.key,
|
||||||
|
sx=self.style,
|
||||||
|
id=self.id,
|
||||||
|
class_name=self.class_name,
|
||||||
).set(
|
).set(
|
||||||
contents=utils.join(
|
contents=utils.join(
|
||||||
[str(tag.contents)] + [child.render() for child in self.children]
|
[str(tag.contents)] + [child.render() for child in self.children]
|
||||||
|
Loading…
Reference in New Issue
Block a user