Skip to content

Commit c23c154

Browse files
author
colinfan
committed
fix: 1、联调 tdesign-cli 生成文档;2、同步 tdesign-react 的 eslintrc 配置;3、新增 vscode 配置文件; 4、新增 src/common.ts 文件
1 parent 842b3b5 commit c23c154

File tree

13 files changed

+270
-31
lines changed

13 files changed

+270
-31
lines changed

.eslintignore

+15-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,15 @@
1-
node_modules
1+
snapshot*
2+
dist/
3+
esm/
4+
lib/
5+
cjs/
6+
lib/
7+
es/
8+
node_modules/
9+
static
10+
cypress
11+
script/test/cypress
12+
_site
13+
temp*
14+
static/
15+
src/_common

.eslintrc.js

+63-11
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,76 @@
11
module.exports = {
2-
env: {
3-
browser: true,
4-
es2021: true,
5-
},
62
extends: [
3+
'airbnb-base',
4+
'prettier', // eslint-config-prettier 处理冲突
75
'plugin:react/recommended',
8-
'airbnb',
6+
'plugin:import/typescript',
7+
'plugin:@typescript-eslint/recommended',
98
],
109
parser: '@typescript-eslint/parser',
10+
plugins: ['@typescript-eslint', 'react-hooks'],
11+
env: {
12+
browser: true,
13+
node: true,
14+
jest: true,
15+
},
16+
settings: {
17+
react: {
18+
pragma: 'React',
19+
version: 'detect',
20+
},
21+
},
1122
parserOptions: {
23+
ecmaVersion: 2019,
24+
sourceType: 'module',
1225
ecmaFeatures: {
1326
jsx: true,
1427
},
15-
ecmaVersion: 13,
16-
sourceType: 'module',
1728
},
18-
plugins: [
19-
'react',
20-
'@typescript-eslint',
21-
],
2229
rules: {
30+
'no-use-before-define': 'off',
31+
'@typescript-eslint/explicit-module-boundary-types': 'off',
32+
'@typescript-eslint/ban-types': 'off',
33+
'@typescript-eslint/explicit-function-return-type': 'off',
34+
'@typescript-eslint/indent': ['off', 2],
35+
'@typescript-eslint/ban-ts-comment': 'off',
36+
'@typescript-eslint/camelcase': 'off',
37+
'@typescript-eslint/no-empty-interface': 'error', // codecc
38+
'@typescript-eslint/no-explicit-any': 'off',
39+
'@typescript-eslint/no-use-before-define': ['error', { functions: false }],
40+
'@typescript-eslint/no-var-requires': 'off',
41+
'@typescript-eslint/no-unused-vars': 'error', // codecc
42+
'import/order': 'error',
43+
'import/extensions': 'off',
44+
'import/no-named-as-default': 'off',
45+
'import/prefer-default-export': 'off',
46+
'import/no-extraneous-dependencies': 'off',
47+
'import/no-cycle': 'off', // TODO: turn on this rule later
48+
'import/no-unresolved': 'off', // TODO: turn on this rule later
49+
'react/display-name': 'off',
50+
'react-hooks/exhaustive-deps': 'warn',
51+
'react-hooks/rules-of-hooks': 'error',
52+
'react/prop-types': 'off',
53+
'max-len': 'off',
54+
'no-shadow': 'off',
55+
'no-console': 'off',
56+
'no-throw-literal': 'off',
57+
'no-unused-expressions': 'off',
58+
'no-bitwise': 'off',
59+
'no-useless-return': 'off',
60+
'no-plusplus': [
61+
'error',
62+
{
63+
allowForLoopAfterthoughts: true,
64+
},
65+
],
66+
'no-continue': 'off',
67+
'no-return-assign': 'off',
68+
'no-restricted-syntax': 'off',
69+
'no-restricted-globals': 'off',
70+
'no-unneeded-ternary': 'off',
71+
'eol-last': 'error', // codecc
72+
'func-names': 'off',
73+
'consistent-return': 'off',
74+
'default-case': 'off',
2375
},
2476
};

.vscode/settings.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"],
3+
"editor.formatOnSave": true,
4+
"[html]": {
5+
"editor.defaultFormatter": "esbenp.prettier-vscode"
6+
},
7+
"[typescriptreact]": {
8+
"editor.defaultFormatter": "esbenp.prettier-vscode"
9+
},
10+
"[javascriptreact]": {
11+
"editor.defaultFormatter": "esbenp.prettier-vscode"
12+
},
13+
"[typescript]": {
14+
"editor.defaultFormatter": "esbenp.prettier-vscode"
15+
},
16+
"[javascript]": {
17+
"editor.defaultFormatter": "esbenp.prettier-vscode"
18+
},
19+
"editor.codeActionsOnSave": {
20+
"source.fixAll.eslint": true
21+
}
22+
}

