-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (43 loc) · 1.05 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import React from "react";
import { List, Grid } from "antd-mobile";
import PropTypes from "prop-types";
class AvatarSelector extends React.Component {
static propTypes = {
selectAvatar: PropTypes.func.isRequired // selectAvatar是一个function,且必传
};
constructor(props) {
super(props);
this.state = {};
}
render() {
const avatarList = "boy,bull,chick,crab,girl,hedgehog,hippopotamus,koala,lemur,man,pig,tiger,whale,woman,zebra"
.split(",")
.map(v => ({
icon: require(`../assets/img/${v}.png`),
text: v
}));
const gridHeader = this.state.icon ? (
<div>
<span>已选择图像</span>
<img style={{ width: 20 }} src={this.state.icon} alt="" />
</div>
) : (
"请选择图像"
);
return (
<div>
<List renderHeader={() => gridHeader}>
<Grid
data={avatarList}
columnNum={5}
onClick={elm => {
this.setState(elm);
this.props.selectAvatar(elm.text);
}}
/>
</List>
</div>
);
}
}
export default AvatarSelector;