kristianpennacchia

payload icon picker

by kristianpennacchia
Custom fields
v4
4.0.0-beta.10
MIT

Overview

Summary generated from the README

A field plugin for Payload CMS v4 that lets editors pick icons from any icon pack, such as react-icons or lucide-react, through a searchable dropdown or a sliding drawer grid. The selected icon name and raw SVG are saved as JSON, so the frontend needs no icon library. It can add fields to collections automatically or be used via an iconField helper. It is a fork of an earlier plugin and requires exactly payload 4.0.0-beta.10.

Features

  • Searchable virtualized dropdown or drawer grid presentation modes
  • Fuzzy, typo-tolerant icon search
  • Stores icon name and raw SVG as JSON in the database
  • Global or collection-specific icon packs via a client provider
  • Multi-select with hasMany and optional close on select
  • IconRenderer component to render saved SVGs on the frontend

Use cases

  • Add selectable icons to blocks, pages or categories without bundling an icon library on the frontend
  • Let editors choose several icons per document from large icon packs
  • Restrict different collections to different custom SVG icon sets

From the author

A dynamic icon picker field plugin for Payload CMS v4 supporting custom icon packs, searching, and custom SVG rendering.

Installation

npm i @kristianpennacchia/payload-icon-picker

0

Stars

0

Forks

0

Open Issues

1 weeks ago

Last Updated

34

Weekly Downloads

v1.5.12-payload-v4.3

npm Version

112.5 KB

Unpacked Size

3

Dependencies

GitHub stars

00 since Nov 22

Show data
GitHub stars by day (UTC)
DateStars
Dec 5, 20260
Dec 4, 20260
Dec 3, 20260
Dec 2, 20260
Dec 1, 20260
Nov 30, 20260
Nov 29, 20260
Nov 28, 20260
Nov 27, 20260
Nov 26, 20260
Nov 25, 20260
Nov 24, 20260
Nov 23, 20260
Nov 22, 20260
npm weekly downloads

42+42 since Nov 25

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 5, 202642
Dec 4, 202662
Dec 3, 2026250
Dec 2, 2026249
Dec 1, 2026244
Nov 30, 2026237
Nov 29, 2026227
Nov 28, 2026219
Nov 27, 2026193
Nov 26, 20260
Nov 25, 20260

Each point is npm's rolling 7-day download count.

Health Score

