DefinitelyTyped/types/css-modules/css-modules-tests.ts
Neek Sandhu 4eb2295312 Add types for css-modules
Enables users to `import styles from '../main.css'` in your TypeScript files.
From there on, assuming user is using `webpack` with `css-loader`, they can also do `styles.toString()` or `classNames(styles.productLabel...` without any squiggly lines, instead works with intellisense beautifully (both of ops have `string` as return type)
2017-07-11 22:17:11 -07:00

22 lines
682 B
TypeScript

import styles from './main.css'
import * as classNames from 'classnames'
class App {
private theme: string
constructor(theme: string) {
this.theme = theme
}
render() {
// as a style tag (using webpack's css-loader)
const tpl = `<div style="${styles.toString()}"></div>`
// or as scoped unique classes, also latest typescript versions allow prop access using dot like styles.darkUI instead of styles['darkUI']
return `
<div class="${classNames((this.theme === 'dark')?
styles['darkUI'] :
styles['lightUI'].toString())}">
</div>
`
}
}