1.0.2 • Published 6 years ago

react-contextual-dialog v1.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

React Contextual Dialog

A simple set of dialog components that utilize React 16 context API

Installation

yarn add react-contextual-dialog or npm i react-contextual-dialog

Usage

Edit Example of react-contextual-dialog

Render a single DialogContainer heigher than you want to render the dialogs.

import React from 'react';
import { render } from 'react-dom';
import ContextualDialog from 'react-contextual-dialog';

const Main = ({ children }) => (
  <ContextualDialog.DialogContainer>
    {children}
  </ContextualDialog.DialogContainer>
);

render(<Main />, document.getElementById('app'));

You can now render a dialog anywhere in the children passed to <Main />

import React, { Fragment } from 'react';
import { render } from 'react-dom';
import ContextualDialog from 'react-contextual-dialog';

const Dialog = ({ open, close, isOpen }) => (
  <Fragment>
    {!isOpen && <button onClick={open}>Open the dialog</button>}
    {isOpen && (
      <div>
        I am a dialog
        <button onClick={close}>Close Me</button>
      </div>
    )}
  </Fragment>
);

const Popup = () => (
  <ContextualDialog.Dialog>
    <Dialog />
  </ContextualDialog.Dialog>
);

const Main = ({ children }) => (
  <ContextualDialog.DialogContainer>
    {children}
  </ContextualDialog.DialogContainer>
);

render(
  <Main>
    <Popup />
  </Main>,
  document.getElementById('app')
);