Skip to content

Commit

Permalink
feat: add 16px icons and update all svgs (#91)
Browse files Browse the repository at this point in the history
* chore(scripts): print names of icon files that have invalid width/height value

When we copy over svgs from Figma, it sometimes happens that those files have invalid height/width
applied to svg element. By printing a list of invalid icons, we are increasing our chances of
spotting those tiny errors.

* feat: update remaining icons and add missing 16px sizes
  • Loading branch information
BalbinaK committed Feb 2, 2024
1 parent 908e12a commit a5f5794
Show file tree
Hide file tree
Showing 590 changed files with 3,340 additions and 2,549 deletions.
34 changes: 25 additions & 9 deletions scripts/output/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ import { getSVGs, getDirname } from '../util/helpers.js'
import chalk from 'chalk'
import defaultIconDescriptions from '../../default-icon-descriptions.js'

const __dirname = getDirname(import.meta.url)
const icons = []
const basepath = joinPath(__dirname, '../../react/')
mkdirSync(basepath, { recursive: true })
const __dirname = getDirname(import.meta.url);
const icons = [];
const basepath = joinPath(__dirname, '../../react/');
mkdirSync(basepath, { recursive: true });
const invalidIconSizes = [];

// Create React Icon
getSVGs().forEach(({ svg, filename, exportName, name }) => {
// Handle i18n of icon title
const iconNameCamelCase = exportName.replace('Icon', '').replace(/\d+/g, '');
const titleMessage = defaultIconDescriptions[iconNameCamelCase.toLowerCase()];
const attrs = Array.from(svg.attrs).map(attr => attr.name + `: ` + `'` + attr.value + `'`)
const attrs = Array.from(svg.attrs).map((attr) => attr.name + `: ` + `'` + attr.value + `'`);
validateSize(svg.attrs, filename);
const { message, id, comment } = titleMessage || {};
const titleHtml = "<title>${title}</title>";
const output = [
Expand All @@ -41,7 +43,21 @@ console.log(`${chalk.cyan('react')}: Processing ${chalk.yellow(iconNames.length)
console.log(`${chalk.cyan('react')}: Wrote ${chalk.yellow(icons.length)} icon files (different sizes for the same icon)`)

// Create index file
const indexFile = icons.map(({ filename }) => `export * from './${filename}'`) .join("\n");
const indexFilename = joinPath(basepath, 'index.js')
writeFileSync(indexFilename, `${indexFile}`, 'utf-8')
console.log(`${chalk.cyan('react')}: Wrote ${chalk.yellow('index')} file`)
const indexFile = icons.map(({ filename }) => `export * from './${filename}'`).join('\n');
const indexFilename = joinPath(basepath, 'index.js');
writeFileSync(indexFilename, `${indexFile}`, 'utf-8');
console.log(`${chalk.cyan('react')}: Wrote ${chalk.yellow('index')} file`);
console.log(`${chalk.red(`Icons with invalid width or height attribute:`)}\n${invalidIconSizes.join('\n')}`);

function validateSize(svgAttrs, filename) {
const attrs = {};
Array.from(svgAttrs).forEach((attr) => {
attrs[attr.name] = attr.value;
});
const { width, height } = attrs;
const sizeFromFilename = filename.match(/\d+(\.\d+)?/g)[0];

if (sizeFromFilename !== width || ![16, 24, 32, 42, 28, 48, 56].includes(Number(height))) {
invalidIconSizes.push(filename);
}
}
8 changes: 8 additions & 0 deletions src/raw/active-ads/icon_16.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 8 additions & 6 deletions src/raw/active-ads/icon_24.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 8 additions & 6 deletions src/raw/active-ads/icon_32.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion src/raw/ads/icon_16.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion src/raw/ads/icon_24.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion src/raw/ads/icon_32.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions src/raw/air-con/icon_16.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 6 additions & 8 deletions src/raw/air-con/icon_24.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 6 additions & 8 deletions src/raw/air-con/icon_32.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions src/raw/airplane/icon_42.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 7 additions & 5 deletions src/raw/alert-error/icon_16.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions src/raw/alert-error/icon_24.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions src/raw/alert-error/icon_32.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 6 additions & 5 deletions src/raw/alert-info/icon_16.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions src/raw/alert-info/icon_24.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit a5f5794

Please sign in to comment.