react-konva-grid
Advanced tools
Comparing version 2.7.0 to 2.7.1
import React from "react"; | ||
import { CellInterface, GridRef } from "../Grid"; | ||
export interface TooltipOptions { | ||
getTooltipComponent?: (cell?: CellInterface | null) => React.ElementType; | ||
component?: React.FC<TooltipProps> | React.ComponentClass<TooltipProps>; | ||
gridRef: React.MutableRefObject<GridRef>; | ||
@@ -9,3 +9,3 @@ getValue: (cell: CellInterface) => any; | ||
export interface TooltipResults { | ||
tooltipComponent: React.ReactNode; | ||
tooltipComponent: React.ReactElement | null; | ||
onMouseMove: (e: React.MouseEvent<HTMLInputElement>) => void; | ||
@@ -19,3 +19,3 @@ onMouseLeave: (e: React.MouseEvent<HTMLInputElement>) => void; | ||
} | ||
declare const useTooltip: ({ getValue, gridRef, getTooltipComponent, }: TooltipOptions) => TooltipResults; | ||
declare const useTooltip: ({ getValue, gridRef, component: Component, }: TooltipOptions) => TooltipResults; | ||
export default useTooltip; |
@@ -23,3 +23,3 @@ "use strict"; | ||
const react_1 = __importStar(require("react")); | ||
const defaultTooltipComponent = ({ content, x, y }) => { | ||
const DefaultTooltipComponent = ({ content, x, y }) => { | ||
const offset = 10; | ||
@@ -38,4 +38,3 @@ return (react_1.default.createElement("div", { style: { | ||
}; | ||
const getDefaultTooltipComponent = () => defaultTooltipComponent; | ||
const useTooltip = ({ getValue, gridRef, getTooltipComponent = getDefaultTooltipComponent, }) => { | ||
const useTooltip = ({ getValue, gridRef, component: Component = DefaultTooltipComponent, }) => { | ||
const [activeCell, setActiveCell] = react_1.useState(null); | ||
@@ -45,4 +44,8 @@ const [tooltipPosition, setTooltipPosition] = react_1.useState({ x: 0, y: 0 }); | ||
const showTooltip = activeCell && content !== null; | ||
const Tooltip = react_1.useMemo(() => getTooltipComponent(activeCell), [activeCell]); | ||
const tooltipComponent = showTooltip ? (react_1.default.createElement(Tooltip, { content: content, x: tooltipPosition.x, y: tooltipPosition.y })) : null; | ||
const tooltipProps = { | ||
content, | ||
x: tooltipPosition.x, | ||
y: tooltipPosition.y, | ||
}; | ||
const tooltipComponent = showTooltip ? react_1.default.createElement(Component, Object.assign({}, tooltipProps)) : null; | ||
const handleMouseMove = react_1.useCallback((e) => { | ||
@@ -49,0 +52,0 @@ const { rowIndex, columnIndex } = gridRef.current.getCellCoordsFromOffset(e.clientX, e.clientY); |
{ | ||
"name": "react-konva-grid", | ||
"description": "Declarative React Canvas Grid primitive for Data table, Pivot table, Excel Worksheets", | ||
"version": "2.7.0", | ||
"version": "2.7.1", | ||
"main": "dist/index.js", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21427
14792469