UNPKG

@atlaskit/section-message

Version:

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

113 lines (112 loc) 4.09 kB
/* section-message.tsx generated by @compiled/babel-plugin v3.0.2 */ 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'; const sectionMessageStyles = { container: "_2rko1mok _1rjcpxbi _18zrpxbi _1nmz1hna", iconContainer: "_1mou1i6y _1e0c1txw", contentContainer: "_16jlkb7n", content: "_11c8fhey _syazi7uo", actionsContainer: "_11c8fhey", dismissButtonContainer: "_1pfh1i6y" }; const 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) */ const SectionMessage = /*#__PURE__*/forwardRef(({ children, appearance = 'information', actions, title, headingLevel = 'h2', icon, isDismissible, onDismiss, testId }, ref) => { const [dismissed, setDismissed] = useState(false); const handleDismiss = useCallback(() => { onDismiss === null || onDismiss === void 0 ? void 0 : onDismiss(); setDismissed(true); }, [onDismiss]); const { primaryIconColor: primaryColor, backgroundColor: secondaryColor, Icon } = getAppearanceIconStyles(appearance, icon); const actionElements = actions && actions.type === Fragment ? actions.props.children : actions; const 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 && `${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 && `${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((action, id) => /*#__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 && `${testId}--dismiss-button`, label: "Dismiss", icon: CrossIcon, appearance: "subtle", onClick: handleDismiss, spacing: "compact" })))); }); SectionMessage.displayName = 'SectionMessage'; export default SectionMessage;