Coder Social home page Coder Social logo

tnargib / react-backdrop-filter Goto Github PK

View Code? Open in Web Editor NEW
10.0 2.0 3.0 6.9 MB

React Backdrop Filter is a quick and easy way of getting experimental backdrop filter to work with canvas.

Home Page: https://www.npmjs.com/package/react-backdrop-filter

CSS 18.52% JavaScript 77.22% HTML 4.25%

react-backdrop-filter's Introduction

React Backdrop Filter

React Backdrop Filter is a quick and easy way to add nice backdrop filters to your app.

npm npm npm

example

Important note

If the css backdrop filter property is not supported by your navigator, the component will fallback to html2canvas by default. To disable this behaviour, remember to set the prop canvasFallback to false.

When using the fallback, the component uses html2canvas. Canvas are slow to calculate and render so it won't do well with animations and movement in the page. It is more recommended to use with static elements or to disable the fallback and add a different background on non supported navigator.

Installation

# Yarn
yarn add react-backdrop-filter

# NPM
npm install react-backdrop-filter

Usage

import BackdropFilter from "react-backdrop-filter";

render() {
    return (
        <div className="container">
            <BackdropFilter
                className="bluredForm"
                filter={"blur(10px) sepia(50%)"}
                canvasFallback={true}
                html2canvasOpts={{
                    allowTaint: true
                }}
                onDraw={() => {
                    console.log("Rendered !");
                }}
                >
                <form>
                    <div className="profilePic">
                    <img src={drwho} alt="me" />
                    </div>
                    <h4>@tnargib</h4>
                    <p>Login</p>
                    <hr />
                    <p>Password</p>
                    <hr />
                    <div className="button">Sign in</div>
                    <small>Forgot password ?</small>
                </form>
            </BackdropFilter>
        </div>
    );
}

Edit 13zvn71zz3

Configuration

prop name type mandatory default value description
filter string NO ""
className string NO ""
canvasFallback function, boolean NO true Set it to false if you don't want the component to fallback on html2canvas
shouldDraw function, boolean NO true Called every time the canvas is about to rerender. Should return true or false if it should continue or not
onDraw function NO null Function called when canvas is rendered
html2canvasOpts object NO {} html2canvas configuration options
logging boolean NO true Display or not the logs from react-backdrop-filter and html2canvas

Example of adding a different background on non supported navigators

@supports not (
  (backdrop-filter: blur(5px)) and (-webkit-backdrop-filter: blur(5px))
) {
  .bluredForm {
    background: rgba(255, 255, 255, 0.3);
  }
}

react-backdrop-filter's People

Contributors

cyb3rl1f3 avatar tnargib avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-backdrop-filter's Issues

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.