Skip to content

Commit

Permalink
1,540th Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Shyam-Chen committed Aug 26, 2024
1 parent 1d71e54 commit 8bafcfe
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 7 deletions.
1 change: 1 addition & 0 deletions app/src/plugins/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const router = createRouter({
...routes,
],
scrollBehavior(to, from, savedPosition) {
if (to.hash) return { selector: to.hash };
if (savedPosition) return savedPosition;
return { top: 0 };
},
Expand Down
52 changes: 45 additions & 7 deletions app/src/routes/(backstage)/(library)/navigation/outline/+page.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<script lang="ts" setup>
import { XBreadcrumb, XButton, XOutline } from '@x/ui';
import { onMounted } from 'vue';
import { useRoute } from 'vue-router';
import { XBreadcrumb, XButton, XOutline, XHashAnchor } from '@x/ui';
import { useOutline } from '@x/ui';
const route = useRoute();
const outline = useOutline([
/* 0 */ { text: '1. Create a Project' },
/* 1 */ { text: '2. Create a Collection' },
Expand All @@ -13,6 +17,10 @@ const outline = useOutline([
/* 7 */ { text: '5. Set Roles & Permissions' },
/* 8 */ { text: '6. Connect to the API' },
]);
onMounted(() => {
if (route.hash) ___location.href = route.hash;
});
</script>

<template>
Expand All @@ -23,7 +31,12 @@ const outline = useOutline([
<div class="grid grid-cols-12 gap-2">
<div class="col-span-9">
<div :ref="(el) => (outline[0].el = el)" class="flex flex-col gap-3 mb-12">
<h2 class="text-3xl font-bold">1. Create a Project</h2>
<XHashAnchor v-slot="{ Hashtag }" hash="create-a-project">
<h2 class="text-3xl font-bold">
1. Create a Project
<component :is="Hashtag"></component>
</h2>
</XHashAnchor>

<div class="flex flex-col gap-3">
<p>
Expand Down Expand Up @@ -55,7 +68,12 @@ const outline = useOutline([
</div>

<div :ref="(el) => (outline[1].el = el)" class="flex flex-col gap-3 mt-8 mb-12">
<h2 class="text-3xl font-bold">2. Create a Collection</h2>
<XHashAnchor v-slot="{ Hashtag }" hash="create-a-collection">
<h2 class="text-3xl font-bold">
2. Create a Collection
<component :is="Hashtag"></component>
</h2>
</XHashAnchor>

<div class="flex flex-col gap-3">
<p>
Expand Down Expand Up @@ -87,7 +105,12 @@ const outline = useOutline([
</div>

<div class="flex flex-col gap-3 mt-8 mb-12">
<h2 :ref="(el) => (outline[2].el = el)" class="text-3xl font-bold">3. Create a Field</h2>
<XHashAnchor v-slot="{ Hashtag }" hash="create-a-field">
<h2 :ref="(el) => (outline[2].el = el)" class="text-3xl font-bold">
3. Create a Field
<component :is="Hashtag"></component>
</h2>
</XHashAnchor>

<div class="flex flex-col gap-3">
<p>
Expand Down Expand Up @@ -129,7 +152,12 @@ const outline = useOutline([
</div>

<div :ref="(el) => (outline[6].el = el)" class="flex flex-col gap-3 mt-8 mb-12">
<h2 class="text-3xl font-bold">4. Create an Item</h2>
<XHashAnchor v-slot="{ Hashtag }" hash="create-an-item">
<h2 class="text-3xl font-bold">
4. Create an Item
<component :is="Hashtag"></component>
</h2>
</XHashAnchor>

<div class="flex flex-col gap-3">
<p>
Expand Down Expand Up @@ -161,7 +189,12 @@ const outline = useOutline([
</div>

<div :ref="(el) => (outline[7].el = el)" class="flex flex-col gap-3 mt-8 mb-12">
<h2 class="text-3xl font-bold">5. Set Roles & Permissions</h2>
<XHashAnchor v-slot="{ Hashtag }" hash="set-roles-&-permissions">
<h2 class="text-3xl font-bold">
5. Set Roles & Permissions
<component :is="Hashtag"></component>
</h2>
</XHashAnchor>

<div class="flex flex-col gap-3">
<p>
Expand Down Expand Up @@ -193,7 +226,12 @@ const outline = useOutline([
</div>

<div :ref="(el) => (outline[8].el = el)" class="flex flex-col gap-3 mt-8 mb-12">
<h2 class="text-3xl font-bold">6. Connect to the API</h2>
<XHashAnchor v-slot="{ Hashtag }" hash="connect-to-the-api">
<h2 class="text-3xl font-bold">
6. Connect to the API
<component :is="Hashtag"></component>
</h2>
</XHashAnchor>

<div class="flex flex-col gap-3">
<p>
Expand Down
25 changes: 25 additions & 0 deletions ui/src/components/hash-anchor/HashAnchor.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<script lang="ts" setup>
import { h } from 'vue';
const props = defineProps<{
hash?: string;
}>();
const Hashtag = () => {
return h(
'a',
{
href: `#${props.hash}`,
class:
'absolute left-0 -ml-6 opacity-0 group-hover:opacity-100 transition-opacity text-primary-500 dark:text-primary-400 select-none',
},
'#',
);
};
</script>

<template>
<div :id="hash" class="relative group scroll-mt-24">
<slot :Hashtag></slot>
</div>
</template>
1 change: 1 addition & 0 deletions ui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export { default as XDropzone } from './components/dropzone/Dropzone.vue';
export { default as XFade } from './components/fade/Fade.vue';
export { default as XFileInput } from './components/file-input/FileInput.vue';
export { default as XFormControl } from './components/form-control/FormControl.vue';
export { default as XHashAnchor } from './components/hash-anchor/HashAnchor.vue';
export { default as XHighlight } from './components/highlight/Highlight.vue';
export { default as XInputMask } from './components/input-mask/InputMask.vue';
export { default as XIterator } from './components/iterator/Iterator.vue';
Expand Down

0 comments on commit 8bafcfe

Please sign in to comment.