-
Notifications
You must be signed in to change notification settings - Fork 13
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(core-react): Add type #175
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import clsx from 'clsx'; | ||
|
||
export default function Type({ Tag, style, className, ...rest }) { | ||
const classes = clsx(className, `ray-text--${style}`); | ||
|
||
return <Tag className={classes} {...rest} />; | ||
} | ||
|
||
Type.propTypes = { | ||
Tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]), | ||
style: PropTypes.oneOf([ | ||
'h1', | ||
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. Just curious, how were these types determined? 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. these are all the type options defined in core |
||
'h2', | ||
'h3', | ||
'h4', | ||
'h5', | ||
'h6', | ||
'body', | ||
'body-large', | ||
'body-small', | ||
'body-x-small', | ||
'display-1', | ||
'display-2' | ||
]), | ||
className: PropTypes.string | ||
}; | ||
|
||
Type.defaultProps = { | ||
Tag: 'div', | ||
style: 'body' | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
|
||
import Type from '.'; | ||
|
||
const SAMPLE_TEXT = 'All their equipment and instruments are alive.'; | ||
|
||
describe('Type', () => { | ||
test('it renders type with ray body class', () => { | ||
const wrapper = mount(<Type>{SAMPLE_TEXT}</Type>); | ||
|
||
expect(wrapper.find(Type).length).toBe(1); | ||
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. should you check that it has the ray body class since you are specifying that in |
||
}); | ||
|
||
test('it renders type with added attributes', () => { | ||
const wrapper = mount( | ||
<Type className="custom-class" data-stuff="hello"> | ||
{SAMPLE_TEXT} | ||
</Type> | ||
); | ||
|
||
expect(wrapper.html()).toBe( | ||
'<div class="custom-class ray-text--body" data-stuff="hello">All their equipment and instruments are alive.</div>' | ||
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. 🔥 |
||
); | ||
}); | ||
|
||
test('it renders type with a style', () => { | ||
const wrapper = mount(<Type style="h3">{SAMPLE_TEXT}</Type>); | ||
|
||
expect(wrapper.html()).toBe( | ||
'<div class="ray-text--h3">All their equipment and instruments are alive.</div>' | ||
); | ||
}); | ||
|
||
test('it renders type with a custom tag', () => { | ||
const wrapper = mount( | ||
<Type Tag="h1" style="display-1"> | ||
{SAMPLE_TEXT} | ||
</Type> | ||
); | ||
|
||
expect(wrapper.html()).toBe( | ||
'<h1 class="ray-text--display-1">All their equipment and instruments are alive.</h1>' | ||
); | ||
}); | ||
|
||
test('it throws a proptype error if style is invalid', () => { | ||
expect(() => { | ||
mount(<Type style="bad-style">{SAMPLE_TEXT}</Type>); | ||
}).toThrow(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
import { storiesOf } from '@storybook/react'; | ||
|
||
import Type from '../src/components/Type'; | ||
|
||
const styles = [ | ||
'h1', | ||
'h2', | ||
'h3', | ||
'h4', | ||
'h5', | ||
'h6', | ||
'body', | ||
'body-large', | ||
'body-small', | ||
'body-x-small', | ||
'display-1', | ||
'display-2' | ||
]; | ||
|
||
storiesOf('Type', module).add('default', () => ( | ||
<> | ||
{styles.map(style => ( | ||
<Type key={style} style={style}> | ||
All their equipment and instruments are alive. | ||
</Type> | ||
))} | ||
</> | ||
)); |
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.
should this just be
PropTypes.node
?