Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 69b6b9b

Browse files
safarelicryogenian
authored andcommitted
Add BuiltInTheme type with IsForeign instance (#32)
* add BuiltInTheme type with IsForeign instance * add parseBuiltInTheme * format code
1 parent dd5db69 commit 69b6b9b

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

src/ECharts/Theme.purs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,53 @@ module ECharts.Theme
66
, roma
77
, shine
88
, vintage
9+
, BuiltInTheme(..)
10+
, parseBuiltInTheme
11+
, builtInToTheme
912
) where
1013

14+
import Prelude (($), (<>))
15+
import Data.Either (Either(..))
1116
import Data.Foreign (Foreign)
1217

13-
foreign import forceExport :: Foreign
18+
foreign import forceExport Foreign
1419

1520
data Theme = ByName String | FromObject Foreign
21+
data BuiltInTheme = Infographic | Macarons | Roma | Shine | Vintage | Dark
22+
23+
parseBuiltInTheme String Either String BuiltInTheme
24+
parseBuiltInTheme str = case str of
25+
"infographic"Right Infographic
26+
"macarons"Right Macarons
27+
"roma"Right Roma
28+
"shine"Right Shine
29+
"vintage"Right Vintage
30+
"dark"Right Dark
31+
_ → Left $ "`" <> str <> "` is not builtin theme"
32+
33+
builtInToTheme BuiltInTheme Theme
34+
builtInToTheme = case _ of
35+
InfographicByName "infographic"
36+
MacaronsByName "macarons"
37+
RomaByName "roma"
38+
ShineByName "shine"
39+
VintageByName "vintage"
40+
DarkByName "dark"
1641

1742
dark Theme
18-
dark = ByName "dark"
43+
dark = builtInToTheme Dark
1944

2045
infographic Theme
21-
infographic = ByName "infographic"
46+
infographic = builtInToTheme Infographic
2247

2348
macarons Theme
24-
macarons = ByName "macarons"
49+
macarons = builtInToTheme Macarons
2550

2651
roma Theme
27-
roma = ByName "roma"
52+
roma = builtInToTheme Roma
2853

2954
shine Theme
30-
shine = ByName "shine"
55+
shine = builtInToTheme Shine
3156

3257
vintage Theme
33-
vintage = ByName "vintage"
58+
vintage = builtInToTheme Vintage

0 commit comments

Comments
 (0)