snappymail/dev/Component/SvgIcon.jsx

28 lines
576 B
React
Raw Normal View History

2015-11-15 08:23:16 +08:00
2016-07-02 06:49:59 +08:00
import $ from '$';
2015-11-15 08:23:16 +08:00
2016-06-30 08:02:45 +08:00
let cachedUrl = null;
const getUrl = () => {
if (!cachedUrl)
{
const version = $('#rlAppVersion').attr('content') || '0.0.0';
cachedUrl = `rainloop/v/${version}/static/css/svg/icons.svg`;
2015-11-15 08:23:16 +08:00
}
2016-06-30 08:02:45 +08:00
return cachedUrl;
};
2015-11-15 08:23:16 +08:00
module.exports = {
template: '<b></b>',
viewModel: {
2016-06-30 08:02:45 +08:00
createViewModel: ({icon = 'null'}, componentInfo) => {
2015-11-15 08:23:16 +08:00
if (componentInfo && componentInfo.element)
{
$(componentInfo.element).replaceWith(
2016-06-30 08:02:45 +08:00
`<svg class="svg-icon svg-icon-${icon}"><use xlink:href="${getUrl()}#svg-icon-${icon}"></use></svg>`
2015-11-15 08:23:16 +08:00
);
}
}
}
};