/
vshmidt
/
label-studio
Обзор
Документация
Войти
/
vshmidt
/
label-studio
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
web/libs/editor/src/common/Menu/MenuItem.jsx
74 строки
1 KB
Raul Martin
chore: ECHO-425: add plugin to validate toClassName on cn (#9397)
19 фев 2026, 21:02
Не верифицирован
19 фев 2026, 21:02
811ff0f
Код
Авторство
О чём код?
import React from "react"; import { useMemo } from "react"; import { cn } from "../../utils/bem"; import { MenuContext } from "./MenuContext"; export const MenuItem = ({ name, children, label, icon, to, className, href, danger, exact = false, forceReload = false, active = false, onClick, ...rest }) => { const { selected, allowClickSelected } = React.useContext(MenuContext); const rootClass = cn("menu", { elem: "item" }); const isActive = (() => { const pathname = window.location.pathname.replace(/\/$/, ""); const url = to ?? href; if (selected.has(name)) { return true; } if (exact) { return pathname === url; } return pathname.includes(url); })(); const linkContent = useMemo( () => ( <> {icon && <span className={rootClass.elem("item-icon").toClassName()}>{icon}</span>} {children ?? label} </> ), [children, label, icon], ); const linkAttributes = { role: "menuitem", className: rootClass .mod({ active: isActive || active, look: danger && "danger", clickable: allowClickSelected, }) .mix(className), onClick, ...rest, }; if (forceReload) { linkAttributes.onClick = () => (window.location.href = to ?? href); } return ( <li> {href ? ( <a href={href ?? "#"} {...linkAttributes}> {linkContent} </a> ) : ( <div {...linkAttributes}>{linkContent}</div> )} </li> ); };