Skip to content

Commit

Permalink
feat(module:list): add option class
Browse files Browse the repository at this point in the history
  • Loading branch information
ng-nest-moon committed Jul 31, 2023
1 parent 22bab47 commit bf3cb99
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/ng-nest/ui/dropdown/dropdown-portal.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
[data]="data"
(nodeClick)="nodeClick($event)"
[(ngModel)]="activatedId"
[optionClass]="optionClass"
(nodeMouseenter)="onEnter($event)"
(nodeMouseleave)="onLeave()"
></x-list>
Expand Down
11 changes: 10 additions & 1 deletion lib/ng-nest/ui/dropdown/dropdown-portal.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class XDropdownPortalComponent implements OnDestroy {
positionChange!: Subject<any>;
portalPositionChange: Subject<any> = new Subject();
node!: XDropdownNode;
portalNode?: XDropdownNode | null;
timeoutHide: any;
timespan = 200;
minWidth!: string | number;
Expand All @@ -70,6 +71,12 @@ export class XDropdownPortalComponent implements OnDestroy {
return XIsString(this.maxHeight) ? this.maxHeight : `${this.maxHeight}px`;
}

optionClass = (node: XDropdownNode) => {
return {
'x-dropdown-portal-hover': node.id === this.portalNode?.id
};
};

@HostListener('mouseenter') mouseenter() {
this.portalHover(true);
}
Expand Down Expand Up @@ -190,10 +197,11 @@ export class XDropdownPortalComponent implements OnDestroy {
if (this.timeoutHide) clearTimeout(this.timeoutHide);
if (this.portalAttached() && this.node?.id !== node.id) {
this.portal?.overlayRef?.dispose();
this.portalNode = null;
}
this.node = node;
if (!this.portalAttached()) {
console.log(this.node);
this.portalNode = node;
this.createPortal();
}
this.cdr.detectChanges();
Expand All @@ -203,6 +211,7 @@ export class XDropdownPortalComponent implements OnDestroy {
if (this.portalAttached()) {
this.timeoutHide = setTimeout(() => {
this.portal?.overlayRef?.dispose();
this.portalNode = null;
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ng-nest/ui/list/list-option.component.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div
class="x-list-option"
[ngClass]="classMap"
[ngClass]="optionClass ? getClassMap(optionClass(node!), classMap) : classMap"
[class.x-selected]="selected"
[class.x-disabled]="disabled"
[class.x-active]="active"
Expand Down
6 changes: 6 additions & 0 deletions lib/ng-nest/ui/list/list-option.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { XClassMap, XClearClass, XConfigService, XIsChange } from '@ng-nest/ui/c
export class XListOptionComponent extends XListOptionProperty implements Highlightable {
@HostBinding('attr.role') role = 'option';
classMap: XClassMap = {};

constructor(public elementRef: ElementRef<HTMLElement>, private cdr: ChangeDetectorRef, public configService: XConfigService) {
super();
}
Expand All @@ -34,6 +35,11 @@ export class XListOptionComponent extends XListOptionProperty implements Highlig
this.classMap[`${XListOptionPrefix}-${this.size}`] = this.size ? true : false;
}

getClassMap(optionClass: { [className: string]: boolean }, classMap: XClassMap) {
console.log(optionClass);
return { ...optionClass, ...classMap };
}

setActiveStyles(): void {
this.active = true;
this.activeChange.emit(this.active);
Expand Down
2 changes: 2 additions & 0 deletions lib/ng-nest/ui/list/list.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
[nodeTpl]="nodeTpl"
[selected]="node.selected"
[disabled]="node.disabled"
[optionClass]="optionClass"
[(active)]="node.active"
[icon]="node.icon"
[label]="node.label"
Expand Down Expand Up @@ -78,6 +79,7 @@
[selected]="node.selected"
[disabled]="node.disabled"
[(active)]="node.active"
[optionClass]="optionClass"
[icon]="node.icon"
[label]="node.label"
[leaf]="node.leaf"
Expand Down
10 changes: 10 additions & 0 deletions lib/ng-nest/ui/list/list.property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ export class XListProperty extends XControlValueAccessor<any> {
* @en_US Case-sensitive
*/
@Input() @XInputBoolean() @XWithConfig<XBoolean>(X_CONFIG_NAME, true) caseSensitive!: XBoolean;
/**
* @zh_CN 自定义数据对象样式
* @en_US Customize data object styles
*/
@Input() optionClass?: (node: XListNode) => { [className: string]: boolean };
/**
* @zh_CN Full event
* @en_US 全选事件
Expand Down Expand Up @@ -251,6 +256,11 @@ export class XListOptionProperty {
* @en_US active
*/
@Input() @XInputBoolean() active?: boolean;
/**
* @zh_CN 自定义数据对象样式
* @en_US Customize data object styles
*/
@Input() optionClass?: (node: XListNode) => { [className: string]: boolean };
/**
* @zh_CN 图标
* @en_US icon
Expand Down
2 changes: 1 addition & 1 deletion src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
export const environment = {
production: false,
layout: 'test',
defaultPage: 'anchor',
defaultPage: 'menu',
static: 'http://localhost:9494'
};

Expand Down
2 changes: 1 addition & 1 deletion src/main/test/modules/menu/leaf/leaf.component.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<x-menu [data]="data"> </x-menu>
<x-menu [data]="data" [portalMinWidth]="150" [trigger]="'click'"> </x-menu>

0 comments on commit bf3cb99

Please sign in to comment.