1use gpui2::{svg, Hsla};
2use strum::EnumIter;
3
4use crate::prelude::*;
5
6#[derive(Default, PartialEq, Copy, Clone)]
7pub enum IconSize {
8 Small,
9 #[default]
10 Medium,
11}
12
13#[derive(Default, PartialEq, Copy, Clone)]
14pub enum IconColor {
15 #[default]
16 Default,
17 Muted,
18 Disabled,
19 Placeholder,
20 Accent,
21 Error,
22 Warning,
23 Success,
24 Info,
25}
26
27impl IconColor {
28 pub fn color(self, cx: &WindowContext) -> Hsla {
29 let theme_colors = cx.theme().colors();
30
31 match self {
32 IconColor::Default => theme_colors.icon,
33 IconColor::Muted => theme_colors.icon_muted,
34 IconColor::Disabled => theme_colors.icon_disabled,
35 IconColor::Placeholder => theme_colors.icon_placeholder,
36 IconColor::Accent => theme_colors.icon_accent,
37 IconColor::Error => gpui2::red(),
38 IconColor::Warning => gpui2::red(),
39 IconColor::Success => gpui2::red(),
40 IconColor::Info => gpui2::red(),
41 }
42 }
43}
44
45#[derive(Debug, Default, PartialEq, Copy, Clone, EnumIter)]
46pub enum Icon {
47 Ai,
48 ArrowLeft,
49 ArrowRight,
50 ArrowUpRight,
51 AudioOff,
52 AudioOn,
53 Bolt,
54 ChevronDown,
55 ChevronLeft,
56 ChevronRight,
57 ChevronUp,
58 Close,
59 Exit,
60 ExclamationTriangle,
61 File,
62 FileGeneric,
63 FileDoc,
64 FileGit,
65 FileLock,
66 FileRust,
67 FileToml,
68 FileTree,
69 Folder,
70 FolderOpen,
71 FolderX,
72 #[default]
73 Hash,
74 InlayHint,
75 MagicWand,
76 MagnifyingGlass,
77 Maximize,
78 Menu,
79 MessageBubbles,
80 Mic,
81 MicMute,
82 Plus,
83 Quote,
84 Replace,
85 ReplaceAll,
86 Screen,
87 SelectAll,
88 Split,
89 SplitMessage,
90 Terminal,
91 XCircle,
92 Copilot,
93 Envelope,
94}
95
96impl Icon {
97 pub fn path(self) -> &'static str {
98 match self {
99 Icon::Ai => "icons/ai.svg",
100 Icon::ArrowLeft => "icons/arrow_left.svg",
101 Icon::ArrowRight => "icons/arrow_right.svg",
102 Icon::ArrowUpRight => "icons/arrow_up_right.svg",
103 Icon::AudioOff => "icons/speaker-off.svg",
104 Icon::AudioOn => "icons/speaker-loud.svg",
105 Icon::Bolt => "icons/bolt.svg",
106 Icon::ChevronDown => "icons/chevron_down.svg",
107 Icon::ChevronLeft => "icons/chevron_left.svg",
108 Icon::ChevronRight => "icons/chevron_right.svg",
109 Icon::ChevronUp => "icons/chevron_up.svg",
110 Icon::Close => "icons/x.svg",
111 Icon::Exit => "icons/exit.svg",
112 Icon::ExclamationTriangle => "icons/warning.svg",
113 Icon::File => "icons/file.svg",
114 Icon::FileGeneric => "icons/file_icons/file.svg",
115 Icon::FileDoc => "icons/file_icons/book.svg",
116 Icon::FileGit => "icons/file_icons/git.svg",
117 Icon::FileLock => "icons/file_icons/lock.svg",
118 Icon::FileRust => "icons/file_icons/rust.svg",
119 Icon::FileToml => "icons/file_icons/toml.svg",
120 Icon::FileTree => "icons/project.svg",
121 Icon::Folder => "icons/file_icons/folder.svg",
122 Icon::FolderOpen => "icons/file_icons/folder_open.svg",
123 Icon::FolderX => "icons/stop_sharing.svg",
124 Icon::Hash => "icons/hash.svg",
125 Icon::InlayHint => "icons/inlay_hint.svg",
126 Icon::MagicWand => "icons/magic-wand.svg",
127 Icon::MagnifyingGlass => "icons/magnifying_glass.svg",
128 Icon::Maximize => "icons/maximize.svg",
129 Icon::Menu => "icons/menu.svg",
130 Icon::MessageBubbles => "icons/conversations.svg",
131 Icon::Mic => "icons/mic.svg",
132 Icon::MicMute => "icons/mic-mute.svg",
133 Icon::Plus => "icons/plus.svg",
134 Icon::Quote => "icons/quote.svg",
135 Icon::Replace => "icons/replace.svg",
136 Icon::ReplaceAll => "icons/replace_all.svg",
137 Icon::Screen => "icons/desktop.svg",
138 Icon::SelectAll => "icons/select-all.svg",
139 Icon::Split => "icons/split.svg",
140 Icon::SplitMessage => "icons/split_message.svg",
141 Icon::Terminal => "icons/terminal.svg",
142 Icon::XCircle => "icons/error.svg",
143 Icon::Copilot => "icons/copilot.svg",
144 Icon::Envelope => "icons/feedback.svg",
145 }
146 }
147}
148
149#[derive(Component)]
150pub struct IconElement {
151 icon: Icon,
152 color: IconColor,
153 size: IconSize,
154}
155
156impl IconElement {
157 pub fn new(icon: Icon) -> Self {
158 Self {
159 icon,
160 color: IconColor::default(),
161 size: IconSize::default(),
162 }
163 }
164
165 pub fn color(mut self, color: IconColor) -> Self {
166 self.color = color;
167 self
168 }
169
170 pub fn size(mut self, size: IconSize) -> Self {
171 self.size = size;
172 self
173 }
174
175 fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
176 let fill = self.color.color(cx);
177 let svg_size = match self.size {
178 IconSize::Small => ui_size(cx, 12. / 14.),
179 IconSize::Medium => ui_size(cx, 15. / 14.),
180 };
181
182 svg()
183 .size(svg_size)
184 .flex_none()
185 .path(self.icon.path())
186 .text_color(fill)
187 }
188}
189
190#[cfg(feature = "stories")]
191pub use stories::*;
192
193#[cfg(feature = "stories")]
194mod stories {
195 use gpui2::{Div, Render};
196 use strum::IntoEnumIterator;
197
198 use crate::Story;
199
200 use super::*;
201
202 pub struct IconStory;
203
204 impl Render for IconStory {
205 type Element = Div<Self>;
206
207 fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
208 let icons = Icon::iter();
209
210 Story::container(cx)
211 .child(Story::title_for::<_, IconElement>(cx))
212 .child(Story::label(cx, "All Icons"))
213 .child(div().flex().gap_3().children(icons.map(IconElement::new)))
214 }
215 }
216}