-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate examples from Open Video UI for Web (#7)
- Loading branch information
Showing
6 changed files
with
158 additions
and
5 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
Submodule web-ui
updated
19 files
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
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,49 @@ | ||
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment'; | ||
import React, { type DetailedHTMLProps, type HTMLAttributes, useEffect } from 'react'; | ||
import type * as CodeInputNamespace from '@webcoder49/code-input/code-input'; | ||
import type * as PrismNamespace from 'prismjs'; | ||
import 'prismjs/themes/prism-okaidia.min.css'; | ||
import '@webcoder49/code-input/code-input.min.css'; | ||
|
||
let codeInput: typeof CodeInputNamespace; | ||
let Prism: typeof PrismNamespace; | ||
if (ExecutionEnvironment.canUseDOM) { | ||
// <code-input> can only be loaded inside the browser | ||
codeInput = require('@webcoder49/code-input/code-input'); | ||
Prism = require('prismjs'); | ||
require('@webcoder49/code-input/plugins/indent'); | ||
// HACK: <code-input> doesn't handle being loaded lazily (after window load) | ||
(codeInput as any).windowLoaded = true; | ||
} | ||
|
||
let codeInputInitialized = false; | ||
|
||
function initializeCodeInput() { | ||
if (codeInputInitialized) return; | ||
// Register our template | ||
codeInput.registerTemplate('syntax-highlighted', codeInput.templates.prism(Prism, [new codeInput.plugins.Indent(true, 4)])); | ||
codeInputInitialized = true; | ||
} | ||
|
||
export interface CodeInputElement extends CodeInputNamespace.CodeInput { | ||
value: string; | ||
} | ||
|
||
export interface Props extends DetailedHTMLProps<HTMLAttributes<CodeInputElement>, CodeInputElement> { | ||
template?: string; | ||
} | ||
|
||
declare module 'react' { | ||
namespace JSX { | ||
interface IntrinsicElements { | ||
'code-input': Props; | ||
} | ||
} | ||
} | ||
|
||
export function CodeInput(props: Props) { | ||
useEffect(() => { | ||
initializeCodeInput(); | ||
}, []); | ||
return <code-input template="syntax-highlighted" {...props}></code-input>; | ||
} |
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