1.0.0 • Published 3 years ago

react-target-popup-modal v1.0.0

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

react-target-popup-modal

react component for highlighting any element of DOM with optional description which rendering in renderProps.

NOTE

  • the component need to render on top level of app.

NPM JavaScript Style Guide

Install

npm install --save react-target-popup-modal

Usage

import React from 'react';

import {
  TargetPopup,
  TargetPopupRenderWrapper,
} from 'react-target-popup-modal';
import 'react-target-popup-modal/dist/index.css';

const App = () => {
  return (
    <div className='layout'>
      <div className='.some-element' />
      <TargetPopup
        querySelector='.some-element'
        color='#32e23d73'
        padding={20}
        renderElem={(elem) => (
          <TargetPopupRenderWrapper
            node={elem}
            position='TOP'
            distance={distancePX}
            distanceY={distancePercent}
          >
            <p className='paragraph'>Hello! I've rendered on TOP!</p>
          </TargetPopupRenderWrapper>
        )}
      />
    </div>
  );
};

TargetPopup props

nametypeexample valuesdefaultdescription
isCanInteractivebooleantruetrueif false, component just highlighted, but without any interactive events
querySelectorstring'.className' or '#id'empty stringpure Javascript selector, that need to find DOMNode in useEffect and call getBoundingClientRect()
paddingnumber10 or -100Number of pixels, that wil increase or decrease highlighting window
queryTopnumber-15 or 250Number of pixels, that wil increase or decrease top line of highlighting window
queryBottomnumber-10 or 200Number of pixels, that wil increase or decrease bottom line of highlighting window
queryLeftnumber-10 or 200Number of pixels, that wil increase or decrease left line of highlighting window
queryRightnumber-10 or 200Number of pixels, that wil increase or decrease right line of highlighting window
queryTopPercentnumber-2 or 10Number of css vh, that wil increase or decrease top line of highlighting window
queryBottomPercentnumber-5 or 150Number of css vh, that wil increase or decrease bottom line of highlighting window
queryLeftPercentnumber-12 or 230Number of css vw, that wil increase or decrease left line of highlighting window
queryRightPercentnumber-10 or 200Number of css vh, that wil increase or decrease right line of highlighting window
colorstring'#dc1bfeb3' or 'rgba(0, 0, 0, 0.4)'rgba(0, 0, 0, 0.4)Background color of popup
renderElemJSX.Element or null(elem) => (Hello! I've rendered on TOP!)nullIt's the renderProp and required function that returns any components, but there parent must be

TargetPopupRenderWrapper props

nametypeexample valuesdefaultdescription
nodetypeof nodeObjnodenodeRequired prop, that given from in first argument in renderProp function
positionstring'TOP','LEFT','BOTTOM','RIGHT'Position relatively highlighted window
distancenumber10 or -100distance on main axis in pixels (see example for more details)
distanceYnumber-15 or 250distance on Y axis relatively main axis in css vw or vh if main axis horizontal (see example for more details)
childrenReact.ReactNodeI'm rendered componentundefinedCommon React children

License

MIT © Immortal230719