Skip to content

Commit a80286f

Browse files
feat(addon/components/paper-button): converts to a glimmer component.
1 parent 16439a8 commit a80286f

File tree

2 files changed

+72
-59
lines changed

2 files changed

+72
-59
lines changed

addon/components/paper-button.hbs

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,39 @@
1-
{{! template-lint-disable no-curly-component-invocation }}
2-
{{#if (has-block)}}
3-
{{yield}}
4-
{{else}}
5-
{{@label}}
6-
{{/if}}
1+
{{#let (element this.tag) as |Tag|}}
2+
<Tag
3+
class='md-default-theme md-button
4+
{{if @raised " md-raised"}}
5+
{{if @iconButton " md-icon-button"}}
6+
{{if this.fab " md-fab"}}
7+
{{if @mini " md-mini"}}
8+
{{if @warn " md-warn"}}
9+
{{if @accent " md-accent"}}
10+
{{if @primary " md-primary"}}
11+
{{if @secondary " md-secondary"}}
12+
{{if this.focused " md-focused"}} {{@class}}'
13+
disabled={{this.disabled}}
14+
download={{@download}}
15+
href={{@href}}
16+
id={{@id}}
17+
rel={{@rel}}
18+
tabindex={{if this.disabled "-1" "0"}}
19+
target={{@target}}
20+
title={{@title}}
21+
type={{this.type}}
22+
{{did-insert this.registerListeners}}
23+
{{will-destroy this.unregisterListeners}}
24+
{{on 'click' this.handleClick}}
25+
...attributes
26+
>
27+
{{#if (has-block)}}
28+
{{yield}}
29+
{{else}}
30+
{{@label}}
31+
{{/if}}
732

8-
<PaperRipple
9-
@fitRipple={{@iconButton}}
10-
@center={{@iconButton}}
11-
@dimBackground={{not @iconButton}}/>
33+
<PaperRipple
34+
@fitRipple={{@iconButton}}
35+
@center={{@iconButton}}
36+
@dimBackground={{not @iconButton}}
37+
/>
38+
</Tag>
39+
{{/let}}

addon/components/paper-button.js

Lines changed: 34 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,44 @@
1-
/* eslint-disable ember/no-classic-components, ember/no-mixins, ember/require-tagless-components */
21
/**
32
* @module ember-paper
43
*/
5-
import { reads } from '@ember/object/computed';
6-
7-
import Component from '@ember/component';
8-
import FocusableMixin from 'ember-paper/mixins/focusable-mixin';
9-
import ProxiableMixin from 'ember-paper/mixins/proxiable-mixin';
10-
import { invokeAction } from 'ember-paper/utils/invoke-action';
4+
import Focusable from './-focusable';
5+
import { action } from '@ember/object';
116

127
/**
138
* @class PaperButton
14-
* @extends Ember.Component
15-
* @uses FocusableMixin
16-
* @uses ProxiableMixin
9+
* @extends Focusable
1710
*/
18-
export default Component.extend(FocusableMixin, ProxiableMixin, {
19-
tagName: 'button',
20-
classNames: ['md-default-theme', 'md-button'],
21-
raised: false,
22-
iconButton: false,
23-
24-
// circular button
25-
fab: reads('mini'),
26-
27-
mini: false,
28-
type: 'button',
29-
href: null,
30-
target: null,
31-
32-
attributeBindings: ['type', 'href', 'target', 'title', 'download', 'rel'],
33-
34-
classNameBindings: [
35-
'raised:md-raised',
36-
'iconButton:md-icon-button',
37-
'fab:md-fab',
38-
'mini:md-mini',
39-
'warn:md-warn',
40-
'accent:md-accent',
41-
'primary:md-primary',
42-
],
43-
44-
init() {
45-
this._super(...arguments);
46-
if (this.href) {
47-
this.setProperties({
48-
tagName: 'a',
49-
type: null,
50-
});
11+
export default class PaperButton extends Focusable {
12+
get tag() {
13+
if (this.args.href) {
14+
return 'a';
15+
}
16+
17+
return 'button';
18+
}
19+
20+
get type() {
21+
if (this.args.type) {
22+
return this.args.type;
23+
}
24+
25+
return 'button';
26+
}
27+
28+
get fab() {
29+
return this.args.fab || this.args.mini;
30+
}
31+
32+
@action handleClick(e) {
33+
if (this.args.onClick) {
34+
this.args.onClick(e);
5135
}
52-
},
5336

54-
click(e) {
55-
invokeAction(this, 'onClick', e);
5637
// Prevent bubbling, if specified. If undefined, the event will bubble.
57-
return this.bubbles;
58-
},
59-
});
38+
if (this.args.bubbles === undefined) {
39+
return true;
40+
}
41+
42+
return this.args.bubbles;
43+
}
44+
}

0 commit comments

Comments
 (0)