-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
John Benavides
committed
Dec 27, 2017
1 parent
e39abbf
commit e8a66ca
Showing
12 changed files
with
304 additions
and
1 deletion.
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
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
72 changes: 72 additions & 0 deletions
72
src/components/message/__test__/__snapshots__/message.test.js.snap
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,72 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Message component Should Exist 1`] = `[Function]`; | ||
|
||
exports[`Message component Should accept a react Element as renderAs prop 1`] = ` | ||
<p | ||
className="message" | ||
style={Object {}} | ||
> | ||
Custom | ||
This should be a p element | ||
</p> | ||
`; | ||
|
||
exports[`Message component Should concat Bulma class with classes in props 1`] = ` | ||
<article | ||
className="message other-class" | ||
style={Object {}} | ||
> | ||
<div | ||
className="message-header" | ||
> | ||
Lorem Ipsum | ||
</div> | ||
<div | ||
className="message-body" | ||
> | ||
Lorem Ipsum | ||
</div> | ||
</article> | ||
`; | ||
|
||
exports[`Message component Should have custom inline styles 1`] = ` | ||
<section | ||
className="message" | ||
style={ | ||
Object { | ||
"width": 200, | ||
"zIndex": 1, | ||
} | ||
} | ||
> | ||
This should be a section with custom styles | ||
</section> | ||
`; | ||
|
||
exports[`Message component Should have message classnames 1`] = ` | ||
<article | ||
className="message" | ||
style={Object {}} | ||
> | ||
<div | ||
className="message-header" | ||
> | ||
Lorem Ipsum | ||
</div> | ||
<div | ||
className="message-body" | ||
> | ||
Lorem Ipsum | ||
</div> | ||
</article> | ||
`; | ||
|
||
exports[`Message component Should render as an html section 1`] = ` | ||
<section | ||
className="message" | ||
style={Object {}} | ||
> | ||
This should be a section | ||
</section> | ||
`; |
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,41 @@ | ||
import React from 'react'; | ||
import renderer from 'react-test-renderer'; | ||
import Message from '..'; | ||
|
||
describe('Message component', () => { | ||
it('Should Exist', () => { | ||
expect(Message).toMatchSnapshot(); | ||
}); | ||
it('Should have message classnames', () => { | ||
const component = renderer.create( | ||
<Message> | ||
<Message.Header>Lorem Ipsum</Message.Header> | ||
<Message.Body>Lorem Ipsum</Message.Body> | ||
</Message>, | ||
); | ||
expect(component.toJSON()).toMatchSnapshot(); | ||
}); | ||
it('Should concat Bulma class with classes in props', () => { | ||
const component = renderer.create( | ||
<Message className="other-class"> | ||
<Message.Header>Lorem Ipsum</Message.Header> | ||
<Message.Body>Lorem Ipsum</Message.Body> | ||
</Message>, | ||
); | ||
expect(component.toJSON()).toMatchSnapshot(); | ||
}); | ||
it('Should render as an html section', () => { | ||
const component = renderer.create(<Message renderAs="section">This should be a section</Message>); | ||
expect(component.toJSON()).toMatchSnapshot(); | ||
}); | ||
it('Should have custom inline styles', () => { | ||
const component = renderer.create(<Message renderAs="section" style={{ width: 200, zIndex: 1 }}>This should be a section with custom styles</Message>); | ||
expect(component.toJSON()).toMatchSnapshot(); | ||
}); | ||
it('Should accept a react Element as renderAs prop', () => { | ||
// eslint-disable-next-line react/prop-types | ||
const Custom = props => (<p {...props}>Custom {props.children}</p>); | ||
const component = renderer.create(<Message renderAs={Custom}>This should be a p element</Message>); | ||
expect(component.toJSON()).toMatchSnapshot(); | ||
}); | ||
}); |
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,39 @@ | ||
import React, { PureComponent } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import classnames from 'classnames'; | ||
|
||
export default class MessageBody extends PureComponent { | ||
static displayName = 'Message.Body' | ||
|
||
static propTypes = { | ||
children: PropTypes.node, | ||
className: PropTypes.string, | ||
renderAs: PropTypes.oneOfType([ | ||
PropTypes.string, | ||
PropTypes.func, | ||
]), | ||
} | ||
|
||
static defaultProps = { | ||
children: null, | ||
className: '', | ||
renderAs: 'div', | ||
} | ||
render() { | ||
const { | ||
children, | ||
className, | ||
renderAs, | ||
...props | ||
} = this.props; | ||
const Element = renderAs; | ||
return ( | ||
<Element | ||
{...props} | ||
className={classnames('message-body', className)} | ||
> | ||
{children} | ||
</Element> | ||
); | ||
} | ||
} |
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,39 @@ | ||
import React, { PureComponent } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import classnames from 'classnames'; | ||
|
||
export default class MessageHeader extends PureComponent { | ||
static displayName = 'Message.Header' | ||
|
||
static propTypes = { | ||
children: PropTypes.node, | ||
className: PropTypes.string, | ||
renderAs: PropTypes.oneOfType([ | ||
PropTypes.string, | ||
PropTypes.func, | ||
]), | ||
} | ||
|
||
static defaultProps = { | ||
children: null, | ||
className: '', | ||
renderAs: 'div', | ||
} | ||
render() { | ||
const { | ||
children, | ||
className, | ||
renderAs, | ||
...props | ||
} = this.props; | ||
const Element = renderAs; | ||
return ( | ||
<Element | ||
{...props} | ||
className={classnames('message-header', className)} | ||
> | ||
{children} | ||
</Element> | ||
); | ||
} | ||
} |
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,3 @@ | ||
import './message.sass'; | ||
|
||
export { default } from './message'; |
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,58 @@ | ||
import React, { PureComponent } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import classnames from 'classnames'; | ||
import CONSTANTS from '../../constants'; | ||
|
||
import MessageBody from './components/body'; | ||
import MessageHeader from './components/header'; | ||
|
||
const colors = [null].concat(Object.keys(CONSTANTS.COLORS).map(key => CONSTANTS.COLORS[key])); | ||
|
||
export default class Message extends PureComponent { | ||
static propTypes = { | ||
children: PropTypes.node, | ||
className: PropTypes.string, | ||
style: PropTypes.shape({}), | ||
renderAs: PropTypes.oneOfType([ | ||
PropTypes.string, | ||
PropTypes.func, | ||
]), | ||
size: PropTypes.oneOf(['small', 'medium', 'large']), | ||
color: PropTypes.oneOf(colors), | ||
} | ||
|
||
static defaultProps = { | ||
children: null, | ||
className: '', | ||
style: {}, | ||
renderAs: 'article', | ||
color: null, | ||
size: null, | ||
} | ||
|
||
static Body = MessageBody | ||
static Header = MessageHeader | ||
|
||
render() { | ||
const { | ||
children, | ||
className, | ||
renderAs, | ||
color, | ||
size, | ||
...props | ||
} = this.props; | ||
const Element = renderAs; | ||
return ( | ||
<Element | ||
{...props} | ||
className={classnames('message', className, { | ||
[`is-${color}`]: color, | ||
[`is-${size}`]: size, | ||
})} | ||
> | ||
{children} | ||
</Element> | ||
); | ||
} | ||
} |
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,2 @@ | ||
@import '../utils.sass'; | ||
@import '~bulma/sass/components/message.sass'; |
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,47 @@ | ||
import React from 'react'; | ||
|
||
import { storiesOf } from '@storybook/react'; | ||
import { withInfo } from '@storybook/addon-info'; | ||
|
||
import Message from '.'; | ||
import Button from '../button'; | ||
|
||
storiesOf('Message', module) | ||
.addDecorator(story => ( | ||
<div style={{ margin: 10 }}> | ||
{story()} | ||
</div> | ||
)) | ||
.add('Default', withInfo()(() => ( | ||
<Message> | ||
<Message.Header> | ||
Title | ||
<Button remove /> | ||
</Message.Header> | ||
<Message.Body> | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. <strong>Pellentesque risus mi</strong>, tempus quis placerat ut, porta nec nulla. Vestibulum rhoncus ac ex sit amet fringilla. Nullam gravida purus diam, et dictum <a>felis venenatis</a> efficitur. Aenean ac <em>eleifend lacus</em>, in mollis lectus. Donec sodales, arcu et sollicitudin porttitor, tortor urna tempor ligula, id porttitor mi magna a neque. Donec dui urna, vehicula et sem eget, facilisis sodales sem. | ||
</Message.Body> | ||
</Message> | ||
))) | ||
.add('Color', withInfo()(() => ( | ||
<React.Fragment> | ||
<Message color="info"> | ||
<Message.Header> | ||
Title | ||
<Button remove /> | ||
</Message.Header> | ||
<Message.Body> | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. <strong>Pellentesque risus mi</strong>, tempus quis placerat ut, porta nec nulla. Vestibulum rhoncus ac ex sit amet fringilla. Nullam gravida purus diam, et dictum <a>felis venenatis</a> efficitur. Aenean ac <em>eleifend lacus</em>, in mollis lectus. Donec sodales, arcu et sollicitudin porttitor, tortor urna tempor ligula, id porttitor mi magna a neque. Donec dui urna, vehicula et sem eget, facilisis sodales sem. | ||
</Message.Body> | ||
</Message> | ||
<Message color="danger"> | ||
<Message.Header> | ||
Title | ||
<Button remove /> | ||
</Message.Header> | ||
<Message.Body> | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. <strong>Pellentesque risus mi</strong>, tempus quis placerat ut, porta nec nulla. Vestibulum rhoncus ac ex sit amet fringilla. Nullam gravida purus diam, et dictum <a>felis venenatis</a> efficitur. Aenean ac <em>eleifend lacus</em>, in mollis lectus. Donec sodales, arcu et sollicitudin porttitor, tortor urna tempor ligula, id porttitor mi magna a neque. Donec dui urna, vehicula et sem eget, facilisis sodales sem. | ||
</Message.Body> | ||
</Message> | ||
</React.Fragment> | ||
))); |
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
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