mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-16 15:11:25 +00:00
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)]
|
||||
|
||||
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 collab_panel;
|
||||
mod stories;
|
||||
|
@ -17,18 +10,70 @@ mod themes;
|
|||
mod ui;
|
||||
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! {
|
||||
// storybook,
|
||||
// [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() {
|
||||
// unsafe { backtrace_on_stack_overflow::enable() };
|
||||
|
||||
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);
|
||||
gpui3::App::production(asset_source).run(|cx| {
|
||||
gpui3::App::production(asset_source).run(move |cx| {
|
||||
match story_selector {
|
||||
Some(selector) => {
|
||||
let window = cx.open_window(
|
||||
WindowOptions {
|
||||
bounds: WindowBounds::Fixed(Bounds {
|
||||
origin: Default::default(),
|
||||
size: size(px(800.), px(600.)),
|
||||
}),
|
||||
..Default::default()
|
||||
},
|
||||
move |cx| {
|
||||
view(
|
||||
cx.entity(|cx| StoryWrapper::new(selector)),
|
||||
StoryWrapper::render,
|
||||
)
|
||||
},
|
||||
);
|
||||
}
|
||||
None => {
|
||||
let window = cx.open_window(
|
||||
WindowOptions {
|
||||
bounds: WindowBounds::Fixed(Bounds {
|
||||
|
@ -39,11 +84,33 @@ fn main() {
|
|||
},
|
||||
|cx| workspace(cx),
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
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) {
|
||||
// let font_paths = Assets.list("fonts");
|
||||
// let mut embedded_fonts = Vec::new();
|
||||
|
|
Loading…
Reference in a new issue