Skip to content

Commit

Permalink
Docs/12367 Adding storybook essentials addons (#12393)
Browse files Browse the repository at this point in the history
* Adding storybook essentials and documentation contribution guidelines

* Deprecation updates

* Update ui/2.DOCUMENTATION.stories.mdx

Co-authored-by: Elliot Winkler <[email protected]>

* Updating spelling and adding label to i18n-party plugin in toolbar

Co-authored-by: kumavis <[email protected]>
Co-authored-by: Elliot Winkler <[email protected]>
  • Loading branch information
3 people authored Oct 29, 2021
1 parent 487080b commit d72f729
Show file tree
Hide file tree
Showing 11 changed files with 2,917 additions and 1,347 deletions.
67 changes: 33 additions & 34 deletions .depcheckrc.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,48 @@
# things that *are* used, that depcheck is wrong about
ignores:
#
#
# webapp deps
#
#

- "@babel/runtime"
- "@fortawesome/fontawesome-free"
- "punycode"
#
- '@babel/runtime'
- '@fortawesome/fontawesome-free'
- 'punycode'

#
# dev deps
#

# safety fallback for npm lifecycle scripts, not used normally
- "@lavamoat/preinstall-always-fail"
- '@lavamoat/preinstall-always-fail'
# used in testing + ci
- "@metamask/auto-changelog" # invoked as `auto-changelog`
- "@metamask/forwarder"
- "@metamask/test-dapp"
- "@sentry/cli" # invoked as `sentry-cli`
- "chromedriver"
- "depcheck" # ooo meta
- "ganache-cli"
- "geckodriver"
- "jest"
- "lavamoat-viz"
- "prettier-plugin-sort-json" # automatically imported by prettier
- "source-map-explorer"
- '@metamask/auto-changelog' # invoked as `auto-changelog`
- '@metamask/forwarder'
- '@metamask/test-dapp'
- '@sentry/cli' # invoked as `sentry-cli`
- 'chromedriver'
- 'depcheck' # ooo meta
- 'ganache-cli'
- 'geckodriver'
- 'jest'
- 'lavamoat-viz'
- 'prettier-plugin-sort-json' # automatically imported by prettier
- 'source-map-explorer'
# development tool
- "yarn-deduplicate"
- "improved-yarn-audit"
- 'yarn-deduplicate'
- 'improved-yarn-audit'
# storybook
- "@storybook/core"
- "@storybook/addon-backgrounds"
- "@storybook/addon-toolbars"
- "style-loader"
- "css-loader"
- "sass-loader"
- "resolve-url-loader"
- '@storybook/core'
- '@storybook/addon-essentials'
- '@storybook/addon-a11y'
- 'style-loader'
- 'css-loader'
- 'sass-loader'
- 'resolve-url-loader'

# files depcheck should not parse
# files depcheck should not parse
ignorePatterns:
# seems to incorrectly parse scss @include pragmas?
- "**/*.scss"
- '**/*.scss'
# self-contained bundle used for testing
- "**/send-eth-with-private-key-test/web3js.js"
- "**/send-eth-with-private-key-test/ethereumjs-tx.js"

- '**/send-eth-with-private-key-test/web3js.js'
- '**/send-eth-with-private-key-test/ethereumjs-tx.js'
52 changes: 28 additions & 24 deletions .storybook/i18n-party-addon/register.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,41 @@
// import { useGlobals } from '@storybook/api';
const { useGlobals } = require('@storybook/api')
const React = require("react")
const { addons, types } = require("@storybook/addons")
const { Icons, IconButton } = require('@storybook/components')
const localeList = require('../../app/_locales/index.json')
const { useEffect } = React
const { useGlobals } = require('@storybook/api');
const React = require('react');
const { addons, types } = require('@storybook/addons');
const { Icons, IconButton } = require('@storybook/components');
const localeList = require('../../app/_locales/index.json');
const { useEffect } = React;

addons.register("i18n-party", () => {

addons.add("i18n-party", {
title: "rotates through every i18n locale",
addons.register('i18n-party', () => {
addons.add('i18n-party', {
title: 'rotates through every i18n locale',
//👇 Sets the type of UI element in Storybook
type: types.TOOL,
match: () => true,
render: (...args) => {
// https://github.com/storybookjs/storybook/blob/6490a0d646dbaa293b76bbde477daca615efe789/addons/toolbars/src/components/MenuToolbar.tsx#L2
const [globals, updateGlobals] = useGlobals()
const [globals, updateGlobals] = useGlobals();
useEffect(() => {
if (!globals.localeParty) return
if (!globals.localeParty) return;
const interval = setInterval((...args) => {
const currentIndex = localeList.findIndex(({ code }) => code === globals.locale)
const nextIndex = (currentIndex + 1) % localeList.length
const nextLocale = localeList[nextIndex].code
updateGlobals({ locale: nextLocale })
}, 2000)
return () => clearInterval(interval)
})
const currentIndex = localeList.findIndex(
({ code }) => code === globals.locale,
);
const nextIndex = (currentIndex + 1) % localeList.length;
const nextLocale = localeList[nextIndex].code;
updateGlobals({ locale: nextLocale });
}, 2000);
return () => clearInterval(interval);
});

return (
<IconButton onClick={() => updateGlobals({ localeParty: !globals.localeParty })}>
<Icons icon={globals.localeParty ? 'star' : 'starhollow'}/>
<IconButton
onClick={() => updateGlobals({ localeParty: !globals.localeParty })}
>
<Icons icon={globals.localeParty ? 'star' : 'starhollow'} />
<span>&nbsp;Shuffle i18n locale</span>
</IconButton>
)
);
},
})
})
});
});
16 changes: 9 additions & 7 deletions .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@ const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = {
stories: ['../ui/**/*.stories.js'],
stories: ['../ui/**/*.stories.js', '../ui/**/*.stories.mdx'],
addons: [
'@storybook/addon-knobs',
'@storybook/addon-essentials',
'@storybook/addon-actions',
'@storybook/addon-backgrounds',
'@storybook/addon-toolbars',
'@storybook/addon-a11y',
'@storybook/addon-knobs',
'./i18n-party-addon/register.js',
],
// Uses babel.config.js settings and prevents "Missing class properties transform" error
babel: async (options) => ({ overrides: options.overrides }),
webpackFinal: async (config) => {
config.context = process.cwd()
config.context = process.cwd();
config.node = {
__filename: true
}
__filename: true,
};
config.module.strictExportPresence = true;
config.module.rules.push({
test: /\.scss$/,
Expand Down
40 changes: 17 additions & 23 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import '../ui/css/index.scss';
import localeList from '../app/_locales/index.json';
import * as allLocales from './locales';
import { I18nProvider, LegacyI18nProvider } from './i18n';
import MetaMetricsProviderStorybook from './metametrics'
import MetaMetricsProviderStorybook from './metametrics';
import testData from './test-data.js';
import { Router } from "react-router-dom";
import { createBrowserHistory } from "history";
import { _setBackgroundConnection } from '../ui/store/actions'
import { Router } from 'react-router-dom';
import { createBrowserHistory } from 'history';
import { _setBackgroundConnection } from '../ui/store/actions';

addParameters({
backgrounds: {
Expand All @@ -38,28 +38,24 @@ export const globalTypes = {
},
};

const styles = {
height: '100vh',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
};

export const getNewState = (state, props) => {
return Object.assign(state, props);
}
};

export const store = configureStore(testData);
const history = createBrowserHistory();
const proxiedBackground = new Proxy({}, {
const proxiedBackground = new Proxy(
{},
{
get(_, method) {
return function() {
action(`Background call: ${method}`)()
return new Promise(() => {})
}
}
})
_setBackgroundConnection(proxiedBackground)
return function () {
action(`Background call: ${method}`)();
return new Promise(() => {});
};
},
},
);
_setBackgroundConnection(proxiedBackground);

const metamaskDecorator = (story, context) => {
const currentLocale = context.globals.locale;
Expand All @@ -73,9 +69,7 @@ const metamaskDecorator = (story, context) => {
current={current}
en={allLocales.en}
>
<LegacyI18nProvider>
<div style={styles}>{story()}</div>
</LegacyI18nProvider>
<LegacyI18nProvider>{story()}</LegacyI18nProvider>
</I18nProvider>
</MetaMetricsProviderStorybook>
</Router>
Expand Down
22 changes: 12 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,18 @@
"@metamask/forwarder": "^1.1.0",
"@metamask/test-dapp": "^4.0.1",
"@sentry/cli": "^1.58.0",
"@storybook/addon-actions": "^6.1.17",
"@storybook/addon-backgrounds": "^6.1.17",
"@storybook/addon-knobs": "^6.1.17",
"@storybook/addon-toolbars": "^6.1.17",
"@storybook/addons": "^6.1.7",
"@storybook/api": "^6.1.7",
"@storybook/components": "^6.1.7",
"@storybook/core": "^6.1.17",
"@storybook/react": "^6.1.17",
"@storybook/storybook-deployer": "^2.8.7",
"@storybook/addon-a11y": "^6.3.12",
"@storybook/addon-actions": "^6.3.12",
"@storybook/addon-essentials": "^6.3.12",
"@storybook/addon-knobs": "^6.3.1",
"@storybook/addons": "^6.3.12",
"@storybook/api": "^6.3.12",
"@storybook/components": "^6.3.12",
"@storybook/core": "^6.3.12",
"@storybook/core-events": "^6.3.0",
"@storybook/react": "^6.3.12",
"@storybook/storybook-deployer": "^2.8.10",
"@storybook/theming": "^6.3.0",
"@testing-library/jest-dom": "^5.11.10",
"@testing-library/react": "^10.4.8",
"@testing-library/react-hooks": "^3.2.1",
Expand Down
15 changes: 15 additions & 0 deletions ui/1.INTRODUCTION.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Meta } from '@storybook/addon-docs';

<Meta title="Getting Started / Introduction" />

# Introduction

Welcome to the MetaMask Browser Extension Storybook.

## Building locally and Contributing

This document is currently only specific to storybook best practices and component documentation guidelines. This may change in future but for now if you are looking to get a local build of Metamask up and running or contribute to the extension codebase please read the Metamask [README.md](https://github.com/MetaMask/metamask-extension)

## Documentation Guidelines

If you're here to improve our storybook documentation you're in the right place! Please head over to the [Documentation Guidelines](./?path=/story/getting-started-documentation-guidelines--page) for contributing to component documentation in storybook.
Loading

0 comments on commit d72f729

Please sign in to comment.