use gpui::{BoxShadow, Styled, hsla, point, px};
use smallvec::{SmallVec, smallvec};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Shadow {
Sm,
Base,
Md,
Lg,
Xl,
}
fn black(alpha: f32) -> gpui::Hsla {
hsla(0., 0., 0., alpha)
}
impl Shadow {
pub fn box_shadows(self) -> SmallVec<[BoxShadow; 2]> {
match self {
Shadow::Sm => smallvec![BoxShadow {
color: black(0.05),
offset: point(px(0.), px(1.)),
blur_radius: px(2.),
spread_radius: px(0.),
}],
Shadow::Base => smallvec![
BoxShadow {
color: black(0.1),
offset: point(px(0.), px(1.)),
blur_radius: px(3.),
spread_radius: px(0.),
},
BoxShadow {
color: black(0.1),
offset: point(px(0.), px(1.)),
blur_radius: px(2.),
spread_radius: px(-1.),
},
],
Shadow::Md => smallvec![
BoxShadow {
color: black(0.1),
offset: point(px(0.), px(4.)),
blur_radius: px(6.),
spread_radius: px(-1.),
},
BoxShadow {
color: black(0.1),
offset: point(px(0.), px(2.)),
blur_radius: px(4.),
spread_radius: px(-2.),
},
],
Shadow::Lg => smallvec![
BoxShadow {
color: black(0.1),
offset: point(px(0.), px(10.)),
blur_radius: px(15.),
spread_radius: px(-3.),
},
BoxShadow {
color: black(0.1),
offset: point(px(0.), px(4.)),
blur_radius: px(6.),
spread_radius: px(-4.),
},
],
Shadow::Xl => smallvec![
BoxShadow {
color: black(0.1),
offset: point(px(0.), px(20.)),
blur_radius: px(25.),
spread_radius: px(-5.),
},
BoxShadow {
color: black(0.1),
offset: point(px(0.), px(8.)),
blur_radius: px(10.),
spread_radius: px(-6.),
},
],
}
}
}
pub trait StyledShadow: Styled + Sized {
fn shadow_level(self, level: Shadow) -> Self {
self.shadow(level.box_shadows().to_vec())
}
}
impl<E: Styled> StyledShadow for E {}