Skip to content

Commit 5c10649

Browse files
committed
wip
1 parent f2269f8 commit 5c10649

File tree

2 files changed

+55
-5
lines changed

2 files changed

+55
-5
lines changed

src/components/index-page/data-colocation/data-colocation.css

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
.sector-opacity {
22
& [data-sector] {
3-
transition: opacity 0.2s ease-out;
3+
transition: opacity 0.2s ease-in;
4+
transition-delay: 0.1s;
45
}
56

67
[data-active-sector] & [data-sector] {
78
opacity: 0.4;
9+
transition-delay: 0s;
10+
transition-timing-function: ease-out;
811
}
912

1013
[data-active-sector="1"] & [data-sector="1"],
@@ -20,6 +23,6 @@
2023
[data-active-sector="2"] & [data-sector="2"],
2124
[data-active-sector="3"] & [data-sector="3"],
2225
[data-active-sector="4"] & [data-sector="4"] {
23-
@apply ring-2 ring-neu-500 ring-offset-2;
26+
@apply ring-2 ring-neu-500 ring-offset-2 dark:ring-neu-400 dark:ring-offset-neu-0;
2427
}
2528
}

src/components/index-page/data-colocation/index.tsx

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { clsx } from "clsx"
22
import { Code } from "nextra/components"
3-
import { ComponentPropsWithoutRef, useRef } from "react"
3+
import {
4+
cloneElement,
5+
ComponentPropsWithoutRef,
6+
ReactElement,
7+
useRef,
8+
} from "react"
49

510
import { Pre } from "@/components/pre"
611
import { SectionLabel } from "@/app/conf/_design-system/section-label"
@@ -13,6 +18,7 @@ import json from "./data-colocation.json"
1318
import Query from "./data-colocation.mdx"
1419
import "./data-colocation.css"
1520
import { useOnClickOutside } from "@/app/conf/_design-system/utils/useOnClickOutside"
21+
import React from "react"
1622

1723
const components = {
1824
pre: (props: ComponentPropsWithoutRef<typeof Pre>) => (
@@ -21,12 +27,53 @@ const components = {
2127
// todo: this bg style might need to become global for all code blocks
2228
className={clsx(
2329
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",
2531
)}
2632
tabIndex={-1}
2733
/>
2834
),
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+
)
3077
}
3178

3279
export function DataColocation() {

0 commit comments

Comments
 (0)