diff --git a/README.md b/README.md index 54e4ef3..94701b3 100644 --- a/README.md +++ b/README.md @@ -3,29 +3,22 @@ ### Usage ```javascript -// main.js -import { PopupProvider } from 'react-popup-provider'; - - - - - -// some-view.js import { Popup } from 'react-popup-provider'; - - {({ + ( - + )} + > {({ - closePopup, + close, }) => (
My popup - +
)}
@@ -34,21 +27,20 @@ import { Popup } from 'react-popup-provider'; ##### More Control ```javascript -// some-view.js -import { PopupContext, PopupContainer, PopupDef } from 'react-popup-provider'; - - - {({ contextRef, openPopup }) => ( +import { Consumer, PopupProvider, PopupContainer } from 'react-popup-provider'; + + + {({ contextRef, open }) => (
- +
)} - - + + {({ - contextClientRect, - closePopup, + contextRef, + close, isOpen, scrollableParents, }) => ( @@ -56,8 +48,8 @@ import { PopupContext, PopupContainer, PopupDef } from 'react-popup-provider'; { isOpen && {props.children} @@ -66,64 +58,56 @@ import { PopupContext, PopupContainer, PopupDef } from 'react-popup-provider'; )} - + ``` ### APIs ##### PopupProvider -Wrap it once or wrap it before you use Popup or Modal. +Context Provider. + +##### Consumer +Context Consumer. ##### Modal - * **Modal** - Simple compound component that hides the ModalContainer, ModalContext, and ModalDef. This is an example of what you can do with the other components. + * **Modal** - Simple compound component that hides the ModalContainer and context APIs. This is an example of what you can do with the other components. + * `as`: `React$ElementType` - defaults to `div`. Container's root element. + * `children`: `({ close, isOpen }) => React$Node` + * `className`: `string` + * `close`: `() => void` - Close function callback. + * `context`: `({ close, contextRef, isOpen, open, scrollableParents }) => React$Node` + * `root`: `HTMLElement` - Portal element. Defaults to `` + * `style`: `{ [string]: any }` * **ModalContainer** - container that renders to portal * `as`: `React$ElementType` - defaults to `div`. Container's root element. - * `children`: `ModalContainerArgs => React$Node` + * `children`: `({ close, isOpen }) => React$Node` * `className`: `string` - * `closeModal`: `CloseModal` - Close modal function callback. - * `id`: `string` - Required. + * `close`: `() => void` - Close function callback. * `root`: `HTMLElement` - Portal element. Defaults to `` * `style`: `{ [string]: any }` - * `willBePreMounted`: `boolean` - This was really for react-spring's animation to `auto` height/width option, not sure if react-spring still works with `auto`. - * **ModalContext** - context for Modal - * `children`: `{ closeModal, isOpen, openModal } => )` - * `popupId`: `string` - Required, must match with PopupDef's `id` - * **PopupDef** - popup definition - * `children`: `({ closePopup, contextRef, isOpen, scrollableParents }) => (isOpen && )` - * `id`: `sting` - Required, must match with PopupContext's `id` - - -### What's Next? - * Eliminate the necessity of `id` by requiring one provider per Modal or Popup. This will simplify some internal logic as well.