Files
eh-downloader/components/StyleSheet.tsx
2023-05-26 13:31:28 +08:00

22 lines
661 B
TypeScript

import { asset } from "$fresh/runtime.ts";
import { Component, ContextType } from "preact";
import { GlobalCtx } from "./GlobalContext.tsx";
export type StyleSheetType = {
href: string;
};
export default class StyleSheet extends Component<StyleSheetType, unknown> {
static contextType = GlobalCtx;
declare context: ContextType<typeof GlobalCtx>;
render() {
const href = this.props.href;
if (this.context) {
const sheets = this.context.stylesheets;
if (sheets.has(href)) return null;
sheets.add(href);
}
return <link rel="stylesheet" href={asset(this.props.href)} />;
}
}