act

Making SVG icon libraries for React apps

Using SVG is currently the best way to create icon libraries for apps. Icons built with SVG are scalable and adjustable, but also discrete, which allows them to be incrementally loaded and updated. In contrast, icons built as fonts cannot be incrementally loaded or updated. This alone makes SVG icons the better choice for high-performance apps that rely on code-splitting and incremental deploys.

This post describes how to make a package of React components from a library of SVG icons. Although I’m focusing on React, making any other type of package is also possible. At Twitter I used the approach described here to publish the company’s SVG icon library in several different formats: optimized SVGs, plain JavaScript modules, React DOM components, and React Native components.

Using the icons

The end result is a JavaScript package that can be installed and used like any other JavaScript package.

yarnpkg add @acme/react-icons

Each icon is available as an individually exported React component.

import IconCamera from '@acme/react-icons/camera';

This allows your module bundler to package only the icons that are needed, and icons can be efficiently split across chunks when using code-splitting. This is a significant advantage over icon libraries that require fonts and bundle all icons into a single component.

// entire icon library is bundled with your app
import Icon from '@acme/react-icons';
const IconCamera = <Icon name='camera' />;

Each icon is straightforward to customize (e.g., color and dimensions) on a per-use basis.

import IconCamera from '@twitter/react-icons/camera';
const Icon = (
  <IconCamera
    style={{ color: 'white', height: '2em' }}
  />
);

Although the icons render to SVG, this is an implementation detail that isn’t exposed to users of the components.

Creating components

Each React component renders an inline SVG, using path and dimensions data extracted from the SVG source files. A helper function called createIconComponent means that only a few lines of boilerplate are needed to create a component from SVG data.

import createIconComponent from './utils/createIconComponent';
import React from 'react';
const IconCamera = createIconComponent({
  content: <g><path d='...'></g>,
  height: 24,
  width: 24
});
IconCamera.displayName = 'IconCamera';
export default IconCamera;

This is an example of what the createIconComponent function looks like when building components for a web app like Twitter Lite, which is built with React Native for Web.

// createIconComponent.js
import { createElement, StyleSheet } from 'react-native-web';
import React from 'react';

const createIconComponent = ({ content, height, width }) =>
  (initialProps) => {
    const props = {
      ...initialProps,
      style: StyleSheet.compose(styles.root, initialProps.style),
      viewBox: `0 0 ${width} ${height}`
    };

    return createElement('svg', props, content);
  };

const styles = StyleSheet.create({
  root: {
    display: 'inline-block',
    fill: 'currentcolor',
    height: '1.25em',
    maxWidth: '100%',
    position: 'relative',
    userSelect: 'none',
    textAlignVertical: 'text-bottom'
  }
});

Setting the fill style to currentcolor allows you to control the color of the SVG using the color style property instead.

All that’s left is to use scripts to process the SVGs and generate each React component.

Creating icon packages

A complete example of one way to do this can be found in the icon-builder-example repository on GitHub.

The project structure of the example tool looks like this.

.
├── README.md
├── package.json
├── scripts/
    ├── build.js
    ├── createReactPackage.js
    └── svgOptimize.js
└── src/
    ├── alerts.svg
    ├── camera.svg
    ├── circle.svg
    └── ...

The build script uses SVGO to optimize the SVGs, extract SVG path data, and extract metadata. The example packager for React then uses templates to create a package.json and the React icon components shown earlier.

import createIconComponent from './utils/createIconComponent';
import React from 'react';
const ${componentName} = createIconComponent({
  height: ${height},
  width: ${width},
  content: <g>${paths}</g>
});
${componentName}.displayName = '${componentName}';
export default ${componentName};

Additional packagers can be included to build other package types from the same SVG source. When the underlying icon library changes, it only takes a couple of commands to rebuild hundreds of icons and publish new versions of each package.




act

Coronavirus | Assam rights activist held for social media post

Rupa Rani Bhuyan, assistant professor of Mangaldoi College, was held for “misbehaving” with the police and “obstructing” them from investigating cases against her




act

