mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-19 14:31:47 +01:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aabf1dd9eb | ||
|
|
c7c78cb47b | ||
|
|
3335a6a32c |
@@ -2,6 +2,13 @@
|
|||||||
|
|
||||||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
||||||
|
|
||||||
|
### [2.0.2](https://github.com/nuxtlabs/ui/compare/v2.0.1...v2.0.2) (2023-05-11)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* **LinkCustom:** handle `button` when no `to` prop ([c7c78cb](https://github.com/nuxtlabs/ui/commit/c7c78cb47b00963c8a9ea0c0599fbc7e128cff66))
|
||||||
|
|
||||||
### [2.0.1](https://github.com/nuxtlabs/ui/compare/v2.0.0...v2.0.1) (2023-05-11)
|
### [2.0.1](https://github.com/nuxtlabs/ui/compare/v2.0.0...v2.0.1) (2023-05-11)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,38 +1,48 @@
|
|||||||
import type { RouterConfig } from '@nuxt/schema'
|
import type { RouterConfig } from '@nuxt/schema'
|
||||||
// https://router.vuejs.org/api/interfaces/routeroptions.html
|
|
||||||
export default <RouterConfig> {
|
|
||||||
scrollBehavior (to, _form, savedPosition) {
|
|
||||||
if (history.state.stop) { return }
|
|
||||||
|
|
||||||
if (history.state.smooth) {
|
function findHashPosition (hash): { el: any, behavior: ScrollBehavior, top: number } {
|
||||||
return {
|
const el = document.querySelector(hash)
|
||||||
el: history.state.smooth,
|
// vue-router does not incorporate scroll-margin-top on its own.
|
||||||
behavior: 'smooth'
|
if (el) {
|
||||||
}
|
const top = parseFloat(getComputedStyle(el).scrollMarginTop)
|
||||||
}
|
|
||||||
|
|
||||||
if (to.hash) {
|
return {
|
||||||
const el = document.querySelector(to.hash) as any
|
el: hash,
|
||||||
|
behavior: 'smooth',
|
||||||
if (!el) { return }
|
top
|
||||||
|
|
||||||
const { marginTop } = getComputedStyle(el)
|
|
||||||
|
|
||||||
const marginTopValue = parseInt(marginTop)
|
|
||||||
|
|
||||||
const offset = (document.querySelector(to.hash) as any).offsetTop - marginTopValue
|
|
||||||
|
|
||||||
return {
|
|
||||||
top: offset,
|
|
||||||
behavior: 'smooth'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Scroll to top of window
|
|
||||||
if (savedPosition) {
|
|
||||||
return savedPosition
|
|
||||||
} else {
|
|
||||||
return { top: 0 }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://router.vuejs.org/api/#routeroptions
|
||||||
|
export default <RouterConfig>{
|
||||||
|
scrollBehavior (to, from, savedPosition) {
|
||||||
|
const nuxtApp = useNuxtApp()
|
||||||
|
|
||||||
|
// If history back
|
||||||
|
if (savedPosition) {
|
||||||
|
// Handle Suspense resolution
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
nuxtApp.hooks.hookOnce('page:finish', () => {
|
||||||
|
setTimeout(() => resolve(savedPosition), 50)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scroll to heading on click
|
||||||
|
if (to.hash) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
if (to.path === from.path) {
|
||||||
|
setTimeout(() => resolve(findHashPosition(to.hash)), 50)
|
||||||
|
} else {
|
||||||
|
nuxtApp.hooks.hookOnce('page:finish', () => {
|
||||||
|
setTimeout(() => resolve(findHashPosition(to.hash)), 50)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scroll to top of window
|
||||||
|
return { top: 0 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@nuxthq/ui",
|
"name": "@nuxthq/ui",
|
||||||
"version": "2.0.1",
|
"version": "2.0.2",
|
||||||
"repository": "https://github.com/nuxtlabs/ui",
|
"repository": "https://github.com/nuxtlabs/ui",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"exports": {
|
"exports": {
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
<template>
|
<template>
|
||||||
|
<button v-if="!$attrs.to" v-bind="$attrs" :class="inactiveClass">
|
||||||
|
<slot />
|
||||||
|
</button>
|
||||||
<NuxtLink
|
<NuxtLink
|
||||||
|
v-else
|
||||||
v-slot="{ href, navigate, exact, isActive, isExactActive }"
|
v-slot="{ href, navigate, exact, isActive, isExactActive }"
|
||||||
custom
|
custom
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user