Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vjp/tree checkable #104

Merged
merged 2 commits into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "purescript-ocelot",
"version": "0.17.0",
"version": "0.18.0",
"private": true,
"scripts": {
"build-all": "yarn run build-ui && yarn run build-css",
Expand Down
22 changes: 15 additions & 7 deletions src/Components/Tree/Component.purs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import Effect.Aff.Class (class MonadAff)
import Halogen as H
import Halogen.HTML as HH
import Halogen.HTML.Events as HE
import Halogen.HTML.Properties (checked) as HP
import Halogen.HTML.Properties as HP
import Ocelot.Block.Checkbox as Checkbox
import Ocelot.Block.Conditional as Conditional
import Ocelot.Block.Icon as Icon
import Ocelot.Data.Tree (ItemPath, Node(..), IndexPath, _expanded, _selected, _children)
import Ocelot.HTML.Properties (css)
Expand All @@ -25,6 +26,7 @@ type State item =
{ items :: Array (Node item)
, initial :: Array (Node item)
, renderItem :: item -> HH.PlainHTML
, checkable :: item -> Boolean
}

data Query item a
Expand All @@ -34,7 +36,9 @@ data Query item a
| SetSelections (Array (ItemPath item)) a

type Input item =
{ renderItem :: item -> HH.PlainHTML }
{ renderItem :: item -> HH.PlainHTML
, checkable :: item -> Boolean
}

data Message item
= ItemAdded item (ItemPath item)
Expand All @@ -53,10 +57,11 @@ component =
, receiver: const Nothing
}
where
initialState { renderItem } =
initialState { renderItem, checkable } =
{ items: []
, initial: []
, renderItem
, checkable
}

eval :: Query item ~> H.ComponentDSL (State item) (Query item) (Message item) m
Expand Down Expand Up @@ -89,7 +94,7 @@ component =
pure a

render :: State item -> H.ComponentHTML (Query item)
render { items, renderItem } =
render { items, renderItem, checkable } =
HH.div_ $ A.concat $ A.mapWithIndex (renderRow 0 [] []) items
where
renderRow depth indexPath itemPath ix (Node { selected, expanded, children, value }) =
Expand All @@ -98,9 +103,12 @@ component =
[ renderCarat children expanded (A.cons ix indexPath)
, HH.div
[ css "inline-flex" ]
[ Checkbox.checkbox_
[ HE.onChecked $ HE.input $ ToggleItem value itemPath (A.cons ix indexPath)
, HP.checked selected
[ Conditional.alt_ (checkable value)
[ Checkbox.checkbox_
[ HE.onChecked $ HE.input $ ToggleItem value itemPath (A.cons ix indexPath)
, HP.checked selected
]
[ HH.fromPlainHTML $ renderItem value ]
]
[ HH.fromPlainHTML $ renderItem value ]
]
Expand Down