Add disabled style on non-draggable menu items (#5974)
Closes https://github.com/twentyhq/twenty/issues/5653 <img width="256" alt="Capture d’écran 2024-06-20 à 17 19 44" src="https://github.com/twentyhq/twenty/assets/22936103/c9d7e58f-818b-44f2-8aa4-4d85c8e1b6be"> <img width="231" alt="Capture d’écran 2024-06-20 à 17 20 03" src="https://github.com/twentyhq/twenty/assets/22936103/5e981e93-9d59-403a-bb6b-0ff75151ace2">
This commit is contained in:
@ -3,7 +3,10 @@ import { IconComponent } from 'twenty-ui';
|
|||||||
import { LightIconButtonGroup } from '@/ui/input/button/components/LightIconButtonGroup';
|
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,
|
||||||
|
StyledMenuItemBase,
|
||||||
|
} from '../internals/components/StyledMenuItemBase';
|
||||||
import { MenuItemAccent } from '../types/MenuItemAccent';
|
import { MenuItemAccent } from '../types/MenuItemAccent';
|
||||||
|
|
||||||
import { MenuItemIconButton } from './MenuItem';
|
import { MenuItemIconButton } from './MenuItem';
|
||||||
@ -15,9 +18,11 @@ export type MenuItemDraggableProps = {
|
|||||||
isTooltipOpen?: boolean;
|
isTooltipOpen?: boolean;
|
||||||
onClick?: () => void;
|
onClick?: () => void;
|
||||||
text: string;
|
text: string;
|
||||||
isDragDisabled?: boolean;
|
|
||||||
className?: string;
|
className?: string;
|
||||||
isIconDisplayedOnHoverOnly?: boolean;
|
isIconDisplayedOnHoverOnly?: boolean;
|
||||||
|
showGrip?: boolean;
|
||||||
|
isDragDisabled?: boolean;
|
||||||
|
isHoverDisabled?: boolean;
|
||||||
};
|
};
|
||||||
export const MenuItemDraggable = ({
|
export const MenuItemDraggable = ({
|
||||||
LeftIcon,
|
LeftIcon,
|
||||||
@ -28,9 +33,24 @@ export const MenuItemDraggable = ({
|
|||||||
isDragDisabled = false,
|
isDragDisabled = false,
|
||||||
className,
|
className,
|
||||||
isIconDisplayedOnHoverOnly = true,
|
isIconDisplayedOnHoverOnly = true,
|
||||||
|
showGrip = false,
|
||||||
|
isHoverDisabled = false,
|
||||||
}: MenuItemDraggableProps) => {
|
}: MenuItemDraggableProps) => {
|
||||||
const showIconButtons = Array.isArray(iconButtons) && iconButtons.length > 0;
|
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 (
|
return (
|
||||||
<StyledHoverableMenuItemBase
|
<StyledHoverableMenuItemBase
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
@ -41,7 +61,8 @@ export const MenuItemDraggable = ({
|
|||||||
<MenuItemLeftContent
|
<MenuItemLeftContent
|
||||||
LeftIcon={LeftIcon}
|
LeftIcon={LeftIcon}
|
||||||
text={text}
|
text={text}
|
||||||
showGrip={!isDragDisabled}
|
isDisabled={isDragDisabled}
|
||||||
|
showGrip={showGrip}
|
||||||
/>
|
/>
|
||||||
{showIconButtons && (
|
{showIconButtons && (
|
||||||
<LightIconButtonGroup
|
<LightIconButtonGroup
|
||||||
|
|||||||
@ -104,3 +104,11 @@ export const Catalog: Story = {
|
|||||||
},
|
},
|
||||||
decorators: [CatalogDecorator],
|
decorators: [CatalogDecorator],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const Grip: Story = {
|
||||||
|
args: { ...Default.args, showGrip: true, isDragDisabled: false },
|
||||||
|
};
|
||||||
|
|
||||||
|
export const HoverDisabled: Story = {
|
||||||
|
args: { ...Default.args, isHoverDisabled: true },
|
||||||
|
};
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import {
|
|||||||
} from 'twenty-ui';
|
} from 'twenty-ui';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
StyledDraggableItem,
|
||||||
StyledMenuItemLabel,
|
StyledMenuItemLabel,
|
||||||
StyledMenuItemLeftContent,
|
StyledMenuItemLeftContent,
|
||||||
} from './StyledMenuItemBase';
|
} from './StyledMenuItemBase';
|
||||||
@ -16,6 +17,7 @@ type MenuItemLeftContentProps = {
|
|||||||
className?: string;
|
className?: string;
|
||||||
LeftIcon: IconComponent | null | undefined;
|
LeftIcon: IconComponent | null | undefined;
|
||||||
showGrip?: boolean;
|
showGrip?: boolean;
|
||||||
|
isDisabled?: boolean;
|
||||||
text: ReactNode;
|
text: ReactNode;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -24,18 +26,34 @@ export const MenuItemLeftContent = ({
|
|||||||
LeftIcon,
|
LeftIcon,
|
||||||
text,
|
text,
|
||||||
showGrip = false,
|
showGrip = false,
|
||||||
|
isDisabled = false,
|
||||||
}: MenuItemLeftContentProps) => {
|
}: MenuItemLeftContentProps) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledMenuItemLeftContent className={className}>
|
<StyledMenuItemLeftContent className={className}>
|
||||||
{showGrip && (
|
{showGrip &&
|
||||||
<IconGripVertical
|
(isDisabled ? (
|
||||||
size={theme.icon.size.md}
|
<IconGripVertical
|
||||||
stroke={theme.icon.stroke.sm}
|
size={theme.icon.size.md}
|
||||||
color={theme.font.color.extraLight}
|
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 && (
|
||||||
<LeftIcon size={theme.icon.size.md} stroke={theme.icon.stroke.sm} />
|
<LeftIcon size={theme.icon.size.md} stroke={theme.icon.stroke.sm} />
|
||||||
)}
|
)}
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import { MenuItemAccent } from '../../types/MenuItemAccent';
|
|||||||
export type MenuItemBaseProps = {
|
export type MenuItemBaseProps = {
|
||||||
accent?: MenuItemAccent;
|
accent?: MenuItemAccent;
|
||||||
isKeySelected?: boolean;
|
isKeySelected?: boolean;
|
||||||
|
isHoverBackgroundDisabled?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const StyledMenuItemBase = styled.div<MenuItemBaseProps>`
|
export const StyledMenuItemBase = styled.div<MenuItemBaseProps>`
|
||||||
@ -31,7 +32,8 @@ export const StyledMenuItemBase = styled.div<MenuItemBaseProps>`
|
|||||||
|
|
||||||
padding: var(--vertical-padding) var(--horizontal-padding);
|
padding: var(--vertical-padding) var(--horizontal-padding);
|
||||||
|
|
||||||
${HOVER_BACKGROUND};
|
${({ isHoverBackgroundDisabled }) =>
|
||||||
|
isHoverBackgroundDisabled ?? HOVER_BACKGROUND};
|
||||||
|
|
||||||
${({ theme, accent }) => {
|
${({ theme, accent }) => {
|
||||||
switch (accent) {
|
switch (accent) {
|
||||||
@ -99,6 +101,10 @@ export const StyledMenuItemRightContent = styled.div`
|
|||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
export const StyledDraggableItem = styled.div`
|
||||||
|
cursor: grab;
|
||||||
|
`;
|
||||||
|
|
||||||
export const StyledHoverableMenuItemBase = styled(StyledMenuItemBase)<{
|
export const StyledHoverableMenuItemBase = styled(StyledMenuItemBase)<{
|
||||||
isIconDisplayedOnHoverOnly?: boolean;
|
isIconDisplayedOnHoverOnly?: boolean;
|
||||||
}>`
|
}>`
|
||||||
|
|||||||
@ -19,7 +19,6 @@ import { DraggableItem } from '@/ui/layout/draggable-list/components/DraggableIt
|
|||||||
import { DraggableList } from '@/ui/layout/draggable-list/components/DraggableList';
|
import { DraggableList } from '@/ui/layout/draggable-list/components/DraggableList';
|
||||||
import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/DropdownMenuItemsContainer';
|
import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/DropdownMenuItemsContainer';
|
||||||
import { StyledDropdownMenuSubheader } from '@/ui/layout/dropdown/components/StyledDropdownMenuSubheader';
|
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 { MenuItemDraggable } from '@/ui/navigation/menu-item/components/MenuItemDraggable';
|
||||||
import { useListenClickOutside } from '@/ui/utilities/pointer-event/hooks/useListenClickOutside';
|
import { useListenClickOutside } from '@/ui/utilities/pointer-event/hooks/useListenClickOutside';
|
||||||
import { groupArrayItemsBy } from '~/utils/array/groupArrayItemsBy';
|
import { groupArrayItemsBy } from '~/utils/array/groupArrayItemsBy';
|
||||||
@ -101,13 +100,17 @@ export const ViewFieldsVisibilityDropdownSection = ({
|
|||||||
)}
|
)}
|
||||||
<DropdownMenuItemsContainer>
|
<DropdownMenuItemsContainer>
|
||||||
{nonDraggableItems.map((field, fieldIndex) => (
|
{nonDraggableItems.map((field, fieldIndex) => (
|
||||||
<MenuItem
|
<MenuItemDraggable
|
||||||
key={field.fieldMetadataId}
|
key={field.fieldMetadataId}
|
||||||
LeftIcon={getIcon(field.iconName)}
|
LeftIcon={getIcon(field.iconName)}
|
||||||
iconButtons={getIconButtons(fieldIndex, field)}
|
iconButtons={getIconButtons(fieldIndex, field)}
|
||||||
isTooltipOpen={openToolTipIndex === fieldIndex}
|
isTooltipOpen={openToolTipIndex === fieldIndex}
|
||||||
text={field.label}
|
text={field.label}
|
||||||
className={`${title}-fixed-item-tooltip-anchor-${fieldIndex}`}
|
className={`${title}-fixed-item-tooltip-anchor-${fieldIndex}`}
|
||||||
|
accent={'placeholder'}
|
||||||
|
isHoverDisabled={field.isVisible}
|
||||||
|
showGrip
|
||||||
|
isDragDisabled
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
{!!draggableItems.length && (
|
{!!draggableItems.length && (
|
||||||
@ -131,6 +134,7 @@ export const ViewFieldsVisibilityDropdownSection = ({
|
|||||||
isTooltipOpen={openToolTipIndex === fieldIndex}
|
isTooltipOpen={openToolTipIndex === fieldIndex}
|
||||||
text={field.label}
|
text={field.label}
|
||||||
className={`${title}-draggable-item-tooltip-anchor-${fieldIndex}`}
|
className={`${title}-draggable-item-tooltip-anchor-${fieldIndex}`}
|
||||||
|
showGrip
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@ -117,7 +117,7 @@ export const ViewPickerListContent = () => {
|
|||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
{indexView && (
|
{indexView && (
|
||||||
<MenuItem
|
<MenuItemDraggable
|
||||||
key={indexView.id}
|
key={indexView.id}
|
||||||
iconButtons={[
|
iconButtons={[
|
||||||
{
|
{
|
||||||
@ -128,6 +128,8 @@ export const ViewPickerListContent = () => {
|
|||||||
onClick={() => handleViewSelect(indexView.id)}
|
onClick={() => handleViewSelect(indexView.id)}
|
||||||
LeftIcon={getIcon(indexView.icon)}
|
LeftIcon={getIcon(indexView.icon)}
|
||||||
text={indexView.name}
|
text={indexView.name}
|
||||||
|
accent="placeholder"
|
||||||
|
isDragDisabled
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</DropdownMenuItemsContainer>
|
</DropdownMenuItemsContainer>
|
||||||
|
|||||||
Reference in New Issue
Block a user