Skip to content

Commit 41772b3

Browse files
committed
refactor: 使用hooks重构PanThumb组件
1 parent f024e92 commit 41772b3

File tree

1 file changed

+33
-32
lines changed

1 file changed

+33
-32
lines changed

src/components/PanThumb/index.jsx

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,39 @@
11
import React, { Component } from "react";
22
import { PropTypes } from "prop-types";
33
import "./index.less";
4-
class PanThumb extends Component {
5-
static propTypes = {
6-
image: PropTypes.string.isRequired,
7-
zIndex: PropTypes.number,
8-
width: PropTypes.string,
9-
height: PropTypes.string,
10-
className: PropTypes.string,
11-
};
12-
static defaultProps = {
13-
width: "150px",
14-
height: "150px",
15-
zIndex: 1,
16-
className:""
17-
};
18-
render() {
19-
const { image, zIndex, width, height,className } = this.props;
20-
return (
21-
<div
22-
className={`pan-item ${className}`}
23-
style={{
24-
zIndex,
25-
height,
26-
width,
27-
}}
28-
>
29-
<div className="pan-info">
30-
<div className="pan-info-roles-container">{this.props.children}</div>
31-
</div>
32-
<img src={image} className="pan-thumb" alt=""/>
4+
5+
const PanThumb = (props) => {
6+
const { image, zIndex, width, height, className } = props;
7+
return (
8+
<div
9+
className={`pan-item ${className}`}
10+
style={{
11+
zIndex,
12+
height,
13+
width,
14+
}}
15+
>
16+
<div className="pan-info">
17+
<div className="pan-info-roles-container">{props.children}</div>
3318
</div>
34-
);
35-
}
36-
}
19+
<img src={image} className="pan-thumb" alt="" />
20+
</div>
21+
);
22+
};
23+
24+
PanThumb.prototype = {
25+
image: PropTypes.string.isRequired,
26+
zIndex: PropTypes.number,
27+
width: PropTypes.string,
28+
height: PropTypes.string,
29+
className: PropTypes.string,
30+
};
31+
32+
PanThumb.defaultProps = {
33+
width: "150px",
34+
height: "150px",
35+
zIndex: 1,
36+
className: "",
37+
};
3738

3839
export default PanThumb;

0 commit comments

Comments
 (0)