71/100Good

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1469528735-root.svg)](https://payloaddirectory.dev/plugins/1469528735-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1469528735-root"><img src="https://payloaddirectory.dev/badge/1469528735-root.svg" alt="Payload Directory"></a>
Updated Nov 24, 2026Created Nov 24, 2026Published Nov 24, 2026

README

payload-icon-picker

Fork of payload-icon-picker by Vachagan Achoyan, updated for Payload CMS v4. The original GitHub repository is no longer available; the original package remains on npm (1.5.12 for Payload 3.x).

Changes in this fork

  • Targets the exact Payload 4.0.0-beta.10 prerelease (payload and @payloadcms/ui peers).
  • Describes the stored icon value with Payload v4's JSON field jsonSchema option, replacing the removed typescriptSchema.
  • Validates icon values directly instead of compiling the JSON schema at runtime, so validation also works in Cloudflare Workers.
  • Uses Payload v4's field path API and passes required through to the field and its label.
  • Replaces Payload 3's removed --theme-* admin variables with v4 semantic tokens.
  • Styles the list-view cell and unselected drawer icons with v4's secondary button style and medium size, replacing the removed subtle style and xsmall size.

The public imports, options and stored { name, svg } value shape are unchanged from the original.


A field plugin for Payload CMS v4 that adds a highly optimized icon picker. It supports both a searchable dropdown interface and an advanced grid-based sliding drawer panel. It automatically extracts and saves the selected icon name and its raw SVG string to the database, allowing you to render icons on your frontend without importing or bundling heavy icon packages.

Features

  • Multiple Presentation Modes:
    • select (Default): A sleek, searchable, and virtualized dropdown list.
    • drawer: An advanced layout that opens a sliding side panel containing a performance-focused, virtualized grid of icons.
  • Smart UX Carousel in Drawer: Selected icons are safely duplicated inside a dedicated sticky basket bar at the top of the grid. Users can click to remove them instantly without losing their scroll positions in the alphabetized grid.
  • SVG Extraction: The raw SVG is extracted and saved directly to the database as JSON, meaning zero icon package dependencies are required on your client-facing frontend.
  • Virtualized Grid & Lists: Powered by @tanstack/react-virtual to seamlessly handle icon packs with over 10,000+ items without a single drop in frame rate or input latency.
  • Custom & Collection-Specific Icon Packs: Supports any icon pack (such as react-icons or custom SVG sets) globally or mapped to specific collections.
  • Fuzzy Searching: Powered by fuse.js to provide lightning-fast, typo-tolerant search across all icon names in both drawer and dropdown modes.
  • Multi-select Support: Full support for choosing multiple icons when hasMany: true is configured.
  • Close on Select: Optionally auto-close the drawer the moment an icon is picked in single-select mode — no need to hit the X button.

Installation

This fork is published as @kristianpennacchia/payload-icon-picker. Install it under the original package name, payload-icon-picker, so the imports in this README and the admin components the field registers (payload-icon-picker/client#…) resolve:

# npm
npm install payload-icon-picker@npm:@kristianpennacchia/payload-icon-picker

# pnpm
pnpm add payload-icon-picker@npm:@kristianpennacchia/payload-icon-picker

It requires Node.js ^24.22.3 || >=26.13.1 and exactly [email protected] and @payloadcms/[email protected].

Usage

1. Register the Plugin in payload.config.ts

The plugin can automatically add fields to collections and/or register a global icon provider.

import { buildConfig } from 'payload'
import { payloadIconPicker } from 'payload-icon-picker'

export default buildConfig({
  plugins: [
    payloadIconPicker({
      // 1. (Optional) Auto-add fields to collections
      collections: {
        categories: true,
        posts: {
          name: 'postIcon',
          label: 'Post Icon',
        },
      },
      // 2. (Optional) Register a global provider for icons
      iconPackProviderPath: './components/IconPackProvider#IconPackProvider',
    }),
  ],
})

2. Create a Client Provider (Optional)

If you want to use a global set of icons, create a client-side provider. If you don't provide this, you'll need to pass icons directly to the field (see "Standalone Use" below).

Create a file (e.g., components/IconPackProvider.tsx):

'use client'

import React from 'react'
import { IconPackProvider as BaseProvider } from 'payload-icon-picker/client'
import { icons as LucideIcons } from 'lucide-react'
import * as FontAwesomeIcons from 'react-icons/fa'

export const IconPackProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
  return (
    <BaseProvider
      icons={LucideIcons} // Global fallback
      collections={{
        posts: FontAwesomeIcons, // Collection-specific
      }}
    >
      {children}
    </BaseProvider>
  )
}

[!NOTE]

💡 Integration Tip for lucide-react Users

If you want to use the lucide-react package as your icon provider, avoid using wildcard imports (import * as Lucide). Wildcard imports pull in internal component factories and configuration utilities that can cause runtime scrolling errors in Next.js 16 / Turbopack environments.

Instead, import the clean icons object directly:

import { icons as LucideIcons } from 'lucide-react'

// Pass `LucideIcons` into your IconPackProvider

This guarantees a 100% stable, fast, and seamless virtualized scrolling experience in the Payload admin panel.

Advanced Usage

Using in Blocks or Globals

You can inject the icon picker manually anywhere inside your fields schema (Collections, Blocks, Globals) using the exported iconField helper. You can now define whether it should display as a standard dropdown list or a sliding drawer layout using the displayMode flag.

import { iconField } from 'payload-icon-picker'

export const MyBlock = {
  slug: 'iconBlock',
  fields: [
    // Standard Searchable Dropdown mode (Default)
    iconField({
      name: 'icon',
      label: 'Block Icon',
      hasMany: false,
    }),

    // Sliding Drawer mode (multi-select)
    iconField({
      name: 'drawerIcon',
      label: 'Drawer Icon',
      hasMany: true,
      displayMode: 'drawer',
    }),

    // Sliding Drawer mode that closes automatically on pick
    iconField({
      name: 'quickIcon',
      label: 'Quick Icon',
      hasMany: false,
      displayMode: 'drawer',
      closeOnSelect: true,
    }),
  ],
}

Standalone (Isolated) Use

If you want to use a specific icon pack for a single field without registering a global provider, create a simple client-side wrapper:

1. Create the wrapper (components/CustomIconPicker.tsx):

'use client'
import React from 'react'
import { IconPicker } from 'payload-icon-picker/client'
import { icons as MyIcons } from 'lucide-react'

export const CustomIconPicker = (props) => <IconPicker {...props} icons={MyIcons} />

2. Use it in your field config:

import { iconField } from 'payload-icon-picker'

const myField = iconField({
  admin: {
    components: {
      Field: './components/CustomIconPicker#CustomIconPicker',
    },
  },
})

Rendering Icons on the Frontend

The plugin exports an IconRenderer helper component that converts a saved SVG string back into a proper React element. It parses the raw SVG, forwards your props (className, color, size, etc.) onto the root <svg> element, and requires zero icon-library dependencies on your frontend.

import { IconRenderer } from 'payload-icon-picker/client'

// Assuming `icon` was fetched from Payload (see Database Schema below)
;<IconRenderer svgString={icon.svg} size={32} color="currentColor" className="my-icon" />

Props

PropTypeRequiredDescription
svgStringstring✅The raw SVG string saved by the icon picker field.
sizenumber | string—Sets both width and height on the <svg> element.
colorstring—Overrides fill and stroke colors where applicable.
classNamestring—Appended to the SVG's existing class names.
...restReact.SVGProps<SVGSVGElement>—Any additional SVG attributes are forwarded through.

Database Schema

When saved, the field outputs a structured object (or an array of objects if hasMany: true), preserving both semantic names and optimized SVG paths directly into your records. Saved values must have exactly the string properties name and svg:

// Single Select Mode (hasMany: false)
"icon": {
  "name": "LuAperture",
  "svg": "<svg stroke=\"currentColor\" fill=\"none\" stroke-width=\"2\" viewBox=\"0 0 24 24\" ... >...</svg>"
}

// Multi Select Mode (hasMany: true)
"icons": [
  {
    "name": "LuAperture",
    "svg": "<svg ... >...</svg>"
  },
  {
    "name": "LuArrowDown",
    "svg": "<svg ... >...</svg>"
  }
]

Configuration Reference

Plugin Options (PayloadIconPickerConfig)

OptionTypeDefaultDescription
collectionsRecord<string, boolean | Options>undefinedDictionary of collection slugs to append the icon field to.
iconPackProviderPathstringundefinedPath to the global client provider.
namestring'icon'Global fallback field name.
hasManybooleanfalseGlobal fallback for multi-select.
closeOnSelectbooleanfalseGlobal fallback: auto-close the drawer after selecting an icon (drawer mode, single-select only). Also settable per collection inside collections.
labelstring'Icon'Global fallback label.
requiredbooleanfalseGlobal fallback: require an icon. Also settable per collection inside collections.
displayMode'drawer' | 'select''select'Global fallback display mode.
disabledbooleanfalseIf true, disables the plugin.
drawerItemsPerRownumber20Global fallback for number of icons per row in drawer mode.
drawerIconSizenumber24Global fallback for icon display size inside the drawer.
drawerRowHeightnumber80Global fallback for virtualized row container height.

Field Options (iconField)

OptionTypeDefaultDescription
namestring'icon'Field name.
labelstring'Icon'Field label.
hasManybooleanfalseEnable multi-select.
requiredbooleanfalseRequire an icon (at least one with hasMany).
closeOnSelectbooleanfalseAuto-close the drawer after selecting an icon (drawer mode, ignored when hasMany: true).
descriptionstringundefinedHelper text.
displayMode'drawer' | 'select''select'Display mode.
drawerItemsPerRownumber20Number of icons per row in drawer mode.
drawerIconSizenumber24Icon rendering size inside the drawer.
drawerRowHeightnumber80Virtualized row container height.
adminFieldAdminundefinedStandard Payload admin field config.

Development

npm install
npm run build
npm test

License

MIT. Original work © 2026 Vachagan Achoyan; Payload v4 changes © 2026 Kristian Pennacchia. See LICENSE.

Tags

Similar plugins