GithubHelp home page GithubHelp logo

kickstartds / storybook-addon-jsonschema Goto Github PK

View Code? Open in Web Editor NEW
12.0 2.0 1.0 2.63 MB

Displays associated JSON Schema documentation using a rich schema explorer interface, and adds a validating JSON Code Editor with semantic auto-complete to interact with your components, and copy configurations with ease.

Home Page: https://www.kickstartDS.com/docs/integration/storybook/schema

License: MIT License

JavaScript 37.10% TypeScript 50.68% CSS 12.22%
storybook-addon data-state json json-schema jsonschema controls addon-controls react storybook

storybook-addon-jsonschema's Introduction

Storybook JSON Schema Addon

Displays associated JSON Schema documentation using a rich JSON Schema Explorer interface, and adds a validating JSON Code Editor with semantic auto-complete to interact with your components, and copy configurations with ease.

JSON Schema Explorer is based on the excellent Atlassian JSON Schema Viewer. It was slightly modified to generate bundles that can be imported for partial use, like this addon does.

JSON Code Editor is based on @monaco-editor/react. The editor is connected to your story state / args, so changing props through Controls is reflected in the code shown. Vice-versa if you edit the JSON, and the result is valid according to the schema, your changed args are applied to the story, too.

Show me a working demo (click on the JSON Schema addon tab)

Teaser image

Table of contents:

What it's for

Three things you can use this addon for:

  1. Explore associated JSON Schema documentation, in a nicely organized fashion in the JSON Schema Explorer
  2. Configure components through Controls, copy the resulting JSON as a starting point or template for API-usage / data generation purposes in the JSON Code Editor
  3. Paste JSON to validate data or preview component state in the JSON Code Editor

Getting started

Prerequesite: Your components need to have JSON Schema files associated with them. Additionally schemas need to be dereferenced already, as $ref-resolution is not (a tested) part of this addon (yet? ... let us know in the issues if you need this).

First step is to install the addon:

$ yarn add --dev @kickstartds/storybook-addon-jsonschema

Second step, register the addon inside your .storybook/main.js (just add it to the list):

module.exports = {
  addons: ["@kickstartds/storybook-addon-jsonschema"],
};

Third step, export the schema as component- or story parameter:

export default {
  title: "Button",
  component: Button,
  parameters: {
    jsonschema: {
      schema: {
        $schema: "http://json-schema.org/draft-07/schema#",
        $id: "https://my-components/button.schema.json",
        type: "object",
        properties: {
          primary: {
            type: "boolean",
            default: false,
          },
          label: {
            type: "string",
          },
        },
      },
    },
  },
};

Advanced configuration

This addon is still early, advanced configuration options will be added at a later date. Feel free to let us know in the issues if something specific is unclear, or doesn't work!

Authors

This addon was made with ๐Ÿ‹ by the team behind kickstartDS - the frontend first framework!

kickstartDS is a comprehensive component and pattern library

We enable web development teams to create consistent and brand compliant web frontends super efficiently. With a built-in Design System to serve all your digital touch points. Easy like squeeeeezing a lemon.

We use the addon to let users of our Design System solution interact with their components through our core JSON Schema property-layer. View our landing page to learn more! ๐Ÿ‘‹

cTeaser image

storybook-addon-jsonschema's People

Contributors

julrich avatar lmestel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

remigailard80

storybook-addon-jsonschema's Issues

Schema "AnyOf" generated as "anything"

I generate a schema of this type,

export type ViewTypeReducerType =
  AdvertisementOverviewViewType.AsObject
  | ButtonTextViewType.AsObject 
  | FleaMarketOverviewViewType.AsObject
  | EventOverviewViewType.AsObject
  | GeneralBusinessOverviewViewType.AsObject
  | GeneralOverviewViewType.AsObject
  | GeneralProgressviewViewType.AsObject
  | GeneralWatchOverviewViewType.AsObject
  | ImageBannerViewType.AsObject
  | NoticeOverviewViewType.AsObject
  | PopupOverviewViewType.AsObject
  | QuestionViewType.AsObject
  | RegionCheckInViewType.AsObject

and generated stuff was

