suomifi-ui-components
Version:
Suomi.fi UI component library
104 lines (101 loc) • 4.46 kB
JavaScript
import { __rest, __assign, __makeTemplateObject } from 'tslib';
import React, { forwardRef } from 'react';
import classnames from 'classnames';
import { styled } from 'styled-components';
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 '../../../reset/HtmlA/HtmlA.js';
import '../../../reset/HtmlButton/HtmlButton.js';
import '../../../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 { HtmlSpan } from '../../../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 { baseStyles } from './StatusText.baseStyles.js';
import { IconErrorFilled, IconCheckCircleFilled } from 'suomifi-icons';
import { filterDuplicateKeys } from '../../../utils/common/common.js';
var baseClassName = 'fi-status-text';
var statusTextClassNames = {
error: "".concat(baseClassName, "--error"),
success: "".concat(baseClassName, "--success")
};
var getIcon = function getIcon(status) {
if (status === undefined || status === 'default') return null;
if (status === 'error') return /*#__PURE__*/React.createElement(IconErrorFilled, {
"aria-hidden": "true"
});
if (status === 'success') {
return /*#__PURE__*/React.createElement(IconCheckCircleFilled, {
"aria-hidden": "true"
});
}
};
var StyledStatusText = styled(function (_a) {
var _b;
var className = _a.className;
_a.globalMargins;
var children = _a.children,
disabled = _a.disabled,
status = _a.status;
_a.theme;
var _c = _a.ariaLiveMode,
ariaLiveMode = _c === void 0 ? 'polite' : _c,
rest = __rest(_a, ["className", "globalMargins", "children", "disabled", "status", "theme", "ariaLiveMode"]);
var _d = separateMarginProps(rest),
passProps = _d[1];
var ariaLiveProp = !disabled ? {
'aria-live': ariaLiveMode
} : {
'aria-live': 'off'
};
return /*#__PURE__*/React.createElement(HtmlSpan, __assign({}, passProps, ariaLiveProp, {
className: classnames(className, baseClassName, (_b = {}, _b[statusTextClassNames.error] = status === 'error', _b[statusTextClassNames.success] = status === 'success', _b)),
"aria-atomic": "true",
style: __assign({}, passProps === null || passProps === void 0 ? void 0 : passProps.style)
}), !!children && getIcon(status), children);
}).withConfig({
componentId: "sc-18fcmym-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.statusText, marginProps);
return baseStyles(theme, cleanedGlobalMargins, marginProps);
});
var StatusText = /*#__PURE__*/forwardRef(function (props, ref) {
var children = props.children,
passProps = __rest(props, ["children"]);
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(StyledStatusText, __assign({
forwardedRef: ref,
globalMargins: margins,
theme: suomifiTheme
}, passProps), children);
});
});
});
StatusText.displayName = 'StatusText';
var templateObject_1;
export { StatusText };
//# sourceMappingURL=StatusText.js.map