Codicons

repository·main·Indexed 22 days ago

https://github.com/microsoft/vscode-codicons

A collection of icons used in Visual Studio Code, provided as an icon font and SVG sprites. This library allows developers to integrate VS Code's icon set into projects via the @vscode/codicons npm package, using either CSS classes or SVG sprites.

Tokens
848
Snippets
5
Records
6
Agent score
28%

What's inside @vscode/codicons

  1. Add new icons to the repository

    main

    To add new icons to the Codicons set:

    1. Export your icons as SVG files to the src/icons folder.
    2. Add a new entry to src/template/mapping.json with a new codepoint key (this is converted into a unicode key).
    3. Run the build command: npm run build. Note that the build process removes subfolders in the icons folder to maintain a consistent structure.
    4. (For VS Code contributors) Update the codicon.ttf file in the VS Code repository.

    Troubleshooting: If icons appear broken after font conversion (common when exporting from Figma), sanitize the SVGs using a tool like svg-reorient.

  2. Build Codicons locally

    main

    If you are developing or modifying the Codicons repository, follow these steps to build the project:

    1. Install dependencies:
      npm install
    
    2. **Run the build command:**
       ```bash
    npm run build

    All icons are stored in src/icons. The class name mappings and unicode characters are defined in src/template/mapping.json, and default styles are in src/template/styles.hbs.

    npm install
    npm run build
  3. Use Codicons via CSS Classes

    main

    To reference an icon using CSS classes, create a DOM element that includes both the codicon class and the specific icon name class (prefixed with codicon-).

    Best Practice: Use a single DOM element for each icon and avoid adding child elements to it.

    <div class='codicon codicon-add'></div>
  4. SVGO configuration for Codicons

    main

    The Codicons repository uses SVGO (SVG Optimizer) to process icon files. The configuration is designed to ensure icons are compatible with CSS styling by removing hardcoded fill attributes and replacing them with currentColor. This allows the icons to inherit the text color of their parent container.

    module.exports = {
        plugins: [
            {
                name: 'removeAttrs',
                params: {
                    attrs: 'fill'
                }
            },
            {
                name: 'addAttributesToSVGElement',
                params: {
                    attributes: [
                        {
                            fill: 'currentColor'
                        }
                    ]
                }
            }
        ]
    }