diff --git a/demo-shell/resources/i18n/en.json b/demo-shell/resources/i18n/en.json index 72d4d7f0fe..d325c43c5e 100644 --- a/demo-shell/resources/i18n/en.json +++ b/demo-shell/resources/i18n/en.json @@ -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": { diff --git a/demo-shell/src/app/app.routes.ts b/demo-shell/src/app/app.routes.ts index d7e73248ce..5cc082be0b 100644 --- a/demo-shell/src/app/app.routes.ts +++ b/demo-shell/src/app/app.routes.ts @@ -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 }, diff --git a/demo-shell/src/app/components/app-layout/app-layout.component.ts b/demo-shell/src/app/components/app-layout/app-layout.component.ts index 83008a3540..8b0dd73ab2 100644 --- a/demo-shell/src/app/components/app-layout/app-layout.component.ts +++ b/demo-shell/src/app/components/app-layout/app-layout.component.ts @@ -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' } ]; diff --git a/demo-shell/src/app/components/icons/icons.component.html b/demo-shell/src/app/components/icons/icons.component.html new file mode 100644 index 0000000000..7fd66b2bbe --- /dev/null +++ b/demo-shell/src/app/components/icons/icons.component.html @@ -0,0 +1,59 @@ +

Icons

+ +

Ligatures

+ + See more details here: + Font icons with ligatures + + +
+
Markup:
+
+    <adf-icon value="alarm"></adf-icon>
+
+ +
+
Result:
+ +
+ +

Named icons

+ + See more details here: + Named icons + + +
+
Code:
+
+    matIconRegistry.addSvgIconInNamespace(
+        'adf',
+        'move_file',
+        this.sanitizer.bypassSecurityTrustResourceUrl(
+            './assets/images/adf-move-file-24px.svg'
+        )
+    );
+
+ +
+
Markup:
+
+    <adf-icon value="adf:move_file"></adf-icon>
+
+ +
+
Result:
+ +
+ +

ADF Thumbnail Service

+
+
Markup:
+
+    <adf-icon value="image/gif"></adf-icon>
+
+ +
+
Result:
+ +
diff --git a/demo-shell/src/app/components/icons/icons.component.ts b/demo-shell/src/app/components/icons/icons.component.ts new file mode 100644 index 0000000000..ea55f94eb9 --- /dev/null +++ b/demo-shell/src/app/components/icons/icons.component.ts @@ -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' + ) + ); + } +} diff --git a/demo-shell/src/app/components/icons/icons.module.ts b/demo-shell/src/app/components/icons/icons.module.ts new file mode 100644 index 0000000000..c6f32d2f66 --- /dev/null +++ b/demo-shell/src/app/components/icons/icons.module.ts @@ -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 {} diff --git a/demo-shell/src/assets/images/adf-move-file-24px.svg b/demo-shell/src/assets/images/adf-move-file-24px.svg new file mode 100644 index 0000000000..bf39e51ccf --- /dev/null +++ b/demo-shell/src/assets/images/adf-move-file-24px.svg @@ -0,0 +1 @@ + diff --git a/docs/core/icon.component.md b/docs/core/icon.component.md new file mode 100644 index 0000000000..8da7cb1111 --- /dev/null +++ b/docs/core/icon.component.md @@ -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 + + + + + + + + +``` + +## 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 + +``` + +## Thumbnail Service + +You can also use icons registered with the ADF [ThumbnailService](thumbnail.service.md) + +```html + +``` diff --git a/lib/core/core.module.ts b/lib/core/core.module.ts index e2faca214a..219a9f5faf 100644 --- a/lib/core/core.module.ts +++ b/lib/core/core.module.ts @@ -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: [ { diff --git a/lib/core/icon/icon.component.html b/lib/core/icon/icon.component.html new file mode 100644 index 0000000000..ba5b060d27 --- /dev/null +++ b/lib/core/icon/icon.component.html @@ -0,0 +1,7 @@ + + + + + + {{ value }} + diff --git a/lib/core/icon/icon.component.scss b/lib/core/icon/icon.component.scss new file mode 100644 index 0000000000..ab73482199 --- /dev/null +++ b/lib/core/icon/icon.component.scss @@ -0,0 +1,4 @@ +.adf-icon { + display: inline-flex; + vertical-align: middle; +} diff --git a/lib/core/icon/icon.component.ts b/lib/core/icon/icon.component.ts new file mode 100644 index 0000000000..d3e553473a --- /dev/null +++ b/lib/core/icon/icon.component.ts @@ -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) {} +} diff --git a/lib/core/icon/icon.module.ts b/lib/core/icon/icon.module.ts new file mode 100644 index 0000000000..85792791e9 --- /dev/null +++ b/lib/core/icon/icon.module.ts @@ -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 {} diff --git a/lib/core/icon/index.ts b/lib/core/icon/index.ts new file mode 100644 index 0000000000..4c6ac1d58f --- /dev/null +++ b/lib/core/icon/index.ts @@ -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'; diff --git a/lib/core/icon/public-api.ts b/lib/core/icon/public-api.ts new file mode 100644 index 0000000000..57df8ebeb4 --- /dev/null +++ b/lib/core/icon/public-api.ts @@ -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'; diff --git a/lib/core/index.ts b/lib/core/index.ts index 8719abdd89..3b7ec04f81 100644 --- a/lib/core/index.ts +++ b/lib/core/index.ts @@ -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';