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