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