stingray-icons
v1.0.4
Published
A simple, maintainable React icon library using Vite and Storybook. Each icon is available as: - A React component (for easy use in React projects) - A pure SVG export (for use outside React)
Readme
Stingray Icons
A simple, maintainable React icon library using Vite and Storybook. Each icon is available as:
- A React component (for easy use in React projects)
- A pure SVG export (for use outside React)
📦 Project Structure
stingray-icons/
├── src/
│ ├── assets/svg/ # SVG icon files
│ ├── components/icons/ # React icon components
│ │ ├── icons/ # Individual icon components (e.g., Add.jsx)
│ │ ├── index.js # Central export for icons (auto-generated)
│ │ └── IconWrapper.jsx # (Shared logic/styling)
│ ├── stories/IconGallery.stories.jsx # Storybook gallery
│ └── ... # App, main.jsx, etc.
├── .storybook/ # Storybook config
├── package.json
├── vite.config.js
├── scripts/generate-icon-index.cjs # (Automation script, run by pre-commit hook)
├── scripts/svg-to-react-icons.cjs # (SVG to React component conversion)
└── ...🚀 Getting Started
npm install
npm run dev # Start Vite dev server
npm run storybook # Start Storybook for icon gallery➕ Adding a New Icon
Follow these steps to add a new icon to the library:
Add SVG(s):
- Place your SVG file(s) in
src/assets/svg/(e.g.,MyIcon.svg).
- Place your SVG file(s) in
Commit the raw SVG(s):
- Stage and commit your new SVG file(s):
git add src/assets/svg/ git commit -m "feat(icons): add raw SVG(s) for new icon(s)" - This triggers the pre-commit hook, which will:
- Clean up all SVGs (replace
fill='black'withfill='currentColor', removewidth/heightattributes) - Automatically update the icon export index (
src/components/icons/index.js)
- Clean up all SVGs (replace
- Stage and commit your new SVG file(s):
Generate the React component(s):
- Run the automated script to convert all SVGs to React components:
node scripts/svg-to-react-icons.cjs - This will generate a
.jsxfile for each SVG insrc/components/icons/icons/, matching the project's conventions (named export, named import forIconWrapper,sizeandcolorprops, and{...props}on the SVG).
- Run the automated script to convert all SVGs to React components:
Commit the generated React component(s):
- Stage and commit the new/updated
.jsxfiles:git add src/components/icons/icons/ git commit -m "feat(icons): generate React components for new icon(s)"
- Stage and commit the new/updated
Note:
- You do not need to manually run the SVG cleanup scripts or the export index script; they are run automatically by the pre-commit hook when you commit SVGs.
- After running the conversion script, check the generated files to ensure they match your expectations.
🖼️ Using Icons
In React:
import { MyIcon } from 'src/components/icons'; // Set a specific size (in px, em, rem, etc.) <MyIcon size={32} color="#333" /> // Or let the icon scale with the font size of its container <div style={{ fontSize: 40 }}> <MyIcon color="rebeccapurple" /> </div>- If you provide a
sizeprop, the icon will use that value for both width and height. - If you omit the
sizeprop, the icon will scale with thefont-sizeof its parent (default is1em). - You can also control the icon size via CSS by setting
font-sizeon a parent element.
- If you provide a
As SVG:
- Use the raw SVG from
src/assets/svg/in any non-React project.
- Use the raw SVG from
📚 Storybook Icon Gallery
- Run
npm run storybookand visit the gallery at http://localhost:6006 - All icons are displayed with size and color controls.
📦 Publishing to npm
Build the library:
npm run build(or
yarn buildif you use Yarn)Update
package.jsonwith your desired name, version, andmain/modulefields.Remove
private: trueif present.Login to npm:
npm loginPublish:
npm publish --access public
🎨 Designer Contribution Guide
- Add new SVGs to
src/assets/svg/. - Keep SVGs clean: no inline styles, no extra metadata, use
currentColorfor fills/strokes. - Developers will convert SVGs to React components for use in the library.
- For bulk additions, coordinate with a developer to automate conversion.
🛠️ Automation
- The export index (
src/components/icons/index.js) is automatically updated by the pre-commit hook when you commit SVGs. - To generate React components from SVGs, run:
node scripts/svg-to-react-icons.cjs - You do not need to run any other scripts manually.
For questions or contributions, open an issue or PR!
