/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
/** * This component represents a Splitter. The splitter supports vertical * as well as horizontal mode.
*/ class SplitBox extends Component { static get propTypes() { return { // Custom class name. You can use more names separated by a space.
className: PropTypes.string, // Initial size of controlled panel.
initialSize: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), // Initial width of controlled panel.
initialWidth: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), // Initial height of controlled panel.
initialHeight: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), // Left/top panel
startPanel: PropTypes.any, // Left/top panel collapse state.
startPanelCollapsed: PropTypes.bool, // Min panel size.
minSize: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), // Max panel size.
maxSize: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), // Right/bottom panel
endPanel: PropTypes.any, // Right/bottom panel collapse state.
endPanelCollapsed: PropTypes.bool, // True if the right/bottom panel should be controlled.
endPanelControl: PropTypes.bool, // Size of the splitter handle bar.
splitterSize: PropTypes.number, // True if the splitter bar is vertical (default is vertical).
vert: PropTypes.bool, // Style object.
style: PropTypes.object, // Call when controlled panel was resized.
onControlledPanelResized: PropTypes.func, // Optional callback when splitbox resize stops
onResizeEnd: PropTypes.func, // Retrieve DOM reference to the start panel element
onSelectContainerElement: PropTypes.any,
};
}
/** * The state stores whether or not the end panel should be controlled, the current * orientation (vertical or horizontal), the splitter size, and the current size * (width/height). All these values can change during the component's life time.
*/ this.state = { // True if the right/bottom panel should be controlled.
endPanelControl: props.endPanelControl, // True if the splitter bar is vertical (default is vertical).
vert: props.vert, // Size of the splitter handle bar.
splitterSize: props.splitterSize, // The state for above 3 properties are derived from props, but also managed by the component itself. // SplitBox manages it's own state but sometimes the parent will pass in new props which will // override the current state of the component. So we need track the prev value of these props so that // compare them to the props change and derive new state whenever these 3 props change.
prevEndPanelControl: props.endPanelControl,
prevVert: props.vert,
prevSplitterSize: props.splitterSize, // Width of controlled panel.
width: props.initialWidth || props.initialSize, // Height of controlled panel.
height: props.initialHeight || props.initialSize,
};
/** * Set 'resizing' cursor on entire document during splitter dragging. * This avoids cursor-flickering that happens when the mouse leaves * the splitter bar area (happens frequently).
*/
onStartMove() { const doc = this.splitBox.ownerDocument; const defaultCursor = doc.documentElement.style.cursor;
doc.documentElement.style.cursor = this.state.vert
? "ew-resize"
: "ns-resize";
/** * Adjust size of the controlled panel. Depending on the current * orientation we either remember the width or height of * the splitter box.
*/
onMove(x, y) { const nodeBounds = this.splitBox.getBoundingClientRect();
let size;
let { endPanelControl, vert } = this.state;
if (vert) { // Use the document owning the SplitBox to detect rtl. The global document might be // the one bound to the toolbox shared BrowserRequire, which is irrelevant here. const doc = this.splitBox.ownerDocument;
// Switch the control flag in case of RTL. Note that RTL // has impact on vertical splitter only. if (doc.dir === "rtl") {
endPanelControl = !endPanelControl;
}
size = endPanelControl
? nodeBounds.left + nodeBounds.width - x
: x - nodeBounds.left;
/** * Calculates the constrained size taking into account the minimum width or * height passed via this.props.minSize. * * @param {Number} requestedSize * The requested size * @param {Number} splitBoxWidthOrHeight * The width or height of the splitBox * * @return {Number} * The constrained size
*/
getConstrainedSizeInPx(requestedSize, splitBoxWidthOrHeight) {
let minSize = this.props.minSize + "";
const style = Object.assign(
{ // Set the size of the controlled panel (height or width depending on the // current state). This can be used to help with styling of dependent // panels. "--split-box-controlled-panel-size": `${
vert ? this.state.width : this.state.height
}`,
}, this.props.style
);
// Calculate class names list.
let classNames = ["split-box"];
classNames.push(vert ? "vert" : "horz"); if (this.props.className) {
classNames = classNames.concat(this.props.className.split(" "));
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.