An story is a file that exports some React components
The exported components will be displayed in a page where you can easily experiment with them in isolation
1// example.vitro.jsx23import React from 'react'4import { Component } from './'56export const Simple = ({}) => {7return <Component />8}910export const DifferentColor = ({}) => {11return <Component flex='1' w='100%' minH='100%' bg='blue.100' />12}
Every exported component will be displayed as a block on the vitro ui
you can declare an object as default export to add story information like
title
component
1// example.vitro.jsx2import { Button } from './'34export default {5title: 'My Awesome Component!',6}78export const SimpleButton = () => {9return <Button>Click me</Button>10}
You can pass a wrapper key to the default export to add a component to be used as wrapper
This is useful to add necessary react providers like a ThemeProvider
or redux Provider
1// example.vitro.jsx2import { Button } from './'34export default {5title: 'My Awesome Component!',6wrapper: ({ children }) => {7return (8<>9<div>This text comes from a wrapper</div>10{children}11</>12)13},14}1516export const SimpleButton = () => {17return <Button>Click me</Button>18}
You can use the isDark
prop to detect if the dark mode switch is active
1export const SimpleButton = ({ isDark, isFullScreen }) => {2return (3<Button4bg={isDark ? 'white' : 'black'}5width={isFullScreen ? '200px' : '100px'}6>7Click me8</Button>9)10}
You can add inline documentation to your components via the docs
template literals, docs blocks will be statically analyzed and replaced with jsx code
1docs`2## Here are some components34In duis incididunt culpa anim sit veniam ullamco duis deserunt.5`67export const SimpleButton = () => {8return <button>Click me</button>9}
Vitro just statically analyzes for the docs
calls, you can import a dummy function to make your code type safe, but remember not to change the import name
1import { docs } from '@vitro/cli/docs'23// docs is just a dummy function: () => {}4docs`5# hello67# paragraph8`
React fast refresh won't work when you change the order of docs blocks, you need to refresh the page in case you change docs blocks order
To add a global wrapper you can create a vitro-overrides.jsx
to add a wrapper to all stories children of that dirname, see overrides to read more
Instead of using static properties like args
and parameters
1import React from 'react'23const Template = (args) => <div {...args} />45export const Primary = Template.bind({})6Primary.args = {7name: 'world',8}
Just pass your args
1import React from 'react'23const Template = (args) => <div {...args} />45export const Primary = () => (6<Template7{...{8name: 'world',9}}10/>11)
Vitro will not transpile code in files with the js extension, if you use jsx
you should use the jsx extension