How to use the @carbon/icon-helpers.getAttributes 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-custom-elements / tools / svg-result-carbon-icon.js View on Github external
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)}\``;
};
github carbon-design-system / carbon / packages / icons / examples / preview / index.js View on Github external
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,
github carbon-design-system / carbon-custom-elements / src / components / icon / icon.ts View on Github external
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);
github carbon-design-system / carbon / packages / icon-build-helpers / src / builders / react / components / Icon.js View on Github external
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;
  }

@carbon/icon-helpers

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

Apache-2.0
Latest version published 29 days ago

Package Health Score

98 / 100
Full package analysis