Skip to content

Commit 58f614d

Browse files
adhami3310bhatia2akshit
authored andcommitted
print warning instead of error with invalid icon (reflex-dev#4959)
* print warning instead of error with invalid icon * dang it darglint * pyi * fix unit tests
1 parent 9db8220 commit 58f614d

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

reflex/components/lucide/icon.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Lucide Icon component."""
22

33
from reflex.components.component import Component
4-
from reflex.utils import format
4+
from reflex.utils import console, format
55
from reflex.utils.imports import ImportVar
66
from reflex.vars.base import LiteralVar, Var
77
from reflex.vars.sequence import LiteralStringVar, StringVar
@@ -33,7 +33,6 @@ def create(cls, *children, **props) -> Component:
3333
3434
Raises:
3535
AttributeError: The errors tied to bad usage of the Icon component.
36-
ValueError: If the icon tag is invalid.
3736
TypeError: If the icon name is not a string.
3837
3938
Returns:
@@ -73,15 +72,18 @@ def create(cls, *children, **props) -> Component:
7372
if isinstance(tag, str):
7473
icons_sorted = sorted(
7574
LUCIDE_ICON_LIST,
76-
key=lambda s: format.length_of_largest_common_substring(tag, s),
75+
key=lambda s, tag=tag: format.length_of_largest_common_substring(
76+
tag, s
77+
),
7778
reverse=True,
7879
)
7980
else:
8081
icons_sorted = LUCIDE_ICON_LIST
81-
raise ValueError(
82-
f"Invalid icon tag: {tag}. Please use one of the following: {', '.join(icons_sorted[0:25])}, ..."
83-
"\nSee full list at https://reflex.dev/docs/library/data-display/icon/#icons-list."
82+
console.warn(
83+
f"Invalid icon tag: {tag}. Please use one of the following: {', '.join(icons_sorted[0:10])}, ..."
84+
"\nSee full list at https://reflex.dev/docs/library/data-display/icon/#icons-list. Using 'circle-help' icon instead."
8485
)
86+
tag = "circle-help"
8587

8688
if tag in LUCIDE_ICON_MAPPING_OVERRIDE:
8789
props["tag"] = LUCIDE_ICON_MAPPING_OVERRIDE[tag]

reflex/components/lucide/icon.pyi

-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ class Icon(LucideIconComponent):
103103
104104
Raises:
105105
AttributeError: The errors tied to bad usage of the Icon component.
106-
ValueError: If the icon tag is invalid.
107106
TypeError: If the icon name is not a string.
108107
109108
Returns:

tests/units/components/lucide/test_icon.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ def test_icon_missing_tag():
2222

2323

2424
def test_icon_invalid_tag():
25-
with pytest.raises(ValueError):
26-
_ = Icon.create("invalid-tag")
25+
invalid = Icon.create("invalid-tag")
26+
assert invalid.tag == "CircleHelpIcon"
2727

2828

2929
def test_icon_multiple_children():

0 commit comments

Comments
 (0)