Skip to content
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
520 changes: 508 additions & 12 deletions .storybook/__snapshots__/Storyshots.test.js.snap

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions .storybook/addons.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
import '@storybook/addon-options/register';
import '@storybook/addon-actions/register';
2 changes: 1 addition & 1 deletion .storybook/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import CssJail from '../src/CssJail';
setTimeout(() => setOptions({
name: '💎 PARAGON',
url: 'https://github.com/edx/paragon',
showDownPanel: false,
showDownPanel: true,
}), 1000);

const req = require.context('../src', true, /\.stories\.jsx$/);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"react-dom": "^15.5.4"
},
"devDependencies": {
"@storybook/addon-actions": "^3.2.12",
"@storybook/addon-options": "^3.2.6",
"@storybook/addon-storyshots": "^3.2.8",
"@storybook/react": "3.2.8",
Expand Down
4 changes: 3 additions & 1 deletion src/Button/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function Button(props) {
);
}

Button.propTypes = {
export const buttonPropTypes = {
Copy link
Contributor Author

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.

buttonType: PropTypes.string,
className: PropTypes.arrayOf(PropTypes.string),
display: PropTypes.string.isRequired,
Expand All @@ -48,6 +48,8 @@ Button.propTypes = {
type: PropTypes.string,
};

Button.propTypes = buttonPropTypes;

Button.defaultProps = {
buttonType: undefined,
className: [],
Expand Down
36 changes: 33 additions & 3 deletions src/Dropdown/Dropdown.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,46 @@ describe('<Dropdown />', () => {
});
});

describe('invalid key in open menu', () => {
it('test', () => {
menuOpen(true, wrapper);
expect(wrapper.find('a').at(0).matchesElement(document.activeElement)).toEqual(true);
wrapper.find('a').at(0).simulate('keyDown', { key: 'q' });
menuOpen(true, wrapper);
expect(wrapper.find('a').at(0).matchesElement(document.activeElement)).toEqual(true);
});
});

it('first menu item after looping through', () => {
wrapper.find('a').at(0).simulate('keyDown', { key: triggerKeys.NAVIGATE_DOWN[0] });
wrapper.find('a').at(1).simulate('keyDown', { key: triggerKeys.NAVIGATE_DOWN[0] });
wrapper.find('a').at(2).simulate('keyDown', { key: triggerKeys.NAVIGATE_DOWN[0] });
expect(wrapper.find('a').at(0).matchesElement(document.activeElement)).toEqual(true);
});

it('toggle on close', () => {
wrapper.find('a').at(0).simulate('keyDown', { key: triggerKeys.CLOSE_MENU[0] });
expect(wrapper.find('[type="button"]').matchesElement(document.activeElement)).toEqual(true);
describe('toggle', () => {
it('toggle on close', () => {
wrapper.find('a').at(0).simulate('keyDown', { key: triggerKeys.CLOSE_MENU[0] });
expect(wrapper.find('[type="button"]').matchesElement(document.activeElement)).toEqual(true);
});

it('does not toggle with invalid key', () => {
wrapper = mount(
<Dropdown
{...props}
/>,
);

menuOpen(false, wrapper);
// open and close button to get focus on button
wrapper.find('[type="button"]').simulate('click');
wrapper.find('[type="button"]').simulate('click');
expect(wrapper.find('[type="button"]').matchesElement(document.activeElement)).toEqual(true);

wrapper.find('[type="button"]').simulate('keyDown', { key: 'q' });
menuOpen(false, wrapper);
expect(wrapper.find('[type="button"]').matchesElement(document.activeElement)).toEqual(true);
});
});
});
});
5 changes: 5 additions & 0 deletions src/Modal/Modal.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@import "~bootstrap/scss/_modal";

.modal-open {
display: block;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This guy could use a newline at the end. Sublime can do this for you automatically: go to Sublime Text > Preferences > Settings and then in the right hand panel ("Preferences.sublime-settings -- User) paste "ensure_newline_at_eof_on_save": true before the closing } at the end of the file. You may need to add a comma on the previous line too so it's valid JSON.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done; thanks for the helpful hint!

151 changes: 151 additions & 0 deletions src/Modal/Modal.stories.jsx
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={() => {}}
/>
));
Loading