-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Read and transform svg icons from list (#3872)
* Read and transform svg icons from list * Apply review comments * Automatically add new icons to the icons story in Storybook (#3873) * Automatically add new icons to the icons story in Storybook * Add available codicons to Storybook (#3874)
- Loading branch information
Showing
35 changed files
with
372 additions
and
473 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,8 @@ jobs: | |
- run: yarn run install-frozen-lockfile | ||
|
||
- run: yarn svgr | ||
|
||
- run: yarn run lint | ||
|
||
- uses: paambaati/[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
export const codicons = [ | ||
'add', | ||
'arrow-up', | ||
'arrow-down', | ||
'beaker', | ||
'check', | ||
'chevron-down', | ||
'chevron-right', | ||
'close', | ||
'copy', | ||
'ellipsis', | ||
'error', | ||
'filter', | ||
'git-commit', | ||
'git-merge', | ||
'graph-line', | ||
'graph-scatter', | ||
'gripper', | ||
'info', | ||
'list-filter', | ||
'pass-filled', | ||
'pinned', | ||
'refresh', | ||
'sort-precedence', | ||
'star-empty', | ||
'star-full', | ||
'trash' | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { transform } from '@svgr/core' | ||
import { | ||
appendFile, | ||
mkdir, | ||
readdir, | ||
readFile, | ||
rm, | ||
writeFile | ||
} from 'node:fs/promises' | ||
import path from 'path' | ||
import { codicons } from './codicons.mjs' | ||
|
||
const iconsPath = 'src/shared/components/icons/' | ||
|
||
try { | ||
await rm(iconsPath, { recursive: true, force: true }) | ||
await mkdir(iconsPath) | ||
} catch (err) { | ||
console.error(err.message) | ||
} | ||
|
||
const customIcons = [] | ||
try { | ||
const files = await readdir('icons') | ||
for (const file of files) { | ||
if (path.extname(file) === '.svg') { | ||
customIcons.push(`icons/${file}`) | ||
} | ||
} | ||
} catch (err) { | ||
console.error(err.message) | ||
} | ||
|
||
const codiconsPath = '../node_modules/@vscode/codicons/src/icons' | ||
|
||
const allIcons = [ | ||
...customIcons, | ||
...codicons.map(codicon => `${codiconsPath}/${codicon}.svg`) | ||
] | ||
|
||
function toPascalCase(text) { | ||
return text.replace(/(^\w|-\w)/g, clearAndUpper) | ||
} | ||
|
||
function clearAndUpper(text) { | ||
return text.replace(/-/, '').toUpperCase() | ||
} | ||
|
||
const components = [] | ||
await Promise.all( | ||
allIcons.map(async icon => { | ||
try { | ||
const iconContent = await readFile(icon, { encoding: 'utf8' }) | ||
const componentName = toPascalCase(path.basename(icon).split('.')[0]) | ||
const svgComponent = await transform( | ||
iconContent, | ||
{ | ||
typescript: true, | ||
plugins: ['@svgr/plugin-jsx', '@svgr/plugin-prettier'] | ||
}, | ||
{ componentName } | ||
) | ||
await writeFile(`${iconsPath}${componentName}.tsx`, svgComponent) | ||
components.push(componentName) | ||
} catch (err) { | ||
console.error(err.message) | ||
} | ||
}) | ||
) | ||
|
||
await appendFile( | ||
`${iconsPath}index.ts`, | ||
components | ||
.sort() | ||
.map( | ||
componentName => | ||
`export { default as ${componentName} } from './${componentName}'\n` | ||
) | ||
.join('') | ||
) | ||
|
||
console.log(`Icons were generated to ${iconsPath}`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,15 @@ | ||
import * as React from 'react' | ||
import { SVGProps } from 'react' | ||
|
||
const SvgAdd = (props: SVGProps<SVGSVGElement>) => ( | ||
import type { SVGProps } from 'react' | ||
const Add = (props: SVGProps<SVGSVGElement>) => ( | ||
<svg | ||
width={16} | ||
height={16} | ||
viewBox="0 0 16 16" | ||
xmlns="http://www.w3.org/2000/svg" | ||
fill="currentColor" | ||
{...props} | ||
> | ||
<path d="M14 7v1H8v6H7V8H1V7h6V1h1v6h6z" fill="currentColor" /> | ||
<path d="M14 7v1H8v6H7V8H1V7h6V1h1v6h6z" /> | ||
</svg> | ||
) | ||
|
||
export default SvgAdd | ||
export default Add |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
import * as React from 'react' | ||
|
||
function SvgClock(props: React.SVGProps<SVGSVGElement>) { | ||
return ( | ||
<svg | ||
viewBox="0 0 16 16" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
{...props} | ||
> | ||
<path | ||
fillRule="evenodd" | ||
clipRule="evenodd" | ||
d="M14 8A6 6 0 112 8a6 6 0 0112 0zm1 0A7 7 0 111 8a7 7 0 0114 0zM7 4v5.5h3v-1H8V4H7z" | ||
fill="currentColor" | ||
/> | ||
</svg> | ||
) | ||
} | ||
|
||
export default SvgClock | ||
import type { SVGProps } from 'react' | ||
const Clock = (props: SVGProps<SVGSVGElement>) => ( | ||
<svg | ||
width={16} | ||
height={16} | ||
viewBox="0 0 16 16" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
{...props} | ||
> | ||
<path | ||
fillRule="evenodd" | ||
clipRule="evenodd" | ||
d="M14 8C14 11.3137 11.3137 14 8 14C4.68629 14 2 11.3137 2 8C2 4.68629 4.68629 2 8 2C11.3137 2 14 4.68629 14 8ZM15 8C15 11.866 11.866 15 8 15C4.13401 15 1 11.866 1 8C1 4.13401 4.13401 1 8 1C11.866 1 15 4.13401 15 8ZM7 4V9V9.5H7.5H10V8.5H8V4H7Z" | ||
fill="currentColor" | ||
/> | ||
</svg> | ||
) | ||
export default Clock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.