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

use-temporary-disclosure

v1.0.1

Published

Effortlessly manage temporary UI elements with this react hook allowing you to show or hide an element for a period of time. Ideal for displaying messages, toggles, or any component that needs to appear and disappear after a set duration.

Downloads

11

Readme

use-temporary-disclosure-banner

use-temporary-disclosure

use-temporary-disclosure is a React hook that provides an easy way to manage the visibility of UI elements for a specific duration. It's perfect for temporary notifications, tooltips, or any component that should appear for a limited time. The hook offers simple yet powerful functions to show and hide elements with timing control and callback functionalities.

Installation

To install the package, run the following command in your project directory:

npm install use-temporary-disclosure

Example use

Here's a basic example of how to use use-temporary-disclosure in your React component to display a notification component for 5000ms.

import useTemporaryDisclosure from 'use-temporary-disclosure';

const DemoComponent = () => {
	const { isOpen, openFor } = useTemporaryDisclosure();

	const handleShowNotification = () => {
		openFor({
			duration: 3000,
			callback: () => alert('Notification closes now'),
		});
	};

	return (
		<div
			style={{
				width: '100vw',
				height: '100vh',
				display: 'flex',
				alignItems: 'center',
				justifyContent: 'center',
			}}
		>
			<button
				onClick={handleShowNotification}
				style={{ cursor: 'pointer' }}
			>
				Show Notification
			</button>

			{isOpen && (
				<div style={{ color: 'green' }}>Notification content.</div>
			)}
		</div>
	);
};

export default DemoComponent;

API Reference

useTemporaryDisclosure returns an object with the following properties

const { openFor, isOpen, openIn, closeIn } =
	useTemporaryDisclosure();

For easy use

openFor(opts: TemporaryDisclosureFunctionOpts): void Sets the state to open, then automatically closes it after a specified duration and executes a callback function, see example above.

isOpen: boolean Indicates the current open state.

export type TemporaryDisclosureFunctionOpts = {
	/**
	 * The delay or duration to apply in milliseconds
	 * @optional
	 * @default 0
	 */
	duration?: number;

	/**
	 * Callback to run after the delay and the action is complete
	 * @optional
	 */
	callback?: () => void;
};

If you want fine grain control

openIn(opts: TemporaryDisclosureFunctionOpts): void Sets the state to open after a delay and executes a callback function.

closeIn(opts: TemporaryDisclosureFunctionOpts): void Sets the state to closed after a delay and executes a callback function.

TemporaryDisclosureFunctionOpts take an optional duration in milliseconds and optional callback.

License

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

Contribute

Feel free to suggest improvements or submit a PR!

Gotchas if you run this locally

Given you have a create-react-app on the side to test the package locally, use the same React versions, in order to do this you should link or import react and react-dom from use-temporary-disclosure.

npm install ../../path-to/use-temporary-disclosure/node_modules/react