docs/vite.config.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import path from 'path';
22

3-
import tdocPlugin from './plugin-tdoc';
43
import replace from '@rollup/plugin-replace';
54
import react from '@vitejs/plugin-react';
65
import { VitePWA } from 'vite-plugin-pwa';
6+
import tdocPlugin from './plugin-tdoc';
77
import pwaConfig from './pwaConfig';
88

99
export default {
@@ -38,10 +38,5 @@ export default {
3838
https: false,
3939
fs: { strict: false },
4040
},
41-
plugins: [
42-
react(),
43-
tdocPlugin(),
44-
VitePWA(pwaConfig),
45-
replace({ __DATE__: new Date().toISOString() }),
46-
],
41+
plugins: [react(), tdocPlugin(), VitePWA(pwaConfig), replace({ __DATE__: new Date().toISOString() })],
4742
};

examples/button/button.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,22 @@ toc: false
1414
## 测试用例2
1515

1616
::: demo demos/test2 button
17-
:::
17+
:::
18+
## API
19+
### Button Props
20+
21+
名称 | 类型 | 默认值 | 说明 | 必传
22+
-- | -- | -- | -- | --
23+
block | Boolean | false | 是否为块级元素 | N
24+
children | TNode | - | 按钮内容,同 content。TS 类型:`string | TNode`[通用类型定义](https://github.com/TDesignOteam/tdesign-mobile-react/blob/develop/src/common.ts) | N
25+
content | TNode | - | 按钮内容。TS 类型:`string | TNode`[通用类型定义](https://github.com/TDesignOteam/tdesign-mobile-react/blob/develop/src/common.ts) | N
26+
disabled | Boolean | false | 是否禁用按钮 | N
27+
ghost | Boolean | false | 是否为幽灵按钮(镂空按钮) | N
28+
icon | TElement | - | 按钮内部图标,可完全自定义。TS 类型:`TNode`[通用类型定义](https://github.com/TDesignOteam/tdesign-mobile-react/blob/develop/src/common.ts) | N
29+
loading | Boolean | false | 是否显示为加载状态 | N
30+
shape | String | square | 按钮形状,有二种:方形、圆角方形。可选项:square/round | N
31+
size | String | medium | 组件尺寸。可选项:small/medium/large。TS 类型:`SizeEnum`[通用类型定义](https://github.com/TDesignOteam/tdesign-mobile-react/blob/develop/src/common.ts) | N
32+
theme | String | default | 组件风格,依次为品牌色、危险色。可选项:default/primary/danger | N
33+
type | String | button | 按钮类型。可选项:submit/reset/button | N
34+
variant | String | base | 按钮形式,基础、线框、文字。可选项:base/outline/text | N
35+
onClick | Function | | 点击时触发。`(e: MouseEvent) => {}` | N

examples/button/demos/test.jsx

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
export default function Base() {
2-
return <h2>hello world</h2>
3-
}
1+
import React from 'react';
2+
import { Button } from 'tdesign-mobile-react';
3+
4+
export default function () {
5+
return <Button>test1</Button>;
6+
}

package.json

+4
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
"@rollup/plugin-replace": "^3.0.0",
8080
"@rollup/plugin-url": "^6.0.0",
8181
"@types/lodash": "^4.14.178",
82+
"@types/react": "^17.0.38",
8283
"@typescript-eslint/eslint-plugin": "^5.6.0",
8384
"@typescript-eslint/parser": "^5.6.0",
8485
"autoprefixer": "^10.4.0",
@@ -91,6 +92,8 @@
9192
"cz-conventional-changelog": "^3.3.0",
9293
"eslint": "^8.4.1",
9394
"eslint-config-airbnb": "^19.0.2",
95+
"eslint-config-airbnb-base": "^15.0.0",
96+
"eslint-config-prettier": "^8.3.0",
9497
"eslint-plugin-import": "^2.25.3",
9598
"eslint-plugin-jsx-a11y": "^6.5.1",
9699
"eslint-plugin-react": "^7.27.1",
@@ -119,6 +122,7 @@
119122
"./docs"
120123
],
121124
"dependencies": {
125+
"hoist-non-react-statics": "^3.3.2",
122126
"lodash": "^4.17.21"
123127
},
124128
"config": {

src/_common

src/button/Button.tsx

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1-
export default function Button() {
2-
return <button>hello</button>
3-
}
1+
import React, { FC } from 'react';
2+
import { TdButtonProps } from './type';
3+
4+
export interface ButtonProps extends TdButtonProps, React.ButtonHTMLAttributes<HTMLButtonElement> {}
5+
6+
const Button: FC<TdButtonProps> = (props) => {
7+
const { children } = props;
8+
return <button>{children}</button>;
9+
};
10+
11+
export default Button;

src/button/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import _Button from './Button';
22

33
import './style/index.js';
44

5-
// export type { ButtonProps } from './Button';
6-
// export * from './type';
5+
export type { ButtonProps } from './Button';
6+
export * from './type';
77

88
export const Button = _Button;
99
export default Button;

src/button/type.ts

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/* eslint-disable */
2+
3+
/**
4+
* 该文件为脚本自动生成文件,请勿随意修改。如需修改请联系 PMC
5+
* updated at 2022-01-07 16:30:49
6+
* */
7+
8+
import { TNode, TElement, SizeEnum } from '../common';
9+
import { MouseEvent } from 'react';
10+
11+
export interface TdButtonProps {
12+
/**
13+
* 是否为块级元素
14+
* @default false
15+
*/
16+
block?: boolean;
17+
/**
18+
* 按钮内容,同 content
19+
*/
20+
children?: TNode;
21+
/**
22+
* 按钮内容
23+
*/
24+
content?: TNode;
25+
/**
26+
* 是否禁用按钮
27+
* @default false
28+
*/
29+
disabled?: boolean;
30+
/**
31+
* 是否为幽灵按钮(镂空按钮)
32+
* @default false
33+
*/
34+
ghost?: boolean;
35+
/**
36+
* 按钮内部图标,可完全自定义
37+
*/
38+
icon?: TElement;
39+
/**
40+
* 是否显示为加载状态
41+
* @default false
42+
*/
43+
loading?: boolean;
44+
/**
45+
* 按钮形状,有二种:方形、圆角方形
46+
* @default square
47+
*/
48+
shape?: 'square' | 'round';
49+
/**
50+
* 组件尺寸
51+
* @default medium
52+
*/
53+
size?: SizeEnum;
54+
/**
55+
* 组件风格,依次为品牌色、危险色
56+
* @default default
57+
*/
58+
theme?: 'default' | 'primary' | 'danger';
59+
/**
60+
* 按钮类型
61+
* @default button
62+
*/
63+
type?: 'submit' | 'reset' | 'button';
64+
/**
65+
* 按钮形式,基础、线框、文字
66+
* @default base
67+
*/
68+
variant?: 'base' | 'outline' | 'text';
69+
/**
70+
* 点击时触发
71+
*/
72+
onClick?: (e: MouseEvent<HTMLButtonElement>) => void;
73+
}

src/common.ts

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/** React 特有全局变量 */
2+
3+
import { ReactElement, ReactNode, CSSProperties, FormEvent } from 'react';
4+
5+
// TElement 表示 API 只接受传入组件
6+
export type TElement = ReactElement | (() => ReactElement);
7+
// 1. TNode = ReactNode; 2. TNode<T> = (props: T) => ReactNode
8+
export type TNode<T = undefined> = T extends undefined ? ReactNode : (props: T) => ReactNode;
9+
10+
export type AttachNodeReturnValue = HTMLElement | Element | Document;
11+
export type AttachNode = CSSSelector | (() => AttachNodeReturnValue);
12+
13+
// 与滚动相关的容器类型,因为 document 上没有 scroll 相关属性, 因此排除document
14+
export type ScrollContainerElement = Window | HTMLElement;
15+
export type ScrollContainer = (() => ScrollContainerElement) | CSSSelector;
16+
17+
export type FormResetEvent = FormEvent<HTMLFormElement>;
18+
export type FormSubmitEvent = FormEvent<HTMLFormElement>;
19+
20+
export type Styles = CSSProperties;
21+
22+
export interface StyledProps {
23+
className?: string;
24+
style?: CSSProperties;
25+
}
26+
/** 通用全局变量 */
27+
28+
export type OptionData = {
29+
label?: string;
30+
value?: string | number;
31+
} & { [key: string]: any };
32+
33+
export type TreeOptionData = {
34+
children?: Array<TreeOptionData>;
35+
} & OptionData;
36+
37+
export type SizeEnum = 'small' | 'medium' | 'large';
38+
39+
export type HorizontalAlignEnum = 'left' | 'center' | 'right';
40+
41+
export type VerticalAlignEnum = 'top' | 'middle' | 'bottom';
42+
43+
export type ClassName = { [className: string]: any } | ClassName[] | string;
44+
45+
export type CSSSelector = string;
46+
47+
export interface KeysType {
48+
value?: string;
49+
label?: string;
50+
}

tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"suppressImplicitAnyIndexErrors": true,
1515
"baseUrl": "./",
1616
"paths": {
17-
"tdesign-react": ["src"],
18-
"tdesign-react/*": ["src/*"],
17+
"tdesign-mobile-react": ["src"],
18+
"tdesign-mobile-react/*": ["src/*"],
1919
"@test/utils": ["test/utils"],
2020
"@common/*": ["src/_common/*"],
2121
},

0 commit comments

Comments
 (0)