VibeFox JS UI — 演示
快速开始
纯 HTML
快速开始中的订单表单:可搜索的下拉框、不允许选择过去日期的日期选择器,以及一个显示 Toast 的按钮。打开下拉框并输入内容进行筛选,选择日期,然后点击 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') } });核心概念
事件
每个事件处理函数都会接收一个负载对象。拖动滑块或使用方向键:值变化时触发 valueChange,滑块松开时触发 slideEnd。
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');状态快照
getState() 返回用户所做的更改,setState() 用于恢复这些更改。选择一个标签页或将其拖动到其他位置,点击 Save state,再次更改标签页,然后点击 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()); }],
]);内容
标签页(对话框、面板、磁贴、卡片等)的内容可以是 HTML 字符串、DOM 节点,或用于填充元素的函数。三个标签页分别演示其中一种方式。
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(); } },
],
});按钮
Button
外观变体、图标以及禁用的按钮。点击 Save:在(模拟的)任务运行期间会显示加载指示器。
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 与 SplitButton
单选按钮组(对齐方式)、多选切换按钮组,以及带菜单的分离按钮。点击这些按钮,以及 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; });表单控件
Input 与 NumberInput
带掩码的电话字段、可清除的电子邮件字段,以及两个数字输入框。在 Phone 中输入数字,并在 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
带搜索、分组和标签的多选下拉框(先显示两个标签,然后是 "+N"),以及一个简单的单选下拉框。打开列表并输入内容进行筛选。
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
第一个字段从异步数据源加载建议项(用来模拟你的服务器,带有延迟);第二个字段对静态列表进行模糊筛选,并以 Chip 的形式保存多个值。在 City 中输入 "ber" 或 "pa",在 Fruits 中输入 "apl"。
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
开/关控件和多选一控件;下方的行显示它们的值。点击这些控件,或使用 Space 键和方向键。
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 and Rating
带两个滑块和提示的范围滑块、单个滑块,以及带半星和标签的评分。拖动滑块,将鼠标悬停在星星上。
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();OTP 输入框
分为两组、每组三位数字的一次性验证码。输入或粘贴 6 位验证码:所有单元格填满后会触发 complete。
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; });原生表单中的表单字段
普通 <form> 中的 VibeFox JS 控件:在必填字段为空时点击 Submit,会显示字段的提示信息并聚焦第一个字段;有效的表单会在下方显示其 FormData。点击 Reset 可恢复初始值。
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);日期、时间和颜色选择器
日期范围、带时间的日期、以 30 分钟为步长的时间,以及带透明度的颜色。打开每个选择器;日历支持方向键以及 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();列表与树
ListView and ListBox
带复选框的列表框(其中一项已禁用),以及可重新排序的列表:拖动某一项,按 Alt+ArrowUp / ArrowDown,或打开某一项的 Move 手柄以显示移动菜单。
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
选择要显示的列:使用按钮、双击或拖动,在列表之间移动项目,并对已选择的项目重新排序;最多可以选择四项。
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
带三态复选框、搜索和延迟加载子节点的树(文件夹 lib 会在短暂延迟后加载其中的文件,类似从服务器加载)。展开 lib,勾选项目,并在搜索框中输入内容。
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(', '); });表单与文件上传
Form
根据带规则的字段描述构建的表单。在字段为空时点击 Register,即可看到错误信息;有效的表单会在下方显示其值以及表单元素的 FormData。
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
分块上传,支持进度显示、取消和重试。这里的传输层是模拟你的服务器的部分(不会有任何数据离开页面):将文件拖到框中,或点击 Add sample files(第三个文件过大,会被拒绝)。
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'; });导航
Tabs and Accordion
可关闭、可重新排序的标签页(拖动标签页或使用其移动手柄),以及可同时展开多个分区的手风琴。点击标签页上的叉号或按 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 and Toolbar
一个下拉菜单,包含勾选项、分隔线和子菜单;另有与灰色框的上下文菜单(右键单击或按 Shift+F10)相同的菜单,以及带切换按钮的工具栏。下方的行显示点击的结果。
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 and Pagination
面包屑导航在项目过多时会折叠中间的项目;分页器可设置每页条数并显示总数。点击页码并更改每页条数。
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 and Wizard
向导的第一步会在继续前检查字段:在名称为空时点击 Next,即可看到错误信息。第二步是可选的;点击 Finish 显示结果。
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
可搜索的命令列表。点击 Open palette(或在示例内按 Ctrl+K / Cmd+K),输入 "dark" 或 "new" 并按 Enter;最近使用的命令排在最前面。
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']]);对话框与浮层
Dialog
带按钮的模态对话框,以及非模态窗口:打开两个窗口,通过标题栏拖动,通过角落调整大小,最大化或最小化;窗口菜单按钮可在不拖动的情况下移动窗口。
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
从某一边缘滑入的面板。可从左侧、右侧或底部打开;按 Esc 或点击遮罩层即可关闭。
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
位于角落的通知:四种类型,其中一种带有操作按钮(在使用前一直保留),另有一种跟随 Promise 的状态变化(加载中,然后完成)。最多同时显示三条,其余的等待显示。
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 and Popover
工具提示在鼠标悬停和键盘聚焦时显示;带标题和富文本内容的弹出框在点击时打开。将鼠标悬停到 Help 上或用 Tab 键切换到它,然后点击 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
引导导览:为每个目标元素高亮显示,并配有步骤卡片。点击 Start tour,然后使用 Next 或方向键浏览各步骤。
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']]);布局
Splitter
三个窗格,之间有可拖动的分隔条;双击第一个分隔条可将其折叠。点击分隔条会打开其移动菜单,聚焦分隔条后可用方向键移动它。
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
类似 IDE 的分区面板。将面板标签拖动到其他区域,或打开标签的移动手柄(或按 Alt+方向键),即可将其停靠到左侧、顶部、中部、底部或右侧。
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
仪表盘网格:通过标题拖动磁贴,通过角落调整其大小,或点击抓手以打开移动菜单(移动、加宽、变窄等)。Ctrl+Z 撤销更改;在较窄的宽度下,磁贴的列数会减少。
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('; '); });数据展示
Card
包含图片、标题、文本和操作按钮的卡片:带阴影的卡片、带边框的卡片,以及作为链接的卡片。点击 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
带首字母的头像、带状态的头像和 "+2" 组合;可选择和删除的筛选 Chip;按钮上带计数的徽章以及圆点徽章。
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
进度条、加载指示器和骨架屏占位符。点击 Load:进度条填满,然后骨架屏被内容替换。
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
带箭头、指示点、滑动手势和循环播放的轮播;根据宽度,同时显示一张、两张或三张幻灯片。可使用箭头、圆点或方向键。
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);看板
带 WIP 限制(2)的看板,其中 In progress 列有标签、负责人、截止日期和进度。在列之间拖动卡片,或打开卡片上的小移动手柄以使用其 "Move" 菜单;使用搜索和快速添加功能,Ctrl+Z 可撤销移动操作。
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'; });聊天与 AI 提示
Chat
支持 Markdown、头像、表情回应、建议项和输入指示器的消息。发送一条消息:代替对方的模拟程序会"输入"并作出回复。将鼠标悬停在消息上,即可进行回复、添加表情回应和复制。
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
与助手的聊天,其回答会逐词流式输出。这里的 request 函数是模拟你的模型的占位实现(不会向任何地方发送内容)。点击某个建议项或提出问题;Stop 会中止回答。
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,
});文件管理器
基于内存适配器(你的后端应接入此处)的资源管理器:在树中打开文件夹,切换详细信息/平铺视图,进行排序和搜索,重命名(F2),复制和粘贴,将文件拖到文件夹中,右键单击可打开菜单。
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');查询构建器
带 AND / OR 分组的条件;下方显示带参数的 SQL、可读文本,以及小表中与之匹配的行。添加规则或分组,更改字段或运算符。
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();电子表格
带公式、数字格式和样式的表格,以及公式栏和工具栏。更改 Units 中的数字,即可看到总计随之变化;在单元格中输入 =TAX(D4) 即可使用自定义函数。
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' });图像编辑器
编辑器中有一张在代码中绘制的图片:裁剪、旋转、翻转、滤镜和注释,并支持撤销。在工具栏中选择工具,添加箭头或文本,尝试应用滤镜。
// 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' });签名板与条形码
SignaturePad
使用鼠标、触控笔或手指签名(线条粗细会随书写速度变化);撤销、重做和清除功能位于工具栏中。点击 Export 可显示 PNG 和 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'; });二维码与条形码
在浏览器中生成的二维码、Data Matrix、EAN-13 和 Code 128(也可在 Node 中使用)。在输入框中输入内容即可更改二维码。
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 || ' '));主题与样式
主题
所有主题中的相同控件:内置的三个主题,以及 vibefox-js-themes.css 主题包。在列表中选择一个主题。
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));CSS 变量
每种颜色和尺寸都是 CSS 变量。选择强调色和圆角半径:一条 CSS 规则会在下方的方框上设置 --vfjs-accent 和 --vfjs-radius,其中的所有控件都会随之变化。
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();外观与尺寸
外观 filled、outline 和 ghost,尺寸 s、m 和 l,只需在容器上通过 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' });
}
}密度与尺寸
切换容器的密度:其中每个控件的高度和内边距都会随之变化。尺寸单位 --vfjs-size-unit 可一次性缩放所有内容。
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'));自定义 CSS
库的规则位于级联层 vfjs 中,因此页面自身的普通 CSS 无需使用 !important 即可生效:此处的主要按钮会显示为大写,按下的切换按钮会显示为粗体文字。
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' }] });本地化与 RTL
语言
内置英语;俄语来自在库之后加载的语言包 vibefox-js-ui.ru.js。切换页面语言:日历、下拉框、分页器和上传框都会以该语言重新渲染。
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' });添加语言
addLocale() 为部分键添加德语字符串;未提供的键将回退为英语。下拉框和分页器使用 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 });从右到左(RTL)
设置 rtl: true 后,组件将从右到左排列,方向键也会按照阅读顺序运作。切换方向。
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');无障碍
无需拖动的拖放
所有可拖动的内容也都提供 "Move…" 菜单。聚焦某一项并按 Shift+F10,或右键单击该项,或点击其小移动手柄:将任务上移、下移或移到另一个列表。
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') + ')'; });与其他 VibeFox JS 库配合使用
使用 link() 连接组件
VibeFox JS UI 的查询构建器会筛选 VibeFox JS Grid 的表格(页面上同时加载两个库):link() 会将条件的每次更改传递给 grid.setFilterModel()。更改条件并观察行的变化。
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);AI 工具
工具调用循环:代码中使用模拟的模型函数(你的模型应接入此处)。它请求工具 sheet_set_range,随后在表格中写入一行合计,再由 sheet_format_range 将其设为粗体。点击 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']]);