Skip to content

Commit 75fb1ec

Browse files
committed
sm-hidden-portal 임시저장
1 parent c7c76cf commit 75fb1ec

File tree

4 files changed

+122
-0
lines changed

4 files changed

+122
-0
lines changed
2.28 MB
Loading
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import type { ArticleItem } from "@modules/article/types";
2+
import type { Category } from "@modules/category";
3+
import dayjs from "dayjs";
4+
import i1 from "./inject.png";
5+
6+
export const title = "`sm:hidden` 자식으로 있는 툴팁(Portal)도 숨기기";
7+
export const url = "https://springfall.cc/article/2025-07/sm-hidden-portal";
8+
export const summary =
9+
"Portal(툴팁 등)로 분리된 자식 컴포넌트가 부모의 숨김 상태(TailwindCSS sm:hidden)를 제대로 반영하지 못하는 문제를 트리키하게 해결하는 법을 알아봅니다.";
10+
11+
export const createdAt = dayjs("2025-07-21").toISOString();
12+
export const updatedAt = dayjs("2025-07-21").toISOString();
13+
export const image = i1;
14+
export const imageAlt = "TODO:이미지수정";
15+
export const category: Category = "기술";
16+
17+
export const item: ArticleItem = {
18+
createdAt,
19+
updatedAt,
20+
image,
21+
imageAlt,
22+
summary,
23+
title,
24+
url,
25+
category,
26+
tags: [],
27+
};
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import ArticleHeader from "@modules/article/ArticleHeader";
2+
import ArticleImage from "@modules/article/ArticleImage";
3+
import getArticleHeaderProps from "@modules/metadata/getArticleHeaderProps";
4+
import getArticleJsonLdProps from "@modules/metadata/getArticleJsonLdProps";
5+
import getArticleMetadata from "@modules/metadata/getArticleMetadata";
6+
import { ArticleJsonLd } from "next-seo";
7+
import { item } from "./metadata";
8+
import i1 from "./inject.png";
9+
10+
export const metadata = getArticleMetadata(item);
11+
12+
<ArticleJsonLd {...getArticleJsonLdProps(item)} />
13+
14+
<ArticleHeader {...getArticleHeaderProps(item)} />
15+
16+
<ArticleImage
17+
img={i1}
18+
border
19+
alt=""
20+
caption={<>일러스트 by ChatGPT TODO: 이미지 수정</>}
21+
/>
22+
23+
## 목차
24+
25+
## 요약
26+
27+
TailwindCSS에서 sm:hidden 클래스를 사용할 때
28+
29+
```tsx
30+
function TooltipContent({
31+
className,
32+
sideOffset = 0,
33+
children,
34+
arrowClassName,
35+
...props
36+
}: React.ComponentProps<typeof TooltipPrimitive.Content> & {
37+
arrowClassName?: string;
38+
}) {
39+
// !mark(1:2)
40+
const anchorId = React.useId();
41+
const contentId = React.useId();
42+
43+
return (
44+
// !mark(1)
45+
<>
46+
<TooltipPrimitive.Portal>
47+
<TooltipPrimitive.Content
48+
data-slot="tooltip-content"
49+
sideOffset={sideOffset}
50+
className={cn(
51+
"bg-brand-primary-700 animate-in fade-in-0 zoom-in-95 text-text-1 text-white",
52+
"data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95",
53+
"data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2",
54+
"data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
55+
"z-50 w-fit origin-(--radix-tooltip-content-transform-origin) px-3 py-1.5",
56+
"text-balance",
57+
className,
58+
)}
59+
{...props}
60+
id={contentId}
61+
>
62+
{children}
63+
<TooltipPrimitive.Arrow
64+
className={cn(
65+
"border-r-brand-primary-700 z-50 size-0 translate-y-[calc(-50%)] rotate-45 border-r-[10px] border-b-[10px] border-b-transparent",
66+
arrowClassName,
67+
)}
68+
/>
69+
{/* !mark(1:17) */}
70+
<style>
71+
{`
72+
body:has([data-show-desktop] #${anchorId}) #${contentId} {
73+
display: none;
74+
}
75+
76+
@media (min-width: 640px) {
77+
body:has([data-show-mobile] #${anchorId}) #${contentId} {
78+
display: none;
79+
}
80+
81+
body:has([data-show-desktop] #${anchorId}) #${contentId} {
82+
display: block;
83+
}
84+
}
85+
`}
86+
</style>
87+
</TooltipPrimitive.Content>
88+
</TooltipPrimitive.Portal>
89+
{/* !mark(1:2) */}
90+
<div id={anchorId} className="hidden"></div>
91+
</>
92+
);
93+
}
94+
```

src/modules/article/items.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ const items: ArticleItem[] = [
102102
ESLintForbidClassName,
103103
Fighting,
104104
NextjsInjectEnv,
105+
// SmHiddenPortal,
105106
];
106107

107108
items.sort((a, b) => dayjs(b.createdAt).diff(a.createdAt));

0 commit comments

Comments
 (0)