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

feat(addon/components/paper-card-actions): migrates to tagless native class. #1273

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions addon/components/paper-card-actions.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{{yield (hash
icons=(component "paper-card-icon-actions")
)}}
<md-card-actions class={{this.classes}} ...attributes>
{{yield (hash
icons=(component "paper-card-icon-actions")
)}}
</md-card-actions>
19 changes: 9 additions & 10 deletions addon/components/paper-card-actions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable ember/no-classic-components, ember/no-component-lifecycle-hooks, ember/require-tagless-components */
/* eslint-disable ember/no-classic-components */
/**
* @module ember-paper
*/
Expand All @@ -8,19 +8,18 @@ import Component from '@ember/component';
* @class PaperCardActions
* @extends Ember.Component
*/
export default Component.extend({
tagName: 'md-card-actions',
classNameBindings: ['defaultClasses'],

didReceiveAttrs() {
this._super(...arguments);
export default class PaperCardActions extends Component {
tagName = '';

get classes() {
// if the consumer didn't set layout classes, we should set them
// to the default (layout = row, layout align = end center)
let providedClasses = this['class'];

if (!providedClasses || providedClasses.indexOf('layout-') === -1) {
this.set('defaultClasses', 'layout-row layout-align-end-center');
return `layout-row layout-align-end-center ${providedClasses}`.trimEnd();
}
},
});

return providedClasses;
}
}
3 changes: 3 additions & 0 deletions addon/components/paper-card-avatar.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<md-card-avatar ...attributes>
{{yield}}
</md-card-avatar>
8 changes: 4 additions & 4 deletions addon/components/paper-card-avatar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable ember/no-classic-components, ember/require-tagless-components, prettier/prettier */
/* eslint-disable ember/no-classic-components */
/**
* @module ember-paper
*/
Expand All @@ -8,6 +8,6 @@ import Component from '@ember/component';
* @class PaperCardAvatar
* @extends Ember.Component
*/
export default Component.extend({
tagName: 'md-card-avatar'
});
export default class PaperCardAvatar extends Component {
tagName = '';
}
3 changes: 3 additions & 0 deletions addon/components/paper-card-content.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<md-card-content ...attributes>
{{yield}}
</md-card-content>
8 changes: 4 additions & 4 deletions addon/components/paper-card-content.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable ember/no-classic-components, ember/require-tagless-components, prettier/prettier */
/* eslint-disable ember/no-classic-components */
/**
* @module ember-paper
*/
Expand All @@ -8,6 +8,6 @@ import Component from '@ember/component';
* @class PaperCardContent
* @extends Ember.Component
*/
export default Component.extend({
tagName: 'md-card-content'
});
export default class PaperCardContent extends Component {
tagName = '';
}
3 changes: 3 additions & 0 deletions addon/components/paper-card-header-headline.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<span class="md-headline" ...attributes>
{{yield}}
</span>
9 changes: 4 additions & 5 deletions addon/components/paper-card-header-headline.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable ember/no-classic-components, ember/require-tagless-components, prettier/prettier */
/* eslint-disable ember/no-classic-components */
/**
* @module ember-paper
*/
Expand All @@ -8,7 +8,6 @@ import Component from '@ember/component';
* @class PaperCardHeaderHeadline
* @extends Ember.Component
*/
export default Component.extend({
tagName: 'span',
classNames: ['md-headline']
});
export default class PaperCardHeaderHeadline extends Component {
tagName = '';
}
3 changes: 3 additions & 0 deletions addon/components/paper-card-header-subhead.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<span class="md-subhead" ...attributes>
{{yield}}
</span>
9 changes: 4 additions & 5 deletions addon/components/paper-card-header-subhead.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable ember/no-classic-components, ember/require-tagless-components, prettier/prettier */
/* eslint-disable ember/no-classic-components */
/**
* @module ember-paper
*/
Expand All @@ -8,7 +8,6 @@ import Component from '@ember/component';
* @class PaperCardHeaderSubhead
* @extends Ember.Component
*/
export default Component.extend({
tagName: 'span',
classNames: ['md-subhead']
});
export default class PaperCardHeaderSubhead extends Component {
tagName = '';
}
3 changes: 3 additions & 0 deletions addon/components/paper-card-header-title.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<span class="md-title" ...attributes>
{{yield}}
</span>
9 changes: 4 additions & 5 deletions addon/components/paper-card-header-title.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable ember/no-classic-components, ember/require-tagless-components, prettier/prettier */
/* eslint-disable ember/no-classic-components */
/**
* @module ember-paper
*/
Expand All @@ -8,7 +8,6 @@ import Component from '@ember/component';
* @class PaperCardHeaderTitle
* @extends Ember.Component
*/
export default Component.extend({
tagName: 'span',
classNames: ['md-title']
});
export default class PaperCardHeaderTitle extends Component {
tagName = '';
}
3 changes: 3 additions & 0 deletions addon/components/paper-card-icon-actions.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<md-card-icon-actions ...attributes>
{{yield}}
</md-card-icon-actions>
8 changes: 4 additions & 4 deletions addon/components/paper-card-icon-actions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable ember/no-classic-components, ember/require-tagless-components, prettier/prettier */
/* eslint-disable ember/no-classic-components */
/**
* @module ember-paper
*/
Expand All @@ -8,6 +8,6 @@ import Component from '@ember/component';
* @class PaperCardIconActions
* @extends Ember.Component
*/
export default Component.extend({
tagName: 'md-card-icon-actions'
});
export default class PaperCardIconActions extends Component {
tagName = '';
}
1 change: 1 addition & 0 deletions addon/components/paper-card-image.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<img class="md-card-image" alt={{@alt}} src={{@src}} title={{@title}} ...attributes>
10 changes: 4 additions & 6 deletions addon/components/paper-card-image.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable ember/no-classic-components, ember/require-tagless-components, prettier/prettier */
/* eslint-disable ember/no-classic-components */
/**
* @module ember-paper
*/
Expand All @@ -8,8 +8,6 @@ import Component from '@ember/component';
* @class PaperCardImage
* @extends Ember.Component
*/
export default Component.extend({
tagName: 'img',
classNames: ['md-card-image'],
attributeBindings: ['src', 'title', 'alt']
});
export default class PaperCardImage extends Component {
tagName = '';
}
16 changes: 9 additions & 7 deletions addon/components/paper-card-title-media.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{{#if (has-block)}}
<div class="md-media-{{this.size}}">
{{yield}}
</div>
{{else}}
<img class="md-media-{{this.size}}" src={{@src}} alt={{@alt}} title={{@title}}>
{{/if}}
<md-card-title-media ...attributes>
{{#if (has-block)}}
<div class="md-media-{{this.size}}">
{{yield}}
</div>
{{else}}
<img class="md-media-{{this.size}}" src={{@src}} alt={{@alt}} title={{@title}}>
{{/if}}
</md-card-title-media>
10 changes: 5 additions & 5 deletions addon/components/paper-card-title-media.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable ember/no-classic-components, ember/require-tagless-components */
/* eslint-disable ember/no-classic-components */
/**
* @module ember-paper
*/
Expand All @@ -8,7 +8,7 @@ import Component from '@ember/component';
* @class PaperCardTitleMedia
* @extends Ember.Component
*/
export default Component.extend({
tagName: 'md-card-title-media',
size: 'md',
});
export default class PaperCardTitleMedia extends Component {
tagName = '';
size = 'md';
}
10 changes: 6 additions & 4 deletions addon/components/paper-card-title-text.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{{yield (hash
headline=(component "paper-card-header-headline")
subhead=(component "paper-card-header-subhead")
)}}
<md-card-title-text ...attributes>
{{yield (hash
headline=(component "paper-card-header-headline")
subhead=(component "paper-card-header-subhead")
)}}
</md-card-title-text>
8 changes: 4 additions & 4 deletions addon/components/paper-card-title-text.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable ember/no-classic-components, ember/require-tagless-components */
/* eslint-disable ember/no-classic-components */
/**
* @module ember-paper
*/
Expand All @@ -8,6 +8,6 @@ import Component from '@ember/component';
* @class PaperCardTitleText
* @extends Ember.Component
*/
export default Component.extend({
tagName: 'md-card-title-text',
});
export default class PaperCardTitleText extends Component {
tagName = '';
}
18 changes: 10 additions & 8 deletions addon/components/paper-card.hbs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{{yield (hash
title=(component "paper-card-title")
content=(component "paper-card-content")
actions=(component "paper-card-actions")
header=(component "paper-card-header")
image=(component "paper-card-image")
media=(component "paper-card-media")
)}}
<md-card ...attributes>
{{yield (hash
title=(component "paper-card-title")
content=(component "paper-card-content")
actions=(component "paper-card-actions")
header=(component "paper-card-header")
image=(component "paper-card-image")
media=(component "paper-card-media")
)}}
</md-card>
8 changes: 4 additions & 4 deletions addon/components/paper-card.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable ember/no-classic-components, ember/require-tagless-components */
/* eslint-disable ember/no-classic-components */
/**
* @module ember-paper
*/
Expand All @@ -8,6 +8,6 @@ import Component from '@ember/component';
* @class PaperCard
* @extends Ember.Component
*/
export default Component.extend({
tagName: 'md-card',
});
export default class PaperCard extends Component {
tagName = '';
}
55 changes: 51 additions & 4 deletions tests/integration/components/paper-card-test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/* eslint-disable prettier/prettier */
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';

module('Integration | Component | paper-card', function(hooks) {
module('Integration | Component | paper-card', function (hooks) {
setupRenderingTest(hooks);

test('blockless media renders image', async function(assert) {
test('blockless media renders image', async function (assert) {
assert.expect(5);

await render(hbs`
Expand Down Expand Up @@ -36,7 +35,7 @@ module('Integration | Component | paper-card', function(hooks) {
assert.dom('img').hasClass('md-media-xl');
});

test('block media renders div with correct class', async function(assert) {
test('block media renders div with correct class', async function (assert) {
assert.expect(1);

await render(hbs`
Expand All @@ -62,4 +61,52 @@ module('Integration | Component | paper-card', function(hooks) {

assert.dom('div.md-media-xl').exists({ count: 1 });
});

test('block actions renders tag with default layout classes', async function (assert) {
assert.expect(3);

await render(hbs`
{{#paper-card as |card|}}
{{#card.actions}}
{{#paper-button iconButton=true}}{{paper-icon "favorite"}}{{/paper-button}}
{{/card.actions}}
{{/paper-card}}
`);

assert.dom('md-card-actions').exists({ count: 1 });
assert.dom('md-card-actions').hasClass('layout-row');
assert.dom('md-card-actions').hasClass('layout-align-end-center');
});

test('block actions renders tag with passed through layout classes', async function (assert) {
assert.expect(2);

await render(hbs`
{{#paper-card as |card|}}
{{#card.actions class="layout-column"}}
{{#paper-button iconButton=true}}{{paper-icon "favorite"}}{{/paper-button}}
{{/card.actions}}
{{/paper-card}}
`);

assert.dom('md-card-actions').exists({ count: 1 });
assert.dom('md-card-actions').hasClass('layout-column');
});

test('block actions renders tag with passed through non-layout classes', async function (assert) {
assert.expect(4);

await render(hbs`
{{#paper-card as |card|}}
{{#card.actions class="call-to-action"}}
{{#paper-button iconButton=true}}{{paper-icon "favorite"}}{{/paper-button}}
{{/card.actions}}
{{/paper-card}}
`);

assert.dom('md-card-actions').exists({ count: 1 });
assert.dom('md-card-actions').hasClass('layout-row');
assert.dom('md-card-actions').hasClass('layout-align-end-center');
assert.dom('md-card-actions').hasClass('call-to-action');
});
});
Loading