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

@ui-controls/progress

v0.0.4

Published

Material-UI Button + IconButton with progress (loading/error/success)

Downloads

167

Readme

UI-Controls: Progress

Material-UI Button + IconButton with progress (loading/error/success) and double-click-to-confirm states.

npm i --save @ui-controls/progress @mui/material react-progress-state

Examples:

Example ButtonConfirm

Only with a text:

import React from 'react'
import {ButtonConfirm} from '@ui-controls/progress/ButtonConfirm'

export const DemoProgress = () => {
    return <>
        <ButtonConfirm
            confirmText={'Click to confirm'}
            onClick={() => {
                console.log('confirm', new Date())
            }}
        >
            submit
        </ButtonConfirm>
    </>
}

With text, initial-icon and confirm icon:

import React from 'react'
import {ButtonConfirm} from '@ui-controls/progress/ButtonConfirm'
import IcDelete from '@mui/icons-material/DeleteOutline'
import IcDeleteConfirm from '@mui/icons-material/Delete'

export const DemoProgress = () => {
    return <>
        <ButtonConfirm
            confirmText={'Click to confirm'}
            confirmIcon={<IcDeleteConfirm/>}
            endIcon={<IcDelete/>}
            onClick={() => {
                console.log('confirm', new Date())
            }}
        >
            submit
        </ButtonConfirm>
    </>
}

Example IconButtonConfirm

import React from 'react'
import {IconButtonConfirm} from '@ui-controls/progress/IconButtonConfirm'
import IcDelete from '@mui/icons-material/DeleteOutline'
import IcDeleteConfirm from '@mui/icons-material/Delete'

export const DemoProgress = () => {
    return <>
        <IconButtonConfirm
            tooltip={'delete'}
            tooltipConfirm={'click again to confirm'}
            confirmIcon={<IcDeleteConfirm/>} // extra icon is optional
            onClick={() => {
                console.log('confirm', new Date())
            }}
        >
            <IcDelete/>
        </IconButtonConfirm>
    </>
}

Example ButtonProgress

import React from 'react'
import {ButtonProgress} from '@ui-controls/progress/ButtonProgress'
import {ps, useProgress} from 'react-progress-state'

export const DemoPage = () => {
    const [loading, setLoading, startLoading] = useProgress()
    return <>
        {/* Here would be your awesome form */}

        <ButtonProgress
            progress={loading.progress}
            onClick={() => {
                const pid = startLoading()
                new Promise((resolve) => {
                    // do some async stuff
                    window.setTimeout(() => {
                        resolve()
                    }, 600)
                })
                    .then(() => {
                        const isPid = setLoading(ps.done, undefined, pid)
                        if(!isPid) return
                        // when it didn't cancel or unmount, run the success logic
                        console.log('done', pid)
                    })
                    .catch((e) => {
                        const isPid = setLoading(ps.error, e, pid)
                        if(!isPid) return
                        // when it didn't cancel or unmount, run the error cleanup logic
                        console.log('error', pid)
                    })
            }}
        >
            submit
        </ButtonProgress>
    </>
}

Example IconButtonProgress

import React from 'react'
import {IconButtonProgress} from '@ui-controls/progress/IconButtonProgress'
import {ps, useProgress} from 'react-progress-state'
import IcLogin from '@mui/icons-material/Login'

export const DemoPage = () => {
    const [loading, setLoading, startLoading] = useProgress()
    return <>
        {/* Here would be your awesome form */}

        <IconButtonProgress
            progress={loading.progress}
            tooltip={'submit'}
            onClick={() => {
                const pid = startLoading()
                new Promise((resolve) => {
                    window.setTimeout(() => {
                        resolve()
                    }, 600)
                })
                    .then(() => {
                        const isPid = setLoading(ps.done, undefined, pid)
                        if(!isPid) return
                        console.log('done', pid)
                    })
                    .catch((e) => {
                        const isPid = setLoading(ps.error, e, pid)
                        if(!isPid) return
                        console.log('error', pid)
                    })
            }}
        >
            <IcLogin/>
        </IconButtonProgress>
    </>
}

Example ButtonProgress confirm

supports all props like ButtonProgress, activate confirm logic with either confirmText or confirmIcon

import React from 'react'
import {ButtonProgress} from '@ui-controls/progress/ButtonProgress'
import {ps, useProgress} from 'react-progress-state'
import IcDelete from '@mui/icons-material/DeleteOutline'
import IcDeleteConfirm from '@mui/icons-material/Delete'

export const DemoPage = () => {
    const [loading, setLoading, startLoading] = useProgress()
    return <>
        {/* Here would be your awesome form */}

        <ButtonProgress
            progress={loading.progress}
            confirmText={'Click to confirm'}
            confirmIcon={<IcDeleteConfirm/>}
            endIcon={<IcDelete/>}
            onClick={() => {
                const pid = startLoading()
                new Promise((resolve) => {
                    // do some async stuff
                    window.setTimeout(() => {
                        resolve()
                    }, 600)
                })
                    .then(() => {
                        const isPid = setLoading(ps.done, undefined, pid)
                        if(!isPid) return
                        // when it didn't cancel or unmount, run the success logic
                        console.log('done', pid)
                    })
                    .catch((e) => {
                        const isPid = setLoading(ps.error, e, pid)
                        if(!isPid) return
                        // when it didn't cancel or unmount, run the error cleanup logic
                        console.log('error', pid)
                    })
            }}
        >
            submit
        </ButtonProgress>
    </>
}

Example IconButtonProgress confirm

import React from 'react'
import {IconButtonProgress} from '@ui-controls/progress/IconButtonProgress'
import {ps, useProgress} from 'react-progress-state'
import IcDelete from '@mui/icons-material/DeleteOutline'
import IcDeleteConfirm from '@mui/icons-material/Delete'

export const DemoPage = () => {
    const [loading, setLoading, startLoading] = useProgress()
    return <>
        {/* Here would be your awesome form */}

        <IconButtonProgress
            progress={loading.progress}
            tooltip={'submit'}
            tooltipConfirm={'click again to confirm'}
            confirmIcon={<IcDeleteConfirm/>} // extra icon is optional
            onClick={() => {
                const pid = startLoading()
                new Promise((resolve) => {
                    window.setTimeout(() => {
                        resolve()
                    }, 600)
                })
                    .then(() => {
                        const isPid = setLoading(ps.done, undefined, pid)
                        if(!isPid) return
                        console.log('done', pid)
                    })
                    .catch((e) => {
                        const isPid = setLoading(ps.error, e, pid)
                        if(!isPid) return
                        console.log('error', pid)
                    })
            }}
        >
            <IcDelete/>
        </IconButtonProgress>
    </>
}

Example ListItemButtonConfirm

import React from 'react'
import {ListItemButtonConfirm} from '@ui-controls/progress/ListItemButtonConfirm'
import MuiList from '@mui/material/List'
import IcLogout from '@mui/icons-material/Logout'
import IcConfirm from '@mui/icons-material/QuestionMark'

export const DemoPage = () => {
    return <>
        <MuiList>
            <ListItemButtonConfirm
                onClick={() => {
                    console.log('confirm', new Date())
                }}
                sx={{py: 0}}
                icon={<IcLogout/>}
                confirmText={'Click to confirm'}
                confirmIcon={<IcConfirm/>}
                primary={'Logout'}
                secondaryTypographyProps={{variant: 'caption'}}
                secondary={'from App'}
            />
        </MuiList>
    </>
}

License

This project is free software distributed under the MIT License.

See: LICENSE.

© 2023 bemit UG (haftungsbeschränkt)