一键导入
variant
Variant type system for component visual variants. Invoke when defining component variant/type attributes using VARIANT_TYPES constant and Enum utility.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Variant type system for component visual variants. Invoke when defining component variant/type attributes using VARIANT_TYPES constant and Enum utility.
用 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.
BEM SCSS mixins for component styling. Invoke when writing or updating component SCSS styles using block/element/modifier/state mixins.
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.
| name | variant |
| description | Variant type system for component visual variants. Invoke when defining component variant/type attributes using VARIANT_TYPES constant and Enum utility. |
统一管理组件视觉变体类型的规范,使用 VARIANT_TYPES 常量和 Enum 工具。
定义在 src/constants/variant.ts:
export const VARIANT_TYPES = [
"primary",
"success",
"warning",
"danger",
"info",
] as const;
export type VariantType = (typeof VARIANT_TYPES)[number];
export const VARIANT_DEFAULT = "info";
export const VARIANT_ICON_MAP: Record<string, string> = {
primary: "circle-info",
success: "circle-check",
info: "circle-info",
warning: "triangle-exclamation",
danger: "circle-xmark",
error: "circle-xmark",
};
导入路径:@utils/Enum
import { Enum } from "@utils/Enum";
// 传入数组
Enum(VARIANT_TYPES) // 返回数组本身
// 传入多个参数
Enum("a", "b", "c") // 返回 ["a", "b", "c"]
Enum() 本质是标识函数,让 @attribute 的 type 字段区分枚举类型和普通构造器。
import { Enum } from "@utils/Enum";
import { VARIANT_TYPES, VARIANT_DEFAULT, type VariantType } from "@constants/variant";
@attribute({
type: Enum(VARIANT_TYPES),
default: VARIANT_DEFAULT,
observer(this: EaAlert, newVal: VariantType) {
this.updateContainerClasslist();
},
})
variant: VariantType = VARIANT_DEFAULT;
@attribute({
type: Enum([...VARIANT_TYPES, "normal"]),
default: "normal",
observer(this: EaComponent) {
this.updateContainerClasslist();
},
})
variant: VariantType | "normal" = "normal";
@attribute({
type: Enum(["outline", "solid", "dashed"]),
default: "solid",
})
borderStyle: string = "solid";
variant:用于表示组件视觉变体/类型的属性,不使用 typedanger:作为错误类型,不使用 error(VARIANT_ICON_MAP 中保留 error 做兼容映射)primary, success, warning, danger, infoupdateContainerClasslist(): string {
const className = bem(
{ [this.variant]: true },
{ disabled: this.disabled }
);
this._container.className = className;
return className;
}
@include block($name) {
@include modifier(primary) {
background-color: var(--primary-color);
}
@include modifier(success) {
background-color: var(--green-500);
}
@include modifier(danger) {
background-color: var(--red-500);
}
}
使用 VARIANT_ICON_MAP 获取 variant 对应的图标名:
import { VARIANT_ICON_MAP } from "@constants/variant";
const iconName = VARIANT_ICON_MAP[this.variant]; // 如 "circle-check"