UNPKG

@primer/react

Version:

An implementation of GitHub's Primer Design System using React

77 lines (74 loc) 1.8 kB
import { c } from 'react-compiler-runtime'; import React from 'react'; import { useOverflow } from '../hooks/useOverflow.js'; import { jsx } from 'react/jsx-runtime'; import Box from '../Box/Box.js'; const defaultStyles = { // When setting overflow, we also set `position: relative` to avoid // `position: absolute` items breaking out of the container and causing // scrollbars on the page. This can occur with common classes like `sr-only` // and can cause difficult to track down layout issues position: 'relative', overflow: 'auto' }; function ScrollableRegion(t0) { const $ = c(13); let children; let label; let labelledby; let rest; if ($[0] !== t0) { ({ "aria-label": label, "aria-labelledby": labelledby, children, ...rest } = t0); $[0] = t0; $[1] = children; $[2] = label; $[3] = labelledby; $[4] = rest; } else { children = $[1]; label = $[2]; labelledby = $[3]; rest = $[4]; } const ref = React.useRef(null); const hasOverflow = useOverflow(ref); let t1; if ($[5] !== hasOverflow || $[6] !== label || $[7] !== labelledby) { t1 = hasOverflow ? { "aria-label": label, "aria-labelledby": labelledby, role: "region", tabIndex: 0 } : {}; $[5] = hasOverflow; $[6] = label; $[7] = labelledby; $[8] = t1; } else { t1 = $[8]; } const regionProps = t1; let t2; if ($[9] !== children || $[10] !== regionProps || $[11] !== rest) { t2 = /*#__PURE__*/jsx(Box, { ...rest, ...regionProps, ref: ref, sx: defaultStyles, children: children }); $[9] = children; $[10] = regionProps; $[11] = rest; $[12] = t2; } else { t2 = $[12]; } return t2; } export { ScrollableRegion };