A framework-agnostic, customizable, and lightweight SVG icon package for React, Vue, Angular, and other JavaScript frameworks.
- โ Lightweight & optimized
- โ Compatible with React, Vue, Angular, and Vanilla JS
- โ Customizable via props or attributes
- โ Dual builds: CommonJS (CJS) & ES Modules (ESM)
- โ Fully written in TypeScript for type safety
- โ Tree-shakable: Import only what you use
npm install universal-svg-icons
yarn add universal-svg-icons
Use the IconWrapper
or import the icon directly as a JSX component:
import { IconWrapper, getCheckIconPath, CheckIcon } from "universal-svg-icons";
export default function App() {
return (
<>
...
<CheckIcon />
<CheckIcon variant="filled" />
...
</>
);
}
Use IconWrapper
in plain JavaScript by building the SVG element manually:
import { getCheckIconPath } from "universal-svg-icons/path";
const svgElement = `<svg width="24" height="24"><path d="${getCheckIconPath()}" fill="black"/></svg>`;
document.body.innerHTML = svgElement;
Use the path directly or register the icon as a component:
<template>
<svg width="32" height="32"><path :d="checkIconPath" fill="black" /></svg>
</template>
<script>
import { getCheckIconPath } from "universal-svg-icons/path";
export default {
data() {
return { checkIconPath: getCheckIconPath() };
},
};
</script>
Use property binding in templates:
<svg width="32" height="32">
<path [attr.d]="checkIconPath" fill="black" />
</svg>
import { Component } from "@angular/core";
import { getCheckIconPath } from "universal-svg-icons/path";
@Component({
selector: "app-root",
templateUrl: "./app.component.html",
})
export class AppComponent {
checkIconPath = getCheckIconPath();
}
You can use the icons directly in your HTML by loading the Web Component from a CDN:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Universal SVG Icon from CDN</title>
<!-- โ
Load the Web Component directly from unpkg CDN -->
<script type="module" src="https://unpkg.com/[email protected]/dist/web-component.js"></script>
<style>
body {
font-family: sans-serif;
padding: 2rem;
text-align: center;
}
universal-svg-icons {
width: 64px;
height: 64px;
stroke: black;
stroke-width: 2;
fill: none;
--path-fill: green;
margin: 1rem;
}
.icon-row {
display: flex;
justify-content: center;
gap: 2rem;
flex-wrap: wrap;
}
</style>
</head>
<body>
<h1>Universal SVG Icons (via CDN)</h1>
<div class="icon-row">
<universal-svg-icons name="check" variant="default"></universal-svg-icons>
<universal-svg-icons name="admin" variant="default"></universal-svg-icons>
<universal-svg-icons name="apple" variant="default"></universal-svg-icons>
<universal-svg-icons name="twitter" variant="default"></universal-svg-icons>
</div>
</body>
</html>
Replace the name
attribute in the <universal-svg-icons>
element with the desired icon's name.
You can use the icons directly in your HTML by loading the Web Component from a CDN:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Universal SVG Icon from CDN</title>
<!-- โ
Load the Web Component directly from unpkg CDN -->
<script
type="module"
src="https://unpkg.com/[email protected]/dist/web-component.js"
></script>
<style>
body {
font-family: sans-serif;
padding: 2rem;
text-align: center;
}
universal-svg-icons {
width: 64px;
height: 64px;
stroke: black;
stroke-width: 2;
fill: none;
--path-fill: green;
margin: 1rem;
}
.icon-row {
display: flex;
justify-content: center;
gap: 2rem;
flex-wrap: wrap;
}
</style>
</head>
<body>
<h1>Universal SVG Icons (via CDN)</h1>
<div class="icon-row">
<universal-svg-icons name="check" variant="default"></universal-svg-icons>
<universal-svg-icons name="admin" variant="default"></universal-svg-icons>
<universal-svg-icons name="apple" variant="default"></universal-svg-icons>
<universal-svg-icons
name="twitter"
variant="default"
></universal-svg-icons>
</div>
</body>
</html>
Replace the name
attribute in the <universal-svg-icons>
element with the desired icon's name.
Prop | Type | Default | Description |
---|---|---|---|
className |
string |
fill-current |
CSS class for the SVG |
width |
string |
24 |
Width of the icon |
height |
string |
24 |
Height of the icon |
viewBox |
string |
0 0 24 24 |
ViewBox of the SVG |
fill |
string |
none |
Fill color of the SVG element |
fillRule |
"evenodd","nonzero", "inherit" |
evenodd |
Fill rule |
clipRule |
string |
evenodd |
Clip rule |
path |
string |
"" |
SVG path data |
pathFill |
string |
"" |
Fill color for the path |
clipPath |
string |
"" |
Clip path reference |
defsClipPath |
React.ReactNode |
<></> |
Clip path definitions |
You can import icons as raw paths or JSX components:
Icon Name | Path Import Name | JSX Component |
---|---|---|
๐ก๏ธ Admin | getAdminIconPath |
<AdminIcon /> |
๐ฆ Bank | getBankIconPath |
<BankIcon /> |
๐ Basketball | getBasketBallIconPath |
<BasketBallIcon /> |
๐ Bell | getBellIconPath |
<BellIcon /> |
๐ Calendar | getCalendarIconPath |
<CalendarIcon /> |
๐ท Cam | getCamIconPath |
<CamIcon /> |
๐ Chart | getChartIconPath |
<ChartIcon /> |
๐ฌ Chat | getChatIconPath |
<ChatIcon /> |
โ Check | getCheckIconPath |
<CheckIcon /> |
โก๏ธ Chevron | getChevronIconPath |
<ChevronIcon /> |
โฐ Clock | getClockIconPath |
<ClockIcon /> |
๐ Contact | getContactIconPath |
<ContactIcon /> |
๐ Dashboard | getDashboardIconPath |
<DashboardIcon /> |
โฎ Dots | getDotsIconPath |
<DotsIcon /> |
โฌ๏ธ Download | getDownloadIconPath |
<DownloadIcon /> |
โ Error | getErrorIconPath |
<ErrorIcon /> |
๐๏ธ Eye | getEyeIconPath |
<EyeIcon /> |
โ FAQ | getFaqIconPath |
<FaqIcon /> |
๐ Form | getFormIconPath |
<FormIcon /> |
๐ฆ Grid | getGridIconPath |
<GridIcon /> |
โน๏ธ Info | getInfoIconPath |
<InfoIcon /> |
๐ซ Institutes | getInstitutsIconPath |
<InstitutsIcon /> |
๐ Lock | getLockIconPath |
<LockIcon /> |
โ๏ธ Mail | getMailIconPath |
<MailIcon /> |
โฐ Menu | getMenuIconPath |
<MenuIcon /> |
โก๏ธ Next | getNextIconPath |
<NextIcon /> |
โ๏ธ Pen | getPenIconPath |
<PenIcon /> |
๐ Phone | getPhoneIconPath |
<PhoneIcon /> |
๐ Portal | getPortalIconPath |
<PortalIcon /> |
โฌ ๏ธ Previous | getPreviousIconPath |
<PreviousIcon /> |
๐ท๏ธ Price Tag | getPriceTagIconPath |
<PriceTagIcon /> |
๐ก๏ธ Privacy | getPrivacyIconPath |
<PrivacyIcon /> |
๐จโ๐ผ Pro | getProIconPath |
<ProIcon /> |
๐ง Profile | getProfilIconPath |
<ProfilIcon /> |
โ๏ธ Settings | getSettingsIconPath |
<SettingsIcon /> |
โ Success | getSuccessIconPath |
<SuccessIcon /> |
๐ ๏ธ Support | getSupportIconPath |
<SupportIcon /> |
๐ Table | getTableIconPath |
<TableIcon /> |
๐ค Text | getTextIconPath |
<TextIcon /> |
๐ค User | getUserIconPath |
<UserIcon /> |
๐งฉ UI | getUiIconPath |
<UiIcon /> |
getWarningIconPath |
<WarningIcon /> |
Example Usage:
import { IconWrapper, getMailIconPath, MailIcon } from "universal-svg-icons";
```- ๐ฆ Tree-shakable: Only includes icons you use
- ๐งฉ Dual build system: Supports both CJS & ESM
- ๐ ๏ธ Type-safe: Written in TypeScript
We welcome contributions! Here's how to get started:
git clone https://github.com/tsb04/universal-svg-icons.git
cd universal-svg-icons
npm install
npm run build
- Add your SVG path to
/src/icons/
- Export it in
/src/index.ts
git checkout -b feature/new-icon
git commit -m "Added new icon"
git push origin feature/new-icon
Then open a Pull Request on GitHub ๐
๐ง Tip
All icons should be designed at
24x24
withviewBox="0 0 24 24"
. Use the scale.py script to scale your icon's SVG path to the required size automatically.
Licensed under the ISC License.
- ๐ Report Issues
- ๐ก Request Features via GitHub Discussions
- ๐ฌ Need help? Start a GitHub Discussion
If this project helps you, please โญ star it on GitHub and share it. Made with โค๏ธ by tsb04 โ Happy coding! ๐