Viijay-Kr / react-ts-css

VS Code Extension for CSS modules in typescript based react projects
https://marketplace.visualstudio.com/items?itemName=viijay-kr.react-ts-css
MIT License
37 stars 4 forks source link
css cssmodules-react less reactjs scss typescript vscode vscode-extension

React CSS modules

build tests license version

VS Code extension that enables CSS modules IntelliSense for your React projects written in TypeScript/JavaScript. Currently supports CSS, SCSS, Less modules

This extension also supports CSS language features which are not supported by built-in VS Code code CSS language features. Check CSS language features for more info

Capabilities

This extension is unique in terms of support for major types of Casings and different types of CSS class selectors

Different types of selectors are supported

  • Root selectors
  • Nested selectors
  • Suffixed selectors (SCSS only)
  • Deeply nested suffix selectors

Almost all project scaffolders such as Vite, Next.js and CRA add css module declaration to the project by injecting it in a .d.ts file (for instance inside node_modules/vite/client.d.ts added by Vite). TypeScript treats these definitions as definition provider for Style properties. This results in a useless definition result when VS Code Go to Definition is triggered. Check this issue.

This extension gives you an option to eliminate the useless results by using the TypeScript plugin typescript-cleanup-defs that can filter out those definitions results. Check the plugin for more details.

Override this plugin using the setting reactTsScss.tsCleanUpDefs

See how it compares with CSS modules

Features React CSS Modules CSS modules
Definition Camel Case selectors - ✅
Snake Case selectors - ✅
Pascal Case selectors - ✅
Kebab Case selectors - ✅
Camel Case selectors - ✅
Snake Case selectors - ❌
Pascal Case selectors - ❌
Kebab Case selectors - ❌
Completion Camel Case selectors - ✅
Snake Case selectors - ✅
Pascal Case selectors - ✅
Kebab Case selectors - ✅
Camel Case selector - ✅
Snake Case selectors - ✅
Pascal Case selectors - ✅
Kebab Case selectors - ✅
Hover Supported for all types of selectors - ✅
SCSS Suffix Selectors
Less suffix selectors
Selector Diagnostics
Selector References
Code lenses
Rename selector
Mixin Selector
Mixin Reference selectors
Code actions
CSS Definitions
CSS Variables Completions
CSS Color Presentation

Langauge Features

TS/TSX|JS/JSX Language Features

Definitions

Hover

Completions

Diagnostics

Code Actions

CSS/SCSS/Less Language Features

Rename Provider

Reference Provider

Code Lens

Variable Completion - [Only CSS]

Demo

Variable Definitions - [Only CSS]

Syntax Colors and Presentation - [Only CSS]

Casings

This extensions supports selectors written in:

  1. snake_case
  2. PascalCase
  3. camelCase
  4. kebab-case

Settings

Defaults

{
  "reactTsScss.peekProperties": true,
  "reactTsScss.autoComplete": true,
  "reactTsScss.autoImport": true,
  "reactTsScss.definition": true,
  "reactTsScss.references": true,
  "reactTsScss.tsconfig": "./tsconfig.json",
  "reactTsScss.baseDir": "src",
  "reactTsScss.diagnostics": true,
  "reactTsScss.cssAutoComplete": true,
  "reactTsScss.cssDefinitions": true,
  "reactTsScss.cssSyntaxColor": true,
  "reactTsScss.tsCleanUpDefs": true,
  "reactTsScss.cleanUpDefs": [
    "*.module.css",
    "*.module.scss",
    "*.module.sass",
    "*.module.less",
    "*.module.styl"
  ],
  "reactTsScss.codelens": false,
  "reactTsScss.renameSelector": true
}

Roadmap

  1. Plain selectors without any reference is a no op in the current version and is expected to be added in coming versions
  2. Support for stylus will be added in the future versions

Contribution

Check out the contribution guide