Icon constructor

Icon(
  1. IconData icon, {
  2. Object? size = 20,
  3. Object? color,
  4. double strokeWidth = 2,
  5. String? label,
  6. String? title,
  7. bool? decorative,
  8. String? className,
  9. Map<String, Object?> props = const {},
  10. Map<String, Object?> style = const {},
  11. DartStyle? dartStyle,
})

Creates an inline SVG icon from a IconData definition.

Implementation

Icon(
  IconData icon, {
  Object? size = 20,
  Object? color,
  double strokeWidth = 2,
  String? label,
  String? title,
  bool? decorative,
  String? className,
  Map<String, Object?> props = const {},
  Map<String, Object?> style = const {},
  DartStyle? dartStyle,
}) : super(
        'svg',
        props: mergeComponentProps(
          {
            ...props,
            'xmlns': 'http://www.w3.org/2000/svg',
            'viewBox': icon.viewBox,
            'fill': 'none',
            'stroke': 'currentColor',
            'stroke-width': strokeWidth,
            'stroke-linecap': 'round',
            'stroke-linejoin': 'round',
            'focusable': 'false',
            if (decorative ?? (label == null && title == null))
              'aria-hidden': 'true'
            else ...{
              'role': 'img',
              'aria-label': label ?? title ?? icon.name,
            },
          },
          className: className,
          defaultStyle: {
            'display': 'inline-block',
            'width': _iconCssSize(size),
            'height': _iconCssSize(size),
            'color': color ?? 'currentColor',
            'vertical-align': 'middle',
            'flex-shrink': 0,
          },
          dartStyle: dartStyle,
          style: style,
        ),
        children: [
          if (title != null)
            FlintElement('title', children: [FlintText(title)]),
          ...icon.shapes.map((shape) => shape.toNode()),
        ],
      );