Skip to content

Commit

Permalink
feat(theme): add NavScreen component
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Feb 9, 2022
1 parent e93d3e5 commit b5cf33c
Show file tree
Hide file tree
Showing 15 changed files with 324 additions and 72 deletions.
2 changes: 2 additions & 0 deletions packages/theme/package.json
Expand Up @@ -44,6 +44,7 @@
"@mr-hope/vuepress-plugin-components": "2.0.0-alpha.15",
"@mr-hope/vuepress-shared": "2.0.0-alpha.15",
"@types/bcryptjs": "^2.4.2",
"@types/body-scroll-lock": "^3.1.0",
"@types/lodash.throttle": "^4.1.6",
"@vuepress/client": "2.0.0-beta.35",
"@vuepress/core": "2.0.0-beta.35",
Expand All @@ -59,6 +60,7 @@
"@vuepress/utils": "2.0.0-beta.35",
"@vueuse/core": "^7.6.0",
"bcryptjs": "^2.4.3",
"body-scroll-lock": "^3.1.5",
"lodash.throttle": "^4.1.1",
"vue": "^3.2.30",
"vue-router": "^4.0.12",
Expand Down
13 changes: 12 additions & 1 deletion packages/theme/src/client/module/navbar/components/NavActions.ts
Expand Up @@ -3,6 +3,7 @@ import { defineComponent, h, resolveComponent } from "vue";
import LanguageDropdown from "@theme-hope/module/navbar/components/LanguageDropdown";
import RepoLink from "@theme-hope/module/navbar/components/RepoLink";
import OutlookButton from "@theme-hope/module/navbar/components/OutlookButton";
import ToggleNavbarButton from "@theme-hope/module/navbar/components/ToggleNavbarButton";

import type { VNode } from "vue";

