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

New modal toast component #165

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
40 changes: 40 additions & 0 deletions examples/client/scripts/components/ModalExamples.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@ const LOOKUP_DATA = [
{ label: 'Opportunity', value: '3', icon: 'standard:opportunity' },
];

function onModalToastClose() {
alert('Close modal toast requested');
}

export default class ModalExamples extends Component {
constructor() {
super();
this.state = {
modal1: { opened: false },
modal2: { opened: false },
modal3: { opened: false },
modal4: { opened: false },
};
}

Expand All @@ -49,6 +54,16 @@ export default class ModalExamples extends Component {
const hideModal1 = this.hideModal.bind(this, 'modal1');
const hideModal2 = this.hideModal.bind(this, 'modal2');
const hideModal3 = this.hideModal.bind(this, 'modal3');
const hideModal4 = this.hideModal.bind(this, 'modal4');

const modalToastConfig = {
modalToastClose: onModalToastClose,
modalToastLevel: 'error',
modalToastIcon: 'warning',
modalToastAlt: 'Close',
modalToastText: 'This is error alert with icon and close button.',
};

return (
<div>
<h2 className='slds-m-vertical--medium'>Modal</h2>
Expand Down Expand Up @@ -147,6 +162,31 @@ export default class ModalExamples extends Component {
</Footer>
</Modal>
</div>
<div style={ styles }>
<Button type='neutral' onClick={ this.showModal.bind(this, 'modal4') }>Show Modal #4 (Modal toast)</Button>
<Modal
opened={ this.state.modal4.opened }
onHide={ hideModal4 }
>
<Header title='Modal' closeButton modalToast={ modalToastConfig } />
<Content style={ { padding: '1em' } }>
<div>
<p>
Sit nulla est ex deserunt exercitation anim occaecat. Nostrud ullamco deserunt aute id consequat veniam incididunt duis in sint irure nisi. Mollit officia cillum Lorem ullamco minim nostrud elit officia tempor esse quis. Cillum sunt ad dolore
quis aute consequat ipsum magna exercitation reprehenderit magna. Tempor cupidatat consequat elit dolor adipisicing.
</p>
<p>
Dolor eiusmod sunt ex incididunt cillum quis nostrud velit duis sit officia. Lorem aliqua enim laboris do dolor eiusmod officia. Mollit incididunt nisi consectetur esse laborum eiusmod pariatur proident. Eiusmod et adipisicing culpa deserunt
nostrud ad veniam nulla aute est. Labore esse esse cupidatat amet velit id elit consequat minim ullamco mollit enim excepteur ea.
</p>
</div>
</Content>
<Footer>
<Button type='neutral' label='Cancel' onClick={ hideModal4 } />
<Button type='brand' label='Done' onClick={ hideModal4 } />
</Footer>
</Modal>
</div>
</div>
);
}
Expand Down
24 changes: 23 additions & 1 deletion src/scripts/Modal.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { Component, PropTypes } from 'react';
import classnames from 'classnames';
import Button from './Button';
import ModalToast from './ModalToast';

export class ModalHeader extends Component {
constructor() {
Expand All @@ -15,7 +16,16 @@ export class ModalHeader extends Component {
}

render() {
const { className, title, tagline, closeButton, ...props } = this.props;
const { className, title, tagline, closeButton, modalToast, ...props } = this.props;

const {
modalToastClose,
modalToastLevel,
modalToastIcon,
modalToastAlt,
modalToastText,
} = modalToast || {};

delete props.onClose;
const hdClassNames = classnames(className, 'slds-modal__header');
return (
Expand All @@ -38,6 +48,17 @@ export class ModalHeader extends Component {
/> :
null
}
{
modalToast ?
<ModalToast
onClose={ modalToastClose }
level={ modalToastLevel }
icon={ modalToastIcon }
alt={ modalToastAlt }
text={ modalToastText }
/> :
null
}
</div>
);
}
Expand All @@ -50,6 +71,7 @@ ModalHeader.propTypes = {
onClose: PropTypes.func,
className: PropTypes.string,
closeButton: PropTypes.bool,
modalToast: PropTypes.shape(),
};

class Modal extends Component {
Expand Down
14 changes: 14 additions & 0 deletions src/scripts/ModalToast.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React, { PropTypes } from 'react';

import { Toast } from './Notification';

const ModalToast = ({ text, ...props }) =>
<div className='slds-notify_container'>
<Toast { ...props }>{ text }</Toast>
</div>;

ModalToast.propTypes = {
text: PropTypes.string,
};

export default ModalToast;
2 changes: 2 additions & 0 deletions src/scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import Toggle from './Toggle';
import Pill from './Pill';
import FileSelector from './FileSelector';
import Card from './Card';
import ModalToast from './ModalToast';

export {
Notification, Alert, Toast,
Expand Down Expand Up @@ -102,6 +103,7 @@ export {
Pill,
FileSelector,
Card,
ModalToast,
};

export { default as util } from './util';