|
| 1 | +import React, { JSX } from 'react'; |
| 2 | +import { NavigationProps } from './types'; |
| 3 | +import * as Styled from './styles'; |
| 4 | +import { MdExpandCircleDown } from 'react-icons/md'; |
| 5 | +import { BBBTypography } from '../Typography'; |
| 6 | + |
| 7 | +/** |
| 8 | + * A customizable Navigation component that acts as a button with an icon and a label. |
| 9 | + * It can be used for navigation actions within an application. |
| 10 | + * |
| 11 | + * @param {NavigationProps} props - The props for the Navigation component. See {@link NavigationProps} for more details. |
| 12 | + * @param {string} props.label - The text to be displayed as the label for the navigation button. |
| 13 | + * @param {React.MouseEventHandler<HTMLButtonElement>} props.onClick - The function to be called when the navigation button is clicked. |
| 14 | + * @param {React.KeyboardEventHandler<HTMLButtonElement>} [props.onKeyDown] - The function to be called when a key is pressed down on the navigation button. |
| 15 | + * @param {React.ReactNode} [props.icon] - A custom icon to be displayed. If not provided, a default icon is used. |
| 16 | + * @param {React.ReactNode} [props.children] - The children to be rendered inside the navigation button, typically used for sub-menus or other content. |
| 17 | + * @param {string} [props.ariaLabel] - The accessible name for the navigation button. |
| 18 | + * @param {string} [props.ariaLabelledBy] - The ID of the element that labels the navigation button. |
| 19 | + * @param {string} [props.ariaDescribedBy] - The ID of the element that describes the navigation button. |
| 20 | + * @param {string} [props.dataTest] - The test ID for the navigation button, used for testing purposes. |
| 21 | + * @returns {JSX.Element} The rendered Navigation component. |
| 22 | + */ |
| 23 | +function Navigation ({ |
| 24 | + label, |
| 25 | + onClick, |
| 26 | + onKeyDown, |
| 27 | + icon, |
| 28 | + children, |
| 29 | + ariaLabel, |
| 30 | + ariaLabelledBy, |
| 31 | + ariaDescribedBy, |
| 32 | + dataTest, |
| 33 | +}: NavigationProps): JSX.Element { |
| 34 | + const isCustomIcon = !!icon; |
| 35 | + const iconToRender = icon || <MdExpandCircleDown size="1.5rem" />; |
| 36 | + |
| 37 | + return ( |
| 38 | + <Styled.NavigationButton |
| 39 | + onClick={onClick} |
| 40 | + onKeyDown={onKeyDown} |
| 41 | + aria-label={ariaLabel} |
| 42 | + aria-labelledby={ariaLabelledBy} |
| 43 | + aria-describedby={ariaDescribedBy} |
| 44 | + data-test={dataTest} |
| 45 | + > |
| 46 | + <Styled.IconTextWrapper> |
| 47 | + <Styled.IconWrapper isCustomIcon={isCustomIcon}> |
| 48 | + {iconToRender} |
| 49 | + </Styled.IconWrapper> |
| 50 | + <BBBTypography variant="default"> |
| 51 | + {label} |
| 52 | + </BBBTypography> |
| 53 | + </Styled.IconTextWrapper> |
| 54 | + {children} |
| 55 | + </Styled.NavigationButton> |
| 56 | + ); |
| 57 | +} |
| 58 | + |
| 59 | +export default Navigation; |
0 commit comments