mochicons
v0.8.1
Published
An open source and hand-crafted SVG icons library
Readme
mochicons
A collection of hand-made and open source SVG icons that you can use in your web projects. Each icon has been designed in a 24x24 grid with a stroke width of 2px and a minimum padding of 2px.
This package provides SVG icons in multiple formats, including React components, CSS variables (data URIs), and SVG sprites.
Features
- Multiple Formats: React components, CSS, SVG Sprite, and JSON metadata.
- Highly Customizable: Control size, color, and stroke width with ease.
- Tree Shakeable: Only include the icons you actually use in your React project.
- Premium Design: Consistent 24x24 grid with a clean, modern aesthetic.
Installation
Add the icons package to your project by running:
## using npm
$ npm install mochicons
## using yarn
$ yarn add mochicons
## using pnpm
$ pnpm add mochiconsUsage
The easiest way is downloading or copying the icons from https://josemi.xyz/mochicons. Each icon consists in a <svg> tag and a single <path>.
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">
<path
fill="none"
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M...."
/>
</svg>You can also include the icons as images in a <img> element using a public CDN:
<img src="https://unpkg.com/mochicons/icons/activity.svg" />React
The React distribution provides individual components for each icon, a base Icon component, and a renderIcon utility.
Individual Components
import { AccessPointIcon, ActivityIcon } from "mochicons/react";
const MyComponent = () => (
<div>
<AccessPointIcon size="24px" color="blue" stroke={2} />
<ActivityIcon size="1.5em" color="currentColor" />
</div>
);Base Icon Component
If you have the icon path data, you can use the base Icon component:
import { Icon } from "mochicons/react";
const CustomIcon = () => (
<Icon path="M..." size="24px" color="red" stroke={1.5} />
);Dynamic Rendering
Use renderIcon to render icons dynamically by their name:
import { renderIcon } from "mochicons/react";
const DynamicIcon = ({ name }) => {
return renderIcon(name) || <span>Icon not found</span>;
};CSS
The CSS distribution provides icons as data URIs. You can use them via CSS classes or directly via CSS variables.
- Import the CSS:
@import "mochicons/css";Class-based Usage
Use the mi- prefix followed by the icon name:
<i class="mi-access-point" style="color: blue; font-size: 24px;"></i>CSS Variable Usage
This is perfect for use in background-image or mask-image:
.my-element {
width: 24px;
height: 24px;
background: var(--mochicons-access-point) no-repeat center;
background-size: contain;
}SVG Sprite
For projects using SVG sprites, you can reference symbols directly from icons.svg.
<svg width="24" height="24">
<use href="node_modules/mochicons/icons.svg#access-point"></use>
</svg>Metadata & Schema
If you are building your own tools or need icon metadata, you can use the JSON distribution:
import iconsMetadata from "mochicons/json";
console.log(iconsMetadata.icons); // Array of { name, path }A JSON Schema is also provided at mochicons/schema.
Customization
Icons are designed on a 24x24 grid. Most icons support the following props (in React) or equivalent CSS properties:
- Size: Defaults to
1em. - Color: Defaults to
currentColor. - Stroke: Defaults to
2. Supports numeric values forstroke-width.
License
Code is licensed under the MIT LICENSE.
Icons in this repository are Public Domain. You can use, copy, modify, distribute, or display the icons without any restrictions or attribution requirements. They are offered on an "as-is" basis, without warranties or conditions of any kind.
By using the icons in this repository, you agree that they are provided without any warranty, and the author(s) shall not be liable for any claim, damages, or other liability arising from the use of the icons.
