-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
13 changed files
with
356 additions
and
54 deletions.
There are no files selected for viewing
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
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
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
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
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
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
88 changes: 88 additions & 0 deletions
88
front/src/modules/ui/table/components/EntityTableColumnMenu.tsx
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,88 @@ | ||
import React, { useRef } from 'react'; | ||
import { useTheme } from '@emotion/react'; | ||
import styled from '@emotion/styled'; | ||
|
||
import { IconButton } from '@/ui/button/components/IconButton'; | ||
import { IconButtonGroup } from '@/ui/button/components/IconButtonGroup'; | ||
import { DropdownMenu } from '@/ui/dropdown/components/DropdownMenu'; | ||
import { DropdownMenuItem } from '@/ui/dropdown/components/DropdownMenuItem'; | ||
import { DropdownMenuItemsContainer } from '@/ui/dropdown/components/DropdownMenuItemsContainer'; | ||
import { IconPlus } from '@/ui/icon'; | ||
import { useListenClickOutside } from '@/ui/utilities/click-outside/hooks/useListenClickOutside'; | ||
|
||
import { ViewFieldDefinition, ViewFieldMetadata } from '../types/ViewField'; | ||
|
||
const StyledColumnMenu = styled(DropdownMenu)` | ||
font-weight: ${({ theme }) => theme.font.weight.regular}; | ||
position: absolute; | ||
right: 0; | ||
z-index: ${({ theme }) => theme.lastLayerZIndex}; | ||
`; | ||
|
||
const StyledIconButtonGroup = styled(IconButtonGroup)` | ||
display: none; | ||
position: absolute; | ||
right: ${({ theme }) => theme.spacing(1)}; | ||
`; | ||
const styledIconButtonGroupClassName = 'column-menu-item-icon-button-group'; | ||
|
||
const StyledColumnMenuItem = styled(DropdownMenuItem)` | ||
position: relative; | ||
&:hover { | ||
.${styledIconButtonGroupClassName} { | ||
display: flex; | ||
} | ||
} | ||
`; | ||
|
||
type EntityTableColumnMenuProps = { | ||
onAddViewField: ( | ||
viewFieldDefinition: ViewFieldDefinition<ViewFieldMetadata>, | ||
) => void; | ||
onClickOutside?: () => void; | ||
viewFieldDefinitions: ViewFieldDefinition<ViewFieldMetadata>[]; | ||
}; | ||
|
||
export const EntityTableColumnMenu = ({ | ||
onAddViewField, | ||
onClickOutside = () => undefined, | ||
viewFieldDefinitions, | ||
}: EntityTableColumnMenuProps) => { | ||
const ref = useRef<HTMLDivElement>(null); | ||
const theme = useTheme(); | ||
|
||
useListenClickOutside({ | ||
refs: [ref], | ||
callback: onClickOutside, | ||
}); | ||
|
||
return ( | ||
<StyledColumnMenu ref={ref}> | ||
<DropdownMenuItemsContainer> | ||
{viewFieldDefinitions.map((viewFieldDefinition) => ( | ||
<StyledColumnMenuItem key={viewFieldDefinition.id}> | ||
{viewFieldDefinition.columnIcon && | ||
React.cloneElement(viewFieldDefinition.columnIcon, { | ||
size: theme.icon.size.md, | ||
})} | ||
{viewFieldDefinition.columnLabel} | ||
<StyledIconButtonGroup | ||
className={styledIconButtonGroupClassName} | ||
variant="transparent" | ||
size="small" | ||
> | ||
{[ | ||
<IconButton | ||
key={`${viewFieldDefinition.id}-add`} | ||
icon={<IconPlus size={theme.icon.size.sm} />} | ||
onClick={() => onAddViewField(viewFieldDefinition)} | ||
/>, | ||
]} | ||
</StyledIconButtonGroup> | ||
</StyledColumnMenuItem> | ||
))} | ||
</DropdownMenuItemsContainer> | ||
</StyledColumnMenu> | ||
); | ||
}; |
Oops, something went wrong.