Skip to content

Commit

Permalink
Passing children to Checkboard component (#703)
Browse files Browse the repository at this point in the history
* Added feature to pass down children to Checkboard component

* Added tests for passed down children in checkboard
  • Loading branch information
Yugam Dhuriya committed Apr 29, 2020
1 parent 32f38db commit 0b3558b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/components/common/Checkboard.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react'
import React, { isValidElement } from 'react'
import reactCSS from 'reactcss'
import * as checkboard from '../../helpers/checkboard'

export const Checkboard = ({ white, grey, size, renderers, borderRadius, boxShadow }) => {
export const Checkboard = ({ white, grey, size, renderers, borderRadius, boxShadow, children }) => {
const styles = reactCSS({
'default': {
grid: {
Expand All @@ -12,11 +12,8 @@ export const Checkboard = ({ white, grey, size, renderers, borderRadius, boxShad
background: `url(${ checkboard.get(white, grey, size, renderers.canvas) }) center left`,
},
},
})

return (
<div style={ styles.grid } />
)
})
return isValidElement(children)?React.cloneElement(children, { ...children.props, style: {...children.props.style,...styles.grid}}):<div style={styles.grid}/>;
}

Checkboard.defaultProps = {
Expand Down
27 changes: 27 additions & 0 deletions src/components/common/__snapshots__/spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,33 @@ exports[`Alpha renders correctly 1`] = `
</div>
`;

exports[`Checkboard renders children correctly 1`] = `
<button
style={
Object {
"MozBorderRadius": undefined,
"MozBoxShadow": undefined,
"OBorderRadius": undefined,
"OBoxShadow": undefined,
"WebkitBorderRadius": undefined,
"WebkitBoxShadow": undefined,
"background": "url(null) center left",
"borderRadius": undefined,
"bottom": "0px",
"boxShadow": undefined,
"left": "0px",
"msBorderRadius": undefined,
"msBoxShadow": undefined,
"position": "absolute",
"right": "0px",
"top": "0px",
}
}
>
Click
</button>
`;

exports[`Checkboard renders correctly 1`] = `
<div
style={
Expand Down
7 changes: 7 additions & 0 deletions src/components/common/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ test('Checkboard renders correctly', () => {
expect(tree).toMatchSnapshot()
})

test('Checkboard renders children correctly', () => {
const tree = renderer.create(
<Checkboard><button>Click</button></Checkboard>,
).toJSON()
expect(tree).toMatchSnapshot()
})

// test('Checkboard renders on server correctly', () => {
// const tree = renderer.create(
// <Checkboard renderers={{ canvas }} />
Expand Down

0 comments on commit 0b3558b

Please sign in to comment.