UNPKG

@blueprintjs/core

Version:

Core styles & components

77 lines 3.72 kB
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime"; /* * Copyright 2015 Palantir Technologies, Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import classNames from "classnames"; import { createRef } from "react"; import { IconSize, SmallCross } from "@blueprintjs/icons"; import { AbstractPureComponent, Classes, DISPLAYNAME_PREFIX, mergeRefs, } from "../../common"; import * as Errors from "../../common/errors"; import { uniqueId } from "../../common/utils"; import { Button } from "../button/buttons"; import { H6 } from "../html/html"; import { Icon } from "../icon/icon"; import { Overlay2, OVERLAY2_DEFAULT_PROPS } from "../overlay2/overlay2"; /** * Dialog component. * * @see https://blueprintjs.com/docs/#core/components/dialog */ export class Dialog extends AbstractPureComponent { constructor(props) { super(props); this.childRef = createRef(); const id = uniqueId("bp-dialog"); this.titleId = `title-${id}`; } render() { var _a; const { className, children, containerRef, style, title, role = "dialog", ...overlayProps } = this.props; return (_jsx(Overlay2, { ...overlayProps, className: Classes.OVERLAY_SCROLL_CONTAINER, childRef: this.childRef, hasBackdrop: true, children: _jsx("div", { className: Classes.DIALOG_CONTAINER, ref: mergeRefs(containerRef, this.childRef), children: _jsxs("div", { className: classNames(Classes.DIALOG, className), role: role, "aria-modal": (_a = overlayProps.enforceFocus) !== null && _a !== void 0 ? _a : OVERLAY2_DEFAULT_PROPS.enforceFocus, "aria-labelledby": this.props["aria-labelledby"] || (title ? this.titleId : undefined), "aria-describedby": this.props["aria-describedby"], style: style, children: [this.maybeRenderHeader(), 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() { // show close button if prop is undefined or null // this gives us a behavior as if the default value were `true` if (this.props.isCloseButtonShown !== false) { return (_jsx(Button, { "aria-label": "Close", className: Classes.DIALOG_CLOSE_BUTTON, icon: _jsx(SmallCross, { size: IconSize.STANDARD }), onClick: this.props.onClose, variant: "minimal" })); } else { return undefined; } } maybeRenderHeader() { const { icon, title } = this.props; if (title == null) { return undefined; } return (_jsxs("div", { className: Classes.DIALOG_HEADER, children: [_jsx(Icon, { icon: icon, size: IconSize.STANDARD, "aria-hidden": true, tabIndex: -1 }), _jsx(H6, { id: this.titleId, children: title }), this.maybeRenderCloseButton()] })); } } Dialog.defaultProps = { canOutsideClickClose: true, isOpen: false, }; Dialog.displayName = `${DISPLAYNAME_PREFIX}.Dialog`; //# sourceMappingURL=dialog.js.map