Skip to content

Commit bff45c6

Browse files
authored
Merge pull request #11 from Carifio24/storybook
Set up Storybook and use that for documentation
2 parents 78e7066 + e57cbe5 commit bff45c6

File tree

11 files changed

+7687
-401
lines changed

11 files changed

+7687
-401
lines changed

.eslintrc.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ module.exports = {
99
'@typescript-eslint',
1010
],
1111
extends: [
12-
'eslint:recommended',
13-
'plugin:@typescript-eslint/eslint-recommended',
14-
'plugin:@typescript-eslint/recommended',
15-
'plugin:vue/essential',
16-
'@vue/typescript/recommended'
12+
"eslint:recommended",
13+
"plugin:@typescript-eslint/eslint-recommended",
14+
"plugin:@typescript-eslint/recommended",
15+
"plugin:vue/essential",
16+
"@vue/typescript/recommended",
17+
"plugin:storybook/recommended"
1718
],
1819
rules: {
1920
"indent": ["error", 2],

.github/workflows/build-deploy-docs.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ jobs:
3232
- name: Build
3333
run: yarn build
3434

35-
- name: Build docs
36-
run: yarn docs
35+
- name: Build Storybook
36+
run: yarn build-storybook
3737

38-
- name: Deploy docs to GitHub Pages
38+
- name: Deploy to GitHub Pages
3939
uses: JamesIves/github-pages-deploy-action@v4
4040
with:
4141
branch: gh-pages

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ jobs:
3434
- name: Build
3535
run: yarn build
3636

37-
- name: Build docs
38-
run: yarn docs
37+
- name: Build Storybook
38+
run: yarn build-storybook
3939

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ tsconfig.tsbuildinfo
2626
*.env
2727

2828
docs/
29+
30+
*storybook.log

.storybook/main.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import type { StorybookConfig } from "@storybook/vue3-webpack5";
2+
3+
const config: StorybookConfig = {
4+
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
5+
addons: [
6+
"@storybook/addon-webpack5-compiler-swc",
7+
"@storybook/addon-links",
8+
"@storybook/addon-essentials",
9+
"@chromatic-com/storybook",
10+
"@storybook/addon-interactions",
11+
"storybook-dark-mode",
12+
],
13+
framework: {
14+
name: "@storybook/vue3-webpack5",
15+
options: {},
16+
},
17+
docs: {
18+
autodocs: "tag",
19+
},
20+
webpackFinal: async (config) => {
21+
config.module?.rules?.push({
22+
test: /\.less/,
23+
sideEffects: true,
24+
use: ["style-loader", "css-loader", "less-loader"],
25+
});
26+
config.module?.rules?.push({
27+
test: /\.md/,
28+
use: ["markdown-loader"]
29+
});
30+
31+
// Remove existing mdx rule if any (but should be none)
32+
// config.module?.rules = config.module?.rules?.filter((f) => f && f != false && f?.test?.toString() !== '/\\.mdx$/')
33+
34+
config.module?.rules?.push({
35+
test: /\.mdx$/,
36+
use: ['@mdx-js/loader'],
37+
});
38+
return config;
39+
},
40+
};
41+
export default config;

.storybook/preview.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { setup, type Preview } from "@storybook/vue3";
2+
3+
import { createVuetify } from 'vuetify';
4+
import * as components from 'vuetify/components';
5+
import * as directives from 'vuetify/directives';
6+
7+
const vuetify = createVuetify({
8+
components,
9+
directives
10+
});
11+
12+
setup((app) => {
13+
app.use(vuetify);
14+
});
15+
16+
const preview: Preview = {
17+
// TODO: This is what storybook tells us to do:
18+
// https://storybook.js.org/docs/writing-docs/autodocs
19+
// but doesn't seem to work. Why not?
20+
// For now, we can work around this by marking each story
21+
// with this tag
22+
// tags: ["autodocs"],
23+
parameters: {
24+
controls: {
25+
matchers: {
26+
color: /(background|color)$/i,
27+
date: /Date$/i,
28+
},
29+
},
30+
},
31+
};
32+
33+
export default preview;

package.json

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,40 @@
1717
"vuetify": "^3.3.3"
1818
},
1919
"devDependencies": {
20+
"@chromatic-com/storybook": "^1.3.3",
21+
"@storybook/addon-essentials": "^8.0.9",
22+
"@storybook/addon-interactions": "^8.0.9",
23+
"@storybook/addon-links": "^8.0.9",
24+
"@storybook/addon-webpack5-compiler-swc": "^1.0.2",
25+
"@storybook/blocks": "^8.0.9",
26+
"@storybook/test": "^8.0.9",
27+
"@storybook/vue3": "^8.0.9",
28+
"@storybook/vue3-webpack5": "^8.0.9",
2029
"@types/leaflet": "^1.9.11",
2130
"@typescript-eslint/eslint-plugin": "^6.19.0",
2231
"@typescript-eslint/parser": "^6.19.0",
2332
"@vue/cli-plugin-eslint": "^5.0.8",
2433
"@vue/cli-plugin-typescript": "^5.0.8",
2534
"@vue/cli-service": "^5.0.8",
35+
"@vue/compiler-sfc": "^3.4.25",
2636
"@vue/eslint-config-typescript": "^12.0.0",
2737
"copy-webpack-plugin": "^12.0.2",
38+
"css-loader": "^7.1.1",
2839
"eslint": "^8.31.0",
40+
"eslint-plugin-storybook": "^0.8.0",
2941
"eslint-plugin-vue": "^9.8.0",
3042
"less": "^4.2.0",
3143
"less-loader": "^12.1.0",
44+
"markdown-loader": "^8.0.0",
45+
"storybook": "^8.0.9",
46+
"storybook-css-modules-preset": "^1.1.1",
47+
"storybook-dark-mode": "^4.0.1",
48+
"style-loader": "^4.0.0",
3249
"typedoc": "^0.25.13",
50+
"typedoc-plugin-markdown": "^3.17.1",
3351
"typedoc-plugin-vue": "^1.1.0",
3452
"typescript": "^4.9.4",
53+
"vue-loader": "^17.4.2",
3554
"vue-template-compiler": "^2.7.14",
3655
"webpack": "^5.75.0"
3756
},
@@ -48,8 +67,10 @@
4867
"scripts": {
4968
"build": "vue-cli-service build --target lib --name index src/index.ts",
5069
"clean": "rimraf dist",
51-
"docs": "typedoc",
52-
"lint": "vue-cli-service lint src --no-fix"
70+
"docs": "typedoc --plugin typedoc-plugin-markdown",
71+
"lint": "vue-cli-service lint src --no-fix",
72+
"storybook": "storybook dev -p 6006 --debug",
73+
"build-storybook": "storybook build -o docs"
5374
},
5475
"types": "./dist/src/index.d.ts"
5576
}

