diff --git a/packages/module/src/WidgetLayout/WidgetDrawer.tsx b/packages/module/src/WidgetLayout/WidgetDrawer.tsx index ace746b..217b736 100644 --- a/packages/module/src/WidgetLayout/WidgetDrawer.tsx +++ b/packages/module/src/WidgetLayout/WidgetDrawer.tsx @@ -13,9 +13,10 @@ import { Title, Tooltip, } from '@patternfly/react-core'; -import React, { useState } from 'react'; +import React, { useLayoutEffect, useRef, useState } from 'react'; import CloseIcon from '@patternfly/react-icons/dist/esm/icons/close-icon'; import GripVerticalIcon from '@patternfly/react-icons/dist/esm/icons/grip-vertical-icon'; +import PlusCircleIcon from '@patternfly/react-icons/dist/esm/icons/plus-circle-icon'; import { WidgetMapping, WidgetConfiguration } from './types'; export type WidgetDrawerProps = React.PropsWithChildren<{ @@ -33,23 +34,20 @@ export type WidgetDrawerProps = React.PropsWithChildren<{ onWidgetDragStart?: (widgetType: string) => void; /** Callback when widget drag ends */ onWidgetDragEnd?: () => void; + /** Callback when a widget is added with the keyboard */ + onWidgetAdd?: (widgetType: string) => void; + /** Whether additions are unavailable because the layout is locked */ + isDisabled?: boolean; }>; -const WidgetWrapper = ({ widgetType, config, onDragStart, onDragEnd }: { +const WidgetWrapper = ({ widgetType, config, onDragStart, onDragEnd, onAdd, isDisabled }: { widgetType: string; config?: WidgetConfiguration; onDragStart: (widgetType: string) => void; onDragEnd: () => void; -}) => { - const headerActions = ( - Drag to add widget

}> - - - -
- ); - - return ( + onAdd?: (widgetType: string, event: React.MouseEvent) => void; + isDisabled?: boolean; +}) => ( { const nodeRect = (e.target as HTMLElement).getBoundingClientRect(); @@ -71,11 +69,37 @@ const WidgetWrapper = ({ widgetType, config, onDragStart, onDragEnd }: { onDragEnd={onDragEnd} unselectable="on" - draggable={true} + draggable={!isDisabled} className="pf-v6-widget-grid-tile" ouiaId={`add-widget-card-${config?.title || widgetType}`} > - + + Drag to add widget

}> + + + +
+ {onAdd && ( +