my-lib/list/list-item/list-item.ts
encapsulation | ViewEncapsulation.None |
selector | list-item,[listItem] |
templateUrl | ./list-item.html |
Properties |
Methods |
Inputs |
Outputs |
HostListeners |
Accessors |
constructor(ele: ElementRef, render: Renderer2)
|
||||||||||||
Defined in my-lib/list/list-item/list-item.ts:87
|
||||||||||||
Parameters :
|
arrow
|
|
Defined in my-lib/list/list-item/list-item.ts:65
|
bottom
|
Type: |
Defined in my-lib/list/list-item/list-item.ts:48
|
disabled
|
Type: |
Defined in my-lib/list/list-item/list-item.ts:28
|
error
|
Type: |
Defined in my-lib/list/list-item/list-item.ts:33
|
extra
|
Type: |
Defined in my-lib/list/list-item/list-item.ts:58
|
middle
|
Type: |
Defined in my-lib/list/list-item/list-item.ts:43
|
multiple
|
|
Defined in my-lib/list/list-item/list-item.ts:22
|
thumb
|
Type: |
Defined in my-lib/list/list-item/list-item.ts:54
|
top
|
Type: |
Defined in my-lib/list/list-item/list-item.ts:38
|
onClick
|
$event type: EventEmitter<any>
|
Defined in my-lib/list/list-item/list-item.ts:72
|
click |
Arguments : '$event'
|
click(e: )
|
Defined in my-lib/list/list-item/list-item.ts:75
|
touchend |
Arguments : '$event'
|
touchend()
|
Defined in my-lib/list/list-item/list-item.ts:85
|
touchstart |
Arguments : '$event'
|
touchstart(e: )
|
Defined in my-lib/list/list-item/list-item.ts:80
|
initRipple |
initRipple()
|
Defined in my-lib/list/list-item/list-item.ts:98
|
Returns :
void
|
setItemActive | ||||||||
setItemActive(isTrue?: boolean)
|
||||||||
Defined in my-lib/list/list-item/list-item.ts:119
|
||||||||
Parameters :
Returns :
void
|
_arrow |
_arrow:
|
Type : string
|
Defined in my-lib/list/list-item/list-item.ts:63
|
_multiple |
_multiple:
|
Type : boolean
|
Default value : false
|
Defined in my-lib/list/list-item/list-item.ts:20
|
_thumb |
_thumb:
|
Type : string
|
Defined in my-lib/list/list-item/list-item.ts:52
|
brief |
brief:
|
Type : TemplateRef<any>
|
Decorators : ContentChild
|
Defined in my-lib/list/list-item/list-item.ts:18
|
listRipple |
listRipple:
|
Type : ListRippleDirective
|
Decorators : ViewChild
|
Defined in my-lib/list/list-item/list-item.ts:71
|
thumbRef |
thumbRef:
|
Type : TemplateRef<any>
|
Decorators : ContentChild
|
Defined in my-lib/list/list-item/list-item.ts:17
|
multiple |
setmultiple(val: )
|
Defined in my-lib/list/list-item/list-item.ts:22
|
disabled |
setdisabled(val: any)
|
Defined in my-lib/list/list-item/list-item.ts:28
|
error |
seterror(val: any)
|
Defined in my-lib/list/list-item/list-item.ts:33
|
top |
settop(val: any)
|
Defined in my-lib/list/list-item/list-item.ts:38
|
middle |
setmiddle(val: any)
|
Defined in my-lib/list/list-item/list-item.ts:43
|
bottom |
setbottom(val: any)
|
Defined in my-lib/list/list-item/list-item.ts:48
|
thumb |
setthumb(val: string)
|
Defined in my-lib/list/list-item/list-item.ts:54
|
extraType |
getextraType()
|
Defined in my-lib/list/list-item/list-item.ts:59
|
arrow |
setarrow(val: )
|
Defined in my-lib/list/list-item/list-item.ts:65
|
import {
ViewEncapsulation, Component, HostBinding, Input,
ChangeDetectorRef, OnChanges, SimpleChanges,
ElementRef, Renderer2, ContentChild, TemplateRef,
HostListener, ViewChild, EventEmitter, Output
} from '@angular/core';
import { fromEvent, isMeepoTrue, merge } from 'meepo-utils';
import { listPrefixCls } from '../var';
import { Antd } from '../../antd';
import { ListRippleDirective } from '../list-ripple/list-ripple';
@Component({
selector: 'list-item,[listItem]',
templateUrl: './list-item.html',
encapsulation: ViewEncapsulation.None
})
export class ListItemComponent extends Antd {
@ContentChild('thumb') thumbRef: TemplateRef<any>;
@ContentChild('brief') brief: TemplateRef<any>;
_multiple: boolean = false;
@Input()
set multiple(val) {
this._multiple = this.isMeepoTrue(val);
this.addToClass('-multiple', isMeepoTrue(val));
}
@Input()
set disabled(val: any) {
this.addToClass('-disabled', isMeepoTrue(val));
}
@Input()
set error(val: any) {
this.addToClass('-error', isMeepoTrue(val));
}
@Input()
set top(val: any) {
this.addToClass('-top', isMeepoTrue(val));
}
@Input()
set middle(val: any) {
this.addToClass('-middle', isMeepoTrue(val));
}
@Input()
set bottom(val: any) {
this.addToClass('-bottom', isMeepoTrue(val));
}
_thumb: string;
@Input()
set thumb(val: string) {
this._thumb = val;
}
@Input() extra: string | TemplateRef<any>;
get extraType() {
return typeof this.extra;
}
_arrow: string;
@Input()
set arrow(val: 'horizontal' | 'up' | 'down' | 'empty') {
val = val || 'horizontal';
this._arrow = val;
}
// new
@ViewChild(ListRippleDirective) listRipple: ListRippleDirective;
@Output() onClick: EventEmitter<any> = new EventEmitter();
@HostListener('click', ['$event'])
click(e) {
this.onClick.emit();
}
@HostListener('touchstart', ['$event'])
touchstart(e) {
this.setItemActive(true);
}
@HostListener('touchend', ['$event'])
touchend() {
this.setItemActive(false);
}
constructor(
ele: ElementRef,
render: Renderer2
) {
super(ele, render, 'list-item');
this.addToClass('-middle', true);
this.initRipple();
}
initRipple() {
const start$ = merge(
fromEvent(this.ele.nativeElement, 'mousedown'),
fromEvent(this.ele.nativeElement, 'touchstart')
);
start$
.map((e: any) => {
const Item = this.ele.nativeElement;
const ClientRect = e.currentTarget.getBoundingClientRect();
const res = this._getPosition(e);
const pointX = res.y - ClientRect.left - Item.offsetWidth / 2;
const pointY = res.y - ClientRect.top - Item.offsetWidth / 2;
return { x: pointX, y: pointY }
})
.subscribe(res => {
const Item = this.ele.nativeElement;
const RippleWidth = Math.max(Item.offsetHeight, Item.offsetWidth);
this.listRipple && this.listRipple.setAnimate(res, RippleWidth);
});
}
setItemActive(isTrue?: boolean) {
this.addToClass('-active', isTrue);
}
}
<div class="{{_name}}-thumb" *ngIf="_thumb && !thumbRef">
<img [src]="_thumb" />
</div>
<ng-container *ngIf="thumbRef">
<div class="{{_name}}-thumb">
<ng-container *ngTemplateOutlet="thumbRef"></ng-container>
</div>
</ng-container>
<div class="am-list-line" [class.am-list-line-multiple]="_multiple">
<div class="{{_name}}-content">
<ng-content></ng-content>
<div class="{{_name}}-brief" *ngIf="brief">
<ng-container *ngTemplateOutlet="brief"></ng-container>
</div>
</div>
<div class="{{_name}}-extra" *ngIf="extra && extraType === 'string'">
{{extra}}
</div>
<div class="{{_name}}-extra" *ngIf="extra && extraType !== 'string'">
<ng-container *ngTemplateOutlet="extra"></ng-container>
</div>
<div [listArrow]="_arrow"></div>
</div>
<div listRipple style="display: none;"></div>