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
- Go to any type of selector definition from your React components - demo
reactTsCSS.definition
- setting for this feature
- Peek CSS properties of a selector on hover - demo
reactTsCSS.peek
- setting for this feature
- Completion of selectors - demo
- Completion of style identifiers with automatic import of closest (S)CSS module - demo
reactTsCSS.autoComplete
- setting for this feature
- 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 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
- Definition of variables across all the css modules
reactTsCSS.cssDefinitions
- setting for this feature
- 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
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
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:
- snake_case
- PascalCase
- camelCase
- 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
- Plain selectors without any reference is a
no op
in the current version and is expected to be added in coming versions
- Support for stylus will be added in the future versions
- Rename Provider - Rename a selector and get all the places updated
Contribution
Check out the contribution guide