* start SidebarNav, enable dark mode * wip: sidebarnav, fix primer components theme rendering * feat: ProductSiteTree, useFeatureFlag * feat: add new product site tree (untested) * wire up HomepageVersionPicker, run lint * fix: remove re-render logic, fix homepage version picker to be natural width * fix: support css + primer/components color modes * fix: rename categoryId -> productId * feat: ProductSiteTree and AllArticlesProduct * fix: cleanup warnings * fix: use next links on ProductSiteTreeNew * fix: use next Link on AllArticlesProduct * fix: add tooltip to ScrollButton, remove stylesheet dependency * feat: ProductArticlesList component * fix: convert color_mode value from cookie when necessary * remove comments * replace liquid with jsx Co-authored-by: Rachael Sewell <rachmari@github.com>
62 lines
1.5 KiB
TypeScript
62 lines
1.5 KiB
TypeScript
import { useState, useEffect } from 'react'
|
|
import cx from 'classnames'
|
|
import { ChevronUpIcon } from '@primer/octicons-react'
|
|
import { useTranslation } from './hooks/useTranslation'
|
|
|
|
export const ScrollButton = () => {
|
|
const [show, setShow] = useState(false)
|
|
const { t } = useTranslation('scroll_button')
|
|
|
|
useEffect(() => {
|
|
// show scroll button only when view is scrolled down
|
|
const onScroll = function () {
|
|
const y = document.documentElement.scrollTop // get the height from page top
|
|
if (y < 100) {
|
|
setShow(false)
|
|
} else if (y >= 100) {
|
|
setShow(true)
|
|
}
|
|
}
|
|
window.addEventListener('scroll', onScroll)
|
|
|
|
return () => {
|
|
window.removeEventListener('scroll', onScroll)
|
|
}
|
|
}, [])
|
|
|
|
const onClick = () => {
|
|
window.scrollTo({ top: 0, behavior: 'smooth' })
|
|
}
|
|
|
|
return (
|
|
<div
|
|
className={cx(
|
|
'position-fixed bottom-3 right-3 transition-200',
|
|
show ? 'opacity-100' : 'opacity-0'
|
|
)}
|
|
>
|
|
<button
|
|
onClick={onClick}
|
|
className={cx(
|
|
'tooltipped tooltipped-n tooltipped-no-delay color-bg-info-inverse color-text-inverse circle border-0'
|
|
)}
|
|
style={{ width: 40, height: 40 }}
|
|
aria-label={t('scroll_to_top')}
|
|
>
|
|
<ChevronUpIcon />
|
|
</button>
|
|
<style jsx>{`
|
|
.opacity-0 {
|
|
opacity: 0;
|
|
}
|
|
.opacity-100 {
|
|
opacity: 1;
|
|
}
|
|
.transition-200 {
|
|
transition: 200ms;
|
|
}
|
|
`}</style>
|
|
</div>
|
|
)
|
|
}
|