mirror of
https://github.com/sst/opencode.git
synced 2025-08-04 13:30:52 +00:00
docs: share page format
This commit is contained in:
parent
8b400515ea
commit
145df08444
2 changed files with 30 additions and 46 deletions
|
@ -595,12 +595,17 @@ export default function Share(props: {
|
||||||
info: Session.Info
|
info: Session.Info
|
||||||
messages: Record<string, Message.Info>
|
messages: Record<string, Message.Info>
|
||||||
}) {
|
}) {
|
||||||
|
let lastScrollY = 0
|
||||||
let hasScrolled = false
|
let hasScrolled = false
|
||||||
|
let scrollTimeout: number | undefined
|
||||||
|
|
||||||
const id = props.id
|
const id = props.id
|
||||||
const params = new URLSearchParams(window.location.search)
|
const params = new URLSearchParams(window.location.search)
|
||||||
const debug = params.get("debug") === "true"
|
const debug = params.get("debug") === "true"
|
||||||
|
|
||||||
|
const [showScrollButton, setShowScrollButton] = createSignal(false)
|
||||||
|
const [isButtonHovered, setIsButtonHovered] = createSignal(false)
|
||||||
|
|
||||||
const anchorId = createMemo<string | null>(() => {
|
const anchorId = createMemo<string | null>(() => {
|
||||||
const raw = window.location.hash.slice(1)
|
const raw = window.location.hash.slice(1)
|
||||||
const [id] = raw.split("-")
|
const [id] = raw.split("-")
|
||||||
|
@ -716,23 +721,18 @@ export default function Share(props: {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
const [showScrollButton, setShowScrollButton] = createSignal(false)
|
function checkScrollNeed() {
|
||||||
const [isButtonHovered, setIsButtonHovered] = createSignal(false)
|
|
||||||
let scrollTimeout: number | undefined
|
|
||||||
let lastScrollY = 0
|
|
||||||
|
|
||||||
const checkScrollNeed = () => {
|
|
||||||
const currentScrollY = window.scrollY
|
const currentScrollY = window.scrollY
|
||||||
const isScrollingDown = currentScrollY > lastScrollY
|
const isScrollingDown = currentScrollY > lastScrollY
|
||||||
const scrolled = currentScrollY > 200 // Show after scrolling 200px
|
const scrolled = currentScrollY > 200 // Show after scrolling 200px
|
||||||
const isNearBottom = window.innerHeight + currentScrollY >= document.body.scrollHeight - 100
|
const isNearBottom = window.innerHeight + currentScrollY >= document.body.scrollHeight - 100
|
||||||
|
|
||||||
// Only show when scrolling down, scrolled enough, and not near bottom
|
// Only show when scrolling down, scrolled enough, and not near bottom
|
||||||
const shouldShow = isScrollingDown && scrolled && !isNearBottom
|
const shouldShow = isScrollingDown && scrolled && !isNearBottom
|
||||||
|
|
||||||
// Update last scroll position
|
// Update last scroll position
|
||||||
lastScrollY = currentScrollY
|
lastScrollY = currentScrollY
|
||||||
|
|
||||||
if (shouldShow) {
|
if (shouldShow) {
|
||||||
setShowScrollButton(true)
|
setShowScrollButton(true)
|
||||||
// Clear existing timeout
|
// Clear existing timeout
|
||||||
|
@ -754,30 +754,6 @@ export default function Share(props: {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleButtonMouseEnter = () => {
|
|
||||||
setIsButtonHovered(true)
|
|
||||||
// Clear timeout when hovering
|
|
||||||
if (scrollTimeout) {
|
|
||||||
clearTimeout(scrollTimeout)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleButtonMouseLeave = () => {
|
|
||||||
setIsButtonHovered(false)
|
|
||||||
// Restart timeout when leaving hover
|
|
||||||
if (showScrollButton()) {
|
|
||||||
scrollTimeout = window.setTimeout(() => {
|
|
||||||
if (!isButtonHovered()) {
|
|
||||||
setShowScrollButton(false)
|
|
||||||
}
|
|
||||||
}, 3000)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const scrollToBottom = () => {
|
|
||||||
document.body.scrollIntoView({ behavior: "smooth", block: "end" })
|
|
||||||
}
|
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
lastScrollY = window.scrollY // Initialize scroll position
|
lastScrollY = window.scrollY // Initialize scroll position
|
||||||
checkScrollNeed()
|
checkScrollNeed()
|
||||||
|
@ -1982,14 +1958,29 @@ export default function Share(props: {
|
||||||
</div>
|
</div>
|
||||||
</Show>
|
</Show>
|
||||||
|
|
||||||
{/* Floating scroll to bottom button */}
|
|
||||||
<Show when={showScrollButton()}>
|
<Show when={showScrollButton()}>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class={styles.scrollButton}
|
class={styles["scroll-button"]}
|
||||||
onClick={scrollToBottom}
|
onClick={() =>
|
||||||
onMouseEnter={handleButtonMouseEnter}
|
document.body.scrollIntoView({ behavior: "smooth", block: "end" })
|
||||||
onMouseLeave={handleButtonMouseLeave}
|
}
|
||||||
|
onMouseEnter={() => {
|
||||||
|
setIsButtonHovered(true)
|
||||||
|
if (scrollTimeout) {
|
||||||
|
clearTimeout(scrollTimeout)
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
onMouseLeave={() => {
|
||||||
|
setIsButtonHovered(false)
|
||||||
|
if (showScrollButton()) {
|
||||||
|
scrollTimeout = window.setTimeout(() => {
|
||||||
|
if (!isButtonHovered()) {
|
||||||
|
setShowScrollButton(false)
|
||||||
|
}
|
||||||
|
}, 3000)
|
||||||
|
}
|
||||||
|
}}
|
||||||
title="Scroll to bottom"
|
title="Scroll to bottom"
|
||||||
aria-label="Scroll to bottom"
|
aria-label="Scroll to bottom"
|
||||||
>
|
>
|
||||||
|
|
|
@ -785,7 +785,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.scrollButton {
|
.scroll-button {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
bottom: 2rem;
|
bottom: 2rem;
|
||||||
right: 2rem;
|
right: 2rem;
|
||||||
|
@ -799,18 +799,11 @@
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
|
||||||
transition: all 0.15s ease, opacity 0.5s ease;
|
transition: all 0.15s ease, opacity 0.5s ease;
|
||||||
z-index: 100;
|
z-index: 100;
|
||||||
appearance: none;
|
appearance: none;
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
|
|
||||||
&:hover {
|
|
||||||
color: var(--sl-color-text);
|
|
||||||
border-color: var(--sl-color-hairline);
|
|
||||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
|
||||||
}
|
|
||||||
|
|
||||||
&:active {
|
&:active {
|
||||||
transform: translateY(1px);
|
transform: translateY(1px);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue