@abucarub/react-circle-countdown 中文文档教程

发布于 4年前 浏览 23 更新于 3年前

React Circle Countdown

React Circle Countdown 是一个可自定义的动画倒计时组件。

Installation

npm i @abucarub/react-circle-countdown

Usage

import CircleCountdown from '@abucarub/react-circle-countdown';

const YourComponent = () => (
      <CircleCountdown
        seconds={10}
        size={150}
        font="bold 20px Arial"
        fontColor="#D7ECE6"
        barColor="rgb(51, 255, 153, 0.5)"
        barWidth={15}
        barTrailColor="#64867B"
        barEndShape="round"
        isPaused={false}
        pausedText="Wait"
        endText="Finished"
        onComplete={() => {
          console.log('Do something');
        }}
      />
)

Props

NameTypeDefaultDescription
secondsNumberrequiredThe seconds to count down ( min value: 1)
sizenumber130The width and height of the component
fontstring"20px sans-serif"Just like the CSS 'font' property
fontColorstring#fff '#fff'Takes any valid color format (HEX, rgb, rgba)
barColorstring#8ac4e1 '#8ac4e1'Takes any valid color format (HEX, rgb, rgba)
barTrailColorstring#6e818b '#6e818b'Takes any valid color format (HEX, rgb, rgba)
barWidthnumber15Path bar width
barEndShaperound | buttbuttThe shape of bar end
isPausedbooleantruePause and play animation
pausedTextstringCurrent timeThe displayed text when the animation is paused
endTextstring"Time over"The displayed when the countdown is over
showMaskbooleantrueIf set false, it show just a countdown without any mask
onCompletefunctionCalled when the countdown is over

Recipes

To restart de countdown

可以随时通过使用 useRef 挂钩重新启动。

import React, { useRef } from 'react';
import CountDown, { IInputHandles } from "../components/CountDown";

const YourComponent = () => {
  const restartRef = useRef<IInputHandles>(null);

  const handleRestart = () => {
    restartRef.current?.restart();
  };

  return (
    <>
      <button onClick={() => handleRestart()}>
        Restart
      </button>
      <CircleCountDown
        ref={restartRef}
        seconds={80}      
      />
    </>
  )
}
...

React Circle Countdown

React Circle Countdown is a customizable animated countdown component.

Installation

npm i @abucarub/react-circle-countdown

Usage

import CircleCountdown from '@abucarub/react-circle-countdown';

const YourComponent = () => (
      <CircleCountdown
        seconds={10}
        size={150}
        font="bold 20px Arial"
        fontColor="#D7ECE6"
        barColor="rgb(51, 255, 153, 0.5)"
        barWidth={15}
        barTrailColor="#64867B"
        barEndShape="round"
        isPaused={false}
        pausedText="Wait"
        endText="Finished"
        onComplete={() => {
          console.log('Do something');
        }}
      />
)

Props

NameTypeDefaultDescription
secondsNumberrequiredThe seconds to count down ( min value: 1)
sizenumber130The width and height of the component
fontstring"20px sans-serif"Just like the CSS 'font' property
fontColorstring#fff '#fff'Takes any valid color format (HEX, rgb, rgba)
barColorstring#8ac4e1 '#8ac4e1'Takes any valid color format (HEX, rgb, rgba)
barTrailColorstring#6e818b '#6e818b'Takes any valid color format (HEX, rgb, rgba)
barWidthnumber15Path bar width
barEndShaperound | buttbuttThe shape of bar end
isPausedbooleantruePause and play animation
pausedTextstringCurrent timeThe displayed text when the animation is paused
endTextstring"Time over"The displayed when the countdown is over
showMaskbooleantrueIf set false, it show just a countdown without any mask
onCompletefunctionCalled when the countdown is over

Recipes

To restart de countdown

Could be restarted at any time, by using a useRef hook.

import React, { useRef } from 'react';
import CountDown, { IInputHandles } from "../components/CountDown";

const YourComponent = () => {
  const restartRef = useRef<IInputHandles>(null);

  const handleRestart = () => {
    restartRef.current?.restart();
  };

  return (
    <>
      <button onClick={() => handleRestart()}>
        Restart
      </button>
      <CircleCountDown
        ref={restartRef}
        seconds={80}      
      />
    </>
  )
}
...
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文