UNPKG

@primer/react

Version:

An implementation of GitHub's Primer Design System using React

175 lines (174 loc) • 4.63 kB
import { useMergedRefs } from "../../hooks/useMergedRefs.js"; import { IconButton } from "../../Button/IconButton.js"; import useDialog from "../../hooks/useDialog.js"; import Dialog_module_css_default from "./Dialog.module.css.js"; import { c } from "react-compiler-runtime"; import { clsx } from "clsx"; import { Fragment, jsx, jsxs } from "react/jsx-runtime"; import React, { forwardRef, useRef } from "react"; import { XIcon } from "@primer/octicons-react"; //#region src/deprecated/DialogV1/Dialog.tsx const noop = () => null; function DialogHeader(t0) { const $ = c(14); let children; let className; let rest; let t1; if ($[0] !== t0) { ({children, className, as: t1, ...rest} = t0); $[0] = t0; $[1] = children; $[2] = className; $[3] = rest; $[4] = t1; } else { children = $[1]; className = $[2]; rest = $[3]; t1 = $[4]; } const Component = t1 === void 0 ? "div" : t1; if (React.Children.toArray(children).every(_temp)) { let t2; if ($[5] !== children) { t2 = /*#__PURE__*/ jsx("span", { className: Dialog_module_css_default.HeaderChild, children }); $[5] = children; $[6] = t2; } else t2 = $[6]; children = t2; } const t2 = rest; let t3; if ($[7] !== className) { t3 = clsx(Dialog_module_css_default.Header, className); $[7] = className; $[8] = t3; } else t3 = $[8]; let t4; if ($[9] !== Component || $[10] !== children || $[11] !== rest || $[12] !== t3) { t4 = /*#__PURE__*/ jsx(Component, { ...t2, className: t3, children }); $[9] = Component; $[10] = children; $[11] = rest; $[12] = t3; $[13] = t4; } else t4 = $[13]; return t4; } function _temp(ch) { return typeof ch === "string"; } const Dialog = /*#__PURE__*/ forwardRef((t0, forwardedRef) => { const $ = c(26); let children; let className; let initialFocusRef; let isOpen; let props; let returnFocusRef; let t1; let t2; if ($[0] !== t0) { ({children, onDismiss: t1, isOpen, initialFocusRef, returnFocusRef, className, as: t2, ...props} = t0); $[0] = t0; $[1] = children; $[2] = className; $[3] = initialFocusRef; $[4] = isOpen; $[5] = props; $[6] = returnFocusRef; $[7] = t1; $[8] = t2; } else { children = $[1]; className = $[2]; initialFocusRef = $[3]; isOpen = $[4]; props = $[5]; returnFocusRef = $[6]; t1 = $[7]; t2 = $[8]; } const onDismiss = t1 === void 0 ? noop : t1; const Component = t2 === void 0 ? "div" : t2; const overlayRef = useRef(null); const modalRef = useRef(null); const mergedRef = useMergedRefs(forwardedRef, modalRef); const closeButtonRef = useRef(null); let t3; if ($[9] !== onDismiss || $[10] !== returnFocusRef) { t3 = () => { onDismiss(); if (returnFocusRef && returnFocusRef.current) returnFocusRef.current.focus(); }; $[9] = onDismiss; $[10] = returnFocusRef; $[11] = t3; } else t3 = $[11]; const onCloseClick = t3; let t4; if ($[12] !== initialFocusRef || $[13] !== isOpen || $[14] !== onCloseClick || $[15] !== returnFocusRef) { t4 = { modalRef, onDismiss: onCloseClick, isOpen, initialFocusRef, closeButtonRef, returnFocusRef, overlayRef }; $[12] = initialFocusRef; $[13] = isOpen; $[14] = onCloseClick; $[15] = returnFocusRef; $[16] = t4; } else t4 = $[16]; const { getDialogProps } = useDialog(t4); let t5; if ($[17] !== Component || $[18] !== children || $[19] !== className || $[20] !== getDialogProps || $[21] !== isOpen || $[22] !== mergedRef || $[23] !== onCloseClick || $[24] !== props) { t5 = isOpen ? /*#__PURE__*/ jsxs(Fragment, { children: [/*#__PURE__*/ jsx("span", { className: Dialog_module_css_default.Overlay, ref: overlayRef }), /*#__PURE__*/ jsxs(Component, { tabIndex: -1, ref: mergedRef, role: "dialog", "aria-modal": "true", ...props, ...getDialogProps(), className: clsx(Dialog_module_css_default.Dialog, className), "data-width": props.wide ? "wide" : props.narrow ? "narrow" : "default", children: [/*#__PURE__*/ jsx(IconButton, { icon: XIcon, ref: closeButtonRef, onClick: onCloseClick, "aria-label": "Close", variant: "invisible", className: Dialog_module_css_default.CloseIcon }), children] })] }) : null; $[17] = Component; $[18] = children; $[19] = className; $[20] = getDialogProps; $[21] = isOpen; $[22] = mergedRef; $[23] = onCloseClick; $[24] = props; $[25] = t5; } else t5 = $[25]; return t5; }); DialogHeader.displayName = "Dialog.Header"; Dialog.displayName = "Dialog"; var Dialog_default = Object.assign(Dialog, { Header: DialogHeader }); //#endregion export { Dialog_default as default };