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

47 lines
1.3 KiB
Plaintext

import React, { useState } from 'react';
import './TopMenu.css';
export default function TopMenu({ items = [], activeKey = '', onChange }) {
const [active, setActive] = useState(activeKey);
function isActive(it) {
if (it.key === active) return true;
return (it.children || []).some(s => s.key === active);
}
function select(it) {
if (!it.children) {
setActive(it.key);
onChange && onChange(it.key);
}
}
return (
<div className="aa-topmenu">
{items.map((it, i) => (
<div
key={i}
className={'aa-topmenu-item' + (isActive(it) ? ' is-active' : '')}
onClick={() => select(it)}
>
<span>{it.label}</span>
{it.badge ? <span className="aa-topmenu-badge">{it.badge}</span> : null}
{it.children ? <span className="aa-topmenu-caret">▾</span> : null}
{it.children ? (
<div className="aa-topmenu-dropdown">
{it.children.map((s, si) => (
<a
key={si}
className={'aa-topmenu-sub' + (s.key === active ? ' is-active' : '')}
onClick={e => { e.stopPropagation(); select(s); }}
>
{s.label}
</a>
))}
</div>
) : null}
</div>
))}
</div>
);
}