suomifi-ui-components
Version:
Suomi.fi UI component library
126 lines (123 loc) • 5.75 kB
JavaScript
import { __extends, __rest, __assign, __makeTemplateObject } from 'tslib';
import React, { Component, forwardRef } from 'react';
import { styled } from 'styled-components';
import classnames from 'classnames';
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 { IconWarning, IconError } from 'suomifi-icons';
import { AutoId } from '../utils/AutoId/AutoId.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 './InlineAlert.baseStyles.js';
import { filterDuplicateKeys } from '../../utils/common/common.js';
var baseClassName = 'fi-inline-alert';
var inlineAlertClassNames = {
styleWrapper: "".concat(baseClassName, "_style-wrapper"),
content: "".concat(baseClassName, "_content"),
label: "".concat(baseClassName, "_label"),
textContentWrapper: "".concat(baseClassName, "_text-content-wrapper"),
icon: "".concat(baseClassName, "_icon"),
smallScreen: "".concat(baseClassName, "--small-screen")
};
var BaseInlineAlert = function (_super) {
__extends(BaseInlineAlert, _super);
function BaseInlineAlert() {
return _super !== null && _super.apply(this, arguments) || this;
}
BaseInlineAlert.prototype.render = function () {
var _a, _b, _c;
var _d = this.props,
className = _d.className,
_e = _d.status,
status = _e === void 0 ? 'neutral' : _e,
labelText = _d.labelText,
children = _d.children,
smallScreen = _d.smallScreen,
id = _d.id;
_d.forwardedRef;
var rest = __rest(_d, ["className", "status", "labelText", "children", "smallScreen", "id", "forwardedRef"]);
var _f = separateMarginProps(rest),
passProps = _f[1];
return /*#__PURE__*/React.createElement(HtmlDivWithRef, __assign({
asProp: "section"
}, passProps, {
className: classnames(baseClassName, className, (_a = {}, _a["".concat(baseClassName, "--").concat(status)] = !!status, _a[inlineAlertClassNames.smallScreen] = !!smallScreen, _a)),
style: __assign({}, passProps === null || passProps === void 0 ? void 0 : passProps.style)
}), /*#__PURE__*/React.createElement(HtmlDiv, {
className: inlineAlertClassNames.styleWrapper
}, status === 'warning' && ( /*#__PURE__*/React.createElement(IconWarning, {
className: classnames(inlineAlertClassNames.icon, (_b = {}, _b["".concat(inlineAlertClassNames.icon, "--").concat(status)] = !!status, _b))
})), status === 'error' && ( /*#__PURE__*/React.createElement(IconError, {
className: classnames(inlineAlertClassNames.icon, (_c = {}, _c["".concat(inlineAlertClassNames.icon, "--").concat(status)] = !!status, _c))
})), /*#__PURE__*/React.createElement(HtmlDiv, {
className: inlineAlertClassNames.textContentWrapper,
id: id
}, labelText && ( /*#__PURE__*/React.createElement(HtmlDiv, {
className: inlineAlertClassNames.label
}, labelText)), /*#__PURE__*/React.createElement(HtmlDiv, {
className: inlineAlertClassNames.content
}, children))));
};
return BaseInlineAlert;
}(Component);
var StyledInlineAlert = styled(function (props) {
props.theme;
props.globalMargins;
var passProps = __rest(props, ["theme", "globalMargins"]);
return /*#__PURE__*/React.createElement(BaseInlineAlert, __assign({}, passProps));
}).withConfig({
componentId: "sc-oiv9xc-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.inlineAlert, marginProps);
return baseStyles(theme, cleanedGlobalMargins, marginProps);
});
var InlineAlert = /*#__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(StyledInlineAlert, __assign({
forwardedRef: ref,
theme: suomifiTheme,
globalMargins: margins,
id: id
}, passProps));
});
});
});
});
InlineAlert.displayName = 'InlineAlert';
var templateObject_1;
export { InlineAlert };
//# sourceMappingURL=InlineAlert.js.map