UNPKG

@onesy/ui-react

Version:
70 lines 3.17 kB
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; const _excluded = ["focus", "selected", "href", "disabled", "onFocus", "onBlur", "InteractionProps", "Component", "className", "children"]; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } import React from 'react'; import { is } from '@onesy/utils'; import { classNames, style as styleMethod, useOnesyTheme } from '@onesy/style-react'; import InteractionElement from '../Interaction'; import { staticClassName } from '../utils'; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; const useStyle = styleMethod(theme => ({ root: { cursor: 'pointer', userSelect: 'none' } }), { name: 'onesy-CardButton' }); const CardButton = props_ => { const theme = useOnesyTheme(); const props = _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.onesyCardButton?.props?.default), props_); const Interaction = theme?.elements?.Interaction || InteractionElement; const { focus: focus_, selected, href, disabled, onFocus: onFocus_, onBlur: onBlur_, InteractionProps, Component: Component_ = props.href ? 'a' : 'div', className, children } = props, other = _objectWithoutProperties(props, _excluded); const { classes } = useStyle(); const [focus, setFocus] = React.useState(focus_ !== undefined ? focus_ : false); const onFocus = event => { if (focus_ === undefined && !disabled) { setFocus(true); if (is('function', onFocus_)) onFocus_(event); } }; const onBlur = event_0 => { if (focus_ === undefined && !disabled) { setFocus(false); if (is('function', onBlur_)) onBlur_(event_0); } }; const Component = Component_; return /*#__PURE__*/_jsxs(Component, _objectSpread(_objectSpread({ tabIndex: !disabled ? 0 : -1, Component: Component, onFocus: onFocus, onBlur: onBlur, href: href, className: classNames([staticClassName('CardButton', theme) && [`onesy-CardButton-root`, focus && `onesy-CardButton-focus`, disabled && `onesy-CardButton-disabled`], className, classes.root]) }, other), {}, { children: [/*#__PURE__*/_jsx(Interaction, _objectSpread({ border: false, pulse: focus, selected: selected }, InteractionProps)), children] })); }; CardButton.displayName = 'onesy-CardButton'; export default CardButton;