-
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: typescript support and AsciinemaPlayer component
Adds support for typescript and the AsciinemaPlayer component.
- Loading branch information
Showing
6 changed files
with
234 additions
and
2 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
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,43 @@ | ||
// @ts-check | ||
// This react component is based on the excellent code at: | ||
// https://github.com/asciinema/asciinema-player/issues/72 | ||
// Props to https://github.com/dunnkers | ||
|
||
import React, { useEffect, useRef } from 'react'; | ||
import * as AsciinemaPlayerLibrary from 'asciinema-player'; | ||
|
||
type AsciinemaPlayerProps = { | ||
src: string; | ||
style: React.CSSProperties; | ||
// START asciinemaOptions | ||
cols: string; | ||
rows: string; | ||
autoPlay: boolean | ||
preload: boolean; | ||
loop: boolean | number; | ||
startAt: number | string; | ||
speed: number; | ||
idleTimeLimit: number; | ||
theme: string; | ||
poster: string; | ||
fit: string; | ||
fontSize: string; | ||
// END asciinemaOptions | ||
}; | ||
|
||
const AsciinemaPlayer: React.FC<AsciinemaPlayerProps> = ({ | ||
src, | ||
style, | ||
...asciinemaOptions | ||
}) => { | ||
const ref = useRef<HTMLDivElement>(null); | ||
|
||
useEffect(() => { | ||
const currentRef = ref.current; | ||
AsciinemaPlayerLibrary.create(src, currentRef, asciinemaOptions); | ||
}, [src]); | ||
|
||
return <div ref={ref} style={style} />; | ||
}; | ||
|
||
export default AsciinemaPlayer; |
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,3 @@ | ||
{ | ||
"extends": "@tsconfig/docusaurus/tsconfig.json" | ||
} |