UNPKG

@primer/react

Version:

An implementation of GitHub's Primer Design System using React

95 lines (90 loc) 2.37 kB
import { c } from 'react-compiler-runtime'; import { memo } from 'react'; import { accessibleSequenceString, Sequence } from './components/Sequence.js'; import classes from './KeybindingHint.module.css.js'; import { clsx } from 'clsx'; import { jsx } from 'react/jsx-runtime'; import Text from '../Text/Text.js'; const Kbd = t0 => { const $ = c(5); const { children, className } = t0; let t1; if ($[0] !== className) { t1 = clsx(className, classes.KeybindingHint); $[0] = className; $[1] = t1; } else { t1 = $[1]; } let t2; if ($[2] !== children || $[3] !== t1) { t2 = /*#__PURE__*/jsx(Text, { as: "kbd", className: t1, "data-testid": "keybinding-hint", children: children }); $[2] = children; $[3] = t1; $[4] = t2; } else { t2 = $[4]; } return t2; }; /** Indicates the presence of an available keybinding. */ // KeybindingHint is a good candidate for memoizing since props will rarely change const KeybindingHint = /*#__PURE__*/memo(t0 => { const $ = c(8); let className; let props; if ($[0] !== t0) { ({ className, ...props } = t0); $[0] = t0; $[1] = className; $[2] = props; } else { className = $[1]; props = $[2]; } let t1; if ($[3] !== props) { t1 = /*#__PURE__*/jsx(Sequence, { ...props }); $[3] = props; $[4] = t1; } else { t1 = $[4]; } let t2; if ($[5] !== className || $[6] !== t1) { t2 = /*#__PURE__*/jsx(Kbd, { className: className, children: t1 }); $[5] = className; $[6] = t1; $[7] = t2; } else { t2 = $[7]; } return t2; }); KeybindingHint.displayName = 'KeybindingHint'; /** * AVOID: `KeybindingHint` is nearly always sufficient for providing both visible and accessible keyboard hints. * However, there may be cases where we need a plain string version, such as when building `aria-label` or * `aria-description`. In that case, this plain string builder can be used instead. * * NOTE that this string should _only_ be used when building `aria-label` or `aria-description` props (never rendered * visibly) and should nearly always also be paired with a visible hint for sighted users. */ const getAccessibleKeybindingHintString = accessibleSequenceString; export { KeybindingHint, getAccessibleKeybindingHintString };