39
loading...
This website collects cookies to deliver better user experience
// styled jsx example with good old CSS
<style jsx>{`
.label { color: red; font-style: italic; }
.article { padding: 0; }
`}
</style>
//JSS example with CSS as a JS object
const useStyles = createUseStyles({
label: {
color: 'red'
fontStyle: 'italic'
},
article: {
padding: 0
}
})
<component>.module.scss
-file, importing it into the component and changing the classes//styled jsx
export default function MyComponent(){
return (<div className={"article"}>
<span className={"label"}>...</span>
<style jsx>{`
.label { color: red; font-style: italic; }
.article { padding: 0; }
`}</style>
</div>)
}
//CSS Modules
import styles from "./MyComponent.module.scss";
export default function MyComponent(){
return (<div className={styles.article}>
<span className={styles.label}>...</span>
</div>)
}
import styles from "./MyComponent.module.scss";
import * as secondaryStyles from "./secondary.module.scss";
export default function MyComponent(){
return (<div className={styles.article}>
<span className={secondaryStyles.label}>...</span>
</div>)
}
TS2339: Property 'label' does not exist on type 'typeof import("*.module.scss")'.
typings.d.ts
-file to the root of your project with the following content// typings.d.ts
declare module "*.module.scss" {
interface IClassNames {
[className: string]: string;
}
const classNames: IClassNames;
export = classNames;
}
// secondary.module.scss
.label {
color: red;
font-style: italic;
}
// MyComponent.module.scss
.article {
padding: 0;
}
.label {
composes: label from "./secondary.module.scss";
}
// MyComponent.tsx
import styles from "./MyComponent.module.scss";
export default function MyComponent(){
return (<div className={styles.article}>
<span className={styles.label}>...</span>
</div>)
}
_app.tsx
, I really did not have to do anything to get my global classes working.:global()
on the class.:global(.label) {
color: red;
font-style: italic;
}