1
1
import { clsx } from "clsx"
2
2
import { Code } from "nextra/components"
3
- import { ComponentPropsWithoutRef , useRef } from "react"
3
+ import {
4
+ cloneElement ,
5
+ ComponentPropsWithoutRef ,
6
+ ReactElement ,
7
+ useRef ,
8
+ } from "react"
4
9
5
10
import { Pre } from "@/components/pre"
6
11
import { SectionLabel } from "@/app/conf/_design-system/section-label"
@@ -13,6 +18,7 @@ import json from "./data-colocation.json"
13
18
import Query from "./data-colocation.mdx"
14
19
import "./data-colocation.css"
15
20
import { useOnClickOutside } from "@/app/conf/_design-system/utils/useOnClickOutside"
21
+ import React from "react"
16
22
17
23
const components = {
18
24
pre : ( props : ComponentPropsWithoutRef < typeof Pre > ) => (
@@ -21,12 +27,53 @@ const components = {
21
27
// todo: this bg style might need to become global for all code blocks
22
28
className = { clsx (
23
29
props . className ,
24
- "!border-none pr-4 leading-[1.459em] backdrop-blur-[6px] max-xs:leading-[16px] max-xs:[&_span]:!text-xs" ,
30
+ "sector-opacity !border-none pr-4 leading-[1.459em] backdrop-blur-[6px] max-xs:leading-[16px] max-xs:[&_span]:!text-xs" ,
25
31
) }
26
32
tabIndex = { - 1 }
27
33
/>
28
34
) ,
29
- code : Code ,
35
+ code : ( { children, ...rest } : ComponentPropsWithoutRef < typeof Code > ) => {
36
+ if ( children ) {
37
+ children = React . Children . map ( children , child => {
38
+ if ( isSpanElement ( child ) ) {
39
+ let children = ( child as ReactElement ) . props . children
40
+ if ( isSpanElement ( children ) ) {
41
+ children = children . props . children
42
+ } else if ( Array . isArray ( children ) ) {
43
+ children = children
44
+ . map ( child => {
45
+ if ( isSpanElement ( child ) ) {
46
+ return child . props . children
47
+ }
48
+ return child
49
+ } )
50
+ . join ( "" )
51
+
52
+ if ( children . includes ( "fragment FriendInfo" ) ) {
53
+ return cloneElement ( child , {
54
+ ...child . props ,
55
+ "data-sector" : "4" ,
56
+ } as React . HTMLAttributes < HTMLSpanElement > )
57
+ }
58
+ }
59
+
60
+ return child
61
+ }
62
+ return child
63
+ } )
64
+ }
65
+ return < Code { ...rest } > { children } </ Code >
66
+ } ,
67
+ }
68
+
69
+ function isSpanElement (
70
+ child : React . ReactNode ,
71
+ ) : child is ReactElement < { children : React . ReactNode } > {
72
+ return (
73
+ typeof child === "object" &&
74
+ ! ! child &&
75
+ ( child as ReactElement ) . type === "span"
76
+ )
30
77
}
31
78
32
79
export function DataColocation ( ) {
0 commit comments