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

@tembell/paresseux

v0.4.0

Published

🐨 Lazy & Synchronous flows for modals interactions in React

Downloads

93

Readme

Paresseux Logo

Paresseux (French word for "sloth" or "lazy", pronounced /pa.ʁɛ.sø/, like "par-eh-suh") is a React modal management library designed to streamline the handling of modals in a linear fashion, especially within complex workflows. It provides a convenient way to manage modals and their interactions while keeping your codebase clean and maintainable.

Getting Started

To start using Paresseux in your React application, follow these simple steps:

Installation

Install the library using your favorite package manager:

npm install @tembell/paresseux
# or
yarn add @tembell/paresseux
# or
pnpm add @tembell/paresseux

Wrap Your App

Wrap your application with the <ModalsProvider> to enable the use of the useOpenModal hook:

import { ModalsProvider } from '@tembell/paresseux';

function App() {
  return (
    <ModalsProvider>
      {/* Your app components */}
    </ModalsProvider>
  );
}

Example Usage

Now, you can use the useOpenModal hook to manage your modals in a linear flow. Here's an example:

import { useOpenModal } from '@tembell/paresseux';

export default function YourComponent() {
  const openModal = useOpenModal();

  async function takeAction() {
    try {
      type SlothAction = 'sleep' | 'eat' | undefined;
      const slothAction = await openModal<SlothAction>((resolve, reject) =>
        <SlothActionModal 
          onCancel={() => reject()}
          onChooseAction={(value) => resolve(value)}
        />
      );

      if (slothAction === 'sleep') {
        // Go to sleep ...
        return;
      }

      type Food = 'leaves' | 'fruits' | 'insects' | undefined;
      const foodChoice = await openModal<Food>((resolve, reject) =>
      <FoodModal 
          onCancel={() => reject()}
          onChooseAction={(value) => resolve(value)}
        />
      );

      // Eat chosen fruit...
    } catch (err) {
      // do nothing for cancel
      return; 
    }
  }

  return (
    <>
      <h1>Hey Mr.Sloth, What do you want to do today?</h1>
      <Button onClick={takeAction}>Take Action</Button>
    </>
  );
}

You can also go to the ./examples/simple React App to see a full app usage.

Typescript

To be able to know what the return type is of the openModal you need to provide it a type, not giving a type will result in unknown.

// ----- No Type ------
try {
  const someValue = await openModal((resolve, reject)=> 
    <div>
      <div 
        onClick={() => resolve("yay")}>
          Resolve
      </div>
      <div 
        onClick={() => reject("nay")}>
          Reject
      </div>
    </div>
  );
  console.log({someValue}) // `someValue` will contain "yay" but will be typed to `unknown` 
} catch(error) {
  console.log({error}) // `error` will contain "nay" but will be typed to `unknown` 
}




// ----- With Type ------
try {
  const someValue = await openModal<"yay", "nay">((resolve, reject)=> 
    <div>
      <div 
        onClick={() => resolve("yay")}>
          Resolve
      </div>
      <div 
        onClick={() => reject("nay")}>
          Reject
      </div>
    </div>
  );
  console.log({someValue}) // `someValue` will contain "yay" and will be typed to `"yay"` 
} catch(error) {
  console.log({error}) // `error` will contain "nay" but will STILL be typed to `unknown` 
}

The types also help you when passing values to resolve and reject

Contributors

A special thanks to Yair for the brilliant idea and the initial pieces of code that laid the foundation for Paresseux.

License

This project is licensed under the MIT License - see the LICENSE file for details.