From ea3f09b6a96b8a6bdf5c12905aa080aff1e8ee55 Mon Sep 17 00:00:00 2001 From: kseniyakuzina Date: Sat, 3 Feb 2024 17:34:36 +0300 Subject: [PATCH] fix(MenuItem): fix non interactive MenuItem style --- src/components/Menu/Menu.scss | 12 +++- src/components/Menu/MenuItem.tsx | 6 +- .../Menu/__stories__/Menu.stories.tsx | 68 ++++++++++++------- 3 files changed, 58 insertions(+), 28 deletions(-) diff --git a/src/components/Menu/Menu.scss b/src/components/Menu/Menu.scss index ccab5a0a71..1b70eb18f7 100644 --- a/src/components/Menu/Menu.scss +++ b/src/components/Menu/Menu.scss @@ -26,7 +26,6 @@ $block: '.#{variables.$ns}menu'; &__item { display: flex; align-items: center; - cursor: pointer; color: var(--g-color-text-primary); text-decoration: none; outline: none; @@ -47,8 +46,15 @@ $block: '.#{variables.$ns}menu'; min-width: 0; } - &:hover, - &:focus, + &_interactive { + cursor: pointer; + + &:hover, + &:focus { + background-color: var(--g-color-base-simple-hover); + } + } + &_selected { background-color: var(--g-color-base-simple-hover); } diff --git a/src/components/Menu/MenuItem.tsx b/src/components/Menu/MenuItem.tsx index 0e1a10a494..a3336fad69 100644 --- a/src/components/Menu/MenuItem.tsx +++ b/src/components/Menu/MenuItem.tsx @@ -70,7 +70,11 @@ export const MenuItem = React.forwardRef(function Me onClickCapture: disabled ? undefined : handleClickCapture, style, tabIndex: disabled ? -1 : 0, - className: b('item', {disabled, active, selected, theme}, className), + className: b( + 'item', + {disabled, active, selected, theme, interactive: Boolean(onClick)}, + className, + ), 'data-qa': qa, }; const content = [ diff --git a/src/components/Menu/__stories__/Menu.stories.tsx b/src/components/Menu/__stories__/Menu.stories.tsx index 8fea81f3df..3de91fa9f3 100644 --- a/src/components/Menu/__stories__/Menu.stories.tsx +++ b/src/components/Menu/__stories__/Menu.stories.tsx @@ -1,6 +1,7 @@ import React from 'react'; import {CircleExclamationFill, Gear} from '@gravity-ui/icons'; +import {action} from '@storybook/addon-actions'; import type {Meta, StoryFn} from '@storybook/react'; import {Icon} from '../../Icon'; @@ -12,24 +13,36 @@ export default { component: Menu, } as Meta; +const createItemClickHandler = (text: string) => () => { + action(`Click ${text} item`); + alert(`${text} item clicked`); +}; + export const Default: StoryFn = (args) => ( - First - Second + First + Second ); export const ItemActive: StoryFn = (args) => ( - First - Second - Third + + First + + Second + Third ); export const ItemIcon: StoryFn = (args) => ( - }>Settings + } + onClick={createItemClickHandler('Settings')} + > + Settings + ); @@ -38,6 +51,7 @@ export const ItemBothIcons: StoryFn = (args) => ( } iconEnd={} + onClick={createItemClickHandler('Settings')} > Settings @@ -46,25 +60,31 @@ export const ItemBothIcons: StoryFn = (args) => ( export const ItemDisabled: StoryFn = (args) => ( - First - Second (unavailable) - Third + First + + Second (unavailable) + + Third ); export const ItemSelected: StoryFn = (args) => ( - First - Second - Third + First + Second + + Third + ); export const ItemTheme: StoryFn = (args) => ( - Normal - Danger - + Normal + + Danger + + Danger (disabled) @@ -86,20 +106,20 @@ export const ItemLink: StoryFn = (args) => ( export const Group: StoryFn = (args) => ( - First + First - One - Two + One + Two - One - Two + One + Two - Middle + Middle - One - Two + One + Two - Last + Last );