-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
chore(website): make playground code editor horizontally resizable #5667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JoshuaKGoldberg
merged 7 commits into
typescript-eslint:main
from
yimothysu:website-playground-resize-editor
Sep 24, 2022
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5938b7f
Make editor horizontally resizable
yimothysu d47778b
Fix panels width split
yimothysu 046b0c5
Switch to react-split-pane
yimothysu a8075f5
Merge branch 'main' into website-playground-resize-editor
yimothysu 95d27d7
Fix bugs and refactor
yimothysu ecbb47e
Switch to ResizeObserver for handling editor resize
yimothysu 643b5b0
Merge branch 'main' into website-playground-resize-editor
yimothysu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
28 changes: 28 additions & 0 deletions
28
packages/website/src/components/SplitPane/ConditionalSplitPane.tsx
This file contains hidden or 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,28 @@ | ||
import clsx from 'clsx'; | ||
import React from 'react'; | ||
import SplitPane, { type SplitPaneProps } from 'react-split-pane'; | ||
|
||
import splitPaneStyles from './SplitPane.module.css'; | ||
|
||
export interface ConditionalSplitPaneProps { | ||
render: boolean; | ||
} | ||
|
||
function ConditionalSplitPane({ | ||
render, | ||
children, | ||
...props | ||
}: ConditionalSplitPaneProps & SplitPaneProps): JSX.Element { | ||
return render ? ( | ||
<SplitPane | ||
resizerClassName={clsx(splitPaneStyles.resizer, splitPaneStyles.vertical)} | ||
{...props} | ||
> | ||
{children} | ||
</SplitPane> | ||
) : ( | ||
<>{children}</> | ||
); | ||
} | ||
|
||
export default ConditionalSplitPane; |
24 changes: 24 additions & 0 deletions
24
packages/website/src/components/SplitPane/SplitPane.module.css
This file contains hidden or 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,24 @@ | ||
.resizer { | ||
background: var(--ifm-color-emphasis-700); | ||
opacity: 0.2; | ||
z-index: 1; | ||
box-sizing: border-box; | ||
background-clip: padding-box; | ||
} | ||
|
||
.resizer:hover { | ||
transition: all 2s ease; | ||
} | ||
|
||
.resizer.vertical { | ||
width: 11px; | ||
margin: 0 -5px; | ||
border-left: 5px solid rgba(255, 255, 255, 0); | ||
border-right: 5px solid rgba(255, 255, 255, 0); | ||
cursor: col-resize; | ||
} | ||
|
||
.resizer.vertical:hover { | ||
border-left: 5px solid var(--ifm-color-emphasis-700); | ||
border-right: 5px solid var(--ifm-color-emphasis-700); | ||
} |
This file contains hidden or 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 hidden or 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,46 @@ | ||
// Modified from https://github.com/antonioru/beautiful-react-hooks/blob/master/src/useMediaQuery.ts | ||
yimothysu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import { useEffect, useState } from 'react'; | ||
|
||
/** | ||
* Accepts a media query string then uses the | ||
* [window.matchMedia](https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia) API to determine if it | ||
* matches with the current document.<br /> | ||
* It also monitor the document changes to detect when it matches or stops matching the media query.<br /> | ||
* Returns the validity state of the given media query. | ||
* | ||
*/ | ||
const useMediaQuery = (mediaQuery: string): boolean => { | ||
const [isVerified, setIsVerified] = useState<boolean>( | ||
!!window.matchMedia(mediaQuery).matches, | ||
); | ||
|
||
useEffect(() => { | ||
const mediaQueryList = window.matchMedia(mediaQuery); | ||
const documentChangeHandler = (): void => | ||
setIsVerified(!!mediaQueryList.matches); | ||
|
||
try { | ||
mediaQueryList.addEventListener('change', documentChangeHandler); | ||
} catch (e) { | ||
// Safari isn't supporting mediaQueryList.addEventListener | ||
// eslint-disable-next-line deprecation/deprecation | ||
mediaQueryList.addListener(documentChangeHandler); | ||
} | ||
|
||
documentChangeHandler(); | ||
return () => { | ||
try { | ||
mediaQueryList.removeEventListener('change', documentChangeHandler); | ||
} catch (e) { | ||
// Safari isn't supporting mediaQueryList.removeEventListener | ||
// eslint-disable-next-line deprecation/deprecation | ||
mediaQueryList.removeListener(documentChangeHandler); | ||
} | ||
}; | ||
}, [mediaQuery]); | ||
|
||
return isVerified; | ||
}; | ||
|
||
export { useMediaQuery }; |
This file contains hidden or 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,12 @@ | ||
diff --git a/node_modules/react-split-pane/index.d.ts b/node_modules/react-split-pane/index.d.ts | ||
index d116f54..9329094 100644 | ||
--- a/node_modules/react-split-pane/index.d.ts | ||
+++ b/node_modules/react-split-pane/index.d.ts | ||
@@ -25,6 +25,7 @@ export type SplitPaneProps = { | ||
pane2Style?: React.CSSProperties; | ||
resizerClassName?: string; | ||
step?: number; | ||
+ children?: React.ReactNode; | ||
}; | ||
|
||
export type SplitPaneState = { |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.