How to use the @carbon/icon-helpers.formatAttributes function in @carbon/icon-helpers

To help you get started, we’ve selected a few @carbon/icon-helpers examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github carbon-design-system / carbon / packages / icons-handlebars / index.js View on Github external
function iconHelper(name, attributes = {}, options = {}) {
  const icon = CarbonIcons[name];
  if (!icon) {
    throw new Error(`Unable to find the icon: \`${name}\``);
  }
  const content = icon.content.map(toString);
  const attrs = {
    ...icon.attrs,
    ...Object.assign({}, attributes.hash || attributes, options.hash),
  };
  return new SafeString(
    `<svg>${content.join('')}</svg>`
  );
}
github carbon-design-system / carbon-custom-elements / tools / svg-result-carbon-icon.js View on Github external
const toString = descriptor =&gt; {
  if (typeof descriptor === 'string') {
    return descriptor;
  }
  const { elem = 'svg', attrs = {}, content = [] } = descriptor;
  const children = content.map(toString).join('');
  if (elem !== 'svg') {
    return `&lt;${elem} ${formatAttributes(attrs)}&gt;${children}`;
  }
  return `&lt;${elem} ${formatAttributes(getAttributes(attrs))}&gt;${children}`;
};
github carbon-design-system / carbon-custom-elements / src / components / icon / icon.ts View on Github external
const toString = descriptor =&gt; {
  if (typeof descriptor === 'string') {
    return descriptor;
  }
  const { elem = 'svg', attrs = {}, content = [] } = descriptor;
  const children = content.map(toString).join('');
  if (elem !== 'svg') {
    return `&lt;${elem} ${formatAttributes(attrs)}&gt;${children}`;
  }
  return `&lt;${elem} ${formatAttributes(getAttributes(attrs))}&gt;${children}`;
};
github carbon-design-system / carbon-custom-elements / src / components / icon / icon.ts View on Github external
const toString = descriptor =&gt; {
  if (typeof descriptor === 'string') {
    return descriptor;
  }
  const { elem = 'svg', attrs = {}, content = [] } = descriptor;
  const children = content.map(toString).join('');
  if (elem !== 'svg') {
    return `&lt;${elem} ${formatAttributes(attrs)}&gt;${children}`;
  }
  return `&lt;${elem} ${formatAttributes(getAttributes(attrs))}&gt;${children}`;
};
github carbon-design-system / carbon-custom-elements / tools / svg-result-carbon-icon.js View on Github external
const toString = descriptor =&gt; {
  if (typeof descriptor === 'string') {
    return descriptor;
  }
  const { elem = 'svg', attrs = {}, content = [] } = descriptor;
  const children = content.map(toString).join('');
  if (elem !== 'svg') {
    return `&lt;${elem} ${formatAttributes(attrs)}&gt;${children}`;
  }
  return `&lt;${elem} ${formatAttributes(getAttributes(attrs))}&gt;${children}`;
};

@carbon/icon-helpers

Helpers used alongside icons for digital and software products using the Carbon Design System

Apache-2.0
Latest version published 1 month ago

Package Health Score

98 / 100
Full package analysis