UNPKG

@primer/react

Version:

An implementation of GitHub's Primer Design System using React

86 lines (85 loc) 2.6 kB
import { warning } from "../utils/warning.js"; import Radio from "../Radio/Radio.js"; import { ListContext } from "./shared.js"; import ActionList_module_css_default from "./ActionList.module.css.js"; import { GroupContext } from "./GroupContext.js"; import { VisualContainer } from "./Visuals.js"; import { c } from "react-compiler-runtime"; import { jsx } from "react/jsx-runtime"; import React from "react"; import { CheckIcon } from "@primer/octicons-react"; //#region src/ActionList/Selection.tsx 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) warning(true, "For Item to be selected, ActionList or ActionList.Group should have a selectionVariant defined."); 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, "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: ActionList_module_css_default.SingleSelectCheckmark }); $[5] = t1; } else t1 = $[5]; let t2; if ($[6] !== className) { t2 = /*#__PURE__*/ jsx(VisualContainer, { 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: ActionList_module_css_default.MultiSelectCheckbox }); $[8] = t1; } else t1 = $[8]; let t2; if ($[9] !== className) { t2 = /*#__PURE__*/ jsx(VisualContainer, { className, "data-component": "ActionList.Selection", children: t1 }); $[9] = className; $[10] = t2; } else t2 = $[10]; return t2; }; //#endregion export { Selection };