Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@postcss-plugins/typescript-css

ezavile439MIT0.1.2TypeScript support: included

PostCSS plugin to create a typescript file definition by each CSS file

@postcss, @postcss-plugins, postcss, postcss-plugins, typescript, css, classnames

readme

@postcss-plugins/typescript-css

npm

A PostCSS plugin to create a TypeScript file by each CSS file.

Installation

yarn add @postcss-plugins/typescript-css

What is this? For example, you have the following CSS file:

componentName.css

.ComponentName {
  color: green;
}
.ComponentName-descendentName {
  color: yellow;
}
.ComponentName--modifierName {
  color: red;
}

And the plugin will give you a TypeScript file in the same location where the CSS file is. This file generated has almost the same name, only it's added ".style.ts", example:

componentName.style.ts

export const componentNameStyle = {
  componentName: 'ComponentName',
  componentDescendentName: 'ComponentName-descendentName',
  componentModifierName: 'ComponentName--modifierName',
};

So, you can import the TypeScript file

Note: you have to import first the componentName.css

import './componentName.css';
import { componentNameStyle } from './componentName.style';

const element = document.createElement('div');
element.className = componentNameStyle.componentName;

Usage

postcss([require('postcss-typescript-css')]);

Contributing

  • ⇄ Pull requests and ★ Stars are always welcome.
  • For bugs and feature requests, please create an issue.

MIT License

changelog

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

0.1.2 (2021-02-25)

Note: Version bump only for package @postcss-plugins/typescript-css

0.1.1 (2021-02-16)

Bug Fixes

  • typescript-css: add missing definition type (92d99ba)

0.1.0 (2021-02-16)

Features

  • typescript-css: :sparkles: add plugin code (6f3398f)