1.4.3 • Published 3 years ago

react-tiny-modals v1.4.3

Weekly downloads
-
License
-
Repository
github
Last release
3 years ago

react-tiny-modals

A super barebones react component library. Featurnig Modal and Popup components.

Install

yarn add react-tiny-modals

or

npm install react-tiny-modals --save

Usage

Modal:

import { Modal } from 'react-tiny-modals'

...

const [showModal, setShowModal] = React.useState(false);

<Modal
  isOpen={showModal}
  onOpen={() => console.log('onopen')}
  onClose={() => console.log('onclose')}
  zIndex={20}
  backOpacity={0.7}
>
  <div>This is the content of the modal.</div>
</Modal>

<button onClick={() => setShowModal(!showModal)}>open modal</button>

Popup:

import { Popup } from 'react-tiny-modals'

...

<Popup
  content={({ show, setShow }) => (
    <div>
      This is the content of the popup.
      <button onClick={() => setShow(!show)}>close</button>
    </div>
  )}
  position={['left', 'right', 'top', 'bottom']}
  align="center"
  reposition={true}
  outerPadding={10}
>
  {({ show, setShow }) => (
    <button onClick={() => setShow(!show)}>open popup</button>
  )}
</Popup>

Props:

Modal:

propertyacceptsdescriptiondefault
isOpenbooleancontrols whether the modal is openfalse
onOpenfunctiongets called after the modal was openednull
onClosefunctiongets called after the modal was closednull
onClickOutsidefunctiongets called after the user clicks outside of the modal contentnull
zIndexnumbersets the zIndex of the modal100
backOpacityfloatsets the opacity of the black background0.8(80%)
innerStyleobjectsets the styles of the inner content wrapperundefined
outerStyleobjectsets the styles of the top level divundefined
classNamestringsets custom className to the top level divundefined

Popup:

property (* is required)acceptsdescriptiondefault
isOpen (not recomended, use render props returned by content and the Popup component instead)booleancontrols whether the popup is openfalse
content*functionrecieves show/setShow as parameters, returns content of the popupnull
zIndexnumbersets the zIndex of the content div100
innerStyleobjectsets the styles of the content divundefined
position'left' | 'right' | 'top' | 'bottom' | Arrayposition of the popup content relative to the calling element, can recieve array of positions(ex.'left', 'right', 'top', 'bottom') ordered by priority. if reposition is set to true, final position will be picked based on available screen space'left', 'right', 'top', 'bottom'
repositionbooleancontrols whether the popup should automatically be repositioned to fit the screen space. when set to false, the popup will always stay in the position specified in the 'position' prop(if an array was provided, the first item will be choosen)true
align'center' | 'start' | 'end'alignment of the popup content relative to the calling elementcenter
outerPaddingnumberspace between the popup content and the calling element(in pixels)0
onOpenfunctiongets called after the popup was openednull
onClosefunctiongets called after the popup was closednull
onClickOutsidefunctiongets called after the user clicks outside of the popup content (recieves show/setShow as parameters)null
1.4.3

3 years ago

1.4.2

3 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.3.14

3 years ago

1.3.17

3 years ago

1.3.18

3 years ago

1.3.15

3 years ago

1.3.16

3 years ago

1.3.19

3 years ago

1.3.13

3 years ago

1.3.12

3 years ago

1.3.11

3 years ago

1.3.9

3 years ago

1.3.8

3 years ago

1.3.7

3 years ago

1.3.6

3 years ago

1.3.5

3 years ago

1.3.4

3 years ago

1.3.3

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago