Skip to content

Instantly share code, notes, and snippets.

@longlho
Created March 21, 2018 23:12
Show Gist options
  • Save longlho/6c8917830e4c1be4971fa0cc60fc9426 to your computer and use it in GitHub Desktop.
Save longlho/6c8917830e4c1be4971fa0cc60fc9426 to your computer and use it in GitHub Desktop.
css-modules
import * as styles from 'foo.css'
type CssMap = typeof styles
export const legacyCss: CssMap = {
container: 'mc-foo',
content: 'mc-content'
}
export interface Props {
css: CssMap
}
export function Foo (props: Props) {
return (
<div className={props.css.container}>
<div className={props.css.content}/>
</div>
)
}
// Legacy mapping by default
Foo.defaultProps = {
css: legacyCss
}
export {CssMap}
// Consumer
function Bar () {
const css: CssMap = {
...legacyCss,
content: 'custom-content-class'
}
return <Foo css={css} />
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment