An open API service indexing awesome lists of open source software.

https://github.com/xandertreat/solid-iconify

A light-weight and performant native Solid.js first class Iconify component with configuration and type-safety
https://github.com/xandertreat/solid-iconify

component esm icon iconify js jsx npm solidjs svg ts tsx vector

Last synced: about 2 months ago
JSON representation

A light-weight and performant native Solid.js first class Iconify component with configuration and type-safety

Awesome Lists containing this project

README

          

# @xtreat/solid-iconify

[![npm version](https://img.shields.io/npm/v/@xtreat/solid-iconify?color=blue&logo=npm)](https://www.npmjs.com/package/@xtreat/solid-iconify)
[![npm downloads](https://img.shields.io/npm/dm/@xtreat/solid-iconify?color=blueviolet)](https://www.npmjs.com/package/@xtreat/solid-iconify)
[![Bundle Size](https://img.shields.io/bundlephobia/minzip/@xtreat/solid-iconify?label=bundlephobia)](https://bundlephobia.com/package/@xtreat/solid-iconify)
[![Types](https://img.shields.io/npm/types/@xtreat/solid-iconify?label=types)](https://www.npmjs.com/package/@xtreat/solid-iconify)

[![CI Checks](https://img.shields.io/github/actions/workflow/status/xandertreat/textual-theme-gen/ci.yml?branch=main)](https://github.com/xandertreat/textual-theme-gen/actions)
[![Maintained](https://img.shields.io/badge/maintained-yes-brightgreen)](https://img.shields.io/badge/maintained-yes-brightgreen)
[![Open Issues](https://img.shields.io/github/issues/xandertreat/textual-theme-gen)](https://github.com/xandertreat/textual-theme-gen/issues)
[![Open PRs](https://img.shields.io/github/issues-pr/xandertreat/textual-theme-gen?color=purple)](https://github.com/xandertreat/textual-theme-gen/pulls)

[![MIT License](https://img.shields.io/badge/license-MIT-success?logo=open-source-initiative&logoColor=white)](https://github.com/xandertreat/textual-theme-gen/blob/main/LICENSE)
[![Code Style: Biome](https://img.shields.io/badge/code%20style-biome-5ed9c7?logo=biome&logoColor=white)](https://biomejs.dev/)
[![SolidJS](https://img.shields.io/badge/SolidJS-1.9.0+-blue?logo=solid)](https://www.solidjs.com/)

[![Forks](https://img.shields.io/github/forks/xandertreat/textual-theme-gen?style=social)](https://github.com/xandertreat/textual-theme-gen/fork)
[![GitHub stars](https://img.shields.io/github/stars/xandertreat/textual-theme-gen?style=social)](https://github.com/xandertreat/textual-theme-gen)
[![Visitors](https://visitor-badge.laobi.icu/badge?page_id=xandertreat.textual-theme-gen)](https://visitor-badge.laobi.icu/badge?page_id=xandertreat.textual-theme-gen)

A blazing-fast, fully reactive, and type-safe [SolidJS](https://www.solidjs.com/) component for rendering [Iconify](https://iconify.design/) icons. Designed for both SSR and client-side rendering, with first-class TypeScript support, flexible configuration, and zero runtime dependencies (besides SolidJS).

---

## โœจ Features

- **Reactive**: Icons update automatically when props change.
- **Type-Safe**: Full TypeScript support, including strict icon specifier validation.
- **SSR-Ready**: Works seamlessly with SolidJS server-side rendering.
- **Configurable**: Customize API endpoints, caching, SVG defaults, and more.
- **Flexible**: Supports all Iconify icon sets and custom collections.
- **Lightweight**: Minimal runtime, no unnecessary dependencies.
- **Secure**: Optional sanitization with [xss](https://www.npmjs.com/package/xss).
- **Modern**: ESM-only, ships with `.jsx` and TypeScript types

---

## ๐Ÿš€ Quick Start

### 1. Install

```sh
npm install @xtreat/solid-iconify
# or
yarn add @xtreat/solid-iconify
# or
bun add @xtreat/solid-iconify
```

### 2. Usage

```tsx
import Icon from "@xtreat/solid-iconify";

function App() {
return (
<>


>
);
}

export default App;
```

#### With Custom Configuration

```tsx
import { configureIconify } from "@xtreat/solid-iconify";

configureIconify({
ICONIFY_API: ["api.iconify.design", "yourapihere.com"],
SANITIZE: true,
});
```

---

## ๐Ÿงฉ API

### `` Props

| Prop | Type | Description |
|--------------|-------------------------|-----------------------------------|
| `icon` | `string` (e.g. `mdi:account`) | **Required.** Iconify icon specifier |
| ...SVG props | | Any valid SVG attribute |

### `configureIconify(config)`

Configure global defaults for all icons. Accepts a partial config object:

```ts
configureIconify({
ICONIFY_API: string | URL | Array,
REQUEST_OPTIONS: RequestInit,
CACHE_SIZE: number | { strategy: "grow" | "static" | "unlimited" },
COLLECTION_SIZE: number | { strategy: "grow" | "static" | "unlimited" },
DEFAULT_SVG_ATTRIBUTES: Partial>,
SANITIZE: boolean,
SANITIZE_OPTIONS: Partial,
});
```

---

## ๐Ÿ—๏ธ How It Works

- **Reactive Fetching:** Uses Solid's `createResource` to fetch and cache SVGs from the Iconify API.
- **Caching:** LRU cache for icons and collections, configurable for memory efficiency.
- **Sanitization:** Optionally sanitizes SVGs for XSS protection.
- **SSR Support:** Works in both server and client environments.

---

## ๐Ÿงช Testing

This package uses [Vitest](https://vitest.dev/) for unit and e2e tests. To run tests:

```sh
npm test
```

---

## ๐Ÿ“ฆ Build & Publish

- Build: `npm run build`
- Lint: `npm run lint`
- Format: `npm run format`
- Type-check: `npm run check`

---

## ๐Ÿ›ก๏ธ TypeScript Types

All types are exported:

```ts
import type {
IconifyIconProps,
IconifyConfig,
// ...etc
} from "@xtreat/solid-iconify";
```

---

## ๐Ÿ“š Example

```tsx
import Icon from "@xtreat/solid-iconify";

```

---

## ๐Ÿ’ฌ Feedback & Contributions

Issues and PRs are welcome! [Open an issue](https://github.com/xandertreat/solid-iconify/issues) or [submit a pull request](https://github.com/xandertreat/solid-iconify/pulls).

---

## ๐Ÿ”— Links

- [Iconify Icon Explorer](https://icon-sets.iconify.design/)
- [SolidJS Docs](https://www.solidjs.com/docs)
- [Project Repository](https://github.com/xandertreat/solid-iconify)

---

## ๐Ÿž Known Bugs

- **Icon reactivity broken**: Changing the `icon` prop does not always update the rendered SVG as expected.

---

## ๐Ÿ“ License

MIT ยฉ 2025 Xander Treat