Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sinoui 库 className 命名规范 #5

Open
liujinxing opened this issue Oct 23, 2019 · 1 comment
Open

sinoui 库 className 命名规范 #5

liujinxing opened this issue Oct 23, 2019 · 1 comment
Labels
enhancement New feature or request 规范

Comments

@liujinxing
Copy link
Member

className 命名规范

本规范参考 BEM 命名规范。

基本形式

.Block__Element--Modifier

Block: 块

Element: 元素

Modifier: 修饰符

以 @sinoui/switch 为例

<span class="sinoui-switch sinoui-switch--disabled sinoui-switch--checked">
    <span class="sinoui-switch__label">
        <input class="sinoui-switch__input" />
        <span class="sinoui-switch__thumb" />
    </span>
    <span class="sinoui-switch__track">
    </span>
</span>

sinoui - 域名,命名空间。

switch - 块。

disabledchecked - 修饰符

__label__input__thumb - 开关组件中的元素。

块与元素的区别

块有完整的语义,如开关组件。

元素是块的组成部分,不能脱离于块而独立被使用。如开关组件的轴(.sinoui-switch__track ),将它脱离于开关组件去用,没有实际意义。

块与元素的深度

只能有一级,不能出现如: sinoui-switch__label__input这样的情况。遇到这种情况,依场景而定。有两种方式:

  • 方式一:类似@sinoui/switch的方式,所有的元素classname以根元素的块名称为前缀。

  • 方式二:采用块嵌套块的方式。即可以定义一些子块。子块的多个单词之间使用 - 连接,如 sinoui-switch-label

@liujinxing liujinxing added the enhancement New feature or request label Oct 23, 2019
@liujinxing
Copy link
Member Author

liujinxing commented Jan 9, 2020

包含关系的修饰符:

  • --has-icon
  • --has-description

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request 规范
Projects
None yet
Development

No branches or pull requests

1 participant