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

rx-cf

v3.0.3

Published

Copy from https://github.com/jonatanklosko/material-ui-confirm.git

Downloads

2

Readme

Material-UI confirm GitHub license npm version Actions Status Coverage Status

Copy from https://github.com/jonatanklosko/material-ui-confirm version 3.0.3 Confirming user choice is a good thing to do, it should also be easy to do.

This package provides simple confirmation dialogs built on top of @mui/material and straightforward to use thanks to React Hooks.

Installation

npm install --save material-ui-confirm

Demo

Edit material-ui-confirm demo

Usage

Wrap your app inside the ConfirmProvider component.
Note: If you're using Material UI ThemeProvider, make sure ConfirmProvider is a child of it.

import React from 'react';
import { ConfirmProvider } from 'material-ui-confirm';

const App = () => {
  return (
    <ConfirmProvider>
      {/* ... */}
    </ConfirmProvider>
  );
};

export default App;

Call the useAsyncConfirm hook wherever you need the confirm function.
Note: A component calling useAsyncConfirm must be a child of ConfirmProvider.

import React from 'react';
import Button from '@mui/material/Button';
import { useAsyncConfirm } from 'material-ui-confirm';

const Item = () => {
  const confirm = useAsyncConfirm();

  const handleClick = () => {
    confirm({ description: 'This action is permanent!' })
      .then(() => { /* ... */ })
      .catch(() => { /* ... */ });
  };

  return (
    <Button onClick={handleClick}>
      Click
    </Button>
  );
};

export default Item;

API

ConfirmProvider

This component is required in order to render a dialog in the component tree.

Props

| Name | Type | Default | Description | | ---- | ---- | ------- | ----------- | | defaultOptions | object | {} | Overrides the default options used by confirm. |

useAsyncConfirm() => confirm

This hook returns the confirm function.

confirm([options]) => Promise

This function opens a confirmation dialog and returns a promise representing the user choice (resolved on confirmation and rejected on cancellation).

Options

| Name | Type | Default | Description | | ---- | ---- | ------- | ----------- | | title | ReactNode | 'Are you sure?' | Dialog title. | | description | ReactNode | '' | Dialog content, automatically wrapped in DialogContentText. | | content | ReactNode | null | Dialog content, same as description but not wrapped in DialogContentText. Supersedes description if present. | | confirmationText | ReactNode | 'Ok' | Confirmation button caption. | | cancellationText | ReactNode | 'Cancel' | Cancellation button caption. | | dialogProps | object | {} | Material-UI Dialog props. | | confirmationButtonProps | object | {} | Material-UI Button props for the confirmation button. | | cancellationButtonProps | object | {} | Material-UI Button props for the cancellation button. | | titleProps | object | {} | Material-UI DialogTitle props for the dialog title. | | contentProps | object | {} | Material-UI DialogContent props for the dialog content. | | allowClose | boolean | true | Whether natural close (escape or backdrop click) should close the dialog. When set to false force the user to either cancel or confirm explicitly. |

Useful notes

Confirm by pressing Enter

You can get this behavior by adding the autoFocus property to the confirmation button. This way the button is focused as soon as the dialog opens and hitting Enter naturally triggers a click.

Locally
const MyComponent = () => {
  // ...

  const handleClick = () => {
    confirm({ confirmationButtonProps: { autoFocus: true } })
      .then(() => { /* ... */ })
      .catch(() => { /* ... */ });
  };

  // ...
};
Globally
const App = () => {
  return (
    <ConfirmProvider
      defaultOptions={{
        confirmationButtonProps: { autoFocus: true }
      }}
    >
      {/* ... */}
    </ConfirmProvider>
  );
};