import { cloneElement, Fragment } from 'react'; import styled, { css } from 'styled-components'; import { Logo } from '../../icons/branding'; import { spacing } from '../../spacing'; import { fontSize, navbarHeight, navbarItemWidth } from '../../style/theme'; import { getContrastText, getThemePropSelector } from '../../utils'; import { Dropdown, type Item } from '../dropdown/Dropdown.component'; import { Icon } from '../icon/Icon.component'; import { Button, FocusVisibleStyle, type Props as ButtonProps } from '../buttonv2/Buttonv2.component'; type ButtonAction = { type: 'button'; } & ButtonProps; type DropdownAction = { type: 'dropdown'; items: Array; text?: string; icon?: JSX.Element; }; type CustomAction = { type: 'custom'; render: React.ComponentType; }; type Action = DropdownAction | ButtonAction | CustomAction; type Actions = Array; type Tab = { title?: string; selected?: boolean; onClick?: (arg0: any) => void; link?: JSX.Element; render?: JSX.Element; }; export type Props = { onToggleClick?: () => void; rightActions: Actions; logo?: JSX.Element; tabs?: Array; }; const getNavbarTextColor = (props) => getContrastText(props.theme.navbarBackground, props.theme.textPrimary, props.theme.textReverse) ?? props.theme.textPrimary; const NavbarContainer = styled.div` height: ${navbarHeight}; display: flex; justify-content: space-between; ${css` background-color: ${getThemePropSelector('navbarBackground')}; color: ${getNavbarTextColor}; .fas, .sc-trigger-text { color: ${getNavbarTextColor}; } box-sizing: border-box; border-bottom: 0.5px solid ${(props) => props.theme.backgroundLevel2}; `}; `; const NavbarMenu = styled.div` display: flex; justify-content: center; align-items: center; `; const NavbarTabs = styled.div` flex: 1; display: flex; justify-content: flex-start; align-items: center; a { box-sizing: border-box; display: flex; justify-content: center; align-items: center; text-decoration: none; height: 100%; padding: 0 ${spacing.r16}; border-bottom: ${spacing.r2} solid transparent; border-top: ${spacing.r2} solid transparent; ${(props) => { const { selectedActive } = props.theme; const navTextColor = getContrastText(props.theme.navbarBackground, props.theme.textPrimary, props.theme.textReverse) ?? props.theme.textPrimary; return css` color: ${navTextColor}; &:hover { background-color: ${getThemePropSelector('highlight')}; } &.selected { color: ${navTextColor}; font-weight: bold; border-bottom-color: ${selectedActive}; } // :focus-visible is the keyboard-only version of :focus &:focus-visible { ${FocusVisibleStyle} color: ${navTextColor}; } `; }}; } `; const TabItem = styled.div<{ selected: boolean }>` box-sizing: border-box; height: 100%; display: flex; justify-content: center; align-items: center; padding: 0 ${spacing.r16}; ${(props) => { const navTextColor = getContrastText(props.theme.navbarBackground, props.theme.textPrimary, props.theme.textReverse) ?? props.theme.textPrimary; return css` color: ${navTextColor}; &:hover { border-bottom: ${spacing.r2} solid; border-top: ${spacing.r2} solid; cursor: pointer; } // :focus-visible is the keyboard-only version of :focus &:focus-visible { ${FocusVisibleStyle} color: ${navTextColor}; } `; }}; ${(props) => props.selected && css` border-top: ${spacing.r2} solid; border-bottom: ${spacing.r2} solid; `}; `; const NavbarMenuItem = styled.div` display: flex; justify-content: center; align-items: center; .sc-dropdown { .trigger { background-color: ${getThemePropSelector('navbarBackground')}; &:hover { background-color: ${getThemePropSelector('highlight')}; } height: auto; font-size: ${fontSize.base}; } .menu-item { max-height: unset; } } .sc-button { margin: 0; border-radius: 0; height: ${navbarHeight}; font-size: ${fontSize.base}; background-color: ${getThemePropSelector('navbarBackground')}; color: ${(props) => getContrastText(props.theme.navbarBackground, props.theme.textPrimary, props.theme.textReverse) ?? props.theme.textPrimary}; &:hover { background-color: ${getThemePropSelector('highlight')}; } // :focus-visible is the keyboard-only version of :focus &:focus-visible { ${FocusVisibleStyle} color: ${(props) => getContrastText(props.theme.navbarBackground, props.theme.textPrimary, props.theme.textReverse) ?? props.theme.textPrimary}; } width: ${navbarItemWidth}; } `; const LogoContainer = styled.div` display: flex; justify-content: center; align-items: center; padding: 0 ${spacing.r16}; svg { width: 7.143rem; height: 2.143rem; } `; const getActionRenderer = (action: Action, index: number) => { switch (action.type) { case 'dropdown': { const { type, items, ...rest } = action; return ( ); } case 'button': { const { type, ...rest } = action; return