1.1.7 • Published 1 year ago

react-scratchcard-v3 v1.1.7

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

react-scratchcard-v3

A scratchcard component for React

NPM JavaScript Style Guide

Note

This is a clone of https://github.com/dopey2/react-scratchcard-v2

Improvement:
  • Added necessary precautions for 'Unable to preventDefault inside passive event listener' error

Demo

scratchcard-demo

Install

npm install --save react-scratchcard-v3

or

yarn add react-scratchcard-v3 

Usage

import React, { useRef }  from 'react';
import ScratchCard from 'react-scratchcard-v3';

import * as IMG from './img.jpg';

const App = () => {
    
  const ref = useRef<ScratchCard>(null);

  const onClickReset = () => {
    ref.current && ref.current.reset();
  }

  return (
    <div>
      <button onClick={onClickReset}>Reset</button>
      <ScratchCard
        width={320}
        height={226}
        image={IMG}
        finishPercent={80}
        onComplete={() => console.log('complete')}
      >
        <div style={{
          display: 'flex',
          width: '100%',
          height: '100%',
          alignItems: 'center',
          justifyContent: 'center'
        }}
        >
          <h1>Scratch card</h1>
        </div>
      </ScratchCard>
    </div>
  );
};

Custom brush

const App = () => {
  return (
    <div>
      <ScratchCard
        width={320}
        height={226}
        image={IMG}
        finishPercent={80}
        customBrush={{
          image: require('./brush.img'),
          width: 15,
          height: 15
        }}
      >
        <h1>Scratch card</h1>
      </ScratchCard>
    </div>
  );
};

or you can use CUSTOM_BRUSH_PRESET object

import { CUSTOM_BRUSH_PRESET } from 'react-scratchcard-v3';

const App = () => {
  return (
    <div>
      <ScratchCard
        width={320}
        height={226}
        image={IMG}
        finishPercent={80}
        customBrush={CUSTOM_BRUSH_PRESET}
      >
        <h1>Scratch card</h1>
      </ScratchCard>
    </div>
  )
}

Type

Props

nametypedefault
widthnumber
heightnumber
imageFile or Base64
finishPercent?number70
triggerPercent?number5
brushSize?number20
fadeOutOnComplete?booleantrue
onComplete?callback
onTrigger?callback
customBrush?CustomBrush
customCheckZone?CustomCheckZone

CustomBrush

nametype
widthnumber
heightnumber
imageFile or Base64

CustomCheckZone

nametype
xnumber
ynumber
widthnumber
heightnumber

License

MIT © PavanS

1.1.7

1 year ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago