npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

countdown-button

v1.0.0

Published

依赖于`Ant Design`的倒计时按钮封装 📦

Downloads

6

Readme

countdown-button

依赖于Ant Design的倒计时按钮封装 📦

Ant Design<Button>组件基础上仅增加倒计时功能,定制性高的同时也无侵入

安装

yarn add countdown-button

默认的使用方式

    <CountdownButton>获取验证码</CountdownButton>
    <CountdownButton type="link" unit="秒">
      获取验证码
    </CountdownButton>
    <CountdownButton type="primary">获取验证码</CountdownButton>
    <CountdownButton>自定义的children</CountdownButton>

点击事件

Ant Design<Button>点击事件不同的是提供了支持异步函数和 Promise

Promiseresolve时会开始倒计时,reject时则不会

    <CountdownButton onClick={() => alert('开始倒计时')}>普通的onClick</CountdownButton>
    <CountdownButton onClick={async () => await sleep(1000)[1]}>async</CountdownButton>
    <CountdownButton onClick={() => new Promise(resolve => sleep(2000)[1].then(resolve))}>
      Promise Resolve
    </CountdownButton>
    <CountdownButton onClick={() => new Promise((_, reject) => sleep(2000)[1].then(reject))}>
      Promise Reject
    </CountdownButton>

Render Props

支持自定义更强的Render Props

    <CountdownButton time={10} onClick={() => sleep(2000)[1]}>
      {(isStart, count, loading) => {
        const text = '支持render props';
        if (loading) return '请稍后...';
        return isStart ? t[count] : text;
      }}
    </CountdownButton>

hook

如果想自定义元素,则可以使用useCountdown钩子,只提供倒计时功能

export default () => {
  const [loading, setLoading] = useState(false);
  const [isStart, count, countdown] = useCountdown(10);

  const onClick = async () => {
    if (isStart || loading) return;
    setLoading(true);
    await sleep(1500)[1];
    setLoading(false);
    countdown();
  };

  const children = isStart ? `${count}秒后重新获取` : `使用hook`;
  const loadingNode = <i>加载中...</i>;
  const btnNode = <button onClick={onClick}>{children}</button>;
  return loading ? loadingNode : btnNode;
};

Props

除去继承自 <Button>props<CountdownButton> 有自己额外的 props

| 属性 | 说明 | 类型 | 默认值 | | ---- | ---------------- | ------ | ------ | | unit | 倒计时数字的单位 | string | s | | time | 倒计时时长 | number | 60 |