Giter Club home page Giter Club logo

react-focus-component's Introduction

react-focus-component

Build Status

A react component that brings other components into visual focus/highlight by placing an overlay over all other elements on the page. Requires React 16 or higher

Example: https://react-focus-component.now.sh/

Usage


import { FocusOverlay } from 'react-focus-component';

class BasicExample extends React.Component {
    constructor(props) {
        super(props);
        this.component = React.createRef();
    }

    render() {
        return (
            <div>
                <div ref={this.component}>
                    This element will be highlighted because the "ref" is passed to the FocusOverlay as the focusComponent prop.
                </div>

                <FocusOverlay focusComponent={this.component.current} onExit={() => alert('runs when the user clicks in the overlay')} />
            </div>
        );
    }
}

API

  • focusComponent - A DOM element instance or an array of DOM elements to calculate the outer boundries of the focus point. This can also be a custom set of coordinates ({ height, width, x, y }), but note that these coordinates are reletive to the scroll position and will not automatically update on page scroll. This should be managed outside of the component.
  • onExit - called when the user clicks on the overlay.
  • target - Determines where the children (if any) will be rendered. Possible values: topleft, top, topright, left, right, bottomleft, bottom (DEFAULT), bottomright.

Development

  • Dependencies: Node 8 or greater.
  • Running examples: npm start.
  • Testing: npm test or npm run unittest or npm run test-watch. Write tests in __tests__ folder.
  • Linting: npm test or npm run lint. Fix: npm run lint-fix.
  • Build & publish: npm publish to build transpiled output to dist folder and publish it to the NPM registry. Requires environment variable NPM_TOKEN.
  • Deploy: npm run deploy deploys to ZEIT Now. Requires environment variable NOW_TOKEN.

License

MIT

react-focus-component's People

Contributors

jayjaydluffy avatar hofnarwillie avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.