Skip to content

Commit

Permalink
chore: improve code organization
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelodelain committed Feb 21, 2024
1 parent 9246fe1 commit 9140147
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
6 changes: 5 additions & 1 deletion src/runtime/components/NuxtStory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const { storiesUIVisible } = useStories()
top: 0;
overflow-y: auto;
width: 17vw;
min-width: 150px;
min-width: 200px;
max-width: 400px;
padding: 1.5rem 2rem;
resize: horizontal;
Expand All @@ -48,5 +48,9 @@ const { storiesUIVisible } = useStories()
border-left: 1px solid #e3e3e3ff;
background-color: #f6f6f6ff;
font-size: 14px;
@media (max-width: 768px) {
display: none;
}
}
</style>
30 changes: 16 additions & 14 deletions src/runtime/components/StoriesNav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import { useRoute } from 'vue-router'
import { useStories } from '../composables/use-stories'
import StoriesNavItem, { type NavItem } from './StoriesNavItem.vue'
const { storiesPath, storiesUIVisible } = useStories()
// ITEM LIST
const route = useRoute()
const childRoutes = computed(() => {
return route.matched[0]?.children
})
const { storiesPath, storiesUIVisible } = useStories()
const itemList = computed(() => {
const result: NavItem = {}
Expand Down Expand Up @@ -42,18 +43,7 @@ const itemList = computed(() => {
return result
})
function onKeyUp(event: KeyboardEvent) {
if (event.key === 'Escape') search.value = ''
}
onMounted(() => {
window.addEventListener('keyup', onKeyUp)
})
onBeforeUnmount(() => {
window.removeEventListener('keyup', onKeyUp)
})
// SEARCH
const search = ref('')
function filterComponentByName(query: string) {
Expand All @@ -79,6 +69,18 @@ const filteredItemList = computed(() => {
if (!search.value) return itemList.value
else return filterComponentByName(search.value)
})
function onKeyUp(event: KeyboardEvent) {
if (event.key === 'Escape') search.value = ''
}
onMounted(() => {
window.addEventListener('keyup', onKeyUp)
})
onBeforeUnmount(() => {
window.removeEventListener('keyup', onKeyUp)
})
</script>

<template>
Expand Down
1 change: 1 addition & 0 deletions src/runtime/components/StoriesPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ useHead({
],
})
// UI visibility
const { storiesUIVisible } = useStories()
function onKeyDown(event: KeyboardEvent) {
Expand Down

0 comments on commit 9140147

Please sign in to comment.