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

Breadcrumb devsite #167

Merged
merged 8 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion web/site/app/app.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { SbcHeaderMain, SbcFooter } from '#components'
import { SbcHeaderMain, SbcFooter, SbcBreadcrumb } from '#components'
const { locale } = useI18n()
const localePath = useLocalePath()
// const user = useCurrentUser()
Expand Down Expand Up @@ -83,6 +83,7 @@ provide('footerHeight', footerHeight)
$route.path.includes('dashboard') ? dashboardNavItems : undefined
"
/>
<SbcBreadcrumb class="sticky inset-x-0 top-16 z-40" />
<NuxtLayout>
<NuxtPage />
</NuxtLayout>
Expand Down
52 changes: 52 additions & 0 deletions web/site/app/components/Sbc/Breadcrumb.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<script setup lang="ts">
import type { BreadcrumbLink } from '#ui/types'
const { t } = useI18n()
const route = useRoute()

const breadcrumbs = computed<BreadcrumbLink[]>(() =>
route.meta.breadcrumbs || [{ label: t('sbcBreadcrumb.default') }]
)

const resolveBackHref = computed(() => {
const bc = breadcrumbs.value
return bc.length > 1 ? bc[bc.length - 2]?.to || bc[bc.length - 2]?.href : ''
})

const isBackButtonDisabled = computed(() => breadcrumbs.value.length <= 2)

</script>
<template>
<div class="2xl: left-1 bg-bcGovColor-nonClickable sm:px-4">
<div class="m-auto flex w-full max-w-[1312px] items-center justify-between">
<div class="flex h-10 min-h-10 items-center">
<UButton
class="mr-3 mt-px size-[28px] rounded-full px-1 text-blue-500"
color="white"
:disabled="isBackButtonDisabled"
icon="i-mdi-arrow-left"
:aria-label="$t('sbcBreadcrumb.backBtn')"
data-cy="crumb-back"
:to="resolveBackHref"
/>
<span class="text-white">|</span>
<UBreadcrumb
:links="breadcrumbs"
:aria-label="$t('sbcBreadcrumb.arialabel')"
class="flex min-w-0 flex-wrap items-center gap-x-1.5 pl-3 text-xs leading-6 text-white"
:ui="{
li: 'flex items-center gap-x-1.5 text-xs text-white leading-6 min-w-0',
base: 'flex items-center gap-x-1.5 group font-normal min-w-0',
label: 'block truncate tracking-wide',
active: 'text-white',
inactive: 'text-white underline hover:text-white',
icon: {
base: 'flex-shrink-0 w-3 h-3 text-white',
active: '',
inactive: '',
},
}"
/>
</div>
</div>
</div>
</template>
2 changes: 1 addition & 1 deletion web/site/app/components/Sbc/Footer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const links = [
target: '_blank'
},
{
label: 'Hours of Availability',
label: 'SbcFooter.hours',
to: 'https://www2.gov.bc.ca/gov/content?id=C41D8179671441B2BAA3BDDD3D89C9A9',
target: '_blank'
},
Expand Down
25 changes: 25 additions & 0 deletions web/site/app/composables/sbcBreadcrumb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { computed } from 'vue'

export function useBreadcrumbs () {
const { t } = useI18n()
const route = useRoute()
const localePath = useLocalePath()

const breadcrumbs = computed(() => {
const bc = [
{ label: t('sbcBreadcrumb.default'), to: 'https://bcregistry.gov.bc.ca/' }
]
bc.push({ label: t('sbcBreadcrumb.sbcHome'), to: '/' })
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need this line?
You can do like this:
const bc = [
{ label: t('sbcBreadcrumb.default'), to: 'https://bcregistry.gov.bc.ca/' },
{ label: t('sbcBreadcrumb.sbcHome'), to: '/' }
]

// Check for /products
if (route.path.includes('/products') && !route.path.includes('/get-started')) {
bc.push({ label: t('sbcBreadcrumb.sbcProductslist'), to: localePath('/products') })
}
// Check for /products/get-started and include sub-paths like /account-setup
if (route.path.includes('/products/get-started')) {
bc.push({ label: t('sbcBreadcrumb.sbcProducts'), to: localePath('/products/get-started') })
}

return bc
})
return breadcrumbs
}
8 changes: 8 additions & 0 deletions web/site/app/locales/en-CA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ export default {
openMainNav: 'Open Main Navigation Menu',
closeMainNav: 'Close Main Navigation Menu'
},
sbcBreadcrumb: {
default: 'BC Registries and Digital Service',
backBtn: 'Go Back',
arialabel: 'Breadcrumb',
sbcHome: 'Service BC Connect',
sbcProductslist: 'Products List',
sbcProducts: 'Products'
},
page: {
notFound: {
h1: 'Page Not Found'
Expand Down
12 changes: 11 additions & 1 deletion web/site/app/pages/index.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
<script setup lang="ts">
import { useBreadcrumbs } from '~/composables/sbcBreadcrumb'
import { setBreadcrumbs } from '~/utils/setBreadcrumb'
const { t } = useI18n()
useHead({
title: t('page.home.title')
})
const localePath = useLocalePath()

const breadcrumbs = useBreadcrumbs()
watch(
breadcrumbs,
(newBreadcrumbs) => {
setBreadcrumbs(newBreadcrumbs)
},
{ immediate: true }
)

</script>
<template>
Expand Down
13 changes: 13 additions & 0 deletions web/site/app/pages/products/[...slug].vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
<script setup lang="ts">
import { useBreadcrumbs } from '~/composables/sbcBreadcrumb'
import { setBreadcrumbs } from '~/utils/setBreadcrumb'

definePageMeta({
layout: 'docs'
})

const breadcrumbs = useBreadcrumbs()
watch(
breadcrumbs,
(newBreadcrumbs) => {
setBreadcrumbs(newBreadcrumbs)
},
{ immediate: true }
)

</script>
<template>
<ContentDoc
Expand Down
11 changes: 11 additions & 0 deletions web/site/app/pages/products/index.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<script setup lang="ts">
import { useBreadcrumbs } from '~/composables/sbcBreadcrumb'
import { setBreadcrumbs } from '~/utils/setBreadcrumb'
const { t, locale } = useI18n()
useHead({
title: t('page.products.title')
Expand All @@ -20,6 +22,15 @@ const completedProducts = computed(() => {
return products.value?.sort((a, b) => a.name.localeCompare(b.name)) ?? []
})

const breadcrumbs = useBreadcrumbs()
watch(
breadcrumbs,
(newBreadcrumbs) => {
setBreadcrumbs(newBreadcrumbs)
},
{ immediate: true }
)

</script>
<template>
<div class="mx-auto w-full max-w-[1360px] p-2 sm:p-4 lg:p-8">
Expand Down
5 changes: 5 additions & 0 deletions web/site/app/utils/setBreadcrumb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { BreadcrumbLink } from '#ui/types'
export function setBreadcrumbs (breadcrumbs: BreadcrumbLink[]) {
const route = useRoute()
route.meta.breadcrumbs = breadcrumbs
}
6 changes: 6 additions & 0 deletions web/site/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// https://nuxt.com/docs/api/configuration/nuxt-config
import type { BreadcrumbLink } from '#ui/types'
export default defineNuxtConfig({
devtools: { enabled: false },
ssr: true,
Expand Down Expand Up @@ -131,3 +132,8 @@ export default defineNuxtConfig({
id: 'G-GKRC2V8PT4'
}
})
declare module '#app' {
interface PageMeta {
breadcrumbs?: BreadcrumbLink[]
}
}
Loading