From d37520edcd8fdc7dd88a35c94eed2091c5856dcf Mon Sep 17 00:00:00 2001 From: atanasster Date: Thu, 16 Apr 2020 12:15:11 -0400 Subject: [PATCH] feat: add theme config to config preset --- core/instrument/README.md | 2 + .../storybook-6-no-docs/.storybook/preview.js | 12 +- examples/storybook-6/.storybook/preview.js | 13 +- integrations/storybook/README.md | 427 +++++++++++------- integrations/storybook/package.json | 1 + integrations/storybook/rollup.config.js | 2 +- .../storybook/src/{config.ts => config.tsx} | 7 +- integrations/storybook/src/preset.ts | 6 + 8 files changed, 276 insertions(+), 194 deletions(-) rename integrations/storybook/src/{config.ts => config.tsx} (73%) diff --git a/core/instrument/README.md b/core/instrument/README.md index b88c281d6..8fe12e316 100644 --- a/core/instrument/README.md +++ b/core/instrument/README.md @@ -1,3 +1,5 @@ +# Table of contents + # Overview Parsing a source file will generate the following information: diff --git a/examples/storybook-6-no-docs/.storybook/preview.js b/examples/storybook-6-no-docs/.storybook/preview.js index dc1886472..c76d75af4 100644 --- a/examples/storybook-6-no-docs/.storybook/preview.js +++ b/examples/storybook-6-no-docs/.storybook/preview.js @@ -1,15 +1,5 @@ -import React from 'react' -import { addDecorator, addParameters } from '@storybook/react'; -import { ThemeProvider, useIsDark } from '@component-controls/storybook'; +import { addParameters } from '@storybook/react'; -addDecorator((story, ctx ) => { - const isDark = useIsDark(); - return ( - - {story(ctx)} - - ); -}) const categories = ['Storybook', 'Blocks', 'Editors', 'Components'] addParameters({ dependencies: { hideEmpty: true }, diff --git a/examples/storybook-6/.storybook/preview.js b/examples/storybook-6/.storybook/preview.js index 57ad35dbc..c76d75af4 100644 --- a/examples/storybook-6/.storybook/preview.js +++ b/examples/storybook-6/.storybook/preview.js @@ -1,15 +1,4 @@ -import React from 'react' -import { addDecorator, addParameters } from '@storybook/react'; -import { ThemeProvider, useIsDark } from '@component-controls/storybook'; - -addDecorator((story, ctx ) => { - const isDark = useIsDark(); - return ( - - {story(ctx)} - - ); -}) +import { addParameters } from '@storybook/react'; const categories = ['Storybook', 'Blocks', 'Editors', 'Components'] addParameters({ diff --git a/integrations/storybook/README.md b/integrations/storybook/README.md index 2cd4fd0bc..25860ca57 100644 --- a/integrations/storybook/README.md +++ b/integrations/storybook/README.md @@ -1,47 +1,67 @@ -## Table of contents - - * [Storybook](#storybook) - * [Introduction writing custom controls:](#introduction-writing-custom-controls) - * [Intro using smart-controls](#intro-using-smart-controls) - * [Getting Started](#getting-started) - * [With React](#with-react) - * [With MDX](#with-mdx) - * [With Vue.js](#with-vue.js) - * [With Angular](#with-angular) - * [With Ember](#with-ember) - * [Available Controls](#available-controls) - * [Smart Controls](#smart-controls) - * [Examples](#smart-controls-examples) - * [Smart Controls React](#smart-controls-react) - * [Smart Controls MDX](#smart-controls-mdx) - * [Smart Controls Angular](#smart-controls-angular) - * [Smart controls options](#smart-controls-options) - * [Random Data Generators](#testing-with-random-data-generators) - * [Categories](#categories) - * [Storybook Docs Block](#storybook-docs-block) - * [Options](#options) - * [smart](#smart-option) - * [addonPanel](#addonPanel-option) - * [docsPreview](#docsPreview-option) - * [docsProps](#docsProps-option) - - -## Storybook +# Table of contents + +- [Overview](#overview) +- [Storybook](#storybook) +- [Introduction](#introduction) + - [Introduction writing custom controls](#introduction-writing-custom-controls) + - [Intro using smart-controls](#intro-using-smart-controls) +- [Getting Started](#getting-started) + - [CSF](#csf) + - [MDX](#mdx) +- [Available Controls](#available-controls) +- [Smart Controls](#smart-controls) + - [Smart Controls Examples](#smart-controls-examples) + - [Smart Controls React](#smart-controls-react) + - [Smart Controls MDX](#smart-controls-mdx) + - [Smart Controls Options](#smart-controls-options) +- [Testing with random data generators](#testing-with-random-data-generators) +- [Categories](#categories) +- [Storybook Docs Block](#storybook-docs-block) +- [Options](#options) + - [**smart** option](#smart-option) + - [**addonPanel** option](#addonpanel-option) + - [**docsPreview** option](#docspreview-option) + - [**docsProps** option](#docsprops-option) +- [List of components](#list-of-components) + - [ComponentSource](#inscomponentsourceins) + - [ControlsTable](#inscontrolstableins) + - [Description](#insdescriptionins) + - [Meta](#insmetains) + - [Playground](#insplaygroundins) + - [PropsTable](#inspropstableins) + - [Stories](#insstoriesins) + - [Story](#insstoryins) + - [StorySource](#insstorysourceins) + - [Subtitle](#inssubtitleins) + - [Title](#institleins) + - [DocsPage](#insdocspageins) + - [PageContextContainer](#inspagecontextcontainerins) + - [PageContainer](#inspagecontainerins) + +# Overview + +The Storybook](https://storybook.js.org) integration of component-controls is the first publicly available integration. + +- Storybook is the most used system for developing components with a focus on design systems +- The Storybook [CSF](https://storybook.js.org/docs/formats/component-story-format/) format introduced in v5.2 was a leap forward and allows for open interoperability. The CSF format is one of the founding blocks upon which componnet-controls expands. +- The Storybook MDX format is a bit of a letdown - it uses a proprietary format that we aim to replace with the portable [frontmatter](https://www.gatsbyjs.org/docs/mdx/markdown-syntax/#frontmatter--mdx-example) format to add metadata. +- The Storybook [docs addon](https://github.com/storybookjs/storybook/tree/next/addons/docs) added the ability to view documentation from CSF and MDX formats. However the architecture suffers from a few issues listed below. +- We wanted to allow component-controls to function both as a full replacement to the addon docs, and also alongside the addon docs. + + +# Storybook The Storybook integration of component-controls allows you to define and then edit story properties dynamically in the [Storybook](https://storybook.js.org) UI with a set of property editors. - The definitions of the control properties can be found [here](https://github.com/ccontrols/component-controls/blob/master/core/specification/src/types.ts): Additional functionality out of the box with Addon Controls are the "smart controls" - using the story's component property table to automatically create editable controls for the stories. Another unique facet of Addon Controls is the one-click generation of random data, using under the hood [faker.js](https://github.com/marak/Faker.js/). -Addon Controls is a successor of [addon-knobs](https://github.com/storybookjs/storybook/tree/next/addons/knobs) and tries to keep compatibility where possible. - -Addon controls and the bundled "smart-controls" can work with all frameworks supported by Storybook +The Storybook integration started as a successor of [addon-knobs](https://github.com/storybookjs/storybook/tree/next/addons/knobs) and we have attempted to keep some level of compatibility where possible. -[Framework Support](https://github.com/storybookjs/storybook/blob/master/ADDONS_SUPPORT.md). +# Introduction ## Introduction writing custom controls @@ -55,7 +75,7 @@ Addon controls and the bundled "smart-controls" can work with all frameworks su introduction to using smart-controls

