Add a story showcasing the color scales

This commit is contained in:
Marshall Bowers
2023-10-30 17:31:15 -04:00
parent 991f58409e
commit a02d806715
6 changed files with 40 additions and 8 deletions
+2
View File
@@ -1,9 +1,11 @@
mod colors;
mod focus;
mod kitchen_sink;
mod scroll;
mod text;
mod z_index;
pub use colors::*;
pub use focus::*;
pub use kitchen_sink::*;
pub use scroll::*;
+28
View File
@@ -0,0 +1,28 @@
use ui::prelude::*;
use crate::story::Story;
#[derive(Component)]
pub struct ColorsStory;
impl ColorsStory {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
let color_scales = theme2::default_color_scales();
Story::container(cx)
.child(Story::title(cx, "Colors"))
.child(
div()
.id("colors")
.flex()
.flex_col()
.overflow_y_scroll()
.text_color(gpui2::white())
.children(color_scales.into_iter().map(|(name, scale)| {
div().child(name.to_string()).child(div().flex().children(
(1..=12).map(|step| div().flex().size_4().bg(scale.step(cx, step))),
))
})),
)
}
}
+2
View File
@@ -14,6 +14,7 @@ use ui::prelude::*;
pub enum ElementStory {
Avatar,
Button,
Colors,
Details,
Focus,
Icon,
@@ -29,6 +30,7 @@ impl ElementStory {
match self {
Self::Avatar => { cx.build_view(|cx| (), |_, _| ui::AvatarStory.render()) }.into_any(),
Self::Button => { cx.build_view(|cx| (), |_, _| ui::ButtonStory.render()) }.into_any(),
Self::Colors => { cx.build_view(|cx| (), |_, _| ColorsStory.render()) }.into_any(),
Self::Details => {
{ cx.build_view(|cx| (), |_, _| ui::DetailsStory.render()) }.into_any()
}
+2 -3
View File
@@ -1,6 +1,5 @@
use std::collections::HashMap;
use gpui2::Rgba;
use indexmap::IndexMap;
use crate::scale::{ColorScaleName, ColorScaleSet, ColorScales};
@@ -35,7 +34,7 @@ impl From<DefaultColorScaleSet> for ColorScaleSet {
pub fn default_color_scales() -> ColorScales {
use ColorScaleName::*;
HashMap::from_iter([
IndexMap::from_iter([
(Gray, gray().into()),
(Mauve, mauve().into()),
(Slate, slate().into()),
+4 -5
View File
@@ -1,6 +1,5 @@
use std::collections::HashMap;
use gpui2::{AppContext, Hsla};
use indexmap::IndexMap;
use crate::{theme, Appearance};
@@ -87,7 +86,7 @@ impl std::fmt::Display for ColorScaleName {
pub type ColorScale = [Hsla; 12];
pub type ColorScales = HashMap<ColorScaleName, ColorScaleSet>;
pub type ColorScales = IndexMap<ColorScaleName, ColorScaleSet>;
/// A one-based step in a [`ColorScale`].
pub type ColorScaleStep = usize;
@@ -146,7 +145,7 @@ impl ColorScaleSet {
}
}
pub fn step(self, cx: &AppContext, step: ColorScaleStep) -> Hsla {
pub fn step(&self, cx: &AppContext, step: ColorScaleStep) -> Hsla {
let appearance = Self::current_appearance(cx);
match appearance {
@@ -155,7 +154,7 @@ impl ColorScaleSet {
}
}
pub fn step_alpha(self, cx: &AppContext, step: ColorScaleStep) -> Hsla {
pub fn step_alpha(&self, cx: &AppContext, step: ColorScaleStep) -> Hsla {
let appearance = Self::current_appearance(cx);
match appearance {
Appearance::Light => self.light_alpha(step),
+2
View File
@@ -4,7 +4,9 @@ mod scale;
mod settings;
mod themes;
pub use default::*;
pub use registry::*;
pub use scale::*;
pub use settings::*;
use gpui2::{AppContext, HighlightStyle, Hsla, SharedString};