optionalize some Component props

This commit is contained in:
Benedikt Bartscher 2024-02-29 18:16:17 +01:00
parent 6d3809efcb
commit 1c89f012b6
No known key found for this signature in database
4 changed files with 46 additions and 36 deletions

View File

@ -1,7 +1,7 @@
"""A bare component.""" """A bare component."""
from __future__ import annotations from __future__ import annotations
from typing import Any, Iterator from typing import Any, Iterator, Optional
from reflex.components.component import Component from reflex.components.component import Component
from reflex.components.tags import Tag from reflex.components.tags import Tag
@ -12,7 +12,7 @@ from reflex.vars import Var
class Bare(Component): class Bare(Component):
"""A component with no tag.""" """A component with no tag."""
contents: Var[str] contents: Optional[Var[str]] = None
@classmethod @classmethod
def create(cls, contents: Any) -> Component: def create(cls, contents: Any) -> Component:

View File

@ -1,5 +1,4 @@
"""Element classes. This is an auto-generated file. Do not edit. See ../generate.py.""" from typing import Union, Optional
from typing import Union
from reflex.components.el.element import Element from reflex.components.el.element import Element
from reflex.vars import Var as Var from reflex.vars import Var as Var
@ -9,49 +8,49 @@ class BaseHTML(Element):
"""Base class for common attributes.""" """Base class for common attributes."""
# Provides a hint for generating a keyboard shortcut for the current element. # Provides a hint for generating a keyboard shortcut for the current element.
access_key: Var[Union[str, int, bool]] access_key: Optional[Var[Union[str, int, bool]]] = None
# Controls whether and how text input is automatically capitalized as it is entered/edited by the user. # Controls whether and how text input is automatically capitalized as it is entered/edited by the user.
auto_capitalize: Var[Union[str, int, bool]] auto_capitalize: Optional[Var[Union[str, int, bool]]] = None
# Indicates whether the element's content is editable. # Indicates whether the element's content is editable.
content_editable: Var[Union[str, int, bool]] content_editable: Optional[Var[Union[str, int, bool]]] = None
# Defines the ID of a <menu> element which will serve as the element's context menu. # Defines the ID of a <menu> element which will serve as the element's context menu.
context_menu: Var[Union[str, int, bool]] context_menu: Optional[Var[Union[str, int, bool]]] = None
# Defines the text direction. Allowed values are ltr (Left-To-Right) or rtl (Right-To-Left) # Defines the text direction. Allowed values are ltr (Left-To-Right) or rtl (Right-To-Left)
dir: Var[Union[str, int, bool]] dir: Optional[Var[Union[str, int, bool]]] = None
# Defines whether the element can be dragged. # Defines whether the element can be dragged.
draggable: Var[Union[str, int, bool]] draggable: Optional[Var[Union[str, int, bool]]] = None
# Hints what media types the media element is able to play. # Hints what media types the media element is able to play.
enter_key_hint: Var[Union[str, int, bool]] enter_key_hint: Optional[Var[Union[str, int, bool]]] = None
# Defines whether the element is hidden. # Defines whether the element is hidden.
hidden: Var[Union[str, int, bool]] hidden: Optional[Var[Union[str, int, bool]]] = None
# Defines the type of the element. # Defines the type of the element.
input_mode: Var[Union[str, int, bool]] input_mode: Optional[Var[Union[str, int, bool]]] = None
# Defines the name of the element for metadata purposes. # Defines the name of the element for metadata purposes.
item_prop: Var[Union[str, int, bool]] item_prop: Optional[Var[Union[str, int, bool]]] = None
# Defines the language used in the element. # Defines the language used in the element.
lang: Var[Union[str, int, bool]] lang: Optional[Var[Union[str, int, bool]]] = None
# Defines the role of the element. # Defines the role of the element.
role: Var[Union[str, int, bool]] role: Optional[Var[Union[str, int, bool]]] = None
# Assigns a slot in a shadow DOM shadow tree to an element. # Assigns a slot in a shadow DOM shadow tree to an element.
slot: Var[Union[str, int, bool]] slot: Optional[Var[Union[str, int, bool]]] = None
# Defines whether the element may be checked for spelling errors. # Defines whether the element may be checked for spelling errors.
spell_check: Var[Union[str, int, bool]] spell_check: Optional[Var[Union[str, int, bool]]] = None
# Defines the position of the current element in the tabbing order. # Defines the position of the current element in the tabbing order.
tab_index: Var[Union[str, int, bool]] tab_index: Optional[Var[Union[str, int, bool]]] = None
# Defines a tooltip for the element. # Defines a tooltip for the element.
title: Var[Union[str, int, bool]] title: Optional[Var[Union[str, int, bool]]] = None

View File

