UNPKG

@blueprintjs/core

Version:
67 lines 2.85 kB
/* * Copyright 2018 Palantir Technologies, Inc. All rights reserved. * * Licensed under the terms of the LICENSE file distributed with this project. */ import classNames from "classnames"; import * as React from "react"; import { AbstractPureComponent } from "../../common/abstractPureComponent"; import * as Classes from "../../common/classes"; import * as Errors from "../../common/errors"; import { DISPLAYNAME_PREFIX } from "../../common/props"; import { Button } from "../button/buttons"; import { H4 } from "../html/html"; import { Icon } from "../icon/icon"; import { Overlay } from "../overlay/overlay"; export class Drawer extends AbstractPureComponent { render() { const { size, style, vertical } = this.props; const classes = classNames(Classes.DRAWER, { [Classes.VERTICAL]: vertical }, this.props.className); const styleProp = size == null ? style : { ...style, [vertical ? "height" : "width"]: size }; return (React.createElement(Overlay, Object.assign({}, this.props, { className: Classes.OVERLAY_CONTAINER }), React.createElement("div", { className: classes, style: styleProp }, this.maybeRenderHeader(), this.props.children))); } validateProps(props) { if (props.title == null) { if (props.icon != null) { console.warn(Errors.DIALOG_WARN_NO_HEADER_ICON); } if (props.isCloseButtonShown != null) { console.warn(Errors.DIALOG_WARN_NO_HEADER_CLOSE_BUTTON); } } } maybeRenderCloseButton() { // `isCloseButtonShown` can't be defaulted through default props because of props validation // so this check actually defaults it to true (fails only if directly set to false) if (this.props.isCloseButtonShown !== false) { return (React.createElement(Button, { "aria-label": "Close", className: Classes.DIALOG_CLOSE_BUTTON, icon: React.createElement(Icon, { icon: "small-cross", iconSize: Icon.SIZE_LARGE }), minimal: true, onClick: this.props.onClose })); } else { return null; } } maybeRenderHeader() { const { icon, title } = this.props; if (title == null) { return null; } return (React.createElement("div", { className: Classes.DRAWER_HEADER }, React.createElement(Icon, { icon: icon, iconSize: Icon.SIZE_LARGE }), React.createElement(H4, null, title), this.maybeRenderCloseButton())); } } Drawer.displayName = `${DISPLAYNAME_PREFIX}.Drawer`; Drawer.defaultProps = { canOutsideClickClose: true, isOpen: false, style: {}, vertical: false, }; Drawer.SIZE_SMALL = "360px"; Drawer.SIZE_STANDARD = "50%"; Drawer.SIZE_LARGE = "90%"; //# sourceMappingURL=drawer.js.map