import styled from '@emotion/styled'; import { css } from '@emotion/react'; import noop from 'utils/noop'; import CloseIcon from 'components/Icon/icons/content/close'; import Button from 'components/Button'; import { mineShaft } from 'styles/colors'; import { fontWeight } from 'styles/fonts'; import { ReactNode } from 'react'; const Container = styled.div>` position: relative; display: flex; align-items: center; padding: 12px 16px; box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.12), 0px 0px 12px rgba(0, 0, 0, 0.1), 0px 0px 20px rgba(0, 0, 0, 0.08); ${({ size }) => css` max-width: ${size === 'large' ? 412 : 328}px; `} ${({ theme: { rtl }, render }) => !render && (rtl ? css` padding-left: 48px; ` : css` padding-right: 48px; `)} > :not(:first-child) { ${({ theme: { rtl } }) => rtl ? css` margin-right: 12px; ` : css` margin-left: 12px; `} } `; const StyledImg = styled.img>` ${({ size }) => { const dim = size === 'large' ? 100 : 64; return css` width: ${dim}px; height: ${dim}px; `; }} `; const Content = styled.div` display: flex; flex-direction: column; color: ${mineShaft[900]}; line-height: 20px; letter-spacing: 0.216667px; > :not(:first-child) { margin-top: 8px; } `; const Title = styled.h3` margin: 0; font-size: 16px; font-weight: ${fontWeight.medium}; line-height: 24px; letter-spacing: 0.25px; `; const ActionButton = styled(Button)` padding: 0; `; const CloseButton = styled.button` position: absolute; top: 12px; ${({ theme: { rtl } }) => css` ${rtl ? 'left' : 'right'}: 16px; `} appearance: none; padding: 0; border: none; background-color: transparent; cursor: pointer; outline: 0; `; export interface Props { /** Source uri of illustration if needed */ imgSrc?: string; /** Controls the size of the dialog */ size?: 'small' | 'large'; /** Title of the Dialog message */ title?: string; /** Description of the Dialog message */ message?: string; /** Label text of the action button */ actionLabel?: string; /** Callback function, to be executed when clicked on action button */ onActionClick?: () => void; /** Callback function, to be executed when clicked close button */ onDismiss?: () => void; /** Custom content render function */ render?: ReactNode; /** Rest Props */ [rest: string]: any; } const Dialog = ({ imgSrc = '', size = 'large', title = '', message = '', actionLabel = '', onActionClick = noop, onDismiss = noop, render, ...rest }: Props) => ( {typeof render === 'function' ? ( render() ) : ( <> {imgSrc && } {title && {title}} {message && {message}} {actionLabel && (
{actionLabel}
)}
)}
); export default Dialog;