material_ui_rs/design/style/
select.rs1use iced_widget::core::{Background, Border, Color};
2use iced_widget::overlay::menu as overlay_menu;
3use iced_widget::pick_list::{Catalog, Status, Style, StyleFn};
4
5use crate::Theme;
6use crate::tokens;
7
8impl Catalog for Theme {
9 type Class<'a> = StyleFn<'a, Self>;
10
11 fn default<'a>() -> <Self as Catalog>::Class<'a> {
12 Box::new(default)
13 }
14
15 fn style(&self, class: &<Self as Catalog>::Class<'_>, status: Status) -> Style {
16 class(self, status)
17 }
18
19 fn default_menu<'a>() -> <Self as overlay_menu::Catalog>::Class<'a> {
20 Box::new(crate::style::menu::outlined_select)
21 }
22}
23
24pub fn default(theme: &Theme, status: Status) -> Style {
25 let colors = theme.colors();
26 let surface = colors.surface;
27
28 let active = Style {
29 text_color: surface.text,
30 placeholder_color: surface.text_variant,
31 handle_color: surface.text_variant,
32 background: Background::Color(Color::TRANSPARENT),
33 border: Border {
34 color: colors.outline.color,
35 width: tokens::component::select::TEXT_FIELD_OUTLINE_WIDTH,
36 radius: tokens::component::select::TEXT_FIELD_CONTAINER_SHAPE.into(),
37 },
38 };
39
40 match status {
41 Status::Active => active,
42 Status::Hovered => Style {
43 border: Border {
44 color: surface.text,
45 width: tokens::component::select::TEXT_FIELD_HOVER_OUTLINE_WIDTH,
46 ..active.border
47 },
48 ..active
49 },
50 Status::Opened { .. } => Style {
51 border: Border {
52 color: colors.primary.color,
53 width: tokens::component::select::TEXT_FIELD_FOCUS_OUTLINE_WIDTH,
54 ..active.border
55 },
56 handle_color: colors.primary.color,
57 ..active
58 },
59 }
60}
61
62#[cfg(test)]
63#[path = "../../../tests/design/style/select.rs"]
64mod tests;