Class LinkNavigate and refactor BEM CSS classes across React TSX components and SCSS modules. Class Link connects your component markup, typed FeaturesCross-file navigation
Works in both directions: from TSX ( Component scaffoldingRight-click a folder in the Explorer and choose New Component... to generate:
BEM class editingWith the cursor on a JSX element, use the editor context menu:
Auto-generated
|
| Variable | Description |
|---|---|
{{COMPONENT_NAME}} |
React component name (PascalCase) |
{{COMPONENT_CLASS_NAME}} |
CSS class name (camelCase in TSX, kebab-case in SCSS) |
{{CLASS_NAMES_TYPE}} |
TypeScript Record of class names from the SCSS file |
Expected project layout
Class Link assumes a co-located component structure:
MyComponent/
├── index.ts
├── MyComponent.tsx
├── MyComponent.module.scss
└── MyComponent.styles.ts
TSX files use a cls helper imported from the .styles.ts file:
import { cls } from './MyComponent.styles';
export const MyComponent: React.FC = () => (
<div className={cls.myComponent.block()}>Hello</div>
);
The SCSS module uses standard BEM naming:
.my-component {
/* block */
}
.my-component__title {
/* element */
}
.my-component--active {
/* modifier */
}
Requirements
- A workspace with
package.json(the extension activates when one is present). tsconfig.jsonin the workspace root (used for TSX parsing).@andreyskn/bemin your project for the generated.styles.tsfiles.
Commands
| Command | Description |
|---|---|
| New Component... | Scaffold a new component in the selected folder (Explorer context menu) |
| New Class Name... | Add a BEM block or element to the selected JSX element |
| Select Class Name... | Apply an existing class from the SCSS module to the selected JSX element |
| Class Link: Edit Template | Open and edit component file templates |
Known limitations
- Modifier creation from the context menu is not yet supported.
- New Class Name / Select Class Name require the cursor to be on a line containing JSX.
Development
npm install
npm run compile # type-check, lint, and bundle
npm run watch # rebuild on change
npm test # run extension tests
Press F5 in VS Code to launch an Extension Development Host.