一键导入
bem-mixin
BEM SCSS mixins for component styling. Invoke when writing or updating component SCSS styles using block/element/modifier/state mixins.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
BEM SCSS mixins for component styling. Invoke when writing or updating component SCSS styles using block/element/modifier/state mixins.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
@attribute decorator for defining HTML attribute-mapped properties. Invoke when creating or updating component attributes that map to HTML attributes.
@property decorator for defining pure JavaScript properties that do NOT map to HTML attributes. Invoke when creating internal component state properties.
Component CSS styling standards including variables, host styles, states, and responsive patterns. Invoke when creating or updating component SCSS files.
@CustomElement decorator for registering Web Components. Invoke when creating new components or modifying component registration options.
Component documentation generation. Invoke when writing or updating component documentation including API tables, examples, and usage guides.
Event system for Web Components including emit() and custom event classes. Invoke when creating or updating component events.
| name | bem-mixin |
| description | BEM SCSS mixins for component styling. Invoke when writing or updating component SCSS styles using block/element/modifier/state mixins. |
使用 SCSS mixin 定义组件的 BEM 样式结构。
mixin 通过 src/themes/namespace.scss 全局引入,无需手动导入。
定义组件块样式:
$name: ea-component;
@include block($name) {
display: inline-flex;
align-items: center;
}
定义元素样式,仅在 @include block() 内部使用:
@include block($name) {
@include element(item) {
padding: var(--#{$name}-padding);
}
@include element(button) {
transition: var(--#{$name}-transition);
&:hover {
background-color: var(--#{$name}-bg-color-hover);
}
// 在 element 内部使用完整选择器
.#{$name}__icon {
margin-right: var(--spacing-xs);
}
}
}
定义修饰符样式,仅在 @include block() 内部使用:
@include block($name) {
@include modifier(large) {
font-size: var(--#{$name}-font-size-large);
// 使用完整选择器覆盖子元素
.#{$name}__item {
padding: var(--spacing-lg);
}
}
@include modifier(small) {
--#{$name}-height: var(--#{$name}-height-small);
}
}
定义状态样式,仅在 @include block() 内部使用:
@include block($name) {
@include state(active) {
background-color: var(--primary-color);
// 使用完整选择器覆盖子元素
.#{$name}__content {
color: var(--color-white);
}
}
@include state(disabled) {
cursor: not-allowed;
opacity: 0.6;
.#{$name}__button {
pointer-events: none;
}
}
}
@include block($name) 内部使用 element、modifier、state 的 mixin.#{$name}__element 完整选择器$name: ea-component-name;
// 1. CSS Custom Properties
:host {
--#{$name}-size: var(--spacing-md);
--#{$name}-bg-color: var(--grey-100);
--#{$name}-transition: var(--transition-fast);
}
// 2. Host 样式
:host {
display: block;
}
:host([disabled]) {
cursor: not-allowed;
}
// 3. BEM 结构
@include block($name) {
display: inline-flex;
align-items: center;
@include element(item) {
padding: var(--#{$name}-padding);
}
@include state(active) {
background-color: var(--primary-color);
.#{$name}__item {
color: var(--color-white);
}
}
@include modifier(small) {
--#{$name}-size: var(--#{$name}-size-small);
}
@include modifier(large) {
--#{$name}-size: var(--#{$name}-size-large);
}
}
使用 ::part 选择器修改子组件样式:
@include block($name) {
@include element(trigger) {
&::part(original) {
display: none;
}
&::part(content) {
background-color: var(--grey-800);
}
}
}
// TypeScript
const bem = createBEM("ea-component");
bem({ size: "large" }); // -> .ea-component.ea-component--size-large
bem({}, { disabled: true }); // -> .ea-component.is-disabled
// SCSS
$name: ea-component;
@include block($name) {
@include modifier(size-large) {
// .ea-component--size-large
// ...
}
}
@include state(disabled) {
// .is-disabled
// ...
}