2018-09-27 07:13:29 +00:00
|
|
|
/* @flow */
|
|
|
|
|
2018-10-10 07:31:26 +00:00
|
|
|
import * as React from 'react';
|
2018-08-28 14:27:59 +00:00
|
|
|
import styled, { css } from 'styled-components';
|
2018-08-28 12:33:42 +00:00
|
|
|
import colors from 'config/colors';
|
2018-09-26 21:29:15 +00:00
|
|
|
import { getColor, getIcon } from 'utils/notification';
|
2018-08-28 14:27:59 +00:00
|
|
|
import Icon from 'components/Icon';
|
|
|
|
import icons from 'config/icons';
|
2018-10-11 10:01:31 +00:00
|
|
|
import { FONT_WEIGHT, FONT_SIZE } from 'config/variables';
|
2018-02-20 09:30:36 +00:00
|
|
|
|
2018-08-14 12:56:47 +00:00
|
|
|
import * as NotificationActions from 'actions/NotificationActions';
|
2018-08-24 07:57:23 +00:00
|
|
|
import Loader from 'components/Loader';
|
2018-10-10 08:55:53 +00:00
|
|
|
import type { CallbackAction } from 'reducers/NotificationReducer';
|
2018-10-10 07:31:26 +00:00
|
|
|
|
2018-09-04 09:30:36 +00:00
|
|
|
import NotificationButton from './components/NotificationButton';
|
2018-02-20 09:30:36 +00:00
|
|
|
|
2018-09-27 07:13:29 +00:00
|
|
|
type Props = {
|
|
|
|
type: string,
|
|
|
|
cancelable?: boolean;
|
|
|
|
title: string;
|
2018-10-11 10:21:24 +00:00
|
|
|
className?: string;
|
2018-09-27 07:13:29 +00:00
|
|
|
message?: string;
|
2018-10-10 08:55:53 +00:00
|
|
|
actions?: Array<CallbackAction>;
|
2018-09-27 07:13:29 +00:00
|
|
|
close?: typeof NotificationActions.close,
|
|
|
|
loading?: boolean
|
|
|
|
};
|
|
|
|
|
2018-08-28 12:33:42 +00:00
|
|
|
const Wrapper = styled.div`
|
2018-10-09 13:02:08 +00:00
|
|
|
width: 100%;
|
2018-08-28 12:33:42 +00:00
|
|
|
position: relative;
|
2018-08-28 14:27:59 +00:00
|
|
|
color: ${colors.TEXT_PRIMARY};
|
|
|
|
background: ${colors.TEXT_SECONDARY};
|
2018-10-11 12:13:04 +00:00
|
|
|
padding: 24px 48px 9px 24px;
|
2018-08-28 12:33:42 +00:00
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
text-align: left;
|
2018-10-11 10:21:24 +00:00
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
2018-08-28 14:27:59 +00:00
|
|
|
|
|
|
|
${props => props.type === 'info' && css`
|
|
|
|
color: ${colors.INFO_PRIMARY};
|
|
|
|
background: ${colors.INFO_SECONDARY};
|
|
|
|
`}
|
|
|
|
|
|
|
|
${props => props.type === 'success' && css`
|
|
|
|
color: ${colors.SUCCESS_PRIMARY};
|
|
|
|
background: ${colors.SUCCESS_SECONDARY};
|
|
|
|
`}
|
|
|
|
|
|
|
|
${props => props.type === 'warning' && css`
|
|
|
|
color: ${colors.WARNING_PRIMARY};
|
|
|
|
background: ${colors.WARNING_SECONDARY};
|
|
|
|
`}
|
|
|
|
|
|
|
|
${props => props.type === 'error' && css`
|
|
|
|
color: ${colors.ERROR_PRIMARY};
|
|
|
|
background: ${colors.ERROR_SECONDARY};
|
|
|
|
`}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const Body = styled.div`
|
2018-08-29 10:07:47 +00:00
|
|
|
display: flex;
|
2018-08-28 12:33:42 +00:00
|
|
|
`;
|
|
|
|
|
2018-10-11 10:01:31 +00:00
|
|
|
const Message = styled.div`
|
2018-10-11 12:13:04 +00:00
|
|
|
padding-bottom: 13px;
|
2018-10-11 10:01:31 +00:00
|
|
|
font-size: ${FONT_SIZE.SMALLER};
|
|
|
|
`;
|
|
|
|
|
2018-08-29 10:07:47 +00:00
|
|
|
const Title = styled.div`
|
2018-08-29 13:48:05 +00:00
|
|
|
padding-bottom: 5px;
|
2018-10-11 12:13:04 +00:00
|
|
|
padding-top: 1px;
|
2018-08-29 10:07:47 +00:00
|
|
|
font-weight: ${FONT_WEIGHT.BIGGER};
|
2018-08-28 14:27:59 +00:00
|
|
|
`;
|
|
|
|
|
2018-08-29 11:54:41 +00:00
|
|
|
const CloseClick = styled.div`
|
|
|
|
position: absolute;
|
|
|
|
right: 0;
|
|
|
|
top: 0;
|
|
|
|
padding: 20px 10px 0 0;
|
|
|
|
`;
|
2018-08-28 14:27:59 +00:00
|
|
|
|
2018-08-29 10:07:47 +00:00
|
|
|
const StyledIcon = styled(Icon)`
|
|
|
|
position: relative;
|
2018-08-29 11:54:41 +00:00
|
|
|
top: -7px;
|
2018-10-01 13:54:35 +00:00
|
|
|
min-width: 20px;
|
2018-08-29 10:07:47 +00:00
|
|
|
`;
|
|
|
|
|
2018-10-01 13:54:35 +00:00
|
|
|
const IconWrapper = styled.div`
|
2018-10-25 09:58:32 +00:00
|
|
|
min-width: 30px;
|
2018-08-29 13:48:05 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
const Texts = styled.div`
|
|
|
|
display: flex;
|
2018-10-11 10:21:24 +00:00
|
|
|
padding: 0 10px 0 0;
|
2018-08-29 13:48:05 +00:00
|
|
|
flex-direction: column;
|
|
|
|
`;
|
|
|
|
|
2018-09-05 14:36:48 +00:00
|
|
|
const AdditionalContent = styled.div`
|
|
|
|
display: flex;
|
|
|
|
justify-content: flex-end;
|
|
|
|
align-items: flex-end;
|
2018-10-01 13:54:35 +00:00
|
|
|
flex: 1;
|
2018-09-05 14:36:48 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
const ActionContent = styled.div`
|
2018-10-01 13:54:35 +00:00
|
|
|
display: flex;
|
2018-09-05 14:36:48 +00:00
|
|
|
justify-content: right;
|
|
|
|
align-items: flex-end;
|
2018-10-11 12:13:04 +00:00
|
|
|
padding-bottom: 14px;
|
2018-09-05 14:36:48 +00:00
|
|
|
`;
|
2018-08-29 10:07:47 +00:00
|
|
|
|
2018-10-10 07:31:26 +00:00
|
|
|
const Notification = (props: Props): React$Element<string> => {
|
2018-04-16 21:19:50 +00:00
|
|
|
const close: Function = typeof props.close === 'function' ? props.close : () => {}; // TODO: add default close action
|
2018-08-29 09:33:17 +00:00
|
|
|
|
2018-02-20 09:30:36 +00:00
|
|
|
return (
|
2018-10-10 15:29:43 +00:00
|
|
|
<Wrapper className={props.className} type={props.type}>
|
2018-08-29 10:07:47 +00:00
|
|
|
{props.loading && <Loader size={50} /> }
|
|
|
|
{props.cancelable && (
|
2018-08-28 14:27:59 +00:00
|
|
|
<CloseClick onClick={() => close()}>
|
2018-08-29 11:54:41 +00:00
|
|
|
<Icon
|
2018-09-26 21:29:15 +00:00
|
|
|
color={getColor(props.type)}
|
2018-08-29 11:54:41 +00:00
|
|
|
icon={icons.CLOSE}
|
|
|
|
size={20}
|
|
|
|
/>
|
2018-08-28 14:27:59 +00:00
|
|
|
</CloseClick>
|
2018-08-29 10:07:47 +00:00
|
|
|
)}
|
2018-08-28 14:27:59 +00:00
|
|
|
<Body>
|
2018-10-01 13:54:35 +00:00
|
|
|
<IconWrapper>
|
2018-08-29 11:07:37 +00:00
|
|
|
<StyledIcon
|
2018-09-26 21:29:15 +00:00
|
|
|
color={getColor(props.type)}
|
|
|
|
icon={getIcon(props.type)}
|
2018-08-29 11:07:37 +00:00
|
|
|
/>
|
2018-10-01 13:54:35 +00:00
|
|
|
</IconWrapper>
|
|
|
|
<Texts>
|
|
|
|
<Title>{ props.title }</Title>
|
2018-10-11 10:01:31 +00:00
|
|
|
{ props.message ? <Message>{props.message}</Message> : '' }
|
2018-10-01 13:54:35 +00:00
|
|
|
</Texts>
|
2018-08-28 14:27:59 +00:00
|
|
|
</Body>
|
2018-08-29 13:48:05 +00:00
|
|
|
<AdditionalContent>
|
|
|
|
{props.actions && props.actions.length > 0 && (
|
|
|
|
<ActionContent>
|
|
|
|
{props.actions.map(action => (
|
2018-08-29 11:54:41 +00:00
|
|
|
<NotificationButton
|
2018-08-29 10:07:47 +00:00
|
|
|
key={action.label}
|
2018-09-05 09:48:01 +00:00
|
|
|
type={props.type}
|
2018-08-28 14:27:59 +00:00
|
|
|
onClick={() => { close(); action.callback(); }}
|
2018-08-30 12:33:21 +00:00
|
|
|
>{action.label}
|
|
|
|
</NotificationButton>
|
2018-08-28 14:27:59 +00:00
|
|
|
))}
|
2018-08-29 13:48:05 +00:00
|
|
|
</ActionContent>
|
|
|
|
)}
|
|
|
|
</AdditionalContent>
|
2018-08-28 12:33:42 +00:00
|
|
|
</Wrapper>
|
2018-07-30 10:52:13 +00:00
|
|
|
);
|
|
|
|
};
|
2018-02-20 09:30:36 +00:00
|
|
|
|
2018-10-10 07:31:26 +00:00
|
|
|
export default Notification;
|