Skip to content

Commit

Permalink
Use custom icons (#55)
Browse files Browse the repository at this point in the history
* Add new icons

* Add generate icons script

* Update components

* Update icons usage

* Add missing icons

* Update navbar

* Add script to package.json
  • Loading branch information
ardier16 authored Mar 14, 2024
1 parent a2c5bfa commit f28b641
Show file tree
Hide file tree
Showing 125 changed files with 511 additions and 265 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"lint": "yarn lint:scripts",
"lint:scripts": "eslint \"{src,config}/**/*.{js,ts,jsx,tsx}\" --cache --fix --max-warnings=0",
"preview": "vite preview",
"rsc": "node scripts/release-sanity-check.mjs"
"rsc": "node scripts/release-sanity-check.mjs",
"generate-icons": "node scripts/generate-icons.mjs"
},
"dependencies": {
"@distributedlab/jac": "^1.0.0-rc.14",
Expand Down
53 changes: 53 additions & 0 deletions scripts/generate-icons.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* eslint-disable no-console */
import fs from 'fs'
import camelCase from 'lodash/camelCase.js'
import upperFirst from 'lodash/upperFirst.js'
import path, { dirname } from 'path'
import { fileURLToPath } from 'url'

const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)

const iconsDir = path.resolve(__dirname, '../src/assets/icons')
const iconsEnumFile = path.resolve(__dirname, '../src/enums/icons.ts')

const ICONS_ENUM_FILE_TEMPLATE = `import { SvgIcon } from '@mui/material'
export enum Icons {
%s
}
export const ICON_COMPONENTS: Record<string, typeof SvgIcon> = {}
`

function generateIconsEnum() {
const iconNames = fs
.readdirSync(iconsDir)
.filter(file => file.endsWith('.svg'))
.map(file => file.replace('-icon.svg', ''))

const iconEnum = iconNames
.map(iconName => `${upperFirst(camelCase(iconName))} = '${iconName}',`)
.join('\n ')

fs.writeFileSync(iconsEnumFile, ICONS_ENUM_FILE_TEMPLATE.replace('%s', iconEnum))
console.log(`Generated ${iconNames.length} icons.`)
console.log(`Icons enum saved to ${iconsEnumFile}`)
}

function renameIconFiles() {
const iconsToRename = fs
.readdirSync(iconsDir)
.filter(file => file.endsWith('.svg'))
.filter(file => !file.endsWith('-icon.svg'))

iconsToRename.forEach(file => {
const filePath = path.resolve(iconsDir, file)
const newFilePath = path.resolve(iconsDir, file.replace('.svg', '-icon.svg'))
fs.renameSync(filePath, newFilePath)
})
console.log(`Renamed ${iconsToRename.length} icon files.`)
}

renameIconFiles()
generateIconsEnum()
3 changes: 3 additions & 0 deletions src/assets/icons/arrow-counter-clockwise-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/icons/arrow-down-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/icons/arrow-left-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/icons/arrow-right-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/icons/arrow-square-out-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/icons/arrow-up-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/icons/backspace-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/icons/bell-fill-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/icons/bell-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/icons/calendar-blank-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/icons/cardholder-fill-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/icons/cardholder-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/icons/caret-left-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/icons/caret-right-icon.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 f28b641

Please sign in to comment.