UNPKG

@atlaskit/section-message

Version:

A section message is used to alert users to a particular section of the screen.

129 lines (127 loc) 5.9 kB
/* section-message.tsx generated by @compiled/babel-plugin v3.0.2 */ "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("./section-message.compiled.css"); var _react = _interopRequireWildcard(require("react")); var React = _react; var _runtime = require("@compiled/react/runtime"); var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); var _button = _interopRequireDefault(require("@atlaskit/button/icon/button")); var _heading = _interopRequireDefault(require("@atlaskit/heading/heading")); var _cross = _interopRequireDefault(require("@atlaskit/icon/core/cross")); var _compiled = require("@atlaskit/primitives/compiled"); var _appearanceIcon = require("./internal/appearance-icon"); 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 sectionMessageStyles = { container: "_2rko1mok _1rjcpxbi _18zrpxbi _1nmz1hna", iconContainer: "_1mou1i6y _1e0c1txw", contentContainer: "_16jlkb7n", content: "_11c8fhey _syazi7uo", actionsContainer: "_11c8fhey", dismissButtonContainer: "_1pfh1i6y" }; var appearanceStyles = { information: "_bfhk19ip", warning: "_bfhk1917", error: "_bfhk1gly", success: "_bfhk1y9u", discovery: "_bfhk6vm6" }; /** * __Section message__ * * A section message is used to alert users to a particular section of the screen. * * - [Examples](https://atlassian.design/components/section-message/examples) * - [Code](https://atlassian.design/components/section-message/code) * - [Usage](https://atlassian.design/components/section-message/usage) */ var SectionMessage = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) { var children = _ref.children, _ref$appearance = _ref.appearance, appearance = _ref$appearance === void 0 ? 'information' : _ref$appearance, actions = _ref.actions, title = _ref.title, _ref$headingLevel = _ref.headingLevel, headingLevel = _ref$headingLevel === void 0 ? 'h2' : _ref$headingLevel, icon = _ref.icon, isDismissible = _ref.isDismissible, onDismiss = _ref.onDismiss, testId = _ref.testId; var _useState = (0, _react.useState)(false), _useState2 = (0, _slicedToArray2.default)(_useState, 2), dismissed = _useState2[0], setDismissed = _useState2[1]; var handleDismiss = (0, _react.useCallback)(function () { onDismiss === null || onDismiss === void 0 || onDismiss(); setDismissed(true); }, [onDismiss]); var _getAppearanceIconSty = (0, _appearanceIcon.getAppearanceIconStyles)(appearance, icon), primaryColor = _getAppearanceIconSty.primaryIconColor, secondaryColor = _getAppearanceIconSty.backgroundColor, Icon = _getAppearanceIconSty.Icon; var actionElements = actions && actions.type === _react.Fragment ? actions.props.children : actions; var actionsArray = _react.Children.toArray(actionElements); return isDismissible && dismissed ? null : /*#__PURE__*/React.createElement("section", { "data-testid": testId, ref: ref, className: (0, _runtime.ax)([sectionMessageStyles.container, appearanceStyles[appearance]]) }, /*#__PURE__*/React.createElement(_compiled.Inline, { space: "space.200", alignBlock: "stretch" }, /*#__PURE__*/React.createElement("div", { className: (0, _runtime.ax)([sectionMessageStyles.iconContainer]) }, /*#__PURE__*/React.createElement(Icon, { size: "medium", primaryColor: primaryColor, secondaryColor: secondaryColor // props for new icon , color: primaryColor, spacing: "spacious" })), /*#__PURE__*/React.createElement(_compiled.Stack, { space: "space.100", testId: testId && "".concat(testId, "--content"), xcss: sectionMessageStyles.contentContainer }, !!title && /*#__PURE__*/React.createElement(_heading.default, { as: headingLevel, size: "small" }, title), /*#__PURE__*/React.createElement("div", { className: (0, _runtime.ax)([sectionMessageStyles.content]) }, children), actionsArray.length > 0 && /*#__PURE__*/React.createElement(_compiled.Inline, { shouldWrap: true, testId: testId && "".concat(testId, "--actions"), separator: "\xB7", space: "space.100", rowSpace: "space.0" // Only use a list role if more than one action is present , role: actionsArray.length > 1 ? 'list' : undefined, xcss: sectionMessageStyles.actionsContainer }, actionsArray.map(function (action, id) { return ( /*#__PURE__*/ // Only use a listitem role if more than one action is present React.createElement(_compiled.Inline, { role: actionsArray.length > 1 ? 'listitem' : undefined, key: id }, action) ); }))), isDismissible && /*#__PURE__*/React.createElement("div", { className: (0, _runtime.ax)([sectionMessageStyles.dismissButtonContainer]) }, /*#__PURE__*/React.createElement(_button.default, { testId: testId && "".concat(testId, "--dismiss-button"), label: "Dismiss", icon: _cross.default, appearance: "subtle", onClick: handleDismiss, spacing: "compact" })))); }); SectionMessage.displayName = 'SectionMessage'; var _default = exports.default = SectionMessage;