import React from 'react'; import Resizable from '../lib/Resizable'; import ResizableBox from '../lib/ResizableBox'; import 'style-loader!css-loader!../css/styles.css'; /* global __VERSION__, __GIT_TAG__, __GIT_COMMIT__ */ // Update the version badge in the header function updateVersionBadge() { const badge = document.getElementById('version-badge'); if (badge) { const version = __GIT_TAG__ || `v${__VERSION__}`; badge.textContent = version + (__GIT_COMMIT__ ? ` (${__GIT_COMMIT__})` : ''); badge.href = `https://github.com/react-grid-layout/react-resizable/releases/tag/${__GIT_TAG__ || __VERSION__}`; } } if (typeof document !== 'undefined') { if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', updateVersionBadge); } else { updateVersionBadge(); } } const CustomResizeHandle = React.forwardRef((props, ref) => { const {handleAxis, ...restProps} = props; return (
); }); export default class ExampleLayout extends React.Component<{}, {width: number, height: number}> { state = { width: 200, height: 200, absoluteWidth: 200, absoluteHeight: 200, absoluteLeft: 0, absoluteTop: 0, }; onResetClick = () => { this.setState({ width: 200, height: 200, absoluteWidth: 200, absoluteHeight: 200 }); }; // On top layout onFirstBoxResize = (event, {element, size, handle}) => { this.setState({width: size.width, height: size.height}); }; // On bottom layout. Used to resize the center element around its flex parent. onResizeAbsolute = (event, {element, size, handle}) => { this.setState((state) => { let newLeft = state.absoluteLeft; let newTop = state.absoluteTop; const deltaHeight = size.height - state.absoluteHeight; const deltaWidth = size.width - state.absoluteWidth; if (handle[0] === 'n') { newTop -= deltaHeight; } else if (handle[0] === 's') { newTop += deltaHeight; } if (handle[handle.length - 1] === 'w') { newLeft -= deltaWidth; } else if (handle[handle.length - 1] === 'e') { newLeft += deltaWidth; } return { absoluteWidth: size.width, absoluteHeight: size.height, absoluteLeft: newLeft, absoluteTop: newTop, }; }); }; render() { return (

Statically Positioned Layout

{"Raw use of element. 200x200, all Resize Handles."}
{""} } handleSize={[8, 8]}> {" with custom overflow style & handle in SE corner."} } handleSize={[8, 8]}> {" with a custom resize handle component."} } handleSize={[8, 8]} resizeHandles={['sw', 'se', 'nw', 'ne', 'w', 'e', 'n', 's']}> {" with custom handles in all locations."} Resizable box that snaps to even intervals of 25px. Resizable box, starting at 200x200. Min size is 150x150, max is 500x300. Resizable box with a handle that only appears on hover. Resizable square with a locked aspect ratio. Resizable rectangle with a locked aspect ratio. Only resizable by "x" axis. Only resizable by "y" axis. Resizable ("both" axis). Not resizable ("none" axis).

Absolutely Positioned Layout

Top-left Aligned Bottom-left Aligned {/* See implementation of `onResizeAbsolute` for how this can be moved around its container */}
{"Raw use of element with controlled position. Resize and reposition in all directions."}
Top-right Aligned Bottom-right Aligned

Scaled Absolute Layout

If you are nesting Resizables in an element with transform: scale(n), be sure to pass the same n  as the transformScale property. This layout has scale(0.75).
{" with correct transformScale={0.75}"} {" with correct transformScale={0.75}"} {/* See implementation of `onResizeAbsolute` for how this can be moved around its container */}
{"Raw use of element with controlled position. Resize and reposition in all directions."}
{" with correct transformScale={0.75}"} {"Without transformScale - notice how the cursor diverges from the handle while dragging"}
); } }