Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

refactor: clean icon button

lawvsaace2cb788bc
diff --git a/libs/components/ui/src/button/IconButton.tsx b/libs/components/ui/src/button/IconButton.tsx
index 0421ecdaf7..9ad863d636 100644
--- a/libs/components/ui/src/button/IconButton.tsx
+++ b/libs/components/ui/src/button/IconButton.tsx
@@ -3,9 +3,7 @@ import type {
MouseEventHandler,
PropsWithChildren,
} from 'react';
-import { cx } from '../clsx';
import { styled } from '../styled';
-import { buttonStatus } from './constants';
/* Temporary solution, needs to be adjusted */
const SIZE_SMALL = 'small' as const;
@@ -29,13 +27,18 @@ const SIZE_CONFIG = {
type SizeType = keyof typeof SIZE_CONFIG;
-interface IconButtonProps {
+type IconButtonContainerProps = {
+ size?: SizeType;
+ hoverColor?: CSSProperties['backgroundColor'];
+ backgroundColor?: CSSProperties['backgroundColor'];
+ disabled?: boolean;
+};
+
+interface IconButtonProps extends IconButtonContainerProps {
onClick?: MouseEventHandler;
disabled?: boolean;
style?: CSSProperties;
className?: string;
- size?: SizeType;
- hoverColor?: string;
}
export const IconButton = ({
@@ -50,55 +53,40 @@ export const IconButton = ({
{...props}
onClick={disabled ? undefined : onClick}
disabled={disabled}
- className={cx({ [buttonStatus.disabled]: disabled }, className)}
>
{children}
</Container>
);
};
-const Container = styled('button')<{
- size?: SizeType;
- hoverColor?: string;
-}>(({ theme, size = SIZE_MIDDLE, hoverColor }) => {
- const { iconSize, areaSize } = SIZE_CONFIG[size];
-
- return {
- display: 'flex',
- justifyContent: 'center',
- alignItems: 'center',
- width: areaSize,
- height: areaSize,
- backgroundColor: 'transparent',
- color: theme.affine.palette.icons,
- padding: theme.affine.spacing.iconPadding,
- borderRadius: '3px',
+const Container = styled('button')<IconButtonContainerProps>(
+ ({ theme, size = SIZE_MIDDLE, hoverColor, backgroundColor, disabled }) => {
+ const { iconSize, areaSize } = SIZE_CONFIG[size];
- '& svg': {
- width: iconSize,
- height: iconSize,
+ return {
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
- },
-
- '&:hover': {
- backgroundColor: hoverColor || theme.affine.palette.hover,
- },
+ width: areaSize,
+ height: areaSize,
+ backgroundColor: backgroundColor ?? 'transparent',
+ color: theme.affine.palette.icons,
+ padding: theme.affine.spacing.iconPadding,
+ borderRadius: '3px',
- [`&${buttonStatus.hover}`]: {
- backgroundColor: theme.affine.palette.hover,
- },
+ '& svg': {
+ width: iconSize,
+ height: iconSize,
+ display: 'flex',
+ justifyContent: 'center',
+ alignItems: 'center',
+ },
- '&:focus': {
- color: theme.affine.palette.primary,
- },
- [`&.${buttonStatus.focus}`]: {
- color: theme.affine.palette.primary,
- },
+ '&:hover': {
+ backgroundColor: hoverColor || theme.affine.palette.hover,
+ },
- [`&${buttonStatus.disabled}`]: {
- cursor: 'not-allowed',
- },
- };
-});
+ ...(disabled ? { cursor: 'not-allowed' } : {}),
+ };
+ }
+);
diff --git a/libs/components/ui/src/button/constants.ts b/libs/components/ui/src/button/constants.ts
deleted file mode 100644
index 22ec35c5d1..0000000000
--- a/libs/components/ui/src/button/constants.ts
+++ /dev/null
@@ -1,6 +0,0 @@
-export const buttonStatus = {
- hover: '.hover',
- focus: '.focus',
- active: '.focus',
- disabled: '.disabled',
-};