mirror of
https://github.com/lWolvesl/antigravity-usage-monitor.git
synced 2026-11-26 17:09:28 +08:00
feat(panel): upgrade modular dashboard UI, 6-segment context meter, and consumption analytics
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* @fileoverview Micro-bezel (2px radius) SegmentedControl switcher
|
||||
* for time-range filtering, context limit selection, and sub-table switching.
|
||||
*/
|
||||
|
||||
import { defineComponent } from '../../core/component.js';
|
||||
import { h, patchAttr, patchClasses, patchKeyedList, patchText } from '../../core/domPatch.js';
|
||||
|
||||
export const SegmentedControl = defineComponent({
|
||||
name: 'SegmentedControl',
|
||||
setup({ getProps, emit }) {
|
||||
const rootEl = h('div', {
|
||||
className: 'segmented',
|
||||
role: 'group',
|
||||
'aria-label': getProps().ariaLabel || '分段切换器',
|
||||
});
|
||||
|
||||
function syncSegments() {
|
||||
const { options = [], modelValue } = getProps();
|
||||
patchKeyedList(rootEl, options, {
|
||||
keyFn: (opt) => opt.value,
|
||||
sigFn: (opt) => `${opt.value}::${opt.label}::${opt.value === modelValue}`,
|
||||
createRow: (opt) => {
|
||||
const btn = h('button', {
|
||||
type: 'button',
|
||||
className: 'seg-btn',
|
||||
onClick: (e) => {
|
||||
e.stopPropagation();
|
||||
if (getProps().modelValue !== opt.value) {
|
||||
emit('update:modelValue', opt.value);
|
||||
}
|
||||
},
|
||||
});
|
||||
return { el: btn, refs: {} };
|
||||
},
|
||||
updateRow: (_refs, opt, _idx, el) => {
|
||||
const active = opt.value === modelValue;
|
||||
patchText(el, opt.label);
|
||||
patchClasses(el, { 'is-active': active });
|
||||
patchAttr(el, 'aria-pressed', active ? 'true' : 'false');
|
||||
patchAttr(el, 'data-seg-value', opt.value);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
syncSegments();
|
||||
|
||||
return {
|
||||
el: rootEl,
|
||||
refs: {},
|
||||
onPropsChange: syncSegments,
|
||||
getValue: () => getProps().modelValue,
|
||||
};
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user