x4js gallery

Timeline

Events one after the other on a line, each with its icon in a round mark: a title, a sentence and its date, written relative to now. A done event has its mark in the accent colour; a click gives its item.

import { Timeline } from "x4js"

Activity

Each event has an icon, a title, a sentence and a date written relative to now; done puts its mark in the accent.

export function activity( ) {
	const ago = ( min: number ) => new Date( Date.now( ) - min * 60000 );

	return new Timeline( { width: 340, items: [
		{ icon: icon_plus, title: "New branch", text: "You've created new branch fix-notifications from master", date: ago( 120 ), done: true },
		{ icon: icon_edit, title: "Commits", text: "You've pushed 23 commits to fix-notifications branch", date: ago( 52 ), done: true },
		{ icon: icon_file, title: "Pull request", text: "You've submitted a pull request Fix incorrect notification message (#187)", date: ago( 34 ) },
		{ icon: icon_user, title: "Code review", text: "Robert left a code review on your pull request", date: ago( 12 ) },
	] } );
}

Side by side

vertical: false puts the events on a line; without a date, no time is shown.

export function horizontal( ) {
	return new Timeline( { vertical: false, width: 560, items: [
		{ icon: icon_check, title: "Ordered", text: "2 items", done: true },
		{ icon: icon_mail, title: "Paid", text: "By card", done: true },
		{ icon: icon_file, title: "Shipped", text: "Within 2 days" },
		{ icon: icon_star, title: "Delivered" },
	] } );
}

Click

A click anywhere in an event fires click, with its item in ev.context.

export function click( ) {
	const label = new Label( { text: "Click an event" } );

	return new HBox( { content: [
		new Timeline( { width: 300, items: projectSteps( ),
			click: ( ev ) => label.setText( `clicked: ${( ev.context as TimelineItem ).title}` ),
		} ),
		label,
	] } );
}

Renderer

renderer gives what is beside the mark; the mark and the line stay.

export function renderer( ) {
	return new Timeline( { width: 300, items: projectSteps( ),
		renderer: ( item ) => new VBox( { cls: "step", content: [
			new Label( { text: item.title } ),
			new Tag( { label: item.done ? "done" : "to do", cls: item.done ? "" : "alert" } ),
		] } ),
	} );
}
.x4timeline .step {
	align-items: flex-start;
	gap: 4px;
	padding-top: 2px;
}

Colors

A class of your own sets the CSS variables of the timeline.

export function colors( ) {
	return new Timeline( { cls: "green", width: 300, items: projectSteps( ) } );
}
.x4timeline.green {
	--timeline-done-color: var( --color-green-600 );
	--timeline-todo-color: var( --color-green-100 );
	--timeline-todo-icon-color: var( --color-green-800 );
}

For an assistant: llms.txt, llms-full.txt.