Skip to content

Commit

Permalink
feat: move modern template icons location to menu bar (#8613)
Browse files Browse the repository at this point in the history
  • Loading branch information
yufeih authored Apr 11, 2023
1 parent 9d98b44 commit 85235a2
Show file tree
Hide file tree
Showing 47 changed files with 342 additions and 282 deletions.
16 changes: 10 additions & 6 deletions templates/modern/layout/_master.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,18 @@
<img id="logo" class="svg" src="{{_rel}}{{{_appLogoPath}}}{{^_appLogoPath}}logo.svg{{/_appLogoPath}}" alt="{{_appName}}" >
{{_appName}}
</a>
<button class="btn btn-lg d-md-none border-0" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
<button class="btn btn-lg d-md-none border-0" type="button" data-bs-toggle="collapse" data-bs-target="#navpanel" aria-controls="navpanel" aria-expanded="false" aria-label="Toggle navigation">
<i class="bi bi-three-dots"></i>
</button>
<div class="collapse navbar-collapse" id="navbar">
<form class="d-flex ms-auto" role="search" id="search">
<i class="bi bi-search"></i>
<input class="form-control" id="search-query" type="search" disabled placeholder="{{__global.search}}" autocomplete="off" aria-label="Search">
</form>
<div class="collapse navbar-collapse" id="navpanel">
<div id="navbar">
{{#_enableSearch}}
<form class="search" role="search" id="search">
<i class="bi bi-search"></i>
<input class="form-control" id="search-query" type="search" disabled placeholder="{{__global.search}}" autocomplete="off" aria-label="Search">
</form>
{{/_enableSearch}}
</div>
</div>
</div>
</nav>
Expand Down
6 changes: 4 additions & 2 deletions templates/modern/src/docfx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { highlight } from './highlight'
import { renderMarkdown } from './markdown'
import { enableSearch } from './search'
import { renderToc } from './toc'
import { renderBreadcrumb, renderFooter, renderInThisArticle, renderNavbar } from './nav'
import { initTheme } from './theme'
import { renderBreadcrumb, renderInThisArticle, renderNavbar } from './nav'

import 'bootstrap-icons/font/bootstrap-icons.scss'
import './docfx.scss'
Expand All @@ -24,10 +25,11 @@ declare global {

window.docfx = {}

initTheme()

document.addEventListener('DOMContentLoaded', function() {
enableSearch()
renderMarkdown()
renderFooter()
highlight()

Promise.all([renderNavbar(), renderToc()])
Expand Down
4 changes: 2 additions & 2 deletions templates/modern/src/layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ $main-padding-bottom: 4rem;
}

html {
width: 100vw;
width: calc(100vw - var(--scrollbar-width));
min-height: 100vh;
overflow-x: hidden;
}

body,
body[data-layout="landing"] {
width: 100vw;
width: calc(100vw - var(--scrollbar-width));
min-height: 100vh;
display: flex;
flex-direction: column;
Expand Down
51 changes: 44 additions & 7 deletions templates/modern/src/nav.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,54 @@
flex-wrap: nowrap;
}

form {
align-items: center;
#navbar {
display: flex;
flex: 1;

>i.bi {
form {
display: flex;
position: relative;
left: 1.8rem;
opacity: .5;
align-items: center;

>i.bi {
position: absolute;
left: .8rem;
opacity: .5;
}

>input {
padding-left: 2.5rem;
}

&.search {
order: 50;
}

&.icons {
margin-left: auto;
}
}
}

@include media-breakpoint-down(md) {
#navbar {
flex-direction: column;
align-items: flex-start;

>input {
padding-left: 2.5rem;
form {
margin: 1rem 0 0;

&.search {
align-self: stretch;
order: 30;
}

&.icons {
align-self: center;
order: 40;
margin: 1rem 0;
}
}
}
}
}
Expand Down
37 changes: 19 additions & 18 deletions templates/modern/src/nav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,30 @@ export async function renderNavbar(): Promise<NavItem[]> {

const activeItem = findActiveItem(navItems)
const navbar = document.getElementById('navbar')
if (navbar) {
const menu = html`
<ul class='navbar-nav'>${
navItems.map(item => {
const current = (item === activeItem ? 'page' : false)
const active = (item === activeItem ? 'active' : null)
return html`
<li class='nav-item'><a class='nav-link ${active}' aria-current=${current} href=${item.href}>${breakWordLit(item.name)}</a></li>`
})
}</ul>`

render(menu, navbar, { renderBefore: navbar.firstChild })
if (!navbar) {
return
}

return activeItem ? [activeItem] : []
}
const menu = html`
<ul class='navbar-nav'>${
navItems.map(item => {
const current = (item === activeItem ? 'page' : false)
const active = (item === activeItem ? 'active' : null)
return html`
<li class='nav-item'><a class='nav-link ${active}' aria-current=${current} href=${item.href}>${breakWordLit(item.name)}</a></li>`
})
}</ul>`

const icons = html`<form class="icons">${githubLink()} ${themePicker(renderCore)}</form>`

export function renderFooter() {
const footer = document.querySelector('footer>div') as HTMLElement
if (footer) {
render(html`${githubLink()} ${themePicker(renderFooter)}`, footer)
function renderCore() {
render(html`${menu} ${icons}`, navbar)
}

renderCore()

return activeItem ? [activeItem] : []

function githubLink() {
const docurl = meta('docfx:docurl')
const github = parseGitHubRepo(docurl)
Expand Down
8 changes: 4 additions & 4 deletions templates/modern/src/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { html } from 'lit-html'

type Theme = 'light' | 'dark' | 'auto'

setTheme(localStorage.getItem('theme') as Theme || 'auto')

function setTheme(theme: Theme) {
localStorage.setItem('theme', theme)
if (theme === 'auto') {
Expand All @@ -16,14 +14,16 @@ function setTheme(theme: Theme) {
}
}

export function initTheme() {
setTheme(localStorage.getItem('theme') as Theme || 'auto')
}

export function getTheme(): 'light' | 'dark' {
return document.documentElement.getAttribute('data-bs-theme') as 'light' | 'dark'
}

export function themePicker(refresh: () => void) {
const theme = localStorage.getItem('theme') as Theme || 'auto'
setTheme(theme)

const icon = theme === 'light' ? 'sun' : theme === 'dark' ? 'moon' : 'circle-half'

return html`
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 85235a2

Please sign in to comment.