1.1.1 • Published 2 years ago

react-bound-highlight v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

React bound highlight

React component for connecting elements hover states

GitHub Workflow Status npm bundle size

Features:

  • Highlight other components when a component is hovered
  • Custom styles
  • Lightweight
  • No dependencies

Examples from storybook

Two directions bound:

Two directions bound with current element highlight ON:

Single direction bound:

Multiple elements in bound:

Custom highlight styles:

Can be used for building side by side editor like this:

Install

npm install react-bound-highlight --save

Basic usage

Wrap needed elements and specify unique id for connected components group:

import BoundHighlight from 'react-bound-highlight';
...
    <div>
      <BoundHighlight id="group1">Group 1</BoundHighlight>
      <BoundHighlight id="group2">Group 2</BoundHighlight>
      ...
      <BoundHighlight id="group1">Group 1</BoundHighlight>
      <BoundHighlight id="group2">Group 2</BoundHighlight>
    </div>
...

Props

PropDescriptionTypeDefault
id*unique group bound identifierstring
currentHoverHighlightOnturn on hover highlight on current elementboolfalse
oppositeHoverHighlightOffturn off current component oposite highlightboolfalse
defaultStyleOffturn off default style for highligtingboolfalse
classNamecustom classNamestring'BoundHighlight'
htmlTagwrapper HTML tagstring'span'
children*nested elementsstring, node

Classes

Use classes to override highlighting styles. Set defaultStyleOff=true prop to turn off default style.

ClassDesciption
BoundHighlightMain class name, can by override via className prop
{className}--currentHoverCurrent hover state className
{className}--boundHoverBound hover state className

Storybook

Review all examples on storybook:

npm run storybook

Run tests

npm run test

Linter

Run linter:

npm run lint

Fix formatting issues:

npm run lint:fix

License

MIT