Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CSS Modules, CSS Variables and the Future of Re...

CSS Modules, CSS Variables and the Future of Reusable CSS

Presented at CSSConf Budapest, 2016 <3

Glen Maddern

May 11, 2016
Tweet

More Decks by Glen Maddern

Other Decks in Technology

Transcript

  1. WE DON'T NEED MORE TOOLING TO MAKE OUR CURRENT COMPONENTS

    THEMEABLE WE NEED TO START BUILDING BETTER COMPONENTS
  2. A COMPONENT SHOULD RESPOND TO ITS ENVIRONMENT • • RATHER

    THAN THE ENVIRONMENT OVERRIDING THE COMPONENT
  3. .parent { display: flex; padding: 1rem; } .parent > *

    { flex-grow: 1; } ONE ONE TWO ONE TWO THREE
  4. .parent { display: flex; padding: 1rem; } .parent > *

    { flex-grow: 1; } .parent > * + * { margin-left: 1rem; } ONE ONE TWO ONE TWO THREE
  5. .parent { display: flex; padding: 1rem; } .parent > *

    { flex-grow: 1; } .parent > * + * { margin-left: 1rem; } .parent > :first-child { flex: 0 0 50%; } ONE TWO ONE TWO THREE ONE TWO THREE FOUR
  6. .component { --size: var(--spacing, 2rem); width: calc(2 * var(--size)); height:

    var(--size); } .component .container .component .container { --spacing: 1rem; }
  7. .component { --size: var(--spacing, 2rem); width: calc(2 * var(--size)); height:

    var(--size); } .component .component.large .large { --spacing: 4rem; /* or */ --size: 4rem; }
  8. .container .container { --grid-size: 1rem; } .component .component .component {

    --size: var(--spacing, 2rem); width: calc(2 * var(--size)); height: var(--size); }
  9. .component .container .component.fix .container { --grid-size: 1rem; } .fix {

    --spacing: var(--grid-size); } .component { --size: var(--spacing, 2rem); width: calc(2 * var(--size)); height: var(--size); }
  10. import styles from './MediaObject.css' const MediaObject = ({ title, image,

    text }) => ( <div className={styles.outer}> <img className={styles.img} src={ image }/> <div className={styles.inner}> <h1 className={styles.h1}>{ title }</h1> <p className={styles.p}>{ text }</p> </div> </div> )
  11. import styles from './MediaObject.css' const MediaObject = ({ title, image,

    text, theme=styles }) =>( <div className={theme.outer}> <img className={theme.img} src={ image }/> <div className={theme.inner}> <h1 className={theme.h1}>{ title }</h1> <p className={theme.p}>{ text }</p> </div> </div> ) https://github.com/css-modules/css-modules/issues/147