Skip to content

Commit

Permalink
feat(storybook): + Storybook v7.6.19 without MDX support
Browse files Browse the repository at this point in the history
+ custom global script to call bundled storybook
+ example component
  • Loading branch information
dark-kitt committed May 12, 2024
1 parent c2f322f commit 568fefa
Show file tree
Hide file tree
Showing 9 changed files with 8,725 additions and 767 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/yarn-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ jobs:
run: npm install
- name: Ensure the integrity of packages from the public npm registry
run: npm audit signatures
- name: Bundle library
- name: Bundle Vue 3 library
run: npm run build
- name: Bundle Storybook
run: npm run build-storybook
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GTHB_TOKEN }}
Expand Down
28 changes: 28 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { StorybookConfig } from '@storybook/vue3-vite';

import { join, dirname } from 'path';

/**
* This function is used to resolve the absolute path of a package.
* It is needed in projects that use Yarn PnP or are set up within a monorepo.
*/
const getAbsolutePath = (value: string): string => {
return dirname(require.resolve(join(value, 'package.json')));
};

const config: StorybookConfig = {
stories: ['../src/components/**/*.stories.ts'],
addons: [
getAbsolutePath('@storybook/addon-links'),
getAbsolutePath('@storybook/addon-essentials'),
getAbsolutePath('@storybook/addon-interactions')
],
framework: {
name: '@storybook/vue3-vite',
options: {}
},
docs: {
autodocs: 'tag'
}
};
export default config;
15 changes: 15 additions & 0 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { Preview } from '@storybook/vue3';

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

export default preview;
52 changes: 50 additions & 2 deletions bin/vue-ts-docs.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,51 @@
#!/usr/bin/env node
// @ts-check
(() => console.log('Inside docs!'))();
import { dirname, resolve } from 'path';
import { fileURLToPath } from 'url';
import { exec } from 'child_process';

import express from 'express';
import portfinder from 'portfinder';
// colors
const RED = '\x1b[31m';
const BLUE = '\x1b[36m';
const GREEN = '\x1b[32m';
const RESET = '\x1b[0m';
// sever
const PORT = 8080;
portfinder.setBasePort(PORT);
(() => {
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

portfinder.getPort(function (err, port) {
if (err) {
console.error(`${BLUE}[vue-ts-docs]${RED}[ERROR]${RESET}:\n${err}`);
return false;
}

const server = express();
const path = resolve(__dirname, '../dist/storybook');
// set up server
server.use(express.static(path));
server.get('*', (req, res) => {
res.sendFile(path + '/index.html');
});

server.listen(port, () => {
// log status
console.log(
`${BLUE}[vue-ts-docs]${GREEN}[INFO]${RESET}: Docs started!\n\n${[
'Server listening on:',
`${GREEN}http://127.0.0.1:${port}${RESET}`,
`${GREEN}http://localhost:${port}${RESET}`,
'\nCancel the process with [ctrl + c]\n'
].join('\n ')}`
);

const start =
process.platform == 'darwin' ? 'open' : process.platform == 'win32' ? 'start' : 'xdg-open';
// open default browser
exec(`${start} http://localhost:${port}`);
});
});
})();
19 changes: 18 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,17 @@
"@semantic-release/git": "^10.0.1",
"@semantic-release/npm": "^12.0.0",
"@semantic-release/release-notes-generator": "^13.0.0",
"@storybook/addon-essentials": "7.6.19",
"@storybook/addon-interactions": "7.6.19",
"@storybook/addon-links": "7.6.19",
"@storybook/blocks": "7.6.19",
"@storybook/test": "7.6.19",
"@storybook/vue3": "7.6.19",
"@storybook/vue3-vite": "7.6.19",
"@types/express": "^4",
"@types/node": "^20.12.10",
"@types/react": "^18",
"@types/react-dom": "^18",
"@typescript-eslint/eslint-plugin": "^7.8.0",
"@typescript-eslint/parser": "^7.8.0",
"@vitejs/plugin-vue": "^5.0.4",
Expand All @@ -27,13 +37,18 @@
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-vue": "^9.25.0",
"prettier": "^3.2.5",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"sass": "^1.77.0",
"storybook": "7.6.19",
"typescript": "^5.4.5",
"vite": "^5.2.11",
"vite-plugin-dts": "^3.9.1",
"vue-eslint-parser": "^9.4.2"
},
"dependencies": {
"express": "^4.19.2",
"portfinder": "^1.0.32",
"vue": "^3.4.27"
},
"type": "module",
Expand All @@ -48,7 +63,9 @@
},
"types": "./dist/index.d.ts",
"scripts": {
"build": "vite build"
"build": "vite build",
"storybook": "CACHE_DIR=\"./.yarn/cache\" storybook dev -p 6006",
"build-storybook": "CACHE_DIR=\"./.yarn/cache\" storybook build -o dist/storybook"
},
"bin": {
"vue-ts-docs": "./bin/vue-ts-docs.js"
Expand Down
10 changes: 5 additions & 5 deletions src/@types/components/Button/Button.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ButtonHTMLAttributes } from 'vue';
import { ButtonHTMLAttributes } from '../../../vue/dist/vue.esm-bundler.js';

