Skip to content

Commit

Permalink
Merge pull request #4 from chenz24/feat/components
Browse files Browse the repository at this point in the history
Add components package and setup storybook and unit testing
  • Loading branch information
chenz24 authored Aug 27, 2021
2 parents 1360eb3 + 5636f81 commit 8c53f1e
Show file tree
Hide file tree
Showing 33 changed files with 1,598 additions and 3 deletions.
8 changes: 8 additions & 0 deletions configs/jest/enzyme.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const Enzyme = require('enzyme');
const Adapter = require('@wojtekmaj/enzyme-adapter-react-17');
const React = require('react');

// Fix broken layout effects on testing environments
React.useLayoutEffect = React.useEffect;

Enzyme.configure({ adapter: new Adapter() });
13 changes: 13 additions & 0 deletions configs/jest/jsdom.mocks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation((query) => ({
matches: false,
media: query,
onchange: null,
addListener: jest.fn(),
removeListener: jest.fn(),
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
})),
});
31 changes: 31 additions & 0 deletions configs/storybook/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* eslint-disable no-param-reassign */
const path = require('path');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin').default;

module.exports = {
stories: [
path.resolve(__dirname, '../../packages/**/*.story.@(ts|tsx)').replace(/\\/g, '/'),
// path.resolve(__dirname, './stories.tsx').replace(/\\/g, '/'),
],
addons: ['storybook-addon-turbo-build', '@storybook/addon-docs'],
typescript: {
reactDocgen: false,
},
webpackFinal: async (config) => {
config.resolve = {
...config.resolve,
plugins: [
...(config.resolve.plugins || []),
new TsconfigPathsPlugin({
extensions: ['.ts', '.tsx', '.js'],
configFile: path.join(__dirname, '../../tsconfig.json'),
}),
],
};

// Turn off docgen plugin as it breaks bundle with displayName
config.plugins.pop();

return config;
},
};
12 changes: 12 additions & 0 deletions configs/storybook/preview-head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<link rel="preconnect" href="https://fonts.gstatic.com" />

<link
href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap"
rel="stylesheet"
/>

<link rel="preconnect" href="https://fonts.gstatic.com" />
<link
href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:ital,wght@0,400;0,500;0,700;1,500&display=swap"
rel="stylesheet"
/>
13 changes: 13 additions & 0 deletions configs/storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import { CssBaseline, KubedConfigProvider } from '../../packages/components/src/index';

export const parameters = {};

export const decorators = [
(Story) => (
<KubedConfigProvider themeType="light">
<CssBaseline />
<Story />
</KubedConfigProvider>
),
];
14 changes: 14 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
transform: {
// https://github.com/aelbore/esbuild-jest/issues/21
'^.+\\.tsx?$': '@sucrase/jest-plugin',
},
testMatch: ['**/__tests__/**/*.ts?(x)', '**/?(*.)+(spec|test).ts?(x)'],
setupFilesAfterEnv: [
'./configs/jest/enzyme.setup.js',
'./configs/jest/jsdom.mocks.js',
],
moduleNameMapper: {
'@kubed/(.*)': '<rootDir>/packages/$1/src',
},
};
Empty file added packages/components/README.md
Empty file.
33 changes: 33 additions & 0 deletions packages/components/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "@kubed/components",
"description": "React components library for KubeSphere console.",
"version": "0.0.1",
"main": "cjs/index.js",
"module": "esm/index.js",
"browser": "lib/index.umd.js",
"types": "lib/src/index.d.ts",
"license": "MIT",
"sideEffects": false,
"repository": {
"url": "https://github.com/kubesphere/kube-design.git",
"type": "git",
"directory": "packages/components"
},
"peerDependencies": {
"@kubed/hooks": "0.0.1",
"@kubed/icons": "0.0.1",
"react": ">=16.8.0",
"react-dom": ">=16.8.0",
"react-is": "^17.0.2"
},
"dependencies": {
"@tippyjs/react": "^4.2.5",
"clsx": "^1.1.1",
"react-textarea-autosize": "^8.3.2",
"react-transition-group": "^4.4.2",
"react-feather": "^2.0.9"
},
"devDependencies": {
"@kubed/tests": "0.0.1"
}
}
36 changes: 36 additions & 0 deletions packages/components/src/Button/Button.story.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react';
import { storiesOf } from '@storybook/react';
import { Add } from '@kubed/icons';
import { Group } from '../Group/Group';
import { Button } from './Button';

storiesOf('@kubed/components/Button', module)
.addParameters({ component: Button })
.add('Demos', () => (
<Group spacing="xl">
<Button variant="filled" color="secondary" shadow radius="xl">
KubeSphere
</Button>
<Button variant="filled" color="default" radius="xl">
KubeSphere
</Button>
<Button variant="text" radius="xl">
KubeSphere
</Button>
<Button variant="filled" color="default" radius="xl" disabled>
KubeSphere
</Button>
</Group>
));

storiesOf('@kubed/components/Button', module).add('Color', () => (
<Button variant="filled" color="warning" shadow radius="xl">
KubeSphere
</Button>
));

storiesOf('@kubed/components/Button', module).add('Icon', () => (
<Button variant="filled" color="default" radius="xl" leftIcon={<Add size={16} />}>
KubeSphere
</Button>
));
Loading

0 comments on commit 8c53f1e

Please sign in to comment.