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

chakraui-modal-wrapper

v1.0.2

Published

A simple Wrapper for the Chakra UI Modal. Made as I wanted to simplify the Modal component which I used extensively in my code.

Downloads

17

Readme

Chakra Modal Wrapper

Simple Wrapper for Chakra UI's Modal, while maintaining flexibility

Installation

Chakra UI needs to be installed, follow Installing ChakraUI

(TLDR for npm. Please note that you still need to setup the ChakraProvider as well, if you've already have it installed just install chakraui-modal-wrapper)

npm

npm i @chakra-ui/react @emotion/react @emotion/styled framer-motion chakraui-modal-wrapper

yarn

yarn add @chakra-ui/react @emotion/react @emotion/styled framer-motion chakraui-modal-wrapper

Props

The <SimpleModal> extends ModalProps of ChakraUI, so you can directly inject those props to <Modal> component. For the other components inside (<ModalBody>,<ModalHeader>,<ModalOverlay>,<ModalFooter>,<ModalContent>,<ModalCloseButton>), you may inject props via the elementProps prop (see table)

| Props | Type | Description | ---|---|---| title | React.ReactNode | Title of Modal | body | React.ReactNode | React.ReactNode[] | Content of Modal | footer | React.ReactNode | React.ReactNode[] | Footer of Modal (if needed) | hideCloseButton | boolean | Hides Close Button (Close Button shown by default) hideOverlay | boolean | Hides Overlay (Overlay shown by default) elementProps| Object ElementTypecloseButtonPropsPartial<ModalCloseButtonProps>overlayPropsPartial<ModalOverlayProps>contentPropsPartial<ModalContentProps>bodyPropsPartial<ModalBodyProps>headerPropsPartial<ModalHeaderProps>footerPropsPartial<ModalFooterProps> |Props for the Chakra UI Elements | elementRefs | Object ElementTypecloseButtonRefRefObject<HTMLButtonElement>overlayRefRefObject<HTMLDivElement>contentRefRefObject<HTMLDivElement>bodyRefRefObject<HTMLDivElement>headerRefRefObject<HTMLDivElement>footerRefRefObject<HTMLDivElement> | Refs for the Chakra UI Elements

Usage

Basic Usage

import {SimpleModal} from "chakraui-modal-wrapper"

const MyModalPage = () => {
  // Use a state or useDisclosure since this is
  // wrapping chakra UI
  const {isOpen, onClose, onOpen} = useDisclosure()
  
  return <div>
    <button onClick={onOpen}>Open Modal</button>
    <SimpleModal 
      isOpen={isOpen}
      onClose={onClose}
      // Use a ReactNode
      title="Modal Title"
      // Use a ReactNode
      body={<div>
        <p>My Modal Body</p>
      </div>}
      isOpen
    />
  </div>
}

Changing the Size / Using ModalProps

import {SimpleModal} from "chakraui-modal-wrapper"

const MyModalPage = () => {
  // Use a state or useDisclosure since this is
  // wrapping chakra UI
  const {isOpen, onClose, onOpen} = useDisclosure()
  
  return <div>
    <button onClick={onOpen}>Open Modal</button>
    <SimpleModal 
      size="4xl" // Extends ModalProps, autocomplete is included
      p={4} // Extends ModalProps
      isOpen={isOpen}
      onClose={onClose}
      // Use a ReactNode
      title="Modal Title"
      // Use a ReactNode
      body={<div>
        <p>My Modal Body</p>
      </div>}
      isOpen
    />
  </div>
}

Injecting Props to Other Components

import {SimpleModal} from "chakraui-modal-wrapper"

const MyModalPage = () => {
  // Use a state or useDisclosure since this is
  // wrapping chakra UI
  const {isOpen, onClose, onOpen} = useDisclosure()
  
  return <div>
    <button onClick={onOpen}>Open Modal</button>
    <SimpleModal 
      size="4xl" // Extends ModalProps, autocomplete is included
      p={4} // Extends ModalProps
      elementProps={{
        footerProps: {p:4, borderColor:'red.400',borderWidth:2} // ModalFooterProps
        bodyProps: {p:2, backgroundColor:'blue.300', } // ModalBodyProps
      }}
      isOpen={isOpen}
      onClose={onClose}
      // Use a ReactNode
      title="Modal Title"
      // Use a ReactNode
      body={<div>
        <p>My Modal Body</p>
      </div>}
      isOpen
    />
  </div>
}

Injecting Refs to components

import {SimpleModal} from "chakraui-modal-wrapper"

const MyModalPage = () => {
  // Use a state or useDisclosure since this is
  // wrapping chakra UI
  const {isOpen, onClose, onOpen} = useDisclosure()


  const footerRef = useRef<HTMLDivElement>()
  
  return <div>
    <button onClick={onOpen}>Open Modal</button>
    <SimpleModal 
      elementRefs={{
        footerRef: footerRef // Each component can be given a ref except for the main Modal, which doesnt have a ref 
      }}
      isOpen={isOpen}
      onClose={onClose}
      // Use a ReactNode
      title="Modal Title"
      // Use a ReactNode
      body={<div>
        <p>My Modal Body</p>
      </div>}
      isOpen
    />
  </div>
}