import React from 'react'; import { Button, Divider, ListItemIcon, Menu, MenuItem, SvgIcon, } from '@mui/material'; import { DataColumn as TableDataColumn, DataColumnFix, DataSortType } from '../types/column.type'; import { HeadersMessages } from '../types/head.type'; import { ArrowTooltip } from '../../tooltip/arrow'; import { TableHeadCellContent, TableHeaderCell, TableHeaderResizer, TableHeaderSorter, TableHeaderSorterHover } from './style'; interface DataColumn extends TableDataColumn { sticky?: number, } export interface DataTableHeadCellProps { column: DataColumn, messages: HeadersMessages, hideSort: boolean, onFixChange: (fix: DataColumnFix) => void, onSortChange: (sort: DataSortType) => void, onHiddenChange: (hidden: boolean) => void, children?: React.ReactNode | React.ReactNode[] | any } export const DataTableHeadCell: React.FC = ({ column, messages, hideSort, onFixChange, onHiddenChange, onSortChange }) => { const [menuAnchor, setMenuAnchor] = React.useState(null); const handleSortChange = () => { const value = column.sort === 'asc' ? 'desc' : 'asc'; if (onSortChange) { onSortChange(value) } } const handleOpenMenu = (event: React.MouseEvent) => { setMenuAnchor(event.currentTarget); } const handleCloseMenu = () => { setMenuAnchor(null); } const handleUnfix = () => { if (onFixChange) { onFixChange(undefined as any); } setMenuAnchor(null); } const handleFixToLeft = () => { if (onFixChange) { onFixChange('left'); } setMenuAnchor(null); } const handleFixToRight = () => { if (onFixChange) { onFixChange('right'); } setMenuAnchor(null); } const handleHide = () => { if (onHiddenChange) { onHiddenChange(true); } setMenuAnchor(null); } const getStyle = (column: DataColumn) => { const result: React.CSSProperties = { }; if (column) { if (column.width) { result.width = column.width; } if (column.minWidth) { result.minWidth = column.minWidth; } if (column.maxWidth) { result.maxWidth = column.maxWidth; } if (column.fix === 'left') { result.left = column.sticky ? column.sticky + 40 : 40; result.zIndex = 1000; result.position = 'sticky'; result.backgroundImage = 'linear-gradient(rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.05))'; } if (column.fix === 'right') { result.right = column.sticky ? column.sticky + 40 : 40; result.zIndex = 1000; result.position = 'sticky'; result.backgroundImage = 'linear-gradient(rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.05))'; } } return result; } return (
{ column.label }
{ column.sort === 'disabled' || hideSort ? <> : column.sort === 'asc' ? : column.sort === 'desc' ? : }
{ column.fix !== 'left' && {messages.fixToLeft} } { column.fix !== 'right' && {messages.fixToRight} } { column.fix && {messages.unfix} } {messages.hide}
) } const SortAscIcon = () => ( ) const SortDescIcon = () => ( ) const MenuIcon = () => ( ) const PinLeftIcon = () => ( ) const PinRightIcon = () => ( ) const UnpinIcon = () => ( ) const HideIcon = () => ( )