Skip to content

Commit 88dd1f1

Browse files
王泽龙王泽龙
王泽龙
authored and
王泽龙
committed
提交组件库
0 parents  commit 88dd1f1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+37296
-0
lines changed

.gitignore

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
/dist
14+
/storybook-static
15+
16+
# misc
17+
.DS_Store
18+
.env.local
19+
.env.development.local
20+
.env.test.local
21+
.env.production.local
22+
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*

.storybook/addons.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import '@storybook/addon-actions/register';
2+
import '@storybook/addon-links/register';

.storybook/config.tsx

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { configure, addDecorator, addParameters } from '@storybook/react';
2+
import { withInfo } from '@storybook/addon-info'
3+
import React from 'react'
4+
import { library } from '@fortawesome/fontawesome-svg-core'
5+
import { fas } from '@fortawesome/free-solid-svg-icons'
6+
import "../src/styles/index.scss"
7+
library.add(fas)
8+
const wrapperStyle: React.CSSProperties = {
9+
padding: '20px 40px'
10+
}
11+
12+
const storyWrapper = (stroyFn: any) => (
13+
<div style={wrapperStyle}>
14+
<h3>组件演示呀</h3>
15+
{stroyFn()}
16+
</div>
17+
)
18+
addDecorator(storyWrapper)
19+
addDecorator(withInfo)
20+
addParameters({info: { inline: true, header: false}})
21+
const loaderFn = () => {
22+
const allExports = [require('../src/welcome.stories.tsx')];
23+
const req = require.context('../src/components', true, /\.stories\.tsx$/);
24+
req.keys().forEach(fname => allExports.push(req(fname)));
25+
return allExports;
26+
};
27+
28+
29+
// automatically import all files ending in *.stories.js
30+
configure(loaderFn, module);

.storybook/webpack.config.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module.exports = ({ config }) => {
2+
config.module.rules.push({
3+
test: /\.tsx?$/,
4+
use: [
5+
{
6+
loader: require.resolve("babel-loader"),
7+
options: {
8+
presets: [require.resolve("babel-preset-react-app")]
9+
}
10+
},
11+
{
12+
loader: require.resolve("react-docgen-typescript-loader"),
13+
options: {
14+
shouldExtractLiteralValuesFromEnum: true,
15+
propFilter: (prop) => {
16+
if (prop.parent) {
17+
return !prop.parent.fileName.includes('node_modules')
18+
}
19+
return true
20+
}
21+
}
22+
}
23+
]
24+
});
25+
26+
config.resolve.extensions.push(".ts", ".tsx");
27+
28+
return config;
29+
};

.travis.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
language: node_js
2+
node_js:
3+
- "stable"
4+
cache:
5+
directories:
6+
- node_modules
7+
env:
8+
- CI=true
9+
script:
10+
- npm run build-storybook
11+
deploy:
12+
provider: pages
13+
skip_cleanup: true
14+
github_token: $github_token
15+
local_dir: storybook-static
16+
on:
17+
branch: master
18+
19+

.vscode/settings.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"eslint.validate": [
3+
"javascript",
4+
"javascriptreact",
5+
{ "language": "typescript", "autoFix": true },
6+
{ "language": "typescriptreact", "autoFix": true }
7+
]
8+
}

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Viking Zhang
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
## Vikingship component library
2+
## 使用 React+typescript 从零到一打造一套你自己的组件库
3+
4+
[![Build Status](https://travis-ci.com/vikingmute/vikingship.svg?token=mHoDqxyxXWX5BSpu8L9y&branch=master)](https://travis-ci.com/vikingmute/vikingship)
5+
6+
vikingship 是为慕课网打造的一套教学组件库,使用 React Hooks 和 typescript
7+
意在让大家从零到一,由浅入深的提高自己的 React 和 typescript 水平,它的官网地址是
8+
[vikingship.xyz](http://vikingship.xyz)
9+
10+
11+
### 安装最后已经发布的组件库来试试
12+
13+
~~~javascript
14+
npm install vikingship --save
15+
~~~
16+
17+
### 使用
18+
19+
~~~javascript
20+
// 加载样式
21+
import 'vikingship/dist/index.css'
22+
// 引入组件
23+
import { Button } from 'vikingship'
24+
~~~
25+
26+
### 课程亮点
27+
28+
* 🔥typescript with React Hooks
29+
* 💧渐进式的教学过程,很多章后面都有扩展作业,引导同学们深入学习和掌握知识
30+
* ⛑️使用 react-testing-library 完成单元测试
31+
* 📚使用 storybook 本地调试和生成文档页面
32+
* 📚使用 react-doc-gen 自动生成文档
33+
* 📦使用第三方库扩充组件-(react-fontawesome, react-transition-group)
34+
* 🌹样式(Sass)文件从零开始,掌握大型应用的 CSS 组织方法
35+
* 🎉涉及全部流程,包括最后的 npm publish,husky提交发布前验证,travis CI/CD 集成,发布文档站点等
36+
37+
### 一些本地开发命令
38+
39+
~~~bash
40+
//启动本地环境
41+
npm run stroybook
42+
43+
//跑单元测试
44+
npm test
45+
46+
//build可发布静态文件
47+
npm run build
48+
49+
//发布到 npm
50+
npm run publish
51+
~~~

jest.test.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
test('test common matcher', () => {
2+
expect( 2 + 2 ).toBe(4)
3+
expect(2 + 2).not.toBe(5)
4+
})
5+
6+
test('test to be true or false', () => {
7+
expect(1).toBeTruthy()
8+
expect(0).toBeFalsy()
9+
})
10+
11+
test('test number', () => {
12+
expect(4).toBeGreaterThan(3)
13+
expect(2).toBeLessThan(3)
14+
})
15+
16+
test('test object', () => {
17+
expect({name: 'viking'}).toEqual({name: 'viking'})
18+
})

0 commit comments

Comments
 (0)