Skip to content

Commit

Permalink
feat: Menu component (#333)
Browse files Browse the repository at this point in the history
* feat: add menu branch

* feat: 初始化菜单文档

* feat: menu基本样式

* feat: 递归menu

* feat: 折叠menu

* fix: button点击两次只触发一次的bug

* feat: menu animation

* feat: 菜单自定义ui

* fix: menu 动画bug

* style: 整理menu代码

* fix: 菜单状态bug

* feat: 完成菜单弹出交互

* fix: 使用takeUntilDestroyed

* docs: menu demos

* docs: menu api docs

* fix: fix docs

* fix: 嵌套menu bugs

* fix: menu item click

* feat: add menu branch

* feat: 初始化菜单文档

* feat: menu基本样式

* feat: 递归menu

* feat: 折叠menu

* fix: button点击两次只触发一次的bug

* feat: menu animation

* feat: 菜单自定义ui

* fix: menu 动画bug

* style: 整理menu代码

* fix: 菜单状态bug

* feat: 完成菜单弹出交互

* fix: 使用takeUntilDestroyed

* docs: menu demos

* docs: menu api docs

* fix: fix docs

* fix: 嵌套menu bugs

* fix: menu item click

* feat: 去掉icon动画,增加css var文档

* fix: 改文案

* fix: menu 折叠保持展开

* feat: menu样式优化,还原button组件代码

* feat: border-radius变量

* fix: menu细节优化

* fix:  menn优化

* fix(menu): 优化样式,submenu加上[cdkConnectedOverlayPush]

* fix(menu):  menu 调整 icon-gap

* fix(menu):  menu title 加省略号

* fix: 还原menu以外的代码,删掉log

* fix(app.component.scss): 删掉.devui-menu的class

* fix(devui/package.json) 删掉 @ngrx/component
  • Loading branch information
lycHub authored Nov 1, 2023
1 parent d4a7e98 commit d26efe4
Show file tree
Hide file tree
Showing 50 changed files with 2,275 additions and 157 deletions.
15 changes: 5 additions & 10 deletions devui-commons/src/sidebar/sidebar.component.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
<div class="sidebar-wrapper">
<d-search
class="sidebar-search-container"
[iconPosition]="'left'"
[styleType]="'gray'"
[isKeyupSearch]="true"
[placeholder]="searchPlaceholder"
(searchFn)="onSearch($event)"
></d-search>
<d-search class="sidebar-search-container" [iconPosition]="'left'" [styleType]="'gray'" [isKeyupSearch]="true"
[placeholder]="searchPlaceholder" (searchFn)="onSearch($event)"></d-search>
<ul class="sidebar-menu" [ngClass]="{'sidebar-menu-design': !sideMenuList.length}">
<li *ngFor="let item of sideMenuList" class="sidebar-menu-item" routerLinkActive="sidebar-menu-item-selected">
<a *ngIf="item.linkType === 'routerLink'" [routerLink]="item.path">
Expand All @@ -18,7 +12,8 @@
</li>
</ul>
<nav class="sidebar-nav">
<d-accordion [data]="componentsDataDisplay" [linkType]="linkType" [itemTemplate]="itemtemplate" (itemClick)="handleResetPage()" [linkDefaultTarget]="linkDefaultTarget"></d-accordion>
<d-accordion [data]="componentsDataDisplay" [linkType]="linkType" [itemTemplate]="itemtemplate"
(itemClick)="handleResetPage()" [linkDefaultTarget]="linkDefaultTarget"></d-accordion>
<ng-template #itemtemplate let-item="item">
{{ item.title }}
<d-tag *ngIf="item.newChange" [tag]="text.new" [labelStyle]="'update-custom'"></d-tag>
Expand All @@ -45,4 +40,4 @@
</a>
</div>
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion devui/button/button.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export type IButtonSize = 'lg' | 'md' | 'sm' | 'xs';
styleUrls: ['./button.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
preserveWhitespaces: false,
})
})
export class ButtonComponent implements AfterContentChecked {
@Input() id: string;
@Input() type: IButtonType = 'button';
Expand Down
134 changes: 68 additions & 66 deletions devui/devui.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { LoadingModule } from 'ng-devui/loading';
import { MentionModule } from 'ng-devui/mention';
import { ModalModule } from 'ng-devui/modal';
import { MultiAutoCompleteModule } from 'ng-devui/multi-auto-complete';
import { MenuModule } from 'ng-devui/menu';
import { NavSpriteModule } from 'ng-devui/nav-sprite';
import { PaginationModule } from 'ng-devui/pagination';
import { PanelModule } from 'ng-devui/panel';
Expand Down Expand Up @@ -134,74 +135,75 @@ export * from './version';
@NgModule({
imports: [],
exports: [
AccordionModule,
AlertModule,
AnchorModule,
AutoCompleteModule,
AvatarModule,
DCommonModule,
BadgeModule,
BackTopModule,
ButtonModule,
BreadcrumbModule,
CardModule,
CarouselModule,
CheckBoxModule,
DataTableModule,
DatepickerModule,
DragDropModule,
DrawerModule,
DropDownModule,
EditableSelectModule,
FormModule,
FullscreenModule,
ImagePreviewModule,
LoadingModule,
LayoutModule,
IconModule,
ModalModule,
MultiAutoCompleteModule,
PaginationModule,
PanelModule,
PopoverModule,
ProgressModule,
RadioModule,
RateModule,
SearchModule,
SelectModule,
StatusModule,
StickyModule,
TabsModule,
TagsModule,
TagsInputModule,
ToastModule,
ToggleModule,
TooltipModule,
TimeAxisModule,
TreeModule,
UploadModule,
UserGuideModule,
InputNumberModule,
SliderModule,
SplitterModule,
TreeSelectModule,
TransferModule,
TextInputModule,
TextareaModule,
WindowRefModule,
StepsGuideModule,
GanttModule,
QuadrantDiagramModule,
TimePickerModule,
CascaderModule,
CategorySearchModule,
DatepickerProModule,
MentionModule,
NavSpriteModule,
ReadTipModule
AccordionModule,
AlertModule,
AnchorModule,
AutoCompleteModule,
AvatarModule,
DCommonModule,
BadgeModule,
BackTopModule,
ButtonModule,
BreadcrumbModule,
CardModule,
CarouselModule,
CheckBoxModule,
DataTableModule,
DatepickerModule,
DragDropModule,
DrawerModule,
DropDownModule,
EditableSelectModule,
FormModule,
FullscreenModule,
ImagePreviewModule,
LoadingModule,
LayoutModule,
IconModule,
ModalModule,
MultiAutoCompleteModule,
MenuModule,
PaginationModule,
PanelModule,
PopoverModule,
ProgressModule,
RadioModule,
RateModule,
SearchModule,
SelectModule,
StatusModule,
StickyModule,
TabsModule,
TagsModule,
TagsInputModule,
ToastModule,
ToggleModule,
TooltipModule,
TimeAxisModule,
TreeModule,
UploadModule,
UserGuideModule,
InputNumberModule,
SliderModule,
SplitterModule,
TreeSelectModule,
TransferModule,
TextInputModule,
TextareaModule,
WindowRefModule,
StepsGuideModule,
GanttModule,
QuadrantDiagramModule,
TimePickerModule,
CascaderModule,
CategorySearchModule,
DatepickerProModule,
MentionModule,
NavSpriteModule,
ReadTipModule
],
declarations: [],
})
})
export class DevUIModule {
static forRoot(): ModuleWithProviders<DevUIModule> {
return {
Expand Down
30 changes: 30 additions & 0 deletions devui/menu/demo/auto-expand/auto-expand.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<div class="demo-menu" style="width: 256px">
<div d-menu>
<ng-container *ngFor="let m of menus; trackBy: trackByMenu">
<div
d-sub-menu
[title]="m.name"
[icon]="m.icon"
[open]="openKeys.includes(m.key)"
(openChange)="openChange($event, m.key)"
*ngIf="m.children?.length; else leafTpl"
>
<div
d-menu-item
(itemClick)="itemClick(item.key)"
[active]="item.key === activeKey"
*ngFor="let item of m.children; trackBy: trackByMenu"
>
<d-icon class="devui-menu-item-icon" icon="icon-op-list" />
<span class="devui-menu-item-name">{{ item.name }}</span>
</div>
</div>
<ng-template #leafTpl>
<div d-menu-item (itemClick)="itemClick(m.key)" [active]="m.key === activeKey">
<d-icon class="devui-menu-item-icon" icon="icon-op-list" />
<span class="devui-menu-item-name over-flow-ellipsis">{{ m.name }}</span>
</div>
</ng-template>
</ng-container>
</div>
</div>
108 changes: 108 additions & 0 deletions devui/menu/demo/auto-expand/auto-expand.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { MenuItemType } from 'ng-devui/menu';

const MENUS: MenuItemType[] = [
{
key: 'c-1',
icon: 'icon-more-func',
name: 'Content 1 (as a leaf menu)'
},
{
key: 'c-2',
name: 'Content 2 (as a parent menu, has children)',
icon: 'icon-more-func',
children: [
{
key: 'c-2-1',
name: 'Content 2 Child 1'
},
{
key: 'c-2-2',
name: 'Content 2 Child 2'
},
{
key: 'c-2-3',
name: 'Content 2 Child 3'
},
]
}, {
key: 'c-3',
name: 'Content 3 (as a parent menu, has children)',
icon: 'icon-more-func',
children: [
{
key: 'c-3-1',
name: 'Content 3 Child 1'
},
{
key: 'c-3-2',
name: 'Content 3 Child 2',
},
{
key: 'c-3-3',
name: 'Content 3 Child 3',
},
{
key: 'c-3-4',
name: 'Content 3 Child 4',
},
]
},
{
key: 'c-4',
icon: 'icon-more-func',
name: 'Content 4 (as a leaf menu)',
}
];

function findAllParent(source: MenuItemType[], key: string) {
const result: string[] = [];
const loop = (list: MenuItemType[]) => {
for (const item of list) {
if (item.key === key) {
// parentKeys.unshift(key);
return true;
}
if (item.children?.length) {
const t = loop(item.children);
if (t) {
result.unshift(item.key);
return true;
}
}
}
};
loop(source);
return result;
}


@Component({
selector: 'd-auto-expand',
templateUrl: './auto-expand.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AutoExpandComponent implements OnInit {
menus = MENUS;
openKeys: string[] = [];
activeKey = 'c-3-2';

openChange(open: boolean, key: string) {
if (open) {
this.openKeys.push(key);
} else {
this.openKeys = this.openKeys.filter(item => item !== key);
}
}

ngOnInit() {
this.openKeys = findAllParent(this.menus, this.activeKey);
}
itemClick(key: string) {
this.activeKey = key;
}

trackByMenu(_: number, item: MenuItemType) {
return item.key;
}
}
32 changes: 32 additions & 0 deletions devui/menu/demo/basic/basic.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<div class="demo-menu" style="width: 256px">
<div d-menu (menuItemClick)="menuItemClick($event)">
<ng-container *ngFor="let m of menus; trackBy: trackByMenu">
<div
d-sub-menu
[title]="m.name"
[icon]="m.icon"
[disabled]="disabledKeys.includes(m.key)"
[open]="openKeys.includes(m.key)"
(openChange)="openChange($event, m.key)"
*ngIf="m.children?.length; else leafTpl"
>
<div
d-menu-item
[disabled]="disabledKeys.includes(item.key)"
(itemClick)="itemClick(item.key)"
[active]="item.key === activeKey"
*ngFor="let item of m.children; trackBy: trackByMenu"
>
<d-icon class="devui-menu-item-icon" icon="icon-op-list" />
<span class="devui-menu-item-name over-flow-ellipsis">{{ item.name }}</span>
</div>
</div>
<ng-template #leafTpl>
<div d-menu-item (itemClick)="itemClick(m.key)" [active]="m.key === activeKey" [disabled]="disabledKeys.includes(m.key)">
<d-icon class="devui-menu-item-icon" icon="icon-op-list" />
<span class="devui-menu-item-name over-flow-ellipsis">{{ m.name }}</span>
</div>
</ng-template>
</ng-container>
</div>
</div>
Loading

0 comments on commit d26efe4

Please sign in to comment.