-
-
Save bigslycat/673bf3fb7165421ede81da134f3818a9 to your computer and use it in GitHub Desktop.
Revisions
-
bigslycat revised this gist
Jan 24, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,9 +13,9 @@ import { } from 'recompose' const Modal = mapProps(({ close, title, ...props }) => ({ ...props, children: `Hide ${title} modal`, onClick: close, }))('button') const ModalButton = withProps({ -
bigslycat revised this gist
Jan 22, 2018 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -32,9 +32,9 @@ const withModal = })(({ isOpen, open, close, buttonProps, ...modalProps }) => ( <Fragment> {isOpen && createPortal( <ModalComponent {...modalProps} title={modalName} close={close} />, modalNode, )} <ButtonComponent {...buttonProps} onClick={open} /> </Fragment> )) -
bigslycat revised this gist
Jan 22, 2018 . 1 changed file with 38 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,22 +3,46 @@ ```javascript import React, { Fragment } from 'react' import { createPortal } from 'react-dom' import { withStateHandlers, withProps, mapProps, } from 'recompose' const Modal = mapProps(({ close, title, ...props }) => ({ children: `Hide ${title} modal`, onClick: close, ...props, }))('button') const ModalButton = withProps({ children: 'Open modal', })('button') const withModal = (modalNode, modalName, ModalComponent) => ButtonComponent => withStateHandlers({ isOpen: false, }, { open: () => () => ({ isOpen: true }), close: () => () => ({ isOpen: false }), })(({ isOpen, open, close, buttonProps, ...modalProps }) => ( <Fragment> {isOpen && createPortal( <ModalComponent {...modalProps} title={modalName} close={close} />, modalNode, )} <ButtonComponent {...buttonProps} onClick={open} /> </Fragment> )) export const PricingModal = withModal( document.getElementById('modals'), 'pricing', Modal, )(ModalButton) ``` -
Bitaru revised this gist
Jan 15, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ ### TASK: > Implement a "withModal" high order component (HOC) that will accept two arguments [modalName: String] and [modalComponent: React.Component]. It should render a "modalComponent" into the portal. In addition, this HOC should inject 'showModal' and 'hideModal' handlers into a new collection of props that are passed to the base component. For instance: ```javascript -
Bitaru revised this gist
Jan 15, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ const PricingModal = ({ title, onHide }) => <button onClick={onHide}>Hide {title} modal</button>; class PricingButton extends React.Component { showPricing: () => { const { openModal, hideModal } = this.props; openModal('pricing', { title: 'Pricing', -
Bitaru revised this gist
Jan 15, 2018 . 1 changed file with 15 additions and 16 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,24 +2,23 @@ > Implement a "withModal" high order component (HOC) that will accept two arguments [modalName: String] and [modalComponent: React.Component]. It should render a "modalComponent" into the portal. In addition, this HOC should inject 'showModal' and 'hideModal' into a new collection of props that are passed to the base component. For instance: ```javascript const PricingModal = ({ title, onHide }) => <button onClick={onHide}>Hide {title} modal</button>; class PricingButton extends React.Component { showProcing: () => { const { openModal, hideModal } = this.props; openModal('pricing', { title: 'Pricing', onHide: (data) => hideModal('pricing') }) } render() { return <button onClick={this.showPricing}>Open modal</button> } } export default withModal('pricing', PricingModal)(PricingButton) ``` -
Bitaru revised this gist
Dec 1, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ ### TASK: > Implement a "withModal" high order component (HOC) that will accept two arguments [modalName: String] and [modalComponent: React.Component]. It should render a "modalComponent" into the portal. In addition, this HOC should inject 'showModal' and 'hideModal' into a new collection of props that are passed to the base component. For instance: ```javascript import { compose, withHandlers } from 'recompose'; -
Bitaru revised this gist
Nov 30, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ ### TASK: > Write a "withModal" high order component (HOC), which will accept two arguments [modalName: String] and [modalComponent: React.Component] and render modalComponent into the portal. In addition, this HOC should inject 'showModal' and 'hideModal' to a new collection of props that are passed to the base component. For instance: ```javascript import { compose, withHandlers } from 'recompose'; -
Bitaru revised this gist
Nov 30, 2017 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,5 @@ ### TASK: > Write down a "withModal" high order component (HOC), which will accept two arguments [modalName: String] and [modalComponent: React.Component] and render modalComponent into the portal. In addition, this HOC should inject 'showModal' and 'hideModal' to a new collection of props that are passed to the base component. For instance: ```javascript import { compose, withHandlers } from 'recompose'; -
Bitaru revised this gist
Nov 30, 2017 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ ### TASK: > Write down a "withModal" high order component, which will accept two arguments [modalName: String] and [modalComponent: React.Component] and render modalComponent into portal. Also, this HOC should inject 'showModal' and 'hideModal' to a new collection of props that are passed to the base component. eq: ```javascript import { compose, withHandlers } from 'recompose'; -
Bitaru revised this gist
Nov 30, 2017 . 1 changed file with 7 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ Also, this HOF should inject 'showModal' and 'hideModal' to a new collection of ```javascript import { compose, withHandlers } from 'recompose'; const PricingModal = ({ title, onHide }) => <button onClick={onHide}>Hide {title} modal</button>; const enhance = compose( withModal('pricing', PricingModal), @@ -17,4 +17,10 @@ const enhance = compose( }) }) ) export default enhance(({ openModal }) => ( <button onClick={openModal}>Open modal</button> )) ``` -
Bitaru created this gist
Nov 30, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ ### TASK: > Write down a "withModal" hight order component, which will accept two arguments [modalName: String] and [modalComponent: React.Component] and render modalComponent into portal. Also, this HOF should inject 'showModal' and 'hideModal' to a new collection of props that are passed to the base component. eq: ```javascript import { compose, withHandlers } from 'recompose'; const PricingModal = ({ title, onHide }) => <button onClick={onHide}>Hide {title} modal</button> const enhance = compose( withModal('pricing', PricingModal), withHandlers({ showPricing: ({ openModal, hideModal }) => () => openModal('pricing', { title: 'Pricing', onHide: (data) => hideModal('pricing') }) }) ) ```