Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
7955125-front-end/src/components/dogicon.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
54 lines (46 sloc)
1.33 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { EditOutlined, EditFilled, HeartOutlined, HeartFilled} from "@ant-design/icons"; | |
function getIcon (theme, iconType) { | |
let Icon; | |
if (theme === 'filled') { | |
if (iconType === 'edit') { | |
Icon = EditFilled | |
} else if (iconType === 'heart') { | |
Icon = HeartFilled | |
} | |
} else if (theme === 'outlined') { | |
if (iconType === 'edit') { | |
Icon = EditOutlined | |
} else if (iconType === 'heart') { | |
Icon = HeartOutlined | |
} | |
} | |
return Icon; | |
} | |
class PostIcon extends React.Component { | |
constructor(props){ | |
super(props); | |
this.state = { | |
selected: props.selected | |
}; | |
this.onClick = this.onClick.bind(this); | |
} | |
onClick(){ | |
//reverse the selected state with every click | |
this.setState({selected: !this.state.selected}); | |
} | |
render(){ | |
const theme = this.state.selected ? 'filled' : 'outlined'; | |
const iconType = this.props.type; | |
const Icon = getIcon(theme, iconType); | |
return ( | |
<span> | |
<Icon | |
onClick={this.onClick} | |
style={{color:'steelblue'}} /> | |
{this.props.count} | |
</span> | |
); | |
} | |
} | |
export default PostIcon; |