Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

Sidebar.js

50 lines1.3 KB

1import { useState } from 'react'
2import cn from 'classnames'
3import { Search } from './Search'
4import CarbonAds from './CarbonAds'
5export const Sidebar = ({ active, children, fixed }) => {
6 const [searching, setSearching] = useState(false)
7 return (
8 <aside
9 className={cn('sidebar bg-white top-24 flex-shrink-0 pr-2', {
10 active,
11 ['pb-0 flex flex-col z-1 sticky']: fixed,
12 fixed,
13 searching,
14 })}
15 >
16 <div className="sidebar-search my-2 lg:hidden">
17 <Search />
18 </div>
19 <div className="sidebar-content overflow-y-auto pb-4">{children}</div>
20 <CarbonAds />
21 <style jsx>{`
22 .sidebar {
23 -webkit-overflow-scrolling: touch;
24 }
25 .sidebar.fixed {
26 width: 300px;
27 padding-right: 2.5rem;
28 /* Full page - content margin - header size - banner */
29 height: calc(100vh - 1.5rem - 64px - 42px);
30 }
31 .sidebar.fixed.searching > .sidebar-content {
32 display: none;
33 }
34 .sidebar-search {
35 position: relative;
36 z-index: 1;
37 }
38 @media screen and (max-width: 1024px) {
39 .sidebar,
40 .sidebar.fixed {
41 display: none;
42 }
43 .sidebar.active {
44 display: block;
45 }
46 }
47 `}</style>
48 </aside>
49 )