generated from timelessco/next-ts-app-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(codeblock): ✨ add finished codeblock to mdx components
- Loading branch information
1 parent
d6b385c
commit 0e3660e
Showing
15 changed files
with
351 additions
and
180 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,25 @@ | ||
import { Button } from "@adaptui/react-tailwind"; | ||
import { useClipboard } from "@chakra-ui/hooks"; | ||
|
||
import { CopiedIcon, CopyIcon } from "./Icons"; | ||
import { CopyButton } from "./CopyButton"; | ||
import { Tooltip, TooltipProps } from "./Tooltip"; | ||
|
||
export type ClipboardCopyButtonProps = { | ||
export type ClipboardCopyButtonProps = TooltipProps & { | ||
content: string; | ||
}; | ||
|
||
export const ClipboardCopyButton: React.FC<ClipboardCopyButtonProps> = ({ | ||
content, | ||
...props | ||
}) => { | ||
const { hasCopied, onCopy } = useClipboard(content); | ||
|
||
return ( | ||
<Button | ||
size="sm" | ||
onClick={onCopy} | ||
iconOnly={hasCopied ? <CopiedIcon /> : <CopyIcon />} | ||
<Tooltip | ||
withArrow | ||
placement="left" | ||
anchor={<CopyButton hasCopied={hasCopied} onCopy={onCopy} />} | ||
content={hasCopied ? "Copied!" : "Copy"} | ||
{...props} | ||
/> | ||
); | ||
}; | ||
|
||
export default ClipboardCopyButton; |
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
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,15 @@ | ||
export const transformer = (rawCode: any, noInline: any) => { | ||
const code = rawCode | ||
// remove imports | ||
.replace(/((^|)import[^;]+[; ]+)+/gi, "") | ||
// replace `export default => {*};` with `render(() => {*});` | ||
.replace(/export default \(\) => {((.|\n)*)};/, "render(() => {$1});") | ||
// replace `export default => (*);` with `render(*);` | ||
.replace(/export default \(\) => \(((.|\n)*)\);/, "render($1);") | ||
// replace `export default => *;` with `render(*);` | ||
.replace(/export default \(\) => ((.|\n)*);/, "render($1);") | ||
.replace(/export const App = ((.|\n)*);/, "render($1);") | ||
.replace(/export default ((.|\n)*);/, "render($1);"); | ||
|
||
return !noInline ? `<>${code}</>` : code; | ||
}; |
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,25 @@ | ||
import React, { forwardRef } from "react"; | ||
import { Button, ButtonProps } from "@adaptui/react-tailwind"; | ||
|
||
import { CopiedIcon, CopyIcon } from "./Icons"; | ||
|
||
export type CopyButtonProps = ButtonProps & { | ||
hasCopied: boolean; | ||
onCopy: () => void; | ||
}; | ||
|
||
export const CopyButton = forwardRef<HTMLButtonElement, CopyButtonProps>( | ||
(props, ref) => { | ||
const { onCopy, hasCopied, ...rest } = props; | ||
|
||
return ( | ||
<Button | ||
ref={ref} | ||
size="sm" | ||
onClick={onCopy} | ||
iconOnly={hasCopied ? <CopiedIcon /> : <CopyIcon />} | ||
{...rest} | ||
/> | ||
); | ||
}, | ||
); |
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,15 @@ | ||
import { CopyCodeBlockButton } from "./Codeblock/CopyCodeBlockButton"; | ||
|
||
export const Pre = (props: { children?: React.ReactNode }) => { | ||
const { children, ...rest } = props; | ||
console.log("%cprops", "color: #00ff88", props); | ||
|
||
return ( | ||
<div className="relative"> | ||
<pre {...rest}> | ||
<>{children}</> | ||
</pre> | ||
<CopyCodeBlockButton code={"copy"} /> | ||
</div> | ||
); | ||
}; |
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,16 @@ | ||
import * as React from "react"; | ||
import { | ||
Tooltip as AdaptTooltip, | ||
TooltipProps as AdaptTooltipProps, | ||
TooltipWrapper, | ||
} from "@adaptui/react-tailwind"; | ||
|
||
export type TooltipProps = AdaptTooltipProps & {}; | ||
|
||
export const Tooltip: React.FC<TooltipProps> = props => { | ||
return ( | ||
<AdaptTooltip {...props}> | ||
<TooltipWrapper style={{ zIndex: 9999 }} /> | ||
</AdaptTooltip> | ||
); | ||
}; |
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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
export * from "./ClipBoardCopyButton"; | ||
export * from "./Codeblock"; | ||
export * from "./ComponentLinks"; | ||
export * from "./InteractiveCodeblock"; | ||
export * from "./Pre"; | ||
export * from "./PropsTable"; | ||
export * from "./RegionTable"; | ||
export * from "./Tooltip"; |
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
Oops, something went wrong.