Section
A part of a page that folds: a title line (an icon, the title, a short summary, tools) and a body.
import { Section } from "x4js"
Title, summary, tools
A click on the title line folds the section; its summary stays; a click on its tool does not fold it.
export function titled( ) {
const info = new Label( { text: "Click the gear." } );
const settings = new Button( { cls: "outline", icon: icon_gear, click: ( ) => info.setText( "The settings of the account." ) } );
const account = new Section( { title: "Account", icon: icon_user, tools: [ settings ], width: 360, content: [
new TextEdit( { label: "Name", value: "Ada" } ),
new TextEdit( { label: "Email", type: "email", value: "ada@example.com" } ),
] } );
account.setSummary( "ada@example.com" );
return new VBox( { content: [ account, info ] } );
}
Folded at first
open: false; toggle tells when the user folds or opens it, setOpen does it by the code.
export function folded( ) {
const info = new Label( { text: "toggle: -" } );
const options = new Section( { title: "Options", icon: icon_info, open: false, width: 360,
toggle: ev => info.setText( `toggle: ${ev.open ? "open" : "folded"}` ),
content: [
new Checkbox( { label: "Dark theme" } ),
new Checkbox( { label: "Notifications", checked: true } ),
],
} );
return new VBox( { content: [
options,
info,
new Button( { label: "Open or fold by the code", click: ( ) => options.setOpen( !options.isOpen( ) ) } ),
] } );
}
Several
Sections one under the other, each folded or opened on its own.
export function several( ) {
return new VBox( { width: 360, style: { gap: "8px" }, content: [
new Section( { title: "General", content: new Checkbox( { label: "Open the last file at start" } ) } ),
new Section( { title: "Editor", open: false, content: new TextEdit( { label: "Tab size", type: "number", value: 4 } ) } ),
new Section( { title: "Advanced", open: false, content: new Checkbox( { label: "Log what happens" } ) } ),
] } );
}
Draggable
draggable: a section dragged by its title line goes above or under the one it is dropped on; move tells it.
export function draggable( ) {
const info = new Label( { text: "Drag a title onto another section." } );
const list = new VBox( { width: 360, style: { gap: "8px" } } );
const showOrder = ( ) => {
const titles = Array.from( list.dom.querySelectorAll( ":scope > .x4section .title" ), el => el.textContent );
info.setText( "Order: " + titles.join( ", " ) );
};
const make = ( title: string ) => new Section( { title, draggable: true, open: false, move: showOrder, content: `The content of ${title}.` } );
list.setContent( [ make( "Inbox" ), make( "Drafts" ), make( "Archive" ) ] );
return new VBox( { content: [ list, info ] } );
}
For an assistant: llms.txt, llms-full.txt.