@@ -5,7 +5,7 @@ import Prelude
5
5
import Control.Monad.Except (runExcept )
6
6
import Data.Array as Array
7
7
import Data.Either (Either (..))
8
- import Data.Maybe (Maybe (..))
8
+ import Data.Maybe (Maybe (..), fromMaybe )
9
9
import Data.Newtype (un )
10
10
import Data.Nullable (notNull , null , toMaybe , toNullable )
11
11
import Effect.Console (log )
@@ -14,15 +14,19 @@ import Foreign (readString, unsafeToForeign)
14
14
import Foreign.Index (readProp )
15
15
import Lumi.Components.Column (column , column_ )
16
16
import Lumi.Components.Images (productThumb_ )
17
+ import Lumi.Components.Input (input , text_ )
17
18
import Lumi.Components.Link as Link
18
19
import Lumi.Components.Lockup (lockup )
20
+ import Lumi.Components.NativeSelect (defaults , nativeSelect )
19
21
import Lumi.Components.Size (Size (..))
20
22
import Lumi.Components.Table (ColumnName (..), SortString (..), table )
21
23
import Lumi.Components.Text (p_ )
22
24
import Lumi.Components.Example (example )
23
25
import React.Basic (Component , JSX , createComponent , make )
24
26
import React.Basic.DOM (css )
25
27
import React.Basic.DOM as R
28
+ import React.Basic.DOM.Events (targetValue )
29
+ import React.Basic.Events (handler )
26
30
import Web.HTML.History (URL (..))
27
31
28
32
component :: Component Unit
@@ -35,6 +39,7 @@ docs = unit # make component { initialState, render }
35
39
{ sort: SortString " asc"
36
40
, sortBy: Just (ColumnName " createdDate" )
37
41
, selected: [" 10cms9" , " 0mf7w" ]
42
+ , selectedOption: " "
38
43
, ex2Columns:
39
44
[ { required: true
40
45
, name: ColumnName " product-type"
@@ -61,12 +66,24 @@ docs = unit # make component { initialState, render }
61
66
, renderCell: \rowData -> R .text rowData.createdDate
62
67
}
63
68
]
69
+ , ex3Columns:
70
+ [ { required: true
71
+ , name: ColumnName " input"
72
+ , label: notNull " Input"
73
+ , filterLabel: null
74
+ , sortBy: null
75
+ , style: css {}
76
+ , hidden: false
77
+ , sticky: false
78
+ , renderCell: \rowData ->
79
+ input text_ { placeholder = " Placeholder..." }
80
+ }
81
+ ]
64
82
}
65
83
66
84
render self =
67
85
column_
68
86
[ p_ " *Right click on table header to see FilterDropdownMenu"
69
-
70
87
, example $
71
88
column
72
89
{ style: css { alignSelf: " stretch" , height: 150 , width: 400 }
@@ -141,6 +158,7 @@ docs = unit # make component { initialState, render }
141
158
]
142
159
}
143
160
161
+ , p_ " *Does not include FilterDropdownMenu"
144
162
, example $
145
163
column
146
164
{ style: css { alignSelf: " stretch" }
@@ -184,6 +202,78 @@ docs = unit # make component { initialState, render }
184
202
}
185
203
]
186
204
}
205
+
206
+ , p_ " *Non selectable variant w/ inputs & selects"
207
+ , example $
208
+ column
209
+ { style: css { alignSelf: " stretch" }
210
+ , children:
211
+ [ table
212
+ { name: " Items"
213
+ , dropdownMenu: true
214
+ , sortable: true
215
+ , sort: notNull self.state.sort
216
+ , sortBy: toNullable self.state.sortBy
217
+ , updateSort: mkEffectFn2 \sort sortBy -> do
218
+ self.setState _ { sort = sort, sortBy = toMaybe sortBy }
219
+ , selectable: false
220
+ , selected: null
221
+ , onSelect: mkEffectFn1 \selected -> self.setState _ { selected = selected }
222
+ , rows: (if self.state.sort == SortString " desc" then Array .reverse else identity)
223
+ let tableFieldSort = comparing \row -> do
224
+ ColumnName sortByCol <- self.state.sortBy
225
+ case runExcept $ readString =<< readProp sortByCol (unsafeToForeign row) of
226
+ Right value -> Just value
227
+ _ -> Nothing
228
+ in Array .sortBy tableFieldSort tableData
229
+ , getRowKey: _.id
230
+ , rowEq: eq
231
+ , onNavigate: mkEffectFn1 \href ->
232
+ log $ " navigate to: " <> un URL href
233
+ , variant: notNull " compact"
234
+ , primaryColumn: notNull
235
+ { name: ColumnName " product-title"
236
+ , label: notNull " Items"
237
+ , filterLabel: notNull " Product title"
238
+ , sortBy: null
239
+ , style: css {}
240
+ , getLink: _.link
241
+ , renderCell: R .text <<< _.title
242
+ , sticky: false
243
+ }
244
+ , columns:
245
+ Array .concat
246
+ [ self.state.ex2Columns
247
+ , self.state.ex3Columns
248
+ , [ { required: true
249
+ , name: ColumnName " select"
250
+ , label: notNull " Select"
251
+ , filterLabel: null
252
+ , sortBy: null
253
+ , style: css {}
254
+ , hidden: false
255
+ , sticky: false
256
+ , renderCell: \rowData ->
257
+ nativeSelect defaults
258
+ { options =
259
+ [ { label: " Select your car..." , value: " " }
260
+ , { label: " Volvo" , value: " volvo" }
261
+ , { label: " Saab" , value: " saab" }
262
+ , { label: " Mercedes" , value: " mercedes" }
263
+ , { label: " Audi" , value: " audi" }
264
+ ]
265
+ , onChange = handler targetValue \value ->
266
+ self.setState _ { selectedOption = fromMaybe " " value }
267
+ , value = self.state.selectedOption
268
+ }
269
+ }
270
+ ]
271
+ ]
272
+ , onColumnChange: notNull $ mkEffectFn1 \columns ->
273
+ self.setState _ { ex2Columns = columns }
274
+ }
275
+ ]
276
+ }
187
277
]
188
278
189
279
tableData =
0 commit comments