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