Skip to content

TSB04/svg-icon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

70 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŒ Universal SVG Icons

A framework-agnostic, customizable, and lightweight SVG icon package for React, Vue, Angular, and other JavaScript frameworks.


๐Ÿš€ Features

  • โœ… 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

๐Ÿ“ฆ Installation

Using npm

npm install universal-svg-icons

Using yarn

yarn add universal-svg-icons

โœจ Usage Examples

โœ… React (JSX Element or Icon Wrapper)

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" />
      ...
    </>
  );
}

๐ŸŒ Vanilla JS / HTML (HTML Element)

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;

๐Ÿ”ง Vue

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>

๐Ÿ…ฐ๏ธ Angular

Use property binding in templates:

Template:

<svg width="32" height="32">
  <path [attr.d]="checkIconPath" fill="black" />
</svg>

Component:

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();
}

๐ŸŒ Pure HTML Usage (via CDN)

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.

๐ŸŒ Pure HTML Usage (via CDN)

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.


๐Ÿ› ๏ธ API Reference

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

๐ŸŽจ Available Icons

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 />
โš ๏ธ Warning getWarningIconPath <WarningIcon />

Example Usage:

import { IconWrapper, getMailIconPath, MailIcon } from "universal-svg-icons";

```

โšก Performance Optimizations

  • ๐Ÿ“ฆ Tree-shakable: Only includes icons you use
  • ๐Ÿงฉ Dual build system: Supports both CJS & ESM
  • ๐Ÿ› ๏ธ Type-safe: Written in TypeScript

๐Ÿ› ๏ธ Development & Contribution

We welcome contributions! Here's how to get started:

Setup

git clone https://github.com/tsb04/universal-svg-icons.git
cd universal-svg-icons
npm install
npm run build

Add a New Icon

  1. Add your SVG path to /src/icons/
  2. Export it in /src/index.ts

Create a Feature Branch

git checkout -b feature/new-icon

Commit & Push

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 with viewBox="0 0 24 24". Use the scale.py script to scale your icon's SVG path to the required size automatically.


๐Ÿ“œ License

Licensed under the ISC License.


๐Ÿ“ฌ Contact & Support

  • ๐Ÿž Report Issues
  • ๐Ÿ’ก Request Features via GitHub Discussions
  • ๐Ÿ’ฌ Need help? Start a GitHub Discussion

โญ Like This Project?

If this project helps you, please โญ star it on GitHub and share it. Made with โค๏ธ by tsb04 โ€” Happy coding! ๐ŸŽ‰

About

No description, website, or topics provided.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •