Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Commit d2aa296

Browse files
authored
Merge release-v2.8.5 into master
2 parents bf0064f + 5e2556c commit d2aa296

File tree

14 files changed

+280
-148
lines changed

14 files changed

+280
-148
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## v2.8.5 (May 29, 2019)
2+
- Remove `linebreak-style` blocks windows users from linting their code properly [#169](https://github.com/mobify/mobify-code-style/pull/169)
3+
- Add in Responsive Best Practices section, updated references to Adaptive [#165](https://github.com/mobify/mobify-code-style/pull/165)
4+
15
## v2.8.4 (October 31, 2017)
26
- Add support to copyright tooling for TypeScript files (.ts, .tsx) [#164](https://github.com/mobify/mobify-code-style/pull/164)
37

css/Readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
* [When to use our selector naming scheme](class-naming-conventions#when-to-use-our-selector-naming-scheme)
4040
* [When to use their existing selectors](class-naming-conventions#when-to-use-their-existing-selectors)
4141
* [How to use their existing selectors in our components](class-naming-conventions#how-to-use-their-existing-selectors-in-our-components)
42+
* [Responsive Best Practices](responsive-best-practices/readme.md)
4243
* [Localization and Theming Best Practices](localization-and-theming-best-practices/readme.md)
4344
* [Block Comment Documentation Guide](comments/Readme.md)
4445
* [Hybrid Projects Best Practices](hybrid-projects/Readme.md)

css/class-naming-conventions/readme.md

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,17 @@ Our CSS class naming convention (which we call CSM or Component, Sub-Component,
4343
</div>
4444
```
4545

46-
This example may seem confusing at first but if we break down each of the selectors that we have, it begins to make more sense.
46+
This example may seem confusing at first, but if we break down each of the selectors that we have, it begins to make more sense.
4747

4848
`.c-blog` This is a high-level component. In this example, it describes a wrapper that may contain blog content.
4949

50-
`.c-blog__title` This is a sub-component. In this example, it is a title for a blog.
50+
`.c-blog__title` This is a sub-component. In this example, it's a title for a blog.
5151

52-
`.c-blog-post` This is another high-level component. In this example, it describes the blog post itself. Notice that it is its own component instead of a sub-component of `c-blog` because a blog post does not need to be child of the blog container. This way the component is able to live anywhere.
52+
`.c-blog-post` This is another high-level component. In this example, it describes the blog post itself. Notice that it can be its own component instead of a sub-component of `c-blog` because a blog post does not need to be child of the blog container. This way, the component is able to live anywhere.
5353

5454
`c-blog-post.c--featured` This is a modifier. Notice that the `c--featured` class is paired with the component or sub-component it belongs to. In this example, it describes a different way of displaying the `c-blog-post` component.
5555

56-
`.c-blog-post__time` Like before, this is another sub-component this time belonging to the `c-blog-post` component. It is still a sub-component even though it is not a **direct** child of the component. In other words, sub-components are not required to be direct children of its parent component.
56+
`.c-blog-post__time` Like before, this is another sub-component this time belonging to the `c-blog-post` component. It's still a sub-component, even though it is not a **direct** child of the component. In other words, sub-components are not required to be direct children of their parent component.
5757

5858
### Components
5959

@@ -70,7 +70,7 @@ Components are independent and self-contained units of UI. Styles belonging to a
7070

7171
### Sub-components
7272

73-
Sub-components are elements that are child to its parent component. The classname should be formatted as such: `c-[parent-component-name]__[sub-component-name]`. Sub-components do not, and should not, have sub-components of their own. If you find you need to write a sub-sub-component, instead just treat it as a sub-component – sub-components are only ever child to the parent component.
73+
Sub-components are elements that are descendants of their parent component. Their classnames should be formatted as such: `c-[parent-component-name]__[sub-component-name]`. Sub-components do not, and should not, have sub-components of their own. If you find you need to write a sub-sub-component, instead just treat it as a sub-component.
7474

7575
Like components, these should always live at the root level of a file. Avoid nesting these within the parent component or another sub-component.
7676

@@ -103,7 +103,7 @@ Like components, these should always live at the root level of a file. Avoid nes
103103

104104
### Modifiers
105105

106-
Modifiers, as their name suggests, modify components or sub-components. They are always chained to the component or sub-component they belong to.
106+
Modifiers, as their name suggests, modify components or sub-components. They're always chained to the component or sub-component they belong to.
107107

108108
* Prefixed with the namespace of the affected element and two dashes (`c--`, `t--`)
109109
* Contained to the scope of a single component
@@ -292,7 +292,7 @@ Prefix | Purpose | Location |
292292
`.m-` (*) | Desktop embedded mobile markup classes: these are classes that we will use if we author Markup that is intended for clients to embed onto their desktop pages, but is for mobile content. | *n/a* |
293293
`.js-` | Javascript classes are used exclusively by scripts and should never have CSS styles applied to them. Repeat: **Do NOT** style Javascript classes. | *n/a*
294294

295-
> \* The `m-` class prefix has an old, deprecated use: Mobify Modules. However, Mobify Modules have been replaced with third part plugins, and are treated as third party libraries with their own conventions.
295+
> \* The `m-` class prefix has an old, deprecated use: Mobify Modules. However, Mobify Modules have been replaced with third party plugins, and are treated as third party libraries with their own conventions.
296296
297297

298298
## Components That Style Components
@@ -308,9 +308,9 @@ Sometimes there are situations when a component makes use of other components, a
308308
</button>
309309
```
310310

311-
In situations like this it is tempting to just style the icon's class inside of the button. However, this practice is poor and creates tight coupling between the Button and Icon components that shouldn't exist. As a rule of thumb, a component should only know about what it's responsible for; it should be unaware of anything external to itself. Continuing with this example, the Icon is an external component, therefore the Button component should be completely unaware there there is even such thing as icon classes, like `c-icon`.
311+
In situations like this it is tempting to just style the icon's class inside of the button. However, this practice is poor and creates tight coupling between the Button and Icon components that shouldn't exist. As a rule of thumb, a component should only know about what it's responsible for; it shouldn't be aware of anything external to itself. Since Icon is an external component, the Button component should be completely unaware of `c-icon`.
312312

313-
The solution to this challenge is to instead give the external component a new class that our new component can know about, like `c-button__icon`. By doing it in this way the external Icon component is, for all intents and purposes, being treated as a sub-component of the Button component. This method also has the benefit of being free of any (tight) coupling between the components. Both components can change, be added or removed, without really effecting the other in an unpredictable way.
313+
The solution to this challenge is to instead give the external component a new class that our new component can know about, like `c-button__icon`. This way, the component is treated like a sub-component of Button, and eliminates any tight coupling between the components. Both components can change, be added or removed, without affecting the other in an unpredictable way.
314314

315315
So, to summarize...
316316

@@ -349,25 +349,22 @@ So, to summarize...
349349

350350
## Parsing vs. Decorating
351351

352-
It's important to understand that we have a few different ways of authoring our CSS, and the way we do this is depends a lot on how we convert the desktop markup for mobile. Ideally, we parse the desktop markup and take full control of the final HTML. However, this isn't always possible, and sometimes we just output the desktop markup as is: untouched, or perhaps partially wrapped in order to control the appearance entirely through CSS.
352+
Ideally, we have total control over the HTML markup of a project. However, sometimes there are engineering requirements that force us to retain client markup, or partially wrap it in a container of our own.
353353

354-
If you find yourself wondering "should I be adding a new class, or should I use the classes from desktop?" consider the following: If we're using their class names, we obviously can't follow our CSM syntax. But that said, sometimes we just have no choice; perhaps there are engineering requirements that force us to retain the markup structure. Under such circumstances, we must stick to the desktop classes.
355-
356-
Below is laid out some situational advice that should clarify when to use desktop classes and when to author our own. We also talk about ways to adjust the code style when using their class names.
354+
If you find yourself wondering "should I be adding a new class, or should I use the classes from desktop?" consider the following: If we're using their class names, we can't follow our CSM syntax. Here's some advice:
357355

358356
### When to use our class naming convention
359357

360358
* When writing your own markup in a template
361-
* When decorating (adding, moving, or wrapping) markup in a View, Parser, Decorator or UI-Script
359+
* When decorating (adding, moving, or wrapping) markup in a View, Parser, Decorator or UI-Script (Adaptive.js)
362360
* When adding custom classes to existing markup
363361
* When you find yourself using @extend
364362

365-
### When to use their existing selectors
363+
### When to use client selectors
366364

367365
* When it's fastest, easiest or most efficient to use their markup than it is to add our own.
368366
* When their markup is too inconsistent, or makes parsing too difficult.
369-
* When mobile functionality is tightly coupled to desktop's markup structure.
370-
* When intercepting AJAXed content or content added after a page is too costly, unperformant, or inefficent.
367+
* When functionality is tightly coupled to markup structure.
371368

372369
### How to use their existing selectors in our components
373370

@@ -394,7 +391,7 @@ Always component classes should always be structured with our naming conventions
394391

395392
Desktop classes can be added inside their parent component, but adding our own classes should be your FIRST approach so as to avoid nesting.
396393

397-
Constantly evaluate your nesting in situation like this.
394+
Constantly evaluate your nesting in situations like this.
398395

399396
```scss
400397
// Okay
@@ -427,7 +424,7 @@ Constantly evaluate your nesting in situation like this.
427424
}
428425
```
429426

430-
Use their modifiers the same way you would use our modifiers. Chain it to the component or sub-component it directly affects.
427+
Use their modifiers the same way you would use our modifiers. Chain them to the component or sub-component it directly affects.
431428

432429
```scss
433430
// Okay
@@ -456,4 +453,4 @@ Use their modifiers the same way you would use our modifiers. Chain it to the co
456453
}
457454
```
458455

459-
Continue on to [Block Comment Documentation Guide ](../localization-and-theming-best-practices/readme.md)
456+
Continue on to [Responsive Best Practices ](../responsive-best-practices/readme.md)

css/css-best-practices/readme.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* [A Note On Attribute Selectors](#a-note-on-attribute-selectors)
1111
* [Class Naming Convention](#class-naming-convention)
1212
* [Self Documenting Selectors](#self-documenting-selectors)
13+
* [Mobile First](#mobile-first)
1314
* [Single Direction Rule](#single-direction-rule)
1415
* [Name Spacing](#name-spacing)
1516
* [Size Units](#size-units)
@@ -21,9 +22,7 @@
2122

2223
## Code Like it's 2020
2324

24-
Because we use Autoprefixer, we are able to write our code as if all our properties are fully supported. When compiled, Autoprefixer will of course convert any properties that have special requirements as far as compatibility is concerned and add prefixes to them as needed.
25-
26-
That includes things like Flexbox, CSS3 properties, and many more! This also means that we *should not* be using mixins for prefixing. Remember that Autoprefixer uses data from caniuse.com to determine what will be output — so properties that don't have enough browser support should probably still be avoided (or at least used with extreme caution).
25+
Because we use post-processors, we are able to write our code as if all our properties are fully supported–includeing things like Flexbox, CSS3 properties, and many more! This also means that we *should not* be using mixins for prefixing.
2726

2827

2928
## Selector Specificity
@@ -32,32 +31,30 @@ We strive to write performant, portable, selectors whenever possible. In short,
3231

3332
To help do that, it might be helpful to know how to measure specificity which [Smashing Magazine has an article just for that](http://www.smashingmagazine.com/2007/07/27/css-specificity-things-you-should-know/)!
3433

35-
### Dos:
34+
### Some Notes:
3635

3736
* Use class names for specificity because it improves performance.
38-
* Use the component oriented naming conventions outlined below.
39-
* If you have no other choice and you must select an ID, use the attribute selector instead
40-
41-
### Do Nots:
42-
4337
* Avoid using IDs. They decrease portability.
38+
* Use the component oriented naming conventions outlined below.
4439
* Avoid using tag selectors. They both impact performance and portability.
4540
* Never over qualify selectors because it impacts performance.
41+
* If you have no other choice and you must select an ID, use the attribute selector instead
42+
4643

4744
```scss
48-
// NO
45+
// Instead of:
4946
ul.button-group li.button {
5047
}
5148

52-
// Yes
49+
// Try:
5350
.button-group__button {
5451
}
5552

56-
// NO
53+
// Instead of:
5754
#something {
5855
}
5956

60-
// Yes (Only as a last resort!)
57+
// Try (Only as a last resort!):
6158
[id="something"] {
6259
}
6360
```
@@ -67,7 +64,7 @@ ul.button-group li.button {
6764

6865
A common use case is to target input types. For example `input[type="text"]`.
6966

70-
It's important to realize that the element selector is not necessary here. If you think about it, we are actually increasing the specificity needlessly. Attribute selectors have the same specificity as a class. The above example has the same specificity as `input.someClass`
67+
It's important to realize that the element selector (`input`, in this case) is not necessary here. Using `input` increases the specificity needlessly. Attribute selectors have the same specificity as a class. The above example has the same specificity as `input.someClass`
7168

7269
All we really need is `[type="text"]`, because that is sufficient for targeting text inputs.
7370

@@ -76,7 +73,7 @@ In summary: *attribute selectors should be used alone*, just like classes.
7673

7774
## Class Naming Convention
7875

79-
We use a modified version of BEM that we call CSM (Component, Sub-component, Modifier). At it's core, it's virtually identical to BEM, but our exact syntax is slightly different. Basically:
76+
We use a modified version of BEM that we call CSM (Component, Sub-component, Modifier). At its core, it's virtually identical to BEM, but our syntax is slightly different. Basically:
8077

8178
```
8279
.c-component
@@ -93,14 +90,18 @@ When authoring CSS, you should be always aware of the selectors that you are cre
9390

9491
Strive to create selectors that actually fully describe where it is authored. Put another way, any given selector should tell you which file and where in the file it is written.
9592

96-
This can be down by following this simple rule: the first class in a selector is the file it can be found
93+
This can be done by following this simple rule: the first class in a selector is the file it can be found.
9794

9895
For example `.t-pdp .c-product` would be written in `_pdp.scss` and NOT `_product.scss`.
9996

100-
The exception to this rule are when a base or root class is dependant on a global state.
97+
The exception to this rule is when a base or root class is dependent on a global state:
98+
99+
`.x-landscape .t-about .c-contact-form` would be found in `_about.scss` and NOT a `_landscape.scss` file (modifier classes alone don't have their own files). Using `x-` prefixes is an old convention and won't be found very often.
101100

102-
For example `.x-landscape .t-about .c-contact-form` would be found in `_about.scss` and NOT a `_landscape.scss` file (modifier classes alone don't have their own files).
103101

102+
## Mobile First
103+
104+
When styling responsively, we use min-width queries and build on top of them when we need to. Learn more about our other responsive best practices [here](responsive-best-practices/readme.md).
104105

105106
## Single Direction Rule
106107

@@ -115,9 +116,7 @@ This principle is talked about in depth by [Harry Roberts on csswizardy.com](htt
115116

116117
## Name Spacing
117118

118-
The first thing you'll notice when going through Customer Success's CSS is that all of our class names are prefixed (aka: name-spaced) to one of two letters: `c-` or `t-`, meaning `_component_` or `_template_` respectively. See the [below table](../class-naming-conventions#class-prefix-conventions) for more details on Mobify's namespacing practices.
119-
120-
Because we work on top of our client's markup and javascript, we need to make sure our class names will never conflict with their class names. By prefixing/namespacing our classes with `c-` or `t-`, we can be assured that 99.9% of those situations are avoided.
119+
The first thing you'll notice when going through our CSS is that all of our class names are prefixed (aka: name-spaced) to one of two letters: `c-` or `t-`, meaning `_component_` or `_template_` respectively. See the [below table](../class-naming-conventions#class-prefix-conventions) for more details on Mobify's namespacing practices.
121120

122121

123122
## Size Units
@@ -230,6 +229,7 @@ And as before, we use [Sass-Lint](https://github.com/sasstools/sass-lint) to hel
230229
1. Pseudo-elements
231230
1. Modifier elements
232231
1. Child elements
232+
1. Media Queries
233233

234234
```scss
235235
.c-selector {
@@ -309,7 +309,7 @@ And as before, we use [Sass-Lint](https://github.com/sasstools/sass-lint) to hel
309309
Sometimes we break out of this convention to add to the readability of our stylesheets. This occurs especially often with long comma separated property values like gradients, shadows, transitions, or includes. These can be arrange across multiple lines and indentation levels to help with diffs and readability.
310310

311311
```scss
312-
.x-selector {
312+
.c-selector {
313313
@include icon(
314314
home,
315315
$color: blue,

css/csscomb/readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ Before you start, make sure you have [Package Control](https://packagecontrol.io
4040
* [CSSComb for VIM](https://github.com/csscomb/vim-csscomb)
4141
* [jetbrains-csscomb](https://github.com/csscomb/jetbrains-csscomb) which should work for all JetBrains IDEs, such as IDEA, PyCharm, WebStorm, PhpStorm, RubyMine, and perhaps others.
4242
* [CSSComb for Emacs](https://github.com/channikhabra/css-comb.el), including Aquamacs
43+
* [CSSComb for VS Code](https://marketplace.visualstudio.com/items?itemName=mrmlnc.vscode-csscomb)

0 commit comments

Comments
 (0)