Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storybook components #96

Merged
merged 39 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
05d2923
Merge with preexisting storybook error
katherinejensen00 Mar 2, 2023
773446a
Incorporate StorybookWebpackConfig with our WebpackRendererConfig
katherinejensen00 Mar 2, 2023
d405033
WIP: Button Wrapper of MUI Button component (Icons not working yet)
katherinejensen00 Mar 9, 2023
829b595
WIP: Fix Bugs and add more functionality to button
katherinejensen00 Mar 10, 2023
aaac7bb
Improved Button argTypes controls
rolfheij-sil Mar 13, 2023
4bd4244
Fixed small bug in Button css
rolfheij-sil Mar 14, 2023
ba5d9a5
Added basic slider
rolfheij-sil Mar 14, 2023
d88f1c2
Merge branch 'main' into 39-storybook
rolfheij-sil Mar 14, 2023
80d4d68
Merge remote-tracking branch 'origin/main' into 39-storybook
rolfheij-sil Mar 15, 2023
fdc8250
Finished slider component
rolfheij-sil Mar 15, 2023
bbabd07
Small fix
rolfheij-sil Mar 15, 2023
c53a04e
Cleanup
rolfheij-sil Mar 17, 2023
ba49cca
Add Textfield component
rolfheij-sil Mar 17, 2023
9da4373
Remove children prop from Textfield
rolfheij-sil Mar 17, 2023
1875f79
Add a bunch of components (#40)
rolfheij-sil Mar 20, 2023
9f5ffe4
Merge branch 'main' into 39-storybook
rolfheij-sil Mar 20, 2023
bed9587
Decided not to use css modules for the moment
katherinejensen00 Mar 20, 2023
c35b10a
Cleaned up and aligned code for all components
rolfheij-sil Mar 21, 2023
8e43f47
Merge branch 'main' into 39-storybook
rolfheij-sil Mar 21, 2023
960ff75
Fix npm test / es-lint issues
rolfheij-sil Mar 21, 2023
f2bbf19
Processed review comments
rolfheij-sil Mar 22, 2023
3d78608
Merge branch 'main' into 39-storybook
rolfheij-sil Mar 22, 2023
1e1ef03
Restore parts of Storybook main
rolfheij-sil Mar 22, 2023
3c1072e
Restored PButton
rolfheij-sil Mar 22, 2023
caba924
Remove devServer from renderedConfig
rolfheij-sil Mar 22, 2023
eb4a3f7
#96 Replace PButton and remove unnecessary icons
katherinejensen00 Mar 22, 2023
beb30fa
Processed more review comments
rolfheij-sil Mar 23, 2023
ca349be
Merge branch '39-storybook' of https://github.com/paranext/paranext-c…
rolfheij-sil Mar 23, 2023
4a517fe
Remove reference to PButton
rolfheij-sil Mar 23, 2023
29f4ffc
Breaking filename on purpose, because changing a lowercase letter to …
rolfheij-sil Mar 23, 2023
95eb2ac
Restoring fill name with proper capital letters
rolfheij-sil Mar 23, 2023
ff59bc6
Merge branch 'main' into 39-storybook
rolfheij-sil Mar 23, 2023
f1e4f7f
Rewrote commit, processed more review comments
rolfheij-sil Mar 27, 2023
17f4170
Processed more review comments
rolfheij-sil Mar 28, 2023
c3ff392
Potentially final commit to this branch
rolfheij-sil Mar 28, 2023
06fa45d
Merge branch 'main' into 39-storybook
rolfheij-sil Mar 28, 2023
71bd5f4
Updated readme
rolfheij-sil Mar 28, 2023
453d309
Restore CSS rules and update stories
rolfheij-sil Mar 29, 2023
43ab5d9
Merge branch 'main' into 39-storybook
rolfheij-sil Mar 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .babelrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"sourceType": "unambiguous",
"presets": [
[
"@babel/preset-env",
{
"targets": {
"chrome": 100
}
}
],
"@babel/preset-typescript",
"@babel/preset-react"
],
"plugins": []
}
5 changes: 4 additions & 1 deletion .erb/configs/webpack.config.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import webpackPaths from './webpack.paths';
import { dependencies as externals } from '../../release/app/package.json';

