Skip to content

Commit

Permalink
Merge pull request #105 from 8base/mctx
Browse files Browse the repository at this point in the history
feat(Modal): export modal context instead of consumer
  • Loading branch information
ej9x authored Nov 2, 2018
2 parents 33ca965 + 5665732 commit 9c6409c
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/atoms/Modal/Modal.stories.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';

export default (asStory) => {
asStory('ATOMS/Modal (skip shot)', module, (story, { Modal, ModalConsumer, Button }) => {
asStory('ATOMS/Modal (skip shot)', module, (story, { Modal, ModalContext, Button }) => {
story
.add('multiple modals', () => (
<React.Fragment>
Expand Down Expand Up @@ -46,11 +46,11 @@ export default (asStory) => {
)
}
</Modal>
<ModalConsumer>
<ModalContext.Consumer>
{
({ openModal }) => <Button onClick={ () => openModal('ID', { foo: '00', bar: '00' }) }>Open</Button>
}
</ModalConsumer>
</ModalContext.Consumer>
</React.Fragment>
));
});
Expand Down
4 changes: 2 additions & 2 deletions src/atoms/Modal/ModalContext.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';

const { Provider, Consumer } = React.createContext('modal');
const ModalContext = React.createContext('modal');

export { Provider, Consumer };
export { ModalContext };
6 changes: 3 additions & 3 deletions src/atoms/Modal/ModalProvider.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component } from 'react';

import { Provider } from './ModalContext';
import { ModalContext } from './ModalContext';

class ModalProvider extends Component {
constructor(props) {
Expand Down Expand Up @@ -36,9 +36,9 @@ class ModalProvider extends Component {
const contextValue = this.collectContextValue();

return (
<Provider value={ contextValue }>
<ModalContext.Provider value={ contextValue }>
{ this.props.children }
</Provider>
</ModalContext.Provider>
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/atoms/Modal/withModal.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import { Consumer } from './ModalContext';
import { ModalContext } from './ModalContext';

const withModal = (BaseComponent) => {
class ModalStateConsumer extends React.Component {
Expand All @@ -15,7 +15,7 @@ const withModal = (BaseComponent) => {
}

render() {
return <Consumer>{ this.renderBaseComponent }</Consumer>;
return <ModalContext.Consumer>{ this.renderBaseComponent }</ModalContext.Consumer>;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/atoms/Modal/withModalState.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import { Consumer } from './ModalContext';
import { ModalContext } from './ModalContext';

const withModalState = (BaseComponent) => {
class ModalStateConsumer extends React.Component {
Expand All @@ -21,7 +21,7 @@ const withModalState = (BaseComponent) => {
const { id, ...rest } = this.props;

if (id) {
return <Consumer>{ this.renderBaseComponentWithModalProps }</Consumer>;
return <ModalContext.Consumer>{ this.renderBaseComponentWithModalProps }</ModalContext.Consumer>;
}

return <BaseComponent { ...rest } />;
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export { ThemeProvider } from 'emotion-theming';
export { defaultTheme, resetGlobal, Z_INDEX } from './theme';
export * from './atoms';
export * from './molecules';
export { Consumer as ModalConsumer } from './atoms/Modal/ModalContext';
export { ModalContext } from './atoms/Modal/ModalContext';
export { withModal } from './atoms/Modal/withModal';
export { EightBaseBoostProvider } from './EightBaseBoostProvider';

0 comments on commit 9c6409c

Please sign in to comment.