-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
98 additions
and
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,76 @@ | ||
const GridItem: React.FC = (): JSX.Element => { | ||
return <>TODO</>; | ||
}; | ||
import { EuiPanel } from '@elastic/eui'; | ||
import { | ||
CSSProperties, | ||
MouseEvent, | ||
ReactNode, | ||
Ref, | ||
TouchEvent, | ||
forwardRef, | ||
} from 'react'; | ||
|
||
interface GridItemProps { | ||
/** | ||
* Required when using custom components as react-grid-layout children. | ||
*/ | ||
ref: Ref<HTMLDivElement>; | ||
/** | ||
* This property is passed to the item from the grid layout. | ||
* You must assign it to the same prop of the root element of the grid item. | ||
*/ | ||
style?: CSSProperties; | ||
/** | ||
* This property is passed to the item from the grid layout. | ||
* You must assign it to the same prop of the root element of the grid item. | ||
*/ | ||
className?: string; | ||
/** | ||
* This property is passed to the item from the grid layout. | ||
* You must assign it to the same prop of the root element of the grid item. | ||
*/ | ||
onMouseDown?: (e: MouseEvent<HTMLDivElement>) => void; | ||
/** | ||
* This property is passed to the item from the grid layout. | ||
* You must assign it to the same prop of the root element of the grid item. | ||
*/ | ||
onMouseUp?: (e: MouseEvent<HTMLDivElement>) => void; | ||
/** | ||
* This property is passed to the item from the grid layout. | ||
* You must assign it to the same prop of the root element of the grid item. | ||
*/ | ||
onTouchEnd?: (e: TouchEvent<HTMLDivElement>) => void; | ||
/** | ||
* This property contains any children nested within the grid item | ||
* when you're constructing the grid layout. | ||
* You must nest it within the root element of the grid item. | ||
*/ | ||
children?: ReactNode; | ||
} | ||
|
||
/** | ||
* How to use custom components as react-grid-layout children. | ||
* https://github.com/react-grid-layout/react-grid-layout/tree/master?tab=readme-ov-file#custom-child-components-and-draggable-handles | ||
* https://stackoverflow.com/questions/67053157/react-grid-layout-error-draggablecore-not-mounted-on-dragstart | ||
*/ | ||
const GridItem: React.FC<GridItemProps> = forwardRef< | ||
HTMLDivElement, | ||
GridItemProps | ||
>((props, ref): JSX.Element => { | ||
const { style, className, children, ...otherProps } = props; | ||
|
||
return ( | ||
<EuiPanel | ||
panelRef={ref} | ||
hasBorder={true} | ||
grow={false} | ||
style={style} | ||
className={className} | ||
{...otherProps} | ||
> | ||
{children} | ||
</EuiPanel> | ||
); | ||
}); | ||
|
||
GridItem.displayName = 'GridItem'; | ||
|
||
export { GridItem }; |
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