增加ActionIcon组件。

This commit is contained in:
徐涛 2025-01-24 11:26:25 +08:00
parent 2b17a5de0f
commit 3882ae764f
2 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,10 @@
@layer components {
.action_icon {
padding: var(--spacing-xs);
border: none;
border-radius: var(--border-radius-xxs);
line-height: 1em;
.icon {
}
}
}

View File

@ -0,0 +1,25 @@
import { Icon, IconProps } from '@iconify/react/dist/iconify.js';
import cx from 'clsx';
import { MouseEventHandler, useCallback } from 'react';
import styles from './ActionIcon.module.css';
type ActionIconProps = {
icon: IconProps['icon'];
onClick?: MouseEventHandler<HTMLButtonElement>;
extendClassName?: HTMLButtonElement['className'];
};
export function ActionIcon({ icon, onClick, extendClassName }: ActionIconProps) {
const handleClick = useCallback(
(event: MouseEvent<HTMLButtonElement>) => {
onClick?.(event);
},
[onClick],
);
return (
<button onClick={handleClick} className={cx(styles.action_icon, extendClassName)}>
<Icon icon={icon} className={styles.icon} />
</button>
);
}