@primer/react
Version:
An implementation of GitHub's Primer Design System using React
208 lines (205 loc) • 4.98 kB
JavaScript
import { c } from 'react-compiler-runtime';
import React, { forwardRef, useRef } from 'react';
import { IconButton } from '../../Button/IconButton.js';
import useDialog from '../../hooks/useDialog.js';
import { useRefObjectAsForwardedRef } from '../../hooks/useRefObjectAsForwardedRef.js';
import { XIcon } from '@primer/octicons-react';
import { clsx } from 'clsx';
import classes from './Dialog.module.css.js';
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
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 === undefined ? "div" : t1;
if (React.Children.toArray(children).every(_temp)) {
let t2;
if ($[5] !== children) {
t2 = /*#__PURE__*/jsx("span", {
className: classes.HeaderChild,
children: children
});
$[5] = children;
$[6] = t2;
} else {
t2 = $[6];
}
children = t2;
}
const t2 = rest;
let t3;
if ($[7] !== className) {
t3 = clsx(classes.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: 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(25);
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 === undefined ? noop : t1;
const Component = t2 === undefined ? "div" : t2;
const overlayRef = useRef(null);
const modalRef = useRef(null);
useRefObjectAsForwardedRef(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] !== onCloseClick || $[23] !== props) {
t5 = isOpen ? /*#__PURE__*/jsxs(Fragment, {
children: [/*#__PURE__*/jsx("span", {
className: classes.Overlay,
ref: overlayRef
}), /*#__PURE__*/jsxs(Component, {
tabIndex: -1,
ref: modalRef,
role: "dialog",
"aria-modal": "true",
...props,
...getDialogProps(),
className: clsx(classes.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: classes.CloseIcon
}), children]
})]
}) : null;
$[17] = Component;
$[18] = children;
$[19] = className;
$[20] = getDialogProps;
$[21] = isOpen;
$[22] = onCloseClick;
$[23] = props;
$[24] = t5;
} else {
t5 = $[24];
}
return t5;
});
DialogHeader.displayName = 'Dialog.Header';
Dialog.displayName = 'Dialog';
var Dialog_default = Object.assign(Dialog, {
Header: DialogHeader
});
export { Dialog_default as default };