-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(Portal): allow TypeScript in Examples.tsx files (#2648)
The code changes of `react-live` to still support SSR are med [here](tujoworker/react-live#1).
- Loading branch information
1 parent
82873c7
commit 98aaf3f
Showing
11 changed files
with
1,076 additions
and
1,229 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
45 changes: 45 additions & 0 deletions
45
packages/dnb-design-system-portal/src/e2e/code-block.spec.ts
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,45 @@ | ||
import { test, expect } from '@playwright/test' | ||
|
||
test.describe('CodeBlock', () => { | ||
test.beforeEach(async ({ page }) => { | ||
await page.goto('/uilib/components/textarea/demos') | ||
|
||
// Check if app is mounted | ||
await page.waitForSelector('#dnb-drawer-list__portal', { | ||
state: 'attached', | ||
}) | ||
}) | ||
|
||
test('should tab to next element except when code change is made', async ({ | ||
page, | ||
}) => { | ||
const textareaList = page.locator('textarea') | ||
const preList = page.locator('pre') | ||
|
||
// Set our starting point | ||
textareaList.nth(0).focus() | ||
|
||
await expect(textareaList.nth(0)).toBeFocused() | ||
|
||
await page.keyboard.down('Tab') | ||
|
||
await expect(preList.nth(0)).toBeFocused() | ||
|
||
await page.keyboard.down('Tab') | ||
|
||
await expect(textareaList.nth(1)).toBeFocused() | ||
|
||
await page.keyboard.down('Tab') | ||
|
||
await expect(preList.nth(1)).toBeFocused() | ||
|
||
// Make code change | ||
await page.keyboard.down('Space') | ||
|
||
// Try a new tab key down | ||
await page.keyboard.down('Tab') | ||
|
||
// Is still in same pre | ||
await expect(preList.nth(1)).toBeFocused() | ||
}) | ||
}) |
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,121 @@ | ||
import { Prism, themes } from 'prism-react-renderer'; | ||
import * as React$1 from 'react'; | ||
import React__default, { CSSProperties, PropsWithChildren, ComponentType } from 'react'; | ||
|
||
type Props$3 = { | ||
className?: string; | ||
code: string; | ||
disabled?: boolean; | ||
language: string; | ||
prism?: typeof Prism; | ||
style?: CSSProperties; | ||
tabMode?: "focus" | "indentation"; | ||
theme?: typeof themes.nightOwl; | ||
onChange?(value: string): void; | ||
editorRef?: React.RefObject<HTMLPreElement>; | ||
} & Omit<React.HTMLAttributes<HTMLPreElement>, "onChange">; | ||
declare const CodeEditor: { | ||
(props: Props$3): JSX.Element; | ||
defaultProps: Pick<Props$3, "tabMode">; | ||
}; | ||
|
||
type Props$2 = { | ||
code?: string; | ||
disabled?: boolean; | ||
enableTypeScript?: boolean; | ||
language?: string; | ||
noInline?: boolean; | ||
skipInitialRender?: boolean; | ||
scope?: Record<string, unknown>; | ||
theme?: typeof themes.nightOwl; | ||
transformCode?(code: string): string; | ||
}; | ||
declare function LiveProvider({ children, code, language, theme, enableTypeScript, disabled, scope, transformCode, noInline, skipInitialRender, }: PropsWithChildren<Props$2>): JSX.Element; | ||
|
||
declare function LiveEditor(props: Partial<Props$3>): JSX.Element; | ||
|
||
declare function LiveError<T extends Record<string, unknown>>(props: T): JSX.Element | null; | ||
|
||
type Props$1<T extends React__default.ElementType = React__default.ElementType> = { | ||
Component?: T; | ||
} & React__default.ComponentPropsWithoutRef<T>; | ||
declare function LivePreview<T extends keyof JSX.IntrinsicElements>(props: Props$1<T>): JSX.Element; | ||
declare function LivePreview<T extends React__default.ElementType>(props: Props$1<T>): JSX.Element; | ||
|
||
type ContextValue = { | ||
error?: string; | ||
element?: ComponentType | null; | ||
code: string; | ||
disabled: boolean; | ||
language: string; | ||
theme?: typeof themes.nightOwl; | ||
onError(error: Error): void; | ||
onChange(value: string): void; | ||
}; | ||
declare const LiveContext: React$1.Context<ContextValue>; | ||
|
||
type Props = { | ||
live: Record<string, unknown>; | ||
}; | ||
declare function withLive<T>(WrappedComponent: ComponentType<T & Props>): { | ||
(props: T): JSX.Element; | ||
displayName: string; | ||
}; | ||
|
||
type GenerateOptions = { | ||
code: string; | ||
scope?: Record<string, unknown>; | ||
enableTypeScript: boolean; | ||
}; | ||
declare const generateElement: ({ code, scope, enableTypeScript }: GenerateOptions, errorCallback: (error: Error) => void) => { | ||
new (props: {} | Readonly<{}>): { | ||
componentDidCatch(error: Error): void; | ||
render(): JSX.Element | null; | ||
context: unknown; | ||
setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<{}>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void; | ||
forceUpdate(callback?: (() => void) | undefined): void; | ||
readonly props: Readonly<{}>; | ||
state: Readonly<{}>; | ||
refs: { | ||
[key: string]: React__default.ReactInstance; | ||
}; | ||
componentDidMount?(): void; | ||
shouldComponentUpdate?(nextProps: Readonly<{}>, nextState: Readonly<{}>, nextContext: any): boolean; | ||
componentWillUnmount?(): void; | ||
getSnapshotBeforeUpdate?(prevProps: Readonly<{}>, prevState: Readonly<{}>): any; | ||
componentDidUpdate?(prevProps: Readonly<{}>, prevState: Readonly<{}>, snapshot?: any): void; | ||
componentWillMount?(): void; | ||
UNSAFE_componentWillMount?(): void; | ||
componentWillReceiveProps?(nextProps: Readonly<{}>, nextContext: any): void; | ||
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<{}>, nextContext: any): void; | ||
componentWillUpdate?(nextProps: Readonly<{}>, nextState: Readonly<{}>, nextContext: any): void; | ||
UNSAFE_componentWillUpdate?(nextProps: Readonly<{}>, nextState: Readonly<{}>, nextContext: any): void; | ||
}; | ||
new (props: {}, context: any): { | ||
componentDidCatch(error: Error): void; | ||
render(): JSX.Element | null; | ||
context: unknown; | ||
setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<{}>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void; | ||
forceUpdate(callback?: (() => void) | undefined): void; | ||
readonly props: Readonly<{}>; | ||
state: Readonly<{}>; | ||
refs: { | ||
[key: string]: React__default.ReactInstance; | ||
}; | ||
componentDidMount?(): void; | ||
shouldComponentUpdate?(nextProps: Readonly<{}>, nextState: Readonly<{}>, nextContext: any): boolean; | ||
componentWillUnmount?(): void; | ||
getSnapshotBeforeUpdate?(prevProps: Readonly<{}>, prevState: Readonly<{}>): any; | ||
componentDidUpdate?(prevProps: Readonly<{}>, prevState: Readonly<{}>, snapshot?: any): void; | ||
componentWillMount?(): void; | ||
UNSAFE_componentWillMount?(): void; | ||
componentWillReceiveProps?(nextProps: Readonly<{}>, nextContext: any): void; | ||
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<{}>, nextContext: any): void; | ||
componentWillUpdate?(nextProps: Readonly<{}>, nextState: Readonly<{}>, nextContext: any): void; | ||
UNSAFE_componentWillUpdate?(nextProps: Readonly<{}>, nextState: Readonly<{}>, nextContext: any): void; | ||
}; | ||
contextType?: React__default.Context<any> | undefined; | ||
}; | ||
declare const renderElementAsync: ({ code, scope, enableTypeScript }: GenerateOptions, resultCallback: (sender: ComponentType) => void, errorCallback: (error: Error) => void) => void; | ||
|
||
export { CodeEditor as Editor, LiveContext, LiveEditor, LiveError, LivePreview, LiveProvider, generateElement, renderElementAsync, withLive }; |
Oops, something went wrong.