@primer/react
Version:
An implementation of GitHub's Primer Design System using React
206 lines (200 loc) • 5.26 kB
JavaScript
'use strict';
var reactCompilerRuntime = require('react-compiler-runtime');
var React = require('react');
var IconButton = require('../Button/IconButton.js');
var useDialog = require('../hooks/useDialog.js');
var useRefObjectAsForwardedRef = require('../hooks/useRefObjectAsForwardedRef.js');
var octiconsReact = require('@primer/octicons-react');
var clsx = require('clsx');
var Dialog_module = require('./Dialog.module.css.js');
var BoxWithFallback = require('../internal/components/BoxWithFallback.js');
var jsxRuntime = require('react/jsx-runtime');
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
var React__default = /*#__PURE__*/_interopDefault(React);
const noop = () => null;
function DialogHeader(t0) {
const $ = reactCompilerRuntime.c(12);
let children;
let className;
let rest;
if ($[0] !== t0) {
({
children,
className,
...rest
} = t0);
$[0] = t0;
$[1] = children;
$[2] = className;
$[3] = rest;
} else {
children = $[1];
className = $[2];
rest = $[3];
}
if (React__default.default.Children.toArray(children).every(_temp)) {
let t1;
if ($[4] !== children) {
t1 = /*#__PURE__*/jsxRuntime.jsx("span", {
className: Dialog_module.HeaderChild,
children: children
});
$[4] = children;
$[5] = t1;
} else {
t1 = $[5];
}
children = t1;
}
const t1 = rest;
let t2;
if ($[6] !== className) {
t2 = clsx.clsx(Dialog_module.Header, className);
$[6] = className;
$[7] = t2;
} else {
t2 = $[7];
}
let t3;
if ($[8] !== children || $[9] !== rest || $[10] !== t2) {
t3 = /*#__PURE__*/jsxRuntime.jsx(BoxWithFallback.BoxWithFallback, {
as: "div",
...t1,
className: t2,
children: children
});
$[8] = children;
$[9] = rest;
$[10] = t2;
$[11] = t3;
} else {
t3 = $[11];
}
return t3;
}
function _temp(ch) {
return typeof ch === "string";
}
const Dialog = /*#__PURE__*/React.forwardRef((t0, forwardedRef) => {
const $ = reactCompilerRuntime.c(23);
let children;
let className;
let initialFocusRef;
let isOpen;
let props;
let returnFocusRef;
let t1;
if ($[0] !== t0) {
({
children,
onDismiss: t1,
isOpen,
initialFocusRef,
returnFocusRef,
className,
...props
} = t0);
$[0] = t0;
$[1] = children;
$[2] = className;
$[3] = initialFocusRef;
$[4] = isOpen;
$[5] = props;
$[6] = returnFocusRef;
$[7] = t1;
} else {
children = $[1];
className = $[2];
initialFocusRef = $[3];
isOpen = $[4];
props = $[5];
returnFocusRef = $[6];
t1 = $[7];
}
const onDismiss = t1 === undefined ? noop : t1;
const overlayRef = React.useRef(null);
const modalRef = React.useRef(null);
useRefObjectAsForwardedRef.useRefObjectAsForwardedRef(forwardedRef, modalRef);
const closeButtonRef = React.useRef(null);
let t2;
if ($[8] !== onDismiss || $[9] !== returnFocusRef) {
t2 = () => {
onDismiss();
if (returnFocusRef && returnFocusRef.current) {
returnFocusRef.current.focus();
}
};
$[8] = onDismiss;
$[9] = returnFocusRef;
$[10] = t2;
} else {
t2 = $[10];
}
const onCloseClick = t2;
let t3;
if ($[11] !== initialFocusRef || $[12] !== isOpen || $[13] !== onCloseClick || $[14] !== returnFocusRef) {
t3 = {
modalRef,
onDismiss: onCloseClick,
isOpen,
initialFocusRef,
closeButtonRef,
returnFocusRef,
overlayRef
};
$[11] = initialFocusRef;
$[12] = isOpen;
$[13] = onCloseClick;
$[14] = returnFocusRef;
$[15] = t3;
} else {
t3 = $[15];
}
const {
getDialogProps
} = useDialog(t3);
let t4;
if ($[16] !== children || $[17] !== className || $[18] !== getDialogProps || $[19] !== isOpen || $[20] !== onCloseClick || $[21] !== props) {
t4 = isOpen ? /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
children: [/*#__PURE__*/jsxRuntime.jsx(BoxWithFallback.BoxWithFallback, {
as: "span",
className: Dialog_module.Overlay,
ref: overlayRef
}), /*#__PURE__*/jsxRuntime.jsxs(BoxWithFallback.BoxWithFallback, {
as: "div",
tabIndex: -1,
ref: modalRef,
role: "dialog",
"aria-modal": "true",
...props,
...getDialogProps(),
className: clsx.clsx(Dialog_module.Dialog, className),
"data-width": props.wide ? "wide" : props.narrow ? "narrow" : "default",
children: [/*#__PURE__*/jsxRuntime.jsx(IconButton.IconButton, {
icon: octiconsReact.XIcon,
ref: closeButtonRef,
onClick: onCloseClick,
"aria-label": "Close",
variant: "invisible",
className: Dialog_module.CloseIcon
}), children]
})]
}) : null;
$[16] = children;
$[17] = className;
$[18] = getDialogProps;
$[19] = isOpen;
$[20] = onCloseClick;
$[21] = props;
$[22] = t4;
} else {
t4 = $[22];
}
return t4;
});
DialogHeader.displayName = 'Dialog.Header';
Dialog.displayName = 'Dialog';
var Dialog$1 = Object.assign(Dialog, {
Header: DialogHeader
});
module.exports = Dialog$1;