Skip to content

Commit

Permalink
Update icon set according to documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
bartaxyz committed Oct 5, 2018
1 parent 8fc1c27 commit 7fb24c9
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 22 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xyz-icon-set",
"version": "0.23.0",
"version": "0.24.0",
"description": "",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand All @@ -9,7 +9,7 @@
"build": "npm run clean && npm run build:source && node ./dist/build.js && npm run build:output",
"build:output": "tsc dist/index.ts -d --outDir dist/",
"build:source": "tsc src/build.ts -d --outDir dist/ && npm run build:utils",
"build:utils": "tsc src/utils/getIcon.ts -d --outDir dist/utils/",
"build:utils": "tsc src/utils/Icon.ts -d --outDir dist/utils/",
"lint": "eslint src tests",
"lint:fix": "npm run lint -- --fix",
"test": "mocha -r ts-node/register src/**/__test__/**/*.ts",
Expand Down
43 changes: 23 additions & 20 deletions src/templates/index.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,11 @@
import {{name}}_{{theme}} from './icons/{{{category}}}.{{{theme}}}.{{{name}}}';
{{/each}}

import { Icon } from './utils/Icon';

export type IconTheme = 'regular' | 'thin' | 'filled' | 'real';

export interface UnthemedIcon {
regular: Icon;
thin: Icon;
filled?: Icon;
real?: Icon;
}

export interface Icon {
source: string;
category: string;
theme: IconTheme;
name: string;
}
/*
* Meta Data - Types
*/

export type IconCategory ={{#iconCategories}}
| '{{this}}'{{/iconCategories}};
Expand All @@ -27,8 +16,12 @@ export type IconName ={{#iconNames}}
| '{{this}}'{{/iconNames}};

export type IconComponentName ={{#iconComponentNames}}
| '{{this}}'{{/iconComponentNames}}
| '{{this}}'{{/iconComponentNames}};


/*
* Meta Data - Exports
*/

export const iconCategories: IconCategory[] = [{{#iconCategories}}
'{{this}}',{{/iconCategories}}
Expand All @@ -42,15 +35,25 @@ export const iconComponentNames: IconComponentName[] = [{{#iconComponentNames}}
'{{this}}',{{/iconComponentNames}}
];


export interface IconComponents { {{#iconComponentNames}}
{{this}}: any;{{/iconComponentNames}}
}

/*
* Icon Classes Export
*/


{{#each icons}}
export const {{@key}}: UnthemedIcon = {
regular: {{#regular}}{{name}}_{{theme}}{{/regular}} as Icon,
thin: {{#thin}}{{name}}_{{theme}}{{/thin}} as Icon,
};
export class {{@key}} extends Icon {
name = '{{@key}}';
category = '{{#regular}}{{category}}{{/regular}}';
source = {
regular: {{#regular}}{{name}}_{{theme}}{{/regular}}.source,
thin: {{#thin}}{{name}}_{{theme}}{{/thin}}.source,
}
}
{{/each}}

const XYZIconSet = {
Expand Down
48 changes: 48 additions & 0 deletions src/utils/Icon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
export type IconTheme = 'regular' | 'thin';

export interface GetIconInput {
source: string;
category: string;
theme: IconTheme;
name: string;
}

export interface IconOptions {
fillOpacity?: number;
}

export interface IconContstructorOptions {
theme?: IconTheme;
}

export class Icon {
name: string;
category: string;
theme: IconTheme;
source: {
[key: string]: string;
};

constructor({ theme }: IconContstructorOptions = {}) {
this.theme = theme || 'regular';
}

toString({ fillOpacity = 0 }: IconOptions = {}): string {
return this.source[this.theme].replace(
/fill\-opacity\=\"0\.1\"/g,
`fill-opacity="${fillOpacity}"`,
);
}

toDocumentFragment({ fillOpacity }: IconOptions = {}): DocumentFragment {
if (!document) {
throw new Error(
'Document object is not in your global scope. This method can be executed in browser only.',
);
}

return document
.createRange()
.createContextualFragment(this.source[this.theme]);
}
}

0 comments on commit 7fb24c9

Please sign in to comment.