Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const icon = descriptor => {
descriptor.attrs = getAttributes(
Object.assign(descriptor.attrs, {
'...': '${spread(attrs)}', // eslint-disable-line no-template-curly-in-string
})
);
descriptor.content.unshift('${children}'); // eslint-disable-line no-template-curly-in-string
return `({ children, ...attrs } = {}) => svg\`${toString(descriptor)}\``;
};
function js2svg(descriptor) {
const { elem, attrs = {}, content = [] } = descriptor;
let attributes = attrs;
if (elem === 'svg') {
const { style, ...iconAttributes } = getAttributes(attrs);
attributes = {
...iconAttributes,
style: style
.split(';')
.map(declaration => {
const [property, value] = declaration
.split(':')
.map(string => string.trim());
return {
[property]: value,
};
})
.reduce(
(acc, declaration) => ({
...acc,
...declaration,
const icon = (descriptor, attributes = {}) => {
const { title, ...rest } = getAttributes(Object.assign(descriptor.attrs, attributes));
descriptor.attrs = rest;
if (title) {
const id = `__carbon-icon__${Math.random()
.toString(36)
.substr(2)}`;
descriptor.content.push({
elem: 'title',
attrs: {
id,
},
content: [title],
});
descriptor.attrs['aria-describedby'] = id;
}
const strings = [toString(descriptor)];
return svg(Object.assign(strings, { raw: strings }) as TemplateStringsArray);
const Icon = React.forwardRef(function Icon(
{ className, children, style = {}, tabIndex, ...rest },
ref
) {
const { tabindex, ...props } = getAttributes({
...rest,
tabindex: tabIndex,
});
if (className) {
props.className = className;
}
if (tabindex !== undefined && tabindex !== null) {
props.tabIndex = tabindex;
}
if (ref) {
props.ref = ref;
}