Expand All @@ -11,14 +12,24 @@ import "../styles/navbar-actions.scss";
export default defineComponent({
name: "NavActions",

setup(_props, { slots }) {
props: {
showScreen: { type: Boolean, default: false },
},

emits: ["toggleScreen"],

setup(props, { emit, slots }) {
return (): VNode | null =>
h("div", { class: "nav-actions-wrapper" }, [
slots.before?.(),
h("div", { class: ["nav-item"] }, h(LanguageDropdown)),
h("div", { class: ["nav-item"] }, h(RepoLink)),
h(OutlookButton),
h(resolveComponent("NavbarSearch")),
h(ToggleNavbarButton, {
active: props.showScreen,
onToggle: () => emit("toggleScreen"),
}),
slots.after?.(),
]);
},
Expand Down
43 changes: 43 additions & 0 deletions packages/theme/src/client/module/navbar/components/NavScreen.ts
@@ -0,0 +1,43 @@
import { disableBodyScroll, clearAllBodyScrollLocks } from "body-scroll-lock";
import { Transition, defineComponent, h, ref } from "vue";

import NavScreenLinks from "@theme-hope/module/navbar/components/NavScreenLinks";

import type { VNode } from "vue";

import "../styles/nav-screen.scss";

export default defineComponent({
name: "NavScreen",

props: {
active: {
type: Boolean,
default: false,
},
},

setup(props) {
const screen = ref<HTMLElement>();

return (): VNode =>
h(
Transition,
{
name: "fade",
onEnter: () =>
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
disableBodyScroll(screen.value!, { reserveScrollBarGap: true }),
onAfterLeave: () => clearAllBodyScrollLocks(),
},
() =>
props.active
? h(
"div",
{ class: "nav-screen", ref: screen },
h("div", { class: "container" }, [h(NavScreenLinks)])
)
: null
);
},
});
Expand Up @@ -10,10 +10,10 @@ import type {
HopeThemeNavGroup,
} from "../../../../shared";

import "../styles/dropdown-link.scss";
import "../styles/nav-screen-dropdown.scss";

export default defineComponent({
name: "SidebarDropdownLink",
name: "NavScreenDropdown",

props: {
config: {
Expand Down Expand Up @@ -49,7 +49,7 @@ export default defineComponent({
h(
"button",
{
class: "mobile-dropdown-title",
class: "nav-screen-dropdown-title",
type: "button",
ariaLabel: dropdownAriaLabel.value,
onClick: () => {
Expand All @@ -72,7 +72,7 @@ export default defineComponent({
h(
"ul",
{
class: ["mobile-nav-dropdown", { hide: !open.value }],
class: ["nav-screen-dropdown", { hide: !open.value }],
},
config.value.children.map((child) =>
h(
Expand Down
@@ -1,15 +1,15 @@
import { defineComponent, h } from "vue";

import AutoLink from "@theme-hope/components/AutoLink";
import SidebarDropdownLink from "@theme-hope/module/sidebar/components/SidebarDropdownLink";
import NavScreenDropdown from "@theme-hope/module/navbar/components/NavScreenDropdown";
import { useNavbarConfig } from "@theme-hope/module/navbar/composables";

import type { VNode } from "vue";

import "../styles/nav-links.scss";
import "../styles/nav-screen-links.scss";

export default defineComponent({
name: "SidebarNavLinks",
name: "NavScreenLinks",

setup() {
const navbarConfig = useNavbarConfig();
Expand All @@ -18,13 +18,13 @@ export default defineComponent({
navbarConfig.value.length
? h(
"nav",
{ class: "sidebar-nav-links" },
{ class: "nav-screen-links" },
navbarConfig.value.map((config) =>
h(
"div",
{ class: "navbar-links-item" },
"children" in config
? h(SidebarDropdownLink, { config })
? h(NavScreenDropdown, { config })
: h(AutoLink, { config })
)
)
Expand Down
15 changes: 12 additions & 3 deletions packages/theme/src/client/module/navbar/components/Navbar.ts
Expand Up @@ -12,6 +12,7 @@ import NavbarBrand from "@theme-hope/module/navbar/components/NavbarBrand";
import NavbarLinks from "@theme-hope/module/navbar/components/NavbarLinks";
import ToggleSidebarButton from "@theme-hope/module/navbar/components/ToggleSidebarButton";
import NavActions from "@theme-hope/module/navbar/components/NavActions";
import NavScreen from "@theme-hope/module/navbar/components/NavScreen";

import type { VNode } from "vue";

Expand Down Expand Up @@ -47,6 +48,7 @@ export default defineComponent({
const themeLocaleData = useThemeLocaleData();

const isMobile = ref(false);
const showScreen = ref(false);

const navbar = ref<HTMLElement>();
const siteBrand = ref<HTMLElement>();
Expand Down Expand Up @@ -110,7 +112,7 @@ export default defineComponent({
);
});

return (): VNode =>
return (): VNode[] => [
h(
"header",
{
Expand All @@ -125,8 +127,15 @@ export default defineComponent({
h(NavbarLinks, {
style: linksWrapperStyle.value,
}),
h(NavActions),
h(NavActions, {
showScreen: showScreen.value,
onToggleScreen: () => {
showScreen.value = !showScreen.value;
},
}),
]
);
),
h(NavScreen, { active: showScreen.value }),
];
},
});
@@ -0,0 +1,37 @@
import { defineComponent, h } from "vue";

import type { VNode } from "vue";

import "../styles/toggle-navbar-button.scss";

export default defineComponent({
name: "ToggleNavbarButton",

props: {
active: {
type: Boolean,
default: false,
},
},

emits: ["toggle"],

setup(props, { emit }) {
return (): VNode =>
h(
"button",
{
class: ["toggle-navbar-button", { "is-active": props.active }],
"aria-label": "Toggle Navbar",
"aria-expanded": props.active,
"aria-controls": "VPNavScreen",
onClick: () => emit("toggle"),
},
h("span", { class: "button-container" }, [
h("span", { class: "button-top" }),
h("span", { class: "button-middle" }),
h("span", { class: "button-bottom" }),
])
);
},
});
@@ -1,13 +1,16 @@
@use "@mr-hope/vuepress-shared/styles/reset";
@use "@mr-hope/vuepress-shared/styles/arrow";

.mobile-dropdown-title {
.nav-screen-dropdown-title {
@include reset.button;

width: 100%;
padding: 0;

color: var(--text-color);
font-family: inherit;
font-size: inherit;
text-align: left;
cursor: pointer;

display: flex;
Expand All @@ -17,12 +20,16 @@
color: var(--theme-color);
}

.title {
flex: 1;
}

.arrow {
@include arrow.arrow;
}
}

.mobile-nav-dropdown {
.nav-screen-dropdown {
margin: 0.5rem 0 0;
padding: 0;
list-style: none;
Expand All @@ -44,9 +51,12 @@

.dropdown-subtitle {
margin: 0;
padding-left: 1.25rem;
font-size: 15px;
line-height: 1.7;
padding-left: 0.25rem;
color: var(--dark-grey);
font-size: 0.75rem;
font-weight: bold;
line-height: 2;
text-transform: uppercase;

.nav-link {
padding: 0;
Expand All @@ -57,14 +67,24 @@
}
}

.dropdown-subitem-wrapper {
margin: 0;
padding: 0;
list-style: none;
}

.dropdown-subitem {
padding-left: 0.5rem;
font-size: 0.9em;
}

.nav-link {
display: block;
position: relative;
margin-bottom: 0;
padding: 0 1.5rem 0 1.25rem;
border-bottom: none;
padding-left: 0.5rem;
font-size: 14px;
font-weight: 400;
line-height: 1.7rem;
line-height: 2rem;

&:hover {
color: var(--theme-color);
Expand All @@ -86,20 +106,4 @@
}
}
}

& > .nav-link {
font-size: 15px;
line-height: 2rem;
}

.dropdown-subitem-wrapper {
margin: 0;
padding: 0;
list-style: none;
}

.dropdown-subitem {
font-size: 0.9em;
padding-left: 0.5rem;
}
}
@@ -0,0 +1,29 @@
.nav-screen-links {
display: none;
padding-bottom: 0.75rem;

@media (max-width: hope-config.$mobile) {
display: block;
}

.navbar-links-item {
position: relative;
display: block;
padding: 12px 4px 11px 0;
font-size: 16px;
line-height: 1.5rem;
border-bottom: 1px solid var(--border-color);

transition: border-bottom-color var(--color-transition);
}

.nav-link {
color: var(--text-color);
font-weight: normal;

&:hover,
&.active {
color: var(--theme-color);
}
}
}

0 comments on commit b5cf33c

Please sign in to comment.