Categories: CSSScriptWeb Design

Themeable Icon Picker In Vanilla JavaScript

A customizable, themeable icon picker that supports popular icon libraries like Font Awesome 6/7, Material Design Icons, and much more.

Table of Contents

Toggle

How to use it:

1. Load the main script icon-picker.min.js at the end of the document.

<script src="dist/icon-picker.min.js"></script>

2. Load a theme of your choice in the document. The library currently comes with 2 themes:

  • Default
  • Bootstrap 5
<!-- Default Theme -->
<link rel="stylesheet" href="dist/themes/default.min.css">
<!-- Bootstrap 5 Theme (Requires Bootstrap 5 Stylesheet) -->
<link rel="stylesheet" href="/path/to/cdn/bootstrap.min.css" />
<link rel="stylesheet" href="dist/themes/bootstrap-5.min.css">
Sponsored

3. Attach the icon picker to a trigger element like input or button.

<input type="text" id="icon-picker">
const iconPickerDemo = new IconPicker('input', {
      // options here
});

4. Set the theme of the icon picker.

const iconPickerDemo = new IconPicker('input', {
      theme: 'bootstrap-5',
});

5. Determine whether to close the icon picker after an icon has been selected. Default: true.

const iconPickerDemo = new IconPicker('input', {
      closeOnSelect: false,
});

6. Add more icon libraries to the icon picker. ‘FontAwesome Brands 5’ | ‘FontAwesome Solid 5’ | ‘FontAwesome Regular 5’ | ‘Material Design Icons’ | ‘Iconoir’, or a custom JSON path.

const iconPickerDemo = new IconPicker('input', {
      iconSource: [],
});
const iconPickerDemo = new IconPicker('input', { 
      iconSource: [
      {
        key: 'academicons',
        prefix: 'ai ai-',
        url: 'https://raw.githubusercontent.com/iconify/icon-sets/master/json/academicons.json'
      }], 
});

7. API methods.

// open the icon picker
iconPickerDemo.open();

// close the icon picker
iconPickerDemo.hide();

// clear the icon
iconPickerDemo.clear();

// check if the icon picker is opened
iconPickerDemo.isOpen();

// check if the icons are loaded
iconPickerDemo.iconsLoaded();

// destroy the instance
iconPickerDemo.destroy(deleteInstance);

8. Event handlers.

iconPickerDemo.on('select', (icon) => {
  // do something
});

iconPickerDemo.on('save', (icon) => {
  // do something
});

iconPickerDemo.on('clear', (icon) => {
  // do something
});

iconPickerDemo.on('show', instance => {
  // do something
});

iconPickerDemo.on('hide', instance => {
  // do something
});

Changelog:

v1.4.2 (11/04/2025)

  • Add FontAwesome 7

v1.4.1 (05/19/2025)

  • Add iconsLoaded method to check loading state of icons

v1.3.1 (08/09/2024)

Sponsored
  • Categories fix

v1.3.0 (02/21/2024)

  • feat: Add search by categories

v1.2.1 (10/03/2023)

  • Update

v1.2.0 (07/22/2023)

  • Add clear() method
  • Allow setting of ‘iconFormat’ in icon json so we can improve performance

v1.1.3 (04/01/2022)

  • Update dependencies and resolve deprecated webpack’s plugin
  • fix: Accessibility improvement

v1.1.2 (03/31/2022)

  • Updated dependencies

v1.1.0 (03/11/2022)

  • Add custom json path
  • Fix z-index problem

v1.0.0 (11/18/2021)

  • Add possibility to add more icons library
  • Set default value for input target

11/15/2021

  • fix: Add missing ‘!default’ and add variables

The post Themeable Icon Picker In Vanilla JavaScript appeared first on CSS Script.

rssfeeds-admin

Share
Published by
rssfeeds-admin

Recent Posts

How Fritz Lang’s Metropolis Created the Blueprint for Modern Science Fiction (1927)

A vast, miserable proletariat squanders its days in meaningless toil. Society is under the control…

16 seconds ago

Ultrahuman’s new flagship smart ring has a 15-day battery

The Ultrahuman Ring Pro comes with a snazzy Pro Charging Case for up to 45…

21 seconds ago

Notes from a Burmese Prison

This story is a comic by Danny Fenster and Amy Kurzweil and is not compatible…

22 seconds ago

Phones are going to get weird next week

Honor’s Robot Phone is set to make an appearance, and this time we might actually…

24 seconds ago

Juniper Networks PTX Vulnerability Enables Full Router Takeover

A major networking vendor has issued an out-of-cycle security bulletin to address a critical vulnerability…

14 minutes ago

Microsoft Defender Expands URL Click Alerts to Include Microsoft Teams for Enhanced Security Visibility

Microsoft is strengthening its cybersecurity ecosystem by extending Microsoft Defender for Office 365 (MDO) URL…

14 minutes ago

This website uses cookies.