🐛 fix asciinema ssr failed

This commit is contained in:
yanyongyu
2022-01-30 18:26:26 +08:00
parent 60ccdf8a7a
commit c7883863c7
7 changed files with 51 additions and 38 deletions

View File

@@ -0,0 +1,35 @@
import * as AsciinemaPlayer from "asciinema-player";
import React, { useEffect, useRef } from "react";
export type AsciinemaOptions = {
cols: number;
rows: number;
autoPlay: boolean;
preload: boolean;
loop: boolean;
startAt: number | string;
speed: number;
idleTimeLimit: number;
theme: string;
poster: string;
fit: string;
fontSize: string;
};
export type AsciinemaProps = {
url: string;
options?: Partial<AsciinemaOptions>;
};
export default function AsciinemaContainer({
url,
options = {},
}: AsciinemaProps): JSX.Element {
const ref = useRef<HTMLDivElement>(null);
useEffect(() => {
AsciinemaPlayer.create(url, ref.current, options);
}, []);
return <div ref={ref} className="not-prose w-full max-w-full my-4"></div>;
}