/
Picker.purs
55 lines (46 loc) · 1.61 KB
/
Picker.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
-- | See [Picker](https://facebook.github.io/react-native/docs/picker.html)
module ReactNative.Components.Picker (
PickerProps, PickerMode, PickerItem, picker, picker', pickerItem
, class PickerType
) where
import Prelude
import ReactNative.Optional (class Optional)
import React (ReactElement)
import ReactNative.Components.View (ViewPropsEx)
import ReactNative.Events (EventHandler)
import ReactNative.Styles (Styles)
import ReactNative.Unsafe.ApplyProps (unsafeApplyProps)
import ReactNative.Unsafe.Components (pickerItemU, pickerU)
import Unsafe.Coerce (unsafeCoerce)
type PickerProps a eff = ViewPropsEx eff (
onValueChange :: EventHandler eff a
, selectedValue :: a
) (
enabled :: Boolean
, mode :: PickerMode
, prompt :: String
) (
itemStyle :: Styles
)
picker :: forall a eff. PickerType a => a -> EventHandler eff a -> Array PickerItem -> ReactElement
picker selectedValue onValueChange items = pickerU {selectedValue, onValueChange} (unsafeCoerce items)
picker' :: forall a eff o
. PickerType a
=> Optional o (PickerProps a eff)
=> {|o} -> Array PickerItem -> ReactElement
picker' p items = pickerU (unsafeApplyProps p) $ unsafeCoerce items
pickerItem :: forall a. PickerType a => String -> a -> PickerItem
pickerItem label value = PickerItem $ pickerItemU {label,value}
newtype PickerItem = PickerItem ReactElement
class PickerType a
instance intPicker :: PickerType Int
instance stringPicker :: PickerType String
newtype PickerMode = PickerMode String
pickerMode :: {
dialog :: PickerMode
, dropdown :: PickerMode
}
pickerMode = {
dialog: PickerMode "dialog"
, dropdown: PickerMode "dropdown"
}