This repository has been archived by the owner on Oct 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(card): Add [mdc-card-button] + refactoring (#90)
* refactor(card): External directives merged into card.component file * feat(card): Add [mdc-card-button] to card component * refactor(card): Remove [darkTheme] property. BREAKING CHANGE: Property [cardAction] of mdc-button was removed, you'll need to use mdc-card-button. Please update your code accordingly. BREAKING CHANGE: [darkTheme] property was removed from Card. Use [mdc-theme-dark] instead.
- Loading branch information
Showing
11 changed files
with
146 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,132 @@ | ||
import { | ||
AfterContentInit, | ||
Component, | ||
ContentChildren, | ||
Directive, | ||
ElementRef, | ||
HostBinding, | ||
Inject, | ||
Input, | ||
QueryList, | ||
Renderer2, | ||
ViewEncapsulation, | ||
} from '@angular/core'; | ||
import { toBoolean } from '../common/boolean-property'; | ||
|
||
import { Ripple } from '../ripple/ripple.directive'; | ||
import { ButtonComponent } from '../button/button.component'; | ||
|
||
@Directive({ | ||
selector: 'mdc-card-primary' | ||
}) | ||
export class CardPrimaryDirective { | ||
@HostBinding('class.mdc-card__primary') isHostClass = true; | ||
} | ||
|
||
@Component({ | ||
selector: 'mdc-card-horizontal', | ||
template: '<ng-content select="mdc-card-primary, mdc-card-title, mdc-card-subtitle, [mdc-card-media-item], mdc-card-actions"></ng-content>', | ||
encapsulation: ViewEncapsulation.None | ||
}) | ||
export class CardHorizontalComponent { | ||
@HostBinding('class.mdc-card__horizontal-block') isHostClass = true; | ||
} | ||
|
||
@Directive({ | ||
selector: '[mdc-card-title], mdc-card-title' | ||
}) | ||
export class CardTitleDirective { | ||
@Input() large: boolean = true; | ||
@HostBinding('class.mdc-card__title') isHostClass = true; | ||
@HostBinding('class.mdc-card__title--large') get classTitleLarge(): string { | ||
return this.large ? 'mdc-card__title--large' : ''; | ||
} | ||
} | ||
|
||
@Directive({ | ||
selector: '[mdc-card-subtitle], mdc-card-subtitle' | ||
}) | ||
export class CardSubtitleComponent { | ||
@HostBinding('class.mdc-card__subtitle') isHostClass = true; | ||
} | ||
|
||
@Directive({ | ||
selector: '[mdc-card-supporting-text], mdc-card-supporting-text' | ||
}) | ||
export class CardSupportingTextDirective { | ||
@HostBinding('class.mdc-card__supporting-text') isHostClass = true; | ||
} | ||
|
||
@Directive({ | ||
selector: '[mdc-card-media-item]' | ||
}) | ||
export class CardMediaItemDirective { | ||
@Input() size: number; | ||
@HostBinding('class.mdc-card__media-item') isHostClass = true; | ||
@HostBinding('class.mdc-card__media-item--1dot5x') get classMediaItemOne(): string { | ||
return this.size === 1 ? 'mdc-card__media-item--1x' : ''; | ||
} | ||
@HostBinding('class.mdc-card__media-item--1dot5x') get classMediaItemOneDotFive(): string { | ||
return this.size === 1.5 ? 'mdc-card__media-item--1dot5x' : ''; | ||
} | ||
@HostBinding('class.mdc-card__media-item--2x') get classMediaItemTwo(): string { | ||
return this.size === 2 ? 'mdc-card__media-item--2x' : ''; | ||
} | ||
@HostBinding('class.mdc-card__media-item--3x') get classMediaItemThree(): string { | ||
return this.size === 3 ? 'mdc-card__media-item--3x' : ''; | ||
} | ||
} | ||
|
||
@Component({ | ||
selector: 'mdc-card-media', | ||
template: '<ng-content></ng-content>', | ||
encapsulation: ViewEncapsulation.None | ||
}) | ||
export class CardMediaComponent { | ||
@HostBinding('class.mdc-card__media') isHostClass = true; | ||
} | ||
|
||
@Directive({ | ||
selector: 'mdc-card-actions' | ||
}) | ||
export class CardActionsDirective { | ||
@Input() vertical: boolean; | ||
@HostBinding('class.mdc-card__actions') isHostClass = true; | ||
@HostBinding('class.mdc-card__actions--vertical') get classCardActionVertical(): string { | ||
return this.vertical ? 'mdc-card__actions--vertical' : ''; | ||
} | ||
} | ||
|
||
@Directive({ | ||
selector: 'button[mdc-card-button], a[mdc-card-button]', | ||
providers: [Ripple] | ||
}) | ||
export class CardActionButtonDirective extends ButtonComponent { | ||
constructor( | ||
@Inject(Renderer2) renderer: Renderer2, | ||
@Inject(ElementRef) elementRef: ElementRef, | ||
@Inject(Ripple) ripple: Ripple) { | ||
super(renderer, elementRef, ripple); | ||
} | ||
} | ||
|
||
@Component({ | ||
selector: 'mdc-card', | ||
template: '<ng-content></ng-content>', | ||
encapsulation: ViewEncapsulation.None | ||
}) | ||
export class CardComponent { | ||
@Input() darkTheme: boolean; | ||
export class CardComponent implements AfterContentInit { | ||
@HostBinding('class.mdc-card') isHostClass = true; | ||
@HostBinding('class.mdc-card--theme-dark') get classDarkTheme(): string { | ||
return this.darkTheme ? 'mdc-card--theme-dark' : ''; | ||
@ContentChildren(CardActionButtonDirective, { descendants: true }) cardButtons: QueryList<CardActionButtonDirective>; | ||
|
||
constructor( | ||
private _renderer: Renderer2, | ||
public elementRef: ElementRef) { } | ||
|
||
ngAfterContentInit() { | ||
this.cardButtons.forEach((_) => { | ||
this._renderer.addClass(_.elementRef.nativeElement, 'mdc-card__action'); | ||
_.compact = true; | ||
}); | ||
} | ||
} |
Oops, something went wrong.