-
Notifications
You must be signed in to change notification settings - Fork 355
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
feat(wizard): adds the pf wizard and modal components #69
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/** | ||
* CustomModalDialog creates custom ReactBootstrap ModalDialog | ||
* https://github.com/react-bootstrap/react-bootstrap/blob/master/src/ModalDialog.js | ||
* | ||
* This extends ModalDialog and adds contentClassName prop for setting | ||
* `modal-content` div's class | ||
*/ | ||
import classNames from 'classnames'; | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { utils } from 'react-bootstrap'; | ||
|
||
const bsClass = utils.bootstrapUtils.bsClass; | ||
const bsSizes = utils.bootstrapUtils.bsSizes; | ||
const getClassSet = utils.bootstrapUtils.getClassSet; | ||
const prefix = utils.bootstrapUtils.prefix; | ||
const splitBsProps = utils.bootstrapUtils.splitBsProps; | ||
|
||
// React Bootstrap utils/StyleConfig Size is currently not exported | ||
const Size = { | ||
LARGE: 'large', | ||
SMALL: 'small', | ||
}; | ||
|
||
class CustomModalDialog extends React.Component { | ||
render() { | ||
const { | ||
dialogClassName, | ||
contentClassName, | ||
className, | ||
style, | ||
children, | ||
...props | ||
} = this.props; | ||
const [bsProps, elementProps] = splitBsProps(props); | ||
|
||
const bsClassName = prefix(bsProps); | ||
|
||
const modalStyle = { display: 'block', ...style }; | ||
|
||
const dialogClasses = { | ||
...getClassSet(bsProps), | ||
[bsClassName]: false, | ||
[prefix(bsProps, 'dialog')]: true, | ||
}; | ||
|
||
return ( | ||
<div | ||
{...elementProps} | ||
tabIndex="-1" | ||
role="dialog" | ||
style={modalStyle} | ||
className={classNames(className, bsClassName)} | ||
> | ||
<div className={classNames(dialogClassName, dialogClasses)}> | ||
<div | ||
className={classNames(prefix(bsProps, 'content'), contentClassName)} | ||
role="document" | ||
> | ||
{children} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
CustomModalDialog.propTypes = { | ||
/** A css class to apply to the Modal dialog DOM node. */ | ||
dialogClassName: PropTypes.string, | ||
/** custom modal-content class added to the content DOM node */ | ||
contentClassName: PropTypes.string, | ||
/** base modal class name */ | ||
className: PropTypes.string, | ||
/** additional modal styles */ | ||
style: PropTypes.object, | ||
/** Children nodes */ | ||
children: PropTypes.node, | ||
}; | ||
|
||
export default bsClass( | ||
'modal', | ||
bsSizes([Size.LARGE, Size.SMALL], CustomModalDialog), | ||
); |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import CustomModalDialog from './InnerComponents/CustomModalDialog'; | ||
import { Modal as BsModal } from 'react-bootstrap'; | ||
|
||
/** | ||
* Modal Component for Patternfly React | ||
*/ | ||
class Modal extends BsModal { | ||
render() { | ||
return super.render(); | ||
} | ||
} | ||
|
||
Modal.defaultProps = Object.assign(BsModal.defaultProps, { | ||
dialogComponentClass: CustomModalDialog, | ||
}); | ||
|
||
export default Modal; |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import React from 'react'; | ||
import { storiesOf } from '@storybook/react'; | ||
import { withInfo } from '@storybook/addon-info'; | ||
import { defaultTemplate } from '../../../storybook/decorators/storyTemplates'; | ||
|
||
import { | ||
MockModalManager, | ||
basicExampleSource, | ||
} from './__mocks__/mockModalManager'; | ||
|
||
import { | ||
MockAboutModalManager, | ||
aboutExampleSource, | ||
} from './__mocks__/mockAboutModalManager'; | ||
|
||
const stories = storiesOf('Modal Overlay', module); | ||
|
||
const description = ( | ||
<p> | ||
This component is based on React Bootstrap Modal component. See{' '} | ||
<a href="https://react-bootstrap.github.io/components.html#modals"> | ||
React Bootstrap Docs | ||
</a>{' '} | ||
for complete Modal component documentation. | ||
</p> | ||
); | ||
|
||
stories.addDecorator( | ||
defaultTemplate({ | ||
title: 'Modal Overlay', | ||
documentationLink: | ||
'http://www.patternfly.org/pattern-library/forms-and-controls/modal-overlay/', | ||
description: description, | ||
}), | ||
); | ||
|
||
stories.add( | ||
'Basic example', | ||
withInfo({ | ||
source: false, | ||
propTablesExclude: [MockModalManager], | ||
text: ( | ||
<div> | ||
<h1>Story Source</h1> | ||
<pre>{basicExampleSource}</pre> | ||
</div> | ||
), | ||
})(() => <MockModalManager />), | ||
); | ||
|
||
stories.add( | ||
'About Modal', | ||
withInfo({ | ||
source: false, | ||
propTablesExclude: [MockAboutModalManager], | ||
text: ( | ||
<div> | ||
<h1>Story Source</h1> | ||
<pre>{aboutExampleSource}</pre> | ||
</div> | ||
), | ||
})(() => <MockAboutModalManager />), | ||
); | ||
131 changes: 131 additions & 0 deletions
131
src/components/Modal/__mocks__/mockAboutModalManager.js
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import React from 'react'; | ||
import { Button } from '../../Button'; | ||
import { Icon } from '../../Icon'; | ||
import { Modal } from '../index'; | ||
import logo from 'patternfly/dist/img/logo-alt.svg'; | ||
|
||
export class MockAboutModalManager extends React.Component { | ||
constructor() { | ||
super(); | ||
this.state = { showModal: false }; | ||
this.open = this.open.bind(this); | ||
this.close = this.close.bind(this); | ||
} | ||
open() { | ||
this.setState({ showModal: true }); | ||
} | ||
close() { | ||
this.setState({ showModal: false }); | ||
} | ||
render() { | ||
return ( | ||
<div> | ||
<Button bsStyle="primary" bsSize="large" onClick={this.open}> | ||
Launch about modal | ||
</Button> | ||
|
||
<Modal | ||
contentClassName="about-modal-pf" | ||
show={this.state.showModal} | ||
onHide={this.close} | ||
> | ||
<Modal.Header> | ||
<button | ||
className="close" | ||
onClick={this.close} | ||
aria-hidden="true" | ||
aria-label="Close" | ||
> | ||
<Icon type="pf" name="close" /> | ||
</button> | ||
</Modal.Header> | ||
<Modal.Body> | ||
<h1>Product Title</h1> | ||
<div className="product-versions-pf"> | ||
<ul className="list-unstyled"> | ||
<li> | ||
<strong>Label</strong> Version | ||
</li> | ||
<li> | ||
<strong>Label</strong> Version | ||
</li> | ||
<li> | ||
<strong>Label</strong> Version | ||
</li> | ||
<li> | ||
<strong>Label</strong> Version | ||
</li> | ||
<li> | ||
<strong>Label</strong> Version | ||
</li> | ||
<li> | ||
<strong>Label</strong> Version | ||
</li> | ||
</ul> | ||
</div> | ||
<div className="trademark-pf"> | ||
Trademark and Copyright Information | ||
</div> | ||
</Modal.Body> | ||
<Modal.Footer> | ||
<img src={logo} alt="Patternfly Logo" /> | ||
</Modal.Footer> | ||
</Modal> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export const aboutExampleSource = ` | ||
<Button bsStyle="primary" bsSize="large" onClick={this.open}> | ||
Launch about modal | ||
</Button> | ||
|
||
<Modal | ||
contentClassName="about-modal-pf" | ||
show={this.state.showModal} | ||
onHide={this.close} | ||
> | ||
<Modal.Header> | ||
<button | ||
className="close" | ||
onClick={this.close} | ||
aria-hidden="true" | ||
aria-label="Close" | ||
> | ||
<Icon type="pf" name="close" /> | ||
</button> | ||
</Modal.Header> | ||
<Modal.Body> | ||
<h1>Product Title</h1> | ||
<div className="product-versions-pf"> | ||
<ul className="list-unstyled"> | ||
<li> | ||
<strong>Label</strong> Version | ||
</li> | ||
<li> | ||
<strong>Label</strong> Version | ||
</li> | ||
<li> | ||
<strong>Label</strong> Version | ||
</li> | ||
<li> | ||
<strong>Label</strong> Version | ||
</li> | ||
<li> | ||
<strong>Label</strong> Version | ||
</li> | ||
<li> | ||
<strong>Label</strong> Version | ||
</li> | ||
</ul> | ||
</div> | ||
<div className="trademark-pf"> | ||
Trademark and Copyright Information | ||
</div> | ||
</Modal.Body> | ||
<Modal.Footer> | ||
<img src={logo} alt="Patternfly Logo" /> | ||
</Modal.Footer> | ||
</Modal> | ||
`; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I don't like the fact you are overriding the text, we are losing tons of benefits.
Some times something like this worked for me:
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.
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.
Nice 👍 ! I will try it. This would be a huge relief...
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.
Any update?
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.
Unfortunately, it works only with stateless components
I guess there is no trivial solution, would be nice if storybook had an option to manually trigger knobs updates.
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.
@sharvit I think this might be something for us to consider in the future... not sure if it helps the React docgen/withInfo content... but it would help make the state more visible.
https://github.com/ndelangen/storybook-state