1use std::{cell::Cell, rc::Rc};
2
3use gpui::{
4 AnyElement, App, BorderStyle, Corners, Div, ElementId, Hsla, InteractiveElement, IntoElement,
5 ParentElement, Pixels, RenderOnce, SharedString, Stateful, Styled, Window, canvas, div, point,
6 prelude::FluentBuilder, px, quad,
7};
8use gpui_material_foundation::{
9 InteractionSource, InteractionState, InteractionTracker, ThemeScope, animate, color,
10 current_material_theme, elevation_shadow_pair,
11};
12use gpui_material_theme::{
13 ColorRole, CornerRole, Direction, Elevation, MotionKind, MotionSpeed, TypeRole,
14 TypographyEmphasis,
15};
16
17use crate::action::{
18 Action, ActionControl, ActionLayout, ActionStyle, Activate, DisabledStyle, SegmentShape,
19 icon_slot, interpolated_corners,
20};
21use crate::button_style::{
22 ButtonBorder, ButtonColors, ButtonElevations, ButtonPadding, ButtonShapes, ButtonStyle,
23 finite_length,
24};
25use crate::{Icon, IconName, SemanticTone};
26
27use super::{Chip, ChipColors, ChipElevations, ChipVariant};
28
29#[derive(Clone, Copy, Debug, Eq, PartialEq)]
30struct ChipToneRoles {
31 foreground: ColorRole,
32 leading: ColorRole,
33 trailing: ColorRole,
34 selected_container: ColorRole,
35 border: ColorRole,
36}
37
38fn chip_tone_roles(
39 variant: ChipVariant,
40 selected: bool,
41 tonal: bool,
42 tone: SemanticTone,
43) -> ChipToneRoles {
44 use ColorRole::*;
45 if let Some((role, _, container, on_container)) = tone.roles() {
46 let fg = if selected { on_container } else { role };
47 ChipToneRoles {
48 foreground: fg,
49 leading: fg,
50 trailing: fg,
51 selected_container: container,
52 border: role,
53 }
54 } else {
55 ChipToneRoles {
56 foreground: if selected {
57 OnSecondaryContainer
58 } else if variant == ChipVariant::Assist {
59 OnSurface
60 } else {
61 OnSurfaceVariant
62 },
63 leading: match (variant, selected, tonal) {
64 (ChipVariant::Input, false, _) | (ChipVariant::Filter, false, true) => {
65 OnSurfaceVariant
66 }
67 (ChipVariant::Filter, true, _) => OnSecondaryContainer,
68 _ => Primary,
69 },
70 trailing: if selected {
71 OnSecondaryContainer
72 } else {
73 OnSurfaceVariant
74 },
75 selected_container: SecondaryContainer,
76 border: OutlineVariant,
77 }
78 }
79}
80
81#[derive(Clone, Copy)]
82struct ChipPalette {
83 foreground: ColorRole,
84 label: Hsla,
85 leading: Hsla,
86 trailing: Hsla,
87 container: Hsla,
88 border_color: Hsla,
89 border_width: Pixels,
90 selection: f32,
91}
92
93#[allow(clippy::too_many_arguments)]
94fn resolve_palette(
95 id: &ElementId,
96 variant: ChipVariant,
97 selectable: bool,
98 selected: bool,
99 tonal: bool,
100 tone: SemanticTone,
101 elevated: bool,
102 disabled: bool,
103 chip_colors: ChipColors,
104 border: Option<ButtonBorder>,
105 window: &mut Window,
106 cx: &mut App,
107) -> ChipPalette {
108 use ColorRole::*;
109 let colors = chip_colors.for_state(disabled, selected);
110 let roles = chip_tone_roles(variant, selected, tonal, tone);
111 let foreground = roles.foreground;
112 let (on_surface, label, leading, trailing, idle, checked, border_color, effects) = {
113 let theme = current_material_theme(window, cx);
114 let theme_color = |role| color(theme.colors.color(role));
115 let on_surface = theme_color(OnSurface);
116 let label = colors.label.unwrap_or_else(|| {
117 if disabled {
118 on_surface.opacity(0.38)
119 } else {
120 theme_color(foreground)
121 }
122 });
123 let leading = colors.leading.unwrap_or_else(|| {
124 if disabled {
125 on_surface.opacity(0.38)
126 } else {
127 theme_color(roles.leading)
128 }
129 });
130 let trailing = colors.trailing.unwrap_or_else(|| {
131 if disabled {
132 on_surface.opacity(0.38)
133 } else {
134 theme_color(roles.trailing)
135 }
136 });
137 let idle = chip_colors.enabled.container.unwrap_or_else(|| {
138 if elevated {
139 theme_color(SurfaceContainerLow)
140 } else {
141 theme_color(roles.selected_container).opacity(0.)
142 }
143 });
144 let checked = chip_colors
145 .selected
146 .container
147 .unwrap_or_else(|| theme_color(roles.selected_container));
148 let border_color = colors
149 .border
150 .or(border.map(|border| border.color))
151 .unwrap_or_else(|| {
152 if disabled {
153 on_surface.opacity(0.12)
154 } else {
155 theme_color(roles.border)
156 }
157 });
158 let effects = theme.motion.spec(
159 MotionKind::Effects,
160 MotionSpeed::Fast,
161 cx.reduce_motion() || disabled,
162 );
163 (
164 on_surface,
165 label,
166 leading,
167 trailing,
168 idle,
169 checked,
170 border_color,
171 effects,
172 )
173 };
174 let selection = if selectable {
175 animate(
176 (id.clone(), "chip-tint"),
177 f32::from(selected),
178 effects,
179 window,
180 cx,
181 )
182 .clamp(0., 1.)
183 } else {
184 0.
185 };
186 let container = if disabled {
187 colors
188 .container
189 .unwrap_or_else(|| on_surface.opacity(if selected || elevated { 0.12 } else { 0. }))
190 } else if selection == 0. {
191 idle
192 } else if selection == 1. {
193 checked
194 } else {
195 crate::motion::mix(idle, checked, selection)
196 };
197 let border_width = border.map_or(px(f32::from(!elevated && !selected)), |border| {
198 finite_length(border.width)
199 });
200 ChipPalette {
201 foreground,
202 label,
203 leading,
204 trailing,
205 container,
206 border_color,
207 border_width,
208 selection,
209 }
210}
211
212#[allow(clippy::too_many_arguments)]
213fn build_chip_style(
214 variant: ChipVariant,
215 selectable: bool,
216 selected: bool,
217 tonal: bool,
218 elevated: bool,
219 shapes: ButtonShapes,
220 foreground: ColorRole,
221) -> ActionStyle {
222 ActionStyle {
223 background: None,
224 background_color: None,
225 foreground,
226 disabled: DisabledStyle {
227 foreground: ColorRole::OnSurface,
228 background: None,
229 outline: (ColorRole::OnSurface, 0.12),
230 },
231 height: 32.,
232 min_width: 0.,
233 corner: if tonal {
234 CornerRole::Medium
235 } else {
236 CornerRole::Small
237 },
238 pressed_corner: CornerRole::Small,
239 selected_corner: if tonal {
240 Some(CornerRole::Full)
241 } else if selectable && shapes.checked.is_some() {
242 Some(CornerRole::Small)
243 } else {
244 None
245 },
246 corner_motion: (MotionKind::Spatial, MotionSpeed::Fast),
247 outline: 0.,
248 outline_role: ColorRole::OutlineVariant,
249 elevation: if elevated {
250 Elevation::Level1
251 } else {
252 Elevation::Level0
253 },
254 hover_elevation: if elevated {
255 Elevation::Level2
256 } else if selected && variant == ChipVariant::Filter {
257 Elevation::Level1
258 } else {
259 Elevation::Level0
260 },
261 }
262}
263
264fn build_chip_layout(
265 split: bool,
266 tab_stop: bool,
267 dragged: bool,
268 shapes: ButtonShapes,
269 elevations: ChipElevations,
270 dragged_elevation: Option<Elevation>,
271 palette: ChipPalette,
272) -> ActionLayout {
273 ActionLayout {
274 tab_stop,
275 dragged,
276 dragged_elevation: (!split).then_some(dragged_elevation).flatten(),
277 appearance: ButtonStyle {
278 shapes,
279 colors: action_colors(
280 palette.label,
281 if split {
282 gpui::transparent_black()
283 } else {
284 palette.container
285 },
286 ),
287 border: (!split).then_some(ButtonBorder {
288 width: palette.border_width,
289 color: palette.border_color,
290 }),
291 elevations: if split {
292 ButtonElevations::default()
293 } else {
294 elevations.button()
295 },
296 },
297 ..Default::default()
298 }
299}
300
301#[allow(clippy::too_many_arguments)]
302fn build_leading_slot(
303 avatar: Option<AnyElement>,
304 leading: Option<AnyElement>,
305 filter_mark: f32,
306 spacing: Pixels,
307 leading_color: Hsla,
308 direction: Direction,
309) -> Option<AnyElement> {
310 avatar
311 .map(|avatar| {
312 div()
313 .size(px(24.))
314 .flex_none()
315 .rounded_full()
316 .overflow_hidden()
317 .text_color(leading_color)
318 .child(icon_slot(avatar, 24.))
319 .into_any_element()
320 })
321 .or_else(|| {
322 leading.map(|leading| {
323 div()
324 .flex_none()
325 .text_color(leading_color)
326 .child(icon_slot(leading, 18.))
327 .into_any_element()
328 })
329 })
330 .or_else(|| {
331 (filter_mark > 0.).then(|| {
332 div()
333 .w((px(18.) + spacing) * filter_mark)
334 .flex_none()
335 .overflow_hidden()
336 .opacity(filter_mark)
337 .text_color(leading_color)
338 .when(direction == Direction::Rtl, |slot| {
339 slot.flex().justify_end()
340 })
341 .child(icon_slot(
342 Icon::new(IconName::Check).into_any_element(),
343 18.,
344 ))
345 .into_any_element()
346 })
347 })
348}
349
350#[allow(clippy::too_many_arguments)]
351fn build_primary_content(
352 leading: Option<AnyElement>,
353 trailing: Option<AnyElement>,
354 label: AnyElement,
355 padding: ButtonPadding,
356 spacing: Pixels,
357 filter_mark: f32,
358 split: bool,
359 direction: Direction,
360 visual_height: &Rc<Cell<Pixels>>,
361) -> AnyElement {
362 let content = div()
363 .relative()
364 .flex()
365 .items_center()
366 .min_w_0()
367 .text_size(px(14.))
368 .when(direction == Direction::Rtl, Styled::flex_row_reverse)
369 .pt(padding.top)
370 .pb(padding.bottom);
371 let mut content = logical_edges(
372 content,
373 padding.start,
374 if split { spacing } else { padding.end },
375 direction,
376 )
377 .children(leading)
378 .when(filter_mark == 0., |row| row.gap(spacing))
379 .child(label)
380 .children(trailing.map(|trailing| {
381 if filter_mark > 0. {
382 logical_edges(div(), spacing, px(0.), direction)
383 .child(trailing)
384 .into_any_element()
385 } else {
386 trailing
387 }
388 }));
389 if split {
390 content = content.child(measure_height(visual_height.clone()));
391 }
392 content.into_any_element()
393}
394
395#[allow(clippy::too_many_arguments)]
396fn render_split_chip(
397 id: ElementId,
398 row: Stateful<Div>,
399 primary: ActionControl,
400 remove_label: SharedString,
401 on_remove: Activate,
402 remove_content: Option<AnyElement>,
403 disabled: bool,
404 dragged: bool,
405 selected: bool,
406 direction: Direction,
407 padding: ButtonPadding,
408 explicit_padding: Option<ButtonPadding>,
409 style: ActionStyle,
410 layout: ActionLayout,
411 palette: ChipPalette,
412 elevations: ButtonElevations,
413 dragged_elevation: Option<Elevation>,
414 visual_height: Rc<Cell<Pixels>>,
415 tracker: Option<InteractionTracker>,
416 window: &mut Window,
417 cx: &mut App,
418) -> Stateful<Div> {
419 let primary_focus = primary.focus_handle(window, cx);
420 let key_remove = on_remove.clone();
421 let remove = ActionControl {
422 id: ElementId::from((id.clone(), "remove")),
423 label: remove_label,
424 focus: None,
425 disabled,
426 action: Action::Invoke(Some(on_remove)),
427 style: split_action_style(style, 32.),
428 content: logical_edges(
429 div().relative().pt(padding.top).pb(padding.bottom),
430 px(0.),
431 explicit_padding.map_or(px(0.), |padding| padding.end),
432 direction,
433 )
434 .child(remove_content.unwrap_or_else(|| {
435 icon_slot(Icon::new(IconName::Close).into_any_element(), 18.).into_any_element()
436 }))
437 .child(measure_height(visual_height.clone()))
438 .into_any_element(),
439 };
440 let primary_state = primary.interaction_snapshot(dragged, window, cx);
441 let remove_state = remove.interaction_snapshot(dragged, window, cx);
442 let mut interaction = primary_state;
443 interaction.hovered |= remove_state.hovered;
444 interaction.pressed |= remove_state.pressed;
445 interaction.focus_visible |= remove_state.focus_visible;
446 let surface = SplitSurface {
447 id,
448 style,
449 layout,
450 direction,
451 selected,
452 container: palette.container,
453 border: ButtonBorder {
454 width: palette.border_width,
455 color: palette.border_color,
456 },
457 elevations,
458 dragged_elevation,
459 visual_height,
460 }
461 .render(interaction, window, cx);
462 let primary_layout = ActionLayout {
463 segment: Some(SegmentShape {
464 leading: true,
465 trailing: false,
466 outer: style.corner,
467 inner: CornerRole::None,
468 pressed: CornerRole::None,
469 }),
470 ..layout
471 };
472 let remove_layout = ActionLayout {
473 segment: Some(SegmentShape {
474 leading: false,
475 trailing: true,
476 outer: style.corner,
477 inner: CornerRole::None,
478 pressed: CornerRole::None,
479 }),
480 presentation_selected: Some(selected),
481 appearance: ButtonStyle {
482 shapes: layout.appearance.shapes,
483 colors: action_colors(palette.trailing, gpui::transparent_black()),
484 ..Default::default()
485 },
486 ..layout
487 };
488 row.when(!disabled, |row| {
489 let on_remove =
490 ThemeScope::bind_action(move |window, cx| key_remove(window, cx), window, cx);
491 row.on_key_down(move |event, window, cx| {
492 if !event.keystroke.modifiers.modified()
493 && matches!(event.keystroke.key.as_str(), "backspace" | "delete")
494 && primary_focus.is_focused(window)
495 {
496 cx.stop_propagation();
497 on_remove(window, cx);
498 }
499 })
500 })
501 .child(surface)
502 .child(primary.render_with_tracker(1., primary_layout, tracker, window, cx))
503 .child(remove.render_with_tracker(1., remove_layout, None, window, cx))
504}
505
506impl RenderOnce for Chip {
507 fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
508 let selectable = matches!(self.variant, ChipVariant::Filter | ChipVariant::Input);
509 let selected = selectable && self.selected;
510 let tonal = selectable && self.tonal;
511 let elevated = self.elevated && self.variant != ChipVariant::Input;
512 let split = selectable && self.remove.is_some();
513 let (direction, density) = {
514 let theme = current_material_theme(window, cx);
515 (theme.layout.direction, theme.layout.density)
516 };
517 let palette = resolve_palette(
518 &self.id,
519 self.variant,
520 selectable,
521 selected,
522 tonal,
523 self.tone,
524 elevated,
525 self.disabled,
526 self.colors,
527 self.border,
528 window,
529 cx,
530 );
531 let style = build_chip_style(
532 self.variant,
533 selectable,
534 selected,
535 tonal,
536 elevated,
537 self.shapes,
538 palette.foreground,
539 );
540 let dragged_elevation = self.elevations.dragged.or(Some(Elevation::Level4));
541 let layout = build_chip_layout(
542 split,
543 self.tab_stop,
544 self.dragged,
545 self.shapes,
546 self.elevations,
547 dragged_elevation,
548 palette,
549 );
550
551 let avatar = (self.variant == ChipVariant::Input)
552 .then_some(self.avatar)
553 .flatten();
554 let has_avatar = avatar.is_some();
555 let filter_mark = if self.variant == ChipVariant::Filter && self.leading.is_none() {
556 palette.selection
557 } else {
558 0.
559 };
560 let leading = build_leading_slot(
561 avatar,
562 self.leading,
563 filter_mark,
564 self.spacing,
565 palette.leading,
566 direction,
567 );
568 let trailing = self
569 .trailing
570 .filter(|_| self.variant != ChipVariant::Suggestion)
571 .map(|content| {
572 div()
573 .flex_none()
574 .text_color(palette.trailing)
575 .text_size(px(18.))
576 .child(content)
577 .into_any_element()
578 });
579 let padding = self.padding.unwrap_or_else(|| ButtonPadding {
580 start: px(if has_avatar {
581 4.
582 } else if filter_mark > 0. {
583 16. - 8. * filter_mark
584 } else if leading.is_some() {
585 8.
586 } else {
587 16.
588 }),
589 end: if split {
590 self.spacing
591 } else if trailing.is_some() {
592 px(8.)
593 } else {
594 px(16.)
595 },
596 ..Default::default()
597 });
598 let label = self.content.unwrap_or_else(|| {
599 crate::text::single_line(
600 self.label.clone(),
601 TypeRole::LabelLarge.style(TypographyEmphasis::Baseline),
602 1.,
603 palette.label,
604 (None, 1., 1.),
605 window,
606 cx,
607 )
608 .into_any_element()
609 });
610 let row = div()
611 .id(self.id.clone())
612 .relative()
613 .flex()
614 .min_w_0()
615 .items_center()
616 .when(direction == Direction::Rtl, Styled::flex_row_reverse);
617 let (trailing, remove_content) = if split {
618 (None, trailing)
619 } else {
620 (trailing, None)
621 };
622 let visual_height = Rc::new(Cell::new(px(density.visual_size(style.height))));
623 let content = build_primary_content(
624 leading,
625 trailing,
626 label,
627 padding,
628 self.spacing,
629 filter_mark,
630 split,
631 direction,
632 &visual_height,
633 );
634 let primary = ActionControl {
635 id: ElementId::from((self.id.clone(), "activate")),
636 label: self.label,
637 focus: self.focus,
638 disabled: self.disabled,
639 action: if selectable {
640 Action::Toggle {
641 selected,
642 on_change: self.on_change,
643 }
644 } else {
645 Action::Invoke(self.on_activate)
646 },
647 style: if split {
648 split_action_style(style, 0.)
649 } else {
650 style
651 },
652 content,
653 };
654 let tracker = self
655 .interaction_source
656 .as_ref()
657 .map(|source| InteractionSource::track(source, &self.id, window, cx));
658 if let Some((label, on_remove)) = self.remove.filter(|_| selectable) {
659 render_split_chip(
660 self.id,
661 row,
662 primary,
663 label,
664 on_remove,
665 remove_content,
666 self.disabled,
667 self.dragged,
668 selected,
669 direction,
670 padding,
671 self.padding,
672 style,
673 layout,
674 palette,
675 self.elevations.button(),
676 dragged_elevation,
677 visual_height,
678 tracker,
679 window,
680 cx,
681 )
682 } else {
683 row.child(primary.render_with_tracker(1., layout, tracker, window, cx))
684 }
685 }
686}
687
688fn logical_edges(element: Div, start: Pixels, end: Pixels, direction: Direction) -> Div {
689 if direction == Direction::Rtl {
690 element.pl(end).pr(start)
691 } else {
692 element.pl(start).pr(end)
693 }
694}
695
696fn action_colors(label: Hsla, container: Hsla) -> ButtonColors {
697 ButtonColors {
698 container: Some(container),
699 content: Some(label),
700 disabled_container: Some(container),
701 disabled_content: Some(label),
702 checked_container: Some(container),
703 checked_content: Some(label),
704 }
705}
706
707fn split_action_style(style: ActionStyle, min_width: f32) -> ActionStyle {
708 ActionStyle {
709 min_width,
710 elevation: Elevation::Level0,
711 hover_elevation: Elevation::Level0,
712 ..style
713 }
714}
715
716fn measure_height(height: Rc<Cell<Pixels>>) -> gpui::Canvas<()> {
717 canvas(
718 move |bounds, _, _| height.set(height.get().max(bounds.size.height)),
719 |_, (), _, _| {},
720 )
721 .absolute()
722 .inset_0()
723}
724
725struct SplitSurface {
727 id: ElementId,
728 style: ActionStyle,
729 layout: ActionLayout,
730 direction: Direction,
731 selected: bool,
732 container: Hsla,
733 border: ButtonBorder,
734 elevations: ButtonElevations,
735 dragged_elevation: Option<Elevation>,
736 visual_height: Rc<Cell<Pixels>>,
737}
738
739impl SplitSurface {
740 fn render(
741 self,
742 state: InteractionState,
743 window: &mut Window,
744 cx: &mut App,
745 ) -> impl IntoElement + use<> {
746 let theme = current_material_theme(window, cx);
747 let shadow = color(theme.colors.color(ColorRole::Shadow));
748 let effects = theme
749 .motion
750 .spec(MotionKind::Effects, MotionSpeed::Fast, cx.reduce_motion());
751 let spatial = theme
752 .motion
753 .spec(MotionKind::Spatial, MotionSpeed::Fast, cx.reduce_motion());
754 let pressed = animate(
755 (self.id.clone(), "chip-press"),
756 f32::from(state.pressed),
757 spatial,
758 window,
759 cx,
760 )
761 .clamp(0., 1.);
762 let selected = if self.style.selected_corner.is_some() {
763 animate(
764 (self.id.clone(), "chip-selection"),
765 f32::from(self.selected),
766 spatial,
767 window,
768 cx,
769 )
770 .clamp(0., 1.)
771 } else {
772 0.
773 };
774 let default_elevation = if state.disabled {
775 Elevation::Level0
776 } else if state.hovered && !state.pressed {
777 self.style.hover_elevation
778 } else {
779 self.style.elevation
780 };
781 let elevation = if state.dragged {
782 self.dragged_elevation
783 } else {
784 self.elevations.for_state(state)
785 }
786 .unwrap_or(default_elevation);
787 let elevation = animate(
788 (self.id.clone(), "chip-elevation"),
789 elevation.dp(),
790 effects,
791 window,
792 cx,
793 )
794 .max(0.);
795 let outline = animate(
796 (self.id.clone(), "chip-outline"),
797 f32::from(self.border.width),
798 effects,
799 window,
800 cx,
801 )
802 .max(0.);
803 canvas(
804 |_, _, _| (),
805 move |mut bounds, (), window, _| {
806 let height = self.visual_height.get().min(bounds.size.height);
807 bounds.origin += point(px(0.), (bounds.size.height - height) / 2.);
808 bounds.size.height = height;
809 let shape =
810 interpolated_corners(bounds, self.style, selected, pressed, 1., self.layout);
811 let [top_left, top_right, bottom_right, bottom_left] = shape
812 .radii(
813 f32::from(bounds.size.width),
814 f32::from(bounds.size.height),
815 self.direction,
816 )
817 .map(px);
818 let radii = Corners {
819 top_left,
820 top_right,
821 bottom_right,
822 bottom_left,
823 };
824 if let Some(shadows) = elevation_shadow_pair(elevation, 1., shadow) {
825 window.paint_drop_shadows(bounds, radii, &shadows);
826 }
827 if self.container.a > 0. || outline > 0. {
828 window.paint_quad(quad(
829 bounds,
830 radii,
831 self.container,
832 px(outline),
833 if outline > 0. {
834 self.border.color
835 } else {
836 gpui::transparent_black()
837 },
838 BorderStyle::Solid,
839 ));
840 }
841 },
842 )
843 .absolute()
844 .inset_0()
845 }
846}
847
848#[cfg(test)]
849mod tests {
850 use super::*;
851
852 #[test]
853 fn chip_tone_roles_map_semantic_tones_and_preserve_defaults() {
854 use ColorRole::*;
855 let default_assist =
856 chip_tone_roles(ChipVariant::Assist, false, false, SemanticTone::Default);
857 assert_eq!(default_assist.foreground, OnSurface);
858 assert_eq!(default_assist.border, OutlineVariant);
859 assert_eq!(default_assist.selected_container, SecondaryContainer);
860
861 let default_selected =
862 chip_tone_roles(ChipVariant::Filter, true, false, SemanticTone::Default);
863 assert_eq!(default_selected.foreground, OnSecondaryContainer);
864 assert_eq!(default_selected.leading, OnSecondaryContainer);
865 assert_eq!(default_selected.trailing, OnSecondaryContainer);
866
867 for (tone, role, container, on_container) in [
868 (
869 SemanticTone::Danger,
870 Error,
871 ErrorContainer,
872 OnErrorContainer,
873 ),
874 (
875 SemanticTone::Success,
876 Success,
877 SuccessContainer,
878 OnSuccessContainer,
879 ),
880 (
881 SemanticTone::Warning,
882 Warning,
883 WarningContainer,
884 OnWarningContainer,
885 ),
886 (SemanticTone::Info, Info, InfoContainer, OnInfoContainer),
887 ] {
888 let unselected = chip_tone_roles(ChipVariant::Filter, false, false, tone);
889 assert_eq!(unselected.foreground, role);
890 assert_eq!(unselected.leading, role);
891 assert_eq!(unselected.trailing, role);
892 assert_eq!(unselected.border, role);
893 assert_eq!(unselected.selected_container, container);
894
895 let selected = chip_tone_roles(ChipVariant::Filter, true, false, tone);
896 assert_eq!(selected.foreground, on_container);
897 assert_eq!(selected.leading, on_container);
898 assert_eq!(selected.trailing, on_container);
899 assert_eq!(selected.selected_container, container);
900 }
901 }
902}