Files
aurora-admin/site/sources/buttongroup/jsx.txt
T
aurora-admin c65a69c34e
Deploy to GitHub Pages / deploy (push) Failing after 16s
Regression / regression (push) Failing after 15m2s
feat(P4): precompute移植+app.js sources双向回填+回归1003/1003+验收体积/文件/data.json
2026-09-12 14:18:41 +08:00

38 lines
1.0 KiB
Plaintext

import React from 'react';
import './ButtonGroup.css';
export default function ButtonGroup({ options = [], value, multiple = false, size = 'default', onChange }) {
function isSelected(v) {
return multiple ? (value || []).indexOf(v) >= 0 : value === v;
}
function toggle(o) {
if (o.disabled) return;
let next;
if (multiple) {
const arr = (value || []).slice();
const idx = arr.indexOf(o.value);
if (idx >= 0) arr.splice(idx, 1); else arr.push(o.value);
next = arr;
} else {
next = o.value;
}
onChange && onChange(next);
}
const sizeCls = size === 'small' ? ' is-sm' : size === 'large' ? ' is-lg' : '';
return (
<div className={'aa-btngroup' + sizeCls}>
{options.map((o, i) => (
<button
key={i}
className={'aa-btngroup-btn' + (isSelected(o.value) ? ' is-selected' : '') + (o.disabled ? ' is-disabled' : '')}
disabled={!!o.disabled}
onClick={() => toggle(o)}
>
{o.label}
</button>
))}
</div>
);
}