feat: improve menuitem btn design (#3152)

feat: add LightIconButtonGroup

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Cao Z.H 2024-01-04 06:15:38 +08:00 committed by GitHub
parent 8483cf0b4b
commit f36fa9aa14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 4 deletions

View File

@ -0,0 +1,41 @@
import { MouseEvent } from 'react';
import styled from '@emotion/styled';
import { IconComponent } from '@/ui/display/icon/types/IconComponent';
import { LightIconButton, LightIconButtonProps } from './LightIconButton';
const StyledLightIconButtonGroupContainer = styled.div`
display: inline-flex;
gap: 2px;
padding: 2px;
`;
export type LightIconButtonGroupProps = Pick<
LightIconButtonProps,
'className' | 'size'
> & {
iconButtons: {
Icon: IconComponent;
onClick?: (event: MouseEvent<any>) => void;
}[];
};
export const LightIconButtonGroup = ({
iconButtons,
size,
className,
}: LightIconButtonGroupProps) => (
<StyledLightIconButtonGroupContainer className={className}>
{iconButtons.map(({ Icon, onClick }, index) => {
return (
<LightIconButton
key={`light-icon-button-${index}`}
Icon={Icon}
onClick={onClick}
size={size}
/>
);
})}
</StyledLightIconButtonGroupContainer>
);

View File

@ -1,7 +1,7 @@
import { MouseEvent } from 'react'; import { MouseEvent } from 'react';
import { IconComponent } from '@/ui/display/icon/types/IconComponent'; import { IconComponent } from '@/ui/display/icon/types/IconComponent';
import { FloatingIconButtonGroup } from '@/ui/input/button/components/FloatingIconButtonGroup'; import { LightIconButtonGroup } from '@/ui/input/button/components/LightIconButtonGroup';
import { MenuItemLeftContent } from '../internals/components/MenuItemLeftContent'; import { MenuItemLeftContent } from '../internals/components/MenuItemLeftContent';
import { import {
@ -59,7 +59,7 @@ export const MenuItem = ({
</StyledMenuItemLeftContent> </StyledMenuItemLeftContent>
<div className="hoverable-buttons"> <div className="hoverable-buttons">
{showIconButtons && ( {showIconButtons && (
<FloatingIconButtonGroup iconButtons={iconButtons} size="small" /> <LightIconButtonGroup iconButtons={iconButtons} size="small" />
)} )}
</div> </div>
</StyledHoverableMenuItemBase> </StyledHoverableMenuItemBase>

View File

@ -1,5 +1,5 @@
import { IconComponent } from '@/ui/display/icon/types/IconComponent'; import { IconComponent } from '@/ui/display/icon/types/IconComponent';
import { FloatingIconButtonGroup } from '@/ui/input/button/components/FloatingIconButtonGroup'; import { LightIconButtonGroup } from '@/ui/input/button/components/LightIconButtonGroup';
import { MenuItemLeftContent } from '../internals/components/MenuItemLeftContent'; import { MenuItemLeftContent } from '../internals/components/MenuItemLeftContent';
import { StyledHoverableMenuItemBase } from '../internals/components/StyledMenuItemBase'; import { StyledHoverableMenuItemBase } from '../internals/components/StyledMenuItemBase';
@ -42,7 +42,7 @@ export const MenuItemDraggable = ({
showGrip={!isDragDisabled} showGrip={!isDragDisabled}
/> />
{showIconButtons && ( {showIconButtons && (
<FloatingIconButtonGroup <LightIconButtonGroup
className="hoverable-buttons" className="hoverable-buttons"
iconButtons={iconButtons} iconButtons={iconButtons}
/> />

View File

@ -91,6 +91,10 @@ export const StyledMenuItemLeftContent = styled.div`
gap: ${({ theme }) => theme.spacing(2)}; gap: ${({ theme }) => theme.spacing(2)};
min-width: 0; min-width: 0;
width: 100%; width: 100%;
& > svg {
flex-shrink: 0;
}
`; `;
export const StyledMenuItemRightContent = styled.div` export const StyledMenuItemRightContent = styled.div`
@ -114,6 +118,7 @@ export const StyledHoverableMenuItemBase = styled(StyledMenuItemBase)<{
& .hoverable-buttons { & .hoverable-buttons {
opacity: 1; opacity: 1;
pointer-events: auto; pointer-events: auto;
position: static;
} }
} }
`; `;