Git Product home page Git Product logo

vanilla-icon-picker's Introduction

Vanilla icon picker

GitHub package.json version npm GitHub

Icons includes:

  • FontAwesome 5 (Brands, Solid and Regular)
  • Material Design Icons
  • Iconoir

Getting started

Node

Install via npm or yarn

// NPM
npm i vanilla-icon-picker

// YARN
yarn add vanilla-icon-picker
// One of the following themes
import 'vanilla-icon-picker/dist/themes/default.min.css'; // 'default' theme
import 'vanilla-icon-picker/dist/themes/bootstrap-5.min.css'; // 'bootstrap-5' theme

import IconPicker from 'vanilla-icon-picker';

⚠️ Attention: If you use bootstrap theme dont forget to include bootstrap 5 css.

Usage

const iconPicker = new IconPicker('input', {
    // Options
});

Live demo →

Options

💙 You can find icons sets at Iconify

{
    // Change icon picker's theme
    theme: 'default' | 'bootstrap-5',

    // Set icon(s) library(ies)
    // iconSource: [
    //     'FontAwesome Brands 5', 
    //     'FontAwesome Solid 5', 
    //     'FontAwesome Regular 5', 
    //     'Material Design Icons', 
    //     'Iconoir', 
    //     {
    //         key: 'academicons',
    //         prefix: 'ai ai-',
    //         url: 'https://raw.githubusercontent.com/iconify/icon-sets/master/json/academicons.json'
    //     }
    // ]
    iconSource: [],

    // Close icon picker modal when icon is selected
    // If is `false` save button appear
    closeOnSelect: true,
    
    // Set a default value, preselect for example
    // icon's value and icon's name work
    defaultValue: null,
        
    // Translatable text
    i18n: {
        'input:placeholder': 'Search icon…',
            
        'text:title': 'Select icon',
        'text:empty': 'No results found…',
            
        'btn:save': 'Save'
    }
}

Events

Use the on(event, callback) and off(event, callback) functions to bind / unbind eventlistener.

Event Description Arguments
select Icon is selected, return icon value, name, svg and unicode if exist Object
save Fired when saved with button or if closeOnSelect option is true, return return icon value, name, svg and unicode if exist Object
show Modal is shown IconPickerInstance
hide Modal picker is hidden IconPickerInstance
iconPicker.on('select', instance => {
    console.log('Select:', instance);
});

Methods

After we initialize IconPicker, we have access instance. Let's look list all available methods:

Method Description
on() Add event handler
off() Remove event handler
open() Open IconPicker's modal
hide() Remove IconPicker's modal
isOpen() Check if open or not
destroy(deleteInstance) Set it to false (by default it is true) to not to delete IconPicker instance

Licence

MIT Licence

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.