@coveord/plasma-mantine
Version:
A Plasma flavoured Mantine theme
106 lines (105 loc) • 3.92 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Box, createVarsResolver, factory, Image, useProps, useStyles } from '@mantine/core';
import { Children } from 'react';
import { Modal } from '../modal';
import Critical from './icons/critical.svg';
import Info from './icons/info.svg';
import Success from './icons/success.svg';
import Warning from './icons/warning.svg';
import { PromptContextProvider } from './Prompt.context';
import classes from './Prompt.module.css';
import { PromptCancelButton } from './PromptCancelButton';
import { PromptConfirmButton } from './PromptConfirmButton';
const PROMPT_VARIANT_ICONS_SRC = {
success: Success,
warning: Warning,
critical: Critical,
info: Info
};
const defaultProps = {
variant: 'info',
centered: true
};
const varsResolver = createVarsResolver((_theme, { icon })=>({
root: {
'--prompt-icon-size': icon ? undefined : '88px'
}
}));
export const Prompt = factory((_props, ref)=>{
const props = useProps('Prompt', defaultProps, _props);
const { variant, title, icon, children, className, classNames, style, styles, unstyled, vars, ...others } = props;
const getStyles = useStyles({
name: 'Prompt',
props,
classes,
className,
style,
classNames,
styles,
unstyled,
vars,
varsResolver
});
const stylesApiProps = {
classNames,
styles
};
const footers = [];
const otherChildren = [];
Children.forEach(children, (child)=>{
(child.type === Modal.Footer ? footers : otherChildren).push(child);
});
return /*#__PURE__*/ _jsx(PromptContextProvider, {
value: {
variant,
getStyles
},
children: /*#__PURE__*/ _jsxs(Modal.Root, {
ref: ref,
variant: "prompt",
size: "sm",
...others,
...getStyles('root'),
children: [
/*#__PURE__*/ _jsx(Modal.Overlay, {
...getStyles('overlay', stylesApiProps)
}),
/*#__PURE__*/ _jsxs(Modal.Content, {
...getStyles('content', stylesApiProps),
children: [
/*#__PURE__*/ _jsxs(Modal.Header, {
...getStyles('header', stylesApiProps),
children: [
icon || icon === null ? icon : /*#__PURE__*/ _jsx(Image, {
alt: "",
role: "presentation",
...getStyles('icon', stylesApiProps),
src: PROMPT_VARIANT_ICONS_SRC[variant]
}),
/*#__PURE__*/ _jsx(Modal.Title, {
...getStyles('title', stylesApiProps),
children: title
}),
/*#__PURE__*/ _jsx(Modal.CloseButton, {
...getStyles('close', stylesApiProps)
})
]
}),
/*#__PURE__*/ _jsx(Modal.Body, {
...getStyles('body', stylesApiProps),
children: /*#__PURE__*/ _jsx(Box, {
...getStyles('inner', stylesApiProps),
children: otherChildren
})
}),
footers
]
})
]
})
});
});
Prompt.CancelButton = PromptCancelButton;
Prompt.ConfirmButton = PromptConfirmButton;
Prompt.Footer = Modal.Footer;
//# sourceMappingURL=Prompt.js.map