From 7b98712b5abd2479c960c8b2cca45f09fea20ecc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gromit=20=28=EC=A0=84=EB=AF=BC=EC=9E=AC=29?=
<64779472+ssi02014@users.noreply.github.com>
Date: Thu, 28 Nov 2024 02:31:17 +0900
Subject: [PATCH] =?UTF-8?q?fix:=20AspectRatio=20Slot=20=EB=B0=8F=20polymor?=
=?UTF-8?q?phicForwardRef=20=ED=99=9C=EC=9A=A9=EC=9D=84=20=ED=86=B5?=
=?UTF-8?q?=ED=95=9C=20=EB=8B=A4=ED=98=95=EC=84=B1=20=EC=A7=80=EC=9B=90=20?=
=?UTF-8?q?(#609)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* fix: AspectRatio Slot 및 polymorphicForwardRef 적용
* chore: changesetlog
* fix: 문서 수정
* docs: ts-doc 수정
---
.changeset/pretty-windows-sort.md | 5 +
docs/docs/react/components/AspectRatio.mdx | 88 ++++++++++++--
docs/docs/react/components/InView.mdx | 108 ++++++++++--------
docs/docs/react/components/Slot.mdx | 56 ++++++++-
packages/react/package.json | 2 +-
.../AspectRatio/AspectRatio.modules.css | 4 +
.../AspectRatio/AspectRatio.spec.tsx | 34 +++++-
.../src/components/AspectRatio/index.tsx | 73 +++++++++---
.../src/components/InView/InView.spec.tsx | 24 ++++
.../react/src/components/InView/index.tsx | 42 +++++--
packages/react/src/components/Slot/index.tsx | 34 +++++-
.../react/src/utils/polymorphicForwardRef.tsx | 54 +++++----
12 files changed, 415 insertions(+), 109 deletions(-)
create mode 100644 .changeset/pretty-windows-sort.md
create mode 100644 packages/react/src/components/AspectRatio/AspectRatio.modules.css
diff --git a/.changeset/pretty-windows-sort.md b/.changeset/pretty-windows-sort.md
new file mode 100644
index 000000000..e14013771
--- /dev/null
+++ b/.changeset/pretty-windows-sort.md
@@ -0,0 +1,5 @@
+---
+'@modern-kit/react': minor
+---
+
+feat(react): AspectRatio Slot 및 polymorphicForwardRef 활용을 통한 다형성 지원 - @ssi02014
diff --git a/docs/docs/react/components/AspectRatio.mdx b/docs/docs/react/components/AspectRatio.mdx
index 432e7d27b..1bf68cfa1 100644
--- a/docs/docs/react/components/AspectRatio.mdx
+++ b/docs/docs/react/components/AspectRatio.mdx
@@ -3,10 +3,18 @@ import { AspectRatio } from '@modern-kit/react';
# AspectRatio
-주어진 **[aspect-ratio](https://developer.mozilla.org/en-US/docs/Web/CSS/aspect-ratio)** 비율을 맞춰주기 위해 선언적으로 사용하는 유틸 컴포넌트입니다.
+주어진 **[aspect-ratio](https://developer.mozilla.org/en-US/docs/Web/CSS/aspect-ratio)** 비율을 맞춰주기 위해 선언적으로 사용하는 유틸 컴포넌트입니다.
미리 영역을 확보하여 `Layout Shift`를 방지하는데 효과적입니다.
+다형성을 지원하기 때문에 `as`, `asChild` 속성을 지원합니다.
+
+- 기본적으로 `div` 태그로 자식 요소를 감싸서 렌더링하며, `as` 속성을 통해 감싸는 요소를 특정 요소로 변경해 렌더링할 수 있습니다. 해당 요소에 `aspect-ratio` 속성을 적용해 영역을 확보합니다.
+- `asChild` 속성이 `true`라면 **[Slot](https://modern-agile-team.github.io/modern-kit/docs/react/components/Slot)** 을 통해 자식 요소를 그대로 렌더링하고, 자식 요소에 `aspect-ratio` 속성을 적용해 영역을 확보합니다.
+ - Slot은 자식으로 `단일 요소`만 허용됩니다.
+ - Slot은 자식으로 컴포넌트가 올 경우 `forwardRef`, `props`를 허용해야 합니다. 허용하지 않으면 정상적으로 동작하지 않습니다.
+ - `asChild` 속성을 사용 할 경우 **[Slot](https://modern-agile-team.github.io/modern-kit/docs/react/components/Slot)** 문서를 참고해주세요.
+
## Code
@@ -17,36 +25,100 @@ import { AspectRatio } from '@modern-kit/react';
interface AspectRatioProps {
children: JSX.Element;
ratio: number;
+ asChild?: boolean;
+ style?: CSSProperties;
+ className?: string;
}
```
```tsx title="typescript"
-const AspectRatio: ({ ratio, children }: AspectRatioProps) => JSX.Element;
+const AspectRatio: PolyForwardComponent<"div", AspectRatioProps, React.ElementType>
```
## Usage
+### Default
+- 기본적으로 `div` 요소에 감싸지며 해당 `div`에 `aspect-ratio` 속성을 적용해 영역을 확보합니다.
```tsx title="typescript"
import { AspectRatio } from '@modern-kit/react'
const Example = () => {
+ const imgUrl = 'https://github.com/user-attachments/assets/dd60ec12-afd7-44c9-bd6b-0069e16bf2c9';
+
return (
-
스크롤 해주세요.
+브라우저 개발자 도구의 콘솔을 확인해주세요.
Box1
-브라우저 개발자 도구의 콘솔을 확인해주세요.
calledOnce: true
as: div
Box3
+calledOnce: false
+asChild: true
+Content
Content
+Content
+