@ -2,7 +2,7 @@
from __future__ import annotations from __future__ import annotations
from typing import Any, Dict, Literal from typing import Any, Dict, Literal, Optional, Union
from reflex.components import Component from reflex.components import Component
from reflex.components.tags import Tag from reflex.components.tags import Tag
@ -101,7 +101,13 @@ class RadixThemesComponent(Component):
""" """
component = super().create(*children, **props) component = super().create(*children, **props)
if component.library is None: if component.library is None:
<<<<<<< HEAD
component.library = RadixThemesComponent.model_fields["library"].default component.library = RadixThemesComponent.model_fields["library"].default
=======
component.library = RadixThemesComponent.model_fields[
"library"
].default
>>>>>>> f7035d9b (optionalize some Component props)
component.alias = "RadixThemes" + ( component.alias = "RadixThemes" + (
component.tag or component.__class__.__name__ component.tag or component.__class__.__name__
) )
@ -127,25 +133,25 @@ class Theme(RadixThemesComponent):
tag = "Theme" tag = "Theme"
# Whether to apply the themes background color to the theme node. Defaults to True. # Whether to apply the themes background color to the theme node. Defaults to True.
has_background: Var[bool] has_background: Optional[Var[bool]] = None
# Override light or dark mode theme: "inherit" | "light" | "dark". Defaults to "inherit". # Override light or dark mode theme: "inherit" | "light" | "dark". Defaults to "inherit".
appearance: Var[LiteralAppearance] appearance: Optional[Var[LiteralAppearance]] = None
# The color used for default buttons, typography, backgrounds, etc # The color used for default buttons, typography, backgrounds, etc
accent_color: Var[LiteralAccentColor] accent_color: Optional[Var[LiteralAccentColor]] = None
# The shade of gray, defaults to "auto". # The shade of gray, defaults to "auto".
gray_color: Var[LiteralGrayColor] gray_color: Optional[Var[LiteralGrayColor]] = None
# Whether panel backgrounds are translucent: "solid" | "translucent" (default) # Whether panel backgrounds are translucent: "solid" | "translucent" (default)
panel_background: Var[LiteralPanelBackground] panel_background: Optional[Var[LiteralPanelBackground]] = None
# Element border radius: "none" | "small" | "medium" | "large" | "full". Defaults to "medium". # Element border radius: "none" | "small" | "medium" | "large" | "full". Defaults to "medium".
radius: Var[LiteralRadius] radius: Optional[Var[LiteralRadius]] = None
# Scale of all theme items: "90%" | "95%" | "100%" | "105%" | "110%". Defaults to "100%" # Scale of all theme items: "90%" | "95%" | "100%" | "105%" | "110%". Defaults to "100%"
scaling: Var[LiteralScaling] scaling: Optional[Var[LiteralScaling]] = None
@classmethod @classmethod
def create( def create(
@ -153,6 +159,7 @@ class Theme(RadixThemesComponent):
*children, *children,
color_mode: LiteralAppearance | None = None, color_mode: LiteralAppearance | None = None,
theme_panel: bool = False, theme_panel: bool = False,
accent_color: Union[LiteralAccentColor, Var[LiteralAccentColor]] | None = None,
**props, **props,
) -> Component: ) -> Component:
"""Create a new Radix Theme specification. """Create a new Radix Theme specification.
@ -170,6 +177,9 @@ class Theme(RadixThemesComponent):
props["appearance"] = color_mode props["appearance"] = color_mode
if theme_panel: if theme_panel:
children = [ThemePanel.create(), *children] children = [ThemePanel.create(), *children]
if not isinstance(accent_color, Var):
accent_color = Var.create(accent_color)
props["accent_color"] = accent_color
return super().create(*children, **props) return super().create(*children, **props)
def _get_imports(self) -> imports.ImportDict: def _get_imports(self) -> imports.ImportDict:

View File

@ -6,6 +6,7 @@ from __future__ import annotations
from reflex import el from reflex import el
from reflex.vars import Var from reflex.vars import Var
from typing import Optional
from ..base import ( from ..base import (
LiteralAccentColor, LiteralAccentColor,
@ -25,25 +26,25 @@ class Heading(el.H1, RadixThemesComponent):
tag = "Heading" tag = "Heading"
# Change the default rendered element for the one passed as a child, merging their props and behavior. # Change the default rendered element for the one passed as a child, merging their props and behavior.
as_child: Var[bool] as_child: Optional[Var[bool]] = None
# Change the default rendered element into a semantically appropriate alternative (cannot be used with asChild) # Change the default rendered element into a semantically appropriate alternative (cannot be used with asChild)
as_: Var[str] as_: Optional[Var[str]] = None
# Text size: "1" - "9" # Text size: "1" - "9"
size: Var[LiteralTextSize] size: Optional[Var[LiteralTextSize]] = None
# Thickness of text: "light" | "regular" | "medium" | "bold" # Thickness of text: "light" | "regular" | "medium" | "bold"
weight: Var[LiteralTextWeight] weight: Optional[Var[LiteralTextWeight]] = None
# Alignment of text in element: "left" | "center" | "right" # Alignment of text in element: "left" | "center" | "right"
align: Var[LiteralTextAlign] align: Optional[Var[LiteralTextAlign]] = None
# Removes the leading trim space: "normal" | "start" | "end" | "both" # Removes the leading trim space: "normal" | "start" | "end" | "both"
trim: Var[LiteralTextTrim] trim: Optional[Var[LiteralTextTrim]] = None
# Overrides the accent color inherited from the Theme. # Overrides the accent color inherited from the Theme.
color_scheme: Var[LiteralAccentColor] color_scheme: Optional[Var[LiteralAccentColor]] = None
# Whether to render the text with higher contrast color # Whether to render the text with higher contrast color
high_contrast: Var[bool] high_contrast: Optional[Var[bool]] = None