@uploadcare/file-uploader
Version:
Building blocks for Uploadcare products integration
44 lines (37 loc) • 865 B
JavaScript
// @ts-check
import { Block } from '../../abstract/Block.js';
export class Icon extends Block {
constructor() {
super();
this.init$ = {
...this.init$,
name: '',
href: '',
};
}
initCallback() {
super.initCallback();
this.sub('name', (val) => {
if (!val) {
return;
}
let iconHref = `#uc-icon-${val}`;
this.subConfigValue('iconHrefResolver', (iconHrefResolver) => {
if (iconHrefResolver) {
const customIconHref = iconHrefResolver(val);
iconHref = customIconHref ?? iconHref;
}
this.$.href = iconHref;
});
});
this.setAttribute('aria-hidden', 'true');
}
}
Icon.template = /* HTML */ `
<svg ref="svg" xmlns="http://www.w3.org/2000/svg">
<use set="@href: href;"></use>
</svg>
`;
Icon.bindAttributes({
name: 'name',
});