-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtimeline-item-container.tsx
105 lines (96 loc) · 3.04 KB
/
timeline-item-container.tsx
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
import React, { ReactNode } from 'react'
import styled from 'styled-components'
import { ActionTypeEnum, MissionSourceEnum } from '../../../../types/env-mission-types.ts'
import { THEME } from "@mtes-mct/monitor-ui";
interface MissionTimelineItemContainerProps {
actionType: ActionTypeEnum
actionSource: MissionSourceEnum
children: ReactNode
}
type ItemOptions = {
backgroundColor?: string
borderColor?: string
color?: string
noMinHeight?: boolean
}
function createActionStyled(options: ItemOptions) {
return styled.div`
min-height: ${options.noMinHeight ? 0 : options.borderColor ? '48px' : '52px'};
background: ${options.backgroundColor || 'inherit'} 0% 0% no-repeat padding-box;
border: ${options.borderColor ? `1px solid ${options.borderColor}` : 'none'};
text-align: left;
letter-spacing: 0px;
`
}
const ActionControl = createActionStyled({
backgroundColor: THEME.color.white,
borderColor: THEME.color.lightGray
})
const ActionSurveillance = createActionStyled(
{
backgroundColor: '#e5e5eb',
borderColor: THEME.color.lightGray
})
const ActionNote = createActionStyled({
backgroundColor: THEME.color.blueYonder25,
borderColor: THEME.color.lightGray
})
const ActionOther = createActionStyled({
backgroundColor: THEME.color.blueYonder25,
borderColor: THEME.color.lightGray
})
const ActionStatus = createActionStyled({
backgroundColor: undefined,
borderColor: undefined,
noMinHeight: true
})
const ActionContact = createActionStyled({
backgroundColor: undefined,
borderColor: undefined,
color: '#707785'
})
const getActionComponent = (
actionSource: MissionSourceEnum,
actionType?: ActionTypeEnum
): React.FC<{ children: any }> | null => {
if (actionSource === MissionSourceEnum.MONITORENV) {
switch (actionType) {
case ActionTypeEnum.CONTROL:
return ActionControl
default:
return null
}
} else if (actionSource === MissionSourceEnum.MONITORFISH) {
switch (actionType) {
case ActionTypeEnum.CONTROL:
return ActionControl
default:
return null
}
} else if (actionSource === MissionSourceEnum.RAPPORTNAV) {
switch (actionType) {
case ActionTypeEnum.CONTROL:
return ActionControl
case ActionTypeEnum.STATUS:
return ActionStatus
case ActionTypeEnum.NOTE:
return ActionNote
default:
return null
}
} else {
return null
}
}
const MissionTimelineItemContainer: React.FC<MissionTimelineItemContainerProps> = ({
children,
actionType,
actionSource
}) => {
const Component = getActionComponent(actionSource, actionType)
if (!Component) {
return null
}
return <Component>{children}</Component>
}
export default MissionTimelineItemContainer