Skip to content
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

Passing children to Checkboard component #703

Merged
merged 2 commits into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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