joyent-portal/packages/ui-toolkit/src/message/index.js

77 lines
1.8 KiB
JavaScript
Raw Normal View History

import React from 'react';
2017-09-08 15:01:37 +03:00
import is from 'styled-is';
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-09-26 19:07:45 +03:00
import { H4 } 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};
2017-09-14 19:50:22 +03:00
width: 100%;
2017-09-26 19:07:45 +03:00
display: flex;
`;
const StyledColor = 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};
${is('error')`
background-color: ${props => props.theme.red};
`};
${is('warning')`
background-color: ${props => props.theme.orange};
`};
`;
const StyledMessageContainer = styled.div`
padding: ${unitcalc(2)} 0 ${unitcalc(2.25)} 0;
`;
const StyledClose = styled(CloseButton)`
position: absolute;
right: ${unitcalc(0.5)};
top: ${unitcalc(0.5)};
`;
const Message = ({ title, message, onCloseClick, children, ...type }) => {
2017-09-26 19:07:45 +03:00
const renderTitle = title ? <H4>{title}</H4> : null;
2017-08-28 22:21:08 +03:00
const renderClose = onCloseClick ? (
<StyledClose onClick={onCloseClick} />
) : null;
return (
<StyledContainer>
2017-09-08 15:01:37 +03:00
<StyledColor {...type} />
2017-09-26 19:07:45 +03:00
<div>
<StyledMessageContainer>
{renderTitle}
<P>{message || children}</P>
</StyledMessageContainer>
</div>
{renderClose}
</StyledContainer>
);
};
Message.propTypes = {
title: PropTypes.string,
message: PropTypes.string,
onCloseClick: PropTypes.func,
2017-09-14 19:50:22 +03:00
error: PropTypes.bool,
warning: PropTypes.bool,
success: PropTypes.bool
};
export default Message;