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

antd-promise-button

v1.0.1

Published

A Promising Button Component

Downloads

5

Readme

🥑 antd-promise-button Typed

Build Status Maintainability Test Coverage Known Vulnerabilities Netlify Status

A Promising Button Component (Demo)

Why?

Promise buttons can be used to make many interfaces feel more responsive and intuitive.

When the user clicks a promise button, a loading spinner is shown and the button is disabled. This feedback assures the user that their action is being processed, and prevents accidental double-clicks and other bugs.

If the action is successful, the button turns green and shows a success message. This makes the page feel more responsive while the user waits for data to load, the page to redirect or other slow processes to complete.

If the action is unsuccessful, the button will turn red and show an error message.

Installation npm version

npm i antd-promise-button

Usage Storybook

See the demo for live examples

import { Button } from 'antd-promise-button';
import 'antd/lib/button/style/css' // Don't forget styles!

// In the simplest case, you just need to return a promise
//   from your onClick handler
const onClick = () => new Promise(res => setTimeout(res, 1000))
return <Button onClick={onClick}>Click Me!</Button>

// For better UX, customise the labels based on the status
return (
  <Button
    type="primary"
    onClick={login}
    labels={{
      [Button.FULFILLED]: 'Logged In',
      [Button.INITIALISED]: 'Log In',
      [Button.PENDING]: 'Logging In',
      [Button.REJECTED]: 'Log In Failed',
    }}
  />
)

// You can even customise the green/red colors
return (
  <Button
    onClick={signUp}
    labels={{
      [Button.FULFILLED]: 'Signed Up',
      [Button.INITIALISED]: 'Sign Up',
      [Button.PENDING]: 'Signing Up',
      [Button.REJECTED]: 'Sign Up Failed',
    }}
    colors={{
      [Button.FULFILLED]: '#00FF00',
      [Button.REJECTED]: '#FF69B4',
    }}
  />
)

onClick

The button is backwards compatible, if your onClick handler doesn't return a promise, it behaves just like a normal button.

Remember that you cannot return false to prevent default behavior in React. So while any non-promise will work, you should only ever need to return a Promise or undefined.

Currently only native promises are tested for, but any thenable should work.

Contribution & Feedback Conventional Commits

Question? Bug? Feature request? Not sure? Open an issue!

If this is almost what you were looking for, let me know and I can probably help!

Pull requests welcome, but please get in touch first. I don't want to waste your time 😁

See the code on GitHub