x4js gallery

Planner

Events by day, week or month, as an agenda: the events with hours side by side in their day, the whole days in a band. The pointer creates, moves, stretches and copies them. Not in x4js: it is imported from x4js/planner.

import { Planner, PlannerEvent } from "x4js/planner"

A week

The events with hours in their day, side by side when they overlap; the whole days in the band under the days. A drag moves an event, its top or its bottom stretches it: change tells it before it is written in the event. The events out of the view have a mark at the top or the bottom of their day.

export function week( ) {
	const result = new Label( { text: "Move an event" } );

	return new VBox( { content: [
		new Planner( { width: "100%", height: 480, events: thisWeek( ),
			click: ( ev ) => result.setText( "click: " + ( ev.context as PlannerEvent ).title ),
			change: ( ev ) => result.setText( `change: ${ev.event.title}, ${formatDateTime( ev.start )} - ${formatDateTime( ev.end )}` ),
		} ),
		result,
	] } );
}

Day, week, month

view, then next and prev go a day, a week or a month further; getRange gives the days shown. In the month, a click on a day opens its week: viewChange tells it.

export function views( ) {
	const range = new Label( { text: "" } );
	const show = ( ) => {
		const { start, end } = planner.getRange( );
		range.setText( `${formatDate( start )} - ${formatDate( end )}` );
	};

	const view = new Select( { value: "month", change: ( ev ) => { planner.setView( ev.value as PlannerView ); show( ); }, items: [
		{ id: "day", text: "Day" },
		{ id: "week", text: "Week" },
		{ id: "month", text: "Month" },
	] } );

	const planner = new Planner( { width: "100%", height: 480, view: "month", events: thisWeek( ),
		viewChange: ( ev ) => { view.setValue( ev.view ); show( ); },
	} );

	show( );

	return new VBox( { content: [
		new HBox( { content: [
			new Button( { label: "◀", cls: "outline", click: ( ) => { planner.prev( ); show( ); } } ),
			new Button( { label: "Today", cls: "outline", click: ( ) => { planner.setDate( new Date( ) ); show( ); } } ),
			new Button( { label: "▶", cls: "outline", click: ( ) => { planner.next( ); show( ); } } ),
			view,
			range,
		] } ),
		planner,
	] } );
}

Create, copy, delete

A drag on an empty place selects a range: select gives it, the application creates the event. ctrl+drag (option on a Mac) copies an event: copy gives its dates, the application adds it. A key on the event selected: addShortcut and getSelection.

export function create( ) {
	const result = new Label( { text: "Select a range, then Delete" } );
	let events = thisWeek( );
	let next = 100;

	const add = ( event: PlannerEvent ) => {
		events = [ ...events, event ];
		planner.setEvents( events );
	};

	const planner = new Planner( { width: "100%", height: 480, events,
		select: ( ev ) => add( { id: next++, title: "New event", start: ev.start, end: ev.end } ),
		copy: ( ev ) => add( { ...ev.event, id: next++, start: ev.start, end: ev.end } ),
	} );

	// Backspace on a Mac too: its key "delete"
	planner.addShortcut( isMac ? [ "Delete", "Backspace" ] : "Delete", ( ) => {
		const event = events.find( e => e.id === planner.getSelection( ) );
		if( event ) {
			events = events.filter( e => e !== event );
			planner.setEvents( events );
			result.setText( "deleted: " + event.title );
		}
	} );

	return new VBox( { content: [ planner, result ] } );
}

Options

The band of the whole days, the hours and the days off, the sub grid, the precision of the pointer: by their props, or by their setters. setReadOnly( true ): nothing created, moved, stretched nor copied; enable( false ): faded, as a Box.

export function options( ) {
	const planner = new Planner( { width: "100%", height: 480, events: thisWeek( ) } );

	return new VBox( { content: [
		new HBox( { content: [
			new Checkbox( { label: "Band", checked: true, change: ( ev ) => planner.setBand( ev.value ) } ),
			new Checkbox( { label: "Off hours", checked: true, change: ( ev ) => planner.setShowOffHours( ev.value ) } ),
			new Checkbox( { label: "Off days", checked: true, change: ( ev ) => planner.setShowOffDays( ev.value ) } ),
			new Checkbox( { label: "Sub grid", change: ( ev ) => planner.setShowSubGrid( ev.value ) } ),
			new Select( { value: 15, change: ( ev ) => planner.setStep( ev.value as number ), items: [
				{ id: 10, text: "10 min" },
				{ id: 15, text: "15 min" },
				{ id: 60, text: "1 h" },
			] } ),
		] } ),
		new HBox( { content: [
			new Checkbox( { label: "Read only", change: ( ev ) => planner.setReadOnly( ev.value ) } ),
			new Checkbox( { label: "Disabled", change: ( ev ) => planner.enable( !ev.value ) } ),
		] } ),
		planner,
	] } );
}

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