UNPKG

@primer/react

Version:

An implementation of GitHub's Primer Design System using React

36 lines (33 loc) 1.25 kB
import React__default, { forwardRef } from 'react'; import { ButtonBase } from './ButtonBase.js'; import { defaultSxProp } from '../utils/defaultSxProp.js'; import { generateCustomSxProp } from './Button.js'; function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } const IconButton = /*#__PURE__*/forwardRef(({ sx: sxProp = defaultSxProp, icon: Icon, ...props }, forwardedRef) => { let sxStyles = sxProp; // grap the button props that have associated data attributes in the styles const { size } = props; if (sxProp !== null && Object.keys(sxProp).length > 0) { sxStyles = generateCustomSxProp({ size }, sxProp); } return ( /*#__PURE__*/ // @ts-expect-error StyledButton wants both Anchor and Button refs React__default.createElement(ButtonBase, _extends({ icon: Icon, "data-component": "IconButton", sx: sxStyles }, props, { ref: forwardedRef })) ); }); export { IconButton };