@@ -64,8 +64,9 @@ import OEQ.Utils.Interop (nullAny)
64
64
import Partial.Unsafe (unsafePartial )
65
65
import React (Children , ReactClass , ReactElement , ReactThis , childrenToArray , createElement )
66
66
import React as R
67
- import React.DOM (div' , footer , span' , text )
67
+ import React.DOM (div' , footer , img , span' , text )
68
68
import React.DOM as D
69
+ import React.DOM.Props (src )
69
70
import React.DOM.Props as DP
70
71
import Web.DOM.DOMTokenList as DOMTokens
71
72
import Web.DOM.Document (documentElement )
@@ -78,7 +79,13 @@ import Web.HTML.HTMLElement as HTML
78
79
import Web.HTML.Window (document , toEventTarget )
79
80
80
81
newtype ExternalHref = ExternalHref String
81
- newtype MenuItem = MenuItem { route :: Either ExternalHref String , title :: String , systemIcon :: Maybe String }
82
+ newtype MenuItem = MenuItem {
83
+ route :: Either ExternalHref String ,
84
+ title :: String ,
85
+ systemIcon :: Maybe String ,
86
+ iconUrl :: Maybe String ,
87
+ newWindow :: Boolean
88
+ }
82
89
83
90
data Command = Init | AttemptRoute Route | NavAway Boolean
84
91
| ToggleMenu | UserMenuAnchor (Maybe HTMLElement ) | MenuClick Route | GoBack | CloseError
@@ -330,15 +337,17 @@ templateClass = withStyles ourStyles $ R.component "Template" $ \this -> do
330
337
where
331
338
logoSrc = logoPath
332
339
group items = [list {component: " nav" } (navItem <$> items)]
333
- navItem (MenuItem {title,systemIcon,route}) = linkProps
340
+ navItem (MenuItem {title,systemIcon,route,iconUrl,newWindow }) = linkProps
334
341
[
335
- listItemIcon_ $ icon {color: inherit} [ D .text $ fromMaybe " folder" $ systemIcon ],
342
+ listItemIcon_ $ case iconUrl of
343
+ Just url -> img [src url]
344
+ Nothing -> icon {color: inherit} [ D .text $ fromMaybe " folder" $ systemIcon ],
336
345
listItemText' {disableTypography: true , primary: typography {variant: subheading, component: " div" } [text title] }
337
346
]
338
347
where
339
348
linkProps = case route of
340
349
Right r | Just m <- routeHref <$> matchRoute r -> RMUI .listItem { component: " a" , href: m.href, onClick: m.onClick }
341
- Left (ExternalHref href) -> RMUI .listItem { component: " a" , href }
350
+ Left (ExternalHref href) -> RMUI .listItem { component: " a" , href, target: if newWindow then " _blank " else " " }
342
351
Right r -> RMUI .listItem {component: " a" , href: show r}
343
352
344
353
htmlElement :: Effect HTMLElement
@@ -561,7 +570,9 @@ instance decodeMI :: DecodeJson MenuItem where
561
570
_ -> Right " home.do"
562
571
title <- o .? " title"
563
572
systemIcon <- o .?? " systemIcon"
564
- pure $ MenuItem {title, route, systemIcon}
573
+ iconUrl <- o .?? " iconUrl"
574
+ newWindow <- o .? " newWindow"
575
+ pure $ MenuItem {title, route, systemIcon, iconUrl, newWindow}
565
576
566
577
decodeCounts :: Json -> Either String Counts
567
578
decodeCounts v = do
0 commit comments