|
@@ -4,76 +4,29 @@
|
|
|
import React from 'react';
|
|
|
import { classes } from 'typestyle/lib';
|
|
|
|
|
|
+import { Icon, defaultIcons } from './icon';
|
|
|
import { camelize } from '../utils';
|
|
|
import { IIconStyle, iconStyle, iconStyleFlat } from '../style/icon';
|
|
|
|
|
|
-/**
|
|
|
- * To add an icon to the defaultIconRegistry requires two lines of code:
|
|
|
- * 1. import the icon's .svg
|
|
|
- * 2. add a relevant entry to _defaultIcons
|
|
|
- */
|
|
|
-
|
|
|
-/* tslint:disable */
|
|
|
import badSvg from '../../style/icons/bad.svg';
|
|
|
-import jupyterFaviconSvg from '../../style/icons/jupyter-favicon.svg';
|
|
|
-
|
|
|
-// filetype icons
|
|
|
-import html5Svg from '../../style/icons/filetype/html5.svg';
|
|
|
-
|
|
|
-// statusbar icons
|
|
|
-import kernelSvg from '../../style/icons/statusbar/kernel.svg';
|
|
|
-import lineFormSvg from '../../style/icons/statusbar/line-form.svg';
|
|
|
-import notTrustedSvg from '../../style/icons/statusbar/not-trusted.svg';
|
|
|
-import statusBarSvg from '../../style/icons/statusbar/status-bar.svg';
|
|
|
-import terminalSvg from '../../style/icons/statusbar/terminal.svg';
|
|
|
-import trustedSvg from '../../style/icons/statusbar/trusted.svg';
|
|
|
-
|
|
|
-// sidebar icons
|
|
|
-import buildSvg from '../../style/icons/sidebar/build.svg'; // originally ic-build-24px.svg
|
|
|
-import extensionSvg from '../../style/icons/sidebar/extension.svg'; // originally ic-extension-24px.svg
|
|
|
-import folderSvg from '../../style/icons/sidebar/folder.svg'; // originally ic-folder-24px.svg
|
|
|
-import paletteSvg from '../../style/icons/sidebar/palette.svg'; // originally ic-palette-24px.svg
|
|
|
-import runningSvg from '../../style/icons/sidebar/running.svg'; // originally stop-circle.svg
|
|
|
-import tabSvg from '../../style/icons/sidebar/tab.svg'; // originally ic-tab-24px.svg
|
|
|
-
|
|
|
-const _defaultIcons: ReadonlyArray<IconRegistry.IModel> = [
|
|
|
- { name: 'jupyter-favicon', svg: jupyterFaviconSvg },
|
|
|
-
|
|
|
- { name: 'html5', svg: html5Svg },
|
|
|
-
|
|
|
- { name: 'kernel', svg: kernelSvg },
|
|
|
- { name: 'line-form', svg: lineFormSvg },
|
|
|
- { name: 'not-trusted', svg: notTrustedSvg },
|
|
|
- { name: 'status-bar', svg: statusBarSvg },
|
|
|
- { name: 'terminal', svg: terminalSvg },
|
|
|
- { name: 'trusted', svg: trustedSvg },
|
|
|
-
|
|
|
- { name: 'build', svg: buildSvg },
|
|
|
- { name: 'extension', svg: extensionSvg },
|
|
|
- { name: 'folder', svg: folderSvg },
|
|
|
- { name: 'palette', svg: paletteSvg },
|
|
|
- { name: 'running', svg: runningSvg },
|
|
|
- { name: 'tab', svg: tabSvg }
|
|
|
-];
|
|
|
-/* tslint:enable */
|
|
|
|
|
|
/**
|
|
|
* The icon registry class.
|
|
|
*/
|
|
|
export class IconRegistry {
|
|
|
- constructor(...icons: IconRegistry.IModel[]) {
|
|
|
+ constructor(...icons: Icon.IModel[]) {
|
|
|
if (icons.length) {
|
|
|
this.addIcon(...icons);
|
|
|
} else {
|
|
|
- this.addIcon(..._defaultIcons);
|
|
|
+ this.addIcon(...defaultIcons);
|
|
|
}
|
|
|
|
|
|
// add the bad state icon
|
|
|
this.addIcon({ name: 'bad', svg: badSvg });
|
|
|
}
|
|
|
|
|
|
- addIcon(...icons: IconRegistry.IModel[]): void {
|
|
|
- icons.forEach((icon: IconRegistry.IModel) => {
|
|
|
+ addIcon(...icons: Icon.IModel[]): void {
|
|
|
+ icons.forEach((icon: Icon.IModel) => {
|
|
|
let className = icon.className
|
|
|
? icon.className
|
|
|
: IconRegistry.iconClassName(icon.name);
|
|
@@ -88,7 +41,7 @@ export class IconRegistry {
|
|
|
// assume name is really a className, split the className into parts and check each part
|
|
|
for (let className of name.split(/\s+/)) {
|
|
|
if (className in this._classNameToName) {
|
|
|
- return this._nameToClassName[className];
|
|
|
+ return this._classNameToName[className];
|
|
|
}
|
|
|
}
|
|
|
// couldn't resolve name, mark as bad
|
|
@@ -167,34 +120,10 @@ export class IconRegistry {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- // override(
|
|
|
- // props: { className: string; name?: string; title?: string } & IIconStyle
|
|
|
- // ) {
|
|
|
- // let { name, className, title, ...propsStyle } = props;
|
|
|
- //
|
|
|
- // // try to resolve name
|
|
|
- // name = name ? name : this.classNameToName(className);
|
|
|
- // if (!name) {
|
|
|
- // // bail
|
|
|
- // return;
|
|
|
- // }
|
|
|
- //
|
|
|
- // for (let container of document.getElementsByClassName(
|
|
|
- // className
|
|
|
- // ) as HTMLCollectionOf<HTMLElement>) {
|
|
|
- // this.icon({
|
|
|
- // name: name,
|
|
|
- // title: title,
|
|
|
- // container: container,
|
|
|
- // ...propsStyle
|
|
|
- // });
|
|
|
- // }
|
|
|
- // }
|
|
|
-
|
|
|
svg(name: string, skipbad: boolean = false): string {
|
|
|
let svgname = this.resolveName(name);
|
|
|
|
|
|
- if (name === 'bad') {
|
|
|
+ if (svgname === 'bad') {
|
|
|
if (!skipbad) {
|
|
|
// log a warning and mark missing icons with an X
|
|
|
console.error(`Invalid icon name: ${name}`);
|
|
@@ -231,21 +160,12 @@ export const IconReact = (
|
|
|
};
|
|
|
|
|
|
export namespace IconRegistry {
|
|
|
- export interface IModel {
|
|
|
- name: string;
|
|
|
- className?: string;
|
|
|
- svg: string;
|
|
|
- }
|
|
|
-
|
|
|
export interface IIconOptions {
|
|
|
name: string;
|
|
|
className?: string;
|
|
|
title?: string;
|
|
|
skipbad?: boolean;
|
|
|
}
|
|
|
-
|
|
|
- // needs the explicit type to avoid a typedoc issue
|
|
|
- export const defaultIcons: ReadonlyArray<IconRegistry.IModel> = _defaultIcons;
|
|
|
}
|
|
|
|
|
|
namespace Private {
|