joyent-portal/ui/src/components/notification/index.js

88 lines
1.5 KiB
JavaScript
Raw Normal View History

const constants = require('../../shared/constants');
2017-01-10 18:52:08 +02:00
const composers = require('../../shared/composers');
2017-02-15 03:19:26 +02:00
const fns = require('../../shared/functions');
const React = require('react');
const Styled = require('styled-components');
const Close = require('../close');
const {
colors
} = constants;
const {
remcalc
} = fns;
const {
default: styled
} = Styled;
2017-01-10 18:52:08 +02:00
const {
baseBox,
2017-02-15 03:19:26 +02:00
pseudoEl,
Baseline
2017-01-10 18:52:08 +02:00
} = composers;
2017-01-10 18:52:08 +02:00
const decorationWidth = remcalc(108);
const StyledNotification = styled.div`
display: inline-block;
2017-01-10 18:52:08 +02:00
min-height: 100%;
position: relative;
width: 100%;
2017-01-10 18:52:08 +02:00
${baseBox(0)}
2017-02-15 03:19:26 +02:00
2017-01-10 18:52:08 +02:00
&::before {
background-color: ${props => colors[props.type] || colors.brandPrimary}
width: ${decorationWidth};
height: 100%;
2017-02-15 03:19:26 +02:00
2017-01-10 18:52:08 +02:00
${pseudoEl()}
}
`;
const StyledContent = styled.div`
float: left;
2017-01-10 18:52:08 +02:00
padding: ${remcalc(18)} 20% ${remcalc(18)} ${remcalc(18)};
margin-left: ${decorationWidth};
width: 100%;
`;
const Notificaton = ({
children,
className,
style,
type,
close
}) => {
2017-02-15 03:19:26 +02:00
const renderClose = !close ? null : (
<Close onClick={close} />
);
return (
<StyledNotification
className={className}
style={style}
type={type}
>
2017-02-15 03:19:26 +02:00
{renderClose}
<StyledContent>
{children}
</StyledContent>
</StyledNotification>
);
};
Notificaton.propTypes = {
children: React.PropTypes.object,
className: React.PropTypes.str,
close: React.PropTypes.func,
style: React.PropTypes.object,
2017-01-10 18:52:08 +02:00
type: React.PropTypes.string
};
2017-02-15 03:19:26 +02:00
module.exports = Baseline(
Notificaton
);