Skip to content

Commit c9377fc

Browse files
committedSep 3, 2021
example(react-component): Update example.
1 parent af5e7ad commit c9377fc

File tree

7 files changed

+26
-98
lines changed

7 files changed

+26
-98
lines changed
 

‎example/basic/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { test } from './utils/Test';
33

44
class Test {
55
constructor() {}
6+
public a: string = 'A';
67
count() {
78
return 10;
89
}

‎example/react-component-tsx/package.json

-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@
3535
"react": ">=16.9.0",
3636
"react-dom": ">=16.9.0"
3737
},
38-
"dependencies": {
39-
"prop-types": "15.7.2"
40-
},
4138
"devDependencies": {
4239
"@babel/runtime": "7.15.4",
4340
"@kkt/less-modules": "6.11.0",
+23-49
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react';
2-
import PropTypes from 'prop-types';
32
import './style/index.less';
43

54
export interface ButtonProps {
@@ -15,53 +14,28 @@ export interface ButtonProps {
1514
children?: React.ReactNode;
1615
htmlType?: React.ButtonHTMLAttributes<HTMLButtonElement>['type'];
1716
}
18-
export default function Button(props: ButtonProps = {}) {
19-
const { prefixCls, type, size, active, disabled, block, basic, className, loading, children, htmlType, ...others } =
20-
props;
2117

22-
const cls = [
23-
className,
24-
prefixCls,
25-
size ? `${prefixCls}-${size}` : false,
26-
type ? `${prefixCls}-${type}` : false,
27-
basic ? `${prefixCls}-basic` : false,
28-
loading ? `${prefixCls}-loading` : false,
29-
disabled || loading ? 'disabled' : false,
30-
active ? 'active' : false,
31-
block ? 'block' : false,
32-
]
33-
.filter(Boolean)
34-
.join(' ');
35-
return (
36-
<button {...others} disabled={disabled || loading} type={htmlType} className={cls}>
37-
{children &&
38-
React.Children.map(children, (child) => {
39-
if (React.isValidElement(child)) return child;
40-
return <span> {child} </span>;
41-
})}
42-
</button>
43-
);
18+
export default class Button extends React.PureComponent<ButtonProps> {
19+
public static defaultProps: ButtonProps = {
20+
type: 'light',
21+
prefixCls: 'w-btn',
22+
size: 'default',
23+
htmlType: 'button',
24+
};
25+
render() {
26+
const { prefixCls, className, children, type, htmlType, size } = this.props;
27+
const cls = [className, prefixCls, size ? `${prefixCls}-${size}` : false, type ? `${prefixCls}-${type}` : false]
28+
.filter(Boolean)
29+
.join(' ');
30+
return (
31+
<button type={htmlType} className={cls}>
32+
{children &&
33+
React.Children.map(children, (child) => {
34+
if (!child) return child;
35+
if (React.isValidElement(child)) return child;
36+
return <span>{child}</span>;
37+
})}
38+
</button>
39+
);
40+
}
4441
}
45-
46-
Button.defaultProps = {
47-
prefixCls: 'w-btn',
48-
disabled: false,
49-
active: false,
50-
loading: false,
51-
block: false,
52-
basic: false,
53-
htmlType: 'button',
54-
type: 'light',
55-
size: 'default',
56-
};
57-
Button.propTypes = {
58-
prefixCls: PropTypes.string,
59-
loading: PropTypes.bool,
60-
disabled: PropTypes.bool,
61-
block: PropTypes.bool,
62-
active: PropTypes.bool,
63-
basic: PropTypes.bool,
64-
htmlType: PropTypes.string,
65-
type: PropTypes.oneOf(['primary', 'success', 'warning', 'danger', 'light', 'dark', 'link']),
66-
size: PropTypes.oneOf(['large', 'default', 'small']),
67-
};

‎example/react-component-tsx/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@
1818
"moduleResolution": "node",
1919
"noEmit": true
2020
},
21-
"include": ["src", "react-app-env.d.ts"]
21+
"include": ["src"]
2222
}

‎example/react-component/.babelrc

-40
This file was deleted.

‎package.json

+1-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"private": true,
44
"license": "MIT",
55
"scripts": {
6+
"prepare": "husky install",
67
"build:basic": "lerna exec \"npm run build\" --scope @template/basic",
78
"watch:basic": "lerna exec \"npm run watch\" --scope @template/basic",
89
"test:basic": "lerna exec \"npm run coverage\" --scope @template/basic",
@@ -31,11 +32,6 @@
3132
"hoist": "lerna bootstrap --hoist",
3233
"publish": "lerna publish from-package"
3334
},
34-
"husky": {
35-
"hooks": {
36-
"pre-commit": "pretty-quick --staged"
37-
}
38-
},
3935
"dependencies": {
4036
"husky": "7.0.2",
4137
"lerna": "4.0.0",

0 commit comments

Comments
 (0)
Please sign in to comment.