Aurora Admin v1.2.0: 79 components x 5 ends, doc site, contracts batch 1, playground, regression, deploy ready
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
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>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user