Go to file
Adam LaCombe f4aa3a2f0d
1.0.3
2020-06-11 23:17:21 +08:00
src Fix injection in case if there is no style-element 2020-06-05 01:13:03 +04:00
.gitignore 1.0.3 2020-06-11 23:17:21 +08:00
.npmignore 1.0.3 2020-06-11 23:17:21 +08:00
.npmrc init 2018-08-05 20:19:01 -04:00
LICENSE Initial commit 2018-08-05 20:02:17 -04:00
package.json 1.0.3 2020-06-11 23:17:21 +08:00
README.md update readme 2018-12-04 09:25:38 -05:00
rollup.config.js init 2018-08-05 20:19:01 -04:00
tsconfig.json update readme 2018-12-04 09:25:38 -05:00
tslint.json add tslint config 2018-12-04 09:18:12 -05:00

Shadow-DOM-inject-styles

A helper function to easily modify Shadow DOM CSS.

Install

npm install shadow-dom-inject-styles --save

Vanilla JS Example / Demo

jsfiddle

<script type="module">
  import {injectStyles} from 'https://unpkg.com/shadow-dom-inject-styles@latest/dist/index.js';

  setTimeout(() => {

    const toolbar = document.querySelector('ion-app > ion-header > ion-toolbar');

    // language=CSS
    const styles = `
        .toolbar-background {
            background: red !important;
        }
        .toolbar-container {
            color: #fff !important;
        }
    `;

    injectStyles(toolbar, '.toolbar-background', styles);

  }, 200);
</script>

Typescript Example

import {injectStyles} from 'shadow-dom-inject-styles';

const toolbar = (this.el.querySelector('ion-header > ion-toolbar') as HTMLElement);

// language=CSS
const styles = `
  .toolbar-background {
    background: red !important;;
  }
`;

injectStyles(toolbar, '.toolbar-background', styles);