clean up code
This commit is contained in:
parent
864bcf4274
commit
f7daa27cd6
@ -42,7 +42,6 @@ class Icon(LucideIconComponent):
|
|||||||
if children:
|
if children:
|
||||||
if len(children) == 1 and isinstance(children[0], str):
|
if len(children) == 1 and isinstance(children[0], str):
|
||||||
props["tag"] = children[0]
|
props["tag"] = children[0]
|
||||||
children = []
|
|
||||||
else:
|
else:
|
||||||
raise AttributeError(
|
raise AttributeError(
|
||||||
f"Passing multiple children to Icon component is not allowed: remove positional arguments {children[1:]} to fix"
|
f"Passing multiple children to Icon component is not allowed: remove positional arguments {children[1:]} to fix"
|
||||||
@ -50,36 +49,31 @@ class Icon(LucideIconComponent):
|
|||||||
if "tag" not in props:
|
if "tag" not in props:
|
||||||
raise AttributeError("Missing 'tag' keyword-argument for Icon")
|
raise AttributeError("Missing 'tag' keyword-argument for Icon")
|
||||||
|
|
||||||
if isinstance(props["tag"], LiteralVar):
|
tag: str | Var | LiteralVar = props.pop("tag")
|
||||||
if isinstance(props["tag"], LiteralStringVar):
|
if isinstance(tag, LiteralVar):
|
||||||
props["tag"] = props["tag"]._var_value
|
if isinstance(tag, LiteralStringVar):
|
||||||
|
tag = tag._var_value
|
||||||
else:
|
else:
|
||||||
raise TypeError("Icon name must be a string")
|
raise TypeError(f"Icon name must be a string, got {type(tag)}")
|
||||||
|
elif isinstance(tag, Var):
|
||||||
if isinstance(props["tag"], Var):
|
return DynamicIcon.create(name=tag, **props)
|
||||||
icon_name: Var = props.pop("tag")
|
|
||||||
if icon_name._var_type is not str:
|
|
||||||
raise TypeError("Icon name must be a string")
|
|
||||||
return DynamicIcon.create(name=icon_name, **props)
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
not isinstance(props["tag"], str)
|
not isinstance(tag, str)
|
||||||
or format.to_snake_case(props["tag"]) not in LUCIDE_ICON_LIST
|
or format.to_snake_case(tag) not in LUCIDE_ICON_LIST
|
||||||
):
|
):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"Invalid icon tag: {props['tag']}. Please use one of the following: {', '.join(LUCIDE_ICON_LIST[0:25])}, ..."
|
f"Invalid icon tag: {tag}. Please use one of the following: {', '.join(LUCIDE_ICON_LIST[0:25])}, ..."
|
||||||
"\nSee full list at https://lucide.dev/icons."
|
"\nSee full list at https://lucide.dev/icons."
|
||||||
)
|
)
|
||||||
|
|
||||||
if props["tag"] in LUCIDE_ICON_MAPPING_OVERRIDE:
|
if tag in LUCIDE_ICON_MAPPING_OVERRIDE:
|
||||||
props["tag"] = LUCIDE_ICON_MAPPING_OVERRIDE[props["tag"]]
|
props["tag"] = LUCIDE_ICON_MAPPING_OVERRIDE[tag]
|
||||||
else:
|
else:
|
||||||
props["tag"] = (
|
props["tag"] = format.to_title_case(format.to_snake_case(tag)) + "Icon"
|
||||||
format.to_title_case(format.to_snake_case(props["tag"])) + "Icon"
|
|
||||||
)
|
|
||||||
props["alias"] = f"Lucide{props['tag']}"
|
props["alias"] = f"Lucide{props['tag']}"
|
||||||
props.setdefault("color", "var(--current-color)")
|
props.setdefault("color", "var(--current-color)")
|
||||||
return super().create(*children, **props)
|
return super().create(**props)
|
||||||
|
|
||||||
|
|
||||||
class DynamicIcon(LucideIconComponent):
|
class DynamicIcon(LucideIconComponent):
|
||||||
|
Loading…
Reference in New Issue
Block a user