|
@@ -428,7 +428,9 @@ class AccordionRoot(AccordionComponent):
|
|
|
|
|
|
def _get_imports(self):
|
|
|
return imports.merge_imports(
|
|
|
- super()._get_imports(), self._var_data.imports if self._var_data else {}
|
|
|
+ super()._get_imports(),
|
|
|
+ self._var_data.imports if self._var_data else {},
|
|
|
+ {"@emotion/react": [imports.ImportVar(tag="keyframes")]},
|
|
|
)
|
|
|
|
|
|
def get_event_triggers(self) -> Dict[str, Any]:
|
|
@@ -442,6 +444,26 @@ class AccordionRoot(AccordionComponent):
|
|
|
"on_value_change": lambda e0: [e0],
|
|
|
}
|
|
|
|
|
|
+ def _get_custom_code(self) -> str:
|
|
|
+ return """
|
|
|
+const slideDown = keyframes`
|
|
|
+from {
|
|
|
+ height: 0;
|
|
|
+}
|
|
|
+to {
|
|
|
+ height: var(--radix-accordion-content-height);
|
|
|
+}
|
|
|
+`
|
|
|
+const slideUp = keyframes`
|
|
|
+from {
|
|
|
+ height: var(--radix-accordion-content-height);
|
|
|
+}
|
|
|
+to {
|
|
|
+ height: 0;
|
|
|
+}
|
|
|
+`
|
|
|
+"""
|
|
|
+
|
|
|
|
|
|
class AccordionItem(AccordionComponent):
|
|
|
"""An accordion component."""
|
|
@@ -493,25 +515,23 @@ class AccordionItem(AccordionComponent):
|
|
|
# The item requires a value to toggle (use a random unique name if not provided).
|
|
|
value = props.pop("value", get_unique_variable_name())
|
|
|
|
|
|
+ if "AccordionItem" not in (
|
|
|
+ cls_name := props.pop("class_name", "AccordionItem")
|
|
|
+ ):
|
|
|
+ cls_name = f"{cls_name} AccordionItem"
|
|
|
+
|
|
|
if (header is not None) and (content is not None):
|
|
|
children = [
|
|
|
AccordionHeader.create(
|
|
|
AccordionTrigger.create(
|
|
|
header,
|
|
|
- Icon.create(
|
|
|
- tag="chevron_down",
|
|
|
- class_name="AccordionChevron",
|
|
|
- display="inline-block",
|
|
|
- ),
|
|
|
- class_name="AccordionTrigger",
|
|
|
+ AccordionIcon.create(),
|
|
|
),
|
|
|
),
|
|
|
- AccordionContent.create(content, class_name="AccordionContent"),
|
|
|
+ AccordionContent.create(content),
|
|
|
]
|
|
|
|
|
|
- return super().create(
|
|
|
- *children, value=value, **props, class_name="AccordionItem"
|
|
|
- )
|
|
|
+ return super().create(*children, value=value, **props, class_name=cls_name)
|
|
|
|
|
|
|
|
|
class AccordionHeader(AccordionComponent):
|
|
@@ -521,12 +541,26 @@ class AccordionHeader(AccordionComponent):
|
|
|
|
|
|
alias = "RadixAccordionHeader"
|
|
|
|
|
|
+ @classmethod
|
|
|
+ def create(cls, *children, **props) -> Component:
|
|
|
+ """Create the Accordion header component.
|
|
|
+
|
|
|
+ Args:
|
|
|
+ *children: The children of the component.
|
|
|
+ **props: The properties of the component.
|
|
|
+
|
|
|
+ Returns:
|
|
|
+ The Accordion header Component.
|
|
|
+ """
|
|
|
+ if "AccordionHeader" not in (
|
|
|
+ cls_name := props.pop("class_name", "AccordionHeader")
|
|
|
+ ):
|
|
|
+ cls_name = f"{cls_name} AccordionHeader"
|
|
|
+
|
|
|
+ return super().create(*children, class_name=cls_name, **props)
|
|
|
+
|
|
|
def _apply_theme(self, theme: Component):
|
|
|
- self.style = Style(
|
|
|
- {
|
|
|
- **self.style,
|
|
|
- }
|
|
|
- )
|
|
|
+ self.style = Style({**self.style})
|
|
|
|
|
|
|
|
|
class AccordionTrigger(AccordionComponent):
|
|
@@ -536,12 +570,48 @@ class AccordionTrigger(AccordionComponent):
|
|
|
|
|
|
alias = "RadixAccordionTrigger"
|
|
|
|
|
|
+ @classmethod
|
|
|
+ def create(cls, *children, **props) -> Component:
|
|
|
+ """Create the Accordion trigger component.
|
|
|
+
|
|
|
+ Args:
|
|
|
+ *children: The children of the component.
|
|
|
+ **props: The properties of the component.
|
|
|
+
|
|
|
+ Returns:
|
|
|
+ The Accordion trigger Component.
|
|
|
+ """
|
|
|
+ if "AccordionTrigger" not in (
|
|
|
+ cls_name := props.pop("class_name", "AccordionTrigger")
|
|
|
+ ):
|
|
|
+ cls_name = f"{cls_name} AccordionTrigger"
|
|
|
+
|
|
|
+ return super().create(*children, class_name=cls_name, **props)
|
|
|
+
|
|
|
def _apply_theme(self, theme: Component):
|
|
|
- self.style = Style(
|
|
|
- {
|
|
|
- **self.style,
|
|
|
- }
|
|
|
- )
|
|
|
+ self.style = Style({**self.style})
|
|
|
+
|
|
|
+
|
|
|
+class AccordionIcon(Icon):
|
|
|
+ """An accordion icon component."""
|
|
|
+
|
|
|
+ @classmethod
|
|
|
+ def create(cls, *children, **props) -> Component:
|
|
|
+ """Create the Accordion icon component.
|
|
|
+
|
|
|
+ Args:
|
|
|
+ *children: The children of the component.
|
|
|
+ **props: The properties of the component.
|
|
|
+
|
|
|
+ Returns:
|
|
|
+ The Accordion icon Component.
|
|
|
+ """
|
|
|
+ if "AccordionChevron" not in (
|
|
|
+ cls_name := props.pop("class_name", "AccordionChevron")
|
|
|
+ ):
|
|
|
+ cls_name = f"{cls_name} AccordionChevron"
|
|
|
+
|
|
|
+ return super().create(tag="chevron_down", class_name=cls_name, **props)
|
|
|
|
|
|
|
|
|
class AccordionContent(AccordionComponent):
|
|
@@ -551,38 +621,32 @@ class AccordionContent(AccordionComponent):
|
|
|
|
|
|
alias = "RadixAccordionContent"
|
|
|
|
|
|
- def _apply_theme(self, theme: Component):
|
|
|
- self.style = Style(
|
|
|
- {
|
|
|
- **self.style,
|
|
|
- }
|
|
|
- )
|
|
|
+ @classmethod
|
|
|
+ def create(cls, *children, **props) -> Component:
|
|
|
+ """Create the Accordion content component.
|
|
|
|
|
|
- def _get_imports(self):
|
|
|
- return {
|
|
|
- **super()._get_imports(),
|
|
|
- "@emotion/react": [imports.ImportVar(tag="keyframes")],
|
|
|
- }
|
|
|
+ Args:
|
|
|
+ *children: The children of the component.
|
|
|
+ **props: The properties of the component.
|
|
|
|
|
|
- def _get_custom_code(self) -> str:
|
|
|
- return """
|
|
|
-const slideDown = keyframes`
|
|
|
-from {
|
|
|
- height: 0;
|
|
|
-}
|
|
|
-to {
|
|
|
- height: var(--radix-accordion-content-height);
|
|
|
-}
|
|
|
-`
|
|
|
-const slideUp = keyframes`
|
|
|
-from {
|
|
|
- height: var(--radix-accordion-content-height);
|
|
|
-}
|
|
|
-to {
|
|
|
- height: 0;
|
|
|
-}
|
|
|
-`
|
|
|
-"""
|
|
|
+ Returns:
|
|
|
+ The Accordion content Component.
|
|
|
+ """
|
|
|
+ if "AccordionContent" not in (
|
|
|
+ cls_name := props.pop("class_name", "AccordionContent")
|
|
|
+ ):
|
|
|
+ cls_name = f"{cls_name} AccordionContent"
|
|
|
+
|
|
|
+ return super().create(*children, class_name=cls_name, **props)
|
|
|
+
|
|
|
+ def _apply_theme(self, theme: Component):
|
|
|
+ self.style = Style({**self.style})
|
|
|
+
|
|
|
+ # def _get_imports(self):
|
|
|
+ # return {
|
|
|
+ # **super()._get_imports(),
|
|
|
+ # "@emotion/react": [imports.ImportVar(tag="keyframes")],
|
|
|
+ # }
|
|
|
|
|
|
|
|
|
class Accordion(SimpleNamespace):
|
|
@@ -591,6 +655,7 @@ class Accordion(SimpleNamespace):
|
|
|
content = staticmethod(AccordionContent.create)
|
|
|
header = staticmethod(AccordionHeader.create)
|
|
|
item = staticmethod(AccordionItem.create)
|
|
|
+ icon = staticmethod(AccordionIcon.create)
|
|
|
root = staticmethod(AccordionRoot.create)
|
|
|
trigger = staticmethod(AccordionTrigger.create)
|
|
|
|