1.52.0 • Published 2 days ago

@s-ui/react-molecule-modal v1.52.0

Weekly downloads
1,723
License
MIT
Repository
-
Last release
2 days ago

MoleculeModal

Description

Modal windows focus users' attention to inform them about a specific interaction. They may require users to make a decision or warn them when an error may have very significant consequences.

Installation

$ npm install @s-ui/react-molecule-modal --save

Usage

⚠️ By default, import will take MoleculeModalWithAnimation, if you want to import a speciffic modal, just use named imports.

Those are the named exports enabled:

  • MoleculeModal
  • MoleculeModalWithURLState
  • MoleculeModalWithAnimation
  • MoleculeModalWithoutAnimation

Basic usage

import MoleculeModal from '@s-ui/react-molecule-modal'

const ContentWithCloseButton = ({children, onClose}) => (
  <div>
    {children}
    <button type="button" onClick={onClose}>
      close modal
    </button>
  </div>
)

class ModalWrapper extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      open: false
    }
  }

  openModal = () => {
    this.setState({
      open: true
    })
  }

  closeModal = () => {
    this.setState({
      open: false
    })
  }

  render() {
    return (
      <div>
        <button type="button" onClick={this.openModal}>
          Open modal
        </button>
        <MoleculeModal
          isOpen={this.state.open}
          closeOnOutsideClick
          closeOnEscKeyDown
          header="My new brand modal"
          iconClose={<IconClose />}
          onClose={this.closeModal}
        >
          <ContentWithCloseButton>
            <p>This is my modal content</p>
          </ContentWithCloseButton>
        </MoleculeModal>
      </div>
    )
  }
}

return (<ModalWrapper />)

Usage with url state

import {MoleculeModalWithURLState} from '@s-ui/react-molecule-modal'

const ContentWithCloseButton = ({children, onClose}) => (
  <div>
    {children}
    <button type="button" onClick={onClose}>
      close modal
    </button>
  </div>
)

const MODAL_HASH = 'myModal'

class ModalWrapper extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      open: false
    }
  }

  openModal = () => {
    this.setState({
      open: true
    })
  }

  closeModal = () => {
    this.setState({
      open: false
    })
  }

  render() {
    return (
      <div>
        <button type="button" onClick={this.openModal}>
          Open modal with url state
        </button>
        <MoleculeModalWithURLState
          isOpen={this.state.open}
          closeOnOutsideClick
          closeOnEscKeyDown
          header="My new brand modal"
          iconClose={<IconClose />}
          onClose={this.closeModal}
          hash={MODAL_HASH}
          openModalTrigger={this.openModal}
        >
          <ContentWithCloseButton>
            <p>This is my modal content</p>
          </ContentWithCloseButton>
        </MoleculeModalWithURLState>
      </div>
    )
  }
}

return (<ModalWrapper />)

Find full description and more examples in the demo page.

1.52.0

2 days ago

1.51.0

3 days ago

1.50.0

4 days ago

1.49.0

15 days ago

1.48.0

1 month ago

1.46.0

2 years ago

1.47.0

1 year ago

1.44.0

2 years ago

1.45.0

2 years ago

1.43.0

2 years ago

1.42.0

3 years ago

1.40.0

3 years ago

1.41.0

3 years ago

1.39.0

3 years ago

1.38.0

3 years ago

1.36.0

3 years ago

1.37.0

3 years ago

1.35.0

3 years ago

1.34.0

3 years ago

1.33.0

3 years ago

1.32.0

3 years ago

1.31.0

3 years ago

1.30.0

3 years ago

1.29.0

3 years ago

1.28.0

3 years ago

1.27.0

3 years ago

1.26.0

3 years ago

1.25.0

3 years ago

1.22.0

3 years ago

1.23.0

3 years ago

1.24.0

3 years ago

1.21.0

3 years ago

1.20.0

3 years ago

1.19.0

4 years ago

1.18.0

4 years ago

1.17.0

4 years ago

1.16.0

4 years ago

1.15.0

4 years ago

1.14.0

4 years ago

1.13.0

4 years ago

1.12.0

4 years ago

1.11.0

4 years ago

1.10.0

4 years ago

1.9.0

4 years ago

1.8.0

5 years ago

1.7.0

5 years ago

1.6.0

5 years ago

1.5.0

5 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.1.0

5 years ago

1.2.0

5 years ago