Skip to content

Commit 4887f70

Browse files
committed
Count curlies
1 parent 5c10649 commit 4887f70

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@
1919
}
2020

2121
.sector-ring {
22+
& [data-sector] {
23+
@apply ring-2 ring-transparent ring-offset-2 ring-offset-transparent transition-shadow duration-200 ease-in;
24+
}
25+
2226
[data-active-sector="1"] & [data-sector="1"],
2327
[data-active-sector="2"] & [data-sector="2"],
2428
[data-active-sector="3"] & [data-sector="3"],
2529
[data-active-sector="4"] & [data-sector="4"] {
26-
@apply ring-2 ring-neu-500 ring-offset-2 dark:ring-neu-400 dark:ring-offset-neu-0;
30+
@apply ring-2 ring-neu-500 duration-200 ease-out dark:ring-neu-400 dark:ring-offset-neu-0;
2731
}
2832
}

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

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as React from "react"
12
import { clsx } from "clsx"
23
import { Code } from "nextra/components"
34
import {
@@ -18,7 +19,13 @@ import json from "./data-colocation.json"
1819
import Query from "./data-colocation.mdx"
1920
import "./data-colocation.css"
2021
import { useOnClickOutside } from "@/app/conf/_design-system/utils/useOnClickOutside"
21-
import React from "react"
22+
23+
const highlightedFragments = {
24+
GetFriendList: 1,
25+
FriendList: 2,
26+
FriendListItem: 3,
27+
FriendInfo: 4,
28+
}
2229

2330
const components = {
2431
pre: (props: ComponentPropsWithoutRef<typeof Pre>) => (
@@ -33,10 +40,14 @@ const components = {
3340
/>
3441
),
3542
code: ({ children, ...rest }: ComponentPropsWithoutRef<typeof Code>) => {
43+
let sectorIndex: number | undefined
44+
let depth = 0
45+
3646
if (children) {
3747
children = React.Children.map(children, child => {
3848
if (isSpanElement(child)) {
3949
let children = (child as ReactElement).props.children
50+
4051
if (isSpanElement(children)) {
4152
children = children.props.children
4253
} else if (Array.isArray(children)) {
@@ -48,17 +59,31 @@ const components = {
4859
return child
4960
})
5061
.join("")
62+
}
5163

52-
if (children.includes("fragment FriendInfo")) {
53-
return cloneElement(child, {
54-
...child.props,
55-
"data-sector": "4",
56-
} as React.HTMLAttributes<HTMLSpanElement>)
64+
if (/query|fragment/.test(children)) {
65+
for (const [name, index] of Object.entries(highlightedFragments)) {
66+
if (children.includes(` ${name} `)) sectorIndex = index
67+
depth++
5768
}
5869
}
5970

71+
if (children.includes("{")) depth++
72+
if (children.includes("}")) {
73+
depth--
74+
if (depth === 0) sectorIndex = undefined
75+
}
76+
77+
if (sectorIndex) {
78+
return cloneElement(child, {
79+
...child.props,
80+
"data-sector": sectorIndex,
81+
} as React.HTMLAttributes<HTMLSpanElement>)
82+
}
83+
6084
return child
6185
}
86+
6287
return child
6388
})
6489
}

0 commit comments

Comments
 (0)