본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

타임라인

원문 보기 위키 갱신

타임라인 (Timeline)

타임라인 컴포넌트는 여러 이벤트를 시간 순서대로 연결된 형태로 시각화해 주는 요소예요. align 속성으로 내용을 왼쪽, 오른쪽, 또는 양쪽에 번갈아 배치할 수 있고, 세로와 가로 방향을 모두 지원해요. 콘텐츠, 반대편 콘텐츠, 마커 같은 템플릿으로 각 이벤트를 자유롭게 구성할 수 있고, 스크린 리더 접근성을 위해 의미 있는 순서 목록 구조를 사용해요. 이 문서에서는 기본 사용법부터 정렬 옵션, props, 패스 스루, 테마까지 타임라인 활용에 필요한 내용을 모두 설명해 줄게요

출처: 문서

본문

접근성

스크린 리더: Timeline은 이벤트를 나열할 때 시맨틱한 ordered list 엘리먼트를 사용해요. 특정 role이 강제되지는 않지만, 유효한 속성은 모두 list 엘리먼트로 전달되기 때문에 어떤 aria role과 속성이든 자유롭게 사용할 수 있어요. 키보드 지원: 컴포넌트에는 인터랙티브한 요소가 포함되어 있지 않아요.

정렬

라인을 기준으로 한 콘텐츠의 위치는 align 프로퍼티로 정의해요.

import { Component } from '@angular/core';
import { TimelineModule } from 'primeng/timeline';

interface EventItem {
    status?: string;
    date?: string;
    icon?: string;
    color?: string;
    image?: string;
}

@Component({
    template: `
        <div class="card flex flex-wrap gap-12">
            <p-timeline [value]="events" class="w-full md:w-80">
                <ng-template #content let-event>
                    {{ event.status }}
                </ng-template>
            </p-timeline>
            <p-timeline [value]="events" class="w-full md:w-80" align="right">
                <ng-template #content let-event>
                    {{ event.status }}
                </ng-template>
            </p-timeline>
            <p-timeline [value]="events" class="w-full md:w-80" align="alternate">
                <ng-template #content let-event>
                    {{ event.status }}
                </ng-template>
            </p-timeline>
        </div>
    `,
    standalone: true,
    imports: [TimelineModule]
})
export class TimelineAlignmentDemo {
    events: EventItem[];

    constructor() {
        this.events = [
                    { status: 'Ordered', date: '15/10/2020 10:30', icon: 'pi pi-shopping-cart', color: '#9C27B0', image: 'game-controller.jpg' },
                    { status: 'Processing', date: '15/10/2020 14:00', icon: 'pi pi-cog', color: '#673AB7' },
                    { status: 'Shipped', date: '15/10/2020 16:15', icon: 'pi pi-shopping-cart', color: '#FF9800' },
                    { status: 'Delivered', date: '16/10/2020 10:00', icon: 'pi pi-check', color: '#607D8B' }
                ];
    }
}

기본

Timeline은 value 프로퍼티를 통해 임의의 객체 컬렉션 형태로 이벤트를 전달받아요. 또한 이벤트의 표현을 보여주려면 content 템플릿이 필요해요. 아래 예시는 이 문서 전반에서 사용되는 샘플 events 배열이에요.

import { Component } from '@angular/core';
import { TimelineModule } from 'primeng/timeline';

@Component({
    template: `
        <div class="card">
            <p-timeline [value]="events">
                <ng-template #content let-event>
                    {{ event.status }}
                </ng-template>
            </p-timeline>
        </div>
    `,
    standalone: true,
    imports: [TimelineModule]
})
export class TimelineBasicDemo {
    events: any[];

    constructor() {
        this.events = [
                    { status: 'Ordered', date: '15/10/2020 10:30', icon: 'pi pi-shopping-cart', color: '#9C27B0', image: 'game-controller.jpg' },
                    { status: 'Processing', date: '15/10/2020 14:00', icon: 'pi pi-cog', color: '#673AB7' },
                    { status: 'Shipped', date: '15/10/2020 16:15', icon: 'pi pi-shopping-cart', color: '#FF9800' },
                    { status: 'Delivered', date: '16/10/2020 10:00', icon: 'pi pi-check', color: '#607D8B' }
                ];
    }
}

가로

TimeLine의 방향은 layout 프로퍼티로 제어해요. 기본값은 vertical이고, 대안으로 horizontal을 사용할 수 있어요.

import { Component } from '@angular/core';
import { TimelineModule } from 'primeng/timeline';

