mirror of
https://github.com/iconify/iconify.git
synced 2024-11-05 21:07:51 +00:00
chore(tailwind): add customise option
This commit is contained in:
parent
7f0454faf0
commit
3365d71a42
@ -1,4 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
@ -17,7 +17,8 @@
|
||||
</span>
|
||||
</p>
|
||||
<p>
|
||||
Custom icons, imported from "svg" directory:
|
||||
Custom icons, imported from "svg" directory (first icon's animation
|
||||
slowed down using "customise" option):
|
||||
<span class="text-3xl demo">
|
||||
<span class="icon-[custom--spinner1]"></span>
|
||||
<span class="icon-[custom--spinner2]"></span>
|
||||
|
@ -66,6 +66,16 @@ module.exports = {
|
||||
iconSets: {
|
||||
custom: customSet.export(),
|
||||
},
|
||||
customise: (content, name, prefix) => {
|
||||
switch (name) {
|
||||
case 'spinner1':
|
||||
return content.replace(
|
||||
'animation:0.75s',
|
||||
'animation:5s'
|
||||
);
|
||||
}
|
||||
return content;
|
||||
},
|
||||
}),
|
||||
// Plugin with dynamic selectors that contains only css for overriding icon
|
||||
addDynamicIconSelectors({
|
||||
|
@ -23,10 +23,15 @@ export function getCSSRulesForIcons(
|
||||
`Cannot load icon set for "${prefix}". Install "@iconify-json/${prefix}" as dev dependency?`
|
||||
);
|
||||
}
|
||||
|
||||
const generated = getIconsCSSData(
|
||||
iconSet,
|
||||
Array.from(prefixes[prefix]),
|
||||
options
|
||||
{
|
||||
...options,
|
||||
customise: (content, name) =>
|
||||
options.customise?.(content, name, prefix) ?? content,
|
||||
}
|
||||
);
|
||||
|
||||
const result = generated.common
|
||||
|
@ -29,6 +29,8 @@ export function getDynamicCSSRules(
|
||||
|
||||
const generated = getIconsCSSData(iconSet, [name], {
|
||||
iconSelector: '.icon',
|
||||
customise: (content, name) =>
|
||||
options.customise?.(content, name, prefix) ?? content,
|
||||
});
|
||||
if (generated.css.length !== 1) {
|
||||
throw new Error(`Cannot find "${icon}". Bad icon name?`);
|
||||
|
@ -1,6 +1,13 @@
|
||||
import type { IconCSSIconSetOptions } from '@iconify/utils/lib/css/types';
|
||||
import type { IconifyJSON } from '@iconify/types';
|
||||
|
||||
// Callback for customising icon
|
||||
type IconifyCustomiseCallback = (
|
||||
content: string,
|
||||
name: string,
|
||||
prefix: string
|
||||
) => string;
|
||||
|
||||
// Callback for loading icon set
|
||||
type IconifyJSONLoaderCallback = () => IconifyJSON;
|
||||
|
||||
@ -17,6 +24,9 @@ export interface CommonIconifyPluginOptions {
|
||||
// Custom icon sets
|
||||
// Value can be loaded icon set or callback that loads icon set
|
||||
iconSets?: Record<string, IconifyIconSetSource>;
|
||||
|
||||
// Replace icon content
|
||||
customise?: IconifyCustomiseCallback;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -24,7 +34,7 @@ export interface CommonIconifyPluginOptions {
|
||||
*/
|
||||
export interface CleanIconifyPluginOptions
|
||||
extends CommonIconifyPluginOptions,
|
||||
IconCSSIconSetOptions {
|
||||
Omit<IconCSSIconSetOptions, 'customise'> {
|
||||
//
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user