Debian Codegraph @

node/@patternfly/react-core/src/components/JumpLinks/JumpLinksItem.tsx

raw
1 import { Children } from 'react';
2 import { css } from '@patternfly/react-styles';
3 import styles from '@patternfly/react-styles/css/components/JumpLinks/jump-links';
4 import { JumpLinksList } from './JumpLinksList';
5 import { Button, ButtonVariant } from '../Button';
6
7 export interface JumpLinksItemProps extends Omit<React.HTMLProps<HTMLLIElement>, 'onClick'> {
8 /** Whether this item is active. Parent JumpLinks component sets this when passed a `scrollableSelector`. */
9 isActive?: boolean;
10 /** Href for this link */
11 href: string;
12 /** Selector or HTMLElement to spy on */
13 node?: string | HTMLElement;
14 /** Text to be rendered inside span */
15 children?: React.ReactNode;
16 /** Click handler for anchor tag. Parent JumpLinks components tap into this. */
17 onClick?: (ev: React.MouseEvent) => void;
18 /** Class to add to li */
19 className?: string;
20 }
21
22 export const JumpLinksItem: React.FunctionComponent<JumpLinksItemProps> = ({
23 isActive,
24 href,
25 // eslint-disable-next-line
26 node,
27 children,
28 onClick,
29 className,
30 ...props
31 }: JumpLinksItemProps) => {
32 const childrenArr = Children.toArray(children) as any[];
33 const sublists = childrenArr.filter((child) => child.type === JumpLinksList);
34 children = childrenArr.filter((child) => child.type !== JumpLinksList);
35
36 return (
37 <li
38 className={css(styles.jumpLinksItem, isActive && styles.modifiers.current, className)}
39 {...(isActive && { 'aria-current': 'location' })}
40 {...props}
41 >
42 <span className={styles.jumpLinksLink}>
43 <Button variant={ButtonVariant.link} component="a" href={href} onClick={onClick}>
44 <span className={styles.jumpLinksLinkText}>{children}</span>
45 </Button>
46 </span>
47 {sublists}
48 </li>
49 );
50 };
51 JumpLinksItem.displayName = 'JumpLinksItem';