UNPKG

@primer/react

Version:

An implementation of GitHub's Primer Design System using React

130 lines (127 loc) 2.96 kB
import { c } from 'react-compiler-runtime'; import React, { useEffect } from 'react'; import { warning } from '../utils/warning.js'; import { clsx } from 'clsx'; import classes from './Details.module.css.js'; import { useMergedRefs } from '../internal/hooks/useMergedRefs.js'; import { jsx } from 'react/jsx-runtime'; const Root = /*#__PURE__*/React.forwardRef( // eslint-disable-next-line @typescript-eslint/no-explicit-any (t0, forwardRef) => { const $ = c(13); let children; let className; let rest; if ($[0] !== t0) { ({ className, children, ...rest } = t0); $[0] = t0; $[1] = children; $[2] = className; $[3] = rest; } else { children = $[1]; className = $[2]; rest = $[3]; } const detailsRef = React.useRef(null); const ref = useMergedRefs(forwardRef, detailsRef); let t1; let t2; if ($[4] === Symbol.for("react.memo_cache_sentinel")) { t1 = () => { if (!(process.env.NODE_ENV !== "production")) { return; } const { current: details } = detailsRef; if (!details) { return; } const summary = details.querySelector("summary:not([data-default-summary])"); process.env.NODE_ENV !== "production" ? warning(summary === null, "The <Details> component must have a <summary> child component. You can either use <Details.Summary> or a native <summary> element.") : void 0; }; t2 = []; $[4] = t1; $[5] = t2; } else { t1 = $[4]; t2 = $[5]; } useEffect(t1, t2); let t3; if ($[6] !== className) { t3 = clsx(className, classes.Details); $[6] = className; $[7] = t3; } else { t3 = $[7]; } let t4; if ($[8] !== children || $[9] !== ref || $[10] !== rest || $[11] !== t3) { t4 = /*#__PURE__*/jsx("details", { className: t3, ...rest, ref: ref, children: children }); $[8] = children; $[9] = ref; $[10] = rest; $[11] = t3; $[12] = t4; } else { t4 = $[12]; } return t4; }); Root.displayName = 'Details'; function Summary(t0) { var _as; const $ = c(9); let as; let children; let props; if ($[0] !== t0) { ({ as, children, ...props } = t0); $[0] = t0; $[1] = as; $[2] = children; $[3] = props; } else { as = $[1]; children = $[2]; props = $[3]; } const Component = (_as = as) !== null && _as !== void 0 ? _as : "summary"; const t1 = Component === "summary" ? null : "summary"; let t2; if ($[4] !== Component || $[5] !== children || $[6] !== props || $[7] !== t1) { t2 = /*#__PURE__*/jsx(Component, { as: t1, ...props, children: children }); $[4] = Component; $[5] = children; $[6] = props; $[7] = t1; $[8] = t2; } else { t2 = $[8]; } return t2; } Summary.displayName = 'Summary'; const Details = Object.assign(Root, { Summary }); export { Summary, Details as default };