Skip to content

Commit

Permalink
feat: allow custom tag
Browse files Browse the repository at this point in the history
  • Loading branch information
kirkov committed Jan 20, 2018
1 parent b950f2e commit 4a1f367
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/__snapshots__/breakbox.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ exports[`can provide custom spaces: uses custom spaces 1`] = `
</div>
`;

exports[`can specify element tag: container can render an article tag 1`] = `
<article
className=" x0"
>
<style
dangerouslySetInnerHTML={
Object {
"__html": ".x0{background:red}",
}
}
/>
</article>
`;

exports[`handle single values: null value 1`] = `
<div
className=" "
Expand Down
6 changes: 3 additions & 3 deletions src/breakbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ const getStyles = (props, config) => {
return styles
}

export const breakbox = (containerStyles = {}, component = 'div') => {
const BreakboxComponent = ({className, children, ...otherProps}, context) => {
export const breakbox = (containerStyles = {}) => {
const BreakboxComponent = ({className, children, tag = 'div', ...otherProps}, context) => {
const config = Object.assign({}, defaultConfig, context.breakbox)
const styles = getStyles(Object.assign(otherProps, containerStyles), config)
const stylesClassName = cxs(styles)
Expand All @@ -71,7 +71,7 @@ export const breakbox = (containerStyles = {}, component = 'div') => {
}

return React.createElement(
component,
tag,
{
className: [className, stylesClassName].join(' ')
},
Expand Down
6 changes: 6 additions & 0 deletions src/breakbox.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ beforeEach(() => {
resetStyles()
})

it('can specify element tag', () => {
matchSnapshot('container can render an article tag',
<Container tag='article' background='red' />
)
})

it('skips breakpoints', () => {
matchSnapshot('skips middle value',
<Container flexDirection={['row', null, 'column']} />
Expand Down

0 comments on commit 4a1f367

Please sign in to comment.