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