Primer::LayoutComponent에서 이전하기
Primer::LayoutComponent에서 이전하기 (Moving Away From Primer::LayoutComponent)
이 가이드는 이제 deprecated된 Primer::LayoutComponent에서 최신 Primer::Alpha::Layout 컴포넌트로 업그레이드하는 방법을 보여줍니다.
출처: 문서
본문
이 가이드는 이제 deprecated된 Primer::LayoutComponent에서 최신 Primer::Alpha::Layout 컴포넌트로 업그레이드하는 방법을 보여줍니다.
기능과 예시 (Features and Examples)
Primer::Alpha::Layout은 일부 인자를 deprecated시키고 몇 가지 새로운 기능도 제공합니다.
사이드바 너비 (Sidebar width)
deprecated된 Primer::LayoutComponent은 사이드바 너비를 열(column) 수의 정수로 구성합니다. Primer::Alpha::Layout에서는 사이드바 너비를 :default, :narrow, :wide 중 하나로 설정합니다. 이 값들은 레이아웃의 breakpoint에 따라 달라지는 숫자에 대응합니다. 특정 breakpoint 너비는 컴포넌트 문서를 참고하세요.
예를 들어, 더 좁은 사이드바를 만들려면:
<%= render(Primer::Alpha::Layout.new) do |component| %>
<% component.with_main { "Main" } %>
<% component.with_sidebar(width: :narrow) { "Sidebar" } %>
<% end %>
사이드바 배치 (Sidebar placement)
사이드바 배치는 이전에는 :left 또는 :right로만 제한되었습니다. 여전히 그렇게 구성할 수 있지만, 이제 행 모드(row mode)로 전환될 때 사이드바가 메인 콘텐츠 위에 있을지 아래에 있을지도 구성할 수 있습니다.
예를 들어, 이전에 사이드바가 왼쪽에 있었고, 페이지가 행 모드로 전환될 때 메인 콘텐츠 위에 오길 원한다고 가정해 봅시다.
Primer::LayoutComponent에서는 아마 이렇게 했을 것입니다:
<%= render(Primer::LayoutComponent.new(side: :left)) do |component| %>
<% component.with_sidebar { "Sidebar" } %>
<% component.with_main { "Main" } %>
<% end %>
Primer::Alpha::Layout로 마이그레이션할 때는 이렇게 시도할 수 있습니다:
<%= render(Primer::Alpha::Layout.new) do |component| %>
<% component.with_main { "Main" } %>
<% component.with_sidebar(col_placement: :start, row_placement: :start) { "Sidebar" } %>
<% end %>
사이드바를 메인 콘텐츠 아래에 유지하려면 row_placement: :end로 설정하거나, row_placement: :none으로 완전히 숨길 수 있었을 것입니다.
키보드 순서 재정렬 (Reordering keyboard order)
접근성 이유로 키보드 내비게이션의 포커스 순서를 수동으로 설정하고 싶을 수 있습니다. Primer::LayoutComponent에서는 소스에서 컴포넌트 순서를 바꿀 수 있지만, Primer::Alpha::LayoutComponent는 first_in_source 인자(:main 또는 :sidebar)로 이를 덮어쓸 수 있습니다.
예를 들어, 키보드 포커스가 항상 메인 콘텐츠 전에 사이드바를 먼저 방문하도록 하려면:
<%= render(Primer::Alpha::Layout.new(first_in_source: :sidebar)) do |component| %>
<% component.with_main { "Main" } %>
<% component.with_sidebar { "Sidebar" } %>
<% end %>
반응형 제어를 위한 특정 중단점 (Specific breakpoints to control responsiveness)
이전에는 Primer::LayoutComponent가 breakpoint를 활성화하기 위해 responsiveness: true만 제공했습니다. 이제 stacking_breakpoint 인자를 :sm, :med, :lg 중 하나로 설정해 더 구체적으로 지정할 수 있습니다. 더 큰 breakpoint를 설정하면 더 넓은 화면에서 레이아웃이 행 모드로 전환됩니다.
예를 들어, 더 작은 화면에서 열을 유지하려면:
<%= render(Primer::Alpha::Layout.new(stacking_breakpoint: :sm)) do |component| %>
<% component.with_main { "Main" } %>
<% component.with_sidebar { "Sidebar" } %>
<% end %>
구성 가능한 거터 너비 (Configurable gutter width)
Primer::Alpha::Layout에는 사이드바와 메인 콘텐츠 사이의 거터(gutter) 너비를 구성하는 새 gutter 인자가 포함되며, :none, :condensed, :default, :spacious 중 하나일 수 있습니다.
예를 들어, 특히 널찍한 거터를 만들려면:
<%= render(Primer::Alpha::Layout.new(gutter: :spacious)) do |component| %>
<% component.with_main { "Main" } %>
<% component.with_sidebar { "Sidebar" } %>
<% end %>
인자 (Arguments)
다음 인자들이 Primer::LayoutComponent와 Primer::Alpha::Layout 사이에서 다릅니다:
| From Primer::LayoutComponent | To Primer::Alpha::Layout | Notes |
|---|---|---|
| responsive | stacking_breakpoint | When to collapse from columns to rows. Previously a Boolean, now one of :lg, :med, or :sm. |
| n/a | first_in_source | Which element to render first in HTML, determining keyboard navigation order. Either :main or :sidebar. |
| n/a | gutter | Amount of space between the sidebar and main section. One of :none, :condensed, :default, or :spacious. |
| side | n/a | Which side should the sidebar be on? Previously either :right or :left, now handled by the col_placement and row_placement slots on the sidebar. |
| sidebar_col | n/a | Width of the sidebar in columns. Now handled by the width slot on the sidebar. |
main과 sidebar 컴포넌트에는 또한 몇 가지 새롭고 추가적인 슬롯이 있습니다.
main 컴포넌트에 새로 추가된 것:
width::full,:xl,:lg,:med중 하나.:full너비는 메인 열을 사용 가능한 모든 공간으로 늘립니다.
sidebar 컴포넌트에 새로 추가된 것:
width::default,:narrow,:wide중 하나. deprecated된Primer::LayoutComponent#sidebar_col인자를 대체합니다.col_placement: 열 모드에서의 사이드바 배치.:start또는:end중 하나.row_placement와 함께 사용해 deprecated된Primer::LayoutComponent#side인자의 기능을 복제하세요.row_placement: 행 모드에서의 사이드바 배치.:start,:end,:none중 하나.
완전한 설명과 예시는 다음 문서를 참고하세요.
Primer::Alpha::LayoutcomponentPrimer::Alpha::LayoutLookbook examples
← Back to development docs
더 알아보기 (Learn more)
Primer::Alpha::Layout컴포넌트 문서에서stacking_breakpoint,gutter,first_in_source인자를 확인해 보세요.- 사이드바의
width,col_placement,row_placement슬롯을 활용해 반응형 배치를 구성해 보세요. - 키보드 포커스 순서를
first_in_source로 제어해 접근성을 높여 보세요.