Label
A text with an icon before it. Its color is the variable --label-color, which the components that hold a label set.
import { Label } from "x4js"
Icons
An icon before the text, or an icon alone; its color follows the text.
export function icons( ) {
return new VBox( { content: [
new Label( { icon: icon_info, text: "An icon and a text" } ),
new Label( { icon: icon_warning, text: "A warning", cls: "warning" } ),
new HBox( { content: [
new Label( { icon: icon_star } ),
new Label( { icon: icon_user } ),
new Label( { icon: icon_mail } ),
] } ),
] } );
}
.x4label.warning {
--label-color: var( --warning-background );
--label-icon-color: var( --warning-background );
}
Alignment
In a label wider than its text, align puts the text on the left, in the center or on the right.
export function alignment( ) {
return new VBox( { cls: "aligned", content: [
new Label( { width: 300, align: "left", icon: icon_folder, text: "left" } ),
new Label( { width: 300, align: "center", icon: icon_folder, text: "center" } ),
new Label( { width: 300, align: "right", icon: icon_folder, text: "right: the icon goes after the text" } ),
] } );
}
.aligned > .x4label {
padding: 4px 8px;
border: 1px dashed var( --border );
}
setText
setText and setIcon change a label that is already shown.
export function setText( ) {
const status = new Label( { icon: icon_info, text: "Not saved" } );
return new HBox( { content: [
new Button( { label: "Save", click: ( ) => {
status.setText( "Saved at " + new Date( ).toLocaleTimeString( ) );
status.setIcon( icon_check );
} } ),
status,
] } );
}
labelFor
A label with the tag "label" and labelFor: a click on it gives the focus to its field.
export function labelFor( ) {
return new HBox( { content: [
new Label( { tag: "label", text: "Your name", labelFor: "label-demo-name" } ),
new Input( { type: "text", id: "label-demo-name", placeholder: "click on the label" } ),
] } );
}
Vertical
The class vertical puts the icon above the text.
export function vertical( ) {
return new HBox( { cls: "tiles", content: [
new Label( { cls: "vertical", icon: icon_folder, text: "Documents" } ),
new Label( { cls: "vertical", icon: icon_mail, text: "Mail" } ),
new Label( { cls: "vertical", icon: icon_star, text: "Favorites" } ),
] } );
}
.tiles > .x4label.vertical {
width: 96px;
padding: 12px;
background: var( --background-secondary );
#icon {
height: 32px;
}
}
For an assistant: llms.txt, llms-full.txt.