File tree Expand file tree Collapse file tree 2 files changed +13
-5
lines changed
frontend/packages/components/src/mdx Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -11,8 +11,12 @@ import { toast } from "sonner";
1111export const CopyCodeTrigger = forwardRef < HTMLElement , PropsWithChildren > (
1212 ( { children } , ref ) => {
1313 const handleClick : MouseEventHandler = ( event ) => {
14+ const codeGroup = event . currentTarget . closest ( "[data-code-group]" ) ;
15+
1416 const code =
15- event . currentTarget . closest < HTMLDivElement > ( ".code" ) ?. innerText ;
17+ codeGroup ?. querySelector ( "[data-state=active] .code" )
18+ ?. textContent ||
19+ codeGroup ?. querySelector ( ".code" ) ?. textContent ;
1620
1721 if ( ! code ) {
1822 toast . error ( "No code to copy" ) ;
Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ export function CodeGroup({ children, className }: CodeGroupProps) {
5151 "code-group group my-4 rounded-md border pt-2" ,
5252 className ,
5353 ) }
54+ data-code-group
5455 >
5556 < Tabs defaultValue = { getChildIdx ( children [ 0 ] ) } >
5657 < div className = "flex gap-1 border-b pr-2" >
@@ -119,15 +120,18 @@ export const pre = ({
119120 isInGroup,
120121} : PreProps ) => {
121122 return (
122- < div className = "not-prose my-4 rounded-md border group-[.code-group]:my-0 group-[.code-group]:-mt-2 group-[.code-group]:border-none" >
123+ < div
124+ className = "not-prose my-4 rounded-md border group-[.code-group]:my-0 group-[.code-group]:-mt-2 group-[.code-group]:border-none"
125+ data-code-group
126+ >
123127 { ! file && isInGroup ? null : (
124128 < div className = "text-foreground flex items-center justify-between gap-2 border-b p-2 text-xs" >
125129 < div className = "text-muted-foreground flex items-center gap-1" >
126130 { file ? (
127- < >
128- < Icon icon = { faFile } className = "block " />
131+ < Badge variant = "outline" >
132+ < Icon icon = { faFile } className = "mr-1 " />
129133 < span > { file } </ span >
130- </ >
134+ </ Badge >
131135 ) : isInGroup ? null : (
132136 < Badge variant = "outline" >
133137 { title || languageNames [ language || "cpp" ] }
You can’t perform that action at this time.
0 commit comments