UNPKG

@pagopa/mui-italia

Version:

[Material-UI](https://mui.com/core/) theme inspired by [Bootstrap Italia](https://italia.github.io/bootstrap-italia/).

75 lines (74 loc) 2.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.computeViewState = exports.computeModel = exports.normalizeProps = void 0; const tslib_1 = require("tslib"); const jsx_runtime_1 = require("react/jsx-runtime"); const EmojiObjectsOutlined_1 = tslib_1.__importDefault(require("@mui/icons-material/EmojiObjectsOutlined")); const colors_1 = require("../../theme/colors"); const Push_1 = require("../../illustrations/Push"); const COLOR_STYLE_MAP = { white: { background: (theme) => theme.palette.background.paper, border: colors_1.neutral[100], }, info: { background: colors_1.blue[50], border: colors_1.blue[100], }, }; const DEFAULT_ICON = (0, jsx_runtime_1.jsx)(EmojiObjectsOutlined_1.default, { fontSize: "small" }); const DEFAULT_PRIMARY_ILLUSTRATION = (0, jsx_runtime_1.jsx)(Push_1.IllusPush, {}); function normalizeProps(props) { var _a; const variant = (_a = props.variant) !== null && _a !== void 0 ? _a : 'primary'; return Object.assign(Object.assign({}, props), { variant }); } exports.normalizeProps = normalizeProps; function computeModel(props, direction) { const { color = 'white', variant = 'primary', badge, onClose, cta, icon, illustration } = props; const hasClose = Boolean(onClose); const hasCta = Boolean(cta); const isHorizontal = direction === 'horizontal'; const resolvedIcon = icon !== null && icon !== void 0 ? icon : DEFAULT_ICON; let variantConfig; switch (variant) { case 'secondary': variantConfig = { textAlign: 'left', ctaKind: 'contained', }; break; case 'tertiary': variantConfig = { textAlign: isHorizontal ? 'left' : 'center', ctaKind: 'naked', topIcon: resolvedIcon, }; break; case 'primary': default: variantConfig = { textAlign: 'left', ctaKind: 'naked', illustrationNode: illustration !== null && illustration !== void 0 ? illustration : DEFAULT_PRIMARY_ILLUSTRATION, }; break; } return Object.assign(Object.assign({ colorStyle: COLOR_STYLE_MAP[color], direction }, variantConfig), { hasClose, hasCta, badgeText: badge }); } exports.computeModel = computeModel; function computeViewState(props, direction) { var _a; const variant = (_a = props.variant) !== null && _a !== void 0 ? _a : 'primary'; const isHorizontal = direction === 'horizontal'; const contentGapPx = variant === 'tertiary' && isHorizontal ? 8 : 16; const primaryIllustrationSizePx = isHorizontal ? 80 : 56; return { variant, isHorizontal, contentGapPx, primaryIllustrationSizePx, }; } exports.computeViewState = computeViewState;