Skip to content

Commit

Permalink
feat(actionbar): add support a item class function
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarbeau committed May 31, 2019
1 parent 587d22c commit 86e164b
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 11 deletions.
4 changes: 3 additions & 1 deletion demo/src/locale/en.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"welcome": "Welcome to {{title}}"
"welcome": "Welcome to {{title}}",
"About": "About",
"Salutation": "Salutation"
}
4 changes: 3 additions & 1 deletion demo/src/locale/fr.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"welcome": "Bienvenue à {{title}}"
"welcome": "Bienvenue à {{title}}",
"About": "À propos",
"Salutation": "Salutation"
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

<ng-template *ngIf="!collapsed" ngFor let-action [ngForOf]="store.view.all$() | async">
<igo-actionbar-item
[ngClass]="itemClassFunc(action)"
color="accent"
[withTitle]="withTitle"
[withIcon]="withIcon"
Expand Down
26 changes: 20 additions & 6 deletions packages/common/src/lib/action/actionbar/actionbar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { ActionStore } from '../shared/store';
changeDetection: ChangeDetectionStrategy.OnPush
})
export class ActionbarComponent implements OnDestroy, OnChanges {

/**
* Reference to the ActionbarMode enum for use in the template
* @internal
Expand All @@ -45,7 +44,9 @@ export class ActionbarComponent implements OnDestroy, OnChanges {
toggleCollapseAction = {
id: 'actionbar_toggle',
icon: 'more_vert',
handler: () => { this.collapsed = !this.collapsed; }
handler: () => {
this.collapsed = !this.collapsed;
}
};

/**
Expand Down Expand Up @@ -103,29 +104,42 @@ export class ActionbarComponent implements OnDestroy, OnChanges {
* Class to add to the actionbar overlay
*/
@Input()
set overlayClass(value: string) { this._overlayClass = value; }
set overlayClass(value: string) {
this._overlayClass = value;
}
get overlayClass(): string {
return [this._overlayClass, 'igo-actionbar-overlay'].join(' ');
}
private _overlayClass = '';

/**
* Function to add class to item actionbar
*/
@Input() itemClassFunc: (action: Action) => { [key: string]: boolean };

/**
* @ignore
*/
@HostBinding('class.with-title')
get withTitleClass() { return this.withTitle; }
get withTitleClass() {
return this.withTitle;
}

/**
* @ignore
*/
@HostBinding('class.with-icon')
get withIconClass() { return this.withIcon; }
get withIconClass() {
return this.withIcon;
}

/**
* @ignore
*/
@HostBinding('class.horizontal')
get horizontalClass() { return this.horizontal; }
get horizontalClass() {
return this.horizontal;
}

constructor(private cdRef: ChangeDetectorRef) {}

Expand Down
3 changes: 2 additions & 1 deletion packages/common/src/lib/tool/toolbox/toolbox.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
[store]="actionStore"
[withIcon]="true"
[withTitle]="toolbarWithTitle"
[horizontal]="false">
[horizontal]="false"
[itemClassFunc]=actionBarItemClassFunc>
</igo-actionbar>

<div
Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/lib/tool/toolbox/toolbox.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ igo-actionbar:not(.with-title) {
box-shadow: 2px 0px 2px 0px #dddddd;
}

igo-actionbar ::ng-deep igo-list {
overflow: inherit;
igo-actionbar ::ng-deep igo-actionbar-item.tool-actived ::ng-deep mat-list-item {
background-color: #e0e0e0;
}

igo-dynamic-outlet {
Expand Down
13 changes: 13 additions & 0 deletions packages/common/src/lib/tool/toolbox/toolbox.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,19 @@ export class ToolboxComponent implements OnInit, OnDestroy {
return tool.options || {};
}

/**
* Get Action bar item class function
* @internal
*/
get actionBarItemClassFunc() {
return (tool: Tool) => {
if (!this.toolbox.activeTool$.value) {
return;
}
return { 'tool-actived': tool.id === this.toolbox.activeTool$.value.name };
};
}

/**
* Initialize an action store
* @param toolbar Toolbar
Expand Down

0 comments on commit 86e164b

Please sign in to comment.