Skip to content

Commit

Permalink
Add grip pointer + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thomtrp committed Jun 21, 2024
1 parent 62fb207 commit 75c4040
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { IconComponent } from 'twenty-ui';
import { LightIconButtonGroup } from '@/ui/input/button/components/LightIconButtonGroup';

import { MenuItemLeftContent } from '../internals/components/MenuItemLeftContent';
import { StyledHoverableMenuItemBase } from '../internals/components/StyledMenuItemBase';
import {
StyledHoverableMenuItemBase,
StyledMenuItemBase,
} from '../internals/components/StyledMenuItemBase';
import { MenuItemAccent } from '../types/MenuItemAccent';

import { MenuItemIconButton } from './MenuItem';
Expand All @@ -15,10 +18,11 @@ export type MenuItemDraggableProps = {
isTooltipOpen?: boolean;
onClick?: () => void;
text: string;
isDragDisabled?: boolean;
className?: string;
isIconDisplayedOnHoverOnly?: boolean;
showGrip?: boolean;
isDragDisabled?: boolean;
isHoverDisabled?: boolean;
};
export const MenuItemDraggable = ({
LeftIcon,
Expand All @@ -30,9 +34,23 @@ export const MenuItemDraggable = ({
className,
isIconDisplayedOnHoverOnly = true,
showGrip = false,
isHoverDisabled = false,
}: MenuItemDraggableProps) => {
const showIconButtons = Array.isArray(iconButtons) && iconButtons.length > 0;

if (isHoverDisabled) {
return (
<StyledMenuItemBase accent={accent} isHoverBackgroundDisabled>
<MenuItemLeftContent
LeftIcon={LeftIcon}
text={text}
isDisabled={isDragDisabled}
showGrip={showGrip}
/>
</StyledMenuItemBase>
);
}

return (
<StyledHoverableMenuItemBase
onClick={onClick}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,11 @@ export const Catalog: Story = {
},
decorators: [CatalogDecorator],
};

export const Grip: Story = {
args: { ...Default.args, showGrip: true, isDragDisabled: false },
};

export const HoverDisabled: Story = {
args: { ...Default.args, isHoverDisabled: true },
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from 'twenty-ui';

import {
StyledDraggableItem,
StyledMenuItemLabel,
StyledMenuItemLeftContent,
} from './StyledMenuItemBase';
Expand All @@ -31,15 +32,28 @@ export const MenuItemLeftContent = ({

return (
<StyledMenuItemLeftContent className={className}>
{showGrip && (
<IconGripVertical
size={theme.icon.size.md}
stroke={theme.icon.stroke.sm}
color={
isDisabled ? theme.font.color.extraLight : theme.font.color.light
}
/>
)}
{showGrip &&
(isDisabled ? (
<IconGripVertical
size={theme.icon.size.md}
stroke={theme.icon.stroke.sm}
color={
isDisabled ? theme.font.color.extraLight : theme.font.color.light
}
/>
) : (
<StyledDraggableItem>
<IconGripVertical
size={theme.icon.size.md}
stroke={theme.icon.stroke.sm}
color={
isDisabled
? theme.font.color.extraLight
: theme.font.color.light
}
/>
</StyledDraggableItem>
))}
{LeftIcon && (
<LeftIcon size={theme.icon.size.md} stroke={theme.icon.stroke.sm} />
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { MenuItemAccent } from '../../types/MenuItemAccent';
export type MenuItemBaseProps = {
accent?: MenuItemAccent;
isKeySelected?: boolean;
isHoverBackgroundDisabled?: boolean;
};

export const StyledMenuItemBase = styled.div<MenuItemBaseProps>`
Expand All @@ -31,7 +32,8 @@ export const StyledMenuItemBase = styled.div<MenuItemBaseProps>`
padding: var(--vertical-padding) var(--horizontal-padding);
${HOVER_BACKGROUND};
${({ isHoverBackgroundDisabled }) =>
isHoverBackgroundDisabled ?? HOVER_BACKGROUND};
${({ theme, accent }) => {
switch (accent) {
Expand Down Expand Up @@ -99,6 +101,10 @@ export const StyledMenuItemRightContent = styled.div`
flex-direction: row;
`;

export const StyledDraggableItem = styled.div`
cursor: grab;
`;

export const StyledHoverableMenuItemBase = styled(StyledMenuItemBase)<{
isIconDisplayedOnHoverOnly?: boolean;
}>`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ export const ViewFieldsVisibilityDropdownSection = ({
isTooltipOpen={openToolTipIndex === fieldIndex}
text={field.label}
className={`${title}-fixed-item-tooltip-anchor-${fieldIndex}`}
accent="placeholder"
isDragDisabled
accent={'placeholder'}
isHoverDisabled={field.isVisible}
showGrip
isDragDisabled
/>
))}
{!!draggableItems.length && (
Expand Down

0 comments on commit 75c4040

Please sign in to comment.