-
Notifications
You must be signed in to change notification settings - Fork 16
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
Create Menu component #2990
Open
luiqor
wants to merge
41
commits into
develop
Choose a base branch
from
feature/2962/create-menu-component
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Create Menu component #2990
Changes from 39 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
6c6ef1d
add basic Menu component
luiqor 3207989
enhance MenuItem
luiqor 3cc4ccb
enhance styles for density 2
luiqor eb17c67
add nested menu items
luiqor 7dbdaad
add isDropdown item
luiqor f46a4b7
replace isDropDown with dropDownIconVariant
luiqor c738a7a
add state logic
luiqor fde760b
replace Fragment with flatMap to fix MUI error
luiqor eaa88a2
replace isToggled handled in parent
luiqor e3d25a1
add onClick to stories
luiqor 82497b8
refactor types for MenuItem
luiqor 86f3f6e
add decorator with anchorEl to storybook
luiqor d9846f2
add Menu props
luiqor 9e78bab
add defaultOnItemClick
luiqor b42a3b6
add stories
luiqor a959490
update stories onClicks
luiqor 3e6988a
enhance style variants for menu item
luiqor 0c3dfa0
remove min width
luiqor 6868eb7
add custom menu positioning stories
luiqor a3acc96
add ability to remove items
luiqor 836be19
enhance remove items styles and logic
luiqor bee008f
enhance stories docs to include arguments and description
luiqor d0d0126
add MenuItem enums
luiqor b3bdc35
add constants to Menu
luiqor 091d3ba
add MenuItem to storybook
luiqor bcb6af3
enhance MenuItem documentation
luiqor b61c666
fix MenuItem checkbox
luiqor bc6b9b7
add initialy toggled functionallity
luiqor accdc9a
add toggleAsSingleItem
luiqor 032f604
add menu items removal tests
luiqor 83faba9
add Menu component tests
luiqor 6323fe7
add menu item tests
luiqor 2518256
add missing argTypes to storybook docs
luiqor 45347c2
fix elements with click handlers must have at least one keyboard list…
luiqor 5fb9b14
fix additional info line height
luiqor f3ff703
fix role button sonar issues
luiqor 5675a26
fix tabIndex on graphics divs sonar issues
luiqor 0782dc2
refactor divs to buttons to fix sonar issues
luiqor e2cf5e4
refactor defaultNoItemsMessage
luiqor d54af8e
refactor small code issues
luiqor 7d4eedb
remove redundant usage of useCallbacks
luiqor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
src/design-system/components/menu-item/MenuItem.constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export enum MenuItemColorVariant { | ||
Default = 'default', | ||
Danger = 'danger', | ||
Secondary = 'secondary' | ||
} | ||
|
||
export enum MenuItemVariant { | ||
Default = 'default', | ||
Nested = 'nested' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
@use '~scss/utilities' as *; | ||
|
||
.#{$prefix}item { | ||
background-color: $neutral-0; | ||
width: 100%; | ||
padding: 16px 8px; | ||
display: flex; | ||
justify-content: space-between; | ||
|
||
&:disabled { | ||
color: $blue-gray-700; | ||
} | ||
|
||
&:hover { | ||
background-color: $blue-gray-100; | ||
} | ||
|
||
&.selected { | ||
background-color: $blue-gray-50; | ||
} | ||
|
||
&--align-center { | ||
justify-content: center; | ||
} | ||
|
||
&--align-right { | ||
justify-content: flex-end; | ||
} | ||
|
||
&--density-1 { | ||
height: 48px; | ||
} | ||
|
||
&--density-2 { | ||
height: 64px; | ||
padding-top: 30px; | ||
} | ||
|
||
&--density-2 &-title { | ||
font-weight: $font-weight-medium; | ||
} | ||
|
||
&--density-2 &-additional-info { | ||
line-height: $line-height-sm; | ||
} | ||
|
||
&--variant-nested { | ||
background-color: $neutral-50; | ||
} | ||
|
||
&--toggled { | ||
background-color: $blue-gray-50; | ||
} | ||
|
||
&--default { | ||
color: $blue-gray-700; | ||
} | ||
|
||
&--color-danger { | ||
color: $red-500; | ||
} | ||
|
||
&--color-secondary { | ||
color: $blue-gray-500; | ||
} | ||
|
||
&--disabled { | ||
color: $blue-gray-700; | ||
} | ||
|
||
&--bottom-border { | ||
border-bottom: 1px solid $blue-gray-100; | ||
} | ||
|
||
&__graphics { | ||
width: 40px; | ||
height: 40px; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
background: none; | ||
border: none; | ||
} | ||
|
||
&__text-box { | ||
margin-left: 12px; | ||
display: flex; | ||
flex-direction: column; | ||
padding-right: 8px; | ||
} | ||
|
||
&__additional-info { | ||
font-size: $font-size-xs; | ||
color: $blue-gray-500; | ||
line-height: $line-height-sm; | ||
} | ||
|
||
&__main-info-box { | ||
display: flex; | ||
align-items: center; | ||
} | ||
|
||
&__close { | ||
font-size: $font-size-sm; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import { FC, useRef } from 'react' | ||
import { MenuItem as MuiMenuItem } from '@mui/material' | ||
import { ArrowDropDown, ArrowDropUp, CloseRounded } from '@mui/icons-material' | ||
|
||
import { MenuItemProps as CommonMenuItemProps } from './MenuItem.types' | ||
import { MenuItemColorVariant, MenuItemVariant } from './MenuItem.constants' | ||
import { cn } from '~/utils/cn' | ||
|
||
import '~scss-components/menu-item/MenuItem.scss' | ||
|
||
interface MenuItemProps extends CommonMenuItemProps { | ||
isDropdown?: boolean | ||
density?: 1 | 2 | ||
isToggled?: boolean | ||
onRemove?: () => void | ||
variant?: MenuItemVariant | ||
} | ||
|
||
const MenuItem: FC<MenuItemProps> = ({ | ||
title, | ||
additionalInfo, | ||
alignVariant = 'left', | ||
colorVariant = MenuItemColorVariant.Default, | ||
density = 1, | ||
graphics, | ||
isDropdown = false, | ||
isToggled = false, | ||
isBottomBorder = false, | ||
isDisabled = false, | ||
onClick, | ||
onRemove, | ||
variant = MenuItemVariant.Default | ||
}) => { | ||
const graphicsRef = useRef<HTMLButtonElement | null>(null) | ||
|
||
const handleClick = () => { | ||
if (graphicsRef.current) { | ||
const interactiveElement = | ||
graphicsRef.current.querySelector<HTMLInputElement>( | ||
'input[type="radio"], input[type="checkbox"], [role="radio"], [role="checkbox"]' | ||
) | ||
|
||
if (interactiveElement) { | ||
interactiveElement.click() | ||
return | ||
} | ||
} | ||
|
||
onClick?.() | ||
} | ||
|
||
const handleGraphicsClick = (event: React.MouseEvent) => { | ||
event.stopPropagation() | ||
onClick?.() | ||
} | ||
|
||
const handleRemoveItem = (event: React.MouseEvent) => { | ||
event.stopPropagation() | ||
onRemove?.() | ||
} | ||
|
||
return ( | ||
<MuiMenuItem | ||
className={cn( | ||
's2s-item', | ||
`s2s-item--density-${density}`, | ||
`s2s-item--variant-${variant}`, | ||
`s2s-item--color-${colorVariant}`, | ||
`s2s-item--align-${alignVariant}`, | ||
isToggled && 's2s-item--toggled', | ||
isBottomBorder && 's2s-item--bottom-border', | ||
isDisabled && 's2s-item--disabled' | ||
)} | ||
disabled={isDisabled} | ||
key={title} | ||
ShadowOfTheSpace marked this conversation as resolved.
Show resolved
Hide resolved
|
||
onClick={handleClick} | ||
> | ||
<div className='s2s-item__main-info-box'> | ||
{graphics && ( | ||
<button | ||
className='s2s-item__graphics' | ||
onClick={handleGraphicsClick} | ||
ref={graphicsRef} | ||
> | ||
{graphics} | ||
</button> | ||
)} | ||
<div className='s2s-item__text-box'> | ||
<span className='s2s-item__additional-info'>{additionalInfo}</span> | ||
<span className='s2s-item__title'>{title}</span> | ||
</div> | ||
</div> | ||
{isDropdown && ( | ||
<div className='s2s-item__graphics'> | ||
{isToggled ? <ArrowDropUp /> : <ArrowDropDown />} | ||
</div> | ||
)} | ||
{onRemove && !isDropdown && !isDisabled && ( | ||
<button className='s2s-item__graphics' onClick={handleRemoveItem}> | ||
<CloseRounded className='s2s-item__close' /> | ||
</button> | ||
)} | ||
</MuiMenuItem> | ||
) | ||
} | ||
|
||
export default MenuItem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { ReactNode } from 'react' | ||
import { MenuItemColorVariant } from './MenuItem.constants' | ||
|
||
export type OnItemClickArgs = Record<string, string | Event> | ||
|
||
export interface MenuItemProps { | ||
title: string | ||
additionalInfo?: string | ||
alignVariant?: 'left' | 'center' | 'right' | ||
colorVariant?: MenuItemColorVariant | ||
isDisabled?: boolean | ||
graphics?: ReactNode | ||
isBottomBorder?: boolean | ||
onClick?: () => void | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
@use '~scss/utilities' as *; | ||
|
||
.#{$prefix}menu { | ||
border-radius: 6px; | ||
box-shadow: | ||
0 0 8px 0 rgba(0, 0, 0, 0.08), | ||
0 10px 12px 0 rgba(0, 0, 0, 0.1); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get same result with using the element? Its default behaviour that it is clicking on input that currently inside the label.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you mean like that:
: unfortunately, checkbox then is not marked as selected on click.
When I am changing the button tag to label here, I can't get rid of onClick triggering two times, even with event.stopPropagation()