Crate icebook

Crate icebook 

Source
Expand description

icebook - A theme-agnostic storybook for Iced components

§Overview

icebook provides a framework for building component storybooks with Iced. It’s designed to be generic over your theme system - bring your own themes by implementing the ThemeProvider trait.

§Quick Start

use icebook::prelude::*;

// Define your theme provider
struct MyThemeProvider;

impl ThemeProvider for MyThemeProvider {
    type Theme = MyTheme;

    fn get_theme(brightness: Brightness) -> &'static Self::Theme {
        // Return your theme based on brightness
    }

    fn get_sidebar_theme(brightness: Brightness) -> &'static dyn SidebarTheme {
        // Return sidebar theming (can use defaults)
        icebook::default_sidebar_theme(brightness)
    }
}

// Define your story registry
#[derive(Default)]
struct MyStories { /* ... */ }

impl StoryRegistry for MyStories {
    type Message = MyMessage;
    type Provider = MyThemeProvider;

    fn stories() -> Vec<StoryMeta> { /* ... */ }
    fn view(&self, story_id: &str, theme: &Self::Theme) -> Element<Self::Message> { /* ... */ }
    // ...
}

// Run the storybook
fn main() -> iced::Result {
    icebook::run::<MyStories>()
}

§Architecture

  • StoryRegistry: Trait that your storybook must implement. Provides story metadata and rendering functions.
  • ThemeProvider: Trait that supplies themes. Your registry specifies which provider to use.
  • SidebarTheme: Minimal theme trait for the sidebar UI. Default implementations provided.
  • Storybook: The main application shell that displays stories.

Modules§

prelude
Prelude for convenient imports

Structs§

NavItem
A navigation item in the sidebar
Settings
Settings for window/application
SidebarConfig
Configuration for the sidebar
SidebarFont
Font configuration for sidebar text
SidebarSection
A section in the sidebar containing navigation items
SimpleDarkSidebar
Simple built-in sidebar theme for dark mode
SimpleLightSidebar
Simple built-in sidebar theme for light mode
StoryMeta
Metadata for a story, used for sidebar navigation and routing
Storybook
The main Storybook application

Enums§

Brightness
Brightness mode for theme switching
Message
Messages for the Storybook application
SidebarMessage
Messages from sidebar interactions

Constants§

FALLBACK_FONT
Built-in fallback font (Fira Sans Regular)
FALLBACK_FONT_NAME
Name of the fallback font family

Traits§

SidebarTheme
Minimal theme interface for icebook’s sidebar UI
Story
Individual story trait for single component documentation
StoryRegistry
Registry of all stories in a storybook
ThemeProvider
Theme provider trait - implement this in your storybook consumer

Functions§

default_sidebar_theme
Returns the default sidebar theme for the given brightness. Convenience function for ThemeProvider implementations that don’t need custom sidebar styling.
default_welcome_view
Default welcome view when no story is selected
run
Run the storybook application
run_with_settings
Run the storybook with custom settings