storybook

package
v0.3.1118 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 20 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHandler

func NewHandler(name string, f any, args ...Arg) http.Handler

Types

type Arg

type Arg struct {
	Name    string
	Value   any
	Control any
	Get     func(q url.Values) any
}

Controls for the configuration. See https://storybook.js.org/docs/react/essentials/controls

func BooleanArg

func BooleanArg(name string, value bool) Arg

func FloatArg

func FloatArg(name string, value float64, min, max, step float64) Arg

func IntArg

func IntArg(name string, value int, conf IntArgConf) Arg

func ObjectArg

func ObjectArg(name string, value any, valuePtr any) Arg

func TextArg

func TextArg(name, value string) Arg

type Conf

type Conf struct {
	Title      string          `json:"title"`
	Parameters StoryParameters `json:"parameters"`
	Args       *SortedMap      `json:"args"`
	ArgTypes   *SortedMap      `json:"argTypes"`
	Stories    []Story         `json:"stories"`
}

func NewConf

func NewConf(title string, args ...Arg) *Conf

func (*Conf) AddStory

func (c *Conf) AddStory(name string, args ...Arg)

type IntArgConf

type IntArgConf struct{ Min, Max, Step *int }

type SortedMap

type SortedMap struct {
	// contains filtered or unexported fields
}

func NewSortedMap

func NewSortedMap() *SortedMap

func (*SortedMap) Add

func (sm *SortedMap) Add(key string, value any)

func (*SortedMap) MarshalJSON

func (sm *SortedMap) MarshalJSON() (output []byte, err error)

type Story

type Story struct {
	Name string     `json:"name"`
	Args *SortedMap `json:"args"`
}

type StoryParameters

type StoryParameters struct {
	Server map[string]any `json:"server"`
}

type Storybook

type Storybook struct {
	// Path to the storybook-server directory, defaults to ./storybook-server.
	Path string
	// RoutePrefix is the prefix of HTTP routes, e.g. /prod/
	RoutePrefix string
	// Config of the Stories.
	Config map[string]*Conf
	// Handlers for each of the components.
	Handlers map[string]http.Handler
	// Handler used to serve Storybook, defaults to filesystem at ./storybook-server/storybook-static.
	StaticHandler      http.Handler
	Header             string
	Server             http.Server
	Log                *slog.Logger
	AdditionalPrefixJS string
}

func New

func New(conf ...StorybookConfig) *Storybook

func (*Storybook) AddComponent

func (sh *Storybook) AddComponent(name string, componentConstructor any, args ...Arg) *Conf

func (*Storybook) Build

func (sh *Storybook) Build(ctx context.Context) (err error)

func (*Storybook) ListenAndServeWithContext

func (sh *Storybook) ListenAndServeWithContext(ctx context.Context) (err error)

func (*Storybook) ServeHTTP

func (sh *Storybook) ServeHTTP(w http.ResponseWriter, r *http.Request)

type StorybookConfig

type StorybookConfig func(*Storybook)

func WithAdditionalPreviewJS added in v0.0.1057

func WithAdditionalPreviewJS(content string) StorybookConfig

WithAdditionalPreviewJS / WithAdditionalPreviewJS allows to add content to the generated .storybook/preview.js file. For example this can be used to include custom CSS.

func WithHeader added in v0.0.1057

func WithHeader(header string) StorybookConfig

func WithPath added in v0.0.1057

func WithPath(path string) StorybookConfig

func WithServerAddr

func WithServerAddr(addr string) StorybookConfig

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址