@atlaskit/primitives
Version:
Primitives are token-backed low-level building blocks.
79 lines (78 loc) • 3.16 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["children", "backgroundColor", "padding", "paddingBlock", "paddingBlockStart", "paddingBlockEnd", "paddingInline", "paddingInlineStart", "paddingInlineEnd", "isDisabled", "type", "testId", "xcss"];
import React, { forwardRef } from 'react';
import { xcss } from '../xcss/xcss';
import Box from './box';
// TODO: Duplicated FocusRing styles due to lack of `xcss` support
// and to prevent additional dependency
var baseFocusRingStyles = {
outlineColor: 'color.border.focused',
outlineWidth: 'border.width.outline',
outlineStyle: 'solid',
outlineOffset: 'space.025'
};
var focusRingStyles = xcss({
':focus-visible': baseFocusRingStyles,
'@supports not selector(*:focus-visible)': {
':focus': baseFocusRingStyles
},
'@media screen and (forced-colors: active), screen and (-ms-high-contrast: active)': {
':focus-visible': {
outline: '1px solid'
}
}
});
/**
* __UNSAFE_PRESSABLE__
*
* @internal Still under development. Do not use.
*
* A Pressable is a primitive component that renders a `<button>`.
*
* - [Examples](https://atlassian.design/components/primitives/pressable/examples)
* - [Code](https://atlassian.design/components/primitives/pressable/code)
* - [Usage](https://atlassian.design/components/primitives/pressable/usage)
*/
var UNSAFE_PRESSABLE = /*#__PURE__*/forwardRef(function (_ref, ref) {
var children = _ref.children,
backgroundColor = _ref.backgroundColor,
padding = _ref.padding,
paddingBlock = _ref.paddingBlock,
paddingBlockStart = _ref.paddingBlockStart,
paddingBlockEnd = _ref.paddingBlockEnd,
paddingInline = _ref.paddingInline,
paddingInlineStart = _ref.paddingInlineStart,
paddingInlineEnd = _ref.paddingInlineEnd,
isDisabled = _ref.isDisabled,
_ref$type = _ref.type,
type = _ref$type === void 0 ? 'button' : _ref$type,
testId = _ref.testId,
xcssStyles = _ref.xcss,
htmlAttributes = _objectWithoutProperties(_ref, _excluded);
// Combine default styles with supplied styles. XCSS does not support deep nested arrays
var styles = [xcss({
cursor: isDisabled ? 'not-allowed' : 'pointer'
}), focusRingStyles];
styles = Array.isArray(xcssStyles) ? [].concat(_toConsumableArray(styles), _toConsumableArray(xcssStyles)) : [].concat(_toConsumableArray(styles), [xcssStyles]);
return /*#__PURE__*/React.createElement(Box, _extends({}, htmlAttributes, {
as: "button",
ref: ref,
testId: testId,
type: type,
backgroundColor: backgroundColor,
padding: padding,
paddingBlock: paddingBlock,
paddingBlockStart: paddingBlockStart,
paddingBlockEnd: paddingBlockEnd,
paddingInline: paddingInline,
paddingInlineStart: paddingInlineStart,
paddingInlineEnd: paddingInlineEnd
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
,
xcss: styles,
disabled: isDisabled
}), children);
});
export default UNSAFE_PRESSABLE;