@Component({
    template: `
        <div class="card flex flex-col gap-4">
            <p-timeline [value]="events" layout="horizontal" align="top">
                <ng-template #content let-event>
                    {{ event }}
                </ng-template>
            </p-timeline>
            <p-timeline [value]="events" layout="horizontal" align="bottom">
                <ng-template #content let-event>
                    {{ event }}
                </ng-template>
            </p-timeline>
            <p-timeline [value]="events" layout="horizontal" align="alternate">
                <ng-template #content let-event>
                    {{ event }}
                </ng-template>
                <ng-template #opposite let-event><span>&nbsp;</span></ng-template>
            </p-timeline>
        </div>
    `,
    standalone: true,
    imports: [TimelineModule]
})
export class TimelineHorizontalDemo {
    events: string[];

    constructor() {
        this.events = ['2020', '2021', '2022', '2023'];
    }
}

반대쪽

라인 반대편에 추가 콘텐츠를 넣고 싶다면 opposite 프로퍼티를 사용하면 돼요.

import { Component } from '@angular/core';
import { TimelineModule } from 'primeng/timeline';

interface EventItem {
    status?: string;
    date?: string;
    icon?: string;
    color?: string;
    image?: string;
}

@Component({
    template: `
        <div class="card">
            <p-timeline [value]="events">
                <ng-template #opposite let-event>
                    <small class="text-surface-500 dark:text-surface-400">{{ event.date }}</small>
                </ng-template>
                <ng-template #content let-event>
                    {{ event.status }}
                </ng-template>
            </p-timeline>
        </div>
    `,
    standalone: true,
    imports: [TimelineModule]
})
export class TimelineOppositeDemo {
    events: EventItem[];

    constructor() {
        this.events = [
                    { status: 'Ordered', date: '15/10/2020 10:30', icon: 'pi pi-shopping-cart', color: '#9C27B0', image: 'game-controller.jpg' },
                    { status: 'Processing', date: '15/10/2020 14:00', icon: 'pi pi-cog', color: '#673AB7' },
                    { status: 'Shipped', date: '15/10/2020 16:15', icon: 'pi pi-shopping-cart', color: '#FF9800' },
                    { status: 'Delivered', date: '16/10/2020 10:00', icon: 'pi pi-check', color: '#607D8B' }
                ];
    }
}

템플릿

커스텀 콘텐츠와 스타일이 적용된 마커를 활용한 샘플 구현이에요.

import { Component } from '@angular/core';
import { ButtonModule } from 'primeng/button';
import { CardModule } from 'primeng/card';
import { TimelineModule } from 'primeng/timeline';

interface EventItem {
    status?: string;
    date?: string;
    icon?: string;
    color?: string;
    image?: string;
}

@Component({
    template: `
        <div class="card">
            <p-timeline [value]="events" align="alternate" class="customized-timeline">
                <ng-template #marker let-event>
                    <span class="flex w-8 h-8 items-center justify-center text-white rounded-full z-10 shadow-sm" [style]="{ 'background-color': event.color }">
                        <i [class]="event.icon"></i>
                    </span>
                </ng-template>
                <ng-template #content let-event>
                    <p-card [header]="event.status" [subheader]="event.date">
                        <img *ngIf="event.image" [src]="'https://primefaces.org/cdn/primeng/images/demo/product/' + event.image" [alt]="event.name" width="200" class="shadow" />
                        <p>
                            Lorem ipsum dolor sit amet, consectetur adipisicing elit. Inventore sed consequuntur error repudiandae numquam deserunt quisquam repellat libero asperiores earum nam nobis, culpa ratione quam perferendis esse, cupiditate
                            neque quas!
                        </p>
                        <p-button label="Read more" [text]="true" />
                    </p-card>
                </ng-template>
            </p-timeline>
        </div>
    `,
    standalone: true,
    imports: [ButtonModule, CardModule, TimelineModule]
})
export class TimelineTemplateDemo {
    events: EventItem[];

    constructor() {
        this.events = [
                    { status: 'Ordered', date: '15/10/2020 10:30', icon: 'pi pi-shopping-cart', color: '#9C27B0', image: 'game-controller.jpg' },
                    { status: 'Processing', date: '15/10/2020 14:00', icon: 'pi pi-cog', color: '#673AB7' },
                    { status: 'Shipped', date: '15/10/2020 16:15', icon: 'pi pi-shopping-cart', color: '#FF9800' },
                    { status: 'Delivered', date: '16/10/2020 10:00', icon: 'pi pi-check', color: '#607D8B' }
                ];
    }
}

Timeline

Timeline은 이어지는 일련의 이벤트를 시각화해요.

프로퍼티

