2019-09-22 20:25:05 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import styled from "styled-components";
|
|
|
|
|
import { Icon } from "@blueprintjs/core";
|
|
|
|
|
import { Resizable, ResizeDirection } from "re-resizable";
|
|
|
|
|
import { WidgetProps, WidgetOperations } from "../widgets/BaseWidget";
|
|
|
|
|
import { ContainerProps } from "./ContainerComponent";
|
|
|
|
|
|
|
|
|
|
export type ResizableComponentProps = WidgetProps & ContainerProps;
|
|
|
|
|
|
|
|
|
|
const ResizableContainer = styled(Resizable)`
|
|
|
|
|
border: ${props => {
|
|
|
|
|
return Object.values(props.theme.borders[0]).join(" ");
|
|
|
|
|
}};
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const CustomHandle = (props: any) => <div {...props} />;
|
|
|
|
|
const BottomRightHandle = () => (
|
|
|
|
|
<CustomHandle>
|
|
|
|
|
<Icon iconSize={15} icon="arrow-bottom-right" />
|
|
|
|
|
</CustomHandle>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export const ResizableComponent = (props: ResizableComponentProps) => {
|
|
|
|
|
const updateSize = (
|
|
|
|
|
e: Event,
|
|
|
|
|
dir: ResizeDirection,
|
|
|
|
|
ref: any,
|
|
|
|
|
delta: { width: number; height: number },
|
|
|
|
|
) => {
|
|
|
|
|
props.updateWidget &&
|
|
|
|
|
props.updateWidget(WidgetOperations.RESIZE, props.widgetId, delta);
|
|
|
|
|
};
|
|
|
|
|
return (
|
|
|
|
|
<ResizableContainer
|
|
|
|
|
size={{
|
2019-09-24 12:36:03 +00:00
|
|
|
width: props.style.componentWidth as number,
|
|
|
|
|
height: props.style.componentHeight as number,
|
2019-09-22 20:25:05 +00:00
|
|
|
}}
|
|
|
|
|
style={{ ...props.style }}
|
|
|
|
|
handleComponent={{ bottomRight: <BottomRightHandle /> }}
|
|
|
|
|
onResizeStop={updateSize}
|
2019-09-25 21:38:03 +00:00
|
|
|
grid={[props.parentColumnSpace, props.parentRowSpace]}
|
|
|
|
|
enable={{
|
|
|
|
|
top: true,
|
|
|
|
|
right: true,
|
|
|
|
|
bottom: true,
|
|
|
|
|
left: true,
|
|
|
|
|
topRight: false,
|
|
|
|
|
topLeft: false,
|
|
|
|
|
bottomRight: true,
|
|
|
|
|
bottomLeft: true,
|
|
|
|
|
}}
|
2019-09-22 20:25:05 +00:00
|
|
|
>
|
|
|
|
|
{props.children}
|
|
|
|
|
</ResizableContainer>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default ResizableComponent;
|