-
Notifications
You must be signed in to change notification settings - Fork 92
add a modal component #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| import '@storybook/addon-options/register'; | ||
| import '@storybook/addon-actions/register'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| @import "~bootstrap/scss/_modal"; | ||
|
|
||
| .modal-open { | ||
| display: block; | ||
| } | ||
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| import React from 'react'; | ||
| import { storiesOf } from '@storybook/react'; | ||
| import { action } from '@storybook/addon-actions'; | ||
| import PropTypes from 'prop-types'; | ||
|
|
||
| import Modal from './index'; | ||
| import Button from '../Button'; | ||
| import InputText from '../InputText'; | ||
|
|
||
| class ModalWrapper extends React.Component { | ||
| constructor(props) { | ||
| super(props); | ||
|
|
||
| this.openModal = this.openModal.bind(this); | ||
| this.resetModalWrapperState = this.resetModalWrapperState.bind(this); | ||
|
|
||
| this.state = { open: false }; | ||
| } | ||
|
|
||
| openModal() { | ||
| this.setState({ open: true }); | ||
| } | ||
|
|
||
| resetModalWrapperState() { | ||
| this.setState({ open: false }); | ||
| this.button.focus(); | ||
| } | ||
|
|
||
| render() { | ||
| return ( | ||
| <div> | ||
| <Modal | ||
| open={this.state.open} | ||
| title={this.props.title} | ||
| body={this.props.body} | ||
| onClose={this.resetModalWrapperState} | ||
| /> | ||
| <Button | ||
| onClick={this.openModal} | ||
| display="Click me to open a modal!" | ||
| buttonType="light" | ||
| inputRef={(input) => { this.button = input; }} | ||
| /> | ||
| </div> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| ModalWrapper.propTypes = { | ||
| title: PropTypes.oneOfType([PropTypes.string, PropTypes.element]).isRequired, | ||
| body: PropTypes.oneOfType([PropTypes.string, PropTypes.element]).isRequired, | ||
| }; | ||
|
|
||
| ModalWrapper.defaultProps = { | ||
| open: false, | ||
| }; | ||
|
|
||
| storiesOf('Modal', module) | ||
| .add('basic usage', () => ( | ||
| <Modal | ||
| open | ||
| title="Modal title." | ||
| body="Modal body." | ||
| onClose={() => {}} | ||
| /> | ||
| )) | ||
| .add('configurable buttons', () => ( | ||
| <Modal | ||
| open | ||
| title="Modal title." | ||
| body="Modal body." | ||
| buttons={[ | ||
| <Button | ||
| display="Blue button!" | ||
| buttonType="primary" | ||
| />, | ||
| { | ||
| display: 'Red button!', | ||
| buttonType: 'danger', | ||
| }, | ||
| <Button | ||
| display="Green button!" | ||
| buttonType="success" | ||
| />, | ||
| ]} | ||
| onClose={() => {}} | ||
| /> | ||
| )) | ||
| .add('configurable title and body', () => ( | ||
| <Modal | ||
| open | ||
| title="Custom title!" | ||
| body="Custom body!" | ||
| buttons={[ | ||
| <Button | ||
| display="Dark button!" | ||
| buttonType="dark" | ||
| />, | ||
| ]} | ||
| onClose={() => {}} | ||
| /> | ||
| )) | ||
| .add('configurable buttons that perform actions', () => ( | ||
| <Modal | ||
| open | ||
| title="Modal title." | ||
| body="Modal body." | ||
| buttons={[ | ||
| <Button | ||
| display="Click me and check the console!" | ||
| buttonType="light" | ||
| onClick={action('button-click')} | ||
| />, | ||
| ]} | ||
| onClose={() => {}} | ||
| /> | ||
| )) | ||
| .add('configurable close button', () => ( | ||
| <Modal | ||
| open | ||
| title="Modal title." | ||
| body="Modal body." | ||
| closeText="SHOO!" | ||
| onClose={() => {}} | ||
| /> | ||
| )) | ||
| .add('modal invoked via a button', () => ( | ||
| <ModalWrapper | ||
| title="I am the modal!" | ||
| body="I was invoked by a button!" | ||
| /> | ||
| )) | ||
| .add('modal with element body', () => ( | ||
| <Modal | ||
| open | ||
| title="Modal title." | ||
| body={( | ||
| <div> | ||
| <p>Enter your e-mail address to receive free cat facts!</p> | ||
| <InputText | ||
| name="e-mail" | ||
| label="E-Mail Address" | ||
| /> | ||
| <Button | ||
| display="Get my facts!" | ||
| /> | ||
| </div> | ||
| )} | ||
| onClose={() => {}} | ||
| /> | ||
| )); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is so we can reference the buttonPropTypes as part of the Modal PropTypes.