2024-06-20 15:37:24 +03:00

58 lines
1.4 KiB
JavaScript

import { NavigationContext } from '@/context/navigation';
import { memo, useContext } from 'react';
import styled from 'styled-components';
const Container = styled.div`
background-color: white;
bottom: 0;
display: flex;
flex-direction: row;
gap: 10px;
height: 46px;
justify-content: space-around;
position: fixed;
width: 100%;
border-top: 1px solid rgba(5, 5, 5, 0.06);
`;
const TabButton = styled.button`
background: ${({ active }) => (active ? 'var(--color-primary)' : 'white')};
color: ${({ active }) => (active ? 'white' : 'black')};
border-radius: 2px 2px 0 0;
border: none;
cursor: pointer;
height: 100%;
width: 100%;
`;
export function NavigationBar() {
const { currentTab, setCurrentTab, tabsList } = useContext(NavigationContext);
return (
<Container>
{tabsList.map(({ key, title }) => (
<TabButton key={key} active={key === currentTab} onClick={() => setCurrentTab(key)}>
{title}
</TabButton>
))}
</Container>
);
}
const Display = styled.div`
display: ${(props) => (props.visible ? 'block' : 'none')};
`;
export const Tabs = memo(
({ tabs }) => {
const { currentTab } = useContext(NavigationContext);
return tabs.map(({ Component, key }) => (
<Display key={key} visible={key === currentTab}>
<Component key={key} />
</Display>
));
},
(prevProps, nextProps) => prevProps.tabs.length === nextProps.tabs.length
);