The strategy of execution [electronic resource] : the five-step guide for turning vision into action / Liz Mellon and Simon Carter

Mellon, Elizabeth




act

Troubleshooting Sharepoint [electronic resource] : the complete guide to tools, best practices, powershell one-liners, and scripts / Stacy Simpkins

Simpkins, Stacy, author




act

Tussle between maintaining customer satisfaction and supply chain constraints [electronic resource] : IGNYS automotive / Chuck Munson with Satish Kumar and Dileep More

Munson, Chuck, author




act

Pharmacy practice management quarterly (Online)




act

U.S. military program management [electronic resource] : lessons learned and best practices / Gregory A. Garrett, Rene G. Rendon

Garrett, Gregory A




act

Using technology to sell [electronic resource] : tactics to ratchet up results / Jonathan London, Martin Lucas

London, Jonathan




act

Visual Design of GraphQL Data [electronic resource] : A Practical Introduction with Legacy Data and Neo4j / by Thomas Frisendal

Frisendal, Thomas. author




act

Web development with MongoDB and Node JS [electronic resource] : build an interactive and full-featured web application from scratch using Node.js and MongoDB / Mithun Sathessh, Bruno Joseph D'mello, Jason Krol

Satheesh, Mithun, author




act

Your first 100 days [electronic resource] : how to make maximum impact in your new leadership role / Niamh O'Keeffe

O'Keeffe, Niamh





































act

Focus on effective surveillance of COVID-19, contact-tracing and early diagnosis: Harsh Vardhan tells Tamil Nadu, Telangana and Karnataka

The Minister also asked the States to ensure adoption of infection, prevention and control (IPC) practices in all health-care settings to avoid and reduce chances of infections to health-care workers.




act

Covid-19 impact: No comfort in hotel stocks as recovery pushed to FY23

Expectations of a slow recovery, high fixed costs and debt worries are putting off investors




act

Practice Management - Custom Training per half hour

Available Sessions for this Seminar:

, February 04, 2015
, February 17, 2015




act

CCH Practice Management: Project Management

Objectives

The Projects course content focuses on features you use to assign employees to projects, enter and track budget information and track project due dates. Project Management list setup and creating projects are integral parts of this course. These features help make sure management has the most up to date information to make informed decisions. Expected prerequisite program knowledge includes the Time Entry module as well as filtering and navigating between modules. This course includes hands-on computer training.

 

Topics

 

·         Set security settings that affect the Project Management and Project Tracking modules

·         Set up Project Management lists

·         Copy Templates to clients

·         Copy existing client projects to other clients

·         Assign staff to projects

·         Create budgets for projects

·         Schedule employee work load and manage resources

·         Use Project Tracking to build lists on-screen

·         Update a project status in the Time Entry module

·         Run project status and scheduling reports

·         Extend project due dates in the program

·         Roll forward or replicate projects for the next period

·         Use Project Management utilities and other helpful features

 

Attendees

Staff that create projects, monitor due dates, set time budgets, assign staff to jobs, and schedule staff workload

 

Available Sessions for this Seminar:

ipwebinar.aspx?tab=1&smid=1247, January 28, 2015




act

CCH Practice Management - Time Entry

Available Sessions for this Seminar:

ipwebinar.aspx?tab=1&smid=1644, January 20, 2015




act

CCH Practice Management: A/R Training

Objectives

 
The End User course content focuses on the key features that all employees use when entering time and expense transactions, updating the status of a project and finding client contact information. All of these features are designed to make sure that management has the most up-to-date information to make decisions.

 

Topics

 

·         Enter billable time or expense transactions in 30 seconds or less

·         Enter nonbillable time, expense, CPE and marketing transactions

·         Update project status when entering time and expenses

·         Review, edit and release time and expense transactions

·         Generate a reimbursable expense report

·         Review summary or detailed timesheet history

·         Monitor client and project alerts

·         Manage and review personal due dates

·         Look up client information

 

 

 

Attendees

 
All staff that enter time, expenses, lookup contact information, and update project status

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Available Sessions for this Seminar:

ipwebinar.aspx?tab=1&smid=1244, January 15, 2015