"ViewTypeReducerType": {
      "anyOf": [
        {
          "type": "object",
          "required": [
            "type"
          ],

.....

, the anyOf of objects.

and generated result on storybook was,

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2022-03-22 แ„‹แ…ฉแ„’แ…ฎ 2 31 38

is there any method to resolve anyof schema correctly?

Add working `Show me a working demo` example

We should add Circle CI jobs for automatic release (auto is already used as a part of the storybookjs/addon-kit) and publishing of the example Storybook on Netlify.

The deploy preview / configured url on Netlify can then be used for the Show me the demo page.

"Darkmode"-compatibility of views

Currently it's next to impossible to read some of the text we display in the addon, when the Storybook itself is themed to be dark, e.g.:
image

We should either a) make this dynamic in the addon, or use the correct token contextually, or b) just remove custom theming, isolating the views and always displaying them in light mode

Module not found: Error: Can't resolve 'crypto' in ".../node_modules/@kickstartds/json-schema-viewer/dist"

When trying to install this add-on to storybook, I am getting this error when running up or building
Module not found: Error: Can't resolve 'crypto' in ".../node_modules/@kickstartds/json-schema-viewer/dist"

There were actually several packages but by installing them in my project node_modules I was able to resolve most of them. However, it looks like this one needs to be polyfilled according to webpack

I am using webpack5, i have installed crypto-browserify and my storybook main looks like this:

const path = require('path');
const rootMain = require('../../../.storybook/main');
const toPath = (filePath) => path.join(process.cwd(), filePath);

module.exports = {
  ...rootMain,
  typescript:{
    check: false,
    checkOptions: {},
    reactDocgen: 'react-docgen-typescript',
    reactDocgenTypescriptOptions: {
      compilerOptions: {
        allowSyntheticDefaultImports: false,
        esModuleInterop: false,
      }
      // propFilter: (prop) => (prop.parent ? !/node_modules/.test(prop.parent.fileName) : true),
    },
  },
  core: {
    ...rootMain.core,
    builder: 'webpack5',
    enableCrashReports: true, // ๐Ÿ‘ˆ Appends the crash reports to the telemetry events
  },

  stories: [
    ...rootMain.stories,
    '../src/app/**/*.stories.@(js|jsx|ts|tsx)',
    '../src/app/**/*.stories.mdx',
  ],

  staticDirs: [
    "../src/assets",
    "../src/public"
  ],

  addons: [...rootMain.addons, '@nrwl/react/plugins/storybook', '@kickstartds/storybook-addon-jsonschema'],
  webpackFinal: async (config, { configType }) => {
    console.log('THIS IS THE STORYBOOK WEBPACK FINAL')
    // apply any global webpack configs that might have been specified in .storybook/main.js
    if (rootMain.webpackFinal)
      config = await rootMain.webpackFinal(config, { configType });
    // add your own webpack tweaks if needed

    //added for material-ui theme font
    config.module.rules.push({
      test: /\.(woff(2)?|ttf|eot)(\?v=\d+\.\d+\.\d+)?$/,
      use: [
        {
          loader: 'file-loader',
          options: {
            name: '[name].[ext]',
            outputPath: 'assets/'
          }
        }
      ]
    });



    const value = {
      ...config,
      resolve: {
        ...config.resolve,
        fallback: {
          crypto: require.resolve('crypto-browserify')
        },
        alias: {
          ...config.resolve.alias,
          '@emotion/core': toPath('node_modules/@emotion/react'),
          'emotion-theming': toPath('node_modules/@emotion/react'),
        },
      },
    };
    console.log('THIS IS THE WEBPACK FINAL VALUE')
    console.log(JSON.stringify(value, null, 2))
    return value
  },
}; 

The logs show that the fallback is added to the config.

Im wondering

  1. Why is this complaining about crypto, i dont even see it in the node modules of the project?
  2. Is this something that needs to be resolved in this project or is there a work around that anyone has found?

Is it impossible to update view when I change nested object?

https://www.kickstartds.com/storybook/?path=/story/base-header--default

in this example, when I change

"items": [
      {
        "label": "Sanity",
        "href": "/sanity",
        "id": "sanity"
      },
      {
        "label": "Integrations",
        "href": "/integrations",
        "id": "integrations"
      },
      {
        "label": "Blog",
        "href": "/blog",
        "id": "blog"
      }
    ]

to

"items": [
      {
        "label": "ABC TEST",
        "href": "/sanity",
        "id": "sanity"
      },
      {
        "label": "Integrations",
        "href": "/integrations",
        "id": "integrations"
      },
      {
        "label": "Blog",
        "href": "/blog",
        "id": "blog"
      }
    ]

it looks like there's not any changes.

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$ref": "#/definitions/AdvertisementDataOverviewType",
  "definitions": {
    "AdvertisementOverviewViewType.Data.AsObject": {
      "type": "object",
      "properties": {
        "title": {
          "type": "string"
        },
        "subTitle": {
          "type": "string"
        },
        "price": {
          "type": "number"
        },
        "countsList": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Count.AsObject"
          }
        },
        "image": {
          "type": "string"
        },
        "targetUri": {
          "type": "string"
        },
        "publishedAt": {
          "type": "number"
        },
        "categoryId": {
          "type": "number"
        },
        "quickReportQuestion": {
          "$ref": "#/definitions/QuickReportQuestion.AsObject"
        },
        "userId": {
          "type": "number"
        },
        "meta": {
          "$ref": "#/definitions/AdvertisementOverviewViewType.Meta.AsObject"
        }
      },
      "required": [
        "title",
        "subTitle",
        "price",
        "countsList",
        "image",
        "targetUri",
        "publishedAt",
        "categoryId",
        "userId"
      ],
      "additionalProperties": false
    },
    "Count.AsObject": {
      "type": "object",
      "properties": {
        "type": {
          "$ref": "#/definitions/CountType"
        },
        "value": {
          "type": "number"
        },
        "image": {
          "type": "string"
        }
      },
      "required": [
        "type",
        "value",
        "image"
      ],
      "additionalProperties": false
    },
    "CountType": {
      "type": "number",
      "enum": [
        0,
        1,
        2,
        3,
        4,
        5,
        6,
        7
      ]
    },
    "QuickReportQuestion.AsObject": {
      "type": "object",
      "properties": {
        "content": {
          "type": "string"
        },
        "reportItemId": {
          "type": "number"
        }
      },
      "required": [
        "content",
        "reportItemId"
      ],
      "additionalProperties": false
    },
    "AdvertisementOverviewViewType.Meta.AsObject": {
      "type": "object",
      "properties": {
        "advertisement": {
          "$ref": "#/definitions/Advertisement.AsObject"
        }
      },
      "additionalProperties": false
    },
    "Advertisement.AsObject": {
      "type": "object",
      "properties": {
        "id": {
          "type": "number"
        }
      },
      "required": [
        "id"
      ],
      "additionalProperties": false
    }
  }
}

