Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add disabled style on non-draggable menu items #5974

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,9 +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 @@ -28,9 +33,24 @@ export const MenuItemDraggable = ({
isDragDisabled = false,
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 All @@ -41,7 +61,8 @@ export const MenuItemDraggable = ({
<MenuItemLeftContent
LeftIcon={LeftIcon}
text={text}
showGrip={!isDragDisabled}
isDisabled={isDragDisabled}
showGrip={showGrip}
/>
{showIconButtons && (
<LightIconButtonGroup
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 @@ -16,6 +17,7 @@ type MenuItemLeftContentProps = {
className?: string;
LeftIcon: IconComponent | null | undefined;
showGrip?: boolean;
isDisabled?: boolean;
text: ReactNode;
};

Expand All @@ -24,18 +26,34 @@ export const MenuItemLeftContent = ({
LeftIcon,
text,
showGrip = false,
isDisabled = false,
}: MenuItemLeftContentProps) => {
const theme = useTheme();

return (
<StyledMenuItemLeftContent className={className}>
{showGrip && (
<IconGripVertical
size={theme.icon.size.md}
stroke={theme.icon.stroke.sm}
color={theme.font.color.extraLight}
/>
)}
{showGrip &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant check for isDisabled inside the color prop.

(isDisabled ? (
<IconGripVertical
size={theme.icon.size.md}
stroke={theme.icon.stroke.sm}
color={
isDisabled ? theme.font.color.extraLight : theme.font.color.light
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant check for isDisabled inside the color prop.

}
/>
) : (
<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 @@ -19,7 +19,6 @@ import { DraggableItem } from '@/ui/layout/draggable-list/components/DraggableIt
import { DraggableList } from '@/ui/layout/draggable-list/components/DraggableList';
import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/DropdownMenuItemsContainer';
import { StyledDropdownMenuSubheader } from '@/ui/layout/dropdown/components/StyledDropdownMenuSubheader';
import { MenuItem } from '@/ui/navigation/menu-item/components/MenuItem';
import { MenuItemDraggable } from '@/ui/navigation/menu-item/components/MenuItemDraggable';
import { useListenClickOutside } from '@/ui/utilities/pointer-event/hooks/useListenClickOutside';
import { groupArrayItemsBy } from '~/utils/array/groupArrayItemsBy';
Expand Down Expand Up @@ -101,13 +100,17 @@ export const ViewFieldsVisibilityDropdownSection = ({
)}
<DropdownMenuItemsContainer>
{nonDraggableItems.map((field, fieldIndex) => (
<MenuItem
<MenuItemDraggable
key={field.fieldMetadataId}
LeftIcon={getIcon(field.iconName)}
iconButtons={getIconButtons(fieldIndex, field)}
isTooltipOpen={openToolTipIndex === fieldIndex}
text={field.label}
className={`${title}-fixed-item-tooltip-anchor-${fieldIndex}`}
accent={'placeholder'}
isHoverDisabled={field.isVisible}
showGrip
isDragDisabled
/>
))}
{!!draggableItems.length && (
Expand All @@ -131,6 +134,7 @@ export const ViewFieldsVisibilityDropdownSection = ({
isTooltipOpen={openToolTipIndex === fieldIndex}
text={field.label}
className={`${title}-draggable-item-tooltip-anchor-${fieldIndex}`}
showGrip
/>
}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const ViewPickerListContent = () => {
)}
/>
{indexView && (
<MenuItem
<MenuItemDraggable
key={indexView.id}
iconButtons={[
{
Expand All @@ -128,6 +128,8 @@ export const ViewPickerListContent = () => {
onClick={() => handleViewSelect(indexView.id)}
LeftIcon={getIcon(indexView.icon)}
text={indexView.name}
accent="placeholder"
isDragDisabled
/>
)}
</DropdownMenuItemsContainer>
Expand Down
Loading