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';
|
2017-09-26 19:07:45 +03:00
|
|
|
import remcalc from 'remcalc';
|
2018-02-26 15:36:37 +02: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';
|
2017-12-22 03:08:27 +02:00
|
|
|
import { Close } from '../icons';
|
2017-08-02 13:29:19 +03:00
|
|
|
|
2017-10-09 16:42:54 +03:00
|
|
|
const Container = styled.div`
|
2018-01-26 16:12:46 +02:00
|
|
|
display: flex;
|
2017-08-02 13:29:19 +03:00
|
|
|
position: relative;
|
|
|
|
background-color: ${props => props.theme.white};
|
2017-12-22 03:08:27 +02:00
|
|
|
box-shadow: ${props => props.theme.shadows.bottomShadow};
|
|
|
|
border: ${remcalc(1)} solid ${props => props.theme.grey};
|
2018-01-26 16:12:46 +02:00
|
|
|
border-radius: ${remcalc(3)};
|
2017-09-14 19:50:22 +03:00
|
|
|
width: 100%;
|
2017-08-02 13:29:19 +03:00
|
|
|
`;
|
|
|
|
|
2017-10-09 16:42:54 +03:00
|
|
|
const Color = styled.div`
|
2018-01-26 16:12:46 +02:00
|
|
|
border-radius: ${remcalc(3)} 0 0 ${remcalc(3)};
|
|
|
|
|
|
|
|
margin: ${remcalc(-1)} 0 ${remcalc(-1)} ${remcalc(-1)};
|
|
|
|
min-width: ${remcalc(12)};
|
2017-09-26 19:07:45 +03:00
|
|
|
min-height: 100%;
|
2018-01-26 16:12:46 +02:00
|
|
|
|
|
|
|
${is('success')`
|
|
|
|
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 */
|
2018-01-26 16:12:46 +02:00
|
|
|
padding: ${remcalc(18)} ${remcalc(18)};
|
|
|
|
`;
|
|
|
|
|
|
|
|
const Text = P.extend`
|
|
|
|
line-height: ${remcalc(14)};
|
|
|
|
font-size: ${remcalc(13)};
|
2017-10-09 21:01:34 +03:00
|
|
|
`;
|
2017-08-02 13:29:19 +03:00
|
|
|
|
2018-01-26 16:12:46 +02:00
|
|
|
const CloseIcons = Close.extend`
|
2017-08-02 13:29:19 +03:00
|
|
|
position: absolute;
|
2018-01-26 16:12:46 +02:00
|
|
|
top: ${remcalc(23)};
|
|
|
|
right: ${remcalc(18)};
|
|
|
|
cursor: pointer;
|
2017-08-02 13:29:19 +03:00
|
|
|
`;
|
|
|
|
|
2017-10-11 14:01:26 +03:00
|
|
|
export const Message = ({ onCloseClick, children, ...type }) => (
|
2018-02-26 15:36:37 +02:00
|
|
|
<Container>
|
|
|
|
<Color {...type} />
|
|
|
|
<Outlet>{children}</Outlet>
|
|
|
|
{onCloseClick ? <CloseIcons onClick={onCloseClick} /> : null}
|
|
|
|
</Container>
|
2017-10-09 16:42:54 +03:00
|
|
|
);
|
2017-08-02 13:29:19 +03:00
|
|
|
|
2018-01-26 16:12:46 +02:00
|
|
|
export const Title = ({ children }) => <H4 noMargin>{children}</H4>;
|
2017-08-02 13:29:19 +03:00
|
|
|
|
2018-01-26 16:12:46 +02:00
|
|
|
export const Description = ({ children }) => <Text>{children}</Text>;
|
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 = {
|
|
|
|
error: false,
|
|
|
|
warning: false,
|
|
|
|
success: true
|
|
|
|
};
|
|
|
|
|
2018-02-26 15:36:37 +02:00
|
|
|
export default Message;
|