|
| 1 | +import { Box } from '@chakra-ui/react' |
| 2 | + |
| 3 | +import { vars } from '@theme' |
| 4 | +import { HelpIcon } from '@/molecules/NavBarButtons/Icons/HelpIcon' |
| 5 | +import { CalendarButtonIcon } from './Icons/CalendarButtonIcon' |
| 6 | +import { Accessibility } from '@/atoms/Icons/Accessibility' |
| 7 | + |
| 8 | +export interface ButtonProps { |
| 9 | + buttonName?: string |
| 10 | + onlyLink?: boolean |
| 11 | + onClick: () => void |
| 12 | + type: 'calendar' | 'help' | 'accessibility' |
| 13 | +} |
| 14 | + |
| 15 | +export const NavBarButton = ({ buttonName, onlyLink, onClick, type }: ButtonProps): JSX.Element => { |
| 16 | + const buttonType = { |
| 17 | + accessibility: { |
| 18 | + icon: <Accessibility />, |
| 19 | + text: buttonName ?? 'ACCESIBILIDAD', |
| 20 | + }, |
| 21 | + calendar: { |
| 22 | + icon: <CalendarButtonIcon />, |
| 23 | + text: buttonName ?? 'CALENDARIO', |
| 24 | + }, |
| 25 | + help: { |
| 26 | + icon: <HelpIcon />, |
| 27 | + text: buttonName ?? 'AYUDA', |
| 28 | + }, |
| 29 | + } |
| 30 | + |
| 31 | + const triggerWidget = (): void => { |
| 32 | + const buttonB = document.getElementById('userWayTrigger') |
| 33 | + if (buttonB?.click) { |
| 34 | + buttonB.click() // Hace clic en el botón del archivo index.html |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + const activeBg = vars('colors-main-deepSkyBlue') ?? '#0189FF' |
| 39 | + const hoverBg = 'rgba(96, 121, 142, 0.8)' |
| 40 | + const isAccessibility = type === 'accessibility' |
| 41 | + |
| 42 | + return ( |
| 43 | + <Box |
| 44 | + as="button" |
| 45 | + id={isAccessibility ? 'UserWayButton' : ''} |
| 46 | + onClick={isAccessibility ? triggerWidget : onClick} |
| 47 | + sx={{ |
| 48 | + display: 'flex', |
| 49 | + gap: '8px', |
| 50 | + h: '30px', |
| 51 | + maxH: '30px', |
| 52 | + |
| 53 | + _hover: { |
| 54 | + '.icon': { |
| 55 | + bg: hoverBg, |
| 56 | + }, |
| 57 | + '.text': { |
| 58 | + color: vars('colors-neutral-white'), |
| 59 | + }, |
| 60 | + }, |
| 61 | + |
| 62 | + _active: { |
| 63 | + '.icon': { |
| 64 | + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing |
| 65 | + bg: onlyLink || isAccessibility ? hoverBg : activeBg, |
| 66 | + }, |
| 67 | + '.text': { |
| 68 | + color: vars('colors-neutral-white'), |
| 69 | + }, |
| 70 | + }, |
| 71 | + |
| 72 | + '.icon': { |
| 73 | + alignItems: 'center', |
| 74 | + bg: vars('colors-main-blueGrey'), |
| 75 | + borderRadius: '100%', |
| 76 | + border: '1px solid transparent', |
| 77 | + display: 'flex', |
| 78 | + height: '30px', |
| 79 | + justifyContent: 'center', |
| 80 | + type: 'button', |
| 81 | + role: 'button', |
| 82 | + width: '30px', |
| 83 | + }, |
| 84 | + |
| 85 | + '.text': { |
| 86 | + alignContent: 'center', |
| 87 | + fontSize: '12px', |
| 88 | + fontWeight: '500', |
| 89 | + forntFamily: 'Roboto', |
| 90 | + color: vars('colors-neutral-silverSand'), |
| 91 | + }, |
| 92 | + }} |
| 93 | + > |
| 94 | + <Box className="icon">{buttonType[type].icon}</Box> |
| 95 | + <Box as="span" className="text"> |
| 96 | + {buttonType[type].text} |
| 97 | + </Box> |
| 98 | + </Box> |
| 99 | + ) |
| 100 | +} |
0 commit comments