-
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add slideover component (#711)
- Loading branch information
1 parent
f2a200d
commit 6d235a0
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { useState } from "react"; | ||
import { SlideOver } from "ui"; | ||
|
||
export default { | ||
component: SlideOver, | ||
parameters: { | ||
layout: 'fullscreen', | ||
backgrounds: { | ||
default: 'dark' | ||
} | ||
}, | ||
}; | ||
|
||
export const Example = () => { | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
const handleOpen = () => setIsOpen(true); | ||
const handleClose = () => setIsOpen(false); | ||
|
||
return ( | ||
<div> | ||
<button onClick={handleOpen} className="bg-white text-black rounded mx-3 my-3">Open SlideOver</button> | ||
|
||
<SlideOver isOpen={isOpen} onClose={handleClose}> | ||
<h2>Content of the SlideOver</h2> | ||
</SlideOver> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { XMarkIcon } from './icons'; | ||
|
||
interface SlideOverProps { | ||
isOpen: boolean; | ||
onClose: () => void; | ||
children: React.ReactNode; | ||
} | ||
|
||
export const SlideOver: React.FC<SlideOverProps> = ({ isOpen, onClose, children }) => { | ||
|
||
if (!isOpen) return null; | ||
|
||
const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => { | ||
if (event.key === 'Escape') { | ||
onClose(); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className="fixed right-0 top-0 bottom-0 w-full max-w-lg h-full bg-gray-950/[.67] text-gray-200 shadow-lg overflow-auto p-2.5 border-l-2 border-gray-700 backdrop-blur-[20px]" tabIndex={0} onKeyDown={handleKeyDown}> | ||
<button className="absolute top-2 right-2 focus:outline-white" onClick={onClose} aria-label="Close"> | ||
<XMarkIcon className="h-6 w-6"/> | ||
</button> | ||
{children} | ||
</div> | ||
); | ||
}; | ||
|
||
export default SlideOver; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters