-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3852 from nyatinte/feat/resizable-notebook
Added resize functionality to notebooks of Article and PDF
- Loading branch information
Showing
4 changed files
with
144 additions
and
146 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
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
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
55 changes: 55 additions & 0 deletions
55
packages/web/components/templates/article/ResizableSidebar.tsx
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,55 @@ | ||
import SlidingPane from 'react-sliding-pane' | ||
import { Resizable, ResizeCallback } from 're-resizable' | ||
import useGetWindowDimensions from '../../../lib/hooks/useGetWindowDimensions' | ||
|
||
type ResizableSidebarProps = { | ||
isShow: boolean | ||
onClose: () => void | ||
children: React.ReactNode | ||
} | ||
|
||
export function ResizableSidebar(props: ResizableSidebarProps): JSX.Element { | ||
const windowDimensions = useGetWindowDimensions() | ||
|
||
const handleResize: ResizeCallback = (_e, _direction, ref) => { | ||
if (parseInt(ref.style.width) < 210) { | ||
props.onClose() | ||
} | ||
} | ||
|
||
return ( | ||
<SlidingPane | ||
className="sliding-pane-class" | ||
isOpen={props.isShow} | ||
width="fit-content" | ||
hideHeader={true} | ||
from="right" | ||
overlayClassName="slide-panel-overlay" | ||
onRequestClose={props.onClose} | ||
> | ||
<Resizable | ||
onResize={handleResize} | ||
defaultSize={{ | ||
width: windowDimensions.width < 600 ? '100%' : '420px', | ||
height: '100%', | ||
}} | ||
enable={ | ||
windowDimensions.width < 600 | ||
? false | ||
: { | ||
top: false, | ||
right: false, | ||
bottom: false, | ||
left: true, | ||
topRight: false, | ||
bottomRight: false, | ||
bottomLeft: false, | ||
topLeft: false, | ||
} | ||
} | ||
> | ||
{props.children} | ||
</Resizable> | ||
</SlidingPane> | ||
) | ||
} |