1.3.2 • Published 8 months ago

react-hotspots v1.3.2

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

GitHub package.json version npm npm bundle size NPM License

react-hotspots

React component to create image hotspots

Install

Install using npm or yarn

npm install react-hotspots
yarn add react-hotspots

Usage

Import the component and base styles:

import ReactHotspots from 'react-hotspots'
import 'react-hotspots/dist/style.css';
import { Si1Password } from 'react-icons/si';

Use it:

	<ReactHotspots
        image='https://unsplash.com/photos/RD8qNV6QXy8/download?ixid=MnwxMjA3fDB8MXxhbGx8M3x8fHx8fDJ8fDE2NzYxNjkwNDk&force=true&w=2400'
        imageAlt="React Logo"
        className="cstm-container"
        iconSize='30px'
		iconColor="#ffffff"
        overlay={true}
        hotspots={[
            {
                left: '50%',
                top: '50%',
                triggerIcon: <Si1Password />,
                className: 'cstm-hotspot',
                iconSize: '60px',
                iconColor: 'red',
                content: 'Text',
                modal: true,
        	},
            {
                left: '25%',
                top: '25%',
                content: <div>Hotspot 2</div>
            },
            {
                left: '75%',
                top: '75%',
                content: <div>Hotspot 3</div>
            }
        ]}
    />

Demo

Edit react-hotspots

Component props

PropsTypeDefaultDescription
imageString, requiredImage source
imageAltString, optionalImage alternative info
overlayBoolean, optionaltrueAdds a transparent black overlay to the image for better visibility
classNameString, optionalApply custom classname to the main container
iconSizeString, optional30pxSet the font size for the icon. This will be applied to all hotspots.
iconColorString, optional#ffffffSet the icon color. This will be applied to all hotspots.
hotspotsArray of objects, requiredContains information of hotspots to be added.

Hotspot object

KeyTypeDefaultDescription
leftString, requiredHorizontal position with css units(px,%,etc.)
topString, requiredVertical position with css units(px,%,etc.)
triggerIconReact element/image/svg, optional<AiFillInfoCircle /> - from react-icons/ai libraryReact element / image / svg / a react-icon to indicate the hotspot
classNameString, optionalApply custom classname to the hotspot element
iconSizeString, optional30pxSet the font size for the icon. This will be applied to individual hotspot and will override the global value.
iconColorString, optional#ffffffSet the icon color. This will be applied to individual hotspot and will override the global value.
modalBoolean, optionalfalseIf set to true, the hotspot content will be displayed in a modal.
contentReact or HTML element, optionalHotspot content. If no content is provided, only the icon would be displayed

License

MIT License © 2023 the-marolie