Skip to content
| Marketplace
Sign in
Visual Studio Code>Programming Languages>React CSS modulesNew to Visual Studio Code? Get it now.

React CSS modules

Vijayakrishna

vijayakrishna.dev
|
818 installs
| (2) | Free
React CSS modules - VS code extension for CSS modules support in React projects written in typescript.Supports Definitions, Hover , Completion Providers and Diagnostics
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

React CSS modules

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 vscode code css langauge fetures. Check CSS language features for more info

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

Capabilities

  • TS/TSX|JS/JSX Language Features
    • Definitions
    • Hover
    • Completions
    • Diagnostics
    • Code Actions
  • CSS/SCSS/Less Langauge Features
    • Variable Completion - [Only CSS]
    • Variable Definitions - [Only CSS]
    • Syntax Colors and Presentation - [Only CSS]
    • Reference Provider (Experimental/Turned OFF)
    • Code Lens (Experimental/Turned OFF))
  • Casings
  • Settings
  • Roadmap
  • Contribution

TS/TSX|JS/JSX Language Features

Definitions

  • Go to any type of selector definition from your React components - demo
    • reactTsCSS.definition - setting for this feature

Hover

  • Peek CSS properties of a selector on hover - demo
    • reactTsCSS.peek - setting for this feature

Completions

  • Completion of selectors - demo
  • Completion of style identifiers with automatic import of closest (S)CSS module - demo
    • reactTsCSS.autoComplete - setting for this feature

Diagnostics

  • Useful diagnostics information are provided for missing selector - demo
  • Module not found error is also provided for non existing CSS modules - demo
  • Settings to change diagnostics
    • reactTsCSS.diagnostics - Toggle to turn off diagnostics
    • reactTsScss.tsconfig - Base TS Config path in the project.Useful for resolving path aliases. Defaults to './tsconfig.json'
    • reactTsScss.baseDir - Root directory of your project. Useful if tsconfig doesn't have information about path aliases.Defaults to 'src'

Code Actions

  • Code Action to quick fix misspelled selectors
  • Code Action to add a non existing selector to the corresponding CSS/SCSS module
  • Code Action to ignore warnings temporarily
  • demo
    • reactTsCSS.diagnostics - setting for this feature

CSS/SCSS/Less Langauge Features

Demo

Variable Completion - [Only CSS]

  • Completion of variables across all the css modules
    • reactTsCSS.cssAutoComplete - setting for this feature

Variable Definitions - [Only CSS]

  • Definition of variables across all the css modules
    • reactTsCSS.cssDefinitions - setting for this feature

Syntax Colors and Presentation - [Only CSS]

  • Color Presentations and color information for variables across all the css modules
    • reactTsCSS.cssSyntaxColor - setting for this feature

      VS codes built in support for CSS Langauge is limited to the current active file.So the above features are limited to active file and hence any access to variables from different modules won't work until you install React CSS modules

Reference Provider

Experimental Feature. This is turned off till some performance problems are identified

  • Find all the references of a selector across various TS/TSX files - Demo
    • reactTsCSS.references - setting for this feature

Code Lens

Experimental feature . This is turned off till some performance problems are identified

  • Useful Code Lens context for selectors based on their references across component files - Demo
  • A quick alternative to reactTsCSS.references
    • reactTsCSS.codelens - setting for this feature

Casings

This extensions supports selectors written in:

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

Settings

Defaults

{
  "reactTsCSS.peek": true,
  "reactTsCSS.autoComplete": true,
  "reactTsCSS.autoImport": true,
  "reactTsCSS.definition": true,
  "reactTsCSS.references": true,
  "reactTsCSS.tsconfig": "./tsconfig.json",
  "reactTsCSS.baseDir": "src",
  "reactTsCSS.diagnostics": true,
  "reactTsCSS.cssAutoComplete": true,
  "reactTsCSS.cssDefinitions": true,
  "reactTsCSS.cssSyntaxColor": true,
  "reactTsCSS.tsCleanUpDefs": true,
  "reactTsCSS.cleanUpDefs": [
    "*.module.css",
    "*.module.scss",
    "*.module.sass",
    "*.module.less",
    "*.module.styl"
  ],
  "reactTsCSS.codelens": 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
  3. Rename Provider - Rename a selector and get all the places updated

Contribution

Check out the contribution guide

  • Contact us
  • Jobs
  • Privacy
  • Terms of use
  • Trademarks
© 2023 Microsoft