UNPKG

@gravity-ui/uikit

Version:

Gravity UI base styling and components

81 lines (80 loc) 3.26 kB
'use client'; import { jsx as _jsx } from "react/jsx-runtime"; import * as React from 'react'; import { ListItemView } from "../lab/ListItemView/ListItemView.js"; import { filterDOMProps } from "../utils/filterDOMProps.js"; import { useMenuContext } from "./BreadcrumbsDropdownMenu.js"; import { b } from "./utils.js"; function BreadcrumbsItem(props, ref) { const domProps = filterDOMProps(props, { labelable: true }); const { href, hrefLang, target, rel, download, ping, referrerPolicy, children, __disabled: disabled, __current: current, __onAction: onAction, __index: index, ...restProps } = props; const handleAction = (event) => { if (disabled) { event.preventDefault(); return; } if (typeof restProps.onClick === 'function') { restProps.onClick(event); } if (typeof onAction === 'function') { onAction(); } }; const linkProps = { onClick: handleAction, 'aria-disabled': disabled ? true : undefined, }; if (href) { linkProps.href = href; linkProps.hrefLang = hrefLang; linkProps.target = target; linkProps.rel = target === '_blank' && !rel ? 'noopener noreferrer' : rel; linkProps.download = download; linkProps.ping = ping; linkProps.referrerPolicy = referrerPolicy; linkProps.tabIndex = disabled ? -1 : undefined; } else { linkProps.role = 'link'; linkProps.tabIndex = disabled ? undefined : 0; linkProps.onKeyDown = (event) => { if (disabled) { event.preventDefault(); return; } if (typeof restProps.onKeyDown === 'function') { restProps.onKeyDown(event); } if (event.key === 'Enter') { if (typeof onAction === 'function') { onAction(); } } }; } if (current) { linkProps['aria-current'] = props['aria-current'] ?? 'page'; } const Element = href ? 'a' : 'span'; const { isMenu, getItemProps, listItemsRef, activeIndex, popupStyle } = useMenuContext(); if (isMenu) { const active = !disabled && activeIndex === index; return (_jsx(ListItemView, { ...getItemProps({ ...restProps, ...domProps, ...linkProps, role: 'menuitem', active, }), ref: (node) => { listItemsRef.current[index ?? 0] = node; }, nestedLevel: popupStyle === 'staircase' ? index : undefined, tabIndex: active ? 0 : -1, active: active, size: "m", className: b('menu-link', props.className), component: Element, disabled: disabled, children: children })); } return (_jsx(Element, { ...restProps, ...domProps, ...linkProps, ref: ref, className: b('link', { 'is-current': current, 'is-disabled': disabled && !current, }, props.className), children: children })); } BreadcrumbsItem.displayName = 'Breadcrumbs.Item'; const _BreadcrumbsItem = React.forwardRef(BreadcrumbsItem); export { _BreadcrumbsItem as BreadcrumbsItem }; //# sourceMappingURL=BreadcrumbsItem.js.map