mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-28 21:33:24 +03:00
Added basic toggle state to like component
This commit is contained in:
parent
ddd72eba98
commit
c394037cab
@ -1,9 +1,30 @@
|
||||
import React from 'react';
|
||||
import AppContext from '../AppContext';
|
||||
import {ReactComponent as LikeIcon} from '../images/icons/like.svg';
|
||||
|
||||
function Like() {
|
||||
return (
|
||||
<button className="flex font-sans text-[14px] items-center"><LikeIcon className='gh-comments-icon gh-comments-icon-like mr-1' />3</button>
|
||||
);
|
||||
class Like extends React.Component {
|
||||
static contextType = AppContext;
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
liked: false
|
||||
};
|
||||
|
||||
this.toggleLike = this.toggleLike.bind(this);
|
||||
}
|
||||
|
||||
toggleLike() {
|
||||
this.setState(state => ({
|
||||
liked: !state.liked
|
||||
}));
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<button className="flex font-sans text-[14px] items-center" onClick={this.toggleLike}><LikeIcon className={`gh-comments-icon gh-comments-icon-like mr-1 ${this.state.liked ? 'fill-black' : ''}`} />3</button>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default Like;
|
||||
|
Loading…
Reference in New Issue
Block a user