-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for resizing panes in the playground (#2581)
fix #2422 ![Kapture 2023-10-17 at 15 12 37](https://github.com/microsoft/typespec/assets/1031227/e2eea00b-3d2f-454a-9c89-76c678c6dedb)
- Loading branch information
1 parent
f39f3a7
commit 9d2cf85
Showing
13 changed files
with
515 additions
and
45 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
common/changes/@typespec/playground/feature-split-pane_2023-10-18-15-43.json
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,10 @@ | ||
{ | ||
"changes": [ | ||
{ | ||
"packageName": "@typespec/playground", | ||
"comment": "Add resizable panes for the editor and output", | ||
"type": "none" | ||
} | ||
], | ||
"packageName": "@typespec/playground" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
declare module "*.module.css"; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { Playground, PlaygroundProps } from "./playground.js"; | ||
export { Playground } from "./playground.js"; | ||
export type { PlaygroundProps } from "./playground.js"; | ||
export { createReactPlayground, renderReactPlayground } from "./standalone.js"; | ||
export * from "./types.js"; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { SplitPane, SplitPaneProps } from "./split-pane.js"; |
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 { HTMLAttributes, PropsWithChildren } from "react"; | ||
|
||
export interface PaneProps { | ||
maxSize?: number | string; | ||
minSize?: number | string; | ||
} | ||
|
||
export default function Pane({ | ||
children, | ||
...props | ||
}: PropsWithChildren<HTMLAttributes<HTMLDivElement> & PaneProps>) { | ||
return <div {...props}>{children}</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 { mergeClasses } from "@fluentui/react-components"; | ||
import { ReactNode } from "react"; | ||
import style from "./split-pane.module.css"; | ||
|
||
export interface SashContentProps { | ||
className?: string; | ||
dragging?: boolean; | ||
children?: ReactNode; | ||
} | ||
|
||
export const SashContent: React.FunctionComponent<SashContentProps> = ({ | ||
className, | ||
children, | ||
dragging, | ||
...others | ||
}: SashContentProps) => { | ||
return ( | ||
<div | ||
className={mergeClasses( | ||
style["sash-content"], | ||
dragging && style["sash-content-dragging"], | ||
className | ||
)} | ||
{...others} | ||
> | ||
{children} | ||
</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,53 @@ | ||
import { mergeClasses } from "@fluentui/react-components"; | ||
import { ReactNode, useState } from "react"; | ||
import style from "./split-pane.module.css"; | ||
|
||
export interface SashProps { | ||
className?: string; | ||
style: React.CSSProperties; | ||
render: (dragging: boolean) => ReactNode; | ||
onReset: () => void; | ||
onDragStart: React.MouseEventHandler<HTMLDivElement>; | ||
onDragging: React.MouseEventHandler<HTMLDivElement>; | ||
onDragEnd: React.MouseEventHandler<HTMLDivElement>; | ||
} | ||
|
||
export const Sash = ({ | ||
className, | ||
render, | ||
onDragStart, | ||
onDragging, | ||
onDragEnd, | ||
onReset, | ||
...others | ||
}: SashProps) => { | ||
const [draging, setDrag] = useState(false); | ||
|
||
const handleMouseMove = (e: any) => { | ||
onDragging(e); | ||
}; | ||
|
||
const handleMouseUp = (e: any) => { | ||
setDrag(false); | ||
onDragEnd(e); | ||
window.removeEventListener("mousemove", handleMouseMove); | ||
window.removeEventListener("mouseup", handleMouseUp); | ||
}; | ||
|
||
return ( | ||
<div | ||
className={mergeClasses(style["sash"], className)} | ||
onMouseDown={(e) => { | ||
setDrag(true); | ||
onDragStart(e); | ||
|
||
window.addEventListener("mousemove", handleMouseMove); | ||
window.addEventListener("mouseup", handleMouseUp); | ||
}} | ||
onDoubleClick={onReset} | ||
{...others} | ||
> | ||
{render(draging)} | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.