1.0.6 • Published 3 years ago

react-heart v1.0.6

Weekly downloads
1,142
License
MIT
Repository
github
Last release
3 years ago

MIT license npm version npm size

Demo

Live demo and sandbox

Installation

React-Heart is available as an npm package.

// with npm
npm install react-heart

Usage

import React, { useState } from "react"
import Heart from "react-heart"

function App() {
	const [active, setActive] = useState(false)
	return (
		<div style={{ width: "2rem" }}>
			<Heart isActive={active} onClick={() => setActive(!active)}/>
		</div>
	);
}

Props

NameTypeRequired?DefaultDescription
isActiveboolrequiredN/ACurrent heart status
onClickfunctionrequiredN/AHeart was clicked callback
animationTrigger'none' | 'click' | 'hover' | 'both'optional'click'Action that triggers animation
animationScalenumberoptional1.05Scale of animation
animationDurationnumberoptional0.05Length of animation
inactiveColorstringoptional'black'Color of inactive heart
activeColorstringoptional'red'Color of active heart
classNamestringoptionalN/AClass name to apply custom CSS
styleobjectoptionalN/AStyle object

Example

import React, { useState } from "react"
import Heart from "react-heart"

function App() {
	const [active, setActive] = useState(false)
	return (
		<div style={{ width: "2rem" }}>
			<Heart isActive={active} onClick={() => setActive(!active)} animationTrigger = "both" inactiveColor = "rgba(255,125,125,.75)" activeColor = "#e019ae" style = {{marginTop:'1rem'}} animationDuration = {0.1}/>
		</div>
	);
}