mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 20:26:49 +00:00
.vscode
assets
components
auth
cart
checkout
common
icons
product
ui
Button
Collapse
Container
Grid
Hero
Input
Link
LoadingDots
Logo
Marquee
Modal
Quantity
Rating
Sidebar
Sidebar.module.css
Sidebar.tsx
index.ts
Skeleton
Text
README.md
context.tsx
index.ts
wishlist
search.tsx
config
framework
lib
pages
public
.editorconfig
.env.template
.gitignore
.prettierignore
.prettierrc
README.md
codegen.bigcommerce.json
codegen.json
commerce.config.json
global.d.ts
license.md
next-env.d.ts
next.config.js
package-lock.json
package.json
postcss.config.js
swell-js.d.ts
tailwind.config.js
tsconfig.js
tsconfig.json
yarn.lock
47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
import { FC, useEffect, useRef } from 'react'
|
|
import s from './Sidebar.module.css'
|
|
import cn from 'classnames'
|
|
import {
|
|
disableBodyScroll,
|
|
enableBodyScroll,
|
|
clearAllBodyScrollLocks,
|
|
} from 'body-scroll-lock'
|
|
|
|
interface SidebarProps {
|
|
children: any
|
|
onClose: () => void
|
|
}
|
|
|
|
const Sidebar: FC<SidebarProps> = ({ children, onClose }) => {
|
|
const ref = useRef() as React.MutableRefObject<HTMLDivElement>
|
|
|
|
useEffect(() => {
|
|
if (ref.current) {
|
|
disableBodyScroll(ref.current, { reserveScrollBarGap: true })
|
|
}
|
|
return () => {
|
|
if (ref && ref.current) {
|
|
enableBodyScroll(ref.current)
|
|
}
|
|
clearAllBodyScrollLocks()
|
|
}
|
|
}, [])
|
|
|
|
return (
|
|
<div className={cn(s.root)}>
|
|
<div className="absolute inset-0 overflow-hidden">
|
|
<div className={s.backdrop} onClick={onClose} />
|
|
<section className="absolute inset-y-0 right-0 max-w-full flex outline-none pl-10">
|
|
<div className="h-full w-full md:w-screen md:max-w-md">
|
|
<div className={s.sidebar} ref={ref}>
|
|
{children}
|
|
</div>
|
|
</div>
|
|
</section>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default Sidebar
|