-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTab.example.purs
87 lines (82 loc) · 3.47 KB
/
Tab.example.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
module Lumi.Components.Examples.Tab where
import Prelude
import Control.Alternative (guard)
import Data.Array (index, (..))
import Data.Maybe (Maybe(..), fromMaybe)
import Data.String (Pattern(..), split, toLower)
import Effect.Uncurried (runEffectFn1)
import Lumi.Components.Column (column_)
import Lumi.Components.Tab (TabId(..), TabKey(..), tabs, urlParts)
import Lumi.Components.Text (h2_)
import Lumi.Components.Utility.ReactRouter (RouterProps, withRouter)
import Lumi.Components.Example (example)
import React.Basic.Classic (Component, JSX, createComponent, element, empty, toReactComponent)
import React.Basic.DOM as R
import Web.HTML.History (URL(..))
component :: Component (RouterProps ())
component = createComponent "TabExample"
docs :: JSX
docs = flip element {} $ withRouter $ toReactComponent identity component { render: \{ props } -> render props }
where
render props =
column_
[ h2_ "Demo 1"
, example $
R.div
{ style: R.css { maxWidth: "800px" }
, children:
[ tabs
{ currentLocation: URL $ "#" <> props.location.pathname <> props.location.search <> props.location.hash
, useHash: true
, navigate: Just \url ->
let
parts = urlParts url
newUrl = parts.path <> parts.query <> parts.hash.path <> parts.hash.query
newUrlNoHash = fromMaybe "" $ flip index 1 $ split (Pattern "#") newUrl
in
runEffectFn1 props.history.push $ URL $ newUrlNoHash
, queryKey: TabKey "demo1"
, style: R.css {}
, tabStyle: R.css {}
, selectedTabStyle: R.css {}
, tabs: 1 .. 10 <#> \i ->
let
label = "Tab with a long title " <> show i
in
{ content: \_ -> empty
, id: TabId (toLower label)
, label
, count: (7*(i - 1) * (i - 1) `mod` 4) * 7 <$ guard (i `mod` 3 /= 1)
, testId: Nothing
}
}
]
}
, h2_ "Demo 2"
, example $
tabs
{ currentLocation: URL $ "#" <> props.location.pathname <> props.location.search <> props.location.hash
, useHash: true
, navigate: Just \url ->
let
parts = urlParts url
newUrl = parts.path <> parts.query <> parts.hash.path <> parts.hash.query
newUrlNoHash = fromMaybe "" $ flip index 1 $ split (Pattern "#") newUrl
in
runEffectFn1 props.history.push $ URL $ newUrlNoHash
, queryKey: TabKey "demo2"
, style: R.css {}
, tabStyle: R.css {}
, selectedTabStyle: R.css {}
, tabs: 1 .. 6 <#> \i ->
let
label = "Tab" <> show i
in
{ content: \_ -> empty
, id: TabId (toLower label)
, label
, count: (i `div` 2) <$ guard (i `mod` 4 == 1)
, testId: Nothing
}
}
]