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,41 @@
|
||||
import React, { useState } from 'react';
|
||||
import './SwitchGroup.css';
|
||||
|
||||
export default function SwitchGroup({ options = [], value = [], title = '', selectAll = false, onChange }) {
|
||||
const allOn = options.length > 0 && options.every(o => value.indexOf(o.value) >= 0);
|
||||
|
||||
function toggle(v) {
|
||||
const arr = value.slice();
|
||||
const idx = arr.indexOf(v);
|
||||
if (idx >= 0) arr.splice(idx, 1); else arr.push(v);
|
||||
onChange && onChange(arr);
|
||||
}
|
||||
function toggleAll() {
|
||||
onChange && onChange(allOn ? [] : options.map(o => o.value));
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="aa-switchgroup">
|
||||
{(title || selectAll) ? (
|
||||
<div className="aa-switchgroup-head">
|
||||
<span className="aa-switchgroup-title">{title}</span>
|
||||
{selectAll ? (
|
||||
<div className={'aa-switch' + (allOn ? ' is-on' : '')} onClick={toggleAll} />
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
{options.map((o, i) => (
|
||||
<div className="aa-switch-row" key={i}>
|
||||
<div className="aa-switch-text">
|
||||
<span className="aa-switch-label">{o.label}</span>
|
||||
{o.desc ? <span className="aa-switch-desc">{o.desc}</span> : null}
|
||||
</div>
|
||||
<div
|
||||
className={'aa-switch' + (value.indexOf(o.value) >= 0 ? ' is-on' : '')}
|
||||
onClick={() => toggle(o.value)}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user