UNPKG

@primer/react

Version:

An implementation of GitHub's Primer Design System using React

161 lines (154 loc) 3.76 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var reactCompilerRuntime = require('react-compiler-runtime'); var React = require('react'); var clsx = require('clsx'); var Details_module = require('./Details.module.css.js'); var useMergedRefs = require('../internal/hooks/useMergedRefs.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 Root = /*#__PURE__*/React__default.default.forwardRef((t0, forwardRef) => { const $ = reactCompilerRuntime.c(16); 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__default.default.useRef(null); const ref = useMergedRefs.useMergedRefs(forwardRef, detailsRef); const [hasSummary, setHasSummary] = React.useState(false); let t1; let t2; if ($[4] === Symbol.for("react.memo_cache_sentinel")) { t1 = () => { const { current: details } = detailsRef; if (!details) { return; } const updateSummary = () => { const summary = details.querySelector("summary:not([data-default-summary])"); setHasSummary(!!summary); }; updateSummary(); const observer = new MutationObserver(() => { updateSummary(); }); observer.observe(details, { childList: true, subtree: true }); return () => { observer.disconnect(); }; }; t2 = []; $[4] = t1; $[5] = t2; } else { t1 = $[4]; t2 = $[5]; } React.useEffect(t1, t2); let t3; if ($[6] !== className) { t3 = clsx.clsx(className, Details_module.Details); $[6] = className; $[7] = t3; } else { t3 = $[7]; } let t4; if ($[8] !== hasSummary) { t4 = !hasSummary && /*#__PURE__*/jsxRuntime.jsx(Details.Summary, { "data-default-summary": true, children: "See Details" }); $[8] = hasSummary; $[9] = t4; } else { t4 = $[9]; } let t5; if ($[10] !== children || $[11] !== ref || $[12] !== rest || $[13] !== t3 || $[14] !== t4) { t5 = /*#__PURE__*/jsxRuntime.jsxs(BoxWithFallback.BoxWithFallback, { as: "details", className: t3, ...rest, ref: ref, children: [t4, children] }); $[10] = children; $[11] = ref; $[12] = rest; $[13] = t3; $[14] = t4; $[15] = t5; } else { t5 = $[15]; } return t5; }); Root.displayName = 'Details'; function Summary(t0) { var _as; const $ = reactCompilerRuntime.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__*/jsxRuntime.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 }); exports.Summary = Summary; exports.default = Details;