Skip to content

Commit

Permalink
feat(tooltip): initial commit for Tooltip (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
Enlcxx authored Nov 27, 2018
1 parent 8aff164 commit 9696883
Show file tree
Hide file tree
Showing 23 changed files with 328 additions and 9 deletions.
1 change: 1 addition & 0 deletions .package.conf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ components:
'@alyle/ui/badge': badge
'@alyle/ui/field': field
'@alyle/ui/snack-bar': snack-bar
'@alyle/ui/tooltip': tooltip
1 change: 1 addition & 0 deletions src/app/components/routes-app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class RoutesAppService {
{ route: 'resizing-cropping-images', name: 'Resizing & cropping' },
{ route: 'snack-bar', name: 'SnackBar' },
{ route: 'toolbar', name: 'Toolbar' },
{ route: 'tooltip', name: 'Tooltip' },
{ route: 'typography', name: 'Typography' }
]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<button ly-button
appearance="icon"
lyTooltip="Delete"
#_tooltip="lyTooltip">
<ly-icon>delete_forever</ly-icon>
</button>
<br />
<button ly-button (click)="_tooltip.toggle()">toggle</button>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { BasicTooltipComponent } from './basic-tooltip.component';

describe('BasicTooltipComponent', () => {
let component: BasicTooltipComponent;
let fixture: ComponentFixture<BasicTooltipComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ BasicTooltipComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(BasicTooltipComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Component } from '@angular/core';

@Component({
selector: 'aui-basic-tooltip',
templateUrl: './basic-tooltip.component.html'
})
export class BasicTooltipComponent { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { BasicTooltipModule } from './basic-tooltip.module';

describe('BasicTooltipModule', () => {
let basicTooltipModule: BasicTooltipModule;

beforeEach(() => {
basicTooltipModule = new BasicTooltipModule();
});

it('should create an instance', () => {
expect(basicTooltipModule).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { LyTooltipModule } from '@alyle/ui/tooltip';
import { LyButtonModule } from '@alyle/ui/button';
import { LyIconModule } from '@alyle/ui/icon';

import { BasicTooltipComponent } from './basic-tooltip.component';

@NgModule({
imports: [
CommonModule,
LyTooltipModule,
LyButtonModule,
LyIconModule
],
exports: [BasicTooltipComponent],
declarations: [BasicTooltipComponent]
})
export class BasicTooltipModule { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<h2 [lyTyp]="'display1'" gutter>Basic Tooltip</h2>
<demo-view path="docs/components/tooltip-demo/basic-tooltip">
<aui-basic-tooltip></aui-basic-tooltip>
</demo-view>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { TooltipDemoComponent } from './tooltip-demo.component';

describe('TooltipDemoComponent', () => {
let component: TooltipDemoComponent;
let fixture: ComponentFixture<TooltipDemoComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ TooltipDemoComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(TooltipDemoComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
14 changes: 14 additions & 0 deletions src/app/docs/components/tooltip-demo/tooltip-demo.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Component, OnInit } from '@angular/core';

@Component({
selector: 'aui-tooltip-demo',
templateUrl: './tooltip-demo.component.html'
})
export class TooltipDemoComponent implements OnInit {

constructor() { }

ngOnInit() {
}

}
13 changes: 10 additions & 3 deletions src/app/docs/docs.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ import { PaperWithColorModule } from './customization/paper-demo/paper-with-colo
/** Icon demo */
import { IconDemoComponent } from './components/icon-demo/icon-demo.component';
import { IconsModule } from './components/icon-demo/icons/icons.module';
import { TooltipDemoComponent } from './components/tooltip-demo/tooltip-demo.component';

/** Tooltip */
import { BasicTooltipModule } from './components/tooltip-demo/basic-tooltip/basic-tooltip.module';

@NgModule({
imports: [
Expand Down Expand Up @@ -118,7 +122,9 @@ import { IconsModule } from './components/icon-demo/icons/icons.module';
BasicPaperModule,
PaperWithColorModule,
/** Icon */
IconsModule
IconsModule,
/** Tooltip */
BasicTooltipModule
],
declarations: [
ThemingComponent,
Expand Down Expand Up @@ -147,8 +153,9 @@ import { IconsModule } from './components/icon-demo/icons/icons.module';
/** Paper */
PaperDemoComponent,
/** Icon */
IconDemoComponent

IconDemoComponent,
/** Tooltip */
TooltipDemoComponent
]
})
export class DocsModule { }
4 changes: 3 additions & 1 deletion src/app/docs/docs.routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ResponsiveDemoComponent } from './layout/responsive/responsive-demo.com
import { SnackBarDemoComponent } from './components/snack-bar-demo/snack-bar-demo.component';
import { PaperDemoComponent } from './customization/paper-demo/paper-demo.component';
import { IconDemoComponent } from './components/icon-demo/icon-demo.component';
import { TooltipDemoComponent } from './components/tooltip-demo/tooltip-demo.component';

const routes: Routes = [
/** layout */
Expand Down Expand Up @@ -48,7 +49,8 @@ const routes: Routes = [
{ path: 'field', component: FieldDemoComponent },
{ path: 'checkbox', component: CheckboxDemoComponent },
{ path: 'snack-bar', component: SnackBarDemoComponent },
{ path: 'icon', component: IconDemoComponent }
{ path: 'icon', component: IconDemoComponent },
{ path: 'tooltip', component: TooltipDemoComponent },
]
}
];
Expand Down
15 changes: 11 additions & 4 deletions src/lib/src/dom/overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class CreateFromTemplateRef implements OverlayFromTemplateRef {
constructor(
private _componentFactoryResolver: ComponentFactoryResolver,
private _appRef: ApplicationRef,
_templateRef: TemplateRef<any>,
_templateRef: TemplateRef<any> | string,
private _overlayContainer: LyOverlayContainer,
_context: any,
private _injector: Injector,
Expand Down Expand Up @@ -109,7 +109,7 @@ class CreateFromTemplateRef implements OverlayFromTemplateRef {
}
}

private _appendComponentToBody(type: TemplateRef<any> | Type<any>, context, injector: Injector) {
private _appendComponentToBody(type: TemplateRef<any> | Type<any> | string, context, injector: Injector) {
if (type instanceof TemplateRef) {
// Create a component reference from the component
const viewRef = this._viewRef = type.createEmbeddedView(context || {});
Expand All @@ -120,8 +120,11 @@ class CreateFromTemplateRef implements OverlayFromTemplateRef {

// Append DOM element to the body
this._overlayContainer._add(this._el);
} else if (typeof type === 'string') {
this._el.innerText = type;
this._overlayContainer._add(this._el);
} else {
this._compRef = this.generateComponent(type, injector);
this._compRef = this.generateComponent(type as Type<any>, injector);
this._el = this._compRef.location.nativeElement;
this._overlayContainer._add(this._el);
}
Expand All @@ -147,6 +150,10 @@ class CreateFromTemplateRef implements OverlayFromTemplateRef {
this._compRef.destroy();
this._overlayContainer._remove(this._el);
this._el = null;
} else if (this._el) {
// remove if content is string
this._overlayContainer._remove(this._el);
this._el = null;
}
if (this._compRefOverlayBackdrop) {
this._appRef.detachView(this._compRefOverlayBackdrop.hostView);
Expand Down Expand Up @@ -176,7 +183,7 @@ export class LyOverlay {
private _windowScroll: WindowScrollService
) { }

create(template: TemplateRef<any>, context?: any, config?: OverlayConfig): OverlayFromTemplateRef {
create(template: TemplateRef<any> | string, context?: any, config?: OverlayConfig): OverlayFromTemplateRef {
return new CreateFromTemplateRef(this._componentFactoryResolver, this._appRef, template, this._overlayContainer, context, this._injector, this._windowScroll, config);
}
}
2 changes: 2 additions & 0 deletions src/lib/src/theme/theme-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { TypographyVariables } from './variables/typography';
import { CheckboxVariables } from './variables/checkbox';
import { SnackBarVariables } from './variables/snack-bar';
import { ButtonVariables } from './variables/button';
import { TooltipVariables } from './variables/tooltip';

export const LY_THEME_GLOBAL_VARIABLES = new InjectionToken<PartialThemeVariables>('ly.theme.global.variables');
export const LY_THEME = new InjectionToken<ThemeConfig | ThemeConfig[]>('ly_theme_config');
Expand Down Expand Up @@ -108,6 +109,7 @@ export interface ThemeConfig {
checkbox: CheckboxVariables;
snackBar: SnackBarVariables;
button: ButtonVariables;
tooltip: TooltipVariables;
}

export type ThemeVariables = LyStyleUtils & ThemeConfig;
Expand Down
5 changes: 5 additions & 0 deletions src/lib/src/theme/variables/tooltip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { StyleContainer } from '../theme2.service';

export interface TooltipVariables {
root: StyleContainer;
}
6 changes: 6 additions & 0 deletions src/lib/themes/minima/dark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,11 @@ export class MinimaDark extends MinimaBase implements ThemeConfig {
color: 'rgba(0,0,0,.87)'
}
};
tooltip = {
root: {
background: 'rgba(250, 250, 250, 0.85)',
color: 'rgba(0,0,0,.87)'
}
};
// direction = Dir.rtl; // beta
}
6 changes: 6 additions & 0 deletions src/lib/themes/minima/light.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,10 @@ export class MinimaLight extends MinimaBase implements ThemeConfig {
color: 'rgba(255,255,255,.7)'
}
};
tooltip = {
root: {
background: 'rgba(50, 50, 50, 0.85)',
color: 'rgba(255,255,255,.7)'
}
};
}
1 change: 1 addition & 0 deletions src/lib/tooltip/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './public_api';
2 changes: 2 additions & 0 deletions src/lib/tooltip/public_api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './tooltip';
export * from './tooltip.module';
8 changes: 8 additions & 0 deletions src/lib/tooltip/tooltip.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { NgModule } from '@angular/core';
import { LyTooltip } from './tooltip';

@NgModule({
declarations: [LyTooltip],
exports: [LyTooltip]
})
export class LyTooltipModule { }
Loading

0 comments on commit 9696883

Please sign in to comment.