Storybook for Laravel Blade
Blast is a low maintenance component library using Storybook Server, built to integrate into your Laravel apps.
Blast allows you to render examples of your app's components using the blade templating engine using Storybook Server within your Laravel app.
We've published some articles to help you get started with Blast and it's features:
composer require area17/blastYou may need to configure your app's assets in config/blast.php after install. To publish the configuration file, use:
php artisan vendor:publish --provider="A17\Blast\BlastServiceProvider" --tag="blast-config"From your app's root directory run:
php artisan blast:launchThis will install all of the dependencies, generate stories and start a Storybook instance, as well as a watch task so updates to .md and .blade.php files in resources/views/stories and .php files in resources/views/stories/data will automatically regenerate the stories and update Storybook.
--install - force install dependencies--noGenerate - skip auto-generating stories based on existing components--port - port used to run StorybookBlast can also generate stories outside of the launch task. You can do this by running:
php artisan blast:generate-stories--watch - watches the story blade files and updates storiesGlobal configuration can be done through the config/blast.php.
Blast uses the public_path() to reference any static assets. This means that any assets in that directory will be available during developement as well as static builds published to the public directory using the blast:publish task.
storybook_versionAllows the use of a different version of Storybook. Blast has only been tested up to 7.1.1.
Default: '7.1.1'
storybook_server_urlThe route Storybook Server uses to render components. You shouldn't need to change this as it isn't ever visible on the FE.
Default: config('app.url') . '/storybook_preview'
auto_documentationBlast can automatically generate documentation pages in the form of stories based on your Tailwind config. Use this array to specify which documentation pages to generate. All options are loaded by default.
Default:
[
'border-radius',
'border-width',
'colors',
'font-size',
'font-weight',
'height',
'layout',
'letter-spacing',
'line-height',
'max-height',
'max-width',
'min-height',
'min-width',
'opacity',
'shadows',
'spacing',
'transition',
'typesets',
'width',
]
tailwind_config_pathThe path to your Tailwind config file. Used to parse the auto-documentation.
Default: base_path('tailwind.config.js')
storybook_expanded_controlsSee https://storybook.js.org/docs/react/essentials/controls Set to true to enable full documentation on the controls tab.
Enabling this feature will require configuration in the @storybook blade directive, see description, defaultValue and table array keys in the blade directive configuration.
Default: true
storybook_themeThe array of theme options used by Storybook. More info here.
The options are normal, dark or custom. Normal and dark themes are out of the box from the @storybook-theming addon.
To add a custom theme edit values in the storybook_custom_theme array in config/blast.php.
Default: 'normal'
storybook_docs_themeWith the same options as storybook_theme this configures the theme applied to the docs tab.
Default: 'normal'
storybook_custom_themeAn array passed to the @storybook-theming addon to create a custom theme. HTML color names, RGB and HEX colors are all supported.
canvas_bg_colorSet the background color of the component canvas area. The Storybook theme doesn't allow this without also changing the background of other areas of the UI.
Default: ''
autoload_assetsBlast will attempt to autoload assets from a mix-manifest.json (Laravel Mix) or manifest.json (Vite - added in 1.7) if the assets arrays are empty. This option allows you to disable that functionality. Note that the Vite assets are only auto loaded from a prod build. If you want to use it with Vite's hot reloading, you will need to manually define it in the asset array using the full local url (eg. http://127.0.0.1:5173/resources/css/app.css), or you can publish and modify the storybook.blade.php view to use Laravel's @vite helper.
Default: true
mix_manifest_pathAllows you to customize the path to the mix-manifest file used to autoload assets.
Default: public_path('mix-manifest.json')
vite_manifest_pathAllows you to customize the path to the vite manifest file used to autoload assets.
Default: public_path('build/manifest.json')
assetsAn array of urls to the css and js used by your components. The css and js urls are seperated out as the css is included in the head and the js is included before the closing body tag. js assets can have types (default: text/javascript).
You can also group assets and specify which to use for different components.
…In your story blade file you would select the assets to use with assetGroup.
@storybook([
'assetGroup' => 'blast',
]);Default: [ 'css' => [], 'js' => [], ]
storybook_statusesBlast ships with the Status Addon by Etch. This allows you to add custom status indicators to each component. This option allows you to customise these status indicators. More information on this can be found in the Custom Status section below.
Default:
[
'deprecated' => [
'background' => '#e02929',
'color' => '#ffffff',
'description' =>
'This component is deprecated and should no longer be used',
],
'wip' => [
'background' => '#f59506',
'color' => '#ffffff',
'description' => 'This component is a work in progress',
],
'readyForQA' => [
'background' => '#34aae5',
'color' => '#ffffff',
'description' => 'This component is complete and ready to qa',
],
'stable' => [
'background' => '#1bbb3f',
'color' => '#ffffff',
'description' => 'This component is stable and released',
],
]
storybook_sort_orderDefine a custom order for the stories. Accepts an array of story names and can contain nested arrays to set the order of 2nd tier stories. More information can be found in the official Storybook Docs.
Default: [] (alphabetical)
storybook_global_typesThe Global Types can be used, for example, to extend and edit the toolbar. The array of toolbars and globals options used by Storybook. More info here.
Default: []
storybook_default_view_modeSet the default view for each story to either the Canvas or Docs view. This can be overridden in each story using the viewMode prop in the @storybook directive. Use the value story for the canvas view and docs for the docs view. If set to false it will use the last used view when changing between stories.
Default: false
build_timeoutSet a custom timeout for tasks in launch and generate-stories
Default: 300
vendor_pathThe relative path to the Blast package directory
Default: vendor/area17/blast
componentsAn array of custom components used by Blast.
Default: [ 'docs-page' => Components\DocsPages\DocsPage::class ]
storybook_viewportsConfigure custom viewports in the Storybook preview toolbar.
It supports an array with the structure found in the Storybook docs and it can also use your Tailwind config to generate the viewports for you by setting the value to 'tailwind'. Defaults to 'tailwind' but fails silently if blast can't find a Tailwind config. The viewports can be disabled by setting to false.
It supports the various ways you can define breakpoints in Tailwind using these rules:
min or only a max it will use that valuemin and max value it will use the min valueraw values will be ignoredDefault: 'tailwind'
There are certain Storybook elements you can configure from within your story blade files. You can do this by adding the @storybook directive to the top of your files:
…The supported options for this directive are:
preset - Use a preset as the base for the component story. Setting options in this directive will override the presetname - Overrides the auto generated name in the Storybook sidebar.layout - Set the component layout in canvas area. Options are fullscreen, padded, centered (default).status - adds a status badge to the component story. Can be configured in the package config. See below for more info.order - Customize the order of each story. Supports float values. Defaults to alphabetical order.design - a Figma url for the component or array of design parameters. You can read more about the supported options hereargs - an array of static data used to create storybook fields. You can read more about that here. The keys in the array are passed to the blade view and updated when the fields are updated in storybook.argTypes - an array to define the args used for the controls. You can read more about them hereactions.handles - an array defining the events that are passed to the @storybook-actions addon. You can read more about actions here - See the Action Event Handlers heading.You can customize a lot of the story component view from within config/blast.php but if you need to take it a step futher you can publish the view to your application folder and modify it there.
php artisan vendor:publish --provider="A17\Blast\BlastServiceProvider" --tag="blast-views"This will publish storybook.blade.php and all of the ui-docs components to resources/views/vendor/blast.
Running php artisan blast:demo will create all the files needed to display a demo component. It creates files in your resources/views/components and resources/views/stories directories and generates the stories.
It can be run alongside the php artisan blast:launch task or you can run the demo task and then the launch task after to init Storybook.
You can create preset options for components to reuse throughout your storybook instance.
The preset options use the same structure as Laravel config files:
…You can preset any of the options available in the @storybook directive.
To use the preset, set the preset option to the array path (using "dot" notation) where the first part is the name of the file followed by the option you wish to acces
No open issues yet, or sync has not completed.