Hover Image React Component
!travis-status


A React Component for an image, which changes its source when mouse hovered.
1. Add to your React project:
yarn add react-hover-image
2. Import and use
``js
import React from "react";
import HoverImage from "react-hover-image";
import yourFile from "./images/yourFile.svg";
import yourFileHover from "./images/yourFile-hover.svg";
const YourComponent: React.SFC = () => {
return (
$3
src and hoverSrc are the only required props.- src : Default image source
- hoverSrc : On hover, show this
- onClick : function to invoke when the image is clicked
- disabled : You can disable clicks
- style : Style props to pass to the
img
- className : CSS class name to pass to the img`ts
export type HoverImageProps = {
src: string;
hoverSrc: string;
disabled?: boolean;
className?: string;
style?: any;
onClick?: React.MouseEventHandler;
};
`$3
We publish types at
index.d.ts with version 2.0.$3
You can view a running storybook at http://jessewolgamott.com/react-hover-image/ or you can download and run
yarn storybook$3
- If using webpack, use
image-loader` to load your images into a data-url andI was working on a project where client wanted to use graphic buttons for
instead of CSS buttons. This is extracted from that project.
The MIT License
Copyright 2017 Jesse Wolgamott
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.