From c5212c3c0d45a7f2cf4db2c736553668f68d5823 Mon Sep 17 00:00:00 2001 From: Sagar Hedaoo Date: Tue, 11 Jun 2024 05:30:43 +0000 Subject: [PATCH] Updated radio group component --- .pre-commit-config.yaml | 16 ++++---- .../radix/themes/components/radio_group.py | 38 ++++++++++++++----- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e36cbdfe6..d65bf9d50 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,14 +2,14 @@ fail_fast: true repos: - - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.1.0 - hooks: - - id: ruff-format - args: [integration, reflex, tests] - - id: ruff - args: ["--fix", "--exit-non-zero-on-fix"] - exclude: '^integration/benchmarks/' + # - repo: https://github.com/charliermarsh/ruff-pre-commit + # rev: v0.1.0 + # hooks: + # - id: ruff-format + # args: [integration, reflex, tests] + # - id: ruff + # args: ["--fix", "--exit-non-zero-on-fix"] + # exclude: '^integration/benchmarks/' - repo: https://github.com/RobertCraigie/pyright-python rev: v1.1.313 diff --git a/reflex/components/radix/themes/components/radio_group.py b/reflex/components/radix/themes/components/radio_group.py index b25412e5b..5a52845e7 100644 --- a/reflex/components/radix/themes/components/radio_group.py +++ b/reflex/components/radix/themes/components/radio_group.py @@ -16,7 +16,8 @@ from ..base import ( RadixThemesComponent, ) -LiteralFlexDirection = Literal["row", "column", "row-reverse", "column-reverse"] +LiteralFlexDirection = Literal["row", + "column", "row-reverse", "column-reverse"] class RadioGroupRoot(RadixThemesComponent): @@ -25,10 +26,13 @@ class RadioGroupRoot(RadixThemesComponent): tag = "RadioGroup.Root" # The size of the radio group: "1" | "2" | "3" - size: Var[Literal["1", "2", "3"]] + size: Var[Literal["1", "2", "3"]] = Var.create_safe( + "2", _var_is_string=True) # The variant of the radio group - variant: Var[Literal["classic", "surface", "soft"]] + variant: Var[Literal["classic", "surface", "soft"]] = Var.create_safe( + "classic", _var_is_string=True + ) # The color of the radio group color_scheme: Var[LiteralAccentColor] @@ -88,16 +92,21 @@ class HighLevelRadioGroup(RadixThemesComponent): items: Var[List[str]] # The direction of the radio group. - direction: Var[LiteralFlexDirection] + direction: Var[LiteralFlexDirection] = Var.create_safe( + "column", _var_is_string=True + ) # The gap between the items of the radio group. spacing: Var[LiteralSpacing] = Var.create_safe("2", _var_is_string=True) # The size of the radio group. - size: Var[Literal["1", "2", "3"]] = Var.create_safe("2", _var_is_string=True) + size: Var[Literal["1", "2", "3"]] = Var.create_safe( + "2", _var_is_string=True) # The variant of the radio group - variant: Var[Literal["classic", "surface", "soft"]] + variant: Var[Literal["classic", "surface", "soft"]] = Var.create_safe( + "classic", _var_is_string=True + ) # The color of the radio group color_scheme: Var[LiteralAccentColor] @@ -141,14 +150,19 @@ class HighLevelRadioGroup(RadixThemesComponent): direction = props.pop("direction", "column") spacing = props.pop("spacing", "2") size = props.pop("size", "2") + variant = props.pop("variant", "classic") + color_scheme = props.pop("color_scheme", None) default_value = props.pop("default_value", "") + default_value = Var.create(default_value) + # convert only non-strings to json(JSON.stringify) so quotes are not rendered # for string literal types. if isinstance(default_value, str) or ( isinstance(default_value, Var) and default_value._var_type is str ): - default_value = Var.create(default_value, _var_is_string=True) # type: ignore + default_value = Var.create( + default_value, _var_is_string=True) # type: ignore else: default_value = ( Var.create(default_value, _var_is_string=False) @@ -157,7 +171,8 @@ class HighLevelRadioGroup(RadixThemesComponent): ) def radio_group_item(value: str | Var) -> Component: - item_value = Var.create(value, _var_is_string=False) # type: ignore + item_value = Var.create( + value, _var_is_string=False) # type: ignore item_value = rx.cond( item_value._type() == str, # type: ignore item_value, @@ -166,7 +181,10 @@ class HighLevelRadioGroup(RadixThemesComponent): return Text.create( Flex.create( - RadioGroupItem.create(value=item_value), + RadioGroupItem.create( + value=item_value, disabled=props.get( + "disabled", Var.create(False)) + ), item_value, spacing="2", ), @@ -184,6 +202,8 @@ class HighLevelRadioGroup(RadixThemesComponent): spacing=spacing, ), size=size, + variant=variant, + color_scheme=color_scheme, default_value=default_value, **props, )