-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Converted React Live codebase to TypeScript
- Loading branch information
1 parent
20d789a
commit b3c8d00
Showing
41 changed files
with
657 additions
and
422 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"react-live": major | ||
--- | ||
|
||
Migrated codebase to TypeScript. |
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,11 +1,12 @@ | ||
{ | ||
"presets": [ | ||
"@babel/preset-env", | ||
"@babel/preset-react" | ||
"@babel/preset-typescript", | ||
["@babel/preset-react", { "runtime": "automatic" }] | ||
], | ||
"plugins": [ | ||
"add-module-exports", | ||
"@babel/plugin-proposal-object-rest-spread", | ||
"@babel/plugin-proposal-class-properties" | ||
] | ||
} | ||
} |
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
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 was deleted.
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,17 @@ | ||
import { Language, PrismTheme } from "prism-react-renderer"; | ||
import { ComponentType, createContext } from "react"; | ||
|
||
type ContextValue = { | ||
error?: string; | ||
element?: ComponentType | null; | ||
code: string; | ||
disabled: boolean; | ||
language: Language; | ||
theme?: PrismTheme; | ||
onError(error: Error): void; | ||
onChange(value: string): void; | ||
} | ||
|
||
const LiveContext = createContext<ContextValue>({} as ContextValue); | ||
|
||
export default LiveContext; |
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
4 changes: 2 additions & 2 deletions
4
src/components/Live/LiveEditor.js → src/components/Live/LiveEditor.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
2 changes: 1 addition & 1 deletion
2
src/components/Live/LiveError.js → src/components/Live/LiveError.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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import React, { useContext } from "react"; | ||
import LiveContext from "./LiveContext"; | ||
|
||
export default function LiveError(props) { | ||
export default function LiveError<T extends Record<string, unknown>>(props: T) { | ||
const { error } = useContext(LiveContext); | ||
return error ? <pre {...props}>{error}</pre> : null; | ||
} |
This file was deleted.
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,16 @@ | ||
import React, { PropsWithChildren, useContext } from "react"; | ||
import LiveContext from "./LiveContext"; | ||
|
||
type Props = { | ||
Component?: React.ComponentType<PropsWithChildren<Record<string, unknown>>>; | ||
}; | ||
|
||
const fallbackComponent = ( | ||
props: PropsWithChildren<Record<string, unknown>> | ||
) => <div {...props} />; | ||
|
||
function LivePreview({ Component = fallbackComponent, ...rest }: Props) { | ||
const { element: Element } = useContext(LiveContext); | ||
return <Component {...rest}>{Element ? <Element /> : null}</Component>; | ||
} | ||
export default LivePreview; |
Oops, something went wrong.