Skip to content

Commit 1b9342e

Browse files
authored
Merge pull request #166 from adierkens/add-context-to-ts
Add LiveContext typings
2 parents 1a3c537 + de588f0 commit 1b9342e

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

typings/react-live.d.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ComponentClass, StatelessComponent, HTMLProps, ComponentType } from 'react'
1+
import { ComponentClass, StatelessComponent, HTMLProps, ComponentType, Context } from 'react'
22
import { PrismTheme, Language } from 'prism-react-renderer';
33

44
// Helper types
@@ -32,6 +32,17 @@ export type EditorProps = Omit<PreProps, 'onChange'> & {
3232

3333
export const Editor: ComponentClass<EditorProps>
3434

35+
// Context
36+
export interface ContextProps {
37+
code?: string;
38+
language?: Language;
39+
theme: PrismTheme;
40+
disabled?: boolean;
41+
error?: string;
42+
}
43+
44+
export const LiveContext: Context<ContextProps>;
45+
3546
// LiveEditor
3647
export type LiveEditorProps = EditorProps;
3748

typings/test.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
LiveEditor,
55
LiveError,
66
LivePreview,
7+
LiveContext,
78
withLive
89
} from '../';
910
import * as React from 'react';
@@ -34,6 +35,12 @@ export const liveEditorC = <LiveEditor onChange={(code: string) => {}} />;
3435

3536
export const liveErrorC = <LiveError />;
3637

38+
export const customError = () => (
39+
<LiveContext.Consumer>
40+
{({ error }) => (error ? <pre>{error}</pre> : null)}
41+
</LiveContext.Consumer>
42+
);
43+
3744
export const livePreviewC = <LivePreview />;
3845

3946
const Component: React.StatelessComponent<{}> = () => <div>Hello World!</div>;

0 commit comments

Comments
 (0)