Skip to content

Commit 1e48090

Browse files
committed
Add lucide_htmx_init_script function to initialize Lucide icons after HTMX content swaps. Update switch component to improve cursor interaction with cursor-pointer class.
1 parent 4947a15 commit 1e48090

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/htpy_uikit/components/lucide.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from htpy import Renderable
22
from htpy import i as i_el
33
from htpy import script
4+
from markupsafe import Markup
45
from sourcetypes import js
56

67
from ._types_lucide import LucideName
@@ -46,3 +47,18 @@ def lucide_auto_init_script() -> Renderable:
4647
lucide.createIcons();
4748
"""
4849
return script()[code]
50+
51+
52+
def lucide_htmx_init_script() -> Renderable:
53+
"""Return a <script> tag that initializes Lucide icons after HTMX content swaps.
54+
55+
This listens for HTMX's 'htmx:afterSwap' event and re-initializes Lucide icons
56+
for any new content that was swapped in. Place this once, near the end of <body>
57+
or in your layout/template head.
58+
"""
59+
code: js = """
60+
document.addEventListener('htmx:afterSwap', function(evt) {
61+
lucide.createIcons();
62+
});
63+
"""
64+
return script()[Markup(code)]

src/htpy_uikit/components/switch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def switch(
4747
# Inline full tailwind classes from reference for switches.
4848
# Color-specific classes are appended based on `color`.
4949
base_switch_classes = (
50-
"input appearance-none focus-visible:border-ring focus-visible:ring-ring/50 "
50+
"input cursor-pointer appearance-none focus-visible:border-ring focus-visible:ring-ring/50 "
5151
"inline-flex h-[1.15rem] w-8 shrink-0 items-center rounded-full border "
5252
"border-border shadow-xs transition-all outline-none focus-visible:ring-[3px] "
5353
"disabled:cursor-not-allowed disabled:opacity-50 bg-input dark:bg-input/80 "

0 commit comments

Comments
 (0)