export interface Props {
primary?: boolean;
size?: 'small' | 'medium' | 'large';
text: string;
HTMLAttributes?: ButtonHTMLAttributes;
}
declare const _default: import('vue').DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<Props>, {
declare const _default: import('../../../vue/dist/vue.esm-bundler.js').DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<Props>, {
primary: boolean;
size: string;
text: string;
Expand All @@ -15,7 +15,7 @@ declare const _default: import('vue').DefineComponent<__VLS_WithDefaults<__VLS_T
type: "button" | "submit" | "reset" | undefined;
disabled: boolean;
};
}>, {}, unknown, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<Props>, {
}>, {}, unknown, {}, {}, import('../../../vue/dist/vue.esm-bundler.js').ComponentOptionsMixin, import('../../../vue/dist/vue.esm-bundler.js').ComponentOptionsMixin, {}, string, import('../../../vue/dist/vue.esm-bundler.js').PublicProps, Readonly<import('../../../vue/dist/vue.esm-bundler.js').ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<Props>, {
primary: boolean;
size: string;
text: string;
Expand All @@ -34,9 +34,9 @@ export default _default;
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
type __VLS_TypePropsToRuntimeProps<T> = {
[K in keyof T]-?: {} extends Pick<T, K> ? {
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
type: import('../../../vue/dist/vue.esm-bundler.js').PropType<__VLS_NonUndefinedable<T[K]>>;
} : {
type: import('vue').PropType<T[K]>;
type: import('../../../vue/dist/vue.esm-bundler.js').PropType<T[K]>;
required: true;
};
};
Expand Down
68 changes: 68 additions & 0 deletions src/@types/components/Button/Button.stories.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { StoryObj } from '@storybook/vue3';

declare const meta: {
title: string;
component: import('../../../vue/dist/vue.esm-bundler.js').DefineComponent<{
primary: {
type: import('../../../vue/dist/vue.esm-bundler.js').PropType<boolean>;
default: boolean;
};
size: {
type: import('../../../vue/dist/vue.esm-bundler.js').PropType<"small" | "medium" | "large">;
default: string;
};
text: {
type: import('../../../vue/dist/vue.esm-bundler.js').PropType<string>;
required: true;
default: string;
};
HTMLAttributes: {
type: import('../../../vue/dist/vue.esm-bundler.js').PropType<import('../../../vue/dist/vue.esm-bundler.js').ButtonHTMLAttributes>;
default: () => {
name: string;
type: "button" | "submit" | "reset" | undefined;
disabled: boolean;
};
};
}, {}, unknown, {}, {}, import('../../../vue/dist/vue.esm-bundler.js').ComponentOptionsMixin, import('../../../vue/dist/vue.esm-bundler.js').ComponentOptionsMixin, {}, string, import('../../../vue/dist/vue.esm-bundler.js').PublicProps, Readonly<import('../../../vue/dist/vue.esm-bundler.js').ExtractPropTypes<{
primary: {
type: import('../../../vue/dist/vue.esm-bundler.js').PropType<boolean>;
default: boolean;
};
size: {
type: import('../../../vue/dist/vue.esm-bundler.js').PropType<"small" | "medium" | "large">;
default: string;
};
text: {
type: import('../../../vue/dist/vue.esm-bundler.js').PropType<string>;
required: true;
default: string;
};
HTMLAttributes: {
type: import('../../../vue/dist/vue.esm-bundler.js').PropType<import('../../../vue/dist/vue.esm-bundler.js').ButtonHTMLAttributes>;
default: () => {
name: string;
type: "button" | "submit" | "reset" | undefined;
disabled: boolean;
};
};
}>>, {
primary: boolean;
size: "small" | "medium" | "large";
text: string;
HTMLAttributes: import('../../../vue/dist/vue.esm-bundler.js').ButtonHTMLAttributes;
}, {}>;
tags: string[];
argTypes: {
size: {
control: string;
options: string[];
};
};
args: {
primary: false;
};
};
export default meta;
type Story = StoryObj<typeof meta>;
export declare const Primary: Story;
32 changes: 32 additions & 0 deletions src/components/Button/Button.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { Meta, StoryObj } from '@storybook/vue3';

import { default as Button } from './Button.vue';

// More on how to set up stories at: https://storybook.js.org/docs/writing-stories
const meta = {
title: 'Components/Button',
component: Button,
// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/writing-docs/autodocs
tags: ['autodocs'],
argTypes: {
size: { control: 'select', options: ['small', 'medium', 'large'] }
},
args: {
primary: false
// Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#action-args
}
} satisfies Meta<typeof Button>;

export default meta;
type Story = StoryObj<typeof meta>;
/*
*👇 Render functions are a framework specific feature to allow you control on how the component renders.
* See https://storybook.js.org/docs/api/csf
* to learn how to use render functions.
*/
export const Primary: Story = {
args: {
primary: true,
text: 'Button'
}
};
Loading

0 comments on commit 568fefa

Please sign in to comment.