VibeFox JS UI — Demo
Avvio rapido
HTML semplice
Il modulo d'ordine dell'avvio rapido: un select con ricerca, un selettore di data che non consente date passate e un pulsante che mostra un toast. Aprire il select, digitare per filtrare, scegliere una data e fare clic su Order.
document.getElementById('app').innerHTML =
'<form id="order" style="display: grid; gap: 6px; max-width: 320px">' +
'<label for="country">Country</label><div id="country"></div>' +
'<label for="date">Delivery date</label><div id="date"></div>' +
'<div id="send" style="margin-top: 8px"></div>' +
'</form>';
const { createSelect, createDatePicker, createButton, createToast } = VibeFoxJSUi;
createSelect('#country', {
options: [{ value: 'de', label: 'Germany' }, { value: 'fr', label: 'France' }, { value: 'it', label: 'Italy' }, { value: 'es', label: 'Spain' }],
searchable: true,
});
createDatePicker('#date', { min: new Date() });
const toast = createToast(document.body, { position: 'bottom-right' });
createButton('#send', { label: 'Order', on: { click: () => toast.success('Order sent') } });Concetti di base
Eventi
Ogni gestore di evento riceve un unico oggetto payload. Trascinare lo slider o usare i tasti freccia: valueChange si attiva mentre il valore cambia, slideEnd quando il cursore viene rilasciato.
const output = document.createElement('pre');
output.style.cssText = 'margin: 12px 0 0; min-height: 3em; font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap';
document.getElementById('app').after(output);
const app = document.getElementById('app');
app.style.maxWidth = '420px';
const slider = VibeFoxJSUi.createSlider('#app', { min: 0, max: 100, value: 20, label: 'Volume', tooltip: true });
const lines = [];
const write = (text) => { lines.unshift(text); output.textContent = lines.slice(0, 5).join('\n'); };
slider.on('valueChange', (e) => write('valueChange ' + e.value));
slider.on('slideEnd', (e) => write('slideEnd ' + e.value));
write('ready — drag the slider');Snapshot dello stato
getState() restituisce ciò che l'utente ha modificato, setState() lo ripristina. Selezionare una scheda o trascinarla in un'altra posizione, fare clic su Save state, modificare di nuovo le schede e fare clic su Restore state.
function addButtons(buttons) {
const bar = document.createElement('div');
bar.id = 'bar';
bar.style.cssText = 'display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px';
for (const [label, click, variant] of buttons) {
VibeFoxJSUi.createButton(bar.appendChild(document.createElement('span')), { label, variant: variant || 'secondary', on: { click } });
}
document.getElementById('app').before(bar);
}
const output = document.createElement('pre');
output.style.cssText = 'margin: 12px 0 0; min-height: 3em; font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap';
document.getElementById('app').after(output);
const tabs = VibeFoxJSUi.createTabs('#app', {
reorder: true,
tabs: [
{ id: 'a', label: 'Overview', content: 'The first tab.' },
{ id: 'b', label: 'Details', content: 'The second tab.' },
{ id: 'c', label: 'History', content: 'The third tab.' },
],
});
let saved = null;
addButtons([
['Save state', () => { saved = tabs.getState(); output.textContent = 'saved ' + JSON.stringify(saved); }],
['Restore state', () => { if (saved) tabs.setState(saved); output.textContent = 'restored ' + JSON.stringify(tabs.getState()); }],
]);Contenuto
Il contenuto di una scheda (finestra di dialogo, pannello, riquadro, card …) è una stringa HTML, un nodo DOM o una funzione che riempie l'elemento. Le tre schede mostrano un caso per ciascun tipo.
const list = document.createElement('ul');
for (const item of ['A DOM node', 'made with createElement']) list.appendChild(document.createElement('li')).textContent = item;
VibeFoxJSUi.createTabs('#app', {
tabs: [
{ id: 'html', label: 'HTML string', content: '<p>An <b>HTML</b> string of your page.</p>' },
{ id: 'node', label: 'DOM node', content: list },
{ id: 'fn', label: 'Renderer', content: (host) => { host.textContent = 'Filled by a function at ' + new Date().toLocaleTimeString(); } },
],
});Pulsanti
Button
Varianti, icone e un pulsante disabilitato. Fare clic su Save: durante l'esecuzione del lavoro (simulato) compare uno spinner.
const app = document.getElementById('app');
app.style.cssText = 'display: flex; flex-wrap: wrap; gap: 8px; align-items: center';
const add = (options) => VibeFoxJSUi.createButton(app.appendChild(document.createElement('span')), options);
for (const variant of ['primary', 'secondary', 'danger', 'outline', 'ghost']) add({ label: variant[0].toUpperCase() + variant.slice(1), variant });
add({ label: 'Next', iconRight: 'chevron-right', variant: 'outline' });
add({ label: 'Disabled', disabled: true });
const save = add({ label: 'Save', icon: 'check' });
save.on('click', async () => {
save.setLoading(true);
await new Promise((resolve) => setTimeout(resolve, 1000));
save.setLoading(false);
});ButtonGroup e SplitButton
Un gruppo a scelta singola (allineamento), un gruppo a scelta multipla di pulsanti toggle e un pulsante diviso con menu. Fare clic sui pulsanti e sulla freccia di Send.
const app = document.getElementById('app');
app.style.cssText = 'display: grid; gap: 12px; justify-items: start';
app.innerHTML =
'<div id="align"></div>' +
'<div id="format"></div>' +
'<div id="send"></div>';
const output = document.createElement('pre');
output.style.cssText = 'margin: 12px 0 0; min-height: 3em; font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap';
document.getElementById('app').after(output);
const align = VibeFoxJSUi.createButtonGroup('#align', { label: 'Alignment', selection: 'single', required: true, value: 'left',
items: [{ id: 'left', icon: 'align-start', title: 'Left' }, { id: 'center', icon: 'align-center', title: 'Center' }, { id: 'right', icon: 'align-end', title: 'Right' }] });
const format = VibeFoxJSUi.createButtonGroup('#format', { label: 'Format', selection: 'multiple',
items: [{ id: 'bold', icon: 'bold', title: 'Bold' }, { id: 'italic', icon: 'italic', title: 'Italic' }, { id: 'underline', icon: 'underline', title: 'Underline' }] });
const send = VibeFoxJSUi.createSplitButton('#send', { label: 'Send', items: [{ id: 'later', label: 'Send later' }, { id: 'draft', label: 'Save draft' }] });
align.on('valueChange', (e) => { output.textContent = 'alignment: ' + e.value; });
format.on('valueChange', (e) => { output.textContent = 'format: ' + JSON.stringify(e.value); });
send.on('click', () => { output.textContent = 'Send'; });
send.on('itemClick', (e) => { output.textContent = 'menu: ' + e.item.id; });Controlli per i moduli
Input e NumberInput
Un campo telefono con maschera, un campo e-mail cancellabile e due campi numerici. Digitare cifre in Phone e usare i tasti freccia in Quantity.
const app = document.getElementById('app');
app.style.cssText = 'display: grid; gap: 14px; max-width: 420px';
app.innerHTML =
'<div><label for="phone">Phone</label><div id="phone"></div></div>' +
'<div><label for="email">E-mail</label><div id="email"></div></div>' +
'<div><label for="qty">Quantity</label><div id="qty"></div></div>' +
'<div><label for="price">Price</label><div id="price"></div></div>';
const output = document.createElement('pre');
output.style.cssText = 'margin: 12px 0 0; min-height: 3em; font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap';
document.getElementById('app').after(output);
const phone = VibeFoxJSUi.createInput('#phone', { mask: '+9 (999) 999-99-99', placeholder: '+1 (555) 123-45-67' });
const email = VibeFoxJSUi.createInput('#email', { type: 'email', clearable: true, value: '[email protected]', prefix: '@' });
const qty = VibeFoxJSUi.createNumberInput('#qty', { value: 1, min: 1, max: 99, step: 1 });
const price = VibeFoxJSUi.createNumberInput('#price', { value: 9.5, min: 0, step: 0.5, precision: 2 });
for (const field of [phone, email, qty, price]) field.on('valueChange', () => {
output.textContent = 'phone ' + phone.getValue() + ', e-mail ' + email.getValue() + ', quantity ' + qty.getValue() + ', price ' + price.getValue();
});Select
Una select multipla con ricerca, gruppi ed etichette (due etichette, poi «+N»), e una select semplice a scelta singola. Aprire gli elenchi e digitare per filtrare.
const app = document.getElementById('app');
app.style.cssText = 'display: grid; gap: 14px; max-width: 420px';
app.innerHTML =
'<div><label for="tags">Languages</label><div id="tags"></div></div>' +
'<div><label for="size">Size</label><div id="size"></div></div>';
const tags = VibeFoxJSUi.createSelect('#tags', {
multiple: true, searchable: true, clearable: true, maxTagCount: 2,
options: [
{ value: 'js', label: 'JavaScript', group: 'Web' }, { value: 'ts', label: 'TypeScript', group: 'Web' }, { value: 'css', label: 'CSS', group: 'Web' },
{ value: 'go', label: 'Go', group: 'Server' }, { value: 'rust', label: 'Rust', group: 'Server' }, { value: 'cobol', label: 'COBOL', group: 'Server', disabled: true },
],
});
tags.setValue(['js', 'go', 'rust']);
VibeFoxJSUi.createSelect('#size', { placeholder: 'Pick a size',
options: [{ value: 's', label: 'Small' }, { value: 'm', label: 'Medium' }, { value: 'l', label: 'Large' }] });AutoComplete
Il primo campo carica i suggerimenti da una sorgente asincrona (un sostituto del server, con ritardo); il secondo filtra in modo fuzzy un elenco statico e mantiene più valori come chip. Digitare «ber» o «pa» in City, «apl» in Fruits.
const app = document.getElementById('app');
app.style.cssText = 'display: grid; gap: 14px; max-width: 420px';
app.innerHTML =
'<div><label for="city">City</label><div id="city"></div></div>' +
'<div><label for="fruit">Fruits</label><div id="fruit"></div></div>';
const CITIES = ['Amsterdam', 'Athens', 'Barcelona', 'Berlin', 'Bern', 'Bratislava', 'Brussels', 'Budapest', 'Lisbon', 'London', 'Madrid', 'Oslo', 'Paris', 'Prague', 'Rome', 'Vienna', 'Warsaw'];
// stand-in for fetch('/api/cities?q=…'): answers after 300 ms
const source = async (query, { signal }) => {
await new Promise((resolve) => setTimeout(resolve, 300));
if (signal.aborted) return [];
return CITIES.filter((name) => name.toLowerCase().includes(query.toLowerCase())).map((name, id) => ({ id, name }));
};
VibeFoxJSUi.createAutoComplete('#city', { source, minLength: 2, delay: 200, textField: 'name', keyField: 'id', placeholder: 'Type 2 letters' });
VibeFoxJSUi.createAutoComplete('#fruit', { data: ['Apple', 'Apricot', 'Banana', 'Cherry', 'Grape', 'Mango', 'Pineapple'], filter: 'fuzzy', multiple: true });Checkbox, Switch, RadioGroup, Segmented
I controlli on / off e a scelta singola tra più opzioni; la riga sottostante mostra i loro valori. Fare clic su di essi oppure usare Space e i tasti freccia.
const app = document.getElementById('app');
app.style.cssText = 'display: grid; gap: 12px; justify-items: start';
app.innerHTML =
'<div id="agree"></div>' +
'<div id="mixed"></div>' +
'<div id="notify"></div>' +
'<div id="plan"></div>' +
'<div id="view"></div>';
const output = document.createElement('pre');
output.style.cssText = 'margin: 12px 0 0; min-height: 3em; font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap';
document.getElementById('app').after(output);
const agree = VibeFoxJSUi.createCheckbox('#agree', { label: 'I agree' });
const mixed = VibeFoxJSUi.createCheckbox('#mixed', { label: 'Some items selected', indeterminate: true });
const notify = VibeFoxJSUi.createSwitch('#notify', { label: 'Notifications', checked: true });
const plan = VibeFoxJSUi.createRadioGroup('#plan', { label: 'Plan', inline: true, value: 'm',
options: [{ value: 'm', label: 'Monthly' }, { value: 'y', label: 'Yearly' }, { value: 'l', label: 'Lifetime', disabled: true }] });
const view = VibeFoxJSUi.createSegmented('#view', { label: 'View', value: 'list',
items: [{ value: 'list', label: 'List', icon: 'list' }, { value: 'grid', label: 'Grid', icon: 'grid' }, { value: 'board', label: 'Board' }] });
const show = () => { output.textContent = 'agree ' + agree.getChecked() + ', notifications ' + notify.getChecked() + ', plan ' + plan.getValue() + ', view ' + view.getValue(); };
for (const control of [agree, mixed, notify, plan, view]) control.on('valueChange', show);
show();Slider e Rating
Uno slider di intervallo con due cursori e tooltip, uno slider singolo e una valutazione con stelle a metà ed etichette. Trascinare i cursori, passare il mouse sulle stelle.
const app = document.getElementById('app');
app.style.cssText = 'display: grid; gap: 14px; max-width: 420px';
app.innerHTML =
'<div><label for="price">Price</label><div id="price"></div></div>' +
'<div><label for="volume">Volume</label><div id="volume"></div></div>' +
'<div><label for="stars">Rating</label><div id="stars"></div></div>' +
'<div><label for="hearts">Likes</label><div id="hearts"></div></div>';
const output = document.createElement('pre');
output.style.cssText = 'margin: 12px 0 0; min-height: 3em; font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap';
document.getElementById('app').after(output);
const price = VibeFoxJSUi.createSlider('#price', { min: 0, max: 500, step: 10, value: [50, 300], tooltip: true });
const volume = VibeFoxJSUi.createSlider('#volume', { min: 0, max: 100, value: 60 });
const stars = VibeFoxJSUi.createRating('#stars', { value: 3.5, max: 5, step: 0.5, labels: ['Bad', 'Poor', 'OK', 'Good', 'Great'] });
VibeFoxJSUi.createRating('#hearts', { value: 2, max: 5, icon: 'heart' });
const show = () => { output.textContent = 'price ' + price.getValue().join(' – ') + ', volume ' + volume.getValue() + ', rating ' + stars.getValue(); };
for (const control of [price, volume, stars]) control.on('valueChange', show);
show();Input OTP
Un codice monouso in due gruppi di tre cifre. Digitare o incollare un codice di 6 cifre: complete si attiva quando tutte le celle sono compilate.
const output = document.createElement('pre');
output.style.cssText = 'margin: 12px 0 0; min-height: 3em; font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap';
document.getElementById('app').after(output);
const code = VibeFoxJSUi.createOTPInput('#app', { label: 'Confirmation code', length: 6, type: 'numeric', groups: [3, 3] });
code.on('valueChange', (e) => { output.textContent = 'value ' + e.value; });
code.on('complete', (e) => { output.textContent = 'complete: ' + e.value; });Campi nei moduli nativi
Controlli VibeFox JS dentro un normale <form>: facendo clic su Submit con campi obbligatori vuoti compaiono i relativi messaggi e viene messo a fuoco il primo; un modulo valido mostra qui sotto il proprio FormData. Reset ripristina i valori iniziali.
const output = document.createElement('pre');
output.style.cssText = 'margin: 12px 0 0; min-height: 3em; font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap';
document.getElementById('app').after(output);
document.getElementById('app').innerHTML =
'<form id="order" style="display: grid; gap: 12px; max-width: 420px">' +
'<div><label for="name">Name</label><div id="name"></div></div>' +
'<div><label for="qty">Quantity</label><div id="qty"></div></div>' +
'<div><label for="country">Country</label><div id="country"></div></div>' +
'<div><label for="day">Delivery date</label><div id="day"></div></div>' +
'<div id="gift"></div>' +
'<div><label for="score">Your rating</label><div id="score"></div></div>' +
'<div id="buttons" style="display: flex; gap: 8px"></div>' +
'</form>';
const form = document.getElementById('order');
VibeFoxJSUi.createInput('#name', { name: 'name', required: true });
VibeFoxJSUi.createNumberInput('#qty', { name: 'qty', value: 2, min: 1 });
VibeFoxJSUi.createSelect('#country', { name: 'country', required: true,
options: [{ value: 'de', label: 'Germany' }, { value: 'fr', label: 'France' }] });
VibeFoxJSUi.createDatePicker('#day', { name: 'day', required: true });
VibeFoxJSUi.createCheckbox('#gift', { label: 'Gift wrap', name: 'gift', checked: true });
VibeFoxJSUi.createRating('#score', { name: 'score', required: true });
const buttons = document.getElementById('buttons');
VibeFoxJSUi.createButton(buttons.appendChild(document.createElement('span')), { label: 'Submit', on: { click: () => form.requestSubmit() } });
VibeFoxJSUi.createButton(buttons.appendChild(document.createElement('span')), { label: 'Reset', variant: 'secondary', on: { click: () => { form.reset(); output.textContent = 'reset'; } } });
form.addEventListener('submit', (e) => {
e.preventDefault(); // the demo shows the data instead of sending it
output.textContent = 'FormData:\n' + [...new FormData(form)].map(([key, value]) => key + ' = ' + value).join('\n');
});
form.addEventListener('invalid', () => { output.textContent = 'not sent: fill in the required fields'; }, true);Selettori di data, ora e colore
Un intervallo di date, una data con l'ora, un orario con passi di 30 minuti e un colore con trasparenza. Aprire ciascun selettore; i calendari funzionano con i tasti freccia e con PageUp / PageDown.
const app = document.getElementById('app');
app.style.cssText = 'display: grid; gap: 14px; max-width: 420px';
app.innerHTML =
'<div><label for="stay">Stay</label><div id="stay"></div></div>' +
'<div><label for="meet">Meeting</label><div id="meet"></div></div>' +
'<div><label for="start">Start</label><div id="start"></div></div>' +
'<div><label for="color">Brand color</label><div id="color"></div></div>';
const output = document.createElement('pre');
output.style.cssText = 'margin: 12px 0 0; min-height: 3em; font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap';
document.getElementById('app').after(output);
const stay = VibeFoxJSUi.createDatePicker('#stay', { range: true, format: 'DD.MM.YYYY', firstDay: 1 });
stay.setValue(['2026-07-01', '2026-07-14']);
const meet = VibeFoxJSUi.createDateTimePicker('#meet', { step: 15, hour12: false, value: '2026-11-03T10:30' });
const start = VibeFoxJSUi.createTimePicker('#start', { min: '08:00', max: '18:00', step: 30, value: '09:00' });
const color = VibeFoxJSUi.createColorPicker('#color', { value: '#2563eb', format: 'hex', alpha: true });
const show = () => { output.textContent = 'state of stay ' + JSON.stringify(stay.getState()) + '\nstate of meeting ' + JSON.stringify(meet.getState()) + '\nstart ' + start.getValue() + ', color ' + color.getValue(); };
for (const picker of [stay, meet, start, color]) picker.on('valueChange', show);
show();Elenchi e alberi
ListView e ListBox
Una casella di riepilogo con caselle di controllo (un elemento disabilitato) e un elenco riordinabile: trascinare un elemento, premere Alt+ArrowUp / ArrowDown oppure aprire la maniglia Move di un elemento per il menu di spostamento.
const app = document.getElementById('app');
app.style.cssText = 'display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px';
app.innerHTML =
'<div><label for="people">Assignees</label><div id="people"></div></div>' +
'<div><label for="tasks">Priorities</label><div id="tasks"></div></div>';
const output = document.createElement('pre');
output.style.cssText = 'margin: 12px 0 0; min-height: 3em; font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap';
document.getElementById('app').after(output);
const people = VibeFoxJSUi.createListBox('#people', {
selection: 'multiple', checkboxes: true, keyField: 'id', textField: 'name', height: 200,
data: [{ id: 1, name: 'Ann' }, { id: 2, name: 'Bob' }, { id: 3, name: 'Cleo', off: true }, { id: 4, name: 'Dan' }, { id: 5, name: 'Eve' }],
disabledField: 'off',
});
people.setValue([1, 2]);
const tasks = VibeFoxJSUi.createListView('#tasks', { draggable: true, height: 200,
data: ['Write docs', 'Fix login', 'Review PR', 'Release 1.2', 'Plan sprint'] });
people.on('valueChange', (e) => { output.textContent = 'assignees ' + JSON.stringify(e.value); });
tasks.on('itemMove', (e) => { output.textContent = 'moved ' + e.from + ' → ' + e.to + (e.reason ? ' (' + e.reason + ')' : ''); });TransferList
Scegliere le colonne da mostrare: spostare gli elementi tra gli elenchi con i pulsanti, con un doppio clic o trascinandoli, e riordinare quelli scelti; se ne possono scegliere al massimo quattro.
const output = document.createElement('pre');
output.style.cssText = 'margin: 12px 0 0; min-height: 3em; font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap';
document.getElementById('app').after(output);
const columns = VibeFoxJSUi.createTransferList('#app', { titles: ['Available', 'Shown'], reorder: true, draggable: true, search: true, max: 4, height: 200,
data: ['Name', 'Email', 'Phone', 'City', 'Company', 'Country', 'Created'], value: ['Name', 'Email'] });
columns.on('valueChange', (e) => { output.textContent = 'shown: ' + e.value.join(', '); });
columns.transfer('City', 'target');Tree
Un albero con caselle di controllo a tre stati, ricerca e nodi figli caricati in modo differito (la cartella lib carica i suoi file dopo un breve ritardo, come da un server). Espandere lib, selezionare elementi, digitare nel campo di ricerca.
const output = document.createElement('pre');
output.style.cssText = 'margin: 12px 0 0; min-height: 3em; font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap';
document.getElementById('app').after(output);
const tree = VibeFoxJSUi.createTree('#app', {
label: 'Folders', checkboxes: true, search: true,
data: [
{ id: 'src', label: 'src', expanded: true, children: [
{ id: 'app', label: 'app.js' },
{ id: 'lib', label: 'lib', lazy: true },
{ id: 'css', label: 'styles', children: [{ id: 'main', label: 'main.css' }, { id: 'print', label: 'print.css' }] },
] },
{ id: 'docs', label: 'docs', children: [{ id: 'readme', label: 'README.md' }] },
],
// stand-in for a server request: the children of a lazy node
load: async (node) => {
await new Promise((resolve) => setTimeout(resolve, 400));
return [{ id: node.id + '/util', label: 'util.js' }, { id: node.id + '/dom', label: 'dom.js' }];
},
});
tree.setChecked('app', true);
tree.on('checkChange', () => { output.textContent = 'checked: ' + tree.getChecked().join(', '); });Moduli e caricamento di file
Form
Un modulo costruito a partire dalle descrizioni dei campi con regole. Fare clic su Register con campi vuoti per vedere gli errori; un modulo valido mostra qui sotto il proprio valore e il FormData del relativo elemento form.
const output = document.createElement('pre');
output.style.cssText = 'margin: 12px 0 0; min-height: 3em; font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap';
document.getElementById('app').after(output);
const form = VibeFoxJSUi.createForm('#app', {
fields: [
{ name: 'email', label: 'Email', type: 'input', props: { type: 'email' }, rules: [{ required: true }, { pattern: '^[^@]+@[^@]+$', message: 'Not an email' }] },
{ name: 'age', label: 'Age', type: 'number', rules: [{ required: true }, { min: 18, message: 'Adults only' }] },
{ name: 'plan', label: 'Plan', type: 'segmented', props: { items: ['Free', 'Pro', 'Team'] } },
{ name: 'start', label: 'Start date', type: 'date' },
{ name: 'terms', label: 'I accept the terms', type: 'checkbox', rules: [{ required: true, message: 'Please accept the terms' }] },
],
value: { plan: 'Free' }, layout: 'horizontal', validateOn: 'change', submitLabel: 'Register', resetLabel: 'Reset',
});
form.on('submit', (e) => {
const data = new FormData(document.querySelector('#app form'));
output.textContent = 'value: ' + JSON.stringify(e.value) + '\nFormData: ' + [...data].map(([key, value]) => key + '=' + value).join(', ');
});
form.on('validate', (e) => { if (!e.valid) output.textContent = 'fix the errors above'; });FileUpload
Caricamenti a blocchi con avanzamento, annullamento e nuovo tentativo. Qui il trasporto è un sostituto del server (nulla lascia la pagina): trascinare i file nel riquadro oppure fare clic su Add sample files (il terzo è troppo grande e viene rifiutato).
function addButtons(buttons) {
const bar = document.createElement('div');
bar.id = 'bar';
bar.style.cssText = 'display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px';
for (const [label, click, variant] of buttons) {
VibeFoxJSUi.createButton(bar.appendChild(document.createElement('span')), { label, variant: variant || 'secondary', on: { click } });
}
document.getElementById('app').before(bar);
}
const output = document.createElement('pre');
output.style.cssText = 'margin: 12px 0 0; min-height: 3em; font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap';
document.getElementById('app').after(output);
// stand-in for your server: "uploads" each chunk in about a second and reports the progress
const fakeServer = async (ctx) => {
for (let step = 1; step <= 10; step++) {
await new Promise((resolve) => setTimeout(resolve, 100));
if (ctx.signal.aborted) throw new Error('aborted');
ctx.onProgress(ctx.chunk.size * step / 10);
}
return { id: ctx.uploadId, chunk: ctx.index + 1 + '/' + ctx.count };
};
const files = VibeFoxJSUi.createFileUpload('#app', {
transport: fakeServer, chunkSize: 256 * 1024, retries: 2, concurrency: 2,
multiple: true, maxFileSize: 1e6, maxFiles: 5, accept: '.txt,.csv,image/*', autoUpload: true, label: 'Attachments',
});
const sample = (name, size) => new File(['x'.repeat(size)], name, { type: 'text/plain' });
addButtons([['Add sample files', () => files.addFiles([sample('report.txt', 600000), sample('notes.txt', 40000), sample('video-dump.txt', 1500000)])]]);
files.on('uploadComplete', (e) => { output.textContent += e.file.name + ' uploaded ' + JSON.stringify(e.response) + '\n'; });
files.on('fileReject', (e) => { output.textContent += e.file.name + ' rejected: ' + e.message + '\n'; });Navigazione
Tabs e Accordion
Schede chiudibili che si possono riordinare (trascinare una scheda o usare la sua maniglia di spostamento) e una fisarmonica in cui più sezioni possono essere aperte. Chiudere una scheda con la sua croce o con il tasto Delete.
const app = document.getElementById('app');
app.style.cssText = 'display: grid; gap: 20px';
app.innerHTML =
'<div id="tabs"></div>' +
'<div id="faq"></div>';
const tabs = VibeFoxJSUi.createTabs('#tabs', { label: 'Document', closable: true, reorder: true,
tabs: [
{ id: 'a', label: 'Overview', content: '<p>Text of the overview.</p>' },
{ id: 'b', label: 'Details', content: (host) => { host.textContent = 'Rendered by a function.'; } },
{ id: 'd', label: 'Locked', content: 'Not available', disabled: true, closable: false },
] });
tabs.addTab({ id: 'c', label: 'History', content: 'Change log' }, { activate: true });
const faq = VibeFoxJSUi.createAccordion('#faq', { multiple: true, headingLevel: 3,
items: [
{ id: 'q1', title: 'How long is the shipping?', content: '3–5 working days.' },
{ id: 'q2', title: 'Can I return an item?', content: 'Yes, within 30 days.' },
{ id: 'q3', title: 'Do you ship abroad?', content: 'To every EU country.' },
] });
faq.expand('q1');Menu e Toolbar
Un menu a discesa con una voce con spunta, una linea divisoria e un sottomenu, lo stesso menu del menu contestuale del riquadro grigio (clic destro o Shift+F10), e una toolbar con pulsanti toggle. La riga sottostante mostra i clic.
const app = document.getElementById('app');
app.style.cssText = 'display: grid; gap: 12px; justify-items: start';
app.innerHTML =
'<div id="tools"></div>' +
'<div id="open"></div>' +
'<div id="area"></div>';
const output = document.createElement('pre');
output.style.cssText = 'margin: 12px 0 0; min-height: 3em; font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap';
document.getElementById('app').after(output);
document.getElementById('area').style.cssText = 'width: 260px; padding: 24px; background: #f1f5f9; border-radius: 6px; text-align: center';
document.getElementById('area').textContent = 'Right-click here';
document.getElementById('area').tabIndex = 0;
const menu = VibeFoxJSUi.createMenu(document.body, { label: 'Actions', items: [
{ id: 'copy', label: 'Copy', shortcut: 'Ctrl+C', icon: 'copy' },
{ id: 'cut', label: 'Cut', shortcut: 'Ctrl+X', icon: 'scissors' },
{ id: 'wrap', label: 'Word wrap', checked: true },
{ divider: true },
{ id: 'export', label: 'Export', children: [{ id: 'pdf', label: 'PDF' }, { id: 'csv', label: 'CSV' }] },
{ id: 'delete', label: 'Delete', icon: 'trash', disabled: true },
] });
VibeFoxJSUi.createButton('#open', { label: 'Actions', iconRight: 'chevron-down', variant: 'outline' });
menu.attachTrigger('#open button');
menu.attachContext('#area');
menu.on('itemClick', (e) => { output.textContent = 'menu: ' + e.path.join(' › '); });
const bar = VibeFoxJSUi.createToolbar('#tools', { label: 'Formatting', items: [
{ type: 'toggle', id: 'bold', icon: 'bold', label: 'Bold' },
{ type: 'toggle', id: 'italic', icon: 'italic', label: 'Italic' },
{ type: 'separator' },
{ type: 'button', id: 'undo', icon: 'undo', tooltip: 'Undo' },
{ type: 'button', id: 'redo', icon: 'redo', tooltip: 'Redo' },
{ type: 'spacer' },
{ type: 'custom', render: (host) => { host.textContent = 'Saved'; } },
] });
bar.on('toggleChange', (e) => { output.textContent = 'toolbar: ' + e.id + ' ' + (e.pressed ? 'on' : 'off'); });
bar.on('itemClick', (e) => { output.textContent = 'toolbar: ' + e.id; });Breadcrumb e Pagination
Un breadcrumb che comprime gli elementi centrali quando sono troppi, e una paginazione con la dimensione della pagina e il totale. Fare clic sulle pagine e cambiare la dimensione della pagina.
const app = document.getElementById('app');
app.style.cssText = 'display: grid; gap: 20px';
app.innerHTML =
'<div id="path"></div>' +
'<div id="pages"></div>';
const output = document.createElement('pre');
output.style.cssText = 'margin: 12px 0 0; min-height: 3em; font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap';
document.getElementById('app').after(output);
VibeFoxJSUi.createBreadcrumb('#path', { maxItems: 4, items: [
{ id: 'home', label: 'Home', href: '#' }, { id: 'docs', label: 'Docs', href: '#' }, { id: 'lib', label: 'Libraries', href: '#' },
{ id: 'ui', label: 'VibeFox JS UI', href: '#' }, { id: 'nav', label: 'Navigation' },
] });
const pages = VibeFoxJSUi.createPagination('#pages', { total: 240, pageSize: 20, page: 3, pageSizes: [10, 20, 50], showTotal: true });
pages.on('pageChange', (e) => { output.textContent = 'page ' + e.page + ', ' + e.pageSize + ' per page'; });Stepper e Wizard
Una procedura guidata il cui primo passo controlla il campo prima di proseguire: fare clic su Next con il nome vuoto per vedere l'errore. Il secondo passo è facoltativo; Finish mostra il risultato.
const output = document.createElement('pre');
output.style.cssText = 'margin: 12px 0 0; min-height: 3em; font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap';
document.getElementById('app').after(output);
const name = document.createElement('div');
const wizard = VibeFoxJSUi.createWizard('#app', { linear: true, steps: [
{ id: 'account', title: 'Account', description: 'Your name', content: name, validate: () => nameInput.getValue().trim() !== '' || 'Enter your name' },
{ id: 'address', title: 'Address', optional: true, content: '<p>The address can be added later.</p>' },
{ id: 'done', title: 'Confirm', content: (host) => { host.textContent = 'Check and click Finish.'; } },
] });
const nameInput = VibeFoxJSUi.createInput(name, { label: 'Name', placeholder: 'Your name' });
wizard.on('stepChange', (e) => { output.textContent = 'step: ' + wizard.getActive(); });
wizard.on('finish', () => { output.textContent = 'finished for ' + nameInput.getValue(); });CommandPalette
Un elenco ricercabile di comandi. Fare clic su Open palette (oppure premere Ctrl+K / Cmd+K all'interno dell'esempio), digitare «dark» o «new» e premere Enter; i comandi recenti compaiono per primi.
function addButtons(buttons) {
const bar = document.createElement('div');
bar.id = 'bar';
bar.style.cssText = 'display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px';
for (const [label, click, variant] of buttons) {
VibeFoxJSUi.createButton(bar.appendChild(document.createElement('span')), { label, variant: variant || 'secondary', on: { click } });
}
document.getElementById('app').before(bar);
}
const output = document.createElement('pre');
output.style.cssText = 'margin: 12px 0 0; min-height: 3em; font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap';
document.getElementById('app').after(output);
const palette = VibeFoxJSUi.createCommandPalette(document.body, { hotkey: 'mod+k', commands: [
{ id: 'new', title: 'New document', category: 'File', shortcut: 'Ctrl+N', icon: 'file', handler: () => { output.textContent = 'new document'; } },
{ id: 'open', title: 'Open…', category: 'File', shortcut: 'Ctrl+O', icon: 'folder', handler: () => { output.textContent = 'open'; } },
{ id: 'dark', title: 'Dark theme', category: 'View', keywords: ['night', 'theme'], handler: () => VibeFoxJSUi.setTheme('dark') },
{ id: 'light', title: 'Light theme', category: 'View', keywords: ['day', 'theme'], handler: () => VibeFoxJSUi.setTheme('light') },
{ id: 'find', title: 'Find in files', category: 'Edit', shortcut: 'Ctrl+Shift+F', icon: 'search', handler: () => { output.textContent = 'find'; } },
] });
palette.on('commandRun', (e) => { output.textContent = 'run: ' + e.command.id; });
addButtons([['Open palette', () => palette.open(), 'primary']]);Finestre di dialogo e sovrapposizioni
Dialog
Una finestra di dialogo modale con pulsanti e finestre non modali: aprirne due, trascinarle dall'intestazione, ridimensionarle dagli angoli, massimizzarle o minimizzarle; il pulsante del menu della finestra le sposta senza trascinamento.
function addButtons(buttons) {
const bar = document.createElement('div');
bar.id = 'bar';
bar.style.cssText = 'display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px';
for (const [label, click, variant] of buttons) {
VibeFoxJSUi.createButton(bar.appendChild(document.createElement('span')), { label, variant: variant || 'secondary', on: { click } });
}
document.getElementById('app').before(bar);
}
const output = document.createElement('pre');
output.style.cssText = 'margin: 12px 0 0; min-height: 3em; font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap';
document.getElementById('app').after(output);
let count = 0;
addButtons([
['Delete file…', () => {
const dlg = VibeFoxJSUi.createDialog(document.body, {
title: 'Delete file?', content: '<p>report.pdf will be deleted. This cannot be undone.</p>', width: 340,
buttons: [{ id: 'cancel', label: 'Cancel', variant: 'secondary' }, { id: 'ok', label: 'Delete', variant: 'danger' }],
});
dlg.on('buttonClick', (e) => { output.textContent = 'clicked ' + e.id; dlg.close(); });
}, 'danger'],
['Open window', () => {
count++;
VibeFoxJSUi.createDialog(document.body, { title: 'Properties ' + count, modal: false, resizable: true, maximizable: true, minimizable: true,
width: 280, height: 160, x: 20 + count * 30, y: 50 + count * 20, content: '<p>Window ' + count + '. Drag me by the header.</p>' });
}],
]);Drawer
Un pannello che scorre da un bordo. Aprirlo da sinistra, da destra o dal basso; Esc oppure un clic sullo sfondo lo chiude.
function addButtons(buttons) {
const bar = document.createElement('div');
bar.id = 'bar';
bar.style.cssText = 'display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px';
for (const [label, click, variant] of buttons) {
VibeFoxJSUi.createButton(bar.appendChild(document.createElement('span')), { label, variant: variant || 'secondary', on: { click } });
}
document.getElementById('app').before(bar);
}
const drawers = {};
for (const side of ['left', 'right', 'bottom']) {
drawers[side] = VibeFoxJSUi.createDrawer(document.body, { side, size: side === 'bottom' ? 160 : 's', title: 'Filters (' + side + ')',
content: '<p>Filter controls go here.</p>', openOnInit: false });
}
addButtons([['Left', () => drawers.left.open()], ['Right', () => drawers.right.open()], ['Bottom', () => drawers.bottom.open()]]);Toast
Notifiche nell'angolo: quattro tipi, uno con un'azione che rimane finché non viene usata, e uno che segue una promessa (caricamento, poi completamento). Al massimo tre sono visibili, le altre attendono.
function addButtons(buttons) {
const bar = document.createElement('div');
bar.id = 'bar';
bar.style.cssText = 'display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px';
for (const [label, click, variant] of buttons) {
VibeFoxJSUi.createButton(bar.appendChild(document.createElement('span')), { label, variant: variant || 'secondary', on: { click } });
}
document.getElementById('app').before(bar);
}
const output = document.createElement('pre');
output.style.cssText = 'margin: 12px 0 0; min-height: 3em; font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap';
document.getElementById('app').after(output);
const toast = VibeFoxJSUi.createToast(document.body, { position: 'bottom-right', duration: 4000, max: 3 });
toast.on('actionClick', (e) => { output.textContent = 'action ' + e.action; toast.hide(e.id); });
addButtons([
['Info', () => toast.info('A new version is available')],
['Success', () => toast.success('Saved')],
['Warning', () => toast.warning('The disk is almost full')],
['Error', () => toast.error('Could not connect')],
['With action', () => toast.show({ type: 'warning', title: 'Offline', message: 'Changes are kept locally.', duration: 0, actions: [{ id: 'retry', label: 'Retry' }] })],
['Promise', () => toast.promise(new Promise((resolve) => setTimeout(resolve, 1500)), { loading: 'Uploading…', success: 'Uploaded', error: 'Upload failed' })],
]);Tooltip e Popover
Un tooltip compare al passaggio del mouse e al focus da tastiera; un popover con titolo e contenuto ricco si apre con un clic. Passare il mouse su Help oppure spostarsi su di esso con Tab, quindi fare clic su Order 42.
const app = document.getElementById('app');
app.style.cssText = 'display: flex; gap: 12px';
app.innerHTML = '<span id="help"></span><span id="order"></span>';
VibeFoxJSUi.createButton('#help', { label: 'Help', variant: 'outline' });
const tip = VibeFoxJSUi.createTooltip('#help button', { content: 'Opens the manual', placement: 'bottom' });
VibeFoxJSUi.createButton('#order', { label: 'Order 42', variant: 'secondary' });
const pop = VibeFoxJSUi.createPopover('#order button', { title: 'Order 42', placement: 'bottom',
content: '<p>3 items, 120 EUR</p><p>Delivery on Monday</p>' });Tour
Un tour di introduzione: un'evidenziazione su ciascun elemento di riferimento con una scheda del passo. Fare clic su Start tour e scorrere i passi con Next o con i tasti freccia.
function addButtons(buttons) {
const bar = document.createElement('div');
bar.id = 'bar';
bar.style.cssText = 'display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px';
for (const [label, click, variant] of buttons) {
VibeFoxJSUi.createButton(bar.appendChild(document.createElement('span')), { label, variant: variant || 'secondary', on: { click } });
}
document.getElementById('app').before(bar);
}
const app = document.getElementById('app');
app.style.cssText = 'display: flex; gap: 8px';
app.innerHTML = '<span id="new"></span><span id="share"></span><span id="export"></span>';
VibeFoxJSUi.createButton('#new', { label: 'New', icon: 'plus' });
VibeFoxJSUi.createButton('#share', { label: 'Share', variant: 'secondary' });
VibeFoxJSUi.createButton('#export', { label: 'Export', icon: 'download', variant: 'outline' });
const tour = VibeFoxJSUi.createTour(document.body, { steps: [
{ target: '#new', title: 'Create', content: 'Start a new document here.', placement: 'bottom' },
{ target: '#share', title: 'Share', content: 'Invite your team.', placement: 'bottom' },
{ target: '#export', title: 'Export', content: 'Download as PDF or Excel.', placement: 'bottom' },
] });
addButtons([['Start tour', () => tour.start(), 'primary']]);Layout
Splitter
Tre pannelli con separatori trascinabili; il primo si comprime con un doppio clic sul suo separatore. Un clic su un separatore apre il suo menu di spostamento; i tasti freccia spostano un separatore messo a fuoco.
const output = document.createElement('pre');
output.style.cssText = 'margin: 12px 0 0; min-height: 3em; font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap';
document.getElementById('app').after(output);
const box = (text) => '<div style="padding: 12px; height: 100%; box-sizing: border-box; background: #f8fafc">' + text + '</div>';
const app = document.getElementById('app');
app.style.height = '240px';
const split = VibeFoxJSUi.createSplitter('#app', { direction: 'horizontal', panes: [
{ content: box('Navigation'), size: 25, min: 100, collapsible: true },
{ content: box('Editor'), size: 50 },
{ content: box('Preview'), size: 25, min: 100 },
] });
split.on('paneResize', (e) => { output.textContent = 'sizes ' + e.sizes.map((s) => Math.round(s) + '%').join(' / '); });DockLayout
Pannelli in zone, come in un IDE. Trascinare la scheda di un pannello in un'altra zona, oppure aprire la maniglia di spostamento di una scheda (o premere Alt+frecce) per agganciarla a sinistra, in alto, al centro, in basso o a destra.
const output = document.createElement('pre');
output.style.cssText = 'margin: 12px 0 0; min-height: 3em; font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap';
document.getElementById('app').after(output);
const app = document.getElementById('app');
app.style.height = '360px';
const dock = VibeFoxJSUi.createDockLayout('#app', { zoneSizes: { left: 180, bottom: 110, right: 180 }, panels: [
{ id: 'files', title: 'Files', zone: 'left', content: '<ul><li>index.html</li><li>main.js</li><li>style.css</li></ul>' },
{ id: 'code', title: 'main.js', zone: 'center', content: '<pre>console.log("hello");</pre>', closable: true },
{ id: 'readme', title: 'README.md', zone: 'center', content: '<p>Read me</p>', closable: true },
{ id: 'log', title: 'Console', zone: 'bottom', content: 'Output' },
{ id: 'props', title: 'Properties', zone: 'right', content: 'Width 960' },
] });
dock.on('panelMove', (e) => { output.textContent = 'moved ' + e.id + ' to ' + e.zone; });TileLayout
Una griglia per dashboard: trascinare un riquadro dalla sua intestazione, ridimensionarlo dall'angolo, oppure fare clic sulla maniglia per il menu di spostamento (move, wider, narrower …). Ctrl+Z annulla una modifica; con una larghezza ridotta i riquadri hanno meno colonne.
const output = document.createElement('pre');
output.style.cssText = 'margin: 12px 0 0; min-height: 3em; font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap';
document.getElementById('app').after(output);
const tiles = VibeFoxJSUi.createTileLayout('#app', {
columns: 12, breakpoints: { 0: 4, 600: 8, 900: 12 }, rowHeight: 60,
tiles: [
{ id: 'sales', title: 'Sales', x: 0, y: 0, w: 6, h: 3, content: 'Chart' },
{ id: 'kpi', title: 'KPI', x: 6, y: 0, w: 3, h: 2, minW: 2, content: '<b style="font-size: 28px">42</b>' },
{ id: 'news', title: 'News', x: 9, y: 0, w: 3, h: 4, collapsible: true, content: 'Text' },
{ id: 'tasks', title: 'Tasks', x: 6, y: 2, w: 3, h: 2, closable: true, content: '3 open' },
],
});
tiles.on('layoutChange', (e) => { output.textContent = e.reason + ': ' + e.layout.map((t) => t.id + ' ' + t.x + ',' + t.y + ' ' + t.w + '×' + t.h).join('; '); });Visualizzazione dei dati
Card
Card con immagine, titolo, testo e azioni: rialzata, con bordo e una card che è un link. Fare clic su Book.
const output = document.createElement('pre');
output.style.cssText = 'margin: 12px 0 0; min-height: 3em; font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap';
document.getElementById('app').after(output);
const app = document.getElementById('app');
app.style.cssText = 'display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px';
// a picture made in the code (your image URL goes here)
const picture = (from, to) => 'data:image/svg+xml,' + encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" width="320" height="160">' +
'<defs><linearGradient id="g" x2="1" y2="1"><stop offset="0" stop-color="' + from + '"/><stop offset="1" stop-color="' + to + '"/></linearGradient></defs>' +
'<rect width="320" height="160" fill="url(#g)"/><path d="M0 160 L110 60 L170 120 L230 70 L320 160Z" fill="#ffffff55"/></svg>');
const card = (options) => VibeFoxJSUi.createCard(app.appendChild(document.createElement('div')), options);
const lodge = card({ title: 'Mountain lodge', subtitle: 'From 120 EUR', media: picture('#0ea5e9', '#1e3a8a'), mediaAlt: 'Mountains',
content: '<p>Quiet place near the lake.</p>', variant: 'elevated', actions: [{ id: 'book', label: 'Book', variant: 'primary' }, { id: 'save', label: 'Save', variant: 'ghost' }] });
card({ title: 'City flat', subtitle: 'From 90 EUR', media: picture('#f97316', '#be123c'), mediaAlt: 'City', content: '<p>Five minutes to the old town.</p>', variant: 'outlined' });
card({ title: 'All offers', content: '<p>The whole card is a link.</p>', href: '#offers', footer: '24 places' });
lodge.on('action', (e) => { output.textContent = 'action ' + e.id; });Avatar, Chip, Badge
Avatar con iniziali, uno stato e un gruppo «+2»; chip di filtro che si possono selezionare e rimuovere; badge con un contatore su un pulsante e come punto.
const app = document.getElementById('app');
app.style.cssText = 'display: grid; gap: 16px; justify-items: start';
app.innerHTML =
'<div id="avatars"></div>' +
'<div id="group"></div>' +
'<div id="chips"></div>' +
'<div id="badges"></div>';
const output = document.createElement('pre');
output.style.cssText = 'margin: 12px 0 0; min-height: 3em; font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap';
document.getElementById('app').after(output);
document.getElementById('avatars').style.cssText = 'display: flex; gap: 8px; align-items: center';
for (const [name, size, status] of [['Ann Lee', 'xs'], ['Bob Stone', 's', 'online'], ['Cleo Park', 'm', 'busy'], ['Dan Roe', 'l', 'away'], ['Eve', 'xl']]) {
VibeFoxJSUi.createAvatar(document.getElementById('avatars').appendChild(document.createElement('span')), { name, size, status });
}
VibeFoxJSUi.createAvatarGroup('#group', { max: 3, items: ['Ann Lee', 'Bob Stone', { name: 'Cleo', status: 'online' }, 'Dan', 'Eve'] });
const filters = VibeFoxJSUi.createChipGroup('#chips', { label: 'Filters', selection: 'multiple', removable: true,
items: ['Open', 'Urgent', { id: 'me', label: 'Mine', icon: 'user' }, 'This week'] });
filters.on('itemRemove', (e) => { output.textContent = 'removed ' + (e.item.label || e.item.id); });
filters.on('valueChange', (e) => { output.textContent = 'selected ' + JSON.stringify(e.value); });
const badges = document.getElementById('badges');
badges.style.cssText = 'display: flex; gap: 24px; align-items: center; padding-top: 8px';
badges.innerHTML = '<span id="inbox"></span><span id="chat"></span>';
VibeFoxJSUi.createButton('#inbox', { label: 'Inbox', variant: 'secondary' });
// the badges sit on the corner of the buttons (attached to their mount elements)
const inbox = VibeFoxJSUi.createBadge('#inbox', { count: 7, max: 99, type: 'error', attached: true });
VibeFoxJSUi.createButton('#chat', { label: 'Chat', variant: 'secondary' });
VibeFoxJSUi.createBadge('#chat', { dot: true, type: 'success', attached: true });
inbox.setCount(12);Progress, Spinner, Skeleton
Una barra di avanzamento, spinner e un segnaposto skeleton. Fare clic su Load: la barra si riempie, poi lo skeleton viene sostituito dal contenuto.
function addButtons(buttons) {
const bar = document.createElement('div');
bar.id = 'bar';
bar.style.cssText = 'display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px';
for (const [label, click, variant] of buttons) {
VibeFoxJSUi.createButton(bar.appendChild(document.createElement('span')), { label, variant: variant || 'secondary', on: { click } });
}
document.getElementById('app').before(bar);
}
const app = document.getElementById('app');
app.style.cssText = 'display: grid; gap: 14px; max-width: 420px';
app.innerHTML =
'<div id="progress"></div>' +
'<div id="spinners"></div>' +
'<div id="skeleton"></div>';
document.getElementById('spinners').style.cssText = 'display: flex; gap: 24px; align-items: center';
const bar = VibeFoxJSUi.createProgressBar('#progress', { value: 30, max: 100, label: true, striped: true });
VibeFoxJSUi.createSpinner(document.getElementById('spinners').appendChild(document.createElement('span')), { size: 'l', label: 'Loading' });
VibeFoxJSUi.createSpinner(document.getElementById('spinners').appendChild(document.createElement('span')), { size: 'l', shape: 'dots', label: 'Loading orders…', showLabel: true });
const skeleton = VibeFoxJSUi.createSkeleton('#skeleton', { rows: 3, avatar: true, animated: true, widths: ['60%', '90%', '40%'] });
addButtons([['Load', () => {
let value = 0;
const timer = setInterval(() => {
value += 10;
bar.setValue(value);
if (value < 100) return;
clearInterval(timer);
skeleton.destroy();
document.getElementById('skeleton').innerHTML = '<b>Ann Lee</b><p>The content is loaded.</p>';
}, 150);
}, 'primary']]);Carousel
Slide con frecce, indicatori, scorrimento con gesto (swipe) e ciclo continuo; una, due o tre slide alla volta a seconda della larghezza. Usare le frecce, i punti o i tasti freccia.
const colors = ['#0ea5e9', '#22c55e', '#f59e0b', '#ef4444', '#8b5cf6', '#14b8a6'];
const slides = VibeFoxJSUi.createCarousel('#app', { label: 'Products', loop: true, perView: { 0: 1, 600: 2, 900: 3 }, perMove: 1,
items: colors.map((color, i) => ({ content: '<div style="height: 140px; display: grid; place-items: center; border-radius: 8px; color: #fff; font: 600 22px system-ui; background: ' + color + '">Slide ' + (i + 1) + '</div>' })) });
slides.goTo(1);Kanban
Una bacheca con un limite WIP di 2 su In progress, etichette, assegnatari, scadenze e avanzamento. Trascinare le card tra le colonne, oppure aprire la piccola maniglia di spostamento di una card per il menu «Move»; usare la ricerca e l'aggiunta rapida, Ctrl+Z annulla uno spostamento.
const output = document.createElement('pre');
output.style.cssText = 'margin: 12px 0 0; min-height: 3em; font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap';
document.getElementById('app').after(output);
const board = VibeFoxJSUi.createKanban('#app', {
columns: [{ id: 'todo', title: 'To do' }, { id: 'doing', title: 'In progress', limit: 2 }, { id: 'done', title: 'Done' }],
cards: [
{ id: 1, column: 'todo', title: 'Write docs', labels: [{ text: 'docs', color: 'info' }], assignees: ['Ann Lee'], due: '2026-11-10' },
{ id: 2, column: 'todo', title: 'Design the logo', labels: ['design'], assignees: ['Cleo Park'] },
{ id: 3, column: 'doing', title: 'Fix login', labels: [{ text: 'bug', color: 'danger' }], progress: 40, assignees: ['Bob Stone'] },
{ id: 4, column: 'doing', title: 'Payment page', progress: 70, due: '2026-11-05' },
{ id: 5, column: 'done', title: 'Set up CI', labels: ['devops'] },
],
wipStrict: true, toolbar: true, quickAdd: true,
});
board.on('cardMove', (e) => { output.textContent = 'moved card ' + e.card.id + ' to ' + e.to.column + ' (' + e.reason + ')'; });
board.on('wipExceed', (e) => { output.textContent = 'the column ' + e.column + ' is full'; });Chat e AI Prompt
Chat
Messaggi con Markdown, avatar e reazioni, suggerimenti e un indicatore di digitazione. Inviare un messaggio: un sostituto dell'altro interlocutore «scrive» e risponde. Passare il mouse su un messaggio per rispondere, reagire o copiare.
const app = document.getElementById('app');
app.style.height = '420px';
const chat = VibeFoxJSUi.createChat('#app', {
user: { id: 'me', name: 'Me' },
users: [{ id: 'ann', name: 'Ann Lee', status: 'online' }],
messages: [
{ id: 1, author: 'ann', text: 'Hi! Did you see **the report**?', time: Date.now() - 3600000 },
{ id: 2, author: 'me', text: 'Not yet, sending it to the printer.', time: Date.now() - 3500000, reactions: { '👍': ['ann'] } },
{ id: 3, author: 'ann', text: 'The numbers are in `Q3.xlsx`:\n- sales +12%\n- costs -3%', time: Date.now() - 60000 },
],
suggestions: ['Thanks!', 'I will check it'],
});
// stand-in for the other side: types for a second, then answers
chat.on('send', (e) => {
setTimeout(() => chat.setTyping(['ann']), 300);
setTimeout(() => { chat.setTyping([]); chat.addMessage({ author: 'ann', text: 'You wrote: *' + e.message.text + '*' }); }, 1500);
});AI Prompt
Una chat con un assistente la cui risposta arriva in streaming, parola per parola. La funzione request qui è un sostituto del modello (nulla viene inviato altrove). Fare clic su un suggerimento oppure porre una domanda; Stop interrompe la risposta.
const app = document.getElementById('app');
app.style.height = '420px';
// stand-in for your model: an async generator that streams the answer word by word
async function* fakeModel(prompt, ctx) {
const answer = 'You asked: "' + prompt + '". This is a **streamed** answer from a stand-in model. ' +
'Your request function can return a string, an async iterable, a ReadableStream or a Response of your server.';
for (const word of answer.split(' ')) {
if (ctx.signal.aborted) return;
await new Promise((resolve) => setTimeout(resolve, 60));
yield word + ' ';
}
}
const ai = VibeFoxJSUi.createAIPrompt('#app', {
assistant: { name: 'Assistant' },
suggestions: ['Summarize my week', 'Draft an e-mail'],
request: (prompt, ctx) => fakeModel(prompt, ctx),
retry: true,
});Gestore di file
Un esploratore basato su un adapter in memoria (il backend va collegato a questo punto): aprire le cartelle nell'albero, passare dalla vista dettagli alla vista a riquadri, ordinare, cercare, rinominare (F2), copiare e incollare, trascinare i file nelle cartelle, fare clic destro per il menu.
const fm = VibeFoxJSUi.createFileManager('#app', {
adapter: VibeFoxJSUi.createMemoryFileAdapter([
{ name: 'Documents', children: [
{ name: 'report.pdf', size: 120000 }, { name: 'notes.txt', content: 'Hello from the notes' }, { name: 'budget.xlsx', size: 48000 },
{ name: 'Contracts', children: [{ name: 'lease.pdf', size: 230000 }] },
] },
{ name: 'Images', children: [{ name: 'logo.svg', size: 3200 }, { name: 'team.jpg', size: 840000 }] },
{ name: 'readme.md', content: '# Read me' },
]),
view: 'details', tree: true, preview: true, height: 400,
});
fm.navigate('/Documents');Costruttore di query
Condizioni con gruppi AND / OR; di seguito sono riportati l'SQL con i parametri, il testo leggibile e le righe di una piccola tabella che corrispondono. Aggiungere una regola o un gruppo, modificare un campo o un operatore.
const output = document.createElement('pre');
output.style.cssText = 'margin: 12px 0 0; min-height: 3em; font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap';
document.getElementById('app').after(output);
const rows = [
{ name: 'Ann', score: 70, city: 'Berlin', active: true }, { name: 'Bob', score: 45, city: 'Paris', active: true },
{ name: 'Cleo', score: 88, city: 'Berlin', active: false }, { name: 'Dan', score: 52, city: 'Rome', active: true },
];
const qb = VibeFoxJSUi.createQueryBuilder('#app', {
fields: [
{ field: 'name', label: 'Name', type: 'text' },
{ field: 'score', label: 'Score', type: 'number' },
{ field: 'city', label: 'City', type: 'list', options: ['Berlin', 'Paris', 'Rome'] },
{ field: 'active', label: 'Active', type: 'boolean' },
],
value: { op: 'and', rules: [{ field: 'score', op: '>=', value: 50 }, { field: 'city', op: 'in', values: ['Berlin', 'Rome'] }] },
});
const show = () => {
const { sql, params } = qb.toSQL({ params: true });
output.textContent = 'SQL: ' + sql + '\nparams: ' + JSON.stringify(params) + '\ntext: ' + qb.toText() +
'\nrows: ' + rows.filter(qb.getPredicate()).map((r) => r.name).join(', ');
};
qb.on('valueChange', show);
show();Foglio di calcolo
Un foglio con formule, formati numerici e stili, la barra della formula e la toolbar. Modificare un numero in Units e vedere i totali aggiornarsi; digitare =TAX(D4) in una cella per usare la funzione personalizzata.
const sheet = VibeFoxJSUi.createSpreadsheet('#app', {
data: { sheets: [{ name: 'Sales', rows: [
['Month', 'Units', 'Price', 'Total'],
['Jan', 10, 2.5, '=B2*C2'],
['Feb', 14, 2.5, '=B3*C3'],
['Mar', 9, 2.75, '=B4*C4'],
], styles: { 'A1:D1': { bold: true, fill: '#e0f2fe' }, 'C2:D5': { numFmt: '#,##0.00' } }, colWidths: { A: 100 } }, { name: 'Notes', rows: [['See Sales']] }] },
functions: { TAX: (x) => x * 0.2 },
rows: 12, cols: 6,
});
sheet.setCell('A5', 'Total');
sheet.setCell('D5', '=SUM(D2:D4)');
sheet.setStyle('A5:D5', { bold: true, fill: '#fef3c7' });Editor di immagini
L'editor con un'immagine disegnata nel codice: ritaglio, rotazione, ribaltamento, filtri e annotazioni, con annullamento. Scegliere uno strumento nella toolbar, aggiungere una freccia o un testo, provare un filtro.
// a picture made in the code (your image, URL, File or Blob goes here)
const canvas = document.createElement('canvas');
canvas.width = 640; canvas.height = 400;
const g = canvas.getContext('2d');
const sky = g.createLinearGradient(0, 0, 0, 400);
sky.addColorStop(0, '#38bdf8'); sky.addColorStop(1, '#e0f2fe');
g.fillStyle = sky; g.fillRect(0, 0, 640, 400);
g.fillStyle = '#facc15'; g.beginPath(); g.arc(500, 90, 45, 0, Math.PI * 2); g.fill();
g.fillStyle = '#166534'; g.beginPath(); g.moveTo(0, 400); g.lineTo(200, 170); g.lineTo(360, 330); g.lineTo(470, 220); g.lineTo(640, 400); g.fill();
const editor = VibeFoxJSUi.createImageEditor('#app', { src: canvas, history: true, format: 'image/png' });
editor.addShape({ type: 'text', x: 30, y: 30, text: 'Draft', size: 36, color: '#dc2626' });Pad per la firma e codici a barre
SignaturePad
Firmare con il mouse, una penna o un dito (il tratto segue la velocità); annulla, ripristina e cancella sono nella toolbar. Export mostra le dimensioni del PNG e dell'SVG.
function addButtons(buttons) {
const bar = document.createElement('div');
bar.id = 'bar';
bar.style.cssText = 'display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px';
for (const [label, click, variant] of buttons) {
VibeFoxJSUi.createButton(bar.appendChild(document.createElement('span')), { label, variant: variant || 'secondary', on: { click } });
}
document.getElementById('app').before(bar);
}
const output = document.createElement('pre');
output.style.cssText = 'margin: 12px 0 0; min-height: 3em; font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap';
document.getElementById('app').after(output);
document.getElementById('app').style.maxWidth = '480px';
const sign = VibeFoxJSUi.createSignaturePad('#app', { label: 'Signature', penWidth: 2.5, velocity: 0.6, guide: true });
sign.setValue({ width: 300, height: 120, strokes: [{ points: [[20, 80, 1], [60, 40, 1], [90, 85, 1], [130, 45, 1], [170, 90, 1], [220, 60, 1]] }] });
addButtons([['Export', () => {
if (sign.isEmpty()) { output.textContent = 'empty'; return; }
output.textContent = 'PNG data URL ' + sign.toDataURL('image/png', { trim: true }).length + ' chars, SVG ' + sign.toSVG().length + ' chars';
}]]);
sign.on('strokeEnd', () => { output.textContent = 'stroke added'; });Codici QR e codici a barre
Un codice QR, una Data Matrix, un EAN-13 e un Code 128 generati nel browser (anche in Node). Digitare nel campo per modificare il codice QR.
const app = document.getElementById('app');
app.style.cssText = 'display: grid; gap: 16px';
app.innerHTML =
'<div><label for="text">QR text</label><div id="text"></div></div>' +
'<div id="codes"></div>';
document.getElementById('codes').style.cssText = 'display: flex; flex-wrap: wrap; gap: 24px; align-items: flex-end';
const place = () => document.getElementById('codes').appendChild(document.createElement('div'));
const qr = VibeFoxJSUi.createQRCode(place(), { value: 'https://example.com/ticket/42', ecLevel: 'M', moduleSize: 4, label: 'Ticket link' });
VibeFoxJSUi.createBarcode(place(), { type: 'datamatrix', value: 'ORDER-42', moduleSize: 5, label: 'Order code' });
VibeFoxJSUi.createBarcode(place(), { type: 'ean13', value: '400638133393', text: true, height: 60, label: 'EAN-13' });
VibeFoxJSUi.createBarcode(place(), { type: 'code128', value: 'VFJS-UI-2026', text: true, height: 60, label: 'Code 128' });
const text = VibeFoxJSUi.createInput('#text', { value: 'https://example.com/ticket/42' });
text.on('valueChange', (e) => qr.setValue(e.value || ' '));Temi e stile
Temi
Gli stessi controlli in ogni tema: i tre integrati e il pacchetto vibefox-js-themes.css. Scegliere un tema nell'elenco.
const app = document.getElementById('app');
app.style.cssText = 'display: grid; gap: 12px';
app.innerHTML =
'<div><label for="theme">Theme</label><div id="theme"></div></div>' +
'<div id="demo"></div>';
const demo = document.getElementById('demo');
demo.style.cssText = 'display: grid; gap: 12px; padding: 16px; border-radius: 8px; background: var(--vfjs-bg); color: var(--vfjs-fg)';
demo.innerHTML = '<div id="t-buttons" style="display: flex; gap: 8px"></div><div id="t-input"></div><div id="t-switch"></div><div id="t-tabs"></div><div id="t-slider"></div>';
VibeFoxJSUi.createButton(document.getElementById('t-buttons').appendChild(document.createElement('span')), { label: 'Primary' });
VibeFoxJSUi.createButton(document.getElementById('t-buttons').appendChild(document.createElement('span')), { label: 'Secondary', variant: 'secondary' });
VibeFoxJSUi.createInput('#t-input', { label: 'Name', value: 'Ann Lee' });
VibeFoxJSUi.createSwitch('#t-switch', { label: 'Notifications', checked: true });
VibeFoxJSUi.createTabs('#t-tabs', { tabs: [{ id: 'a', label: 'Overview', content: 'Text' }, { id: 'b', label: 'Details', content: 'More' }] });
VibeFoxJSUi.createSlider('#t-slider', { label: 'Volume', value: 40 });
const names = ['light', 'dark', 'high-contrast', 'high-contrast-light', 'paper', 'paper-dark', 'glass', 'glass-dark', 'classic', 'classic-dark',
'ocean', 'ocean-dark', 'forest', 'forest-dark', 'sunset', 'sunset-dark', 'graphite', 'graphite-dark'];
const theme = VibeFoxJSUi.createSelect('#theme', { value: 'light', options: names.map((name) => ({ value: name, label: name })) });
theme.on('valueChange', (e) => VibeFoxJSUi.setTheme(e.value, demo));Variabili CSS
Ogni colore e dimensione è una variabile CSS. Scegliere un colore di accento e un raggio degli angoli: una regola CSS imposta --vfjs-accent e --vfjs-radius sul riquadro sottostante, e ogni controllo al suo interno si adegua.
const app = document.getElementById('app');
app.style.cssText = 'display: grid; gap: 14px; max-width: 420px';
app.innerHTML =
'<div><label for="accent">Accent color</label><div id="accent"></div></div>' +
'<div><label for="radius">Corner radius</label><div id="radius"></div></div>' +
'<div id="demo"></div>';
const demo = document.getElementById('demo');
demo.style.cssText = 'display: grid; gap: 12px; padding-top: 8px';
demo.innerHTML = '<div id="v-button"></div><div id="v-select"></div><div id="v-check"></div><div id="v-slider"></div>';
VibeFoxJSUi.createButton('#v-button', { label: 'Save', icon: 'check' });
VibeFoxJSUi.createSelect('#v-select', { label: 'Plan', value: 'pro', options: [{ value: 'free', label: 'Free' }, { value: 'pro', label: 'Pro' }] });
VibeFoxJSUi.createCheckbox('#v-check', { label: 'Remember me', checked: true });
VibeFoxJSUi.createSlider('#v-slider', { label: 'Level', value: 60 });
const accent = VibeFoxJSUi.createColorPicker('#accent', { value: '#0f766e', swatches: ['#2563eb', '#0f766e', '#c026d3', '#ea580c', '#1f2937'] });
const radius = VibeFoxJSUi.createSlider('#radius', { min: 0, max: 16, value: 4, tooltip: true });
// the variables go on the box: every component inside follows
const rule = document.head.appendChild(document.createElement('style'));
const apply = () => { rule.textContent = '#demo { --vfjs-accent: ' + accent.getValue() + '; --vfjs-radius: ' + radius.getValue() + 'px; }'; };
accent.on('valueChange', apply);
radius.on('valueChange', apply);
apply();Varianti e dimensioni
Gli aspetti filled, outline e ghost nelle dimensioni s, m e l si impostano una volta sola su un contenitore con data-vfjs-ui-variant / data-vfjs-ui-size.
const app = document.getElementById('app');
app.style.cssText = 'display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px';
for (const variant of ['filled', 'outline', 'ghost']) {
for (const size of ['s', 'm', 'l']) {
const box = app.appendChild(document.createElement('div'));
box.setAttribute('data-vfjs-ui-variant', variant);
box.setAttribute('data-vfjs-ui-size', size);
box.style.cssText = 'display: grid; gap: 6px; align-content: start';
box.appendChild(document.createElement('b')).textContent = variant + ' / ' + size;
VibeFoxJSUi.createInput(box.appendChild(document.createElement('div')), { label: 'Name', placeholder: 'Name' });
VibeFoxJSUi.createSelect(box.appendChild(document.createElement('div')), { label: 'Plan', value: 'pro', options: [{ value: 'pro', label: 'Pro' }, { value: 'free', label: 'Free' }] });
VibeFoxJSUi.createButton(box.appendChild(document.createElement('div')), { label: 'Button' });
}
}Densità e dimensione
Cambiare la densità del contenitore: altezze e spaziature di ogni controllo al suo interno si adeguano. L'unità di dimensione --vfjs-size-unit scala tutto insieme.
const app = document.getElementById('app');
app.style.cssText = 'display: grid; gap: 14px; max-width: 420px';
app.innerHTML =
'<div><label for="density">Density</label><div id="density"></div></div>' +
'<div><label for="unit">Size unit</label><div id="unit"></div></div>' +
'<div id="demo"></div>';
const demo = document.getElementById('demo');
demo.style.cssText = 'display: grid; gap: 10px';
demo.innerHTML = '<div id="d-input"></div><div id="d-list"></div><div id="d-button"></div>';
VibeFoxJSUi.createInput('#d-input', { label: 'Search', prefix: 'search', placeholder: 'Search' });
VibeFoxJSUi.createListBox('#d-list', { label: 'Items', data: ['First', 'Second', 'Third'], value: 'Second' });
VibeFoxJSUi.createButton('#d-button', { label: 'Apply' });
const density = VibeFoxJSUi.createSegmented('#density', { value: 'normal', items: ['compact', 'normal', 'comfortable'] });
density.on('valueChange', (e) => demo.setAttribute('data-vfjs-density', e.value));
const unit = VibeFoxJSUi.createSlider('#unit', { min: 0.8, max: 1.3, step: 0.05, value: 1, tooltip: true });
unit.on('valueChange', (e) => demo.style.setProperty('--vfjs-size-unit', e.value + 'px'));Il proprio CSS
Le regole della libreria si trovano nel layer di cascata vfjs, quindi il CSS normale della pagina prevale senza !important: qui i pulsanti primari sono scritti in maiuscolo e i pulsanti toggle premuti hanno il testo in grassetto.
const style = document.createElement('style');
style.textContent = '.vfjs-ui-btn--primary { text-transform: uppercase; letter-spacing: .04em; }' +
' .vfjs-ui-btn--pressed { font-weight: 700; }';
document.head.appendChild(style);
const app = document.getElementById('app');
app.style.cssText = 'display: flex; flex-wrap: wrap; gap: 12px; align-items: center';
VibeFoxJSUi.createButton(app.appendChild(document.createElement('span')), { label: 'Save' });
VibeFoxJSUi.createButton(app.appendChild(document.createElement('span')), { label: 'Cancel', variant: 'secondary' });
VibeFoxJSUi.createButtonGroup(app.appendChild(document.createElement('span')), { label: 'Period', selection: 'single', value: 'week',
items: [{ id: 'day', label: 'Day' }, { id: 'week', label: 'Week' }, { id: 'month', label: 'Month' }] });Localizzazione e RTL
Lingue
L'inglese è integrato, il russo proviene dal pacchetto linguistico vibefox-js-ui.ru.js caricato dopo la libreria. Cambiare la lingua della pagina: il calendario, la select, la paginazione e il riquadro di caricamento vengono ridisegnati nella nuova lingua.
const app = document.getElementById('app');
app.style.cssText = 'display: grid; gap: 14px; justify-items: start';
app.innerHTML =
'<div id="lang"></div>' +
'<div id="select"></div>' +
'<div id="pages"></div>' +
'<div id="calendar"></div>';
const lang = VibeFoxJSUi.createSegmented('#lang', { label: 'Language', value: 'en', items: [{ value: 'en', label: 'English' }, { value: 'ru', label: 'Русский' }] });
lang.on('valueChange', (e) => VibeFoxJSUi.setLocale(e.value));
VibeFoxJSUi.createSelect('#select', { options: [{ value: 1, label: 'One' }, { value: 2, label: 'Two' }] });
VibeFoxJSUi.createPagination('#pages', { total: 120, pageSize: 20, showTotal: true });
VibeFoxJSUi.createDatePicker('#calendar', { inline: true, value: '2026-11-03' });Aggiunta di una lingua
addLocale() aggiunge stringhe in tedesco per alcune chiavi; le chiavi non indicate ricadono sull'inglese. La select e la paginazione usano la localizzazione de.
VibeFoxJSUi.addLocale('de', {
'ui.select.placeholder': 'Auswählen…',
'ui.select.searchPlaceholder': 'Suchen…',
'ui.select.empty': 'Nichts gefunden',
'ui.pagination.total': '{total} Einträge',
'ui.pagination.perPage': '/ Seite',
'ui.pagination.prev': 'Vorherige Seite',
'ui.pagination.next': 'Nächste Seite',
});
const app = document.getElementById('app');
app.style.cssText = 'display: grid; gap: 14px; justify-items: start';
app.innerHTML =
'<div id="select"></div>' +
'<div id="pages"></div>';
VibeFoxJSUi.createSelect('#select', { locale: 'de', searchable: true, options: [{ value: 1, label: 'Eins' }, { value: 2, label: 'Zwei' }] });
VibeFoxJSUi.createPagination('#pages', { locale: 'de', total: 120, pageSize: 20, pageSizes: [10, 20, 50], showTotal: true });Da destra a sinistra
Con rtl: true i componenti vengono disposti da destra a sinistra e i tasti freccia seguono l'ordine di lettura. Cambiare la direzione.
const app = document.getElementById('app');
app.style.cssText = 'display: grid; gap: 14px';
app.innerHTML =
'<div id="dir"></div>' +
'<div id="path"></div>' +
'<div id="tabs"></div>' +
'<div id="slider"></div>' +
'<div id="input"></div>';
const parts = [
VibeFoxJSUi.createBreadcrumb('#path', { items: [{ label: 'Home', href: '#' }, { label: 'Docs', href: '#' }, { label: 'UI' }] }),
VibeFoxJSUi.createTabs('#tabs', { tabs: [{ id: 'a', label: 'First', content: 'The first tab' }, { id: 'b', label: 'Second', content: 'The second tab' }, { id: 'c', label: 'Third', content: 'The third tab' }] }),
VibeFoxJSUi.createSlider('#slider', { label: 'Volume', value: 30 }),
VibeFoxJSUi.createInput('#input', { label: 'Search', prefix: 'search', clearable: true, value: 'text' }),
];
const dir = VibeFoxJSUi.createSegmented('#dir', { label: 'Direction', value: 'rtl', items: [{ value: 'ltr', label: 'Left to right' }, { value: 'rtl', label: 'Right to left' }] });
const apply = (value) => { for (const part of parts) part.setOptions({ rtl: value === 'rtl' }); };
dir.on('valueChange', (e) => apply(e.value));
apply('rtl');Accessibilità
Trascinamento e rilascio senza trascinare
Tutto ciò che si può trascinare ha anche un menu «Move…». Mettere a fuoco un elemento e premere Shift+F10, fare clic destro su di esso oppure fare clic sulla sua piccola maniglia di spostamento: spostare un'attività su, giù o nell'altro elenco.
const app = document.getElementById('app');
app.style.cssText = 'display: grid; grid-template-columns: 1fr 1fr; gap: 16px';
app.innerHTML =
'<div><label for="todo">To do</label><div id="todo"></div></div>' +
'<div><label for="done">Done</label><div id="done"></div></div>';
const output = document.createElement('pre');
output.style.cssText = 'margin: 12px 0 0; min-height: 3em; font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap';
document.getElementById('app').after(output);
const todo = VibeFoxJSUi.createListView('#todo', { draggable: true, dragGroup: 'tasks', height: 190,
data: ['Write docs', 'Fix login', 'Review PR', 'Plan sprint'] });
const done = VibeFoxJSUi.createListView('#done', { draggable: true, dragGroup: 'tasks', height: 190,
data: ['Set up CI', 'Design the logo'] });
for (const list of [todo, done]) list.on('itemMove', (e) => { output.textContent = 'moved ' + JSON.stringify(e.items || e.item || e.from) + ' (' + (e.reason || 'drag') + ')'; });Uso con altre librerie VibeFox JS
Collegamento dei componenti con link()
Un costruttore di query di VibeFox JS UI filtra una tabella di VibeFox JS Grid (entrambe le librerie nella pagina): link() passa ogni modifica delle condizioni a grid.setFilterModel(). Modificare una condizione e osservare le righe.
const app = document.getElementById('app');
app.innerHTML = '<div id="qb"></div><div id="grid" style="margin-top: 12px"></div>';
const qb = VibeFoxJSUi.createQueryBuilder('#qb', {
fields: [
{ field: 'name', label: 'Name', type: 'text' },
{ field: 'city', label: 'City', type: 'list', options: ['Berlin', 'Paris', 'Rome'] },
{ field: 'score', label: 'Score', type: 'number' },
],
value: { op: 'and', rules: [{ field: 'score', op: '>=', value: 50 }] },
});
const grid = VibeFoxJSGrid.createGrid('#grid', {
height: 220,
columns: [{ field: 'name', header: 'Name' }, { field: 'city', header: 'City' }, { field: 'score', header: 'Score', type: 'number' }],
data: [
{ name: 'Ann', city: 'Berlin', score: 70 }, { name: 'Bob', city: 'Paris', score: 45 }, { name: 'Cleo', city: 'Berlin', score: 88 },
{ name: 'Dan', city: 'Rome', score: 52 }, { name: 'Eve', city: 'Paris', score: 91 }, { name: 'Finn', city: 'Rome', score: 30 },
],
});
grid.setFilterModel(qb.getFilterModel());
const unlink = VibeFoxJSUi.link(qb, 'filterChange', grid, 'setFilterModel', (e) => e.filterModel);Strumenti AI
Il ciclo degli strumenti con una funzione modello sostitutiva nel codice (il modello va inserito in quel punto): richiede lo strumento sheet_set_range e nel foglio viene scritta una riga di totale; poi sheet_format_range la mette in grassetto. Fare clic su Ask.
function addButtons(buttons) {
const bar = document.createElement('div');
bar.id = 'bar';
bar.style.cssText = 'display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px';
for (const [label, click, variant] of buttons) {
VibeFoxJSUi.createButton(bar.appendChild(document.createElement('span')), { label, variant: variant || 'secondary', on: { click } });
}
document.getElementById('app').before(bar);
}
const output = document.createElement('pre');
output.style.cssText = 'margin: 12px 0 0; min-height: 3em; font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap';
document.getElementById('app').after(output);
const app = document.getElementById('app');
app.style.height = '260px';
const sheet = VibeFoxJSUi.createSpreadsheet('#app', { toolbar: false, data: { sheets: [{ name: 'Sales', rows: [['Month', 'Units'], ['Jan', 10], ['Feb', 14], ['Mar', 9]] }] } });
const kit = VibeFoxJSUi.createToolKit({ budget: sheet });
// stand-in for your model: first it calls the tools, then it answers with text
const model = async (request) => {
if (request.messages.at(-1).role === 'tool') return { text: 'Added a total row under the units.' };
return { toolCalls: [
{ id: 'c1', name: 'budget_sheet_set_range', arguments: { range: 'A5:B5', values: [['Total', '=SUM(B2:B4)']] } },
{ id: 'c2', name: 'budget_sheet_format_range', arguments: { range: 'A5:B5', style: { bold: true, fill: '#fef3c7' } } },
] };
};
addButtons([['Ask', async () => {
const answer = await kit.ask('Add a total row under the units', { model });
output.textContent = 'tools: ' + kit.tools().map((t) => t.name).join(', ') + '\ncalls: ' + answer.calls.map((c) => c.name + (c.result.ok ? ' ok' : ' error ' + c.result.error)).join(', ') + '\nmodel: ' + answer.text;
}, 'primary']]);