-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
100 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,26 @@ | ||
import { SidePanel } from './SidePanel'; | ||
|
||
export default { title: 'Components/SidePanel' }; | ||
|
||
export const _SidePanelLeft = { | ||
render: () => ( | ||
<SidePanel | ||
onOpen={() => console.log('opened')} | ||
onClose={() => console.log('closed')} | ||
> | ||
<div className="flex h-full items-center">That's a side panel</div> | ||
</SidePanel> | ||
), | ||
}; | ||
|
||
export const _SidePanelRight = { | ||
render: () => ( | ||
<SidePanel | ||
side="left" | ||
onOpen={() => console.log('opened')} | ||
onClose={() => console.log('closed')} | ||
> | ||
<div className="flex h-full items-center">That's a side panel</div> | ||
</SidePanel> | ||
), | ||
}; |
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,13 @@ | ||
import '@testing-library/jest-dom'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { SidePanel } from '.'; | ||
|
||
describe('Components | SidePanel', () => { | ||
test('it should render', () => { | ||
render(<SidePanel />); | ||
|
||
let sidePanel = screen.getByTestId('side-panel'); | ||
|
||
expect(sidePanel).toBeInTheDocument(); | ||
}); | ||
}); |
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,60 @@ | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
import React from 'react'; | ||
|
||
import { | ||
ComponentPropsWithoutRef, | ||
ReactNode, | ||
ChangeEvent, | ||
useState, | ||
} from 'react'; | ||
import { FiMenu } from 'react-icons/fi'; | ||
|
||
export interface SidePanelProps extends ComponentPropsWithoutRef<'div'> { | ||
side?: 'left' | 'right'; | ||
customClass?: string; | ||
children?: ReactNode; | ||
onOpen?: () => void; | ||
onClose?: () => void; | ||
} | ||
|
||
export function SidePanel({ ...props }) { | ||
const { | ||
side = 'right', | ||
children, | ||
onClose, | ||
onOpen, | ||
customClass, | ||
...rest | ||
} = props; | ||
const [toggle, setToggle] = useState(false); | ||
|
||
const isRight = side === 'right'; | ||
|
||
console.log(isRight); | ||
|
||
const sideClass = isRight ? 'right-0' : 'left-0'; | ||
const toggleClass = toggle ? 'w-[450px]' : 'w-10'; | ||
const iconClass = isRight ? 'flex-row' : 'flex-row-reverse'; | ||
|
||
function toggleDropdown(e: ChangeEvent<unknown>) { | ||
setToggle(!toggle); | ||
|
||
toggle ? onClose?.(e) : onOpen?.(e); | ||
} | ||
|
||
return ( | ||
<div | ||
data-testid="side-panel" | ||
className={`fixed top-0 ${sideClass} ${toggleClass} h-screen bg-secondary ${customClass}`} | ||
{...rest} | ||
> | ||
<div className={`flex ${iconClass} h-full`}> | ||
<button onClick={toggleDropdown} className="p-2 flex items-center"> | ||
<FiMenu className="h-6 w-6" /> | ||
</button> | ||
<div className="flex">{toggle ? children : null}</div> | ||
</div> | ||
</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 @@ | ||
export * from './SidePanel'; |