[ADF-3874] icon component (#4112)

* adf-icon component

* demo shell example page

* add docs

* integration with thumbnail service
This commit is contained in:
Denys Vuika 2019-01-08 15:08:06 +00:00 committed by Eugenio Romano
parent 96e16fb046
commit 7dde329d81
16 changed files with 370 additions and 3 deletions

View File

@ -88,7 +88,8 @@
"SEARCH_CREATED_BY": "Created By",
"SEARCH_SERVICE_APPROACH": "Check this to disable the input property and configure using the service",
"HEADER_DATA": "Header Data",
"TREE_VIEW": "Tree View"
"TREE_VIEW": "Tree View",
"ICONS": "Icons"
},
"TRASHCAN": {
"ACTIONS": {

View File

@ -314,6 +314,10 @@ export const appRoutes: Routes = [
path: 'about',
loadChildren: 'app/components/about/about.module#AppAboutModule'
},
{
path: 'icons',
loadChildren: './components/icons/icons.module#AppIconsModule'
},
{ path: 'form', component: FormComponent },
{ path: 'form-list', component: FormListComponent },
{ path: 'form-loading', component: FormLoadingComponent },

View File

@ -59,6 +59,7 @@ export class AppLayoutComponent implements OnInit {
/* cspell:disable-next-line */
{ href: '/overlay-viewer', icon: 'pageview', title: 'APP_LAYOUT.OVERLAY_VIEWER' },
{ href: '/treeview', icon: 'nature', title: 'APP_LAYOUT.TREE_VIEW' },
{ href: '/icons', icon: 'tag_faces', title: 'APP_LAYOUT.ICONS' },
{ href: '/about', icon: 'info_outline', title: 'APP_LAYOUT.ABOUT' }
];

View File

@ -0,0 +1,59 @@
<h1>Icons</h1>
<h2>Ligatures</h2>
<small>
See more details here:
<a href="https://material.angular.io/components/icon/overview#font-icons-with-ligatures">Font icons with ligatures</a>
</small>
<div>
<div><strong>Markup:</strong></div>
<pre>
&lt;adf-icon value="alarm"&gt;&lt;/adf-icon&gt;</pre>
</div>
<div>
<div><strong>Result:</strong></div>
<adf-icon value="alarm"></adf-icon>
</div>
<h2>Named icons</h2>
<small>
See more details here:
<a href="https://material.angular.io/components/icon/overview#named-icons">Named icons</a>
</small>
<div>
<div><strong>Code:</strong></div>
<pre>
matIconRegistry.addSvgIconInNamespace(
'adf',
'move_file',
this.sanitizer.bypassSecurityTrustResourceUrl(
'./assets/images/adf-move-file-24px.svg'
)
);</pre>
</div>
<div>
<div><strong>Markup:</strong></div>
<pre>
&lt;adf-icon value="adf:move_file"&gt;&lt;/adf-icon&gt;</pre>
</div>
<div>
<div><strong>Result:</strong></div>
<adf-icon value="adf:move_file"></adf-icon>
</div>
<h2>ADF Thumbnail Service</h2>
<div>
<div><strong>Markup:</strong></div>
<pre>
&lt;adf-icon value="image/gif"&gt;&lt;/adf-icon&gt;</pre>
</div>
<div>
<div><strong>Result:</strong></div>
<adf-icon value="image/gif"></adf-icon>
</div>

View File

@ -0,0 +1,41 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Component, OnInit } from '@angular/core';
import { MatIconRegistry } from '@angular/material';
import { DomSanitizer } from '@angular/platform-browser';
@Component({
selector: 'app-icons-demo',
templateUrl: './icons.component.html'
})
export class IconsComponent implements OnInit {
constructor(
private matIconRegistry: MatIconRegistry,
private sanitizer: DomSanitizer
) {}
ngOnInit() {
this.matIconRegistry.addSvgIconInNamespace(
'adf',
'move_file',
this.sanitizer.bypassSecurityTrustResourceUrl(
'./assets/images/adf-move-file-24px.svg'
)
);
}
}

View File

@ -0,0 +1,39 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { CommonModule } from '@angular/common';
import { CoreModule } from '@alfresco/adf-core';
import { IconsComponent } from './icons.component';
const routes: Routes = [
{
path: '',
component: IconsComponent
}
];
@NgModule({
imports: [
CommonModule,
CoreModule.forChild(),
RouterModule.forChild(routes)
],
declarations: [IconsComponent]
})
export class AppIconsModule {}

View File

@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg width="100%" height="100%" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:1.41421;"><g id="Artboard_1"><g id="Page_1"><rect id="Fill_1" x="0" y="0" width="24" height="24" style="fill:none;"/><path id="Fill_2" d="M20,20l-16,0c-1.097,0 -2,-0.903 -2,-2l0.01,-12c0,-1.093 0.897,-1.995 1.99,-2l6,0l2,2l8,0c1.097,0 2,0.903 2,2l0,10c0,1.097 -0.903,2 -2,2Zm-9,-9l0,4l4,0l0,2l4,-4l-4,-4l0,2l-4,0Z" style="fill-rule:nonzero;"/></g></g></svg>

After

Width:  |  Height:  |  Size: 794 B

View File

@ -0,0 +1,77 @@
# [Icon Component](../../lib/core/icon/icon.component.ts "Defined in icon.component.ts")
Provides universal way of rendering registered and named icons.
## Contents
- [Basic usage](#basic-usage)
- [Class members](#class-members)
- [Properties](#properties)
- [Named icons](#named-icons)
## Basic usage
```html
<!-- Font ligature -->
<adf-icon value="alert"></adf-icon>
<!-- ADF Thumbnail Service -->
<adf-icon value="image/png"></adf-icon>
<!-- Custom icon from MatIconRegistry -->
<adf-icon value="my-company:my-icon"></adf-icon>
```
## Class members
### Properties
| Name | Type | Default value | Description |
| ---- | ---- | ------------- | ----------- |
| value | `string` | | Icon value, can be either ligature name or custom icon in the format `[namespace]:[name]` |
## Named icons
You can register custom SVG files as named icons in the format `[namespace]:[name]`.
Example below shows how to register a new icon named `adf:move_file`
that points to an external file within the `assets` folder.
```ts
import { Component, OnInit } from '@angular/core';
import { MatIconRegistry } from '@angular/material';
import { DomSanitizer } from '@angular/platform-browser';
@Component({...})
export class AppComponent implements OnInit {
constructor(
private matIconRegistry: MatIconRegistry,
private sanitizer: DomSanitizer
) {}
ngOnInit() {
this.matIconRegistry.addSvgIconInNamespace(
'adf',
'move_file',
this.sanitizer.bypassSecurityTrustResourceUrl(
'./assets/images/adf-move-file-24px.svg'
)
);
}
}
```
In the HTML you can now use it like in the following snippet:
```html
<adf-icon value="adf:move_file"></adf-icon>
```
## Thumbnail Service
You can also use icons registered with the ADF [ThumbnailService](thumbnail.service.md)
```html
<adf-icon value="image/gif"></adf-icon>
```

View File

@ -54,6 +54,7 @@ import { TranslateLoaderService } from './services/translate-loader.service';
import { TranslationService } from './services/translation.service';
import { startupServiceFactory } from './services/startup-service-factory';
import { SortingPickerModule } from './sorting-picker/sorting-picker.module';
import { IconModule } from './icon/icon.module';
export function createTranslateLoader(http: HttpClient) {
return new TranslateLoaderService(http);
@ -89,6 +90,7 @@ export function createTranslateLoader(http: HttpClient) {
DataTableModule,
ButtonsMenuModule,
TemplateModule,
IconModule,
TranslateModule.forChild({
loader: {
provide: TranslateLoader,
@ -128,7 +130,8 @@ export function createTranslateLoader(http: HttpClient) {
TranslateModule,
ButtonsMenuModule,
TemplateModule,
SortingPickerModule
SortingPickerModule,
IconModule
]
})
export class CoreModuleLazy {
@ -163,6 +166,7 @@ export class CoreModuleLazy {
DataTableModule,
ButtonsMenuModule,
TemplateModule,
IconModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
@ -202,7 +206,8 @@ export class CoreModuleLazy {
TranslateModule,
ButtonsMenuModule,
TemplateModule,
SortingPickerModule
SortingPickerModule,
IconModule
],
providers: [
{

View File

@ -0,0 +1,7 @@
<ng-container *ngIf="isCustom; else: default">
<mat-icon [svgIcon]="value"></mat-icon>
</ng-container>
<ng-template #default>
<mat-icon>{{ value }}</mat-icon>
</ng-template>

View File

@ -0,0 +1,4 @@
.adf-icon {
display: inline-flex;
vertical-align: middle;
}

View File

@ -0,0 +1,55 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
Component,
Input,
ViewEncapsulation,
ChangeDetectionStrategy
} from '@angular/core';
import { ThumbnailService } from '../services/thumbnail.service';
@Component({
selector: 'adf-icon',
templateUrl: './icon.component.html',
styleUrls: ['./icon.component.scss'],
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
host: { class: 'adf-icon' }
})
export class IconComponent {
private _value = '';
private _isCustom = false;
get value(): string {
return this._value;
}
@Input()
set value(value: string) {
this._value = value || 'settings';
this._isCustom =
this._value.includes(':') ||
this.thumbnailService.mimeTypeIcons[value];
}
get isCustom(): boolean {
return this._isCustom;
}
constructor(private thumbnailService: ThumbnailService) {}
}

View File

@ -0,0 +1,35 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { NgModule } from '@angular/core';
import { IconComponent } from './icon.component';
import { MatIconModule } from '@angular/material';
import { CommonModule } from '@angular/common';
@NgModule({
imports: [
CommonModule,
MatIconModule
],
declarations: [
IconComponent
],
exports: [
IconComponent
]
})
export class IconModule {}

18
lib/core/icon/index.ts Normal file
View File

@ -0,0 +1,18 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from './public-api';

View File

@ -0,0 +1,19 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from './icon.component';
export * from './icon.module';

View File

@ -40,6 +40,7 @@ export * from './services/index';
export * from './directives/index';
export * from './clipboard/index';
export * from './dialogs/index';
export * from './icon/index';
export * from './utils/index';
export * from './interface/index';