UNPKG

@s-ui/react-atom-checkbox

Version:

AtomCheckbox is a component that displays an input checkbox w/ its expected behavior

55 lines 1.8 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose"; var _excluded = ["disabled", "size", "status", "onClick", "icon", "checked", "className", "indeterminate", "isNative"]; import { useRef } from 'react'; import PropTypes from 'prop-types'; import { CHECKBOX_SIZES, CHECKBOX_STATUS, className, pressedValue } from './config.js'; import { jsx as _jsx } from "react/jsx-runtime"; var CheckboxIcon = function CheckboxIcon(_ref) { var disabled = _ref.disabled, size = _ref.size, status = _ref.status, onClick = _ref.onClick, SVGIcon = _ref.icon, checked = _ref.checked, classNameProp = _ref.className, indeterminate = _ref.indeterminate, isNative = _ref.isNative, props = _objectWithoutPropertiesLoose(_ref, _excluded); var buttonRef = useRef(); if (!SVGIcon) return null; var handleKeydown = function handleKeydown(event) { if (event.key === 'Enter') { event.preventDefault(); event.stopPropagation(); } }; return /*#__PURE__*/_jsx("button", _extends({ ref: buttonRef, type: "button", className: className({ size: size, checked: checked, disabled: disabled, indeterminate: indeterminate, className: classNameProp }), onClick: onClick(buttonRef), onKeyDown: handleKeydown, disabled: disabled }, Object.values(CHECKBOX_STATUS).includes(status) && { 'data-status': status }, { "aria-pressed": pressedValue({ checked: checked, indeterminate: indeterminate }), "aria-hidden": isNative }, props, { children: /*#__PURE__*/_jsx(SVGIcon, { size: size }) })); }; CheckboxIcon.displayName = 'CheckboxIcon'; export default CheckboxIcon;