@@ -42,44 +42,38 @@ def create(cls, *children, **props) -> Component:
42
42
if children :
43
43
if len (children ) == 1 and isinstance (children [0 ], str ):
44
44
props ["tag" ] = children [0 ]
45
- children = []
46
45
else :
47
46
raise AttributeError (
48
47
f"Passing multiple children to Icon component is not allowed: remove positional arguments { children [1 :]} to fix"
49
48
)
50
49
if "tag" not in props :
51
50
raise AttributeError ("Missing 'tag' keyword-argument for Icon" )
52
51
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
56
56
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 )
64
60
65
61
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
68
64
):
69
65
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 ])} , ..."
71
67
"\n See full list at https://lucide.dev/icons."
72
68
)
73
69
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 ]
76
72
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"
80
74
props ["alias" ] = f"Lucide{ props ['tag' ]} "
81
75
props .setdefault ("color" , "var(--current-color)" )
82
- return super ().create (* children , * *props )
76
+ return super ().create (** props )
83
77
84
78
85
79
class DynamicIcon (LucideIconComponent ):
0 commit comments