UNPKG

@primer/react

Version:

An implementation of GitHub's Primer Design System using React

115 lines (112 loc) 2.87 kB
import { c } from 'react-compiler-runtime'; import React from 'react'; import { CheckIcon } from '@primer/octicons-react'; import { GroupContext } from './Group.js'; import { ListContext } from './shared.js'; import { VisualContainer } from './Visuals.js'; import classes from './ActionList.module.css.js'; import { warning } from '../utils/warning.js'; import { jsx } from 'react/jsx-runtime'; import Radio from '../Radio/Radio.js'; const Selection = t0 => { const $ = c(11); const { selected, className } = t0; const { selectionVariant: listSelectionVariant, role: listRole } = React.useContext(ListContext); const { selectionVariant: groupSelectionVariant } = React.useContext(GroupContext); let selectionVariant; if (typeof groupSelectionVariant !== "undefined") { selectionVariant = groupSelectionVariant; } else { selectionVariant = listSelectionVariant; } if (!selectionVariant) { if (selected) { process.env.NODE_ENV !== "production" ? warning(true, "For Item to be selected, ActionList or ActionList.Group should have a selectionVariant defined.") : void 0; } return null; } if (selectionVariant === "radio") { let t1; if ($[0] !== selected) { t1 = /*#__PURE__*/jsx(Radio, { value: "unused", checked: selected, "aria-hidden": true, tabIndex: -1 }); $[0] = selected; $[1] = t1; } else { t1 = $[1]; } let t2; if ($[2] !== className || $[3] !== t1) { t2 = /*#__PURE__*/jsx(VisualContainer, { className: className, "data-component": "ActionList.Selection", children: t1 }); $[2] = className; $[3] = t1; $[4] = t2; } else { t2 = $[4]; } return t2; } if (selectionVariant === "single" || listRole === "menu") { let t1; if ($[5] === Symbol.for("react.memo_cache_sentinel")) { t1 = /*#__PURE__*/jsx(CheckIcon, { className: classes.SingleSelectCheckmark }); $[5] = t1; } else { t1 = $[5]; } let t2; if ($[6] !== className) { t2 = /*#__PURE__*/jsx(VisualContainer, { className: className, "data-component": "ActionList.Selection", children: t1 }); $[6] = className; $[7] = t2; } else { t2 = $[7]; } return t2; } let t1; if ($[8] === Symbol.for("react.memo_cache_sentinel")) { t1 = /*#__PURE__*/jsx("div", { className: classes.MultiSelectCheckbox }); $[8] = t1; } else { t1 = $[8]; } let t2; if ($[9] !== className) { t2 = /*#__PURE__*/jsx(VisualContainer, { className: className, "data-component": "ActionList.Selection", children: t1 }); $[9] = className; $[10] = t2; } else { t2 = $[10]; } return t2; }; export { Selection };