Files
aurora-admin/site/sources/switchgroup/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

42 lines
1.3 KiB
Plaintext

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>
);
}