Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@uxf/icons-generator

Package Overview
Dependencies
Maintainers
0
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@uxf/icons-generator

A well configurable tool for generating and managing custom SVG icons and sprites in web projects.

  • 11.32.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
160
decreased by-14.44%
Maintainers
0
Weekly downloads
 
Created
Source

@uxf/icons-generator

A well configurable tool for generating and managing custom SVG icons and sprites in web projects.

Quick Start

Installation

Use npm or yarn to install:

npm i -D @uxf/icons-generator
yarn add -D @uxf/icons-generator

Configuration

Create a icons.config.js file in your project's root:

module.exports = {
    icons: {
        test: {
            width: 24,
            height: 24,
            data: `<path fill="#fecd09" d="M33.03 17.44c-1.68 0-3.12-.99-3.79-2.42h7.58a4.181 4.181 0 01-3.79 2.42z" />`
        }
    }
}

See the full configuration options here.

Generating Icons

Run the generator:

icons-gen

For a custom config file name:

icons-gen --configFile=yourConfigFileName.js

Configuration Details

KeyTypeDefaultRequiredDescription
typescriptbooleantrueNo-
configDirectorystring"/src/config/"No-
generatedDirectorystring"/public/icons-generated/"No-
spriteFileNamestring_icon-sprite.svgNoSpecify custom sprite file name
typeNamestringIconsSetNo-
customDefinitionContentstring-No-
iconsRecord<string, SimpleIcon | SizedIcon | IconFromAdapterFunction>-YesMore details here
fallbackFilesDirectory--NoMore details here

Icon Types

SimpleIcon

type SimpleIcon = {
    data: string;
    height: number;
    width: number;
};

Example:

test: {
    width: 50,
    height: 60,
    data: `<path fill="#fecd09" d="M33.03 17.44c-1.68 0-3.12-.99-3.79-2.42h7.58a4.181 4.181 0 01-3.79 2.42z" />`,
}

SizedIcon

type SizedIcon = Record<number, string>;

Example:

test: {
    24: `<path fill="#fecd09" d="M33.03 17.44c-1.68 0-3.12-.99-3.79-2.42h7.58a4.181 4.181 0 01-3.79 2.42z" />`,
    44: `<path fill="#fecd09" d="M33.03 17.44c-1.68 0-3.12-.99-3.79-2.42h7.58a4.181 4.181 0 01-3.79 2.42z" />`,
}

Predefined providers

Font Awesome Pro Adapter

Local Development Setup
// Set registry and token
npm config set "@fortawesome:registry" https://npm.fontawesome.com/
npm config set "//npm.fontawesome.com/:_authToken" YOUR_TOKEN

// Install package
npm install --save-dev @fortawesome/fontawesome-pro
Usage
const { faPro } = require('@uxf/icons-generator/providers/fa-pro');

icons: {
    // for icons with default name (preferred)
    ...faPro.adapter(["brands.linkedin"]),
    // to define custom name for an icon
    twitter: faPro.icon("brands.twitter"),
}
Without Private Key

If your project already contains generated icons, installing the Font Awesome Pro package is not necessary. The package automatically generates a 'fallback file' for the icons in use, ensuring functionality even without Font Awesome Pro. However, while this setup allows for the continued use of existing icons, adding new icons from the adapter will not be possible.

1. Configuration

Create and configure your icon settings in a config file at the project's root.

2. Icon Generation

Execute icons-gen to produce:

  • SVG sprite and individual files.
  • Definition file with icon list and sizes.
  • Config file with icon version and sprite path.

3. Icon Component Setup

Incorporate the generated output into your project. Example for TypeScript and React:

import { ICONS, IconsSet } from "src/config/icons";
import { ICON_SPRITE } from "src/config/icons-config";

type IconProps = {
    name: IconsSet;
};

export const Icon: FC<IconProps> = ({ name }) => {
    const sizes = ICONS[name];

    return (
        <svg
            height={sizes.h}
            width={sizes.w}
            preserveAspectRatio="xMidYMid meet"
            role="img"
            viewBox={`0 0 ${sizes.w} ${sizes.h}`}
        >
            <use xlinkHref={`${ICON_SPRITE}#icon-sprite--${name}`} />
        </svg>
    );
};

4. Sprite Preloading (Optional)

import { ICON_SPRITE, ICONS_VERSION } from "src/config/icons-config";

// code here...

<Head>
    <link
        as="image"
        href={`${ICON_SPRITE}?v=${ICONS_VERSION}`}
        rel="preload"
        type="image/svg+xml"
    />
</Head>

5. Verification

Run icons-check to ensure icon consistency with the config. It's recommended to integrate this check into your CI process.

FAQs

Package last updated on 05 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc