@@ -5,7 +5,7 @@ import Prelude
55import Control.Monad.Except (runExcept )
66import Data.Array as Array
77import Data.Either (Either (..))
8- import Data.Maybe (Maybe (..))
8+ import Data.Maybe (Maybe (..), fromMaybe )
99import Data.Newtype (un )
1010import Data.Nullable (notNull , null , toMaybe , toNullable )
1111import Effect.Console (log )
@@ -14,15 +14,19 @@ import Foreign (readString, unsafeToForeign)
1414import Foreign.Index (readProp )
1515import Lumi.Components.Column (column , column_ )
1616import Lumi.Components.Images (productThumb_ )
17+ import Lumi.Components.Input (input , text_ )
1718import Lumi.Components.Link as Link
1819import Lumi.Components.Lockup (lockup )
20+ import Lumi.Components.NativeSelect (defaults , nativeSelect )
1921import Lumi.Components.Size (Size (..))
2022import Lumi.Components.Table (ColumnName (..), SortString (..), table )
2123import Lumi.Components.Text (p_ )
2224import Lumi.Components.Example (example )
2325import React.Basic (Component , JSX , createComponent , make )
2426import React.Basic.DOM (css )
2527import React.Basic.DOM as R
28+ import React.Basic.DOM.Events (targetValue )
29+ import React.Basic.Events (handler )
2630import Web.HTML.History (URL (..))
2731
2832component :: Component Unit
@@ -35,6 +39,7 @@ docs = unit # make component { initialState, render }
3539 { sort: SortString " asc"
3640 , sortBy: Just (ColumnName " createdDate" )
3741 , selected: [" 10cms9" , " 0mf7w" ]
42+ , selectedOption: " "
3843 , ex2Columns:
3944 [ { required: true
4045 , name: ColumnName " product-type"
@@ -61,12 +66,24 @@ docs = unit # make component { initialState, render }
6166 , renderCell: \rowData -> R .text rowData.createdDate
6267 }
6368 ]
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+ ]
6482 }
6583
6684 render self =
6785 column_
6886 [ p_ " *Right click on table header to see FilterDropdownMenu"
69-
7087 , example $
7188 column
7289 { style: css { alignSelf: " stretch" , height: 150 , width: 400 }
@@ -141,6 +158,7 @@ docs = unit # make component { initialState, render }
141158 ]
142159 }
143160
161+ , p_ " *Does not include FilterDropdownMenu"
144162 , example $
145163 column
146164 { style: css { alignSelf: " stretch" }
@@ -184,6 +202,78 @@ docs = unit # make component { initialState, render }
184202 }
185203 ]
186204 }
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+ }
187277 ]
188278
189279 tableData =
0 commit comments