Skip to content

Commit

Permalink
[ENG-4351] Add mapping for lucide icons (reflex-dev#4622)
Browse files Browse the repository at this point in the history
* [ENG-4351] Add mapping for lucide icons

For icon names that don't auto-translate to the correct lucide tag name,
provide manual override.

Fix reflex-dev#4621

* account for new mapping in unit tests
  • Loading branch information
masenf authored Jan 10, 2025
1 parent 427d7c5 commit 1e7a37b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
14 changes: 13 additions & 1 deletion reflex/components/lucide/icon.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ def create(cls, *children, **props) -> Component:
"\nSee full list at https://lucide.dev/icons."
)

props["tag"] = format.to_title_case(format.to_snake_case(props["tag"])) + "Icon"
if props["tag"] in LUCIDE_ICON_MAPPING_OVERRIDE:
props["tag"] = LUCIDE_ICON_MAPPING_OVERRIDE[props["tag"]]
else:
props["tag"] = (
format.to_title_case(format.to_snake_case(props["tag"])) + "Icon"
)
props["alias"] = f"Lucide{props['tag']}"
props.setdefault("color", "var(--current-color)")
return super().create(*children, **props)
Expand Down Expand Up @@ -1634,3 +1639,10 @@ def create(cls, *children, **props) -> Component:
"zoom_in",
"zoom_out",
]

# The default transformation of some icon names doesn't match how the
# icons are exported from Lucide. Manual overrides can go here.
LUCIDE_ICON_MAPPING_OVERRIDE = {
"grid_2x_2_check": "Grid2x2Check",
"grid_2x_2_x": "Grid2x2X",
}
4 changes: 4 additions & 0 deletions reflex/components/lucide/icon.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1682,3 +1682,7 @@ LUCIDE_ICON_LIST = [
"zoom_in",
"zoom_out",
]
LUCIDE_ICON_MAPPING_OVERRIDE = {
"grid_2x_2_check": "Grid2x2Check",
"grid_2x_2_x": "Grid2x2X",
}
10 changes: 8 additions & 2 deletions tests/units/components/lucide/test_icon.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import pytest

from reflex.components.lucide.icon import LUCIDE_ICON_LIST, Icon
from reflex.components.lucide.icon import (
LUCIDE_ICON_LIST,
LUCIDE_ICON_MAPPING_OVERRIDE,
Icon,
)
from reflex.utils import format


@pytest.mark.parametrize("tag", LUCIDE_ICON_LIST)
def test_icon(tag):
icon = Icon.create(tag)
assert icon.alias == f"Lucide{format.to_title_case(tag)}Icon"
assert icon.alias == "Lucide" + LUCIDE_ICON_MAPPING_OVERRIDE.get(
tag, f"{format.to_title_case(tag)}Icon"
)


def test_icon_missing_tag():
Expand Down

0 comments on commit 1e7a37b

Please sign in to comment.