react-feather#List JavaScript Examples
The following examples show how to use
react-feather#List.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.js From pancake-info-v1 with GNU General Public License v3.0 | 4 votes |
function SideNav({ history }) {
const below1080 = useMedia('(max-width: 1080px)')
const below1180 = useMedia('(max-width: 1180px)')
const seconds = useSessionStart()
const [isDark, toggleDarkMode] = useDarkModeManager()
return (
<Wrapper isMobile={below1080}>
{!below1080 ? (
<DesktopWrapper>
<AutoColumn gap="1rem" style={{ marginLeft: '.75rem', marginTop: '1.5rem' }}>
<Title />
{!below1080 && (
<AutoColumn gap="1.25rem" style={{ marginTop: '1rem' }}>
<BasicLink to="/home">
<Option activeText={history.location.pathname === '/home' ?? undefined}>
<TrendingUp size={20} style={{ marginRight: '.75rem' }} />
Overview
</Option>
</BasicLink>
<BasicLink to="/tokens">
<Option
activeText={
(history.location.pathname.split('/')[1] === 'tokens' ||
history.location.pathname.split('/')[1] === 'token') ??
undefined
}
>
<Disc size={20} style={{ marginRight: '.75rem' }} />
Tokens
</Option>
</BasicLink>
<BasicLink to="/pairs">
<Option
activeText={
(history.location.pathname.split('/')[1] === 'pairs' ||
history.location.pathname.split('/')[1] === 'pair') ??
undefined
}
>
<PieChart size={20} style={{ marginRight: '.75rem' }} />
Pairs
</Option>
</BasicLink>
<BasicLink to="/accounts">
<Option
activeText={
(history.location.pathname.split('/')[1] === 'accounts' ||
history.location.pathname.split('/')[1] === 'account') ??
undefined
}
>
<List size={20} style={{ marginRight: '.75rem' }} />
Accounts
</Option>
</BasicLink>
</AutoColumn>
)}
</AutoColumn>
<AutoColumn gap="0.5rem" style={{ marginLeft: '.75rem', marginBottom: '4rem' }}>
<HeaderText>
<Link href="https://pancakeswap.finance/" target="_blank">
PancakeSwap
</Link>
</HeaderText>
<HeaderText>
<Link href="https://docs.pancakeswap.finance/" target="_blank">
Docs
</Link>
</HeaderText>
<HeaderText>
<Link href="https://twitter.com/PancakeSwap " target="_blank">
Twitter
</Link>
</HeaderText>
<Toggle isActive={isDark} toggle={toggleDarkMode} />
</AutoColumn>
{!below1180 && (
<Polling style={{ marginLeft: '.5rem' }}>
<PollingDot />
<a href="/" style={{ color: 'white' }}>
<TYPE.small color={'white'}>
Updated {!!seconds ? seconds + 's' : '-'} ago <br />
</TYPE.small>
</a>
</Polling>
)}
</DesktopWrapper>
) : (
<MobileWrapper>
<Title />
</MobileWrapper>
)}
</Wrapper>
)
}
Example #2
Source File: Docs.jsx From vertx-web-site.github.io with Apache License 2.0 | 4 votes |
Docs = ({ metadata, allVersions, fallbackGitHubStars, toc, contents }) => {
const tocRef = useRef()
const searchResultsRef = useRef()
const contentRef = useRef()
const sidebarRef = useRef()
const sidebarAutoHideTimer = useRef(null)
const [sidebarCollapse, setSidebarCollapse] = useState(false)
const [hasSearchResults, setHasSearchResults] = useState()
const currentVersion = useContext(VersionContext.State)
const sortedAllVersions = allVersions.sort().reverse()
const activeVersion = currentVersion.version !== undefined ? currentVersion.version : latestRelease.version
const activeVersionTitle = docsMetadata.find(m => m.version === activeVersion)
.metadata.title || activeVersion
const enableBodyScrollInternal = () => {
enableBodyScroll(tocRef.current)
enableBodyScroll(searchResultsRef.current)
}
const disableBodyScrollInternal = () => {
// Do not disable body scroll if the window has a scrollbar (typically on
// Windows). Otherwise, the scrollbar will disappear and the content will
// jump to the right.
let hasScrollbar = window.innerWidth > document.documentElement.clientWidth
if (!hasScrollbar) {
disableBodyScroll(searchResultsRef.current)
disableBodyScroll(tocRef.current)
}
}
const cancelSidebarAutoHideTimer = useCallback(() => {
if (sidebarAutoHideTimer.current) {
clearTimeout(sidebarAutoHideTimer.current)
sidebarAutoHideTimer.current = null
}
}, [])
const startSidebarAutoHideTimer = useCallback(() => {
cancelSidebarAutoHideTimer()
sidebarAutoHideTimer.current = setTimeout(() => {
setSidebarCollapse(false)
sidebarAutoHideTimer.current = null
}, 500)
}, [cancelSidebarAutoHideTimer])
const onHashChangeStart = useCallback((url, initial) => {
enableBodyScrollInternal()
cancelSidebarAutoHideTimer()
setSidebarCollapse(false)
let hash = url.substring(url.indexOf("#") + 1)
let target = document.getElementById(hash)
if (!target) {
return
}
// make it so that the search box and the element are vertically centered
let computedStyle = window.getComputedStyle(target)
let paddingTop = parseInt(computedStyle.paddingTop)
let lineHeight = parseInt(computedStyle.lineHeight)
let sidebarStyle = window.getComputedStyle(sidebarRef.current)
let sidebarTop = parseInt(sidebarStyle.top)
let offset = target.offsetTop - sidebarTop +
paddingTop + (lineHeight / 2 - 20)
smoothScrollTo(offset, initial ? 200 : 500)
}, [cancelSidebarAutoHideTimer])
const onHashChange = useCallback((e) => {
onHashChangeStart(e.newURL)
}, [onHashChangeStart])
const onSidebarMouseEnter = useCallback(() => {
cancelSidebarAutoHideTimer()
disableBodyScrollInternal()
}, [cancelSidebarAutoHideTimer])
const onSidebarMouseLeave = useCallback(() => {
enableBodyScrollInternal()
startSidebarAutoHideTimer()
}, [startSidebarAutoHideTimer])
const onContentMouseDown = () => {
onSidebarMouseLeave()
}
const onContentTouchStart = () => {
onSidebarMouseLeave()
}
const onSidebarToggle = () => {
if (sidebarCollapse) {
enableBodyScrollInternal()
} else {
disableBodyScrollInternal()
}
cancelSidebarAutoHideTimer()
setSidebarCollapse(!sidebarCollapse)
}
// replace internal links' onclick with Router.push() so we can scroll smoothly
const replaceInternalLinks = useCallback((ref) => {
let internalLinks = ref.current.querySelectorAll("a[href^='#']")
for (let il of internalLinks) {
il.onclick = (e) => {
e.preventDefault()
let href = window.location.href
let hash = href.substring(href.indexOf("#"))
if (hash !== il.getAttribute("href")) {
Router.push(window.location.pathname + il.getAttribute("href"))
} else {
onHashChangeStart(href)
}
}
}
}, [onHashChangeStart])
useEffect(() => {
Router.events.on("hashChangeStart", onHashChangeStart)
window.addEventListener("hashchange", onHashChange)
let sidebar = sidebarRef.current
sidebar.addEventListener("mouseenter", onSidebarMouseEnter)
sidebar.addEventListener("mouseleave", onSidebarMouseLeave)
replaceInternalLinks(tocRef)
replaceInternalLinks(contentRef)
// initial scroll
onHashChangeStart(window.location.href, true)
return () => {
sidebar.removeEventListener("mouseenter", onSidebarMouseEnter)
sidebar.removeEventListener("mouseleave", onSidebarMouseLeave)
window.removeEventListener("hashchange", onHashChange)
Router.events.off("hashChangeStart", onHashChangeStart)
clearAllBodyScrollLocks()
}
}, [onHashChange, onHashChangeStart, onSidebarMouseEnter, onSidebarMouseLeave,
replaceInternalLinks])
let repository
if (metadata.repository) {
let m = metadata.repository.match(/https?:\/\/github\.com\/([^/]+)\/([^/]+)/)
if (m) {
let org = m[1]
let repo = m[2]
repository = <GitHubStars org={org} repo={repo} fallbackValue={fallbackGitHubStars} />
} else {
repository = <a href={metadata.repository}><Code className="feather" /> Source code</a>
}
}
let examples
if (metadata.examples) {
examples = <a href={metadata.examples}><Paperclip className="feather" /> Examples</a>
}
let edit
if (metadata.edit) {
edit = <a href={metadata.edit}><Edit className="feather" /> Edit</a>
}
return (
<main className="page docs">
<Header title={metadata.name}/>
<div className="page-content docs-content">
<div className="container">
<div className="docs-content-wrapper">
<aside className={classNames({ "docs-has-search-results": hasSearchResults, "collapse": sidebarCollapse })}>
<div className="docs-content-wrapper-sidebar" ref={sidebarRef}>
<SearchPanel contentRef={contentRef} onHasResults={setHasSearchResults} ref={searchResultsRef} />
<div dangerouslySetInnerHTML={{ __html: toc }} ref={tocRef}
className="docs-content-toc" />
</div>
</aside>
<div className={classNames("docs-content-sidebar-toggle", { "collapse": sidebarCollapse })}
onClick={onSidebarToggle}>
<div style={{ position: "relative" }}>
<List className="feather-list" />
<X className="feather-x" />
</div>
</div>
<div className="docs-content-inner" onMouseDown={onContentMouseDown}
onTouchStart={onContentTouchStart}>
<div className="docs-content-metadata">
<div className="docs-content-metadata-left">
{repository && <div className="docs-content-metadata-repo">{repository}</div>}
<div>
<a href={`/docs/${currentVersion.version ? `${currentVersion.version}/` : ""}apidocs`}>
<Book className="feather" /> API
</a>
</div>
{examples && <div className="docs-content-metadata-examples">{examples}</div>}
{edit && <div className="docs-content-metadata-edit">{edit}</div>}
<span className="docs-content-metadata-version">
<DropDown title={`v${activeVersionTitle}`} align="right">
{filterLatestBugfixVersions(sortedAllVersions).map(v => {
let md = docsMetadata.find(m => m.version === v)
let title = md.metadata.title || v
if (latestRelease.version === v) {
return (
<DropDownItem key={v} active={activeVersion === v}
href={`/docs${metadata.href}`}>
Latest (v{title})
</DropDownItem>
)
} else {
return (
<DropDownItem key={v} active={activeVersion === v}
href={`/docs/${v}${metadata.href}`}>
v{title}
</DropDownItem>
)
}
})}
</DropDown>
</span>
</div>
{metadata.label && <div className="docs-content-metadata-label">
<Label small nowrap>{metadata.label}</Label>
</div>}
</div>
<div dangerouslySetInnerHTML={{ __html: contents }} ref={contentRef} />
</div>
</div>
</div>
</div>
<Footer />
<style jsx>{styles}</style>
</main>
)
}