mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
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)
22 lines
682 B
TypeScript
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>
|
|
`
|
|
}
|
|
}
|