2017-08-02 13:29:19 +03:00
|
|
|
import React from 'react';
|
2017-09-08 15:01:37 +03:00
|
|
|
import is from 'styled-is';
|
2017-08-02 13:29:19 +03:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import styled from 'styled-components';
|
|
|
|
import unitcalc from 'unitcalc';
|
|
|
|
|
|
|
|
import { H3 } from '../text/headings';
|
|
|
|
import P from '../text/p';
|
|
|
|
import CloseButton from '../close-button';
|
|
|
|
import { border, bottomShaddow } from '../boxes';
|
|
|
|
|
|
|
|
const StyledContainer = styled.div`
|
|
|
|
position: relative;
|
|
|
|
margin-bottom: ${unitcalc(2)};
|
|
|
|
background-color: ${props => props.theme.white};
|
|
|
|
box-shadow: ${bottomShaddow};
|
|
|
|
border: ${border.confirmed};
|
|
|
|
`;
|
|
|
|
|
|
|
|
const StyledColor = styled.div`
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
width: ${unitcalc(6)};
|
|
|
|
height: 100%;
|
2017-09-08 15:01:37 +03:00
|
|
|
background-color: ${props => props.theme.green};
|
|
|
|
${is('error')`
|
|
|
|
background-color: ${props => props.theme.red};
|
|
|
|
`};
|
|
|
|
${is('warning')`
|
|
|
|
background-color: ${props => props.theme.orange};
|
|
|
|
`};
|
2017-08-02 13:29:19 +03:00
|
|
|
`;
|
|
|
|
|
|
|
|
const StyledMessageContainer = styled.div`
|
|
|
|
padding: ${unitcalc(2)} 0 ${unitcalc(2.25)} 0;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const StyledTitle = styled(H3)`
|
|
|
|
margin: 0 ${unitcalc(9)} ${unitcalc(0.25)} ${unitcalc(9)};
|
|
|
|
font-weight: 600;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const StyledMessage = styled(P)`
|
|
|
|
margin: ${unitcalc(0.25)} ${unitcalc(9)} 0 ${unitcalc(9)};
|
|
|
|
`;
|
|
|
|
|
|
|
|
const StyledClose = styled(CloseButton)`
|
|
|
|
position: absolute;
|
|
|
|
right: ${unitcalc(0.5)};
|
|
|
|
top: ${unitcalc(0.5)};
|
|
|
|
`;
|
|
|
|
|
2017-09-08 18:44:08 +03:00
|
|
|
const Message = ({ title, message, onCloseClick, children, ...type }) => {
|
2017-08-28 22:21:08 +03:00
|
|
|
const renderTitle = title ? <StyledTitle>{title}</StyledTitle> : null;
|
2017-08-02 13:29:19 +03:00
|
|
|
|
2017-08-28 22:21:08 +03:00
|
|
|
const renderClose = onCloseClick ? (
|
|
|
|
<StyledClose onClick={onCloseClick} />
|
|
|
|
) : null;
|
2017-08-02 13:29:19 +03:00
|
|
|
|
|
|
|
return (
|
|
|
|
<StyledContainer>
|
2017-09-08 15:01:37 +03:00
|
|
|
<StyledColor {...type} />
|
2017-08-02 13:29:19 +03:00
|
|
|
<StyledMessageContainer>
|
2017-08-08 13:07:18 +03:00
|
|
|
{renderTitle}
|
2017-09-08 18:44:08 +03:00
|
|
|
<StyledMessage>{message || children}</StyledMessage>
|
2017-08-02 13:29:19 +03:00
|
|
|
</StyledMessageContainer>
|
2017-08-08 13:07:18 +03:00
|
|
|
{renderClose}
|
2017-08-02 13:29:19 +03:00
|
|
|
</StyledContainer>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
Message.propTypes = {
|
|
|
|
title: PropTypes.string,
|
|
|
|
message: PropTypes.string.isRequired,
|
|
|
|
onCloseClick: PropTypes.func,
|
2017-09-08 15:01:37 +03:00
|
|
|
error: PropTypes.boolean,
|
|
|
|
warning: PropTypes.boolean,
|
|
|
|
success: PropTypes.boolean
|
2017-08-02 13:29:19 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Message;
|