let processType: string;
if (process.env.npm_lifecycle_script?.includes('webpack.config.renderer'))
if (
process.env.npm_lifecycle_script?.includes('webpack.config.renderer') ||
process.env.npm_lifecycle_script?.includes('storybook')
)
processType = 'renderer';
else if (
process.env.npm_lifecycle_script?.includes('webpack.config.extension-host')
Expand Down
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ npm-debug.log.*
# eslint ignores hidden directories by default:
# https://github.com/eslint/eslint/issues/8429
!.erb
!.storybook
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = {
extends: 'erb', // https://github.com/electron-react-boilerplate/eslint-config-erb/blob/main/index.js
extends: ['erb', 'plugin:storybook/recommended'], // https://github.com/electron-react-boilerplate/eslint-config-erb/blob/main/index.js
// https://github.com/storybookjs/eslint-plugin-storybook/blob/main/lib/configs/recommended.ts
// airbnb rules are embedded in erb https://github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb
rules: {
// #region ERB rules
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ node_modules
release/app/dist
release/build
.erb/dll
storybook-static

.idea
npm-debug.log.*
Expand Down
83 changes: 83 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import type { StorybookConfig } from '@storybook/react-webpack5';
import { mergeWithCustomize } from 'webpack-merge';
import { RuleSetRule } from 'webpack';

const config: StorybookConfig = {
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
addons: [
'@storybook/addon-links',
'@storybook/addon-essentials',
'@storybook/addon-interactions',
],
framework: {
name: '@storybook/react-webpack5',
options: {},
},
docs: {
autodocs: 'tag',
},
typescript: {
check: false,
checkOptions: {},
reactDocgen: 'react-docgen-typescript',
reactDocgenTypescriptOptions: {
// speeds up storybook build time
// @ts-expect-error The following line is interpreted as an error even though it isn't
allowSyntheticDefaultImports: false,
// speeds up storybook build time
esModuleInterop: false,
},
},

// Merge StorybookWebpackConfig with our WebpackRendererConfig
// See the current webpack configuration using npm run storybook -- --debug-webpack
// TODO: Make this work in production mode
webpackFinal: async (webpackConfig, { configType }) => {
const rendererConfig =
configType === 'PRODUCTION'
? // Storybook is a build tool so this will not affect anything
// eslint-disable-next-line global-require
require('../.erb/configs/webpack.config.renderer.prod').default
: // eslint-disable-next-line global-require
require('../.erb/configs/webpack.config.renderer.dev').default;
// Remove configs that break stuff (https://storybook.js.org/docs/react/builders/webpack#extending-storybooks-webpack-config)
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { devServer, entry, output, ...rendererConfigSanitized } =
rendererConfig;

// Remove the Storybook Webpack rules that we already have our own rules for
return mergeWithCustomize({
customizeObject(wpConfig: object, rConfig: object, key: string) {
if (key === 'module') {
return mergeWithCustomize({
customizeArray(
wpModule: object[],
rModule: object[],
moduleKey: string,
) {
if (moduleKey === 'rules') {
const wpRules = wpModule as RuleSetRule[];
const rRules = rModule as RuleSetRule[];
return [
...wpRules.filter(
(rule) =>
!rule ||
!rule.test ||
(rule.test.toString() !== /\.css$/.toString() &&
rule.test.toString() !==
/\.(mjs|tsx?|jsx?)$/.toString()),
),
...rRules,
];
}

return undefined;
},
})(wpConfig, rConfig);
}
return undefined;
},
})(webpackConfig, rendererConfigSanitized);
},
};
export default config;
18 changes: 18 additions & 0 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { Preview } from '@storybook/react';

const preview: Preview = {
parameters: {
backgrounds: {
default: 'light',
},
actions: { argTypesRegex: '^on[A-Z].*' },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
},
};

export default preview;
9 changes: 9 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@
"env": {
"IN_VSCODE": "true"
}
},
{
"name": "Storybook",
"type": "node",
"request": "launch",
"protocol": "inspector",
"runtimeExecutable": "npm",
"runtimeArgs": ["run", "storybook"],
"env": { "autoAttachChildProcesses": true }
}
],
"compounds": [
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,26 @@ npm run package
8. Publish the release on GitHub.
9. Merge the release branch back into **main** with a merge commit.

## Storybook

To run Storybook locally:

```bash
npm run storybook
```

To build Storybook:

```bash
npm run storybook:build
```

To run Storybook as a web app:

```bash
npm run storybook:build {path to storybook-static folder}
```

## Windows Development with WSL2

On Windows, you can install [WSL](https://learn.microsoft.com/en-us/windows/wsl/) (Windows Subsystem for Linux) so you can test cross-platform compatibility on Linux (as well as Windows). You'll need to use a Linux distribution with WSL2 (rather than WSL1) so the X-Server windows can be opened for Electron.
Expand Down
10 changes: 5 additions & 5 deletions extensions/hello-world/hello-world.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const getReactComponent = (name, functionModifier = '') =>
react: {
context: { TestContext },
hooks: { usePromise },
components: { PButton }
components: { Button }
},
logger
} = papi;
Expand Down Expand Up @@ -46,10 +46,10 @@ const getReactComponent = (name, functionModifier = '') =>
return createElement('div', null,
createElement('div', null,
createElement(
PButton,
Button,
{
onClick: () => {
logger.log('${name} PButton clicked!');
logger.log('${name} Button clicked!');
setMyState(myStateCurrent => myStateCurrent + 1);
papi.fetch('https://bible-api.com/matthew+24:14')
.then((res) => res.json())
Expand All @@ -59,7 +59,7 @@ const getReactComponent = (name, functionModifier = '') =>
);
}
},
'Hello World PButton ',
'Hello World Button ',
myState
)
),
Expand All @@ -71,7 +71,7 @@ const getReactComponent = (name, functionModifier = '') =>
),
createElement('div', null,
createElement(
PButton,
Button,
{
onClick: () => {
throw new Error('${name} test exception!');
Expand Down
Loading