add animation when button is clicked and fix title in button (#2488)

* add animation similar to toolbar in vscode and fix title in button

* remove bur method in button
This commit is contained in:
Abbie Petchtes
2018-09-11 10:37:02 -07:00
committed by GitHub
parent 4ea13bdbc0
commit a5c537197c
7 changed files with 59 additions and 5 deletions

View File

@@ -518,7 +518,8 @@ export default class MainController implements vscode.Disposable {
let runButton = view.modelBuilder.button() let runButton = view.modelBuilder.button()
.withProperties({ .withProperties({
label: 'Run', label: 'Run',
iconPath: runIcon iconPath: runIcon,
title: 'Run title'
}).component(); }).component();
let monitorLightPath = vscode.Uri.file(path.join(__dirname, '..', 'media', 'monitor.svg')); let monitorLightPath = vscode.Uri.file(path.join(__dirname, '..', 'media', 'monitor.svg'));
@@ -530,7 +531,8 @@ export default class MainController implements vscode.Disposable {
let monitorButton = view.modelBuilder.button() let monitorButton = view.modelBuilder.button()
.withProperties({ .withProperties({
label: 'Monitor', label: 'Monitor',
iconPath: monitorIcon iconPath: monitorIcon,
title: 'Monitor title'
}).component(); }).component();
let toolbarModel = view.modelBuilder.toolbarContainer() let toolbarModel = view.modelBuilder.toolbarContainer()
.withToolbarItems([{ .withToolbarItems([{

View File

@@ -23,6 +23,18 @@ export class Button extends vsButton {
this.$el.style('outline-color', this.buttonFocusOutline ? this.buttonFocusOutline.toString() : null); this.$el.style('outline-color', this.buttonFocusOutline ? this.buttonFocusOutline.toString() : null);
this.$el.style('outline-width', '1px'); this.$el.style('outline-width', '1px');
}); });
this.$el.on(DOM.EventType.MOUSE_DOWN, (e) => {
const mouseEvent = e as MouseEvent;
if (!this.$el.hasClass('disabled') && mouseEvent.button === 0) {
this.$el.addClass('active');
}
});
this.$el.on([DOM.EventType.MOUSE_UP], (e) => {
DOM.EventHelper.stop(e);
this.$el.removeClass('active');
});
} }
public style(styles: IButtonStyles): void { public style(styles: IButtonStyles): void {

View File

@@ -13,11 +13,11 @@ import * as sqlops from 'sqlops';
import { ComponentWithIconBase } from 'sql/parts/modelComponents/componentWithIconBase'; import { ComponentWithIconBase } from 'sql/parts/modelComponents/componentWithIconBase';
import { IComponent, IComponentDescriptor, IModelStore, ComponentEventType } from 'sql/parts/modelComponents/interfaces'; import { IComponent, IComponentDescriptor, IModelStore, ComponentEventType } from 'sql/parts/modelComponents/interfaces';
import { attachButtonStyler } from 'sql/common/theme/styler'; import { attachButtonStyler } from 'sql/common/theme/styler';
import { Button } from 'sql/base/browser/ui/button/button';
import { SIDE_BAR_BACKGROUND, SIDE_BAR_TITLE_FOREGROUND } from 'vs/workbench/common/theme'; import { SIDE_BAR_BACKGROUND, SIDE_BAR_TITLE_FOREGROUND } from 'vs/workbench/common/theme';
import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService'; import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService';
import { focusBorder, foreground } from 'vs/platform/theme/common/colorRegistry'; import { focusBorder, foreground } from 'vs/platform/theme/common/colorRegistry';
import { Button } from 'sql/base/browser/ui/button/button';
import { Color } from 'vs/base/common/color'; import { Color } from 'vs/base/common/color';
@@ -101,6 +101,7 @@ export default class ButtonComponent extends ComponentWithIconBase implements IC
super.setProperties(properties); super.setProperties(properties);
this._button.enabled = this.enabled; this._button.enabled = this.enabled;
this._button.label = this.label; this._button.label = this.label;
this._button.title = this.title;
if (this.width) { if (this.width) {
this._button.setWidth(this.convertSize(this.width.toString())); this._button.setWidth(this.convertSize(this.width.toString()));
} }
@@ -165,4 +166,13 @@ export default class ButtonComponent extends ComponentWithIconBase implements IC
private setFileProperties(properties: sqlops.ButtonProperties, isFile: boolean): void { private setFileProperties(properties: sqlops.ButtonProperties, isFile: boolean): void {
properties.isFile = isFile; properties.isFile = isFile;
} }
private get title(): string {
return this.getPropertyOrDefault<sqlops.ButtonProperties, string>((props) => props.title, '');
}
private set title(newValue: string) {
this.setPropertyFromUI<sqlops.ButtonProperties, string>((properties, title) => { properties.title = title; }, newValue);
}
} }

View File

@@ -29,7 +29,7 @@ export class ToolbarItem {
template: ` template: `
<div #container *ngIf="items" [class]="toolbarClass" > <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" [title]="getItemTitle(item)" [style.paddingTop]="paddingTop" tabindex="0"> <div class="modelview-toolbar-item" [style.paddingTop]="paddingTop">
<div *ngIf="shouldShowTitle(item)" class="modelview-toolbar-title" > <div *ngIf="shouldShowTitle(item)" class="modelview-toolbar-title" >
{{getItemTitle(item)}} {{getItemTitle(item)}}
</div> </div>

View File

@@ -62,4 +62,12 @@
margin-right: 0.3em; margin-right: 0.3em;
background-position: 50% 50%; background-position: 50% 50%;
} }
.modelview-toolbar-container .modelview-toolbar-component modelview-button .monaco-text-button.active {
-ms-transform: scale(1.272019649, 1.272019649); /* 1.272019649 = √φ */
-webkit-transform: scale(1.272019649, 1.272019649);
-moz-transform: scale(1.272019649, 1.272019649);
-o-transform: scale(1.272019649, 1.272019649);
transform: scale(1.272019649, 1.272019649);
}

View File

@@ -561,6 +561,7 @@ declare module 'sqlops' {
label?: string; label?: string;
isFile?: boolean; isFile?: boolean;
fileContent?: string; fileContent?: string;
title?: string;
} }
export interface LoadingComponentProperties { export interface LoadingComponentProperties {
@@ -662,8 +663,22 @@ declare module 'sqlops' {
} }
export interface ButtonComponent extends Component, ButtonProperties { export interface ButtonComponent extends Component, ButtonProperties {
/**
* The label for the button
*/
label: string; label: string;
/**
* The title for the button. This title will show when it hovers
*/
title: string;
/**
* Icon Path for the button.
*/
iconPath: string | vscode.Uri | { light: string | vscode.Uri; dark: string | vscode.Uri }; iconPath: string | vscode.Uri | { light: string | vscode.Uri; dark: string | vscode.Uri };
/**
* An event called when the button is clicked
*/
onDidClick: vscode.Event<any>; onDidClick: vscode.Event<any>;
} }

View File

@@ -1103,6 +1103,13 @@ class ButtonWrapper extends ComponentWrapper implements sqlops.ButtonComponent {
this.setProperty('iconPath', v); this.setProperty('iconPath', v);
} }
public get title(): string {
return this.properties['title'];
}
public set title(v: string) {
this.setProperty('title', v);
}
public get onDidClick(): vscode.Event<any> { public get onDidClick(): vscode.Event<any> {
let emitter = this._emitterMap.get(ComponentEventType.onDidClick); let emitter = this._emitterMap.get(ComponentEventType.onDidClick);
return emitter && emitter.event; return emitter && emitter.event;