@@ -145,17 +145,62 @@ This package contains the global type files for React.
145145
146146``` tsx
147147// CodeBlock.tsx
148- import React , {useEffect , CodeBlockHTMLAttributes } from ' react' ;
148+ import {CodeBlockProps } from ' @heppokofrontend/html-code-block-element/dist/manual' ;
149+ import styleSheet from ' @heppokofrontend/html-code-block-element/dist/styleSheet' ;
150+ import hljs from ' highlight.js/lib/common' ;
151+ import Head from ' next/head' ;
152+ import {useEffect } from ' react' ;
153+
154+ declare module ' react' {
155+ // A type for the properties of a function component
156+ interface CodeBlockHTMLAttributes <T > extends HTMLAttributes <T > {
157+ /** The accessible name of code block */
158+ label? : string | undefined ;
159+ /** The Language name */
160+ language? : string | undefined ;
161+ /** The flag to display the UI */
162+ controls? : boolean ;
163+ }
164+ }
165+
166+ declare global {
167+ // A type for JSX markup
168+ namespace JSX {
169+ interface IntrinsicElements {
170+ ' code-block' : CodeBlockProps ;
171+ }
172+ }
173+ }
149174
150- export const CodeBlock: React .FC <CodeBlockHTMLAttributes <HTMLElement >> = ({
151- children ,
152- ... props
153- }) => {
175+ type Props = Omit <React .CodeBlockHTMLAttributes <HTMLElement >, ' className' >;
176+
177+ export const CodeBlock = ({children , ... props }: Props ) => {
154178 useEffect (() => {
155- import (` @heppokofrontend/html-code-block-element ` );
156- });
179+ const loadWebComponent = async () => {
180+ // import('@heppokofrontend/html-code-block-element');
181+ const {HTMLCodeBlockElement, createHighlightCallback} = await import (
182+ ' @heppokofrontend/html-code-block-element/dist/manual'
183+ );
184+
185+ if (customElements .get (' code-block' )) {
186+ return ;
187+ }
188+
189+ HTMLCodeBlockElement .highlight = createHighlightCallback (hljs );
190+ customElements .define (' code-block' , HTMLCodeBlockElement );
191+ };
157192
158- return <code-block { ... props } >{ children } </code-block >;
193+ loadWebComponent ();
194+ }, []);
195+
196+ return (
197+ <>
198+ <Head >
199+ <style >{ styleSheet } </style >
200+ </Head >
201+ <code-block { ... props } >{ children } </code-block >
202+ </>
203+ );
159204};
160205```
161206
0 commit comments