Skip to content
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 2 commits into from
Dec 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions src/components/Modal/InnerComponents/CustomModalDialog.js
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),
);
17 changes: 17 additions & 0 deletions src/components/Modal/Modal.js
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;
63 changes: 63 additions & 0 deletions src/components/Modal/Modal.stories.js
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 />),
);
Copy link
Contributor

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:

() => MockAboutModalManager()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • same in wizards

Copy link
Member Author

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...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any update?

Copy link
Contributor

@sharvit sharvit Dec 8, 2017

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.

Copy link
Member Author

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

131 changes: 131 additions & 0 deletions src/components/Modal/__mocks__/mockAboutModalManager.js
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>
`;
Loading