src/stories/CreditLogos.stories.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* eslint-disable @typescript-eslint/naming-convention */
2+
3+
import { Meta, StoryObj } from "@storybook/vue3";
4+
import { CreditLogosProps } from "../types";
5+
import CreditLogos from "../components/CreditLogos.vue";
6+
7+
const meta: Meta<typeof CreditLogos> = {
8+
component: CreditLogos,
9+
tags: ["autodocs"],
10+
};
11+
12+
export default meta;
13+
type Story = StoryObj<typeof CreditLogos>;
14+
15+
export const Primary: Story = {
16+
render: (args: CreditLogosProps) => ({
17+
components: { CreditLogos },
18+
template: `<CreditLogos v-bind="args" />`,
19+
setup() {
20+
return { args };
21+
}
22+
}),
23+
args: {
24+
logoSize: "5vmin",
25+
extraLogos: [
26+
{
27+
alt: "Smithsonian Logo",
28+
src: "https://upload.wikimedia.org/wikipedia/commons/thumb/c/c4/Smithsonian_sun_logo_no_text.svg/1024px-Smithsonian_sun_logo_no_text.svg.png",
29+
href: "https://www.si.edu/"
30+
}
31+
],
32+
defaultLogos: ["wwt", "cosmicds", "nasa", "sciact"],
33+
}
34+
};

src/stories/IconButton.stories.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/* eslint-disable @typescript-eslint/naming-convention */
2+
3+
import { Meta, StoryObj } from "@storybook/vue3";
4+
import { IconButtonProps } from "../types";
5+
import IconButton from "../components/IconButton.vue";
6+
7+
import { library } from "@fortawesome/fontawesome-svg-core";
8+
import { faBookOpen } from "@fortawesome/free-solid-svg-icons";
9+
10+
library.add(faBookOpen);
11+
12+
const meta: Meta<typeof IconButton> = {
13+
component: IconButton,
14+
tags: ["autodocs"],
15+
};
16+
17+
export default meta;
18+
type Story = StoryObj<typeof IconButton>;
19+
20+
export const Primary: Story = {
21+
render: (args: IconButtonProps) => ({
22+
components: { IconButton },
23+
template: `<IconButton v-bind="args" />`,
24+
setup() {
25+
return { args };
26+
}
27+
}),
28+
decorators: [
29+
() => {
30+
return { template: `<div style="width: 50px"><story /></div>` };
31+
}
32+
],
33+
args: {
34+
modelValue: false,
35+
faIcon: "book-open",
36+
mdIcon: null,
37+
color: "white",
38+
focusColor: "red",
39+
backgroundColor: "#040404",
40+
boxShadow: true,
41+
border: true,
42+
longPressTimeMs: 500,
43+
tooltipText: "Tooltip",
44+
tooltipLocation: "start",
45+
tooltipOnClick: false,
46+
tooltipOnFocus: false,
47+
tooltipOnHover: true,
48+
showTooltip: true,
49+
faSize: "lg",
50+
mdSize: "100px"
51+
}
52+
};

typedoc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"$schema": "https://typedoc.org/schema.json",
33
"entryPoints": ["./src/index.ts"],
44
"out": "docs",
5-
"exclude": ["**/*.vue", "src/shims-vue.d.ts"]
5+
"exclude": ["**/*.vue", "src/shims-vue.d.ts", "src/stories/**"]
66
}

0 commit comments

Comments
 (0)