Debian Codegraph @

node/@patternfly/react-core/src/components/Breadcrumb/BreadcrumbItem.tsx

raw
1 import RhMicronsCaretRightIcon from '@patternfly/react-icons/dist/esm/icons/rh-microns-caret-right-icon';
2 import styles from '@patternfly/react-styles/css/components/Breadcrumb/breadcrumb';
3 import { css } from '@patternfly/react-styles';
4
5 export interface BreadcrumbItemRenderArgs {
6 className: string;
7 ariaCurrent: 'page' | undefined;
8 }
9
10 export interface BreadcrumbItemProps extends React.HTMLProps<HTMLLIElement> {
11 /** Content rendered inside the breadcrumb item. */
12 children?: React.ReactNode;
13 /** Additional classes added to the breadcrumb item. */
14 className?: string;
15 /** HREF for breadcrumb link. */
16 to?: string;
17 /** Flag indicating whether the item is active. */
18 isActive?: boolean;
19 /** Flag indicating whether the item contains a dropdown. */
20 isDropdown?: boolean;
21 /** Internal prop set by Breadcrumb on all but the first crumb */
22 showDivider?: boolean;
23 /** Target for breadcrumb link. */
24 target?: string;
25 /** Sets the base component to render. Defaults to <a> */
26 component?: React.ElementType;
27 /** A render function to render the component inside the breadcrumb item. */
28 render?: (props: BreadcrumbItemRenderArgs) => React.ReactNode;
29 }
30
31 export const BreadcrumbItem: React.FunctionComponent<BreadcrumbItemProps> = ({
32 children = null,
33 className: classNameProp = '',
34 to = undefined,
35 isActive = false,
36 isDropdown = false,
37 showDivider,
38 target = undefined,
39 component = 'a',
40 render = undefined,
41 ...props
42 }: BreadcrumbItemProps) => {
43 const Component = component;
44 const ariaCurrent = isActive ? 'page' : undefined;
45 const className = css(styles.breadcrumbLink, isActive && styles.modifiers.current);
46 return (
47 <li {...props} className={css(styles.breadcrumbItem, classNameProp)}>
48 {showDivider && (
49 <span className={styles.breadcrumbItemDivider}>
50 <RhMicronsCaretRightIcon />
51 </span>
52 )}
53 {component === 'button' && (
54 <button className={className} aria-current={ariaCurrent} type="button">
55 {children}
56 </button>
57 )}
58 {isDropdown && <span className={css(styles.breadcrumbDropdown)}>{children}</span>}
59 {render && render({ className, ariaCurrent })}
60 {to && !render && (
61 <Component href={to} target={target} className={className} aria-current={ariaCurrent}>
62 {children}
63 </Component>
64 )}
65 {!to && component !== 'button' && !isDropdown && children}
66 </li>
67 );
68 };
69 BreadcrumbItem.displayName = 'BreadcrumbItem';