UNPKG

@primer/react

Version:

An implementation of GitHub's Primer Design System using React

139 lines (136 loc) 3.31 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 '../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) => { var _dataComponent; const $ = c(15); let children; let className; let dataComponent; let rest; if ($[0] !== t0) { ({ className, children, "data-component": dataComponent, ...rest } = t0); $[0] = t0; $[1] = children; $[2] = className; $[3] = dataComponent; $[4] = rest; } else { children = $[1]; className = $[2]; dataComponent = $[3]; rest = $[4]; } const detailsRef = React.useRef(null); const ref = useMergedRefs(forwardRef, detailsRef); let t1; let t2; if ($[5] === 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 = []; $[5] = t1; $[6] = t2; } else { t1 = $[5]; t2 = $[6]; } useEffect(t1, t2); let t3; if ($[7] !== className) { t3 = clsx(className, classes.Details); $[7] = className; $[8] = t3; } else { t3 = $[8]; } const t4 = (_dataComponent = dataComponent) !== null && _dataComponent !== void 0 ? _dataComponent : "Details"; let t5; if ($[9] !== children || $[10] !== ref || $[11] !== rest || $[12] !== t3 || $[13] !== t4) { t5 = /*#__PURE__*/jsx("details", { className: t3, ...rest, ref: ref, "data-component": t4, children: children }); $[9] = children; $[10] = ref; $[11] = rest; $[12] = t3; $[13] = t4; $[14] = t5; } else { t5 = $[14]; } return t5; }); 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, "data-component": "Details.Summary", 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 };