-
Notifications
You must be signed in to change notification settings - Fork 6
# add-Toast #47
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
base: master
Are you sure you want to change the base?
# add-Toast #47
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Pull Request Template | ||
# add-Toast | ||
|
||
## Types of changes | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import classnames from 'classnames' | ||
|
||
const colors = ['primary', 'secondary', 'success', 'warning', 'error'] | ||
|
||
const propTypes = { | ||
children: PropTypes.node, | ||
className: PropTypes.string, | ||
color: PropTypes.oneOf(colors), | ||
renderAs: PropTypes.oneOfType([PropTypes.func, PropTypes.string]) | ||
} | ||
|
||
const defaultProps = { | ||
renderAs: 'div' | ||
} | ||
|
||
const Toast = ({ children, ...props }) => { | ||
const { color, className, renderAs: Element, ...attributes } = props | ||
|
||
const classNames = classnames( | ||
{ | ||
[`toast-${color}`]: color, | ||
toast: 'toast' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Static classnames should not be inside the object for |
||
}, | ||
className | ||
) | ||
|
||
return ( | ||
<Element {...attributes} className={classNames}> | ||
{children} | ||
</Element> | ||
) | ||
} | ||
|
||
Toast.propTypes = propTypes | ||
Toast.defaultProps = defaultProps | ||
|
||
export default Toast |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default from './Toast' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React from 'react' | ||
import { shallow } from 'enzyme' | ||
|
||
import { Toast } from '../..' | ||
|
||
describe('Toasts', () => { | ||
it('Should render a div tag by default', () => { | ||
const wrapper = shallow(<Toast />) | ||
|
||
expect(wrapper.type()).toBe('div') | ||
}) | ||
|
||
it('Should render children', () => { | ||
const wrapper = shallow(<Toast>My toast</Toast>) | ||
|
||
expect(wrapper.text()).toBe('My toast') | ||
}) | ||
|
||
it('Should pass additional classNames', () => { | ||
const wrapper = shallow(<Toast className="extra">My Toasts</Toast>) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent quotes here. Use single quotes, follow the StandardJS style, run |
||
|
||
expect(wrapper.hasClass('extra')).toBe(true) | ||
}) | ||
|
||
it('Should render with "Toasts" class by default', () => { | ||
const wrapper = shallow(<Toast>Toasts</Toast>) | ||
|
||
expect(wrapper.hasClass('toast')).toBe(true) | ||
}) | ||
|
||
it('Should render with "toast-{color}" class when a color is provided', () => { | ||
const wrapper = shallow(<Toast color="primary">Primary</Toast>) | ||
|
||
expect(wrapper.hasClass('toast-primary')).toBe(true) | ||
}) | ||
|
||
it('Should render custom tag', () => { | ||
const wrapper = shallow(<Toast renderAs="main">custom</Toast>) | ||
|
||
expect(wrapper.type()).toBe('main') | ||
}) | ||
|
||
it('Should match the snapshot', () => { | ||
const wrapper = shallow(<Toast />) | ||
|
||
expect(wrapper).toMatchSnapshot() | ||
}) | ||
|
||
// it('Should have toast classname', () => { | ||
// const wrapper = renderer.create(<Toast>Test</Toast>) | ||
|
||
// expect(wrapper.toJSON()).toMatchSnapshot() | ||
// }) | ||
|
||
// it('Should concat classnames in props with Spectre classnames', () => { | ||
// const wrapper = renderer.create( | ||
// <Toast className='other-class this-is-a-test'>classes</Toast> | ||
// ) | ||
|
||
// expect(wrapper.toJSON()).toMatchSnapshot() | ||
// }) | ||
|
||
// it('Should use inline styles', () => { | ||
// const wrapper = renderer.create( | ||
// <Toast style={{ width: 250 }}>Inline styles</Toast>) | ||
|
||
// expect(wrapper.toJSON()).toMatchSnapshot() | ||
// }) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Toasts Should match the snapshot 1`] = ` | ||
<div | ||
className="toast" | ||
/> | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React from 'react' | ||
import { storiesOf } from '@storybook/react' | ||
import { Container, Col, Row, Toast } from '../src' | ||
|
||
storiesOf('Toasts', module) | ||
.add('Default', () => ( | ||
<Container> | ||
<Row> | ||
<Col all={3}> | ||
<Toast className="m-2"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent quotes, needs to follow the StandardJS style guidelines using single quotes. |
||
<button className="btn btn-clear float-right" /> | ||
<h5>Toast Title</h5> | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. | ||
</Toast> | ||
|
||
<Toast className="m-2"> | ||
<button className="btn btn-clear float-right" /> | ||
Default Toast | ||
</Toast> | ||
</Col> | ||
</Row> | ||
</Container> | ||
)) | ||
.add('Colors', () => ( | ||
<Container> | ||
<Row> | ||
<Col all={3}> | ||
<Toast className="m-2" color="primary"> | ||
<button className="btn btn-clear float-right" /> | ||
Toast - primary | ||
</Toast> | ||
<Toast className="m-2" color="secondary"> | ||
<button className="btn btn-clear float-right" /> | ||
Toast - secondary | ||
</Toast> | ||
<Toast className="m-2" color="error"> | ||
<button className="btn btn-clear float-right" /> | ||
Toast - error | ||
</Toast> | ||
<Toast className="m-2" color="warning"> | ||
<button className="btn btn-clear float-right" /> | ||
Toast - warning | ||
</Toast> | ||
<Toast className="m-2" color="success"> | ||
<button className="btn btn-clear float-right" /> | ||
Toast - success | ||
</Toast> | ||
</Col> | ||
</Row> | ||
</Container> | ||
)) |
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.
PULL_REQUEST_TEMPLATE.md should not be changed