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

[#3362] Sidebar on mobile #3379

Merged
merged 16 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from 12 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
47 changes: 30 additions & 17 deletions packages/docs/components/layout/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

<template #right>
<div
v-if="breakpoint.mdUp"
v-if="isOptionsListVisible"
class="header__options"
>
<va-button
Expand All @@ -56,7 +56,7 @@

<!-- options mobile menu -->
<va-button
v-if="breakpoint.smDown"
v-if="isOptionsMenuVisible"
:aria-label="$t('menu.openOptionsMenu')"
preset="plain"
@click="toggleOptions"
Expand Down Expand Up @@ -141,7 +141,7 @@
</template>

<script lang="ts" setup>
import { computed } from 'vue'
import { computed, ref } from 'vue'
import { useBreakpoint } from 'vuestic-ui'

import LanguageDropdown from './LanguageDropdown.vue'
Expand All @@ -155,8 +155,24 @@ import SocialsLinks from '../landing/SocialsLinks.vue'
import StarsButton from '../landing/StarsButton.vue'
import { useSharedLanguageSwitcher } from '@/composables/useLanguageSwitcher'

const props = defineProps({
isSidebarVisible: {
type: Boolean,
default: false,
},
isOptionsVisible: {
type: Boolean,
default: false,
},
})

const emit = defineEmits(['update:isSidebarVisible', 'update:isOptionsVisible'])

const { t, locale, locales, setLocale } = useSharedLanguageSwitcher()
const breakpoint = useBreakpoint()
const breakpoints = useBreakpoint()

const isOptionsMenuVisible = ref(false)
const isOptionsListVisible = ref(false)

const landing = computed(() => ({
text: t('menu.home'),
Expand All @@ -175,26 +191,23 @@ const links = computed(() => [
},
])

const props = defineProps({
isSidebarVisible: {
type: Boolean,
default: false,
},
isOptionsVisible: {
type: Boolean,
default: false,
},
})

const emit = defineEmits(['update:isSidebarVisible', 'update:isOptionsVisible'])

const toggleSidebar = () => {
emit('update:isSidebarVisible', !props.isSidebarVisible)
}

const toggleOptions = () => {
emit('update:isOptionsVisible', !props.isOptionsVisible)
}

watch(() => breakpoints.smDown, (newValue: boolean) => {
isOptionsMenuVisible.value = newValue
isOptionsListVisible.value = !newValue
})

onMounted(() => {
isOptionsMenuVisible.value = breakpoints.smDown
isOptionsListVisible.value = !breakpoints.smDown
})
</script>

<style lang="scss">
Expand Down
8 changes: 4 additions & 4 deletions packages/docs/components/layout/Sidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
v-for="(route, key) in navigationRoutes"
:key="key"
>
<template #header="{ value, hasKeyboardFocus }">
<template #header="{ value: isCollapsed, hasKeyboardFocus }">
<va-sidebar-item
class="sidebar__collapse-custom-header"
:class="{
Expand All @@ -21,7 +21,7 @@
}"
>
{{ t(route.displayName) }}
<va-icon :name="value ? 'va-arrow-up' : 'va-arrow-down'" />
<va-icon :name="isCollapsed ? 'va-arrow-up' : 'va-arrow-down'" />
</va-sidebar-item>
</template>
<div
Expand Down Expand Up @@ -66,7 +66,7 @@
</template>

<script lang="ts">
import { defineComponent, watch, ref, computed, PropType } from 'vue'
import { defineComponent, watch, ref, computed } from 'vue'
import { useRoute } from 'vue-router'
import { useI18n } from 'vue-i18n'

Expand Down Expand Up @@ -106,6 +106,7 @@ export default defineComponent({
visible: { type: Boolean, default: false },
mobile: { type: Boolean, default: false },
},
emits: ['update:visible'],
setup: (props, { emit }) => {
const i18n = useI18n()
const route = useRoute()
Expand Down Expand Up @@ -147,7 +148,6 @@ export default defineComponent({
return {
...i18n,
navigationRoutes: getSortedNavigationRoutes(navigationRoutes),
route,
getColor,
writableVisible,
sidebarWidth,
Expand Down
27 changes: 6 additions & 21 deletions packages/docs/components/layout/header/HeaderSelector.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<template>
<div
class="header-selector flex-center"
class="header-selector"
role="button"
tabindex="0"
:aria-label="`${minimized ? `expand` : `minimize`} navigation menu`"
:aria-label="`${minimized ? 'expand' : 'minimize'} navigation menu`"
@click="toggleSidebar"
@keydown.enter="toggleSidebar"
>
Expand Down Expand Up @@ -39,18 +39,17 @@ export default defineComponent({
props: {
minimized: {
type: Boolean,
required: true,
default: false,
RVitaly1978 marked this conversation as resolved.
Show resolved Hide resolved
},
},
emits: ['toggle-sidebar'],

setup (props, { emit }) {
const { getColors } = useColors()

const toggleSidebar = () => emit('toggleSidebar', !props.minimized)

return {
colors: computed(getColors),
toggleSidebar,
toggleSidebar: () => emit('toggle-sidebar', !props.minimized),
}
},
})
Expand All @@ -65,25 +64,11 @@ export default defineComponent({
width: 1.5rem;
}

.i-menu-expanded {
@extend .i-nav;

background: url("@/public/layout/menu-collapsed.svg") no-repeat center;
}

.i-menu-collapsed {
@extend .i-nav;

background: url("@/public/layout/menu-expanded.svg") no-repeat center;
}

.header-selector {
cursor: pointer;
max-width: 55px;

&:focus {
&:focus-visible {
@include focus-outline(2px, 2px, 2px);
}
}

</style>
26 changes: 12 additions & 14 deletions packages/docs/layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<aside class="docs-layout__sidebar">
<LayoutSidebar
v-model:visible="isSidebarVisible"
:mobile="breakpoints.sm"
:mobile="isMobileSidebar"
RVitaly1978 marked this conversation as resolved.
Show resolved Hide resolved
/>
</aside>
<main class="docs-layout__main-content">
Expand All @@ -36,33 +36,31 @@ const cookie = useCookie('vuestic-theme')
const { applyPreset } = useColors()
const breakpoints = useBreakpoint()

const isSidebarVisible = ref(!breakpoints.smDown)
const isSidebarVisible = ref(false)
const isOptionsVisible = ref(false)
const isMobileSidebar = ref(false)

applyPreset(cookie.value || 'light')

watch(() => breakpoints.smDown, (newValue, oldValue) => {
if (newValue && !oldValue) {
isSidebarVisible.value = false
}
if (!newValue && oldValue) {
isSidebarVisible.value = true
}
watch(() => breakpoints.smDown, (newValue: boolean) => {
isSidebarVisible.value = !newValue
isOptionsVisible.value = false
isMobileSidebar.value = newValue
})

const { afterEach } = useRouter()
const { scrollToElement } = useDocsScroll()
afterEach(() => {
scrollToElement()
isSidebarVisible.value = !breakpoints.smDown
isOptionsVisible.value = false

if (breakpoints.smDown) {
isSidebarVisible.value = false
}
})

onMounted(scrollToElement)
onMounted(() => {
scrollToElement()
isSidebarVisible.value = !breakpoints.smDown
isMobileSidebar.value = breakpoints.smDown
})

useHead({
link: [
Expand Down