UNPKG

@atlaskit/inline-message

Version:

An inline message lets users know when important information is available or when an action is required.

138 lines (136 loc) 6 kB
/* index.tsx generated by @compiled/babel-plugin v0.39.1 */ "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; require("./index.compiled.css"); var _react = _interopRequireWildcard(require("react")); var React = _react; var _runtime = require("@compiled/react/runtime"); var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); var _useId = require("@atlaskit/ds-lib/use-id"); var _popup = _interopRequireDefault(require("@atlaskit/popup")); var _compiled = require("@atlaskit/primitives/compiled"); var _messageIcon = _interopRequireDefault(require("../message-icon")); var _excluded = ["ref"]; function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); } var styles = { contentStyles: "_1reo1wug _18m91wug _bozg1ejb _y4ti1ejb _1q51pxbi _85i5pxbi _p12flti4 _c71llti4", rootStyles: "_1e0c1o8l _p12f1osq _1yyu1kum _y2mv1w7i", pressableStyles: "_2rko1qi0 _11c8fhey _1rjcze3t _18zrze3t _1e0c116y _bfhksm61 _syazazsu _o5721q9c _kqswh2mm _4cvr1q9y _p12f1osq _4t3i1wug _1bsb1wug _s7n41q9y _9oik1r31 _1bnx8stv _jf4cnqa1" }; var iconColor = { connectivity: "_x5v91ft0", confirmation: "_x5v94pcx", info: "_x5v9qm1h", warning: "_x5v9ervl", error: "_x5v9s4qr" }; /** * __Inline message__ * * An inline message lets users know when important information is available or when an action is required. * * - [Examples](https://atlassian.design/components/inline-message/examples) * - [Code](https://atlassian.design/components/inline-message/code) * - [Usage](https://atlassian.design/components/inline-message/usage) * * @example * * ```jsx * const Component = () => ( * <InlineMessage * title="Inline Message Title Example" * secondaryText="Secondary Text" * > * <p>Some text that would be inside the open dialog and otherwise hidden.</p> * </InlineMessage> * ); * ``` */ var InlineMessage = function InlineMessage(_ref) { var _ref$placement = _ref.placement, placement = _ref$placement === void 0 ? 'bottom-start' : _ref$placement, _ref$secondaryText = _ref.secondaryText, secondaryText = _ref$secondaryText === void 0 ? '' : _ref$secondaryText, _ref$title = _ref.title, title = _ref$title === void 0 ? '' : _ref$title, _ref$appearance = _ref.appearance, appearance = _ref$appearance === void 0 ? 'connectivity' : _ref$appearance, _ref$spacing = _ref.spacing, spacing = _ref$spacing === void 0 ? 'spacious' : _ref$spacing, children = _ref.children, testId = _ref.testId, iconLabel = _ref.iconLabel, fallbackPlacements = _ref.fallbackPlacements; var _useState = (0, _react.useState)(false), _useState2 = (0, _slicedToArray2.default)(_useState, 2), isOpen = _useState2[0], setIsOpen = _useState2[1]; var id = (0, _useId.useId)(); var toggleDialog = (0, _react.useCallback)(function () { setIsOpen(function (oldState) { return !oldState; }); }, [setIsOpen]); var onCloseDialog = (0, _react.useCallback)(function () { return setIsOpen(false); }, [setIsOpen]); return /*#__PURE__*/React.createElement("div", { "data-testid": testId, className: (0, _runtime.ax)([styles.rootStyles, iconColor[appearance]]) }, /*#__PURE__*/React.createElement(_popup.default, { onClose: onCloseDialog, content: function content() { return /*#__PURE__*/React.createElement(_compiled.Box, { xcss: styles.contentStyles }, children); }, isOpen: isOpen, placement: placement, testId: testId && "".concat(testId, "--popup"), fallbackPlacements: fallbackPlacements, shouldRenderToParent: true, role: "dialog", titleId: id, trigger: function trigger(_ref2) { var ref = _ref2.ref, triggerProps = (0, _objectWithoutProperties2.default)(_ref2, _excluded); return /*#__PURE__*/React.createElement(_compiled.Pressable, (0, _extends2.default)({}, triggerProps, { ref: ref, id: id, "data-ds--inline-message--button": true, onClick: toggleDialog, testId: testId && "".concat(testId, "--button"), xcss: styles.pressableStyles, "aria-expanded": isOpen }), /*#__PURE__*/React.createElement(_compiled.Inline, { as: "span", space: "space.050", alignBlock: "center" }, /*#__PURE__*/React.createElement(_messageIcon.default, { isOpen: isOpen, appearance: appearance, label: iconLabel, spacing: spacing }), /*#__PURE__*/React.createElement(_compiled.Inline, { as: "span", space: "space.100" }, title && /*#__PURE__*/React.createElement(_compiled.Text, { weight: "medium", testId: testId && "".concat(testId, "--title") }, title), secondaryText && /*#__PURE__*/React.createElement(_compiled.Text, { weight: "medium", color: "color.text.subtlest", maxLines: 1, testId: testId && "".concat(testId, "--text") }, secondaryText)))); } })); }; var _default = exports.default = InlineMessage;