Skip to content

Commit 8c4b82c

Browse files
Allow for dropdownMenu entries to be disabled (#140)
1 parent 8df6e77 commit 8c4b82c

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

docs/Examples/DropdownButton.example.purs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ docs =
143143
dropdownMenu dropdownMenuDefaults
144144
{ label = "Dropdown Menu"
145145
, items =
146-
[ [ { label: "Export all results to CSV", action: log "hello" }
147-
, { label: "Export selected results to CSV", action: log "hola" }
148-
, { label: "Assign manager", action: log "bonjour" }
146+
[ [ { label: "Export all results to CSV", action: Just $ log "hello" }
147+
, { label: "Export selected results to CSV", action: Just $ log "hola" }
148+
, { label: "Assign manager", action: Nothing }
149149
]
150-
, [ { label: "Archive", action: log "olá" }
150+
, [ { label: "Archive", action: Just $ log "olá" }
151151
]
152152
]
153153
}
@@ -156,11 +156,11 @@ docs =
156156
{ label = "Dropdown Menu (right)"
157157
, alignment = toNullable (Just "right")
158158
, items =
159-
[ [ { label: "Export all results to CSV", action: log "hello" }
160-
, { label: "Export selected results to CSV", action: log "hola" }
161-
, { label: "Assign manager", action: log "bonjour" }
159+
[ [ { label: "Export all results to CSV", action: Just $ log "hello" }
160+
, { label: "Export selected results to CSV", action: Just $ log "hola" }
161+
, { label: "Assign manager", action: Nothing }
162162
]
163-
, [ { label: "Archive", action: log "olá" }
163+
, [ { label: "Archive", action: Just $ log "olá" }
164164
]
165165
]
166166
}
@@ -194,9 +194,9 @@ docs =
194194
, dropdownMenu dropdownMenuDefaults
195195
{ label = "Dropdown Menu"
196196
, items =
197-
[ [ { label: "Export all results to CSV", action: log "hello" }
198-
, { label: "Export selected results to CSV", action: log "hola" }
199-
, { label: "Assign manager", action: log "bonjour" }
197+
[ [ { label: "Export all results to CSV", action: Just $ log "hello" }
198+
, { label: "Export selected results to CSV", action: Just $ log "hola" }
199+
, { label: "Assign manager", action: Nothing }
200200
]
201201
]
202202
}

src/Lumi/Components/DropdownButton.purs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import Color (cssStringHSLA)
66
import Control.MonadZero (guard)
77
import Data.Foldable (fold, foldMap, intercalate)
88
import Data.Int (toNumber)
9-
import Data.Maybe (Maybe(..), fromMaybe, maybe)
9+
import Data.Maybe (Maybe(..), fromMaybe, isNothing, maybe)
10+
import Data.Monoid as Monoid
1011
import Data.Nullable (Nullable, toMaybe, toNullable)
12+
import Data.Traversable (for_)
1113
import Effect (Effect)
1214
import Effect.Uncurried (EffectFn2, runEffectFn2)
1315
import JSS (JSS, jss)
@@ -195,7 +197,7 @@ type DropdownMenuProps =
195197
, items ::
196198
Array (Array
197199
{ label :: String
198-
, action :: Effect Unit
200+
, action :: Maybe (Effect Unit)
199201
})
200202
}
201203

@@ -215,9 +217,14 @@ dropdownMenu = makeStateless dropdownMenuComponent render where
215217
fromItems xs =
216218
column_ $ xs <#> \item ->
217219
Link.link Link.defaults
218-
{ className = pure "lumi-dropdown-menu-item"
220+
{ className = pure $ fold
221+
[ "lumi-dropdown-menu-item"
222+
, Monoid.guard (isNothing item.action) " disabled"
223+
]
219224
, text = p_ item.label
220-
, navigate = pure $ closeSelf *> item.action
225+
, navigate = pure $ for_ item.action \action -> do
226+
closeSelf
227+
action
221228
}
222229
in
223230
fragment [ intercalate divider_ (map fromItems items) ]
@@ -343,7 +350,10 @@ styles = jss
343350
, whiteSpace: "nowrap"
344351
, color: cssStringHSLA colors.black
345352
, textDecoration: "none"
346-
, "&:hover":
353+
, "&.disabled":
354+
{ color: cssStringHSLA colors.black1
355+
}
356+
, "&:not(.disabled):hover":
347357
{ backgroundColor: cssStringHSLA colors.black7
348358
}
349359
}

0 commit comments

Comments
 (0)