-## Getting Started +# Getting Started First of all, you need to install Addon Controls into your project as a dev dependency. @@ -73,7 +93,8 @@ module.exports = { That's it, you can now use controls inside your stories -### With React +## CSF + ```js import React from "react"; @@ -95,7 +116,8 @@ controlsStory.story = { } ``` -### With MDX +### MDX + ```md import { Story, Preview, Meta } from '@storybook/addon-docs/blocks'; import { ControlsTable } from '@component-controls/storybook'; @@ -118,113 +140,17 @@ import { ControlsTable } from '@component-controls/storybook'; ``` -### With Vue.js -```js - -import MyButton from './MyButton.vue'; - -export default { - title: "Storybook Controls", -}; - -export const controlsStory = ({ disabled, text }) => ({ - components: { MyButton }, - props: { - isDisabled: { - default: disabled - }, - text: { - default: text - } - }, - template: `{{ text }}` -}); - -controlsStory.story = { - controls: { - disabled: { type: 'boolean', value: false }, - text: { type: 'text', value: 'Hello Storybook' }, - } -} -``` - -MyButton.vue: -```vue - - - -``` - -### With Angular -```js - -import { Button } from '@storybook/angular/demo'; - -export default { - title: "Storybook Controls", -}; - -export const controlsStory = props => ({ - component: Button, - props, -}); - -controlsStory.story = { - controls: { - disabled: { type: 'boolean', value: false }, - text: { type: 'text', value: 'Hello Storybook' }, - } -} -``` - -### With Ember -```js -import hbs from 'htmlbars-inline-precompile'; - -export default { - title: 'StoryBook Controls', -}; - -export const controlsStory = context => ({ - template: hbs` - - `, - context, -}); - -controlsStory.story = { - controls: { - disabled: { type: 'boolean', value: false }, - text: { type: 'text', value: 'Hello Storybook' }, - } -} -``` - -## Available Controls +# Available Controls The list of available controls and their documented properties is available [here](https://github.com/ccontrols/component-controls/blob/master/core/specification/src/types.ts) - -## Smart Controls +# Smart Controls Smart Controls use a story component's properties table type information to generate automatically controls for the story. By default, Addon Controls enables the smart-controls option for your storybook site, but there are 2 basic requirements for a story to use smart controls: -1. The story needs to have a component assigned, and this component needs to have a valid properties table (it can be typescript, or prop-types or any other format supported by Storybook). -2. The story needs to accept "some" parameters / internally detected by Addon Controls within the source loaders / enabling the story to use the passed control values. +1\. The story needs to have a component assigned, and this component needs to have a valid properties table (it can be typescript, or prop-types or any other format supported by Storybook). +2\. The story needs to accept "some" parameters / internally detected by Addon Controls within the source loaders / enabling the story to use the passed control values. A screenshot of smart controls in action. @@ -235,6 +161,7 @@ A screenshot of smart controls in action. ## Smart Controls Examples ### Smart Controls React + ```js import React from 'react'; import { Button } from './Button'; @@ -250,6 +177,7 @@ export const smartControls = props =>