Skip to content

Stencil Storybook

Jorge Proaño edited this page May 5, 2022 · 1 revision

This document describes a mechanism to use Storybook with Stencil.

Background

Storybook does not provide an stencil preset, historically we have use the @storybook/react package to make a thin wrap between our components and Storybook.

This method has proven to not scale well as the props from out components moved from basic types like string and boolean to complex objects like VideoPrint, this created the need to have internal functions like getOrParse() which only purpose is to bridge the gap between how props are passed between web-components and React.

Eventually we needed to let go of storybook because the parsed objects are be copies of the one passed breaking the ability to interact with internal methods of the original one.

Goals

  • Remove React from the system.
  • Write Stories using jsx.
  • Keep our stories strictly typed vit TypeScript.
  • Enable hot-reloading.

Project setup

package.json

We need to include the following dev dependencies:

The exact versions will depend on the already existing versions on the stack repository

{
  "devDependencies": {
    "@babel/core": "^7.17.10",
    "@babel/plugin-syntax-jsx": "^7.16.7",
    "@babel/plugin-transform-react-jsx": "^7.17.3",
    "@storybook/addon-actions": "^6.4.22",
    "@storybook/addon-essentials": "^6.4.22",
    "@storybook/addon-links": "^6.4.22",
    "@storybook/html": "^6.4.22",
    "babel-loader": "^8.2.5"
  }
}

We need to add the following scripts:

{
  "scripts": {
    "storybook": "start-storybook",
    "build-storybook": "build-storybook"
  }
}

Storybook

THe Storybook configuration lives on the .storybook directory, in order to make Storybook render our stories the following changes are needed.

Clone this wiki locally