File size: 1,078 Bytes
1e92f2d |
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 48 49 50 51 |
import { CompactCard as Card } from '@automattic/components';
import { PureComponent } from 'react';
import LikeButton from 'calypso/blocks/like-button/button';
class SimpleLikeButtonContainer extends PureComponent {
state = {
liked: !! this.props.liked,
count: this.props.likeCount || 0,
};
render() {
return (
<LikeButton
{ ...this.props }
onLikeToggle={ this.handleLikeToggle }
likeCount={ this.state.count }
liked={ this.state.liked }
/>
);
}
handleLikeToggle = ( newState ) => {
this.setState( {
liked: newState,
count: ( this.state.count += newState ? 1 : -1 ),
} );
};
}
class LikeButtons extends PureComponent {
static displayName = 'LikeButton';
render() {
return (
<div>
<Card compact>
<SimpleLikeButtonContainer tagName="a" likeCount={ 0 } />
</Card>
<Card compact>
<SimpleLikeButtonContainer tagName="a" likeCount={ 12 } />
</Card>
<Card compact>
<SimpleLikeButtonContainer tagName="a" likeCount={ 12 } liked />
</Card>
</div>
);
}
}
export default LikeButtons;
|