Skip to main content

logicaffeine_web/ui/components/
icon.rs

1//! Centralized SVG icon component system.
2//!
3//! Provides a unified icon component with 30+ variants for consistent iconography
4//! across the application. All icons are inline SVGs (24x24 viewBox, stroke-based)
5//! for crisp rendering at any size.
6//!
7//! # Usage
8//!
9//! ```no_run
10//! # use dioxus::prelude::*;
11//! use logicaffeine_web::ui::components::icon::{Icon, IconVariant, IconSize};
12//!
13//! # fn Example() -> Element {
14//! rsx! {
15//!     Icon { variant: IconVariant::Book, size: IconSize::Medium }
16//!     Icon { variant: IconVariant::Lightning, size: IconSize::Large, class: "text-orange" }
17//! }
18//! # }
19//! ```
20
21use dioxus::prelude::*;
22
23/// Icon size variants.
24#[derive(Clone, Copy, PartialEq, Default)]
25pub enum IconSize {
26    /// 16px - for inline text and tight spaces
27    Small,
28    /// 20px - default size for most UI
29    #[default]
30    Medium,
31    /// 24px - for emphasis and larger displays
32    Large,
33    /// 32px - for hero sections and large displays
34    XLarge,
35    /// 48px - for achievement toasts and celebrations
36    XXLarge,
37}
38
39impl IconSize {
40    /// Returns the pixel size as a string.
41    pub fn px(&self) -> &'static str {
42        match self {
43            IconSize::Small => "16px",
44            IconSize::Medium => "20px",
45            IconSize::Large => "24px",
46            IconSize::XLarge => "32px",
47            IconSize::XXLarge => "48px",
48        }
49    }
50}
51
52/// All available icon variants.
53#[derive(Clone, Copy, PartialEq)]
54pub enum IconVariant {
55    // Navigation
56    Book,
57    Package,
58    GraduationCap,
59    Beaker,
60    Newspaper,
61    Map,
62    Diamond,
63    Lightning,
64
65    // Files
66    Folder,
67    FolderOpen,
68    File,
69
70    // Actions
71    Check,
72    Copy,
73    Close,
74    ChevronRight,
75    ChevronDown,
76    Plus,
77    Minus,
78    Menu,
79    Warning,
80
81    // Misc
82    Lock,
83    Document,
84    Tools,
85    Crab,
86    Sparkles,
87    Owl,
88    Github,
89
90    // Roadmap status
91    Hammer,
92    DraftingCompass,
93}
94
95impl IconVariant {
96    /// Returns the SVG path data for this icon.
97    pub fn svg_content(&self) -> &'static str {
98        match self {
99            // Book - open book icon
100            IconVariant::Book => {
101                r#"<path stroke-linecap="round" stroke-linejoin="round" d="M12 6.042A8.967 8.967 0 0 0 6 3.75c-1.052 0-2.062.18-3 .512v14.25A8.987 8.987 0 0 1 6 18c2.305 0 4.408.867 6 2.292m0-14.25a8.966 8.966 0 0 1 6-2.292c1.052 0 2.062.18 3 .512v14.25A8.987 8.987 0 0 0 18 18a8.967 8.967 0 0 0-6 2.292m0-14.25v14.25"/>"#
102            }
103
104            // Package - box/package icon
105            IconVariant::Package => {
106                r#"<path stroke-linecap="round" stroke-linejoin="round" d="m21 7.5-9-5.25L3 7.5m18 0-9 5.25m9-5.25v9l-9 5.25M3 7.5l9 5.25M3 7.5v9l9 5.25m0-9v9"/>"#
107            }
108
109            // GraduationCap - academic cap
110            IconVariant::GraduationCap => {
111                r#"<path stroke-linecap="round" stroke-linejoin="round" d="M4.26 10.147a60.438 60.438 0 0 0-.491 6.347A48.62 48.62 0 0 1 12 20.904a48.62 48.62 0 0 1 8.232-4.41 60.46 60.46 0 0 0-.491-6.347m-15.482 0a50.636 50.636 0 0 0-2.658-.813A59.906 59.906 0 0 1 12 3.493a59.903 59.903 0 0 1 10.399 5.84c-.896.248-1.783.52-2.658.814m-15.482 0A50.717 50.717 0 0 1 12 13.489a50.702 50.702 0 0 1 7.74-3.342M6.75 15a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Zm0 0v-3.675A55.378 55.378 0 0 1 12 8.443m-7.007 11.55A5.981 5.981 0 0 0 6.75 15.75v-1.5"/>"#
112            }
113
114            // Beaker - science/lab flask
115            IconVariant::Beaker => {
116                r#"<path stroke-linecap="round" stroke-linejoin="round" d="M9.75 3.104v5.714a2.25 2.25 0 0 1-.659 1.591L5 14.5M9.75 3.104c-.251.023-.501.05-.75.082m.75-.082a24.301 24.301 0 0 1 4.5 0m0 0v5.714c0 .597.237 1.17.659 1.591L19.8 15.3M14.25 3.104c.251.023.501.05.75.082M19.8 15.3l-1.57.393A9.065 9.065 0 0 1 12 15a9.065 9.065 0 0 1-6.23.693L5 15.3m14.8 0 .002 1.057a2.254 2.254 0 0 1-1.593 2.15l-1.721.489a2.254 2.254 0 0 1-1.236 0l-1.006-.286a2.25 2.25 0 0 0-1.236 0l-1.006.286a2.254 2.254 0 0 1-1.236 0l-1.72-.489a2.254 2.254 0 0 1-1.594-2.15l.002-1.057"/>"#
117            }
118
119            // Newspaper - news icon
120            IconVariant::Newspaper => {
121                r#"<path stroke-linecap="round" stroke-linejoin="round" d="M12 7.5h1.5m-1.5 3h1.5m-7.5 3h7.5m-7.5 3h7.5m3-9h3.375c.621 0 1.125.504 1.125 1.125V18a2.25 2.25 0 0 1-2.25 2.25M16.5 7.5V18a2.25 2.25 0 0 0 2.25 2.25M16.5 7.5V4.875c0-.621-.504-1.125-1.125-1.125H4.125C3.504 3.75 3 4.254 3 4.875V18a2.25 2.25 0 0 0 2.25 2.25h13.5M6 7.5h3v3H6v-3Z"/>"#
122            }
123
124            // Map - roadmap/directions
125            IconVariant::Map => {
126                r#"<path stroke-linecap="round" stroke-linejoin="round" d="M9 6.75V15m0-8.25L6 4.5m3 2.25 3-1.5M9 15l-3 1.5m3-1.5 3-1.5m0 0V6.75m0 6.75 3 1.5m-3-1.5 3-1.5m0 0V6.75m0 6.75 3-1.5M15 6.75l3-1.5M15 15l3 1.5m-3-1.5V6.75m3 8.25V6.75m0 8.25-3-1.5m3 1.5-3 1.5m-9-1.5 3 1.5M6 15V6.75m0 8.25L3 15.75V7.5l3-1.5m12-1.5 3 1.5v8.25l-3-1.5"/>"#
127            }
128
129            // Diamond - premium/pricing
130            IconVariant::Diamond => {
131                r#"<path stroke-linecap="round" stroke-linejoin="round" d="M12 2L2 8.5l10 12.5 10-12.5L12 2z M2 8.5h20 M7 8.5l5 12.5 5-12.5 M7 8.5l5-6.5 5 6.5"/>"#
132            }
133
134            // Lightning - speed/action
135            IconVariant::Lightning => {
136                r#"<path stroke-linecap="round" stroke-linejoin="round" d="m3.75 13.5 10.5-11.25L12 10.5h8.25L9.75 21.75 12 13.5H3.75Z"/>"#
137            }
138
139            // Folder - closed folder
140            IconVariant::Folder => {
141                r#"<path stroke-linecap="round" stroke-linejoin="round" d="M2.25 12.75V12A2.25 2.25 0 0 1 4.5 9.75h15A2.25 2.25 0 0 1 21.75 12v.75m-8.69-6.44-2.12-2.12a1.5 1.5 0 0 0-1.061-.44H4.5A2.25 2.25 0 0 0 2.25 6v12a2.25 2.25 0 0 0 2.25 2.25h15A2.25 2.25 0 0 0 21.75 18V9a2.25 2.25 0 0 0-2.25-2.25h-5.379a1.5 1.5 0 0 1-1.06-.44Z"/>"#
142            }
143
144            // FolderOpen - open folder
145            IconVariant::FolderOpen => {
146                r#"<path stroke-linecap="round" stroke-linejoin="round" d="M3.75 9.776c.112-.017.227-.026.344-.026h15.812c.117 0 .232.009.344.026m-16.5 0a2.25 2.25 0 0 0-1.883 2.542l.857 6a2.25 2.25 0 0 0 2.227 1.932H19.05a2.25 2.25 0 0 0 2.227-1.932l.857-6a2.25 2.25 0 0 0-1.883-2.542m-16.5 0V6A2.25 2.25 0 0 1 6 3.75h3.879a1.5 1.5 0 0 1 1.06.44l2.122 2.12a1.5 1.5 0 0 0 1.06.44H18A2.25 2.25 0 0 1 20.25 9v.776"/>"#
147            }
148
149            // File - document file
150            IconVariant::File => {
151                r#"<path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 0 0-3.375-3.375h-1.5A1.125 1.125 0 0 1 13.5 7.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H8.25m2.25 0H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 0 0-9-9Z"/>"#
152            }
153
154            // Check - success/complete
155            IconVariant::Check => {
156                r#"<path stroke-linecap="round" stroke-linejoin="round" d="m4.5 12.75 6 6 9-13.5"/>"#
157            }
158
159            // Copy - two stacked sheets, copy to the clipboard
160            IconVariant::Copy => {
161                r#"<path stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 0 0-2.25-2.25H6A2.25 2.25 0 0 0 3.75 6v8.25A2.25 2.25 0 0 0 6 16.5h2.25m8.25-8.25H18a2.25 2.25 0 0 1 2.25 2.25V18A2.25 2.25 0 0 1 18 20.25h-7.5A2.25 2.25 0 0 1 8.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 0 0-2.25 2.25v6"/>"#
162            }
163
164            // Close - dismiss/cancel
165            IconVariant::Close => {
166                r#"<path stroke-linecap="round" stroke-linejoin="round" d="M6 18 18 6M6 6l12 12"/>"#
167            }
168
169            // ChevronRight - expand/navigate
170            IconVariant::ChevronRight => {
171                r#"<path stroke-linecap="round" stroke-linejoin="round" d="m8.25 4.5 7.5 7.5-7.5 7.5"/>"#
172            }
173
174            // ChevronDown - dropdown/collapse
175            IconVariant::ChevronDown => {
176                r#"<path stroke-linecap="round" stroke-linejoin="round" d="m19.5 8.25-7.5 7.5-7.5-7.5"/>"#
177            }
178
179            // Plus - add
180            IconVariant::Plus => {
181                r#"<path stroke-linecap="round" stroke-linejoin="round" d="M12 4.5v15m7.5-7.5h-15"/>"#
182            }
183
184            // Minus - remove
185            IconVariant::Minus => {
186                r#"<path stroke-linecap="round" stroke-linejoin="round" d="M5 12h14"/>"#
187            }
188
189            // Menu - hamburger menu
190            IconVariant::Menu => {
191                r#"<path stroke-linecap="round" stroke-linejoin="round" d="M3.75 6.75h16.5M3.75 12h16.5m-16.5 5.25h16.5"/>"#
192            }
193
194            // Warning - alert/caution
195            IconVariant::Warning => {
196                r#"<path stroke-linecap="round" stroke-linejoin="round" d="M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126ZM12 15.75h.007v.008H12v-.008Z"/>"#
197            }
198
199            // Lock - protected/locked
200            IconVariant::Lock => {
201                r#"<path stroke-linecap="round" stroke-linejoin="round" d="M16.5 10.5V6.75a4.5 4.5 0 1 0-9 0v3.75m-.75 11.25h10.5a2.25 2.25 0 0 0 2.25-2.25v-6.75a2.25 2.25 0 0 0-2.25-2.25H6.75a2.25 2.25 0 0 0-2.25 2.25v6.75a2.25 2.25 0 0 0 2.25 2.25Z"/>"#
202            }
203
204            // Document - clipboard/doc
205            IconVariant::Document => {
206                r#"<path stroke-linecap="round" stroke-linejoin="round" d="M15.666 3.888A2.25 2.25 0 0 0 13.5 2.25h-3c-1.03 0-1.9.693-2.166 1.638m7.332 0c.055.194.084.4.084.612v0a.75.75 0 0 1-.75.75H9.75a.75.75 0 0 1-.75-.75v0c0-.212.03-.418.084-.612m7.332 0c.646.049 1.288.11 1.927.184 1.1.128 1.907 1.077 1.907 2.185V19.5a2.25 2.25 0 0 1-2.25 2.25H6.75A2.25 2.25 0 0 1 4.5 19.5V6.257c0-1.108.806-2.057 1.907-2.185a48.208 48.208 0 0 1 1.927-.184"/>"#
207            }
208
209            // Tools - settings/utilities
210            IconVariant::Tools => {
211                r#"<path stroke-linecap="round" stroke-linejoin="round" d="M11.42 15.17 17.25 21A2.652 2.652 0 0 0 21 17.25l-5.877-5.877M11.42 15.17l2.496-3.03c.317-.384.74-.626 1.208-.766M11.42 15.17l-4.655 5.653a2.548 2.548 0 1 1-3.586-3.586l6.837-5.63m5.108-.233c.55-.164 1.163-.188 1.743-.14a4.5 4.5 0 0 0 4.486-6.336l-3.276 3.277a3.004 3.004 0 0 1-2.25-2.25l3.276-3.276a4.5 4.5 0 0 0-6.336 4.486c.091 1.076-.071 2.264-.904 2.95l-.102.085m-1.745 1.437L5.909 7.5H4.5L2.25 3.75l1.5-1.5L7.5 4.5v1.409l4.26 4.26m-1.745 1.437 1.745-1.437m6.615 8.206L15.75 15.75M4.867 19.125h.008v.008h-.008v-.008Z"/>"#
212            }
213
214            // Crab - Rust gear logo
215            IconVariant::Crab => {
216                r#"<path stroke-linecap="round" stroke-linejoin="round" d="M12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6Z"/><path stroke-linecap="round" stroke-linejoin="round" d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1Z"/>"#
217            }
218
219            // Sparkles - celebration/magic
220            IconVariant::Sparkles => {
221                r#"<path stroke-linecap="round" stroke-linejoin="round" d="M9.813 15.904 9 18.75l-.813-2.846a4.5 4.5 0 0 0-3.09-3.09L2.25 12l2.846-.813a4.5 4.5 0 0 0 3.09-3.09L9 5.25l.813 2.846a4.5 4.5 0 0 0 3.09 3.09L15.75 12l-2.846.813a4.5 4.5 0 0 0-3.09 3.09ZM18.259 8.715 18 9.75l-.259-1.035a3.375 3.375 0 0 0-2.455-2.456L14.25 6l1.036-.259a3.375 3.375 0 0 0 2.455-2.456L18 2.25l.259 1.035a3.375 3.375 0 0 0 2.456 2.456L21.75 6l-1.035.259a3.375 3.375 0 0 0-2.456 2.456ZM16.894 20.567 16.5 21.75l-.394-1.183a2.25 2.25 0 0 0-1.423-1.423L13.5 18.75l1.183-.394a2.25 2.25 0 0 0 1.423-1.423l.394-1.183.394 1.183a2.25 2.25 0 0 0 1.423 1.423l1.183.394-1.183.394a2.25 2.25 0 0 0-1.423 1.423Z"/>"#
222            }
223
224            // Owl - wisdom/learning
225            IconVariant::Owl => {
226                r#"<path stroke-linecap="round" stroke-linejoin="round" d="M12 3c-4 0-7 3-7 7v6c0 2.5 2 4.5 4.5 4.5h5c2.5 0 4.5-2 4.5-4.5v-6c0-4-3-7-7-7ZM8 11a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3ZM16 11a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3ZM12 15v2M10 15h4M5 10l-2-3M19 10l2-3"/>"#
227            }
228
229            // Hammer - work being built
230            IconVariant::Hammer => {
231                r#"<path stroke-linecap="round" stroke-linejoin="round" d="M10.4 7.23 13.23 4.4l6.37 6.37-2.83 2.83ZM14.47 11.29l-8.34 8.34a1.25 1.25 0 0 1-1.77-1.77l8.35-8.33"/>"#
232            }
233
234            // DraftingCompass - work on the drawing board
235            IconVariant::DraftingCompass => {
236                r#"<path stroke-linecap="round" stroke-linejoin="round" d="M12 2.75V1.5m1.75 3a1.75 1.75 0 1 1-3.5 0 1.75 1.75 0 0 1 3.5 0Zm-2.65 1.55-5.85 14.2m7.65-14.2 5.85 14.2M3.75 12.75a11.25 11.25 0 0 0 16.5 0"/>"#
237            }
238
239            // Github - social
240            IconVariant::Github => {
241                r#"<path fill-rule="evenodd" clip-rule="evenodd" d="M12 2C6.477 2 2 6.477 2 12c0 4.42 2.865 8.164 6.839 9.489.5.092.682-.217.682-.482 0-.237-.009-.866-.013-1.7-2.782.603-3.369-1.342-3.369-1.342-.454-1.155-1.11-1.462-1.11-1.462-.908-.62.069-.608.069-.608 1.003.07 1.531 1.03 1.531 1.03.892 1.529 2.341 1.087 2.91.831.092-.646.35-1.086.636-1.336-2.22-.253-4.555-1.11-4.555-4.943 0-1.091.39-1.984 1.029-2.683-.103-.253-.446-1.27.098-2.647 0 0 .84-.269 2.75 1.025A9.578 9.578 0 0112 6.836c.85.004 1.705.114 2.504.336 1.909-1.294 2.747-1.025 2.747-1.025.546 1.377.203 2.394.1 2.647.64.699 1.028 1.592 1.028 2.683 0 3.842-2.339 4.687-4.566 4.935.359.309.678.919.678 1.852 0 1.336-.012 2.415-.012 2.743 0 .267.18.578.688.48C19.138 20.161 22 16.418 22 12c0-5.523-4.477-10-10-10z" fill="currentColor" stroke="none"/>"#
242            }
243        }
244    }
245}
246
247const ICON_STYLE: &str = r#"
248.icon {
249    display: inline-flex;
250    align-items: center;
251    justify-content: center;
252    vertical-align: middle;
253    flex-shrink: 0;
254}
255"#;
256
257/// SVG icon component with configurable size and styling.
258///
259/// # Props
260///
261/// - `variant` - The icon to display (see [`IconVariant`])
262/// - `size` - Icon size (default: Medium/20px)
263/// - `class` - Optional additional CSS classes
264/// - `color` - Optional color override (uses currentColor by default)
265#[component]
266pub fn Icon(
267    variant: IconVariant,
268    #[props(default)] size: IconSize,
269    #[props(default)] class: Option<&'static str>,
270    #[props(default)] color: Option<&'static str>,
271) -> Element {
272    let size_px = size.px();
273    let svg_content = variant.svg_content();
274    let extra_class = class.unwrap_or("");
275    let stroke_color = color.unwrap_or("currentColor");
276
277    // GitHub icon uses fill instead of stroke
278    let is_filled = matches!(variant, IconVariant::Github);
279
280    rsx! {
281        style { "{ICON_STYLE}" }
282        if is_filled {
283            svg {
284                class: "icon {extra_class}",
285                xmlns: "http://www.w3.org/2000/svg",
286                width: "{size_px}",
287                height: "{size_px}",
288                view_box: "0 0 24 24",
289                fill: "{stroke_color}",
290                dangerous_inner_html: "{svg_content}"
291            }
292        } else {
293            svg {
294                class: "icon {extra_class}",
295                xmlns: "http://www.w3.org/2000/svg",
296                width: "{size_px}",
297                height: "{size_px}",
298                view_box: "0 0 24 24",
299                fill: "none",
300                stroke: "{stroke_color}",
301                stroke_width: "1.5",
302                dangerous_inner_html: "{svg_content}"
303            }
304        }
305    }
306}