Skip to content

Instantly share code, notes, and snippets.

@joshwnj
Created October 17, 2017 06:14
Show Gist options
  • Save joshwnj/2ef1f7856fae06e544593a8b6ec9918b to your computer and use it in GitHub Desktop.
Save joshwnj/2ef1f7856fae06e544593a8b6ec9918b to your computer and use it in GitHub Desktop.
// @flow
import React, { PureComponent } from 'react'
import cmz from 'cmz'
import elem from '../utils/elem'
import type { Element } from 'react'
type Props = {
title?: string,
isTwoColumns?: boolean,
children?: Element<*>|string,
}
const Section = elem.section(cmz(`
--contentBorder: 1px solid red
margin: 0
padding: 1rem
display: var(--display)
`))
const Header = elem.h1(cmz(`
margin: 0
padding: 0.5rem
border: var(--headerBorder)
`))
const Content = elem.div(cmz(`
border: var(--contentBorder)
`))
const twoColStyles = {
'--display': 'flex',
'--headerBorder': '1px solid blue',
'--contentBorder': '1px solid orange'
}
export default class CollapsibleSection extends PureComponent<Props> {
static defaultProps = {
title: '',
isTwoColumns: false,
children: null,
}
render () {
const {
title,
isTwoColumns,
children,
} = this.props
return Section({ style: isTwoColumns ? twoColStyles : {} },
Header(title),
Content(children)
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment