Add storybook CLI
This commit is contained in:
parent
0323a60d85
commit
e84b8747a1
1 changed files with 85 additions and 18 deletions
|
@ -1,12 +1,5 @@
|
||||||
#![allow(dead_code, unused_variables)]
|
#![allow(dead_code, unused_variables)]
|
||||||
|
|
||||||
use assets::Assets;
|
|
||||||
use gpui3::{px, size, Bounds, WindowBounds, WindowOptions};
|
|
||||||
use log::LevelFilter;
|
|
||||||
use simplelog::SimpleLogger;
|
|
||||||
use std::sync::Arc;
|
|
||||||
use workspace::workspace;
|
|
||||||
|
|
||||||
mod assets;
|
mod assets;
|
||||||
mod collab_panel;
|
mod collab_panel;
|
||||||
mod stories;
|
mod stories;
|
||||||
|
@ -17,33 +10,107 @@ mod themes;
|
||||||
mod ui;
|
mod ui;
|
||||||
mod workspace;
|
mod workspace;
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use clap::Parser;
|
||||||
|
use gpui3::{
|
||||||
|
div, px, size, view, Bounds, Context, Element, ViewContext, WindowBounds, WindowOptions,
|
||||||
|
};
|
||||||
|
use log::LevelFilter;
|
||||||
|
use simplelog::SimpleLogger;
|
||||||
|
|
||||||
|
use crate::assets::Assets;
|
||||||
|
use crate::story_selector::StorySelector;
|
||||||
|
use crate::theme::themed;
|
||||||
|
use crate::themes::rose_pine_dawn;
|
||||||
|
use crate::ui::prelude::*;
|
||||||
|
use crate::workspace::workspace;
|
||||||
|
|
||||||
// gpui2::actions! {
|
// gpui2::actions! {
|
||||||
// storybook,
|
// storybook,
|
||||||
// [ToggleInspector]
|
// [ToggleInspector]
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
#[derive(Parser)]
|
||||||
|
#[command(author, version, about, long_about = None)]
|
||||||
|
struct Args {
|
||||||
|
#[arg(value_enum)]
|
||||||
|
story: Option<StorySelector>,
|
||||||
|
|
||||||
|
/// The name of the theme to use in the storybook.
|
||||||
|
///
|
||||||
|
/// If not provided, the default theme will be used.
|
||||||
|
#[arg(long)]
|
||||||
|
theme: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// unsafe { backtrace_on_stack_overflow::enable() };
|
// unsafe { backtrace_on_stack_overflow::enable() };
|
||||||
|
|
||||||
SimpleLogger::init(LevelFilter::Info, Default::default()).expect("could not initialize logger");
|
SimpleLogger::init(LevelFilter::Info, Default::default()).expect("could not initialize logger");
|
||||||
|
|
||||||
|
let args = Args::parse();
|
||||||
|
|
||||||
|
let story_selector = args.story.clone();
|
||||||
|
|
||||||
let asset_source = Arc::new(Assets);
|
let asset_source = Arc::new(Assets);
|
||||||
gpui3::App::production(asset_source).run(|cx| {
|
gpui3::App::production(asset_source).run(move |cx| {
|
||||||
let window = cx.open_window(
|
match story_selector {
|
||||||
WindowOptions {
|
Some(selector) => {
|
||||||
bounds: WindowBounds::Fixed(Bounds {
|
let window = cx.open_window(
|
||||||
origin: Default::default(),
|
WindowOptions {
|
||||||
size: size(px(800.), px(600.)),
|
bounds: WindowBounds::Fixed(Bounds {
|
||||||
}),
|
origin: Default::default(),
|
||||||
..Default::default()
|
size: size(px(800.), px(600.)),
|
||||||
},
|
}),
|
||||||
|cx| workspace(cx),
|
..Default::default()
|
||||||
);
|
},
|
||||||
|
move |cx| {
|
||||||
|
view(
|
||||||
|
cx.entity(|cx| StoryWrapper::new(selector)),
|
||||||
|
StoryWrapper::render,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
let window = cx.open_window(
|
||||||
|
WindowOptions {
|
||||||
|
bounds: WindowBounds::Fixed(Bounds {
|
||||||
|
origin: Default::default(),
|
||||||
|
size: size(px(800.), px(600.)),
|
||||||
|
}),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
|cx| workspace(cx),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
cx.activate(true);
|
cx.activate(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct StoryWrapper {
|
||||||
|
selector: StorySelector,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl StoryWrapper {
|
||||||
|
pub(crate) fn new(selector: StorySelector) -> Self {
|
||||||
|
Self { selector }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element<State = Self> {
|
||||||
|
themed(rose_pine_dawn(), cx, |cx| {
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.h_full()
|
||||||
|
.child_any(self.selector.story())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// fn load_embedded_fonts(platform: &dyn gpui2::Platform) {
|
// fn load_embedded_fonts(platform: &dyn gpui2::Platform) {
|
||||||
// let font_paths = Assets.list("fonts");
|
// let font_paths = Assets.list("fonts");
|
||||||
// let mut embedded_fonts = Vec::new();
|
// let mut embedded_fonts = Vec::new();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue