/
StatusSlat.purs
98 lines (87 loc) · 2.81 KB
/
StatusSlat.purs
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
module Lumi.Components.StatusSlat where
import Prelude
import Color (cssStringHSLA)
import Data.Nullable (Nullable, toNullable, toMaybe)
import JSS (JSS, jss)
import Lumi.Components.Color (colors)
import Lumi.Components.Column (column)
import Lumi.Components.Row (row)
import Lumi.Components.Status (Status)
import Lumi.Components.Text (subtext_, title_)
import React.Basic (Component, JSX, createComponent, element, makeStateless)
import React.Basic.DOM (css, unsafeCreateDOMComponent)
type StatusCellProps =
{ data :: Array
{ label :: String
, content :: String
, status :: Nullable Status
}
}
component :: Component StatusCellProps
component = createComponent "StatusSlat"
statusSlat :: StatusCellProps -> JSX
statusSlat = makeStateless component $ lumiStatusSlat <<< mapProps
where
mapProps props =
{ className: "lumi"
, children:
row
{ style: css
{ height: "100%" }
, children: map toStatusCell props.data
}
}
toStatusCell { label, content, status } =
lumiStatusSlatCell
{ "data-status": toNullable (map show (toMaybe status))
, children:
column
{ style: css
{ height: "100%"
, justifyContent: "center"
}
, children:
[ subtext_ label
, title_ content
]
}
}
lumiStatusSlat = element (unsafeCreateDOMComponent "lumi-status-slat")
lumiStatusSlatCell = element (unsafeCreateDOMComponent "lumi-status-slat-cell")
styles :: JSS
styles = jss
{ "@global":
{ "lumi-status-slat":
{ border: [ "1px", "solid", cssStringHSLA colors.black4 ]
, width: "100%"
, height: "64px"
, display: "inline-block"
, borderRadius: "5px"
, "& lumi-status-slat-cell":
{ borderRight: [ "1px", "solid", cssStringHSLA colors.black4 ]
, height: "100%"
, minWidth: "calc(25% - (2 * 16px))"
, display: "inline-block"
, padding: "0 16px"
, whiteSpace: "nowrap"
, overflow: "hidden"
, textOverflow: "ellipsis"
, "&:last-child":
{ borderRight: "none"
}
, "&[data-status=\"active\"]":
{ color: cssStringHSLA colors.accent1
}
, "&[data-status=\"warning\"]":
{ color: cssStringHSLA colors.accent2
}
, "&[data-status=\"error\"]":
{ color: cssStringHSLA colors.accent3
}
, "&[data-status=\"unknown\"]":
{ color: cssStringHSLA colors.black1
}
}
}
}
}