Skip to content

Commit 24652a8

Browse files
authored
Merge pull request #1497 from github/koesie10/storybook
Setup Storybook for testing UI components
2 parents 7c4eac8 + 2ee46cf commit 24652a8

28 files changed

+58628
-10582
lines changed

.gitattributes

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,8 @@ yarn.lock merge=binary
1818
# https://mirrors.edge.kernel.org/pub/software/scm/git/docs/gitattributes.html
1919
# suggests that this might interleave lines arbitrarily, but empirically
2020
# it keeps added chunks contiguous
21-
CHANGELOG.md merge=union
21+
CHANGELOG.md merge=union
22+
23+
# Mark some JSON files containing test data as generated so they are not included
24+
# as part of diffs or language statistics.
25+
extensions/ql-vscode/src/stories/remote-queries/data/*.json linguist-generated

.vscode/launch.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@
124124
"outFiles": [
125125
"${workspaceRoot}/extensions/ql-vscode/out/**/*.js",
126126
],
127+
},
128+
{
129+
"name": "Launch Storybook",
130+
"type": "node",
131+
"request": "launch",
132+
"cwd": "${workspaceFolder}/extensions/ql-vscode",
133+
"runtimeExecutable": "npm",
134+
"runtimeArgs": ["run-script", "storybook"]
127135
}
128136
]
129137
}

CONTRIBUTING.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,20 @@ $ vscode/scripts/code-cli.sh --install-extension dist/vscode-codeql-*.vsix # if
7777

7878
You can use VS Code to debug the extension without explicitly installing it. Just open this directory as a workspace in VS Code, and hit `F5` to start a debugging session.
7979

80+
### Storybook
81+
82+
You can use [Storybook](https://storybook.js.org/) to preview React components outside VSCode. Inside the `extensions/ql-vscode` directory, run:
83+
84+
```shell
85+
npm run storybook
86+
```
87+
88+
Your browser should automatically open to the Storybook UI. Stories live in the `src/stories` directory.
89+
90+
Alternatively, you can start Storybook inside of VSCode. There is a VSCode launch configuration for starting Storybook. It can be found in the debug view.
91+
92+
More information about Storybook can be found inside the **Overview** page once you have launched Storybook.
93+
8094
### Running the unit tests and integration tests that do not require a CLI instance
8195

8296
Unit tests and many integration tests do not require a copy of the CodeQL CLI.

extensions/ql-vscode/.npmrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Storybook requires this option to be set. See https://github.com/storybookjs/storybook/issues/18298
2+
legacy-peer-deps=true
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type { StorybookConfig } from '@storybook/core-common';
2+
3+
const config: StorybookConfig = {
4+
stories: [
5+
'../src/**/*.stories.mdx',
6+
'../src/**/*.stories.@(js|jsx|ts|tsx)'
7+
],
8+
addons: [
9+
'@storybook/addon-links',
10+
'@storybook/addon-essentials',
11+
'@storybook/addon-interactions'
12+
],
13+
framework: '@storybook/react',
14+
core: {
15+
builder: '@storybook/builder-webpack5'
16+
}
17+
};
18+
19+
module.exports = config;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { addons } from '@storybook/addons';
2+
import { themes } from '@storybook/theming';
3+
4+
addons.setConfig({
5+
theme: themes.dark,
6+
enableShortcuts: false,
7+
});
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { themes } from '@storybook/theming';
2+
import { action } from '@storybook/addon-actions';
3+
4+
// Allow all stories/components to use Codicons
5+
import '@vscode/codicons/dist/codicon.css';
6+
7+
import '../src/stories/vscode-theme.css';
8+
9+
// https://storybook.js.org/docs/react/configure/overview#configure-story-rendering
10+
export const parameters = {
11+
// All props starting with `on` will automatically receive an action as a prop
12+
actions: { argTypesRegex: "^on[A-Z].*" },
13+
// All props matching these names will automatically get the correct control
14+
controls: {
15+
matchers: {
16+
color: /(background|color)$/i,
17+
date: /Date$/,
18+
},
19+
},
20+
// Use a dark theme to be aligned with VSCode
21+
docs: {
22+
theme: themes.dark,
23+
},
24+
backgrounds: {
25+
default: 'dark',
26+
values: [
27+
{
28+
name: 'dark',
29+
value: '#1e1e1e',
30+
},
31+
],
32+
}
33+
};
34+
35+
(window as any).acquireVsCodeApi = () => ({
36+
postMessage: action('post-vscode-message')
37+
});

0 commit comments

Comments
 (0)