Support vertical orientation for toolbar (#2308)

* Support vertical orientation for toolbar modelview component

* Add tab support for each button

* Fix padding and simplify styles
This commit is contained in:
Kevin Cunnane
2018-08-23 10:54:20 -07:00
committed by GitHub
parent 7a30d535e8
commit 84da9d289b
6 changed files with 69 additions and 17 deletions

View File

@@ -5,32 +5,32 @@
import 'vs/css!./toolbarLayout'; import 'vs/css!./toolbarLayout';
import { import {
Component, Input, Inject, ChangeDetectorRef, forwardRef, ComponentFactoryResolver, Component, Input, Inject, ChangeDetectorRef, forwardRef,
ViewChild, ViewChildren, ElementRef, Injector, OnDestroy, QueryList, AfterViewInit ViewChild, ElementRef, OnDestroy, AfterViewInit
} from '@angular/core'; } from '@angular/core';
import { IComponent, IComponentDescriptor, IModelStore, ComponentEventType } from 'sql/parts/modelComponents/interfaces'; import { Orientation, ToolbarLayout } from 'sql/workbench/api/common/sqlExtHostTypes';
import { IComponent, IComponentDescriptor, IModelStore } from 'sql/parts/modelComponents/interfaces';
import { DashboardServiceInterface } from 'sql/parts/dashboard/services/dashboardServiceInterface.service';
import { ContainerBase } from 'sql/parts/modelComponents/componentBase'; import { ContainerBase } from 'sql/parts/modelComponents/componentBase';
import { ModelComponentWrapper } from 'sql/parts/modelComponents/modelComponentWrapper.component';
import { CommonServiceInterface } from 'sql/services/common/commonServiceInterface.service'; import { CommonServiceInterface } from 'sql/services/common/commonServiceInterface.service';
export interface ToolbarItemConfig { export interface ToolbarItemConfig {
title?: string; title?: string;
} }
class ToolbarItem { export class ToolbarItem {
constructor(public descriptor: IComponentDescriptor, public config: ToolbarItemConfig) { } constructor(public descriptor: IComponentDescriptor, public config: ToolbarItemConfig) { }
} }
@Component({ @Component({
selector: 'modelview-toolbarContainer', selector: 'modelview-toolbarContainer',
template: ` template: `
<div #container *ngIf="items" class="modelview-toolbar-container"> <div #container *ngIf="items" [class]="toolbarClass" >
<ng-container *ngFor="let item of items"> <ng-container *ngFor="let item of items">
<div class="modelview-toolbar-item" > <div class="modelview-toolbar-item" [title]="getItemTitle(item)" [style.paddingTop]="paddingTop" tabindex="0">
<div *ngIf="hasTitle(item)" class="modelview-toolbar-title" > <div *ngIf="shouldShowTitle(item)" class="modelview-toolbar-title" >
{{getItemTitle(item)}} {{getItemTitle(item)}}
</div> </div>
<div class="modelview-toolbar-component"> <div class="modelview-toolbar-component">
@@ -48,10 +48,13 @@ export default class ToolbarContainer extends ContainerBase<ToolbarItemConfig> i
@ViewChild('container', { read: ElementRef }) private _container: ElementRef; @ViewChild('container', { read: ElementRef }) private _container: ElementRef;
private _orientation: Orientation;
constructor( constructor(
@Inject(forwardRef(() => CommonServiceInterface)) private _commonService: CommonServiceInterface, @Inject(forwardRef(() => CommonServiceInterface)) private _commonService: CommonServiceInterface,
@Inject(forwardRef(() => ChangeDetectorRef)) changeRef: ChangeDetectorRef) { @Inject(forwardRef(() => ChangeDetectorRef)) changeRef: ChangeDetectorRef) {
super(changeRef); super(changeRef);
this._orientation = Orientation.Horizontal;
} }
ngOnInit(): void { ngOnInit(): void {
@@ -67,16 +70,39 @@ export default class ToolbarContainer extends ContainerBase<ToolbarItemConfig> i
/// IComponent implementation /// IComponent implementation
public setLayout(layout: any): void { public setLayout(layout: ToolbarLayout): void {
this._orientation = layout.orientation ? layout.orientation : Orientation.Horizontal;
this.layout(); this.layout();
} }
private getItemTitle(item: ToolbarItem): string { public getItemTitle(item: ToolbarItem): string {
let itemConfig = item.config; let itemConfig = item.config;
return itemConfig ? itemConfig.title : ''; return itemConfig ? itemConfig.title : '';
} }
public shouldShowTitle(item: ToolbarItem): boolean {
return this.hasTitle(item) && this.isHorizontal();
}
private hasTitle(item: ToolbarItem): boolean { private hasTitle(item: ToolbarItem): boolean {
return item && item.config && item.config.title !== undefined; return item && item.config && item.config.title !== undefined;
} }
public get paddingTop(): string {
return this.isHorizontal() ? '' : '10px';
}
public get toolbarClass(): string {
let classes = ['modelview-toolbar-container'];
if (this.isHorizontal()) {
classes.push('toolbar-horizontal');
} else {
classes.push('toolbar-vertical');
}
return classes.join(' ');
}
private isHorizontal(): boolean {
return this._orientation === Orientation.Horizontal;
}
} }

View File

@@ -5,17 +5,24 @@
.modelview-toolbar-container { .modelview-toolbar-container {
display: flex; display: flex;
padding: 15px;
justify-content: flex-start; justify-content: flex-start;
line-height: 1.4em; line-height: 1.4em;
white-space: nowrap; white-space: nowrap;
flex-wrap: wrap; flex-wrap: wrap;
}
.modelview-toolbar-container.toolbar-horizontal {
flex-direction: row;
border-bottom-width: .5px; border-bottom-width: .5px;
border-bottom-style: solid; border-bottom-style: solid;
box-sizing: border-box; box-sizing: border-box;
border-bottom-color: rgba(128, 128, 128, 0.35); border-bottom-color: rgba(128, 128, 128, 0.35);
} }
.modelview-toolbar-container.toolbar-vertical {
flex-direction: column;
}
.modelview-toolbar-container .modelview-toolbar-item { .modelview-toolbar-container .modelview-toolbar-item {
flex: 0 0; flex: 0 0;
flex-direction: row; flex-direction: row;

View File

@@ -75,8 +75,8 @@ declare module 'sqlops' {
export interface GroupBuilder extends ContainerBuilder<GroupContainer, GroupLayout, GroupItemLayout> { export interface GroupBuilder extends ContainerBuilder<GroupContainer, GroupLayout, GroupItemLayout> {
} }
export interface ToolbarBuilder extends ContainerBuilder<ToolbarContainer, any, any> { export interface ToolbarBuilder extends ContainerBuilder<ToolbarContainer, ToolbarLayout, any> {
withToolbarItems(components: ToolbarComponent[]): ContainerBuilder<ToolbarContainer, any, any>; withToolbarItems(components: ToolbarComponent[]): ContainerBuilder<ToolbarContainer, ToolbarLayout, any>;
/** /**
* Creates a collection of child components and adds them all to this container * Creates a collection of child components and adds them all to this container
@@ -307,7 +307,16 @@ declare module 'sqlops' {
export interface GroupContainer extends Container<GroupLayout, GroupItemLayout> { export interface GroupContainer extends Container<GroupLayout, GroupItemLayout> {
} }
export interface ToolbarContainer extends Container<any, any> {
export enum Orientation {
Horizontal = 'horizontal',
Vertical = 'vertial'
}
export interface ToolbarLayout {
orientation: Orientation;
}
export interface ToolbarContainer extends Container<ToolbarLayout, any> {
} }
/** /**

View File

@@ -285,6 +285,15 @@ export enum CardType {
Details = 'Details' Details = 'Details'
} }
export enum Orientation {
Horizontal = 'horizontal',
Vertical = 'vertial'
}
export interface ToolbarLayout {
orientation: Orientation;
}
export class TreeComponentItem extends TreeItem { export class TreeComponentItem extends TreeItem {
checked?: boolean; checked?: boolean;
} }

View File

@@ -333,7 +333,7 @@ class FormContainerBuilder extends ContainerBuilderImpl<sqlops.FormContainer, sq
} }
} }
class ToolbarContainerBuilder extends ContainerBuilderImpl<sqlops.ToolbarContainer, any, any> implements sqlops.ToolbarBuilder { class ToolbarContainerBuilder extends ContainerBuilderImpl<sqlops.ToolbarContainer, sqlops.ToolbarLayout, any> implements sqlops.ToolbarBuilder {
withToolbarItems(components: sqlops.ToolbarComponent[]): sqlops.ContainerBuilder<sqlops.ToolbarContainer, any, any> { withToolbarItems(components: sqlops.ToolbarComponent[]): sqlops.ContainerBuilder<sqlops.ToolbarContainer, any, any> {
this._component.itemConfigs = components.map(item => { this._component.itemConfigs = components.map(item => {
return this.convertToItemConfig(item); return this.convertToItemConfig(item);

View File

@@ -424,6 +424,7 @@ export function createApiFactory(
ui: ui, ui: ui,
StatusIndicator: sqlExtHostTypes.StatusIndicator, StatusIndicator: sqlExtHostTypes.StatusIndicator,
CardType: sqlExtHostTypes.CardType, CardType: sqlExtHostTypes.CardType,
Orientation: sqlExtHostTypes.Orientation,
SqlThemeIcon: sqlExtHostTypes.SqlThemeIcon, SqlThemeIcon: sqlExtHostTypes.SqlThemeIcon,
TreeComponentItem: sqlExtHostTypes.TreeComponentItem TreeComponentItem: sqlExtHostTypes.TreeComponentItem
}; };