generated schema, and It looks like every ref objects read as anything.

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2022-03-22 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 2 20 25

Create reset state button for component / story

In the Controls panel you can reset the state of the story by clicking a small "Refresh"-Icon.

We should add something similar to the addon, to reset the state to its initial values. Handy if you're just tinkering with values, and don't feel like backtracking your changes made.

Upgrade react peer depenendency

The package currently only declares a peer dependency React 16 and 17 so when installing for React 18 repos, I get this following error. Can a peer for React 18 be added? Thank you!

npm ERR! While resolving: XXXXXXXX
npm ERR! Found: [email protected]
npm ERR! node_modules/react
npm ERR!   dev react@"^18.2.0" from XXXXXXXX
npm ERR!   packages/XXXXXXXX
npm ERR!     XXXXXXXX
npm ERR!     node_modules/XXXXXXXX
npm ERR!       workspace packages/XXXXXXXX from the root project
npm ERR!       1 more (XXXXXXXX)
npm ERR!   peer react@"^16.8.0 || ^17.0.0 || ^18.0.0" from @storybook/[email protected]
npm ERR!   node_modules/@storybook/addons
npm ERR!     peer @storybook/addons@"^6.3.6" from @kickstartds/[email protected]
npm ERR!     node_modules/@kickstartds/storybook-addon-jsonschema
npm ERR!       dev @kickstartds/storybook-addon-jsonschema@"^1.0.6" from [email protected]
npm ERR!       XXXXXXXX
npm ERR!         [email protected]
npm ERR!         XXXXXXXX
npm ERR!   4 more (react-dom, @storybook/api, @storybook/components, @storybook/theming)
npm ERR!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.