Skip to content

Commit ce47281

Browse files
committed
feat(button): add mdcButtonIcon
1 parent 2a5425a commit ce47281

File tree

2 files changed

+302
-290
lines changed

2 files changed

+302
-290
lines changed
Lines changed: 86 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,86 @@
1-
import { AfterContentInit, Directive, ElementRef, HostBinding, Input, OnDestroy, Renderer2, forwardRef } from '@angular/core';
2-
import { MDCRipple } from '@material/ripple';
3-
import { asBoolean } from '../../utils/value.utils';
4-
import { AbstractMdcRipple } from '../ripple/abstract.mdc.ripple';
5-
import { MdcEventRegistry } from '../../utils/mdc.event.registry';
6-
7-
// TODO: mdc-button__icon
8-
9-
/**
10-
* Material design button. Anchors can also be styled as buttons with this directive.
11-
* Defaults to a button that is flushed with the surface.
12-
* Use the input modifiers to alter the styling, or create your own style
13-
* based on the provided sass-mixins.
14-
*/
15-
@Directive({
16-
selector: 'button[mdcButton],a[mdcButton]',
17-
providers: [{provide: AbstractMdcRipple, useExisting: forwardRef(() => MdcButtonDirective) }]
18-
})
19-
export class MdcButtonDirective extends AbstractMdcRipple implements AfterContentInit, OnDestroy {
20-
@HostBinding('class.mdc-button') _cls = true;
21-
private _dense = false;
22-
private _raised = false;
23-
private _outlined = false;
24-
25-
constructor(public _elm: ElementRef, renderer: Renderer2, registry: MdcEventRegistry) {
26-
super(_elm, renderer, registry);
27-
}
28-
29-
ngAfterContentInit() {
30-
this.initRipple();
31-
}
32-
33-
ngOnDestroy() {
34-
this.destroyRipple();
35-
}
36-
37-
/**
38-
* When this input is defined and does not have value false, the button will be elevated
39-
* upon the surface.
40-
*/
41-
@HostBinding('class.mdc-button--raised') @Input()
42-
get raised() {
43-
return this._raised;
44-
}
45-
46-
set raised(val: any) {
47-
this._raised = asBoolean(val);
48-
}
49-
50-
/**
51-
* When this input is defined and does not have value false, the button will be styled
52-
* flush with the surface and have a visible border.
53-
*/
54-
@HostBinding('class.mdc-button--outlined') @Input()
55-
get outlined() {
56-
return this._outlined;
57-
}
58-
59-
set outlined(val: any) {
60-
this._outlined = asBoolean(val);
61-
}
62-
63-
/**
64-
* When this input is defined and does not have value false, the button text is compressed
65-
* to make it slightly smaller.
66-
*/
67-
@HostBinding('class.mdc-button--dense') @Input()
68-
get dense() {
69-
return this._dense;
70-
}
71-
72-
set dense(val: any) {
73-
this._dense = asBoolean(val);
74-
}
75-
}
1+
import { AfterContentInit, Directive, ElementRef, HostBinding, Input, OnDestroy, Renderer2, forwardRef } from '@angular/core';
2+
import { MDCRipple } from '@material/ripple';
3+
import { asBoolean } from '../../utils/value.utils';
4+
import { AbstractMdcRipple } from '../ripple/abstract.mdc.ripple';
5+
import { MdcEventRegistry } from '../../utils/mdc.event.registry';
6+
7+
/**
8+
* Use this directive for adding an icon to an <code>mdcButton</code>. This directive can be
9+
* added to font-style icons (such as <a href="https://material.io/icons/">material icons</a>
10+
* from Google fonts), or with <code>svg</code> elements for svg based icons.
11+
*/
12+
@Directive({
13+
selector: 'mdcButtonIcon'
14+
})
15+
export class MdcButtonIconDirective {
16+
@HostBinding('class.mdc-button__icon') _cls = true;
17+
@HostBinding('attr.aria-hidden') _ariaHidden = true;
18+
}
19+
20+
/**
21+
* Material design button. Anchors can also be styled as buttons with this directive.
22+
* Defaults to a button that is flushed with the surface.
23+
* Use the input modifiers to alter the styling, or create your own style
24+
* based on the provided sass-mixins.
25+
*/
26+
@Directive({
27+
selector: 'button[mdcButton],a[mdcButton]',
28+
providers: [{provide: AbstractMdcRipple, useExisting: forwardRef(() => MdcButtonDirective) }]
29+
})
30+
export class MdcButtonDirective extends AbstractMdcRipple implements AfterContentInit, OnDestroy {
31+
@HostBinding('class.mdc-button') _cls = true;
32+
private _dense = false;
33+
private _raised = false;
34+
private _outlined = false;
35+
36+
constructor(public _elm: ElementRef, renderer: Renderer2, registry: MdcEventRegistry) {
37+
super(_elm, renderer, registry);
38+
}
39+
40+
ngAfterContentInit() {
41+
this.initRipple();
42+
}
43+
44+
ngOnDestroy() {
45+
this.destroyRipple();
46+
}
47+
48+
/**
49+
* When this input is defined and does not have value false, the button will be elevated
50+
* upon the surface.
51+
*/
52+
@HostBinding('class.mdc-button--raised') @Input()
53+
get raised() {
54+
return this._raised;
55+
}
56+
57+
set raised(val: any) {
58+
this._raised = asBoolean(val);
59+
}
60+
61+
/**
62+
* When this input is defined and does not have value false, the button will be styled
63+
* flush with the surface and have a visible border.
64+
*/
65+
@HostBinding('class.mdc-button--outlined') @Input()
66+
get outlined() {
67+
return this._outlined;
68+
}
69+
70+
set outlined(val: any) {
71+
this._outlined = asBoolean(val);
72+
}
73+
74+
/**
75+
* When this input is defined and does not have value false, the button text is compressed
76+
* to make it slightly smaller.
77+
*/
78+
@HostBinding('class.mdc-button--dense') @Input()
79+
get dense() {
80+
return this._dense;
81+
}
82+
83+
set dense(val: any) {
84+
this._dense = asBoolean(val);
85+
}
86+
}

0 commit comments

Comments
 (0)