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

translate style.md #148

Merged
merged 2 commits into from
Mar 8, 2018
Merged

translate style.md #148

merged 2 commits into from
Mar 8, 2018

Conversation

yutingzhao1991
Copy link
Contributor

No description provided.


## less

Ant Design Pro defaults to using less as the style language, we recommended that you learn about the features of [less](http://lesscss.org/) before using it or sometimes when you have some questions.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recommend?


## CSS Modules

In the style development process, there are two problems are prominent:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are two prominent problems:


In the style development process, there are two problems are prominent:

- Global Pollution - CSS file selectors are globally valid. according to the build file generated in the order, the ahead selector's style will be cover by the back one which has the same selector name;
Copy link
Contributor

@ddcat1115 ddcat1115 Mar 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CSS selectors are globally valid. Selectors with the same name in different files will be built together, and the former will be overrided by the latter.

In the style development process, there are two problems are prominent:

- Global Pollution - CSS file selectors are globally valid. according to the build file generated in the order, the ahead selector's style will be cover by the back one which has the same selector name;
- Selector complex - in order to avoid the above problem, we have to be careful when writing styles. the class name will be brought flag for limit the style's scope lead to it will getting longer and longer. And in multi-person development, it not only easily lead to the naming style confusion but also cause the number of selectors used on an element be more and more.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Complex selector

...The increase in flags for range restriction will lead to a growing class name, besides that, naming style confusion in multi person development and an increasing number of selectors on an element is hard to avoid.

- Global Pollution - CSS file selectors are globally valid. according to the build file generated in the order, the ahead selector's style will be cover by the back one which has the same selector name;
- Selector complex - in order to avoid the above problem, we have to be careful when writing styles. the class name will be brought flag for limit the style's scope lead to it will getting longer and longer. And in multi-person development, it not only easily lead to the naming style confusion but also cause the number of selectors used on an element be more and more.

In order to solve the above problems, our scaffold use CSS Modules as a modular solution. let us have a look at how to write style in this mode.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

首字母大写

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

或者改成逗号

}
```

Write style use less file does not seem to change, but the class name is relatively simple (the actual project is also the case). js file change at the className property, it changed with an object attribute instead of the original string. the object is import from the less file, and the attribute name same as the selector name in less file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write style use less file does not seem to change much

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...The classname in js files would be replaced by an object attribute, which has the same name as the selector in the less file from where the object was imported.


Write style use less file does not seem to change, but the class name is relatively simple (the actual project is also the case). js file change at the className property, it changed with an object attribute instead of the original string. the object is import from the less file, and the attribute name same as the selector name in less file.

In the above style file, `.title` will only work in this file, you can use the same selector name in any other file, it will not affect here. But sometimes, we just want a global style which effective everywhere? You can use `:global`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we just want a global style which can take effect everywhere

<div class="title___3TqAx">title</div>
```

The class name is automatically added a hash value, which guarantees its uniqueness.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hash value is added to the class name automatically...


The class name is automatically added a hash value, which guarantees its uniqueness.

In addition to the basics above, there are some key points to note:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be noted:


In addition to the basics above, there are some key points to note:

- CSS Modules only convert `className` and `id`. Others such as property selectors and tag selectors are not processed. It is recommended to use className as much as possible.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is recommended to use className as much as possible. 这句有歧义,可以改为:

It is recommended to take className as the first choice.

- CSS Modules only convert `className` and `id`. Others such as property selectors and tag selectors are not processed. It is recommended to use className as much as possible.
- Since you do not have to worry about className repeat, your className can be as simple as possible with basic semantics.

CSS Modules above only the most basic introduction, are interested can refer to other documents:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a brief introduction for CSS Modules, for details, please refer to:

}
```

> Because antd will bring some global settings, such as font size, color, line height。 so here, you only need to focus on their own individual needs can be, without a lot of reset.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

中文句号

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there is no need to do a lot of reset, you can focus on your individualized demands.


### src/utils/utils.less

Here you can place some tool functions for the call, such as clearing the floating `.clearfix`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you can place some tool functions for the call


#### Component level

This is also very simple, there are component-related styles. In your project, there are some reusing fragments in the page or relatively independent function which can be define as components, the relevant style should be extracted on the component, rather than confusing in the page.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also very simple, they are component-related styles

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reusing -> reuseable

}
```

Two points need to note:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be noted

Two points need to note:

- The imported antd component class name is not translated by CSS Modules, so the overridden class name `.ant-select-selection` must be put in `:global`.
- Because of the previous note, the coverage is global. To prevent this from affecting other Select components, need to wrap extra className for limit the scope of the style.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid affecting other Select components, the setting needs to be wrapped by an extra classname to add range restriction.

@ddcat1115
Copy link
Contributor

@yutingzhao1991

@yutingzhao1991
Copy link
Contributor Author

OK, got it, I will fix it later.

@ddcat1115 ddcat1115 merged commit 61a6091 into master Mar 8, 2018
@afc163 afc163 deleted the yu-translate branch March 8, 2018 05:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants