IconButton
A Shadcn button that shows only an icon.
Example:
shad.IconButton(
icon=shad.LucideIcons.ROCKET,
on_click=lambda e: print("launched"),
)

Inherits: LayoutControl
Properties
autofocus- Whether this button should be focused on initial display.bgcolor- The background color.color- The icon color.hover_bgcolor- The background color while the pointer hovers over this button.hover_color- The icon color while the pointer hovers over this button.icon- The icon to show.icon_size- The size oficon.variant- The visual variant of this button.
Events
on_blur- Called when this button loses focus.on_click- Called when this button is clicked.on_focus- Called when this button receives focus.on_hover- Called when the pointer enters or exits this button.on_long_press- Called when this button is long-pressed.
Methods
focus- Requests focus for this button.
Example
Shadcn IconButton
import flet_shadcn_ui as shad
import flet as ft
def main(page: ft.Page):
page.title = "Shadcn IconButton"
def handle_click(e: ft.Event[shad.IconButton]):
message.value = f"Clicked: {e.control.data}"
message = ft.Text("Click a button")
page.add(
ft.SafeArea(
content=ft.Column(
controls=[
ft.Row(
controls=[
shad.IconButton(
icon=shad.LucideIcons.ROCKET,
data="Primary",
on_click=handle_click,
),
shad.IconButton(
icon=shad.LucideIcons.TRASH_2,
variant=shad.ButtonVariant.DESTRUCTIVE,
data="Destructive",
on_click=handle_click,
),
shad.IconButton(
icon=shad.LucideIcons.SETTINGS,
variant=shad.ButtonVariant.OUTLINE,
data="Outline",
on_click=handle_click,
),
shad.IconButton(
icon=shad.LucideIcons.COPY,
variant=shad.ButtonVariant.SECONDARY,
data="Secondary",
on_click=handle_click,
),
shad.IconButton(
icon=shad.LucideIcons.HEART,
variant=shad.ButtonVariant.GHOST,
data="Ghost",
on_click=handle_click,
),
],
),
message,
],
)
)
)
if __name__ == "__main__":
ft.run(main)

Properties
autofocusclass-attributeinstance-attribute
autofocus: bool = FalseWhether this button should be focused on initial display.
bgcolorclass-attributeinstance-attribute
bgcolor: ColorValue | None = NoneThe background color.
If None, the color is taken from variant.
colorclass-attributeinstance-attribute
color: ColorValue | None = NoneThe icon color.
If None, the color is taken from variant.
hover_bgcolorclass-attributeinstance-attribute
hover_bgcolor: ColorValue | None = NoneThe background color while the pointer hovers over this button.
hover_colorclass-attributeinstance-attribute
hover_color: ColorValue | None = NoneThe icon color while the pointer hovers over this button.
icon_sizeclass-attributeinstance-attribute
icon_size: Number | None = NoneThe size of icon.
If None, defaults to 16.
variantclass-attributeinstance-attribute
variant: ButtonVariant = ButtonVariant.PRIMARYThe visual variant of this button.
Events
on_blurclass-attributeinstance-attribute
on_blur: ControlEventHandler[IconButton] | None = NoneCalled when this button loses focus.
on_clickclass-attributeinstance-attribute
on_click: ControlEventHandler[IconButton] | None = NoneCalled when this button is clicked.
on_focusclass-attributeinstance-attribute
on_focus: ControlEventHandler[IconButton] | None = NoneCalled when this button receives focus.
on_hoverclass-attributeinstance-attribute
on_hover: ControlEventHandler[IconButton] | None = NoneCalled when the pointer enters or exits this button.
The data property of the event handler argument is
True when the pointer entered, and False when it exited.
on_long_pressclass-attributeinstance-attribute
on_long_press: ControlEventHandler[IconButton] | None = (
None
)Called when this button is long-pressed.