범위 안의 스칼라 측정값을 위한 스타일 없는 미터 그룹 primitive예요.
출처: 문서
본문
마크업과 스타일은 직접 가져와요. MeterGroup은 수학과 데이터 속성을 처리해요.
기능 (Features)
- 복합 파트:
Root, Meters, Meter, Labels, Label, Marker, Text
index prop 없음. [data-part="meter"], [data-part="marker"] 또는 [data-part="label"]에 :nth-child(n)으로 개별 행을 지정해요
- 백분율은
min / max에서 계산돼요. 스크린 리더를 위해 루트에 aria-valuenow를 전달해요
- 색상은 하나의
--p-metergroup-color CSS 변수로 흐릅니다. primitive는 스스로 색을 고르지 않아요
- 미터와 라벨 모두 가로·세로 방향 지원
사용법 (Usage)
import { MeterGroup } from 'primereact/metergroup';
<MeterGroup.Root aria-valuenow={total}>
<MeterGroup.Meters>
<MeterGroup.Meter />
</MeterGroup.Meters>
<MeterGroup.Labels>
<MeterGroup.Label>
<MeterGroup.Marker />
<MeterGroup.Text></MeterGroup.Text>
</MeterGroup.Label>
</MeterGroup.Labels>
</MeterGroup.Root>
primitive는 children을 보며 값을 합산하지 않아요. 데이터가 있는 곳에서 합계를 계산해 aria-valuenow로 전달해요. 생략하면 속성은 0이에요.
동작 (Behavior)
다형성 렌더링 (Polymorphic Rendering)
모든 파트는 as prop을 받아요. 요소나 다른 컴포넌트를 넘겨 렌더링 태그를 바꿔요.
<MeterGroup.Root as="section"></MeterGroup.Root>
<MeterGroup.Labels as="ul"></MeterGroup.Labels>
<MeterGroup.Label as="div"></MeterGroup.Label>
기본값: Root=div, Meters=div, Meter=div, Labels=ol, Label=li, Marker=span, Text=span.
항목별 스타일링 (Per-item styling)
하위 항목별 인덱스는 내보내지 않아요. [data-part="meter"], [data-part="marker"] 또는 [data-part="label"]에 :nth-child(n)을 사용해요. 정말로 안정적인 인덱스 속성이 필요하다면 pt를 통해 전달해요: pt={{ root: { 'data-index': i } }}.
CSS 변수를 통한 색상 (Color via CSS variable)
Meter와 Marker의 color는 모든 CSS 색상 값을 허용해요. primitive는 그걸 요소의 --p-metergroup-color에 기록하고, 스타일 레이어는 background: var(--p-metergroup-color, var(--p-primary-color))로 렌더링해요. 조상 어디에서든 변수를 설정하면 그룹 전체를 다시 칠할 수 있어요:
<div style={{ '--p-metergroup-color': 'magenta' } as React.CSSProperties}>
<MeterGroup.Root values={values}>{/* ... */}</MeterGroup.Root>
</div>
렌더 함수 children (Render Function Children)
Root는 children으로 렌더 함수를 받아요. 함수는 컴포넌트 인스턴스를 받아요.
<MeterGroup.Root>{(instance) => <span>{instance.props['aria-valuenow']}%</span>}</MeterGroup.Root>
패스 스루 (Pass Through)
<DocPTViewer name="metergroup-pt" components={['MeterGroupRoot']} />
API
MeterGroupRoot
| Attribute |
Value |
data-scope |
"metergroup" |
data-part |
"root" |
data-orientation |
Current orientation value |
| Label |
Type |
Description |
| root |
MeterGroupRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
| meters |
MeterGroupRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the meters' DOM element. |
| meter |
MeterGroupRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the meter's DOM element. |
| labels |
MeterGroupRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the labels' DOM element. |
| label |
MeterGroupRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the label's DOM element. |
| marker |
MeterGroupRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the label marker's DOM element. |
| text |
MeterGroupRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the label text's DOM element. |
MeterGroupMeters
| Attribute |
Value |
data-scope |
"metergroup" |
data-part |
"meters" |
data-orientation |
Current orientation value |
| Label |
Type |
Description |
| root |
MeterGroupMetersPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
MeterGroupMeter
| Attribute |
Value |
data-scope |
"metergroup" |
data-part |
"meter" |
data-orientation |
Current orientation value |
| Label |
Type |
Description |
| root |
MeterGroupMeterPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
MeterGroupLabels
| Attribute |
Value |
data-scope |
"metergroup" |
data-part |
"labels" |
data-orientation |
Current orientation value |
| Label |
Type |
Description |
| root |
MeterGroupLabelsPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
MeterGroupLabel
| Attribute |
Value |
data-scope |
"metergroup" |
data-part |
"label" |
| Label |
Type |
Description |
| root |
MeterGroupLabelPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
MeterGroupMarker
| Attribute |
Value |
data-scope |
"metergroup" |
data-part |
"marker" |
| Label |
Type |
Description |
| root |
MeterGroupMarkerPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
MeterGroupText
| Attribute |
Value |
data-scope |
"metergroup" |
data-part |
"text" |
| Label |
Type |
Description |
| root |
MeterGroupTextPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
접근성 (Accessibility)
스크린 리더 (Screen Reader)
루트는 role="meter"와 함께 aria-valuemin, aria-valuemax, aria-valuenow를 사용해요. aria-valuenow는 기본적으로 0이며, Root의 네이티브 속성으로 재정의해요. 그룹은 aria-labelledby 또는 aria-label로 라벨을 붙여요.
키보드 지원 (Keyboard Support)
MeterGroup 안에는 포커스 가능하거나 상호작용하는 것이 없어요.
더 알아보기 (Learn more)