Skip to content

Commit

Permalink
Cleanup and small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ky-one committed Jan 29, 2023
1 parent 95a34c5 commit 7f5c556
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AfterViewInit, Component, HostBinding, HostListener, Input, ViewChild } from '@angular/core';
import { AfterViewInit, Component, EventEmitter, HostBinding, HostListener, Input, Output, ViewChild } from '@angular/core';
import { BaseComponent } from '../../base/base.component';
import { Mouse } from '../../helpers/mouse';
import { animationFrameScheduler, fromEvent } from 'rxjs';
Expand Down Expand Up @@ -75,6 +75,14 @@ export class ContextMenuComponent extends BaseComponent implements AfterViewInit
@Input()
public margin = 5;

// eslint-disable-next-line @angular-eslint/no-output-rename
@Output('close')
public readonly onclose = new EventEmitter<void>();

// eslint-disable-next-line @angular-eslint/no-output-rename
@Output('open')
public readonly onopen = new EventEmitter<void>();

@ViewChild(MenuComponent)
public menu: MenuComponent;

Expand Down Expand Up @@ -137,10 +145,12 @@ export class ContextMenuComponent extends BaseComponent implements AfterViewInit
}
this.isVisible = true;
animationFrameScheduler.schedule(() => this.refreshPosition());
this.onopen.emit();
}

public close(): void {
this.isVisible = false;
this.onclose.emit();
}
}

6 changes: 6 additions & 0 deletions projects/mantic-ui/src/lib/helpers/date-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@
}
return left.getFullYear() === right.getFullYear() && left.getMonth() === right.getMonth() && left.getDate() === right.getDate();
}

public static today(): Date {
const today = new Date();
today.setUTCHours(0, 0, 0, 0);
return today;
}
}
5 changes: 5 additions & 0 deletions projects/mantic-ui/src/lib/helpers/math2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@
public static sum(values: (number | undefined)[] | undefined): number {
return values ? values.reduce((partialSum, a) => partialSum + (a ?? 0), 0) : 0;
}

public static round(value: number, decimals: number): number {
const factor = Math.pow(10, decimals);
return Math.round(value * factor) / factor;
}
}
3 changes: 2 additions & 1 deletion projects/mantic-ui/src/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export * from './lib/base/base.component';
export * from './lib/base/destroyable.component';
export * from './lib/base/destroyable.directive';
export * from './lib/base/destroyable';
export * from './lib/base/base.component';
export * from './lib/base/button-base.component';
export * from './lib/base/base.directive';
export * from './lib/base/invertible.component';
export * from './lib/components/animation/animation.component';
Expand Down Expand Up @@ -63,6 +63,7 @@ export * from './lib/components/grid/grid.component';
export * from './lib/components/header/header.component';
export * from './lib/components/icon-button/icon-button.component';
export * from './lib/components/icon/icon.component';
export * from './lib/components/icon/icon-size';
export * from './lib/components/info/info.component';
export * from './lib/components/image-upload/image-upload.component';
export * from './lib/components/input/text/input.component';
Expand Down
19 changes: 18 additions & 1 deletion src/app/examples/context-menu/context-menu.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ <h1 m-header>
Top-Left
<m-context-menu openOnLeftClick>
<m-context-menu-item (click)="show('Top-Left')">Top-Left</m-context-menu-item>
<m-context-menu-item icon="lock" (click)="show('Keep open')" keepOpen>Keep open</m-context-menu-item>
<m-context-menu-item icon="lock" keepOpen (click)="show('Keep open')">Keep open</m-context-menu-item>
<m-context-menu-item *ngIf="!isScrolling" icon="angle double down" (click)="isScrolling = true">Activate Scrolling</m-context-menu-item>
<m-context-menu-item *ngIf="isScrolling" icon="angle double up" (click)="isScrolling = false">Deactivate Scrolling</m-context-menu-item>
</m-context-menu>
Expand Down Expand Up @@ -147,4 +147,21 @@ <h1 m-header>
</m-flex>
</m-flex>
</m-tab>
<m-tab label="Events">
<m-example header="Open event" description="Occurs when the context menu opens">
<m-button>
Context Menu
<m-context-menu (open)="log('open')"></m-context-menu>
</m-button>
<m-example-code [code]="openEventCode"></m-example-code>
</m-example>
<m-example header="Close event" description="Occurs when the context menu closes">
<m-button>
Context Menu
<m-context-menu (close)="log('close')"></m-context-menu>
</m-button>
<m-example-code [code]="closeEventCode"></m-example-code>
</m-example>
<pre><ng-container *ngFor="let entry of logEntries">{{entry + '\n'}}</ng-container></pre>
</m-tab>
</m-tab-group>
5 changes: 5 additions & 0 deletions src/app/examples/context-menu/context-menu.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ m-flex {
align-items: center;
}
}

pre {
max-height: 400px;
overflow-y: auto;
}
8 changes: 8 additions & 0 deletions src/app/examples/context-menu/context-menu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,12 @@ this.contextMenu?.open();`;
public show(message: string): void {
alert(message);
}

protected readonly logEntries: string[] = [];
public openEventCode = `<m-context-menu (open)="log('open')"></m-context-menu>`;
public closeEventCode = `<m-context-menu (close)="log('close')"></m-context-menu>`;

protected log(eventName: string): void {
this.logEntries.push(eventName);
}
}

0 comments on commit 7f5c556

Please sign in to comment.