add other files

This commit is contained in:
Elijah 2024-10-16 13:45:45 +00:00
parent d0fd3bd9f2
commit 1294ffaa94
6 changed files with 46 additions and 29 deletions

View File

@ -165,16 +165,18 @@ class ConnectionToaster(Toaster):
class ConnectionBanner(Component): class ConnectionBanner(Component):
"""A connection banner component.""" """A connection banner component."""
@classmethod # The component to render when there's a server connection error.
def create(cls, comp: Optional[Component] = None) -> Component: comp: Var[Optional[Component]] = None
"""Create a connection banner component.
Args: @classmethod
comp: The component to render when there's a server connection error. def create(cls, **props) -> Component:
"""Create a connection banner component.
Returns: Returns:
The connection banner component. The connection banner component.
""" """
comp = props.pop("comp", None)
if not comp: if not comp:
comp = Flex.create( comp = Flex.create(
Text.create( Text.create(
@ -195,16 +197,18 @@ class ConnectionBanner(Component):
class ConnectionModal(Component): class ConnectionModal(Component):
"""A connection status modal window.""" """A connection status modal window."""
@classmethod # The component to render when there's a server connection error.
def create(cls, comp: Optional[Component] = None) -> Component: comp: Var[Optional[Component]] = None
"""Create a connection banner component.
Args: @classmethod
comp: The component to render when there's a server connection error. def create(cls, **props) -> Component:
"""Create a connection banner component.
Returns: Returns:
The connection banner component. The connection banner component.
""" """
comp = props.pop("comp", None)
if not comp: if not comp:
comp = Text.create(*default_connection_error()) comp = Text.create(*default_connection_error())
return cond( return cond(

View File

@ -193,6 +193,12 @@ class AccordionItem(AccordionComponent):
# When true, prevents the user from interacting with the item. # When true, prevents the user from interacting with the item.
disabled: Var[bool] disabled: Var[bool]
# The header of the accordion item.
header: Var[Optional[Component | Var]] = None
# The content of the accordion item.
content: Var[Optional[Component | Var]] = None
_valid_children: List[str] = [ _valid_children: List[str] = [
"AccordionHeader", "AccordionHeader",
"AccordionTrigger", "AccordionTrigger",
@ -205,21 +211,20 @@ class AccordionItem(AccordionComponent):
def create( def create(
cls, cls,
*children, *children,
header: Optional[Component | Var] = None,
content: Optional[Component | Var] = None,
**props, **props,
) -> Component: ) -> Component:
"""Create an accordion item. """Create an accordion item.
Args: Args:
*children: The list of children to use if header and content are not provided. *children: The list of children to use if header and content are not provided.
header: The header of the accordion item.
content: The content of the accordion item.
**props: Additional properties to apply to the accordion item. **props: Additional properties to apply to the accordion item.
Returns: Returns:
The accordion item. The accordion item.
""" """
header = props.pop("header", None)
content = props.pop("content", None)
# The item requires a value to toggle (use a random unique name if not provided). # The item requires a value to toggle (use a random unique name if not provided).
value = props.pop("value", get_uuid_string_var()) value = props.pop("value", get_uuid_string_var())

View File

@ -17,7 +17,7 @@ rx.text(
from __future__ import annotations from __future__ import annotations
from typing import Dict, List, Literal, get_args from typing import Dict, List, Literal, get_args, Optional
from reflex.components.component import BaseComponent from reflex.components.component import BaseComponent
from reflex.components.core.cond import Cond, color_mode_cond, cond from reflex.components.core.cond import Cond, color_mode_cond, cond
@ -96,23 +96,28 @@ def _set_static_default(props, position, prop, default):
class ColorModeIconButton(IconButton): class ColorModeIconButton(IconButton):
"""Icon Button for toggling light / dark mode via toggle_color_mode.""" """Icon Button for toggling light / dark mode via toggle_color_mode."""
# The position of the icon button. Follow document flow if None.
position: Var[Optional[LiteralPosition]] = None
# Allow picking the "system" value for the color mode.
allow_system: Var[bool] = False
@classmethod @classmethod
def create( def create(
cls, cls,
position: LiteralPosition | None = None,
allow_system: bool = False,
**props, **props,
): ):
"""Create a icon button component that calls toggle_color_mode on click. """Create a icon button component that calls toggle_color_mode on click.
Args: Args:
position: The position of the icon button. Follow document flow if None.
allow_system: Allow picking the "system" value for the color mode.
**props: The props to pass to the component. **props: The props to pass to the component.
Returns: Returns:
The button component. The button component.
""" """
position = props.pop("position", None)
allow_system = props.pop("allow_system", None)
# position is used to set nice defaults for positioning the icon button # position is used to set nice defaults for positioning the icon button
if isinstance(position, Var): if isinstance(position, Var):
_set_var_default(props, position, "position", "fixed", position) _set_var_default(props, position, "position", "fixed", position)

View File

@ -180,16 +180,17 @@ class HighLevelSelect(SelectRoot):
position: Var[Literal["item-aligned", "popper"]] position: Var[Literal["item-aligned", "popper"]]
@classmethod @classmethod
def create(cls, items: Union[List[str], Var[List[str]]], **props) -> Component: def create(cls, **props) -> Component:
"""Create a select component. """Create a select component.
Args: Args:
items: The items of the select.
**props: Additional properties to apply to the select component. **props: Additional properties to apply to the select component.
Returns: Returns:
The select component. The select component.
""" """
items = props.pop("items")
trigger_prop_list = [ trigger_prop_list = [
"placeholder", "placeholder",
"variant", "variant",

View File

@ -61,6 +61,9 @@ class Slider(RadixThemesComponent):
# The name of the slider. Submitted with its owning form as part of a name/value pair. # The name of the slider. Submitted with its owning form as part of a name/value pair.
name: Var[str] name: Var[str]
# The width of the slider.
width: Var[Optional[str]] = "100%"
# The minimum value of the slider. # The minimum value of the slider.
min: Var[Union[float, int]] min: Var[Union[float, int]]
@ -89,20 +92,19 @@ class Slider(RadixThemesComponent):
def create( def create(
cls, cls,
*children, *children,
width: Optional[str] = "100%",
**props, **props,
) -> Component: ) -> Component:
"""Create a Slider component. """Create a Slider component.
Args: Args:
*children: The children of the component. *children: The children of the component.
width: The width of the slider.
**props: The properties of the component. **props: The properties of the component.
Returns: Returns:
The component. The component.
""" """
default_value = props.pop("default_value", [50]) default_value = props.pop("default_value", [50])
width = props.pop("width", "100%")
if isinstance(default_value, Var): if isinstance(default_value, Var):
if issubclass(default_value._var_type, (int, float)): if issubclass(default_value._var_type, (int, float)):

View File

@ -12,20 +12,22 @@ from .flex import Flex, LiteralFlexDirection
class Stack(Flex): class Stack(Flex):
"""A stack component.""" """A stack component."""
# The spacing between each stack item.
spacing: LiteralSpacing = "3"
# The alignment of the stack items.
align: LiteralAlign = "start"
@classmethod @classmethod
def create( def create(
cls, cls,
*children, *children,
spacing: LiteralSpacing = "3",
align: LiteralAlign = "start",
**props, **props,
) -> Component: ) -> Component:
"""Create a new instance of the component. """Create a new instance of the component.
Args: Args:
*children: The children of the stack. *children: The children of the stack.
spacing: The spacing between each stack item.
align: The alignment of the stack items.
**props: The properties of the stack. **props: The properties of the stack.
Returns: Returns:
@ -39,8 +41,6 @@ class Stack(Flex):
return super().create( return super().create(
*children, *children,
spacing=spacing,
align=align,
**props, **props,
) )