Documentation ¶
Overview ¶
Package storytempl runs a Storybook server for Templ components so that you can preview them during development.
Index ¶
- Constants
- func NewHandler(name string, templateFn interface{}, conf *Conf) http.Handler
- type Arg
- func BooleanArg(name string, value bool) Arg
- func CheckArg(name string, value string) Arg
- func ColorArg(name, value string) Arg
- func DateArg(name string, value time.Time) Arg
- func FileArg(name, value string) Arg
- func FloatArg(name string, value float64) Arg
- func NumberArg(name string, value int) Arg
- func ObjectArg(name string, value interface{}) Arg
- func RadioArg(name string, value string) Arg
- func RangeArg(name string, value int) Arg
- func SelectArg(argName string, option string) Arg
- func TextArg(name, value string) Arg
- type ArgType
- func BooleanArgType(name string) ArgType
- func CheckArgType(name string, options []string) ArgType
- func CheckInlineArgType(name string, options []string) ArgType
- func ColorArgType(name string, presetColors *[]string) ArgType
- func DateArgType(name string) ArgType
- func FileArgType(name, accept string) ArgType
- func FloatArgType(name string, min, max, step float64) ArgType
- func NumberArgType(name string, conf *NumberArgConf) ArgType
- func ObjectArgType(name string, valuePtr interface{}) ArgType
- func RadioArgType(name string, options []string) ArgType
- func RadioInlineArgType(name string, options []string) ArgType
- func RangeArgType(name string, conf *NumberArgConf) ArgType
- func SelectArgType(name string, options []string) ArgType
- func SelectMultiArgType(name string, options []string) ArgType
- func TextArgMaxLenType(name string, maxLen int) ArgType
- func TextArgType(name string) ArgType
- type Conf
- type NumberArgConf
- type Storybook
- func (sb *Storybook) AddComponent(componentConstructor interface{}, conf *Conf) *Storybook
- func (sb *Storybook) GetComponentPath(conf *Conf) string
- func (sb *Storybook) GetComponentURL(title string) string
- func (sb *Storybook) GetPreviewHandler() http.Handler
- func (sb *Storybook) ListenAndServe() error
- func (sb *Storybook) ListenAndServeWithContext(ctx context.Context) error
Constants ¶
const NPM_CMD = "npm"
const PNPM_CMD = "pnpm"
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Arg ¶
type Arg struct { Name string Value interface{} }
type ArgType ¶
type ArgType struct { Name string Control interface{} Options *[]string // Function to retrieve/decode the value from a URL query string Get queryParamGetter // Optional arg value validator for this arg type Validate func(interface{}) error }
func BooleanArgType ¶
Provides a toggle for switching between possible states.
func CheckArgType ¶
Provides a set of stacked checkboxes for selecting multiple options.
func CheckInlineArgType ¶
Provides a set of inlined checkboxes for selecting multiple options.
func ColorArgType ¶
Provides a color picker to choose color values. Can be optionally configured to include a set of color presets that show in the color picker.
func DateArgType ¶
Provides a datepicker to choose a date which is returned as a time.Time type.
func FileArgType ¶
Provides a file input that returns an array of URLs formatted as a string. Can be further customized to accept specific file types.
func FloatArgType ¶
Provides a float64 numeric input with optional min/max/step.
func NumberArgType ¶
func NumberArgType(name string, conf *NumberArgConf) ArgType
Provides a numeric input with optional min/max/step.
func ObjectArgType ¶
func RadioArgType ¶
Provides a set of stacked radio buttons based on the available options.
func RadioInlineArgType ¶
Provides a set of inlined radio buttons based on the available options.
func RangeArgType ¶
func RangeArgType(name string, conf *NumberArgConf) ArgType
Provides a numeric range slider with optional min/max/step.
func SelectArgType ¶
Provides a select to choose a single value from the options.
func SelectMultiArgType ¶
Provides a select to choose any number of the provided options.
func TextArgMaxLenType ¶
Provides a text input with a maximum length.
type Conf ¶
type Conf struct { Title string `json:"title"` Parameters storyParameters `json:"parameters"` Args *util.OrderedMap[string, interface{}] `json:"args"` ArgTypes *util.OrderedMap[string, interface{}] `json:"argTypes"` Stories []story `json:"stories"` // contains filtered or unexported fields }
This is the "real" config that will get turned into a *_stories.json file.
func (*Conf) AddArgTypes ¶
func (*Conf) AddDefaultArgs ¶
type NumberArgConf ¶
type NumberArgConf struct{ Min, Max, Step *int }
func NewNumberArgConf ¶
func NewNumberArgConf() *NumberArgConf
func (*NumberArgConf) SetMax ¶
func (conf *NumberArgConf) SetMax(max int) *NumberArgConf
func (*NumberArgConf) SetMin ¶
func (conf *NumberArgConf) SetMin(min int) *NumberArgConf
func (*NumberArgConf) SetStep ¶
func (conf *NumberArgConf) SetStep(step int) *NumberArgConf
type Storybook ¶
type Storybook struct { // Path to the directory where storybook files will be installed. // Defaults to "storybook-server". ServerPath string // Host and port number to bind to, such as "localhost:8080" or ":60606" (default) ServerAddress string // Header to be included in the <head> of the storybook preview. Header string // A name of the npm executable to use, either 'pnpm' or 'npm'. // Defaults to trying both in that order if not set. NpmExecutable string // Main configuration to be copied to .storybook/main.js. MainJS string // Javascript code to be copied to .storybook/preview.js. PreviewJS string // Component configuration used to generate the stories. Config map[string]*Conf // http Handlers to wrap each of the component templates. Handlers map[string]http.Handler // Handler used to serve files generated by `storybook build` StaticHandler http.Handler // Optional path to directory which will be available with a /static path // prefix. Useful for serving JS/CSS referenced by Header. UserStaticFilesDir string // Skip the Storybook install/build step if true, and only serve the // components. Meant to be used for testing. SkipBuild bool Log *slog.Logger Server http.Server // contains filtered or unexported fields }
func (*Storybook) AddComponent ¶
Adds a component to Storybook. The title can have a slash to create a hierarchy of components in the Storybook UI.
func (*Storybook) GetComponentPath ¶ added in v0.2.0
func (*Storybook) GetComponentURL ¶ added in v0.2.0
func (*Storybook) GetPreviewHandler ¶ added in v0.2.0
Returns the http.Handler that serves the rendered templates with a "/preview/" prefix in case you want to use it with your own server. Used for unit testing.
func (*Storybook) ListenAndServe ¶
Starts the Storybook web UI. ListenAndServe wraps ListenAndServeWithContext using context.Background.