mirror of
https://github.com/notion-enhancer/notion-enhancer.git
synced 2025-04-06 05:29:02 +00:00
34 lines
1.0 KiB
JavaScript
34 lines
1.0 KiB
JavaScript
/**
|
|
* notion-enhancer: components
|
|
* (c) 2021 dragonwocky <thedragonring.bod@gmail.com> (https://dragonwocky.me/)
|
|
* (https://notion-enhancer.github.io/) under the MIT license
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
/** shared notion-style elements */
|
|
|
|
import { fs, web } from '../index.mjs';
|
|
|
|
let _$iconSheet;
|
|
|
|
/**
|
|
* generate an icon from the feather icons set
|
|
* @param {string} name - the name/id of the icon
|
|
* @param {object} attrs - an object of attributes to apply to the icon e.g. classes
|
|
* @returns {string} an svg string
|
|
*/
|
|
export const feather = async (name, attrs = {}) => {
|
|
if (!_$iconSheet) {
|
|
_$iconSheet = web.html`${await fs.getText('dep/feather-sprite.svg')}`;
|
|
}
|
|
attrs.style = (
|
|
(attrs.style ? attrs.style + ';' : '') +
|
|
'stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;fill:none;'
|
|
).trim();
|
|
attrs.viewBox = '0 0 24 24';
|
|
return `<svg ${Object.entries(attrs)
|
|
.map(([key, val]) => `${web.escape(key)}="${web.escape(val)}"`)
|
|
.join(' ')}>${_$iconSheet.getElementById(name)?.innerHTML}</svg>`;
|
|
};
|