Skip to content

Commit

Permalink
move the icon-service to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jul 26, 2020
1 parent 4991138 commit a05713b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
23 changes: 23 additions & 0 deletions lib/icon-service/mdi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Convert the CSS class name of mdi icons to the JS name
function mdiIconName(str) {
// https://github.com/Templarian/MaterialDesign-JS/blob/master/build.js#L5
let name = str.replace(/(-\w)/g, (matches) => matches[1].toUpperCase());
name = `${name[0].toUpperCase()}${name.slice(1)}`;
return `mdi${name}`;
}

let mdi; // mdi iconSet
export async function createMDIIcon(iconName, iconSize) {
if (!mdi) {
mdi = await import('@mdi/js')
}
const iconData = mdi[mdiIconName(iconName)];
const icon = document.createElement("div");
icon.style.verticalAlign = "bottom"
icon.innerHTML = `
<svg style='width:${iconSize}px; height:${iconSize}px' viewBox='0 0 24 24'>
<path fill='currentColor', d='${iconData}'/>
<svg/>
`
return icon
}
27 changes: 1 addition & 26 deletions lib/items/tool-bar-button-view.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,6 @@
import {CompositeDisposable} from 'atom';
import { ToolBarItem } from './tool-bar-item';


// Convert the CSS class name of mdi icons to the JS name
function mdiIconName(str) {
// https://github.com/Templarian/MaterialDesign-JS/blob/master/build.js#L5
let name = str.replace(/(-\w)/g, (matches) => matches[1].toUpperCase());
name = `${name[0].toUpperCase()}${name.slice(1)}`;
return `mdi${name}`;
}

let mdi; // mdi iconSet
async function createMDIIcon(iconName, iconSize) {
if (!mdi) {
mdi = await import('@mdi/js')
}
const iconData = mdi[mdiIconName(iconName)];
const icon = document.createElement("div");
icon.style.verticalAlign = "bottom"
icon.innerHTML = `
<svg style='width:${iconSize}px; height:${iconSize}px' viewBox='0 0 24 24'>
<path fill='currentColor', d='${iconData}'/>
<svg/>
`
return icon
}

import { createMDIIcon } from '../icon-service/mdi';

/**
* A button class with many options
Expand Down

0 comments on commit a05713b

Please sign in to comment.