UNPKG

@atlaskit/primitives

Version:

Primitives are token-backed low-level building blocks.

89 lines (87 loc) 4.82 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); var _typeof = require("@babel/runtime/helpers/typeof"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); var _react = _interopRequireWildcard(require("react")); var _xcss = require("../xcss/xcss"); var _box = _interopRequireDefault(require("./box")); var _excluded = ["children", "backgroundColor", "padding", "paddingBlock", "paddingBlockStart", "paddingBlockEnd", "paddingInline", "paddingInlineStart", "paddingInlineEnd", "isDisabled", "type", "testId", "xcss"]; function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } // 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 = (0, _xcss.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__*/(0, _react.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 = (0, _objectWithoutProperties2.default)(_ref, _excluded); // Combine default styles with supplied styles. XCSS does not support deep nested arrays var styles = [(0, _xcss.xcss)({ cursor: isDisabled ? 'not-allowed' : 'pointer' }), focusRingStyles]; styles = Array.isArray(xcssStyles) ? [].concat((0, _toConsumableArray2.default)(styles), (0, _toConsumableArray2.default)(xcssStyles)) : [].concat((0, _toConsumableArray2.default)(styles), [xcssStyles]); return /*#__PURE__*/_react.default.createElement(_box.default, (0, _extends2.default)({}, 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); }); var _default = exports.default = UNSAFE_PRESSABLE;