Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions reflex/components/lucide/icon.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def create(cls, *children, **props) -> Component:
if "tag" not in props:
raise AttributeError("Missing 'tag' keyword-argument for Icon")

tag: str | Var | LiteralVar = props.pop("tag")
tag: str | Var | LiteralVar = Var.create(props.pop("tag"))
if isinstance(tag, LiteralVar):
if isinstance(tag, LiteralStringVar):
tag = tag._var_value
Expand All @@ -70,9 +70,17 @@ def create(cls, *children, **props) -> Component:
not isinstance(tag, str)
or format.to_snake_case(tag) not in LUCIDE_ICON_LIST
):
if isinstance(tag, str):
icons_sorted = sorted(
LUCIDE_ICON_LIST,
key=lambda s: format.length_of_largest_common_substring(tag, s),
reverse=True,
)
else:
icons_sorted = LUCIDE_ICON_LIST
raise ValueError(
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."
f"Invalid icon tag: {tag}. Please use one of the following: {', '.join(icons_sorted[0:25])}, ..."
"\nSee full list at https://reflex.dev/docs/library/data-display/icon/#icons-list."
)

if tag in LUCIDE_ICON_MAPPING_OVERRIDE:
Expand Down
30 changes: 30 additions & 0 deletions reflex/utils/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,36 @@
}


def length_of_largest_common_substring(str1: str, str2: str) -> int:
"""Find the length of the largest common substring between two strings.

Args:
str1: The first string.
str2: The second string.

Returns:
The length of the largest common substring.
"""
if not str1 or not str2:
return 0

# Create a matrix of size (len(str1) + 1) x (len(str2) + 1)
dp = [[0] * (len(str2) + 1) for _ in range(len(str1) + 1)]

# Variables to keep track of maximum length and ending position
max_length = 0

# Fill the dp matrix
for i in range(1, len(str1) + 1):
for j in range(1, len(str2) + 1):
if str1[i - 1] == str2[j - 1]:
dp[i][j] = dp[i - 1][j - 1] + 1
if dp[i][j] > max_length:
max_length = dp[i][j]

return max_length


def get_close_char(open: str, close: str | None = None) -> str:
"""Check if the given character is a valid brace.

Expand Down