2024-10-27 21:22:06 +01:00
|
|
|
// Copyright 2023, Command Line Inc.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2024-09-09 21:35:53 +02:00
|
|
|
import { useLongClick } from "@/app/hook/useLongClick";
|
|
|
|
import { makeIconClass } from "@/util/util";
|
|
|
|
import clsx from "clsx";
|
|
|
|
import { memo, useRef } from "react";
|
2024-11-22 01:05:04 +01:00
|
|
|
import "./iconbutton.scss";
|
2024-09-09 21:35:53 +02:00
|
|
|
|
|
|
|
export const IconButton = memo(({ decl, className }: { decl: IconButtonDecl; className?: string }) => {
|
|
|
|
const buttonRef = useRef<HTMLDivElement>(null);
|
2024-12-04 23:16:50 +01:00
|
|
|
const spin = decl.iconSpin ?? false;
|
2024-09-09 21:35:53 +02:00
|
|
|
useLongClick(buttonRef, decl.click, decl.longClick, decl.disabled);
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
ref={buttonRef}
|
2024-12-04 23:16:50 +01:00
|
|
|
className={clsx("iconbutton", className, decl.className, {
|
|
|
|
disabled: decl.disabled,
|
|
|
|
"no-action": decl.noAction,
|
|
|
|
})}
|
2024-09-09 21:35:53 +02:00
|
|
|
title={decl.title}
|
2024-09-13 12:36:15 +02:00
|
|
|
style={{ color: decl.iconColor ?? "inherit" }}
|
2024-09-09 21:35:53 +02:00
|
|
|
>
|
2024-12-04 23:16:50 +01:00
|
|
|
{typeof decl.icon === "string" ? <i className={makeIconClass(decl.icon, true, { spin })} /> : decl.icon}
|
2024-09-09 21:35:53 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|