mirror of
https://github.com/iconify/iconify.git
synced 2024-12-12 13:47:49 +00:00
chore(tailwind): add square option to plugin, fix lint
This commit is contained in:
parent
ad7158c315
commit
4666bde4c1
@ -9,6 +9,7 @@
|
|||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@iconify-json/fa6-regular": "^1.1.21",
|
||||||
"@iconify-json/mdi-light": "^1.1.10",
|
"@iconify-json/mdi-light": "^1.1.10",
|
||||||
"@iconify-json/vscode-icons": "^1.1.36",
|
"@iconify-json/vscode-icons": "^1.1.36",
|
||||||
"@iconify/tailwind": "workspace:*",
|
"@iconify/tailwind": "workspace:*",
|
||||||
|
@ -41,6 +41,12 @@
|
|||||||
class="iconify mdi-light--home h-12 w-12 text-red-600"
|
class="iconify mdi-light--home h-12 w-12 text-red-600"
|
||||||
></span>
|
></span>
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
Scaled non-square icons:
|
||||||
|
<span
|
||||||
|
class="fa6-mask fa6-regular-bookmark text-blue-600"
|
||||||
|
></span>
|
||||||
|
</p>
|
||||||
</section>
|
</section>
|
||||||
<section class="mb-2">
|
<section class="mb-2">
|
||||||
<h1 class="text-2xl">Dynamic selectors plugin, custom options</h1>
|
<h1 class="text-2xl">Dynamic selectors plugin, custom options</h1>
|
||||||
|
@ -91,6 +91,15 @@ module.exports = {
|
|||||||
scale: 0,
|
scale: 0,
|
||||||
// No prefixes list: reusing data from plugin above
|
// No prefixes list: reusing data from plugin above
|
||||||
}),
|
}),
|
||||||
|
// Main plugin, no square and scale
|
||||||
|
addIconSelectors({
|
||||||
|
maskSelector: '.fa6-mask',
|
||||||
|
backgroundSelector: '.fa6-bg', // unused
|
||||||
|
iconSelector: '.{prefix}-{name}',
|
||||||
|
square: false,
|
||||||
|
scale: 2,
|
||||||
|
prefixes: ['fa6-regular'],
|
||||||
|
}),
|
||||||
// Plugin with clean selectors: requires writing all used icons in first parameter
|
// Plugin with clean selectors: requires writing all used icons in first parameter
|
||||||
addCleanIconSelectors(['mdi-light:home']),
|
addCleanIconSelectors(['mdi-light:home']),
|
||||||
// Plugin with dynamic selectors
|
// Plugin with dynamic selectors
|
||||||
|
2
plugins/tailwind/.eslintignore
Normal file
2
plugins/tailwind/.eslintignore
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
lib
|
||||||
|
dist
|
33
plugins/tailwind/.eslintrc.cjs
Normal file
33
plugins/tailwind/.eslintrc.cjs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
module.exports = {
|
||||||
|
env: {
|
||||||
|
browser: true,
|
||||||
|
es6: true,
|
||||||
|
node: true,
|
||||||
|
},
|
||||||
|
extends: [
|
||||||
|
'eslint:recommended',
|
||||||
|
'plugin:@typescript-eslint/recommended',
|
||||||
|
'plugin:@typescript-eslint/recommended-requiring-type-checking',
|
||||||
|
'plugin:prettier/recommended',
|
||||||
|
],
|
||||||
|
globals: {
|
||||||
|
Atomics: 'readonly',
|
||||||
|
SharedArrayBuffer: 'readonly',
|
||||||
|
},
|
||||||
|
parser: '@typescript-eslint/parser',
|
||||||
|
parserOptions: {
|
||||||
|
tsconfigRootDir: __dirname,
|
||||||
|
project: ['tsconfig.json', 'tests/tsconfig.json'],
|
||||||
|
extraFileExtensions: ['.cjs'],
|
||||||
|
},
|
||||||
|
plugins: ['@typescript-eslint'],
|
||||||
|
rules: {
|
||||||
|
'no-mixed-spaces-and-tabs': ['off'],
|
||||||
|
'no-unused-vars': ['off'],
|
||||||
|
},
|
||||||
|
overrides: [
|
||||||
|
{
|
||||||
|
files: ['src/**/*.ts', 'tests/*.ts'],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
@ -2,7 +2,7 @@
|
|||||||
"name": "@iconify/tailwind",
|
"name": "@iconify/tailwind",
|
||||||
"description": "Iconify plugin for Tailwind CSS",
|
"description": "Iconify plugin for Tailwind CSS",
|
||||||
"author": "Vjacheslav Trushkin <cyberalien@gmail.com> (https://iconify.design)",
|
"author": "Vjacheslav Trushkin <cyberalien@gmail.com> (https://iconify.design)",
|
||||||
"version": "1.1.1",
|
"version": "1.1.2",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "./dist/plugin.js",
|
"main": "./dist/plugin.js",
|
||||||
"types": "./dist/plugin.d.ts",
|
"types": "./dist/plugin.d.ts",
|
||||||
|
@ -19,7 +19,9 @@ export function locateIconSet(prefix: string): LocatedIconSet | undefined {
|
|||||||
main,
|
main,
|
||||||
info,
|
info,
|
||||||
};
|
};
|
||||||
} catch {}
|
} catch {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
// Try `@iconify/json`
|
// Try `@iconify/json`
|
||||||
try {
|
try {
|
||||||
@ -27,7 +29,9 @@ export function locateIconSet(prefix: string): LocatedIconSet | undefined {
|
|||||||
return {
|
return {
|
||||||
main,
|
main,
|
||||||
};
|
};
|
||||||
} catch {}
|
} catch {
|
||||||
|
//
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,13 +49,19 @@ const cache = Object.create(null) as Record<string, IconifyJSON>;
|
|||||||
*/
|
*/
|
||||||
function loadIconSetFromFile(source: LocatedIconSet): IconifyJSON | undefined {
|
function loadIconSetFromFile(source: LocatedIconSet): IconifyJSON | undefined {
|
||||||
try {
|
try {
|
||||||
const result = JSON.parse(readFileSync(source.main, 'utf8'));
|
const result = JSON.parse(
|
||||||
|
readFileSync(source.main, 'utf8')
|
||||||
|
) as IconifyJSON;
|
||||||
if (!result.info && source.info) {
|
if (!result.info && source.info) {
|
||||||
// Load info from a separate file
|
// Load info from a separate file
|
||||||
result.info = JSON.parse(readFileSync(source.info, 'utf8'));
|
result.info = JSON.parse(
|
||||||
|
readFileSync(source.info, 'utf8')
|
||||||
|
) as IconifyJSON['info'];
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
} catch {}
|
} catch {
|
||||||
|
//
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -75,7 +85,7 @@ export function loadIconSet(
|
|||||||
// Try to parse JSON
|
// Try to parse JSON
|
||||||
if (source.startsWith('{')) {
|
if (source.startsWith('{')) {
|
||||||
try {
|
try {
|
||||||
return JSON.parse(source);
|
return JSON.parse(source) as IconifyJSON;
|
||||||
} catch {
|
} catch {
|
||||||
// Invalid JSON
|
// Invalid JSON
|
||||||
}
|
}
|
||||||
|
@ -94,6 +94,9 @@ export interface IconifyPluginOptionsObject {
|
|||||||
// Scale for icons, defaults to 1
|
// Scale for icons, defaults to 1
|
||||||
scale?: number;
|
scale?: number;
|
||||||
|
|
||||||
|
// Make icons square, defaults to true
|
||||||
|
square?: boolean;
|
||||||
|
|
||||||
// Prefixes to load
|
// Prefixes to load
|
||||||
prefixes?: IconifyPluginListOptions;
|
prefixes?: IconifyPluginListOptions;
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ export function addDynamicIconSelectors(options?: DynamicIconifyPluginOptions) {
|
|||||||
return getDynamicCSSRules(icon, options);
|
return getDynamicCSSRules(icon, options);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Log error, but do not throw it
|
// Log error, but do not throw it
|
||||||
console.error(err.message);
|
console.error((err as Error).message);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -5,6 +5,7 @@ import {
|
|||||||
} from '@iconify/utils/lib/css/common';
|
} from '@iconify/utils/lib/css/common';
|
||||||
import { defaultIconProps } from '@iconify/utils/lib/icon/defaults';
|
import { defaultIconProps } from '@iconify/utils/lib/icon/defaults';
|
||||||
import { parseIconSet } from '@iconify/utils/lib/icon-set/parse';
|
import { parseIconSet } from '@iconify/utils/lib/icon-set/parse';
|
||||||
|
import { calculateSize } from '@iconify/utils/lib/svg/size';
|
||||||
import type {
|
import type {
|
||||||
IconifyPluginOptions,
|
IconifyPluginOptions,
|
||||||
IconifyPluginOptionsObject,
|
IconifyPluginOptionsObject,
|
||||||
@ -90,6 +91,12 @@ export function getCSSRulesForPlugin(options: IconifyPluginOptionsObject) {
|
|||||||
// Add icon sets
|
// Add icon sets
|
||||||
const iconSelector = options.iconSelector || '.{prefix}--{name}';
|
const iconSelector = options.iconSelector || '.{prefix}--{name}';
|
||||||
|
|
||||||
|
// Make icons square
|
||||||
|
const square = options.square !== false;
|
||||||
|
|
||||||
|
// Scale
|
||||||
|
const scale = options.scale ?? 1;
|
||||||
|
|
||||||
options.prefixes?.forEach((item) => {
|
options.prefixes?.forEach((item) => {
|
||||||
let prefix: string;
|
let prefix: string;
|
||||||
let iconSet: IconifyJSON | undefined;
|
let iconSet: IconifyJSON | undefined;
|
||||||
@ -162,7 +169,7 @@ export function getCSSRulesForPlugin(options: IconifyPluginOptionsObject) {
|
|||||||
{
|
{
|
||||||
mode: 'mask', // not used because varName is set, but required
|
mode: 'mask', // not used because varName is set, but required
|
||||||
varName,
|
varName,
|
||||||
forceSquare: true,
|
forceSquare: square,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -171,6 +178,11 @@ export function getCSSRulesForPlugin(options: IconifyPluginOptionsObject) {
|
|||||||
.replace('{prefix}', prefix)
|
.replace('{prefix}', prefix)
|
||||||
.replace('{name}', name);
|
.replace('{name}', name);
|
||||||
|
|
||||||
|
// Scale non-square icons
|
||||||
|
if (!square && scale > 0 && scale !== 1 && iconRules.width) {
|
||||||
|
iconRules.width = calculateSize(iconRules.width, scale);
|
||||||
|
}
|
||||||
|
|
||||||
// Add to rules
|
// Add to rules
|
||||||
rules[selector] = iconRules;
|
rules[selector] = iconRules;
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"extends": "./tsconfig-base.json",
|
"extends": "./tsconfig-base.json",
|
||||||
"include": ["src/**/*.ts", ".eslintrc.js"],
|
"include": ["src/**/*.ts", ".eslintrc.cjs"],
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"rootDir": "./src",
|
"rootDir": "./src",
|
||||||
"outDir": "./lib",
|
"outDir": "./lib",
|
||||||
|
@ -832,6 +832,9 @@ importers:
|
|||||||
|
|
||||||
plugins-demo/tailwind-demo:
|
plugins-demo/tailwind-demo:
|
||||||
devDependencies:
|
devDependencies:
|
||||||
|
'@iconify-json/fa6-regular':
|
||||||
|
specifier: ^1.1.21
|
||||||
|
version: 1.1.21
|
||||||
'@iconify-json/mdi-light':
|
'@iconify-json/mdi-light':
|
||||||
specifier: ^1.1.10
|
specifier: ^1.1.10
|
||||||
version: 1.1.10
|
version: 1.1.10
|
||||||
@ -2639,6 +2642,9 @@ packages:
|
|||||||
'@iconify-icons/uil@1.2.3':
|
'@iconify-icons/uil@1.2.3':
|
||||||
resolution: {integrity: sha512-+UlrTCKJ13k8MdZdBJUdJLwrys6r8/BG3MT+C09Vcqbzh5IKGxS9RdJ7G3XeTn+H2MrIJ/EHWCNNUANlDqLk6A==}
|
resolution: {integrity: sha512-+UlrTCKJ13k8MdZdBJUdJLwrys6r8/BG3MT+C09Vcqbzh5IKGxS9RdJ7G3XeTn+H2MrIJ/EHWCNNUANlDqLk6A==}
|
||||||
|
|
||||||
|
'@iconify-json/fa6-regular@1.1.21':
|
||||||
|
resolution: {integrity: sha512-xgKt8d9AeMXKc1gfaUUqhYpDZjmC++e6ETsNyW6G0g8n7m2pUsnlpiTDUXGEtalVt6zl7M+HSU9RKrq4ma0rHg==}
|
||||||
|
|
||||||
'@iconify-json/flat-color-icons@1.1.10':
|
'@iconify-json/flat-color-icons@1.1.10':
|
||||||
resolution: {integrity: sha512-tkkxTEPMYqDtss8tFij/gWfwrnt/NeChZoUGr6l71sWi7jYMwD35dYjFhM2bjtww5MCkVIAJaVx/3QJGUmMD/g==}
|
resolution: {integrity: sha512-tkkxTEPMYqDtss8tFij/gWfwrnt/NeChZoUGr6l71sWi7jYMwD35dYjFhM2bjtww5MCkVIAJaVx/3QJGUmMD/g==}
|
||||||
|
|
||||||
@ -11600,6 +11606,10 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
'@iconify/types': 2.0.0
|
'@iconify/types': 2.0.0
|
||||||
|
|
||||||
|
'@iconify-json/fa6-regular@1.1.21':
|
||||||
|
dependencies:
|
||||||
|
'@iconify/types': 2.0.0
|
||||||
|
|
||||||
'@iconify-json/flat-color-icons@1.1.10':
|
'@iconify-json/flat-color-icons@1.1.10':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@iconify/types': 2.0.0
|
'@iconify/types': 2.0.0
|
||||||
|
Loading…
Reference in New Issue
Block a user