Skip to content

Commit f2fa997

Browse files
author
Kevin Verdieck
committed
Add the ability to customize the drag preview in MosaicWindow. Fixes #18
1 parent 769e683 commit f2fa997

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/window/MosaicWindow.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export interface MosaicWindowProps<T> {
4242
additionalControlButtonText?: string;
4343
draggable?: boolean;
4444
createNode?: CreateNode<T>;
45+
renderPreview?: (props: MosaicWindowProps<T>) => JSX.Element;
4546
}
4647

4748
interface DragSourceProps {
@@ -102,10 +103,19 @@ const dropTarget = { };
102103
})) as ClassDecorator)
103104
@PureRenderDecorator
104105
class MosaicWindowClass<T> extends React.Component<Props<T>, State> {
105-
static defaultProps = {
106+
static defaultProps: Partial<Props<any>> = {
106107
additionalControlButtonText: 'More',
107108
draggable: true,
108-
} as any;
109+
renderPreview: ({ title }) =>
110+
div({ className: 'mosaic-preview' },
111+
div({ className: 'mosaic-window-toolbar' },
112+
div({ className: 'mosaic-window-title' }, title)),
113+
div({ className: 'mosaic-window-body' },
114+
h4({}, title),
115+
span({ className: 'pt-icon pt-icon-application' }),
116+
),
117+
),
118+
};
109119

110120
static contextTypes = MosaicTileContext;
111121

@@ -130,7 +140,7 @@ class MosaicWindowClass<T> extends React.Component<Props<T>, State> {
130140
}
131141

132142
render() {
133-
const { className, isOver, title, additionalControls, connectDropTarget, connectDragPreview, draggedMosaicId } = this.props;
143+
const { className, isOver, renderPreview, additionalControls, connectDropTarget, connectDragPreview, draggedMosaicId } = this.props;
134144

135145
return connectDropTarget(div({
136146
className: classNames('mosaic-window mosaic-drop-target', className, {
@@ -150,16 +160,7 @@ class MosaicWindowClass<T> extends React.Component<Props<T>, State> {
150160
div({ className: 'mosaic-window-additional-actions-bar' },
151161
additionalControls,
152162
),
153-
connectDragPreview(
154-
div({ className: 'mosaic-preview' },
155-
div({ className: 'mosaic-window-toolbar' },
156-
div({ className: 'mosaic-window-title' }, title)),
157-
div({ className: 'mosaic-window-body' },
158-
h4({}, title),
159-
span({ className: 'pt-icon pt-icon-application' }),
160-
),
161-
),
162-
),
163+
connectDragPreview(renderPreview!(this.props)),
163164
div({ className: 'drop-target-container' },
164165
_.values<string>(MosaicDropTargetPosition).map(this.renderDropTarget),
165166
),

0 commit comments

Comments
 (0)