2.0.15 • Published 4 months ago

embroider-css-modules v2.0.15

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

This project uses GitHub Actions for continuous integration. This project is using Percy.io for visual regression testing.

embroider-css-modules

CSS modules for Embroider projects

  1. What is it?
  2. Installation
  3. API
  4. Compatibility
  5. Contributing
  6. License

What is it?

embroider-css-modules provides a set of tools and conventions to help you implement CSS modules. It is compatible with "bleeding-edge" Ember:

Installation

ember install embroider-css-modules
  • Update your template registry to extend this addon's. Check the Glint documentation for more information.

    import '@glint/environment-ember-loose';
    
    import type EmbroiderCssModulesRegistry from 'embroider-css-modules/template-registry';
    
    declare module '@glint/environment-ember-loose/registry' {
      export default interface Registry extends EmbroiderCssModulesRegistry, /* other addon registries */ {
        // local entries
      }
    }
  • In a <template> tag, use the named import to consume the {{local}} helper.

    /* app/components/hello.css */
    .message {
      align-items: center;
      display: flex;
      height: 100%;
      justify-content: center;
    }
    
    .emphasize {
      font-size: 64px;
      font-style: italic;
    }
    /* app/components/hello.gts */
    import { local } from 'embroider-css-modules';
    
    import styles from './hello.css';
    
    <template>
      <div class={{local styles "message" "emphasize"}}>
        Hello world!
      </div>
    </template>

API

The addon provides 1 helper:

  • {{local}}

Throughout the section, you can assume that there is a styles object, which maps local class names to global ones.

// An example
const styles = {
  'container': 'lzeQ4',
  'is-inline': 'mJGCE',
  'is-wide': '_2lPSR',
  'no-feedback': 'YpQbt',
};

Helper: {{local}}

Why use it?

The {{local}} helper is useful when you want to apply multiple styles.

{{! app/components/ui/form/field.hbs }}
<div
  class={{concat
    this.styles.container
    " "
    (if @isInline this.styles.is-inline)
    " "
    (if @isWide this.styles.is-wide)
    " "
    (unless @errorMessage this.styles.no-feedback)
  }}
>
  ...
</div>
{{! app/components/ui/form/field.hbs }}
<div
  class={{local
    this.styles
    "container"
    (if @isInline "is-inline")
    (if @isWide "is-wide")
    (unless @errorMessage "no-feedback")
  }}
>
  ...
</div>

To conditionally apply multiple styles, use the {{array}} helper.

{{! app/components/hello.hbs }}
<div
  class={{local
    this.styles
    "message"
    (if this.someCondition (array "hide" "after-3-sec"))
  }}
>
  Hello world!
</div>

Arguments

The {{local}} helper uses positional arguments so that styles are applied in sequence. Pass the styles object first, then the local class name(s).

Outputs

The {{local}} helper returns a concatenated string. The string lists the global class names in the same order as the local ones.

Compatibility

  • Ember.js v4.12 or above1
  • Node.js v18 or above

1. ember-container-query may work on older versions of Ember (e.g. 4.4), but issues that arise from these won't be supported.

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.

2.0.15

4 months ago

2.0.13

5 months ago

2.0.14

5 months ago

2.0.12

7 months ago

2.0.11

10 months ago

2.0.10

11 months ago

2.0.9

1 year ago

2.0.8

1 year ago

2.0.7

1 year ago

2.0.6

1 year ago

2.0.5

1 year ago

2.0.4

1 year ago

2.0.3

1 year ago

2.0.2

2 years ago

2.0.1

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.1.2

2 years ago

2.0.0

2 years ago

1.0.0

2 years ago

0.1.10

2 years ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.4

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.3

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago