1.2.5 • Published 5 years ago

context-react-modal v1.2.5

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

Context Modal

Table of Contents

Installation

To install, you can use npm:

$ npm install context-react-modal

Usage

import React from 'react'
import ReactDOM from 'react-dom'
import { ModalContext, ModalRootProvider, Modal } from 'context-react-modal'

const App = () => {
  const { showModal } = React.useContext(ModalContext)

  return (
    <div>
      <button
        onClick={() => {
          showModal(params => (
            <Modal
              animationName='swing'
              condition={() => (10 > 20 ? true : false)}
              closeTimeout={400}
              {...params}
            >
              {({ closeModal }) => Some modal}
            </Modal>
          ))
        }}
      >
        Try me!
      </button>
    </div>
  )
}

const rootElement = document.getElementById('root')
ReactDOM.render(
  <ModalRootProvider>
    <App />
  </ModalRootProvider>,
  rootElement,
)

API documentation

PropsTyperequiredexamplesdescription
childrenReactNodetrue
typestring - danger , success, primaryfalseexample-types
customTypeStylesFlattenInterpolation - key: { danger , success,primary }falsecustom-types
styleFlattenInterpolationfalsecustom-style
animationNamestring - jackIn, rubber, swing, rotate, translate, scale, rollinfalseAnimations
customAnimationFlattenInterpolation<ThemedStyledProps<{ isAnimated?: boolean }, any>>falseCustom animation
labelTextstringfalse
labelComponent(props: CustomLabelProps) => ReactNodefalselabel component
idnumbertrue
condition() => booleanfalseyour condition to render the component
cookieobjectfalseArray modals
cookie => namestringtrue
cookie => maxAgenumber - MSfalsecookie lifetime - ms
closeTimeoutnumber - MSfalsetime to remove a component - ms (400)

API context

ContextTypedescription
showModal<T extends RenderNodeModal | Array<RenderNodeModal>>(renderNodeModal: T) => voidmodal open function
hideModal(id: number) => voidmodal close request
nodeListArray<{ id: number, node: node: (props: { id: number; key: number }) => ReactNode }>opened modals
currentNodeIdnumberid active modal
renderNodeModalRenderNodeModal = (props: { id: number }) => React.ReactNodemodal component type

Demos

https://bogdanq.github.io/modal-story/public/?path=/story/modals--default-modal

1.2.5

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago