Skip to content

Commit a418038

Browse files
authored
responsive keyValueList (#75)
responsive keyValueList
2 parents 022180e + cfb9772 commit a418038

File tree

2 files changed

+134
-8
lines changed

2 files changed

+134
-8
lines changed

docs/Examples/List.example.purs

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import Lumi.Components.Color (colorNames)
88
import Lumi.Components.Column (columnSelfStretch, column_)
99
import Lumi.Components.Images (avatar, avatar_)
1010
import Lumi.Components.Link (link, defaults)
11-
import Lumi.Components.List (borderlessList, compactList, defaultList, list, structuredColumnList)
11+
import Lumi.Components.List (borderlessList, compactList, defaultList, keyValueList, list, structuredColumnList)
1212
import Lumi.Components.Lockup (lockup)
1313
import Lumi.Components.Row (row_)
1414
import Lumi.Components.Size (Size(..))
1515
import Lumi.Components.Text (text, subtext, h2_, body_)
16+
import Lumi.Components.Text as T
1617
import Lumi.Components.Example (example)
1718
import React.Basic (JSX, fragment)
1819
import React.Basic.DOM as R
@@ -111,6 +112,32 @@ docs =
111112
]
112113
}
113114
]
115+
116+
, h2_ "Key Value Lists"
117+
, example
118+
$ keyValueList
119+
{ rightAligned: true
120+
, rows: r
121+
, borders: true
122+
}
123+
, example
124+
$ keyValueList
125+
{ rightAligned: false
126+
, rows: r
127+
, borders: true
128+
}
129+
, example
130+
$ keyValueList
131+
{ rightAligned: true
132+
, rows: r
133+
, borders: false
134+
}
135+
, example
136+
$ keyValueList
137+
{ rightAligned: false
138+
, rows: r
139+
, borders: false
140+
}
114141
]
115142
where
116143
simpleListData =
@@ -167,3 +194,25 @@ docs =
167194
, id: "789"
168195
}
169196
]
197+
198+
r =
199+
[ { label: "Name"
200+
, value: T.body_ "Flexo"
201+
}
202+
, { label: "Email"
203+
, value: T.body_ "[email protected]"
204+
}
205+
, { label: ""
206+
, value: lockup
207+
{ title: R.text "Flexo R."
208+
, subtitle: Just $ R.text "Lumi"
209+
, image: Just $ avatar_
210+
{ size: Large
211+
, image:
212+
R.img
213+
{ src: "https://s3.amazonaws.com/lumi-flapjack-staging/mockups/9e7f08b801e6bb3a428ef72e93c49fe5.jpg"
214+
}
215+
}
216+
}
217+
}
218+
]

src/Lumi/Components/List.purs

Lines changed: 84 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ module Lumi.Components.List where
22

33
import Prelude
44

5+
import Data.Nullable (notNull)
56
import Color (cssStringHSLA)
67
import Data.Array (mapMaybe)
78
import Data.Maybe (Maybe(..))
89
import JSS (JSS, jss)
9-
import Lumi.Components.Color (colors)
10+
import Lumi.Components.Color (colors, colorNames)
11+
import Lumi.Components.Row (row)
1012
import Lumi.Components.Size (Size(..))
13+
import Lumi.Components.Text as T
1114
import React.Basic (Component, JSX, createComponent, element, makeStateless)
1215
import React.Basic.DOM as R
1316

@@ -102,6 +105,64 @@ structuredColumnList = makeStateless structuredColumnListComponent render
102105
renderRowCell row col =
103106
col.renderCell row
104107

108+
keyValueList
109+
:: { rightAligned :: Boolean
110+
, rows ::
111+
Array
112+
{ label :: String
113+
, value :: JSX
114+
}
115+
, borders :: Boolean
116+
}
117+
-> JSX
118+
keyValueList { rightAligned, rows, borders } =
119+
let
120+
lumiKeyValueListElement = element (R.unsafeCreateDOMComponent "lumi-key-value-list")
121+
lumiKeyValueListLabelElement = element (R.unsafeCreateDOMComponent "lumi-key-value-list-label")
122+
lumiKeyValueListValueElement = element (R.unsafeCreateDOMComponent "lumi-key-value-list-value")
123+
124+
toRows r =
125+
r <#> \{ label, value } ->
126+
[ row
127+
{ style: R.css
128+
{ alignItems: "center"
129+
, justifyContent: "space-between"
130+
, width: "100%"
131+
}
132+
, children:
133+
[ lumiKeyValueListLabelElement
134+
{ children:
135+
[ T.text T.body
136+
{ style = R.css {}
137+
, color = notNull colorNames.black1
138+
, children = [ R.text label ]
139+
}
140+
]
141+
, style: R.css {}
142+
}
143+
, lumiKeyValueListValueElement
144+
{ children: [ value ]
145+
, style: R.css
146+
{ justifyContent: if rightAligned then "flex-end" else "flex-start"
147+
}
148+
}
149+
]
150+
}
151+
]
152+
in
153+
lumiKeyValueListElement
154+
{ children:
155+
[ if borders
156+
then list compactList
157+
{ rows = toRows rows
158+
}
159+
else borderlessList compactList
160+
{ rows = toRows rows
161+
}
162+
]
163+
, style: R.css { width: "100%" }
164+
}
165+
105166
styles :: JSS
106167
styles = jss
107168
{ "@global":
@@ -111,7 +172,6 @@ styles = jss
111172
, flexFlow: "column"
112173
, listStyleType: "none"
113174
, borderBottom: [ "1px", "solid", cssStringHSLA colors.black4 ]
114-
115175
, "& > lumi-list-row":
116176
{ boxSizing: "border-box"
117177
, display: "flex"
@@ -120,7 +180,6 @@ styles = jss
120180
, minHeight: "calc(48px + 1px)"
121181
, padding: "6px 0"
122182
, borderTop: [ "1px", "solid", cssStringHSLA colors.black4 ]
123-
124183
, "& > lumi-list-row-cell":
125184
{ boxSizing: "border-box"
126185
, display: "flex"
@@ -130,14 +189,12 @@ styles = jss
130189
, maxWidth: "100%"
131190
}
132191
}
133-
134192
, "&[data-borders=\"false\"]":
135193
{ border: "0"
136194
, "& > lumi-list-row":
137195
{ border: "0"
138196
}
139197
}
140-
141198
, "&[data-size=\"small\"] > lumi-list-row":
142199
{ minHeight: "calc(40px + 1px)"
143200
, padding: "2px 0"
@@ -152,13 +209,33 @@ styles = jss
152209
, justifyContent: "flex-end"
153210
, alignItems: "center"
154211
}
155-
156212
, "@media (max-width: 448px)":
157213
{ "& > lumi-list-row > lumi-list-row-cell":
158214
{ alignItems: "flex-end"
159215
}
160216
}
161217
}
162-
218+
, "lumi-key-value-list":
219+
{ "& lumi-key-value-list-label":
220+
{ "flex": "3 5 0%"
221+
, "padding": "8px 0"
222+
}
223+
, "& lumi-key-value-list-value":
224+
{ "display": "flex"
225+
, "flexFlow": "row"
226+
, "alignItems": "center"
227+
, "flex": "7 7 0%"
228+
, "flexWrap": "wrap"
229+
}
230+
, "@media (max-width: 860px)":
231+
{ "width": "100%"
232+
, "& lumi-key-value-list-label":
233+
{ "flex": "initial"
234+
}
235+
, "& lumi-key-value-list-value":
236+
{ "flex": "initial"
237+
}
238+
}
239+
}
163240
}
164241
}

0 commit comments

Comments
 (0)