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';
|
2017-09-26 19:07:45 +03:00
|
|
|
import remcalc from 'remcalc';
|
2017-08-02 13:29:19 +03:00
|
|
|
|
2017-09-26 19:07:45 +03:00
|
|
|
import { H4 } from '../text/headings';
|
2017-08-02 13:29:19 +03:00
|
|
|
import P from '../text/p';
|
|
|
|
import CloseButton from '../close-button';
|
2017-10-10 13:15:35 +03:00
|
|
|
import { border, bottomShadow } from '../boxes';
|
2017-08-02 13:29:19 +03:00
|
|
|
|
2017-10-09 16:42:54 +03:00
|
|
|
const Container = styled.div`
|
2017-08-02 13:29:19 +03:00
|
|
|
position: relative;
|
|
|
|
margin-bottom: ${unitcalc(2)};
|
|
|
|
background-color: ${props => props.theme.white};
|
2017-10-10 13:15:35 +03:00
|
|
|
box-shadow: ${bottomShadow};
|
2017-08-02 13:29:19 +03:00
|
|
|
border: ${border.confirmed};
|
2017-09-14 19:50:22 +03:00
|
|
|
width: 100%;
|
2017-09-26 19:07:45 +03:00
|
|
|
display: flex;
|
2017-08-02 13:29:19 +03:00
|
|
|
`;
|
|
|
|
|
2017-10-09 16:42:54 +03:00
|
|
|
const Color = styled.div`
|
2017-09-26 19:07:45 +03:00
|
|
|
min-width: ${remcalc(36)};
|
|
|
|
margin-right: ${remcalc(18)};
|
|
|
|
min-height: 100%;
|
2017-09-08 15:01:37 +03:00
|
|
|
background-color: ${props => props.theme.green};
|
2017-10-09 16:42:54 +03:00
|
|
|
|
2017-09-08 15:01:37 +03:00
|
|
|
${is('error')`
|
|
|
|
background-color: ${props => props.theme.red};
|
|
|
|
`};
|
2017-10-09 16:42:54 +03:00
|
|
|
|
2017-09-08 15:01:37 +03:00
|
|
|
${is('warning')`
|
|
|
|
background-color: ${props => props.theme.orange};
|
|
|
|
`};
|
2017-08-02 13:29:19 +03:00
|
|
|
`;
|
|
|
|
|
2017-10-09 21:01:34 +03:00
|
|
|
const Outlet = styled.div`
|
|
|
|
/* trick prettier */
|
|
|
|
padding: ${unitcalc(2)} 0 ${unitcalc(2.25)} 0;
|
|
|
|
`;
|
2017-08-02 13:29:19 +03:00
|
|
|
|
2017-10-09 16:42:54 +03:00
|
|
|
const Close = styled(CloseButton)`
|
2017-08-02 13:29:19 +03:00
|
|
|
position: absolute;
|
|
|
|
right: ${unitcalc(0.5)};
|
|
|
|
top: ${unitcalc(0.5)};
|
|
|
|
`;
|
|
|
|
|
2017-10-11 14:01:26 +03:00
|
|
|
export const Message = ({ onCloseClick, children, ...type }) => (
|
2017-10-09 16:42:54 +03:00
|
|
|
<Container>
|
|
|
|
<Color {...type} />
|
|
|
|
<Outlet>{children}</Outlet>
|
2017-10-09 21:01:34 +03:00
|
|
|
{onCloseClick && <Close onClick={onCloseClick} />}
|
2017-10-09 16:42:54 +03:00
|
|
|
</Container>
|
|
|
|
);
|
2017-08-02 13:29:19 +03:00
|
|
|
|
2017-10-09 16:42:54 +03:00
|
|
|
export const Title = ({ children }) => <H4>{children}</H4>;
|
2017-08-02 13:29:19 +03:00
|
|
|
|
2017-10-09 16:42:54 +03:00
|
|
|
export const Description = ({ children }) => <P>{children}</P>;
|
2017-08-02 13:29:19 +03:00
|
|
|
|
|
|
|
Message.propTypes = {
|
2017-10-23 17:09:49 +03:00
|
|
|
/**
|
|
|
|
* Function to call when the close button is clicked
|
|
|
|
*/
|
2017-08-02 13:29:19 +03:00
|
|
|
onCloseClick: PropTypes.func,
|
2017-10-23 17:09:49 +03:00
|
|
|
/**
|
|
|
|
* Is it an error message ?
|
|
|
|
*/
|
2017-09-14 19:50:22 +03:00
|
|
|
error: PropTypes.bool,
|
2017-10-23 17:09:49 +03:00
|
|
|
/**
|
|
|
|
* Is it an warning message ?
|
|
|
|
*/
|
2017-09-14 19:50:22 +03:00
|
|
|
warning: PropTypes.bool,
|
2017-10-23 17:09:49 +03:00
|
|
|
/**
|
|
|
|
* Is it an success message ?
|
|
|
|
*/
|
2017-09-14 19:50:22 +03:00
|
|
|
success: PropTypes.bool
|
2017-08-02 13:29:19 +03:00
|
|
|
};
|
|
|
|
|
2017-10-23 17:09:49 +03:00
|
|
|
Message.defaultProps = {
|
|
|
|
onCloseClick: () => {},
|
|
|
|
error: false,
|
|
|
|
warning: false,
|
|
|
|
success: true
|
|
|
|
};
|
|
|
|
|
2017-08-02 13:29:19 +03:00
|
|
|
export default Message;
|