Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/buschtoens/ember-css-modules-active-route

`:app-root` & `:document-root` selectors to apply styles to the root element, when a route is active.
https://github.com/buschtoens/ember-css-modules-active-route

ember ember-addon ember-css-modules ember-routing emberjs

Last synced: about 2 months ago
JSON representation

`:app-root` & `:document-root` selectors to apply styles to the root element, when a route is active.

Awesome Lists containing this project

README

        

# ember-css-modules-active-route

[![Build Status](https://travis-ci.org/buschtoens/ember-css-modules-active-route.svg)](https://travis-ci.org/buschtoens/ember-css-modules-active-route)
[![npm version](https://badge.fury.io/js/ember-css-modules-active-route.svg)](http://badge.fury.io/js/ember-css-modules-active-route)
[![Download Total](https://img.shields.io/npm/dt/ember-css-modules-active-route.svg)](http://badge.fury.io/js/ember-css-modules-active-route)
[![Ember Observer Score](https://emberobserver.com/badges/ember-css-modules-active-route.svg)](https://emberobserver.com/addons/ember-css-modules-active-route)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
[![dependencies](https://img.shields.io/david/buschtoens/ember-css-modules-active-route.svg)](https://david-dm.org/buschtoens/ember-css-modules-active-route)
[![devDependencies](https://img.shields.io/david/dev/buschtoens/ember-css-modules-active-route.svg)](https://david-dm.org/buschtoens/ember-css-modules-active-route)

`:app-root` and `:document-root` selectors to apply styles to the root element,
when a route is active.

## Installation

```
ember install ember-css-modules-active-route ember-css-modules
```

This is a plugin for [`ember-css-modules`][ember-css-modules], so you need to
have it installed as well.

[ember-css-modules]: https://github.com/salsify/ember-css-modules

## Usage

- **`:app-root`**: Maps to the [root element][root-element] of your application.
Usually ``.
- **`:document-root`**: Maps to the [`documentElement`][document-element] /
[`:root`][css-root], which is the `` element.

[root-element]: https://guides.emberjs.com/release/configuring-ember/embedding-applications/
[document-element]: https://developer.mozilla.org/en-US/docs/Web/API/Document/documentElement
[css-root]: https://developer.mozilla.org/en-US/docs/Web/CSS/:root

### Example

```ts
Router.map(function() {
this.route('foo', function() {
this.route('bar');
});
this.route('qux');
});
```

```css
/* app/foo/styles.css */

:app-root {
background: green;
}
```

```css
/* app/foo/index/styles.css */

:app-root {
background: red;
}
```

When the user enters the `foo` route, the `:app-root` pseudo-selector will be
applied to the app's `rootElement` (``). The background of the page will
be `red`, as `foo.index` overrides `foo`.

When the user navigates to `foo.bar`, the background will turn `green`, as the
user has left the `foo.index` route and the override no longer takes effect.

When the user navigates to `qux`, the background will become transparent again,
as no route styles are active any more.

### Combining Selectors

You can also combine the `:app-root` & `:document-root` selectors with other
regular selectors. For instance, instead of just using `:document-root`, which
targets the `:root` element (``), you can target child elements instead:

```css
:document-root :global(.some-cookie-banner) {
display: none;
}
```

In this example, `