@atlaskit/section-message
Version:
A section message is used to alert users to a particular section of the screen.
120 lines (119 loc) • 4.73 kB
JavaScript
/* section-message.tsx generated by @compiled/babel-plugin v3.0.2 */
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import "./section-message.compiled.css";
import * as React from 'react';
import { ax, ix } from "@compiled/react/runtime";
import { Children, forwardRef, Fragment, useCallback, useState } from 'react';
import IconButton from '@atlaskit/button/icon/button';
import Heading from '@atlaskit/heading/heading';
import CrossIcon from '@atlaskit/icon/core/cross';
import { Inline, Stack } from '@atlaskit/primitives/compiled';
import { getAppearanceIconStyles } from './internal/appearance-icon';
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__*/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 = useState(false),
_useState2 = _slicedToArray(_useState, 2),
dismissed = _useState2[0],
setDismissed = _useState2[1];
var handleDismiss = useCallback(function () {
onDismiss === null || onDismiss === void 0 || onDismiss();
setDismissed(true);
}, [onDismiss]);
var _getAppearanceIconSty = getAppearanceIconStyles(appearance, icon),
primaryColor = _getAppearanceIconSty.primaryIconColor,
secondaryColor = _getAppearanceIconSty.backgroundColor,
Icon = _getAppearanceIconSty.Icon;
var actionElements = actions && actions.type === Fragment ? actions.props.children : actions;
var actionsArray = Children.toArray(actionElements);
return isDismissible && dismissed ? null : /*#__PURE__*/React.createElement("section", {
"data-testid": testId,
ref: ref,
className: ax([sectionMessageStyles.container, appearanceStyles[appearance]])
}, /*#__PURE__*/React.createElement(Inline, {
space: "space.200",
alignBlock: "stretch"
}, /*#__PURE__*/React.createElement("div", {
className: ax([sectionMessageStyles.iconContainer])
}, /*#__PURE__*/React.createElement(Icon, {
size: "medium",
primaryColor: primaryColor,
secondaryColor: secondaryColor
// props for new icon
,
color: primaryColor,
spacing: "spacious"
})), /*#__PURE__*/React.createElement(Stack, {
space: "space.100",
testId: testId && "".concat(testId, "--content"),
xcss: sectionMessageStyles.contentContainer
}, !!title && /*#__PURE__*/React.createElement(Heading, {
as: headingLevel,
size: "small"
}, title), /*#__PURE__*/React.createElement("div", {
className: ax([sectionMessageStyles.content])
}, children), actionsArray.length > 0 && /*#__PURE__*/React.createElement(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(Inline, {
role: actionsArray.length > 1 ? 'listitem' : undefined,
key: id
}, action)
);
}))), isDismissible && /*#__PURE__*/React.createElement("div", {
className: ax([sectionMessageStyles.dismissButtonContainer])
}, /*#__PURE__*/React.createElement(IconButton, {
testId: testId && "".concat(testId, "--dismiss-button"),
label: "Dismiss",
icon: CrossIcon,
appearance: "subtle",
onClick: handleDismiss,
spacing: "compact"
}))));
});
SectionMessage.displayName = 'SectionMessage';
export default SectionMessage;