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

react-paramify

v0.0.15

Published

A React package for handling data displaying by using URL parameters written by TS

Downloads

8

Readme

React Paramify

React Paramify is a package written with TypeScript for React.js, for managing modals and dialogs and ... via URL parameters.

This package is currently using Material UI components for displaying data ( that's just for now ).

React Paramify is great choice for PWA applications where you have to deal with device back buttons !

React Paramify simply manages the opened UI components ( modals, alerts , ... ) when user press/click the device/browser back button so they will NOT redirect to previous URL unwanted ! instead, only the last opened component would be closed.

Installation

If you are using npm :

 npm install react-paramify

using yarn:

 yarn add react-paramify

Dependencies

Following packages are required as dependencies temporary :

 npm install @mui/material @emotion/react @emotion/styled @mui/icons-material

Usage

Using react-paramify package is pretty simple !

All you have to do is to wrap the ParamifyWrapper component around your application at root of the project.

Initialization

in root file of your project :

import { ParamifyWrapper } from 'react-paramify';

/**
 * The root component of the application.
 */

const root = createRoot(document.getElementById('root'));

root.render(<ParamifyWrapper>{/* Your Application Code */}</ParamifyWrapper>);

And that's it ! react-paramify is now listening for you to trigger UI components by the hooks that will be introduced later in this documentation.

ParamifyWrapper

The main component that should be wrapped around your application.

ParamifyWrapper props interface :

  • children : Your application code and components.
  • fallback? : Fallback component which will be rendered for lazy components loading. ( default : MUI linear loading at top of the page )

Modals

MUI Dialog component is used as modal component, you can open modal at anywhere on your app via usePushModal() hook :

import { usePushModal } from 'react-paramify';

function SomeRandomComponent() {
  const pushModal = usePushModal();

  const onNewModal = () => {
    pushModal({ key: 'some-random-key', body: () => <SomeRandomModal /> });
  };

  return <button onClick={onNewModal}> Click </button>;
}

After using this hook, the object ( which is Modal interface) you provided for pushModal function will be added to the modal list array and getting rendered immediately on the page.

Usually you don't need to close modals manually, react-paramify takes the control for that but for special cases, you can close the last opened modal via usePopModal() hook ( pop out of array ) :

import { usePopModal } from 'react-paramify';

function SomeRandomComponent() {
  const popModal = usePopModal();

  const onCloseModal = () => {
    popModal();
  };

  return <button onClick={onCloseModal}> Click </button>;
}

Alternatively you can close all modals at once with usePopAllModals() hook :

import { usePopAllModals } from 'react-paramify';

const popAllModals = usePopAllModals();
popAllModals();

Here is the last hook for modals : the useModal() hook.

this hook returns following fields :

  • items : they array of modal items that are currently available and open in react-paramify, every time you use any hook related to modals ( the introduced hooks ), this property gets changed.
  • pushModal: returns usePushModal()
  • popModal : returns usePopModal()
  • popAllModals : returns usePopAllModals()
import { useModal } from 'react-paramify';

const {
  items, // array of Modal interface
  pushModal, // function
  popModal, // function
  popAllModals, // function
} = useModal();

Alert

MUI Dialog component is used as alert component, you can open alert at anywhere on your app via usePushAlert() hook :

import { usePushAlert } from 'react-paramify';

function SomeRandomComponent() {
  const pushAlert = usePushAlert();

  const onNewAlert = () => {
    pushAlert({ key: 'some-random-key', body: <SomeRandomAlert /> });
  };

  return <button onClick={onNewAlert}> Click </button>;
}

After using this hook, the object ( which is Alert interface) you provided for pushAlert function will be added to the alert list array and getting rendered immediately on the page.

Usually you don't need to close alerts manually, react-paramify takes the control for that but for special cases, you can close the last opened alert via usePopAlert() hook ( pop out of array ) :

import { usePopAlert } from 'react-paramify';

function SomeRandomComponent() {
  const popAlert = usePopAlert();

  const onCloseAlert = () => {
    popAlert();
  };

  return <button onClick={onCloseAlert}> Click </button>;
}

Alternatively you can close all alerts at once with usePopAllAlerts() hook :

import { usePopAllAlerts } from 'react-paramify';

const popAllAlerts = usePopAllAlerts();
popAllAlert();

Here is the last hook for alerts : the useAlert() hook.

this hook returns following fields :

  • items : they array of alert items that are currently available and open in react-paramify, every time you use any hook related to alerts ( the introduced hooks ), this property gets changed.
  • pushAlert: returns usePushAlert()
  • popAlert : returns usePopAlert()
  • popAllAlerts : returns usePopAllAlerts()
import { useAlert } from 'react-paramify';

const {
  items, // array of Modal interface
  pushAlert, // function
  popAlert, // function
  popAllAlerts, // function
} = useAlert();

Interfaces

Modal :

import { ReactNode } from 'react';
import { DialogProps } from '@mui/material';

interface Modal {
  key: string;
  body: (bodyProps: BodyProps) => ReactNode;
  title?: string;
  closeIcon?: ReactNode;
  maxWidth?: DialogProps['maxWidth'];
  scroll?: DialogProps['scroll'];
  fullScreen?: boolean;
}

Alert :

import { ReactNode } from 'react';
import { DialogProps } from '@mui/material';

interface Alert {
  key: string;
  body: ReactNode;
  title?: string;
  onCancel?: () => void;
  cancelText?: string;
  cancelColor?: ButtonProps['color'];
  onOk?: () => void;
  okText?: string;
  okColor?: ButtonProps['color'];
}

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.