Socket
Socket
Sign inDemoInstall

css-modulizer

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    css-modulizer

Use with CSS Modules without a JS framework.


Version published
Maintainers
1
Install size
5.69 kB
Created

Readme

Source

CSS modulizer

Use with CSS Modules without a JS framework.

What?

Working from the premise that CSS Modules—which allow for locally-scoped, truly modular CSS—are a preferred way to author styles, this script allows you to make use of CSS Modules without the need for a JS framework.

Arguments

This script exports a function takes a single object as its only parameter. The following properties are valid:

PropertyTypeDescription
classNamestringA CSS Modules class name
elementobjectThe component's element
childrenobjectKey/value pairs of selector/localized CSS Module classes
hiddenInitiallybooleanIf the component is initially hidden

How?

Load your component script inside the component you're working with, e.g.:

<article>
  <script async
    type="text/javascript"
    src="path/to/component.js">
  </script>
  <h2>My Title</h2>
  <p>Some more stuff...</p>
  <div class="tags">Art, cats, bird watching</div>
</article>

And, in component.js:

import { article, title, excerpt, tags } from './component.css';
import cssmodulizer from 'path/to/cssmodulizer';

cssmodulizer({
  className: article,
  children: {
    'h2': title,
    'p': excerpt,
    '.tags': tags,
  },
});

This will add the locally scoped article class to the <article> tag in the above example, while also add locally scoped classes for each of the given children: h2 (title), p (excerpt), and .tags (tags).

It's recommended that you hide the component initially to prevent a FOUC, like so:

<article>
  <style> article { visibility: hidden } </style>
  <script async
    type="text/javascript"
    src="path/to/component.js">
  </script>
  <h2>My Title</h2>
  <p>Some more stuff...</p>
  <div class="tags">Art, cats, bird watching</div>
</article>

The script will remove that style tag (by default), once it has loaded.

Keywords

FAQs

Last updated on 28 Feb 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc