@momentum-ui/react-collaboration
Version:
Cisco Momentum UI Framework for React Collaboration Applications
59 lines • 3.39 kB
JavaScript
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
import React, { forwardRef, useRef } from 'react';
import classnames from 'classnames';
import { useButton } from '@react-aria/button';
import { useHover } from '@react-aria/interactions';
import FocusRing from '../FocusRing';
import { STYLE } from './ButtonSimple.constants';
import './ButtonSimple.style.scss';
/**
* A simple button component without overhead styling.
* This is used as an injectable button component for other sibling components.
* @internal use only. Should not be consumed from any external parties.
* @deprecated Use the equivalent from momentum.design (NPM: `@momentum-design/components/dist/react`)
*/
var ButtonSimple = forwardRef(function (props, providedRef) {
var children = props.children, className = props.className, isDisabled = props.isDisabled, id = props.id, style = props.style, title = props.title, useNativeKeyDown = props.useNativeKeyDown, role = props.role, tabIndex = props.tabIndex, restProps = __rest(props, ["children", "className", "isDisabled", "id", "style", "title", "useNativeKeyDown", "role", "tabIndex"]);
var internalRef = useRef();
var ref = providedRef || internalRef;
var buttonProps = useButton(props, ref).buttonProps;
var hoverProps = useHover(props).hoverProps;
var ariaProps = {
'aria-selected': restProps['aria-selected'],
};
var otherProps = tabIndex
? __assign(__assign(__assign(__assign({}, buttonProps), hoverProps), ariaProps), { role: role, tabIndex: tabIndex }) : __assign(__assign(__assign(__assign({}, buttonProps), hoverProps), ariaProps), { role: role });
// props should override buttonProps for aria-disabled because react-aria has it's own logic for aria-disabled.
// so if we want to pass it in via props, we need to make sure it's not overridden.
if (props['aria-disabled'] === true) {
otherProps['aria-disabled'] = true;
}
return (React.createElement(FocusRing, { disabled: isDisabled },
React.createElement("button", __assign({ className: classnames(className, STYLE.wrapper), id: id, ref: ref, style: style, title: title }, otherProps, {
// override of onKeyDown to ensure the standard html button behavior (on enter => onClick) happens
onKeyDown: useNativeKeyDown ? props.onKeyDown : buttonProps.onKeyDown }), typeof children === 'string' ? React.createElement("span", null, children) : children)));
});
ButtonSimple.displayName = 'ButtonSimple';
export default ButtonSimple;
//# sourceMappingURL=ButtonSimple.js.map