Skip to content

Commit 5887575

Browse files
committed
Bugfix mobile Data Colocation section
1 parent 668991d commit 5887575

File tree

4 files changed

+29
-20
lines changed

4 files changed

+29
-20
lines changed

src/app/conf/_design-system/utils/useOnClickOutside.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import { useEffect } from "react"
22

33
export function useOnClickOutside(
4-
ref: React.RefObject<HTMLElement | null>,
4+
refs: React.RefObject<HTMLElement | null>[],
55
handler: (event: MouseEvent) => void,
66
) {
77
useEffect(() => {
88
const listener = (event: MouseEvent) => {
9-
if (ref.current && event.composedPath().includes(ref.current)) {
9+
const path = event.composedPath()
10+
if (refs.every(ref => !ref.current || !path.includes(ref.current))) {
11+
console.log("clicked outside", refs)
12+
handler(event)
1013
return
1114
}
12-
handler(event)
15+
console.log("clicked inside", refs)
1316
}
1417

1518
document.addEventListener("click", listener)

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
import ModemIcon from "@/app/conf/_design-system/pixelarticons/modem.svg?svgr"
22
import clsx from "clsx"
3+
import { forwardRef } from "react"
34

45
const INNER_BOX_SIZE = 16
56

67
interface ComponentTreeProps extends React.HTMLAttributes<HTMLDivElement> {
78
names: [string, string, string, string]
89
}
910

10-
export function ComponentTree({
11-
names,
12-
className,
13-
...rest
14-
}: ComponentTreeProps) {
11+
export const ComponentTree = forwardRef(function ComponentTree(
12+
{ names, className, ...rest }: ComponentTreeProps,
13+
ref: React.Ref<HTMLDivElement>,
14+
) {
1515
return (
1616
<div
17+
ref={ref}
1718
className={clsx(
1819
"sector-opacity mx-auto flex max-w-[500px] justify-between [--gap-x:20px] md:gap-x-10 md:[--gap-x:32px] 3xl:gap-x-20",
1920
className,
@@ -57,7 +58,7 @@ export function ComponentTree({
5758
className="flex size-12 items-center justify-center bg-neu-100 dark:bg-neu-50"
5859
data-sector="1"
5960
>
60-
<ModemIcon className="size-6 text-neu-600" />
61+
<ModemIcon className="pointer-events-none size-6 text-neu-600" />
6162
</div>
6263

6364
<div className="h-4 w-px bg-neu-300 dark:bg-neu-100" />
@@ -107,7 +108,7 @@ export function ComponentTree({
107108
</div>
108109
</div>
109110
)
110-
}
111+
})
111112

112113
interface NestedBoxProps extends React.HTMLAttributes<HTMLDivElement> {
113114
bgColor: string

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@
2727
[data-active-sector="2"] & [data-sector="2"],
2828
[data-active-sector="3"] & [data-sector="3"],
2929
[data-active-sector="4"] & [data-sector="4"] {
30-
@apply ring-2 ring-neu-500 duration-200 ease-out dark:ring-neu-400 dark:ring-offset-neu-0;
30+
@apply ring-2 ring-neu-500 ring-offset-neu-0 duration-200 ease-out dark:ring-neu-400;
3131
}
3232
}

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export function DataColocation() {
109109
const sectorElement = target?.closest("[data-sector]") as HTMLElement | null
110110
const sector = sectorElement?.dataset.sector
111111

112-
if (!sector) return
112+
if (sector == null) return
113113

114114
const currentTarget = event.currentTarget
115115

@@ -119,7 +119,6 @@ export function DataColocation() {
119119
}
120120

121121
const unmarkSector = (event: React.MouseEvent<HTMLElement>) => {
122-
console.log("unmarkSector", window.matchMedia("(hover: none)").matches)
123122
if (window.matchMedia("(hover: none)").matches) return
124123

125124
const target =
@@ -143,17 +142,19 @@ export function DataColocation() {
143142
currentTarget.dataset.activeSector = targetSector
144143
}
145144

146-
const ref = useRef<HTMLDivElement>(null)
147-
useOnClickOutside(ref, event => {
148-
console.log("clicked outside")
149-
if (event.currentTarget && event.currentTarget instanceof HTMLElement) {
150-
delete event.currentTarget.dataset.activeSector
145+
const sectionRef = useRef<HTMLElement>(null)
146+
const figureRef = useRef<HTMLElement>(null)
147+
const componentTreeRef = useRef<HTMLDivElement>(null)
148+
useOnClickOutside([figureRef, componentTreeRef], () => {
149+
const section = sectionRef.current
150+
if (section && section.dataset.activeSector) {
151+
delete section.dataset.activeSector
151152
}
152153
})
153154

154155
return (
155156
<section
156-
ref={ref}
157+
ref={sectionRef}
157158
className="gql-container gql-section flex flex-wrap justify-between gap-4 sm:max-xl:gap-y-8 xl:p-24"
158159
onMouseOver={markSector}
159160
onMouseOut={unmarkSector}
@@ -169,6 +170,7 @@ export function DataColocation() {
169170
</p>
170171
</header>
171172
<ComponentTree
173+
ref={componentTreeRef}
172174
className="mt-6 md:mt-8 lg:mt-12 xl:mt-16"
173175
names={[
174176
"Server",
@@ -178,7 +180,10 @@ export function DataColocation() {
178180
]}
179181
/>
180182
</div>
181-
<article className="flex flex-wrap divide-neu-100 dark:divide-neu-50 dark:shadow-[0_.5px_20px_0_hsl(0_0_0/.25)] max-xl:w-full max-lg:gap-4 lg:shadow-[0_.5px_20px_0_hsl(var(--color-neu-400))] lg:dark:bg-neu-50/10 xl:divide-x xl:rounded-lg">
183+
<article
184+
className="flex flex-wrap divide-neu-100 dark:divide-neu-50 dark:shadow-[0_.5px_20px_0_hsl(0_0_0/.25)] max-xl:w-full max-lg:gap-4 lg:shadow-[0_.5px_20px_0_hsl(var(--color-neu-400))] lg:dark:bg-neu-50/10 xl:divide-x xl:rounded-lg"
185+
ref={figureRef}
186+
>
182187
<div className="flex grow flex-col gap-y-4 lg:flex-col-reverse lg:p-4">
183188
<FigureInfo />
184189
<div className="sector-ring">

0 commit comments

Comments
 (0)