Skip to content

Commit

Permalink
Added support of Bootstrap Icons
Browse files Browse the repository at this point in the history
Support of Bootstrap Icons through `@xrnoz/bootstrap-icons-js`.

Updated dependencies.
  • Loading branch information
Yzen90 committed Aug 6, 2023
1 parent 0a8a47e commit 08dbef9
Show file tree
Hide file tree
Showing 6 changed files with 1,228 additions and 451 deletions.
28 changes: 21 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ Allows the mixed usage of these icon packages and the embedding of icons:
- [Material Design Icons](https://pictogrammers.com/library/mdi/)
- [Material Design Icons Light](https://pictogrammers.com/library/mdil/)
- [heroicons (outline, solid and mini variants)](https://heroicons.com/)
- [Bootstrap Icons](https://icons.getbootstrap.com/)
- Others can be added by creating custom `ExtractionOptions`.

This package is composed of three main parts:

1. A Vue component for Vuetify based on the one from the `mdi` IconPack exported by `'vuetify/iconsets/mdi-svg'`, that gets the icon data from a string with the format: `'SVG;<path data>;<view box>;<fill>;<stroke width>;<fill rule>'` if the string does not start with `'SVG;'`, it just uses the string as the path data like `mdi-svg` does.
2. Functions that output the the previously mentioned format. The combination of the component and this functions allows the usage of icons from different packages in any Vuetify component that uses icons.
2. Functions that output the the previously mentioned format. The combination of the component and this functions allows the mixed usage of icons from different packages in any Vuetify component that uses icons.
1. `useFA` to use a `IconDefinition` object representing a Font Awesome icon.
2. `useHIO` to use [heroicons](https://heroicons.com/) outline variant from `@xrnoz/heroicons-js`.
3. `useHIS` to use heroicons solid variant from `@xrnoz/heroicons-js`.
4. `useHIM` to use heroicons mini variant from `@xrnoz/heroicons-js`.
5. `useBI` to use Bootstrap Icons from `@xrnoz/bootstrap-icons-js`.
3. A Vite plugin that replaces the calls of the provided functions with it's resulting string to optimize the usage of the icons. By default it also removes the first import of `@xrnoz/vuetify-svg-icons` and of the icon package(s), as after replacing the function calls the imports are no longer neccesary.

**Table of contents**
Expand Down Expand Up @@ -43,7 +45,8 @@ yarn add @xrnoz/vuetify-svg-icons
# yarn add @fortawesome/free-regular-svg-icons
# yarn add @mdi/js
# yarn add @mdi/light-js
# yarn add @@xrnoz/heroicons-js
# yarn add @xrnoz/heroicons-js
# yarn add @xrnoz/bootstrap-icons-js
```

### 2. Create a file `icons.ts`:
Expand All @@ -59,8 +62,10 @@ import { far } from '@fortawesome/free-regular-svg-icons';

import { his, hio, him } from '@xrnoz/heroicons-js';

// To use the plugin some of the functions are different, see section 5.
import { useFA, useHIO, useHIS, useHIM } from '@xrnoz/vuetify-svg-icons';
import { bi } from '@xrnoz/bootstrap-icons-js';

// To use the vite plugin some of the functions are different, see section 5.
import { useFA, useHIO, useHIS, useHIM, useBI } from '@xrnoz/vuetify-svg-icons';

import type { IconAliases } from 'vuetify';

Expand All @@ -87,6 +92,9 @@ export const aliases: IconAliases = {

// heroicons mini
experimental: useHIM(him.beaker),

// bootstrap icons
inLove: useBI(bi.biArrowThroughHeart),
};
```

Expand Down Expand Up @@ -183,7 +191,9 @@ import { far } from '@fortawesome/free-regular-svg-icons';

import { his, hio, him } from '@xrnoz/heroicons-js';

import { useMDI, useMDIL, useFAS, useFAR, useHIO, useHIS, useHIM } from '@xrnoz/vuetify-svg-icons';
import { bi } from '@xrnoz/bootstrap-icons-js';

import { useMDI, useMDIL, useFAS, useFAR, useHIO, useHIS, useHIM, useBI } from '@xrnoz/vuetify-svg-icons';

import type { IconAliases } from 'vuetify';

Expand All @@ -210,6 +220,9 @@ export const aliases: IconAliases = {

// heroicons mini
experimental: useHIM(him.beaker),

// bootstrap icons
inLove: useBI(bi.biArrowThroughHeart),
};
```

Expand All @@ -227,7 +240,7 @@ export default defineConfig({
vuetify({}),

// Use `embed` option to indicate the presets to use or add a custom one:
embedIcons({ include: './src/icons.ts', embed: ['mdi', 'mdil', 'fas', 'far', 'hio', 'his', 'him'] }),
embedIcons({ include: './src/icons.ts', embed: ['mdi', 'mdil', 'fas', 'far', 'hio', 'his', 'him', 'bi'] }),
],
});
```
Expand Down Expand Up @@ -263,4 +276,5 @@ export const fasPreset: ExtractionOptions = {
- [Material Design Icons](https://pictogrammers.com/library/mdi/)
- [Material Design Icons Light](https://pictogrammers.com/library/mdil/)
- [heroicons](https://heroicons.com/)
- [Vuetify Icon Fonts Documentation](https://next.vuetifyjs.com/en/features/icon-fonts/)
- [Bootstrap Icons](https://icons.getbootstrap.com/)
- [Vuetify Icon Fonts Documentation](https://vuetifyjs.com/en/features/icon-fonts/)
3 changes: 3 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ export const useMDIL = embed;
export const useHIS = (icon: string) => `SVG;${icon};;;;evenodd`;
export const useHIO = (icon: string) => `SVG;${icon};;none;1.5`;
export const useHIM = (icon: string) => `SVG;${icon};0 0 20 20;;;evenodd`;

// Bootstrap Icons
export const useBI = (icon: string) => `SVG;${icon};0 0 16 16`;
31 changes: 16 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xrnoz/vuetify-svg-icons",
"version": "2.0.0",
"version": "2.1.0",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand All @@ -19,7 +19,7 @@
"dist/**"
],
"dependencies": {
"acorn": "8.8.2",
"acorn": "^8.10.0",
"acorn-walk": "^8.2.0",
"picocolors": "^1.0.0"
},
Expand All @@ -29,18 +29,19 @@
"vuetify": "3.x"
},
"devDependencies": {
"@fortawesome/fontawesome-common-types": "6.3.0",
"@tsconfig/node18-strictest-esm": "1.0.1",
"@types/estree": "1.0.0",
"@types/node": "18.14.0",
"jest-diff": "29.4.3",
"prettier": "2.8.4",
"rimraf": "4.1.2",
"ts-node": "10.9.1",
"typescript": "4.9.5",
"vite": "4.1.4",
"vue": "3.2.47",
"vuetify": "3.1.6"
"@fortawesome/fontawesome-common-types": "6.4.2",
"@tsconfig/node20": "20.1.0",
"@tsconfig/strictest": "2.0.1",
"@types/estree": "1.0.1",
"@types/node": "20.4.8",
"del-cli": "5.0.0",
"jest-diff": "29.6.2",
"prettier": "3.0.1",
"tsx": "3.12.7",
"typescript": "5.1.6",
"vite": "4.4.8",
"vue": "3.3.4",
"vuetify": "3.3.11"
},
"engines": {
"yarn": "1.22.19"
Expand All @@ -49,7 +50,7 @@
"build": "rimraf dist && tsc",
"dev:check": "tsc --noEmit",
"fmt": "prettier --write .",
"test": "ts-node scripts/parse-test.ts",
"test": "tsx scripts/parse-test.ts",
"prepublishOnly": "yarn build"
},
"description": "SVG icons usage alternative for Vuetify 3 and icon embedding.",
Expand Down
10 changes: 9 additions & 1 deletion plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface ExtractionOptions {
extractorPkg: string;
}

export type Preset = 'fas' | 'far' | 'mdi' | 'mdil' | 'hio' | 'his' | 'him';
export type Preset = 'fas' | 'far' | 'mdi' | 'mdil' | 'hio' | 'his' | 'him' | 'bi';

export interface IconEmbedOptions {
/** Target files for the plugin. */
Expand Down Expand Up @@ -94,6 +94,13 @@ export const himPreset: ExtractionOptions = {
extractorPkg: '@xrnoz/vuetify-svg-icons',
};

export const biPreset: ExtractionOptions = {
iconsPkg: '@xrnoz/bootstrap-icons-js',
iconsExport: 'bi',
extractor: 'useBI',
extractorPkg: '@xrnoz/vuetify-svg-icons',
};

const presets: { [key in Preset]: ExtractionOptions } = {
fas: fasPreset,
far: farPreset,
Expand All @@ -102,6 +109,7 @@ const presets: { [key in Preset]: ExtractionOptions } = {
hio: hioPreset,
his: hisPreset,
him: himPreset,
bi: biPreset,
};

export default (options: IconEmbedOptions) => {
Expand Down
8 changes: 2 additions & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
{
"extends": "@tsconfig/node18-strictest-esm/tsconfig.json",
"extends": ["@tsconfig/strictest/tsconfig", "@tsconfig/node20/tsconfig"],
"compilerOptions": {
"module": "ESNext",
"declaration": true,
"outDir": "dist",
"noImplicitReturns": false
},
"files": ["index.ts", "plugin.ts"],
"exclude": ["node_modules"],
"ts-node": {
"esm": true
}
"exclude": ["node_modules"]
}
Loading

0 comments on commit 08dbef9

Please sign in to comment.