Skip to content

Commit

Permalink
Remove Subtree sections, all collapse all button (#2213)
Browse files Browse the repository at this point in the history
- Resolves #2198

<img width="700" alt="Screenshot 2023-06-20 at 14 09 21"
src="https://github.com/anoma/juvix/assets/8126674/f5ebb89e-5f2a-41fe-8495-13b1ec4aea02">
  • Loading branch information
vrom911 authored Jun 23, 2023
1 parent f77e055 commit 9840878
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 12 deletions.
23 changes: 23 additions & 0 deletions assets/css/linuwial.css
Original file line number Diff line number Diff line change
Expand Up @@ -883,3 +883,26 @@ p.directory {
}

/* @end */

/* Styles for the toggle button */
.toggle-button {
display: inline-block;
padding: 5px 10px;
background-color: #D84E53;
color: #fff;
border: none;
cursor: pointer;
width: 165px;
text-align: left;
}

.toggle-button:hover {
background-color: #803353;
}

/* Styles for the toggle icon */
.toggle-icon {
display: inline-block;
margin-right: 5px;
font-weight: bold;
}
18 changes: 18 additions & 0 deletions assets/js/toggle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function toggle() {
const toggleAllButton = document.getElementById('toggle-all-button');
if (toggleAllButton.classList.contains('opened')) {
document.getElementById('toggle-button-text').textContent =
'▶ Expand all modules';
toggleAllButton.classList.remove('opened');
document.body
.querySelectorAll('details')
.forEach((detail) => detail.removeAttribute('open'));
} else {
document.getElementById('toggle-button-text').textContent =
'▼ Hide all modules';
toggleAllButton.classList.add('opened');
document.body
.querySelectorAll('details')
.forEach((detail) => detail.setAttribute('open', ''));
}
}
3 changes: 3 additions & 0 deletions src/Juvix/Compiler/Backend/Html/Extra.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ jsLink js = do
! Attr.type_ "text/javascript"
$ mempty

toggleJs :: (Members '[Reader HtmlOptions] r) => Sem r Html
toggleJs = jsLink "toggle.js"

linuwialCss :: (Members '[Reader HtmlOptions] r) => Sem r Html
linuwialCss = cssLink "linuwial.css"

Expand Down
31 changes: 19 additions & 12 deletions src/Juvix/Compiler/Backend/Html/Translation/FromTyped.hs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ createIndexFile ps = do
Html.div ! Attr.id "content" $
Html.div ! Attr.id "module-list" $
(p ! Attr.class_ "caption" $ "Modules")
<> ( button
! Attr.id "toggle-all-button"
! Attr.class_ "toggle-button opened"
! Attr.onclick "toggle()"
$ Html.span
! Attr.id "toggle-button-text"
! Attr.class_ "toggle-icon"
$ "▼ Hide all modules"
)
<> tree'

tree :: ModuleTree
Expand All @@ -106,7 +115,7 @@ createIndexFile ps = do
nodeRow = case lbl of
Nothing ->
return $
Html.p ! Attr.class_ attrBare $
Html.span ! Attr.class_ attrBare $
toHtml (prettyText s)
Just lbl' -> do
lnk <- nameIdAttrRef lbl' Nothing
Expand All @@ -121,21 +130,17 @@ createIndexFile ps = do
attrBare = attrBase <> " directory"

node :: Sem r Html
node = do
row' <- nodeRow
childs' <- childs
return (row' <>? childs')
node = nodeRow >>= getRowWithChilds
where
childs :: Sem r (Maybe Html)
childs
| null children = return Nothing
getRowWithChilds :: Html -> Sem r Html
getRowWithChilds row'
| null children = return row'
| otherwise = do
c' <- mapM (uncurry goChild) (HashMap.toList children)
return $
Just $
details ! Attr.open "open" $
summary "Subtree"
<> ul (mconcatMap li c')
details ! Attr.open "open" $
summary row'
<> ul (mconcatMap li c')

writeHtml :: (Members '[Embed IO] r) => Path Abs File -> Html -> Sem r ()
writeHtml f h = Prelude.embed $ do
Expand Down Expand Up @@ -209,6 +214,7 @@ template rightMenu' content' = do
mathJax <- mathJaxCdn
ayuTheme <- ayuCss
judocTheme <- linuwialCss
toggle <- toggleJs
let mhead :: Html
mhead =
Html.head $
Expand All @@ -223,6 +229,7 @@ template rightMenu' content' = do
<> livejs
<> ayuTheme
<> judocTheme
<> toggle

titleStr :: Html
titleStr = "Juvix Documentation"
Expand Down

0 comments on commit 9840878

Please sign in to comment.