UNPKG

suomifi-ui-components

Version:
164 lines (161 loc) 8.12 kB
import { __extends, __rest, __assign, __makeTemplateObject } from 'tslib'; import React, { Component, forwardRef } from 'react'; import { styled } from 'styled-components'; import classnames from 'classnames'; import { IconError, IconInfo, IconClose } from 'suomifi-icons'; import '../../reset/HtmlA/HtmlA.js'; import '../../reset/HtmlButton/HtmlButton.js'; import { HtmlDivWithRef, HtmlDiv } from '../../reset/HtmlDiv/HtmlDiv.js'; import '../../reset/HtmlFieldSet/HtmlFieldSet.js'; import '../../reset/HtmlH/HtmlH.js'; import '../../reset/HtmlInput/HtmlInput.js'; import '../../reset/HtmlLabel/HtmlLabel.js'; import '../../reset/HtmlLegend/HtmlLegend.js'; import '../../reset/HtmlLi/HtmlLi.js'; import '../../reset/HtmlNav/HtmlNav.js'; import '../../reset/HtmlOl/HtmlOl.js'; import '../../reset/HtmlSpan/HtmlSpan.js'; import '../../reset/HtmlTextarea/HtmlTextarea.js'; import '../../reset/HtmlUl/HtmlUl.js'; import '../../reset/HtmlTable/HtmlTable.js'; import '../../reset/HtmlTable/HtmlTableCaption.js'; import '../../reset/HtmlTable/HtmlTableHeader.js'; import '../../reset/HtmlTable/HtmlTableRow.js'; import '../../reset/HtmlTable/HtmlTableBody.js'; import '../../reset/HtmlTable/HtmlTableHeaderCell.js'; import '../../reset/HtmlTable/HtmlTableCell.js'; import { getConditionalAriaProp } from '../../utils/aria/aria.js'; import { Heading } from '../Heading/Heading.js'; import { AutoId } from '../utils/AutoId/AutoId.js'; import { Button } from '../Button/Button.js'; import { SuomifiThemeConsumer } from '../theme/SuomifiThemeProvider/SuomifiThemeProvider.js'; import '../theme/SuomifiTheme/SuomifiTheme.js'; import { SpacingConsumer } from '../theme/SpacingProvider/SpacingProvider.js'; import { separateMarginProps } from '../theme/utils/spacing.js'; import { baseStyles } from './Notification.baseStyles.js'; import { filterDuplicateKeys } from '../../utils/common/common.js'; var baseClassName = 'fi-notification'; var notificationClassNames = { styleWrapper: "".concat(baseClassName, "_style-wrapper"), content: "".concat(baseClassName, "_content"), contentWrapper: "".concat(baseClassName, "_contentWrapper"), heading: "".concat(baseClassName, "_heading"), textContentWrapper: "".concat(baseClassName, "_text-content-wrapper"), icon: "".concat(baseClassName, "_icon"), iconWrapper: "".concat(baseClassName, "_icon-wrapper"), closeButton: "".concat(baseClassName, "_close-button"), smallScreen: "".concat(baseClassName, "--small-screen"), actionElementWrapper: "".concat(baseClassName, "_action-element-wrapper") }; var BaseNotification = function (_super) { __extends(BaseNotification, _super); function BaseNotification() { return _super !== null && _super.apply(this, arguments) || this; } BaseNotification.prototype.render = function () { var _a, _b, _c; var _d = this.props, className = _d.className, _e = _d.status, status = _e === void 0 ? 'neutral' : _e, headingText = _d.headingText, children = _d.children, id = _d.id, actionElements = _d.actionElements, closeText = _d.closeText, onCloseButtonClick = _d.onCloseButtonClick, smallScreen = _d.smallScreen, _f = _d.closeButtonProps, closeButtonProps = _f === void 0 ? {} : _f, _g = _d.headingVariant, headingVariant = _g === void 0 ? 'h2' : _g, style = _d.style, regionAriaLabel = _d.regionAriaLabel, _h = _d.showCloseButton, showCloseButton = _h === void 0 ? true : _h, rest = __rest(_d, ["className", "status", "headingText", "children", "id", "actionElements", "closeText", "onCloseButtonClick", "smallScreen", "closeButtonProps", "headingVariant", "style", "regionAriaLabel", "showCloseButton"]); var _j = separateMarginProps(rest), passProps = _j[1]; var customCloseButtonClassName = closeButtonProps.className, closeButtonPropsAriaDescribedBy = closeButtonProps["aria-describedby"], closeButtonPropsAriaLabel = closeButtonProps["aria-label"], closeButtonPassProps = __rest(closeButtonProps, ["className", 'aria-describedby', 'aria-label']); return /*#__PURE__*/React.createElement(HtmlDivWithRef, __assign({ asProp: "section", role: "region", "aria-label": regionAriaLabel || headingText || (typeof children === 'string' ? children : undefined) }, passProps, { className: classnames(baseClassName, "".concat(baseClassName, "--").concat(status), className, (_a = {}, _a[notificationClassNames.smallScreen] = !!smallScreen, _a)), style: style }), /*#__PURE__*/React.createElement(HtmlDiv, { className: notificationClassNames.styleWrapper, style: style }, /*#__PURE__*/React.createElement(HtmlDiv, { className: notificationClassNames.iconWrapper }, status === 'error' && ( /*#__PURE__*/React.createElement(IconError, { className: classnames(notificationClassNames.icon, (_b = {}, _b["".concat(notificationClassNames.icon, "--").concat(status)] = !!status, _b)) })), status === 'neutral' && ( /*#__PURE__*/React.createElement(IconInfo, { className: classnames(notificationClassNames.icon, (_c = {}, _c["".concat(notificationClassNames.icon, "--").concat(status)] = !!status, _c)) }))), /*#__PURE__*/React.createElement(HtmlDiv, { className: notificationClassNames.textContentWrapper, id: id }, /*#__PURE__*/React.createElement(HtmlDiv, { className: notificationClassNames.content }, headingText && ( /*#__PURE__*/React.createElement(Heading, { variant: headingVariant, className: notificationClassNames.heading }, headingText)), /*#__PURE__*/React.createElement(HtmlDiv, { className: notificationClassNames.contentWrapper }, children))), showCloseButton && ( /*#__PURE__*/React.createElement(Button, __assign({ variant: "secondaryNoBorder", className: classnames(notificationClassNames.closeButton, customCloseButtonClassName) }, getConditionalAriaProp('aria-label', [closeButtonPropsAriaLabel || (smallScreen ? closeText : undefined)]), getConditionalAriaProp('aria-describedby', [closeButtonPropsAriaDescribedBy]), { onClick: onCloseButtonClick }, closeButtonPassProps, { iconRight: /*#__PURE__*/React.createElement(IconClose, null) }), !smallScreen ? closeText : ''))), actionElements && ( /*#__PURE__*/React.createElement(HtmlDiv, { className: notificationClassNames.actionElementWrapper }, actionElements))); }; return BaseNotification; }(Component); var StyledNotification = styled(function (props) { props.theme; props.globalMargins; var passProps = __rest(props, ["theme", "globalMargins"]); return /*#__PURE__*/React.createElement(BaseNotification, __assign({}, passProps)); }).withConfig({ componentId: "sc-1mn5t9v-0" })(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n"], ["\n ", "\n"])), function (_a) { var theme = _a.theme, globalMargins = _a.globalMargins, rest = __rest(_a, ["theme", "globalMargins"]); var _b = separateMarginProps(rest), marginProps = _b[0]; var cleanedGlobalMargins = filterDuplicateKeys(globalMargins.notification, marginProps); return baseStyles(theme, cleanedGlobalMargins, marginProps); }); var Notification = /*#__PURE__*/forwardRef(function (props, ref) { var propId = props.id, passProps = __rest(props, ["id"]); return /*#__PURE__*/React.createElement(SpacingConsumer, null, function (_a) { var margins = _a.margins; return /*#__PURE__*/React.createElement(SuomifiThemeConsumer, null, function (_a) { var suomifiTheme = _a.suomifiTheme; return /*#__PURE__*/React.createElement(AutoId, { id: propId }, function (id) { return /*#__PURE__*/React.createElement(StyledNotification, __assign({ forwardedRef: ref, theme: suomifiTheme, globalMargins: margins, id: id }, passProps)); }); }); }); }); Notification.displayName = 'Notification'; var templateObject_1; export { Notification, baseClassName, notificationClassNames }; //# sourceMappingURL=Notification.js.map