이름 타입 기본값 설명
dt InputSignal undefined 컴포넌트의 스코프 디자인 토큰을 정의해요.
unstyled InputSignal undefined 컴포넌트를 스타일 없이 렌더링할지 여부를 나타내요.
pt InputSignal undefined 컴포넌트 내부의 DOM 엘리먼트에 속성을 전달할 때 사용해요.
ptOptions InputSignal undefined 컴포넌트의 passthrough(pt) 옵션을 구성할 때 사용해요.
value any[] - 표시할 이벤트 배열이에요.
styleClass string - 컴포넌트의 스타일 클래스예요. (지원 중단됨)
align string left 콘텐츠를 기준으로 한 타임라인 바의 위치예요. vertical 레이아웃에서는 "left", "right"가, horizontal 레이아웃에서는 "top", "bottom"이 유효한 값이에요.
layout "vertical" | "horizontal" vertical 타임라인의 방향이에요.

템플릿

이름 타입 설명
content TemplateRef<TimelineItemTemplateContext> 커스텀 콘텐츠 템플릿이에요.
opposite TemplateRef<TimelineItemTemplateContext> 커스텀 opposite 아이템 템플릿이에요.
marker TemplateRef<TimelineItemTemplateContext> 커스텀 마커 템플릿이에요.

Pass Through 옵션

이름 타입 설명
host PassThroughOption<HTMLElement, I> 호스트의 DOM 엘리먼트에 속성을 전달할 때 사용해요.
root PassThroughOption<HTMLDivElement, I> 루트의 DOM 엘리먼트에 속성을 전달할 때 사용해요.
event PassThroughOption<HTMLDivElement, I> event의 DOM 엘리먼트에 속성을 전달할 때 사용해요.
eventOpposite PassThroughOption<HTMLDivElement, I> event opposite의 DOM 엘리먼트에 속성을 전달할 때 사용해요.
eventSeparator PassThroughOption<HTMLDivElement, I> event separator의 DOM 엘리먼트에 속성을 전달할 때 사용해요.
eventMarker PassThroughOption<HTMLDivElement, I> event marker의 DOM 엘리먼트에 속성을 전달할 때 사용해요.
eventConnector PassThroughOption<HTMLDivElement, I> event connector의 DOM 엘리먼트에 속성을 전달할 때 사용해요.
eventContent PassThroughOption<HTMLDivElement, I> event content의 DOM 엘리먼트에 속성을 전달할 때 사용해요.

테마

CSS 클래스

클래스 설명
p-timeline 루트 엘리먼트의 클래스 이름이에요.
p-timeline-event event 엘리먼트의 클래스 이름이에요.
p-timeline-event-opposite event opposite 엘리먼트의 클래스 이름이에요.
p-timeline-event-separator event separator 엘리먼트의 클래스 이름이에요.
p-timeline-event-marker event marker 엘리먼트의 클래스 이름이에요.
p-timeline-event-connector event connector 엘리먼트의 클래스 이름이에요.
p-timeline-event-content event content 엘리먼트의 클래스 이름이에요.

디자인 토큰

Token CSS Variable Description
timeline.event.min.height --p-timeline-event-min-height 이벤트의 최소 높이예요.
timeline.horizontal.event.content.padding --p-timeline-horizontal-event-content-padding 가로 방향 이벤트 콘텐츠의 패딩이에요.
timeline.vertical.event.content.padding --p-timeline-vertical-event-content-padding 세로 방향 이벤트 콘텐츠의 패딩이에요.
timeline.event.marker.size --p-timeline-event-marker-size 이벤트 마커의 크기예요.
timeline.event.marker.border.radius --p-timeline-event-marker-border-radius 이벤트 마커의 테두리 반경이에요.
timeline.event.marker.border.width --p-timeline-event-marker-border-width 이벤트 마커의 테두리 두께예요.
timeline.event.marker.background --p-timeline-event-marker-background 이벤트 마커의 배경이에요.
timeline.event.marker.border.color --p-timeline-event-marker-border-color 이벤트 마커의 테두리 색상이에요.
timeline.event.marker.content.border.radius --p-timeline-event-marker-content-border-radius 이벤트 마커 콘텐츠의 테두리 반경이에요.
timeline.event.marker.content.size --p-timeline-event-marker-content-size 이벤트 마커 콘텐츠의 크기예요.
timeline.event.marker.content.background --p-timeline-event-marker-content-background 이벤트 마커 콘텐츠의 배경이에요.
timeline.event.marker.content.inset.shadow --p-timeline-event-marker-content-inset-shadow 이벤트 마커 콘텐츠의 안쪽 그림자예요.
timeline.event.connector.color --p-timeline-event-connector-color 이벤트 커넥터의 색상이에요.
timeline.event.connector.size --p-timeline-event-connector-size 이벤트 커넥터의 크기예요.

더 알아보기 (Learn more)

이 문서에는 원문에서 추출한 별도의 관련 문서 링크가 없어요.