Skip to content

Commit 4bb72f9

Browse files
authored
feat(styleNamespace): now upgrading to using 'styleNamespace' for the namespace computed property. Will offically deprecate componentCssClassName in the future (#254)
1 parent d37978d commit 4bb72f9

9 files changed

Lines changed: 34 additions & 21 deletions

File tree

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ To be able to use this for routes, you need to add a wrapping `div` around the o
103103

104104
After that it's quite easy: add a style file in your route directory alongside your `route.js` or `template.hbs` files.
105105

106-
An individual controller also has access to a `styleNamespace` property that is the namespace for a given route. This can be used for various use cases. (like enabling BEM style similar to how the `componentCssClassName` is used in a component)
106+
An individual controller also has access to a `styleNamespace` property that is the namespace for a given route. This can be used for various use cases. (like enabling BEM style similar to how the `styleNamespace` is used in a component)
107107

108108
### Usage with classic (non pod) structure
109109

@@ -184,18 +184,18 @@ postcss plugins in this way too.
184184

185185
### Getting the generated class name
186186

187-
You also have access to the generated class name to use in your templates. There is a computed property `componentCssClassName` This can be used to pass the class name to things like [`ember-wormhole`](https://github.com/yapplabs/ember-wormhole) or for use in BEM style classnames.
187+
You also have access to the generated class name to use in your templates. There is a computed property `styleNamespace` This can be used to pass the class name to things like [`ember-wormhole`](https://github.com/yapplabs/ember-wormhole) or for use in BEM style classnames.
188188
An example of BEM usage would be
189189

190190
`my-component/template.hbs`
191191
```handlebars
192-
<button class="{{componentCssClassName}}__button">
192+
<button class="{{styleNamespace}}__button">
193193
Normal button
194194
</button>
195-
<button class="{{componentCssClassName}}__button {{componentCssClassName}}__button--state-success">
195+
<button class="{{styleNamespace}}__button {{styleNamespace}}__button--state-success">
196196
Success button
197197
</button>
198-
<button class="{{componentCssClassName}}__button {{componentCssClassName}}__button--state-danger">
198+
<button class="{{styleNamespace}}__button {{styleNamespace}}__button--state-danger">
199199
Danger button
200200
</button>
201201
```
@@ -221,17 +221,19 @@ An example of BEM usage would be
221221
}
222222
```
223223

224+
*`componentCssClassName` will be officially deprecated, then removed in future versions. Will be migrating to the more appropriately named `styleNamespace`*
225+
224226
#### Using the generated class name in `classNameBindings`
225227

226-
You can build your own computed properties on top of `componentCssClassName`. One use case is using it to build a `classNameBinding`:
228+
You can build your own computed properties on top of `styleNamespace`. One use case is using it to build a `classNameBinding`:
227229

228230
`my-component/component.hbs`
229231
```js
230232
classNameBindings: ['customBinding'],
231233
stateProperty: false,
232-
customBinding: computed('componentCssClassName', 'stateProperty', function() {
234+
customBinding: computed('styleNamespace', 'stateProperty', function() {
233235
if (this.get('stateProperty') {
234-
return `${this.get('componentCssClassName')}--state`;
236+
return `${this.get('styleNamespace')}--state`;
235237
} else {
236238
return '';
237239
}

addon/mixins/style-namespacing-extras.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default Mixin.create({
1414

1515
_shouldAddNamespacedClassName: computed({
1616
get() {
17-
return this.get('tagName') !== '' && this.get('componentCssClassName');
17+
return this.get('tagName') !== '' && this.get('styleNamespace');
1818
}
1919
}),
2020
});

app/initializers/component-styles.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ const {
66
Component,
77
ComponentLookup,
88
computed,
9+
computed: {
10+
// deprecatingAlias,
11+
alias,
12+
},
913
getOwner
1014
} = Ember;
1115

@@ -21,17 +25,24 @@ ComponentLookup.reopen({
2125
});
2226

2327
Component.reopen(StyleNamespacingExtras, {
24-
componentCssClassName: computed({
28+
styleNamespace: computed({
2529
get() {
2630
return podNames[this.get('_componentIdentifier')] || '';
2731
}
2832
}),
2933

34+
// componentCssClassName: deprecatingAlias('styleNamespace', {
35+
// id: 'ember-component-css.deprecate-componentCssClassName',
36+
// until: '0.7.0',
37+
// }),
38+
39+
componentCssClassName: alias('styleNamespace'),
40+
3041
init() {
3142
this._super(...arguments);
3243

3344
if (this.get('_shouldAddNamespacedClassName')) {
34-
this.classNames = this.classNames.concat(this.get('componentCssClassName'));
45+
this.classNames = this.classNames.concat(this.get('styleNamespace'));
3546
}
3647
}
3748
});

app/initializers/route-styles.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Router.reopen({
1111
let currentPath = route.name.replace(/\./g, '/');
1212

1313
if (podNames[currentPath]) {
14-
getOwner(this).lookup(`controller:${route.name}`).set('routeStyleNamespaceClass', podNames[currentPath]);
14+
getOwner(this).lookup(`controller:${route.name}`).set('styleNamespace', podNames[currentPath]);
1515
classes.push(podNames[currentPath]);
1616
}
1717
}

tests/dummy/app/components/base-rules/template.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
</span>
55
</span>
66
</span>
7-
<span class="{{componentCssClassName}}__element"></span>
8-
<span class="{{componentCssClassName}}__element--variant" tabindex="0">element variant</span>
7+
<span class="{{styleNamespace}}__element"></span>
8+
<span class="{{styleNamespace}}__element--variant" tabindex="0">element variant</span>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{{#each items as |item|}}
2-
<span class="{{componentCssClassName}}__element--{{item}}"></span>
2+
<span class="{{styleNamespace}}__element--{{item}}"></span>
33
{{/each}}

tests/dummy/lib/no-style-files-yet/addon/components/no-style/template.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
</span>
55
</span>
66
</span>
7-
<span class="{{componentCssClassName}}__element"></span>
8-
<span class="{{componentCssClassName}}__element--variant"></span>
7+
<span class="{{styleNamespace}}__element"></span>
8+
<span class="{{styleNamespace}}__element--variant"></span>

tests/dummy/lib/second-test-addon/addon/components/second-addon-less/template.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
</span>
66
</span>
77
</span>
8-
<span class="{{componentCssClassName}}__element"></span>
9-
<span class="{{componentCssClassName}}__element--variant"></span>
8+
<span class="{{styleNamespace}}__element"></span>
9+
<span class="{{styleNamespace}}__element--variant"></span>

tests/dummy/lib/test-addon/addon/components/addon-scss/template.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
</span>
66
</span>
77
</span>
8-
<span class="{{componentCssClassName}}__element"></span>
9-
<span class="{{componentCssClassName}}__element--variant"></span>
8+
<span class="{{styleNamespace}}__element"></span>
9+
<span class="{{styleNamespace}}__element--variant"></span>

0 commit comments

Comments
 (0)