Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | 98x 98x 1x 42x 3x 42x 42x 3x 98x 98x 98x 3x 91x | /*
Copyright (c) 2018-2019 Uber Technologies, Inc.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
// @flow
import {styled} from '../styles/index.js';
import {getSvgStyles} from '../icon/styled-components.js';
import {KIND, PLACEMENT, TYPE} from './constants.js';
import type {
SharedStylePropsArgT,
ToasterSharedStylePropsArgT,
KindTypeT,
NotificationTypeT,
PlacementTypeT,
} from './types.js';
import type {ThemeT} from '../styles/types.js';
function getBackgroundColor(
kind: KindTypeT,
type: NotificationTypeT,
theme: ThemeT,
) {
const isInline = type === TYPE.inline;
return {
[KIND.info]: isInline
? theme.colors.notificationPrimaryBackground
: theme.colors.toastPrimaryBackground,
[KIND.positive]: isInline
? theme.colors.notificationPositiveBackground
: theme.colors.toastPositiveBackground,
[KIND.warning]: isInline
? theme.colors.notificationWarningBackground
: theme.colors.toastWarningBackground,
[KIND.negative]: isInline
? theme.colors.notificationNegativeBackground
: theme.colors.toastNegativeBackground,
}[kind];
}
function getFontColor(kind: KindTypeT, theme: ThemeT) {
return {
[KIND.info]: theme.colors.notificationPrimaryText,
[KIND.positive]: theme.colors.notificationPositiveText,
[KIND.warning]: theme.colors.notificationWarningText,
[KIND.negative]: theme.colors.notificationNegativeText,
}[kind];
}
export function getPlacement(placement: PlacementTypeT) {
return {
[PLACEMENT.topLeft]: {
top: 0,
alignItems: 'flex-start',
justifyContent: 'flex-start',
flexDirection: 'column',
},
[PLACEMENT.top]: {
top: 0,
alignItems: 'center',
justifyContent: 'flex-start',
flexDirection: 'column',
},
[PLACEMENT.topRight]: {
top: 0,
alignItems: 'flex-end',
justifyContent: 'flex-start',
flexDirection: 'column',
},
[PLACEMENT.bottomRight]: {
bottom: 0,
alignItems: 'flex-end',
justifyContent: 'flex-end',
flexDirection: 'column-reverse',
},
[PLACEMENT.bottom]: {
bottom: 0,
alignItems: 'center',
justifyContent: 'flex-end',
flexDirection: 'column-reverse',
},
[PLACEMENT.bottomLeft]: {
bottom: 0,
alignItems: 'flex-start',
justifyContent: 'flex-end',
flexDirection: 'column-reverse',
},
}[placement];
}
// $FlowFixMe https://github.com/facebook/flow/issues/7745
export const Root = styled<ToasterSharedStylePropsArgT>('div', props => {
const {$placement, $theme} = props;
return {
pointerEvents: 'none',
position: 'fixed',
right: 0,
left: 0,
display: 'flex',
marginTop: $theme.sizing.scale300,
marginBottom: $theme.sizing.scale300,
marginLeft: $theme.sizing.scale600,
marginRight: $theme.sizing.scale600,
...getPlacement($placement),
};
});
// $FlowFixMe https://github.com/facebook/flow/issues/7745
export const Body = styled<SharedStylePropsArgT>('div', props => {
const {$isVisible, $kind, $type, $theme} = props;
const isInline = $type === TYPE.inline;
return {
...$theme.typography.font350,
pointerEvents: 'auto',
color: isInline ? getFontColor($kind, $theme) : $theme.colors.toastText,
height: 'auto',
width: '288px',
paddingTop: $theme.sizing.scale600,
paddingRight: $theme.sizing.scale600,
paddingBottom: $theme.sizing.scale600,
paddingLeft: $theme.sizing.scale600,
marginTop: $theme.sizing.scale300,
marginBottom: $theme.sizing.scale300,
backgroundColor:
getBackgroundColor($kind, $type, $theme) || $theme.colors.primary500,
boxShadow: isInline ? 'none' : $theme.lighting.shadow600,
opacity: $isVisible ? 1 : 0,
transitionProperty: 'all',
transitionDuration: $theme.animation.timing100,
transitionTimingFunction: $theme.animation.easeInOutCurve,
display: 'flex',
justifyContent: 'space-between',
};
});
// $FlowFixMe https://github.com/facebook/flow/issues/7745
export const CloseIconSvg = styled<SharedStylePropsArgT>('svg', props => {
return {
...getSvgStyles(props),
cursor: 'pointer',
width: '16px',
flexShrink: 0,
};
});
|