Skip to content

Commit

Permalink
i18n(ko-KR): update overriding-components.mdx (#2890)
Browse files Browse the repository at this point in the history
Co-authored-by: trueberryless <99918022+trueberryless@users.noreply.github.com>
  • Loading branch information
jsparkdev and trueberryless authored Feb 16, 2025
1 parent 5693268 commit 3780051
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions docs/src/content/docs/ko/guides/overriding-components.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ Starlight의 기본 컴포넌트를 재정의하는 것은 다음과 같은 경
```astro
---
// src/components/EmailLink.astro
import type { Props } from '@astrojs/starlight/props';
const email = 'houston@example.com';
---
<a href="mailto:houston@example.com">메일 보내기</a>
<a href=`mailto:${email}`>메일 보내기</a>
```

3. `astro.config.mjs` 파일의 [`components`](/ko/reference/configuration/#components) 구성 옵션에서 사용자 정의 컴포넌트를 사용하기 위한 설정을 추가합니다.
Expand Down Expand Up @@ -70,52 +71,47 @@ Starlight의 기본 UI 컴포넌트를 사용하여 나만의 컴포넌트를

아래 예시는 기존 `SocialIcons` 컴포넌트와 함께 이메일 링크를 렌더링하는 사용자 정의 컴포넌트를 나타냅니다.

```astro {4,8}
```astro {3,7}
---
// src/components/EmailLink.astro
import type { Props } from '@astrojs/starlight/props';
import Default from '@astrojs/starlight/components/SocialIcons.astro';
---
<a href="mailto:houston@example.com">메일 보내기</a>
<Default {...Astro.props}><slot /></Default>
<Default><slot /></Default>
```

사용자 정의 컴포넌트 내부에 내장 컴포넌트를 렌더링하는 경우:

- 전개 연산자를 사용하여 내장 컴포넌트에 `Astro.props`의 모든 속성을 전달합니다. 이를 통해, 내장 컴포넌트는 렌더링에 필요한 모든 데이터를 전달받습니다.
- 기본 컴포넌트 내에 [`<slot />`](https://docs.astro.build/ko/basics/astro-components/#슬롯)을 추가합니다. 이를 통해, 하위 컴포넌트를 전달받은 경우, Astro가 전달받은 컴포넌트를 렌더링할 위치를 알 수 있습니다.
사용자 정의 컴포넌트 내부에 내장 컴포넌트를 렌더링할 때 기본 컴포넌트 내부에 [`<slot />`](https://docs.astro.build/ko/basics/astro-components/#슬롯)을 추가하세요. 이렇게 하면 컴포넌트에 자식 요소가 전달될 경우 Astro가 해당 요소를 렌더링할 위치를 알 수 있습니다.

[명명된 슬롯](https://docs.astro.build/ko/basics/astro-components/#명명된-슬롯)이 포함된 [`PageFrame`](/ko/reference/overrides/#pageframe) 또는 [`TwoColumnContent`](/ko/reference/overrides/#twocolumncontent) 컴포넌트를 재사용하는 경우 이러한 슬롯도 [전송](https://docs.astro.build/ko/basics/astro-components/#슬롯-전송)해야 합니다.

아래 예시는 `TwoColumnContent` 컴포넌트를 재사용하는 사용자 정의 컴포넌트를 보여줍니다. 이 컴포넌트는 `right-sidebar`라는 이름의 추가 슬롯을 포함하여 전송합니다.

```astro {9}
```astro {8}
---
// src/components/CustomContent.astro
import type { Props } from '@astrojs/starlight/props';
import Default from '@astrojs/starlight/components/TwoColumnContent.astro';
---
<Default {...Astro.props}>
<Default>
<slot />
<slot name="right-sidebar" slot="right-sidebar" />
</Default>
```

## 페이지 데이터 사용

Starlight 컴포넌트를 재정의할 때, 사용자 정의 구현은 현재 페이지의 모든 데이터가 포함된 표준 `Astro.props` 객체를 전달받습니다.
Starlight 컴포넌트를 재정의할 때, 현재 페이지의 모든 데이터를 포함하는 전역 [`starlightRoute` 객체](/ko/guides/route-data/)에 접근할 수 있습니다.

전달받은 값을 사용하여 컴포넌트 템플릿이 렌더링되는 방식을 제어할 수 있습니다.

예를 들어, `Astro.props.entry.data`를 통해 페이지의 모든 프론트매터 속성을 읽을 수 있습니다. 다음 예시에서 대체 [`PageTitle`](/ko/reference/overrides/#pagetitle) 컴포넌트는 이를 사용하여 현재 페이지의 제목을 표시합니다.
다음 예제에서 대체된 [`PageTitle`](/ko/reference/overrides/#pagetitle) 컴포넌트는 콘텐츠 프런트매터에 설정된 현재 페이지의 제목을 표시합니다:

```astro {5} "{title}"
```astro {4} "{title}"
---
// src/components/Title.astro
import type { Props } from '@astrojs/starlight/props';
const { title } = Astro.props.entry.data;
const { title } = Astro.locals.starlightRoute.entry.data;
---
<h1 id="_top">{title}</h1>
Expand All @@ -127,28 +123,27 @@ const { title } = Astro.props.entry.data;
</style>
```

[재정의 참조](/ko/reference/overrides/#컴포넌트-속성)에서 사용 가능한 모든 속성에 대해 자세히 알아보세요.
[경로 데이터 참조](/ko/reference/route-data/)에서 사용 가능한 모든 속성에 대해 자세히 알아보세요.

### 특정 페이지 재정의

컴포넌트 재정의는 모든 페이지에 적용됩니다. 하지만, 사용자 정의 UI, Starlight의 기본 UI, 또는 완전히 다른 무언가가 나타나는 시기를 결정하기 위해 `Astro.props`의 값을 사용하여 조건부 렌더링이 가능합니다.
컴포넌트 재정의는 모든 페이지에 적용됩니다. 하지만, 사용자 정의 UI, Starlight의 기본 UI, 또는 완전히 다른 무언가가 나타나는 시기를 결정하기 위해 `starlightRoute`의 값을 사용하여 조건부 렌더링이 가능합니다.

다음 예시에서 Starlight의 [`Footer`](/ko/reference/overrides/#footer)를 재정의하는 컴포넌트는 "Starlight 🌟 를 사용하여 구축"을 홈페이지에만 표시하고, 다른 모든 페이지에는 기본 바닥글만 표시합니다.

```astro
---
// src/components/ConditionalFooter.astro
import type { Props } from '@astrojs/starlight/props';
import Default from '@astrojs/starlight/components/Footer.astro';
const isHomepage = Astro.props.id === '';
const isHomepage = Astro.locals.starlightRoute.id === '';
---
{
isHomepage ? (
<footer>Starlight 🌟 를 사용하여 구축</footer>
) : (
<Default {...Astro.props}>
<Default>
<slot />
</Default>
)
Expand Down

0 comments on commit 3780051

Please sign in to comment.