Skip to content

Commit f7daa27

Browse files
committed
clean up code
1 parent 864bcf4 commit f7daa27

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

reflex/components/lucide/icon.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,44 +42,38 @@ def create(cls, *children, **props) -> Component:
4242
if children:
4343
if len(children) == 1 and isinstance(children[0], str):
4444
props["tag"] = children[0]
45-
children = []
4645
else:
4746
raise AttributeError(
4847
f"Passing multiple children to Icon component is not allowed: remove positional arguments {children[1:]} to fix"
4948
)
5049
if "tag" not in props:
5150
raise AttributeError("Missing 'tag' keyword-argument for Icon")
5251

53-
if isinstance(props["tag"], LiteralVar):
54-
if isinstance(props["tag"], LiteralStringVar):
55-
props["tag"] = props["tag"]._var_value
52+
tag: str | Var | LiteralVar = props.pop("tag")
53+
if isinstance(tag, LiteralVar):
54+
if isinstance(tag, LiteralStringVar):
55+
tag = tag._var_value
5656
else:
57-
raise TypeError("Icon name must be a string")
58-
59-
if isinstance(props["tag"], Var):
60-
icon_name: Var = props.pop("tag")
61-
if icon_name._var_type is not str:
62-
raise TypeError("Icon name must be a string")
63-
return DynamicIcon.create(name=icon_name, **props)
57+
raise TypeError(f"Icon name must be a string, got {type(tag)}")
58+
elif isinstance(tag, Var):
59+
return DynamicIcon.create(name=tag, **props)
6460

6561
if (
66-
not isinstance(props["tag"], str)
67-
or format.to_snake_case(props["tag"]) not in LUCIDE_ICON_LIST
62+
not isinstance(tag, str)
63+
or format.to_snake_case(tag) not in LUCIDE_ICON_LIST
6864
):
6965
raise ValueError(
70-
f"Invalid icon tag: {props['tag']}. Please use one of the following: {', '.join(LUCIDE_ICON_LIST[0:25])}, ..."
66+
f"Invalid icon tag: {tag}. Please use one of the following: {', '.join(LUCIDE_ICON_LIST[0:25])}, ..."
7167
"\nSee full list at https://lucide.dev/icons."
7268
)
7369

74-
if props["tag"] in LUCIDE_ICON_MAPPING_OVERRIDE:
75-
props["tag"] = LUCIDE_ICON_MAPPING_OVERRIDE[props["tag"]]
70+
if tag in LUCIDE_ICON_MAPPING_OVERRIDE:
71+
props["tag"] = LUCIDE_ICON_MAPPING_OVERRIDE[tag]
7672
else:
77-
props["tag"] = (
78-
format.to_title_case(format.to_snake_case(props["tag"])) + "Icon"
79-
)
73+
props["tag"] = format.to_title_case(format.to_snake_case(tag)) + "Icon"
8074
props["alias"] = f"Lucide{props['tag']}"
8175
props.setdefault("color", "var(--current-color)")
82-
return super().create(*children, **props)
76+
return super().create(**props)
8377

8478

8579
class DynamicIcon(LucideIconComponent):

0 commit comments

Comments
 (0)