2023-01-11 04:47:46 +03:00
|
|
|
import { useEffect, useState } from 'preact/hooks';
|
2022-12-13 15:42:09 +03:00
|
|
|
|
2022-12-10 12:14:48 +03:00
|
|
|
const SIZES = {
|
|
|
|
s: 12,
|
|
|
|
m: 16,
|
|
|
|
l: 20,
|
|
|
|
xl: 24,
|
|
|
|
xxl: 32,
|
|
|
|
};
|
|
|
|
|
|
|
|
const ICONS = {
|
|
|
|
x: 'mingcute:close-line',
|
|
|
|
heart: 'mingcute:heart-line',
|
|
|
|
bookmark: 'mingcute:bookmark-line',
|
|
|
|
'check-circle': 'mingcute:check-circle-line',
|
|
|
|
transfer: 'mingcute:transfer-4-line',
|
|
|
|
rocket: 'mingcute:rocket-line',
|
|
|
|
'arrow-left': 'mingcute:arrow-left-line',
|
|
|
|
'arrow-right': 'mingcute:arrow-right-line',
|
|
|
|
'arrow-up': 'mingcute:arrow-up-line',
|
2022-12-29 06:47:10 +03:00
|
|
|
'arrow-down': 'mingcute:arrow-down-line',
|
2022-12-10 12:14:48 +03:00
|
|
|
earth: 'mingcute:earth-line',
|
|
|
|
lock: 'mingcute:lock-line',
|
|
|
|
unlock: 'mingcute:unlock-line',
|
|
|
|
'eye-close': 'mingcute:eye-close-line',
|
|
|
|
'eye-open': 'mingcute:eye-2-line',
|
|
|
|
message: 'mingcute:mail-line',
|
|
|
|
comment: 'mingcute:chat-3-line',
|
2023-02-08 17:56:30 +03:00
|
|
|
home: 'mingcute:home-3-line',
|
2022-12-10 12:14:48 +03:00
|
|
|
notification: 'mingcute:notification-line',
|
|
|
|
follow: 'mingcute:user-follow-line',
|
|
|
|
'follow-add': 'mingcute:user-add-line',
|
2023-01-12 19:20:36 +03:00
|
|
|
poll: ['mingcute:chart-bar-line', '90deg'],
|
2022-12-10 12:14:48 +03:00
|
|
|
pencil: 'mingcute:pencil-line',
|
|
|
|
quill: 'mingcute:quill-pen-line',
|
|
|
|
at: 'mingcute:at-line',
|
|
|
|
attachment: 'mingcute:attachment-line',
|
|
|
|
upload: 'mingcute:upload-3-line',
|
|
|
|
gear: 'mingcute:settings-3-line',
|
2023-02-25 05:03:52 +03:00
|
|
|
more: 'mingcute:more-3-line',
|
2022-12-13 15:42:09 +03:00
|
|
|
external: 'mingcute:external-link-line',
|
|
|
|
popout: 'mingcute:external-link-line',
|
|
|
|
popin: ['mingcute:external-link-line', '180deg'],
|
2022-12-14 16:48:17 +03:00
|
|
|
plus: 'mingcute:add-circle-line',
|
2022-12-18 15:53:32 +03:00
|
|
|
'chevron-left': 'mingcute:left-line',
|
2023-01-14 14:42:04 +03:00
|
|
|
'chevron-right': 'mingcute:right-line',
|
2022-12-22 05:35:39 +03:00
|
|
|
reply: ['mingcute:share-forward-line', '180deg', 'horizontal'],
|
|
|
|
thread: 'mingcute:route-line',
|
2022-12-23 16:25:01 +03:00
|
|
|
group: 'mingcute:group-line',
|
2022-12-27 13:09:23 +03:00
|
|
|
bot: 'mingcute:android-2-line',
|
2023-02-10 08:39:46 +03:00
|
|
|
menu: 'mingcute:rows-4-line',
|
2023-02-10 19:05:18 +03:00
|
|
|
list: 'mingcute:list-check-line',
|
|
|
|
search: 'mingcute:search-2-line',
|
2023-02-11 11:48:47 +03:00
|
|
|
hashtag: 'mingcute:hashtag-line',
|
2023-02-11 17:36:19 +03:00
|
|
|
info: 'mingcute:information-line',
|
2023-02-16 12:51:54 +03:00
|
|
|
shortcut: 'mingcute:lightning-line',
|
|
|
|
user: 'mingcute:user-4-line',
|
|
|
|
following: 'mingcute:walk-line',
|
2023-02-17 05:12:59 +03:00
|
|
|
pin: 'mingcute:pin-line',
|
2023-02-25 06:25:50 +03:00
|
|
|
bus: 'mingcute:bus-2-line',
|
2023-02-26 19:55:04 +03:00
|
|
|
link: 'mingcute:link-2-line',
|
|
|
|
history: 'mingcute:history-line',
|
|
|
|
share: 'mingcute:share-2-line',
|
2023-02-28 10:27:42 +03:00
|
|
|
sparkles: 'mingcute:sparkles-line',
|
2023-02-28 12:12:17 +03:00
|
|
|
exit: 'mingcute:exit-line',
|
2023-03-07 17:38:06 +03:00
|
|
|
translate: 'mingcute:translate-line',
|
2023-03-13 18:40:08 +03:00
|
|
|
play: 'mingcute:play-fill',
|
2023-03-17 12:14:54 +03:00
|
|
|
trash: 'mingcute:delete-2-line',
|
2023-03-18 11:24:04 +03:00
|
|
|
mute: 'mingcute:volume-mute-line',
|
|
|
|
unmute: 'mingcute:volume-line',
|
|
|
|
block: 'mingcute:forbid-circle-line',
|
|
|
|
unblock: ['mingcute:forbid-circle-line', '180deg'],
|
|
|
|
flag: 'mingcute:flag-4-line',
|
|
|
|
time: 'mingcute:time-line',
|
2023-03-19 15:12:45 +03:00
|
|
|
refresh: 'mingcute:refresh-2-line',
|
2023-03-24 17:30:05 +03:00
|
|
|
emoji2: 'mingcute:emoji-2-line',
|
2023-04-03 05:36:31 +03:00
|
|
|
filter: 'mingcute:filter-2-line',
|
2023-04-05 20:14:38 +03:00
|
|
|
chart: 'mingcute:chart-line-line',
|
2023-04-06 17:51:48 +03:00
|
|
|
react: 'mingcute:react-line',
|
2022-12-10 12:14:48 +03:00
|
|
|
};
|
|
|
|
|
2023-01-11 04:47:46 +03:00
|
|
|
const modules = import.meta.glob('/node_modules/@iconify-icons/mingcute/*.js');
|
|
|
|
|
2023-03-09 16:51:50 +03:00
|
|
|
function Icon({
|
|
|
|
icon,
|
|
|
|
size = 'm',
|
|
|
|
alt,
|
|
|
|
title,
|
|
|
|
class: className = '',
|
|
|
|
style = {},
|
|
|
|
}) {
|
2022-12-14 16:48:17 +03:00
|
|
|
if (!icon) return null;
|
|
|
|
|
2022-12-10 12:14:48 +03:00
|
|
|
const iconSize = SIZES[size];
|
2022-12-13 15:42:09 +03:00
|
|
|
let iconName = ICONS[icon];
|
2022-12-22 05:35:39 +03:00
|
|
|
let rotate, flip;
|
2022-12-13 15:42:09 +03:00
|
|
|
if (Array.isArray(iconName)) {
|
2022-12-22 05:35:39 +03:00
|
|
|
[iconName, rotate, flip] = iconName;
|
2022-12-13 15:42:09 +03:00
|
|
|
}
|
2023-01-11 04:47:46 +03:00
|
|
|
|
|
|
|
const [iconData, setIconData] = useState(null);
|
|
|
|
useEffect(async () => {
|
|
|
|
const name = iconName.replace('mingcute:', '');
|
|
|
|
const icon = await modules[
|
|
|
|
`/node_modules/@iconify-icons/mingcute/${name}.js`
|
|
|
|
]();
|
|
|
|
setIconData(icon.default);
|
|
|
|
}, [iconName]);
|
|
|
|
|
2022-12-10 12:14:48 +03:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
class={`icon ${className}`}
|
|
|
|
title={title || alt}
|
|
|
|
style={{
|
|
|
|
width: `${iconSize}px`,
|
|
|
|
height: `${iconSize}px`,
|
|
|
|
display: 'inline-block',
|
|
|
|
overflow: 'hidden',
|
|
|
|
lineHeight: 0,
|
2023-03-09 16:51:50 +03:00
|
|
|
...style,
|
2022-12-10 12:14:48 +03:00
|
|
|
}}
|
|
|
|
>
|
2023-01-11 04:47:46 +03:00
|
|
|
{iconData && (
|
|
|
|
<svg
|
|
|
|
width={iconSize}
|
|
|
|
height={iconSize}
|
|
|
|
viewBox={`0 0 ${iconData.width} ${iconData.height}`}
|
|
|
|
dangerouslySetInnerHTML={{ __html: iconData.body }}
|
|
|
|
style={{
|
|
|
|
transform: `${rotate ? `rotate(${rotate})` : ''} ${
|
|
|
|
flip ? `scaleX(-1)` : ''
|
|
|
|
}`,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
2022-12-10 12:14:48 +03:00
|
|
|
</div>
|
|
|
|
);
|
2022-12-16 08:27:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Icon;
|