-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(website): Add tree without depth in documentation pages.
- Loading branch information
Showing
3 changed files
with
102 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
website/src/jsMain/kotlin/io/github/ayfri/kore/website/components/doc/DocTree.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package io.github.ayfri.kore.website.components.doc | ||
|
||
import androidx.compose.runtime.Composable | ||
import com.varabyte.kobweb.compose.css.ListStyleType | ||
import com.varabyte.kobweb.compose.css.listStyle | ||
import com.varabyte.kobweb.core.rememberPageContext | ||
import io.github.ayfri.kore.website.GlobalStyle | ||
import io.github.ayfri.kore.website.docEntries | ||
import io.github.ayfri.kore.website.utils.A | ||
import io.github.ayfri.kore.website.utils.transition | ||
import org.jetbrains.compose.web.css.* | ||
import org.jetbrains.compose.web.dom.Li | ||
import org.jetbrains.compose.web.dom.Ul | ||
|
||
@Composable | ||
fun Entry(article: DocArticle, selected: Boolean = false) { | ||
A(article.path, article.navTitle) { | ||
classes(DocTreeStyle.entry) | ||
if (selected) classes(DocTreeStyle.selected) | ||
} | ||
} | ||
|
||
@Composable | ||
fun DocTree() { | ||
Style(DocTreeStyle) | ||
|
||
val context = rememberPageContext().route | ||
val entries = docEntries | ||
val currentURL = context.path | ||
|
||
Ul({ | ||
classes(DocTreeStyle.list) | ||
}) { | ||
Li { | ||
entries.forEach { entry -> | ||
Entry(entry, entry.path == currentURL) | ||
} | ||
} | ||
} | ||
} | ||
|
||
object DocTreeStyle : StyleSheet() { | ||
val list by style { | ||
listStyle(ListStyleType.None) | ||
padding(0.8.cssRem) | ||
marginRight(1.cssRem) | ||
|
||
height(100.vh) | ||
position(Position.Sticky) | ||
top(0.px) | ||
left(0.px) | ||
} | ||
|
||
val entry by style { | ||
padding(0.5.cssRem) | ||
|
||
borderRadius(GlobalStyle.roundingButton) | ||
color(GlobalStyle.textColor) | ||
fontSize(1.2.cssRem) | ||
|
||
transition(0.2.s, "background-color") | ||
|
||
self + hover style { | ||
backgroundColor(GlobalStyle.tertiaryBackgroundColor) | ||
} | ||
} | ||
|
||
val selected by style { | ||
color(GlobalStyle.linkColor) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters