use gpui_material_theme::ColorRole;
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub enum SemanticTone {
#[default]
Default,
Danger,
Success,
Warning,
Info,
}
impl SemanticTone {
pub const fn roles(self) -> Option<(ColorRole, ColorRole, ColorRole, ColorRole)> {
use ColorRole::*;
match self {
Self::Default => None,
Self::Danger => Some((Error, OnError, ErrorContainer, OnErrorContainer)),
Self::Success => Some((Success, OnSuccess, SuccessContainer, OnSuccessContainer)),
Self::Warning => Some((Warning, OnWarning, WarningContainer, OnWarningContainer)),
Self::Info => Some((Info, OnInfo, InfoContainer, OnInfoContainer)),
}
}
pub const fn role(self) -> Option<ColorRole> {
match self.roles() {
Some((role, _, _, _)) => Some(role),
None => None,
}
}
pub const fn on_role(self) -> Option<ColorRole> {
match self.roles() {
Some((_, on_role, _, _)) => Some(on_role),
None => None,
}
}
pub const fn container_role(self) -> Option<ColorRole> {
match self.roles() {
Some((_, _, container, _)) => Some(container),
None => None,
}
}
pub const fn on_container_role(self) -> Option<ColorRole> {
match self.roles() {
Some((_, _, _, on_container)) => Some(on_container),
None => None,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn semantic_tone_resolves_expected_color_roles() {
use ColorRole::*;
assert_eq!(SemanticTone::Default.roles(), None);
assert_eq!(SemanticTone::Default.role(), None);
assert_eq!(SemanticTone::Default.on_role(), None);
assert_eq!(SemanticTone::Default.container_role(), None);
assert_eq!(SemanticTone::Default.on_container_role(), None);
let cases = [
(
SemanticTone::Danger,
Error,
OnError,
ErrorContainer,
OnErrorContainer,
),
(
SemanticTone::Success,
Success,
OnSuccess,
SuccessContainer,
OnSuccessContainer,
),
(
SemanticTone::Warning,
Warning,
OnWarning,
WarningContainer,
OnWarningContainer,
),
(
SemanticTone::Info,
Info,
OnInfo,
InfoContainer,
OnInfoContainer,
),
];
for (tone, role, on_role, container, on_container) in cases {
assert_eq!(tone.roles(), Some((role, on_role, container, on_container)));
assert_eq!(tone.role(), Some(role));
assert_eq!(tone.on_role(), Some(on_role));
assert_eq!(tone.container_role(), Some(container));
assert_eq!(tone.on_container_role(), Some(on_container));
}
}
}