gpui-component/docs/docs/components
grubby d251a9b08b
icon: Rework icons to make use of the IconNamed trait (#1640)
This makes use of the `IconNamed` trait and a blanked implementation to
convert anything that implements this to an `Icon`.

This allows for easily defined custom versions of `IconName`, while
minimally changing existing code (essentially only if you previously
made use of the `.path()` method on the `IconName` enum; this now
requires an import of the `IconNamed` trait).

# Example
```rust
use gpui_component::IconNamed;

pub enum IconName {
    Encounters,
    Monsters,
    Spells,
}

impl IconNamed for IconName {
    fn path(self) -> gpui::SharedString {
        match self {
            IconName::Encounters => "icons/encounters.svg",
            IconName::Monsters => "icons/monsters.svg",
            IconName::Spells => "icons/spells.svg",
        }
        .into()
    }
}

// this allows for the following interactions (works with anything that has the `.icon(icon)` method
Button::new("my-button").icon(IconName::Spells);
Icon::new(IconName::Monsters); 
```

If you want to directly "render" a custom `IconName` you must implement
the `RenderOnce` trait and derive `IntoElement` on the `IconName`.

```rust
use gpui::{IntoElement, RenderOnce};
use gpui_component::IconNamed;

#[derive(IntoElement)]
pub enum IconName {
    // The same as before
}

impl IconNamed for IconName {
    // The same as before
}

impl RenderOnce for IconName {
    fn render(self, _: &mut gpui::Window, _: &mut gpui::App) -> impl gpui::IntoElement {
        gpui_component::Icon::empty().path(self.path())
    }
}

// this allows for the following interaction
div()
    .child(IconName::Monsters)
```

Overall I think is an improvement to the existing way to do custom
`IconName` implementations.

I am unsure if this change should also be reflected in the documentation
on the section with "Icons & Assets", though I personally think it would
make sense to highlight this way to do custom versions of `IconName` as
it is considerably less involved than the current approach.

Closes #1627.

---------

Co-authored-by: Jason Lee <huacnlee@gmail.com>
2025-11-20 02:30:08 +00:00
..
accordion.md chore: Standardize the overall API and improve docs. (#1516) 2025-11-05 19:10:30 +08:00
alert.md docs: Improve docs add more details. (#1447) 2025-10-29 02:41:28 +00:00
avatar.md docs: Improve docs add more details. (#1447) 2025-10-29 02:41:28 +00:00
badge.md docs: Improve docs add more details. (#1447) 2025-10-29 02:41:28 +00:00
button.md button: Add dropdown_caret option to show a caret icon to end of button. (#1637) 2025-11-18 16:41:16 +08:00
calendar.md docs: Improve docs add more details. (#1447) 2025-10-29 02:41:28 +00:00
chart.md docs: Update chart (#1446) 2025-10-28 14:46:13 +08:00
checkbox.md chore: Standardize the overall API and improve docs. (#1516) 2025-11-05 19:10:30 +08:00
clipboard.md clipboard: Removed content method from Clipboard. (#1520) 2025-11-05 07:17:58 +00:00
collapsible.md collapsible: Add Collapsible. (#1525) 2025-11-06 10:57:18 +08:00
color-picker.md chore: Standardize the overall API and improve docs. (#1516) 2025-11-05 19:10:30 +08:00
date-picker.md input, select, date_picker: Refactor cleanable to have argument and default to false. (#1506) 2025-11-05 09:33:31 +08:00
description-list.md description_list: Renamed child to item, and add child to add DescriptionItem. (#1521) 2025-11-05 07:26:17 +00:00
dialog.md Revert "root: Render overlays inside Root element by default. (#1570)" (#1584) 2025-11-13 13:37:05 +08:00
dropdown_button.md dropdown_button: Add more button option methods to DropdownButton. (#1633) 2025-11-18 14:31:14 +08:00
editor.md chore: Rename Dropdown to Select, TextInput to Input. (#1449) 2025-10-28 21:22:31 +08:00
form.md form: Rename FormField to Field. (#1539) 2025-11-07 18:43:01 +08:00
group-box.md dialog: Rename Modal to Dialog. (#1538) 2025-11-07 17:25:55 +08:00
icon.md icon: Rework icons to make use of the IconNamed trait (#1640) 2025-11-20 02:30:08 +00:00
image.md docs: Remove incorrect Accessibility section. (#1439) 2025-10-28 10:24:48 +08:00
index.md dropdown_button: Add more button option methods to DropdownButton. (#1633) 2025-11-18 14:31:14 +08:00
input.md input, select, date_picker: Refactor cleanable to have argument and default to false. (#1506) 2025-11-05 09:33:31 +08:00
kbd.md chore: Update List, Tree, Kbd exports. (#1467) 2025-10-30 07:19:39 +00:00
label.md docs: Remove incorrect Accessibility section. (#1439) 2025-10-28 10:24:48 +08:00
list.md chore: Move searchable to ListState and SelectState. (#1507) 2025-11-04 21:26:11 +08:00
menu.md chore: Standardize the overall API and improve docs. (#1516) 2025-11-05 19:10:30 +08:00
notification.md Revert "root: Render overlays inside Root element by default. (#1570)" (#1584) 2025-11-13 13:37:05 +08:00
number-input.md docs: Remove incorrect Accessibility section. (#1439) 2025-10-28 10:24:48 +08:00
otp-input.md docs: Remove incorrect Accessibility section. (#1439) 2025-10-28 10:24:48 +08:00
popover.md popover: Fix click trigger to close popover. (#1559) 2025-11-11 21:14:56 +08:00
progress.md chore: Standardize the overall API and improve docs. (#1516) 2025-11-05 19:10:30 +08:00
radio.md docs: Remove incorrect Accessibility section. (#1439) 2025-10-28 10:24:48 +08:00
resizable.md resizable: Simplify Resizable API. (#1459) 2025-10-29 23:01:05 +08:00
scrollable.md Fix state internal update to refresh for List, Tree, Table and Select. (#1492) 2025-11-04 16:25:37 +08:00
select.md input, select, date_picker: Refactor cleanable to have argument and default to false. (#1506) 2025-11-05 09:33:31 +08:00
sheet.md Revert "root: Render overlays inside Root element by default. (#1570)" (#1584) 2025-11-13 13:37:05 +08:00
sidebar.md sidebar: Improve Sidebar to allows caret icon to expand submenu. (#1642) 2025-11-19 05:39:24 +00:00
skeleton.md chore: Standardize the overall API and improve docs. (#1516) 2025-11-05 19:10:30 +08:00
slider.md slider: Add option to choose between linear and logarithmic scale (#1543) 2025-11-10 02:56:09 +00:00
spinner.md spinner: Rename Indicator to Spinner. (#1526) 2025-11-06 11:36:39 +08:00
switch.md chore: Standardize the overall API and improve docs. (#1516) 2025-11-05 19:10:30 +08:00
table.md chore: Standardize the overall API and improve docs. (#1516) 2025-11-05 19:10:30 +08:00
tabs.md tab: Refactor creation to use builder pattern (#1553) 2025-11-11 10:35:00 +08:00
tag.md docs: Remove incorrect Accessibility section. (#1439) 2025-10-28 10:24:48 +08:00
title-bar.md docs: Remove incorrect Accessibility section. (#1439) 2025-10-28 10:24:48 +08:00
toggle.md toggle: Refactor Toggle, ToggleGroup API. (#1515) 2025-11-05 10:47:55 +08:00
tooltip.md docs: Remove incorrect Accessibility section. (#1439) 2025-10-28 10:24:48 +08:00
tree.md chore: Update List, Tree, Kbd exports. (#1467) 2025-10-30 07:19:39 +00:00
virtual-list.md chore: Update List, Tree, Kbd exports. (#1467) 2025-10-30 07:19:39 +00:00
webview.md docs: Improve docs to use variable version from toml. (#1603) 2025-11-14 16:10:48 +08:00