IconPark Documentation

repository·master·Indexed 27 days ago

https://github.com/bytedance/iconpark

An icon library featuring over 2000 high-quality icons with a system for transforming a single SVG source into multiple themes: outline, filled, two-tone, and multi-color. It provides dedicated packages for React (@icon-park/react), Vue 2 (@icon-park/vue), Vue 3 (@icon-park/vue-next), and pure SVG (@icon-park/svg). Supports tree-shaking, on-demand loading via babel-plugin-import, and global configuration through IconProvider or setConfig.

Tokens
6.9K
Snippets
31
Records
55
Agent score
93%

What's inside IconPark

  1. Configure global icon settings via provide

    master

    You can set global configuration for all icons by using Vue's provide API with the ICON_CONFIGS key. This allows you to override default settings like the prefix globally.

    <template>
    <div>
    <home/>
    </div>
    </template>
    <script lang="ts">
    import {DEFAULT_ICON_CONFIGS} from '@icon-park/vue'
    import {Home} from '@icon-park/vue';
    
    const IconConfig = {...DEFAULT_ICON_CONFIGS, prefix: 'icon'}
    
    export default {
        name: 'App',
        provide () {
            return {
                ICON_CONFIGS: IconConfig
            }
        },
        components: {
            Home
        }
    };
    </script>
  2. Customize icon themes and colors

    master

    IconPark uses a technology that transforms a single SVG source into multiple themes by adjusting fill and stroke attributes. You can switch between the following themes:

    • outline
    • filled
    • two-tone
    • multi-color

    Coloring Rules:

    • Basic coloring: Set the fill attribute. fill sets the color inside the object, while stroke sets the color of the lines.
    • Two-tone/Multi-color: Pass an array of colors to the fill prop to apply different colors to different parts of the icon.
  3. Configure Import on Demand with babel-plugin-import

    master

    To reduce bundle size, use babel-plugin-import to load icons on demand. Configure your Babel settings as follows:

    {
        "plugins": [
            [
                "import",
                {
                    "libraryName": "@icon-park/vue",
                    "libraryDirectory": "es/icons",
                    "camel2DashComponentName": false 
                }
            ]
        ]
    }
  4. Install IconPark globally

    master

    To avoid manual imports for every icon, you can install IconPark globally in your Vue app. This allows you to use icons via a prefix (e.g., icon-people for the People icon).

    By default, the prefix is icon. You can specify a custom prefix as the second argument to install().

    import {install} from '@icon-park/vue-next/es/all';
    import {createApp} from 'vue';
    
    const app = createApp({});
    
    // Install with default prefix 'icon' (e.g., <icon-people />)
    install(app);
    
    // Install with custom prefix 'i' (e.g., <i-people />)
    install(app, 'i');
    
    app.mount('#app');
  5. Install icons globally

    master

    To use icons globally without manual imports in every component, use the install method from @icon-park/vue-next/es/all.

    By default, the component prefix is icon (e.g., People becomes icon-people). You can provide a custom prefix as the second argument to install (e.g., i makes it i-people).

    import {install} from '@icon-park/vue-next/es/all';
    import {createApp} from 'vue';
    
    const app = createApp({});
    
    // Install with default prefix 'icon'
    install(app); 
    
    // Install with custom prefix 'i'
    install(app, 'i'); 
    
    app.mount('#app');
  6. Enable on-demand loading with babel-plugin-import

    master

    To reduce bundle size, use babel-plugin-import to load icons on demand. Configure the plugin in your Babel configuration as follows:

    {
        "plugins": [
            [
                "import",
                {
                    "libraryName": "@icon-park/react",
                    "libraryDirectory": "es/icons",
                    "camel2DashComponentName": false 
                }
            ]
        ]
    }