|
1 |
| -import { useState } from 'react'; |
2 |
| -import { MenuItem, Submenu, Text, useDevice } from '@deriv-com/ui'; |
| 1 | +import clsx from 'clsx'; |
| 2 | +import { MenuItem, Text, useDevice } from '@deriv-com/ui'; |
3 | 3 | import { PlatformSwitcher } from '../PlatformSwitcher';
|
4 |
| -import { MobileMenuConfig, TSubmenuSection } from './MobileMenuConfig'; |
5 |
| -import { SubmenuContent } from './SubmenuContent'; |
| 4 | +import { MobileMenuConfig } from './MobileMenuConfig'; |
6 | 5 |
|
7 | 6 | export const MenuContent = () => {
|
8 |
| - const [isSubmenuOpen, setIsSubmenuOpen] = useState(false); |
9 |
| - const [renderSubmenuFor, setRenderSubmenuFor] = useState<TSubmenuSection>('accountSettings'); |
10 | 7 | const { isMobile } = useDevice();
|
11 |
| - |
12 |
| - const data = MobileMenuConfig().menuConfig; |
| 8 | + const textSize = isMobile ? 'md' : 'sm'; |
13 | 9 |
|
14 | 10 | return (
|
15 | 11 | <div className='flex flex-col h-full'>
|
16 |
| - {!isSubmenuOpen && ( |
17 |
| - <div className='flex items-center justify-center h-28 border-b border-[#f2f3f4]'> |
18 |
| - <PlatformSwitcher /> |
19 |
| - </div> |
20 |
| - )} |
| 12 | + <div className='flex items-center justify-center h-28 border-b border-[#f2f3f4]'> |
| 13 | + <PlatformSwitcher /> |
| 14 | + </div> |
21 | 15 |
|
22 | 16 | <div className='relative h-full pt-4'>
|
23 |
| - {data.map((item, index) => ( |
24 |
| - <div className='pl-[4.8rem] pr-[1.6rem] border-b border-[#f2f3f4]' key={index}> |
25 |
| - {item.map(({ LeftComponent, RightComponent, as, href, label, onClick, submenu }) => { |
26 |
| - const textSize = isMobile ? 'md' : 'sm'; |
| 17 | + {MobileMenuConfig().map((item, index) => { |
| 18 | + const removeBorderBottom = item.find(({ removeBorderBottom }) => removeBorderBottom); |
27 | 19 |
|
28 |
| - if (as === 'a') { |
| 20 | + return ( |
| 21 | + <div |
| 22 | + className={clsx('pl-[4.8rem] pr-[1.6rem]', { |
| 23 | + 'border-b border-[#f2f3f4]': !removeBorderBottom, |
| 24 | + })} |
| 25 | + key={index} |
| 26 | + > |
| 27 | + {item.map(({ LeftComponent, RightComponent, as, href, label, onClick, target }) => { |
| 28 | + if (as === 'a') { |
| 29 | + return ( |
| 30 | + <MenuItem |
| 31 | + as='a' |
| 32 | + className='h-[5.6rem]' |
| 33 | + disableHover |
| 34 | + href={href} |
| 35 | + key={label} |
| 36 | + leftComponent={ |
| 37 | + <LeftComponent className='mr-[1.6rem]' height={16} width={16} /> |
| 38 | + } |
| 39 | + target={target} |
| 40 | + > |
| 41 | + <Text size={textSize}>{label}</Text> |
| 42 | + </MenuItem> |
| 43 | + ); |
| 44 | + } |
29 | 45 | return (
|
30 | 46 | <MenuItem
|
31 |
| - as='a' |
32 |
| - className='h-[5.6rem]' |
| 47 | + as='button' |
| 48 | + className='w-full h-[5.6rem]' |
33 | 49 | disableHover
|
34 |
| - href={href} |
35 | 50 | key={label}
|
36 |
| - leftComponent={<LeftComponent className='mr-[1.6rem]' height={16} width={16} />} |
| 51 | + leftComponent={<LeftComponent className='mr-[1.6rem]' iconSize='xs' />} |
| 52 | + onClick={onClick} |
| 53 | + rightComponent={RightComponent} |
37 | 54 | >
|
38 |
| - <Text size={textSize}>{label}</Text> |
| 55 | + <Text className='mr-auto' size={textSize}> |
| 56 | + {label} |
| 57 | + </Text> |
39 | 58 | </MenuItem>
|
40 | 59 | );
|
41 |
| - } |
42 |
| - return ( |
43 |
| - <MenuItem |
44 |
| - as='button' |
45 |
| - className='w-full h-[5.6rem]' |
46 |
| - disableHover |
47 |
| - key={label} |
48 |
| - leftComponent={<LeftComponent className='mr-[1.6rem]' iconSize='xs' />} |
49 |
| - onClick={() => { |
50 |
| - if (submenu) { |
51 |
| - setRenderSubmenuFor(submenu); |
52 |
| - setIsSubmenuOpen(true); |
53 |
| - } else onClick?.(); |
54 |
| - }} |
55 |
| - rightComponent={RightComponent} |
56 |
| - > |
57 |
| - <Text className='mr-auto' size={textSize}> |
58 |
| - {label} |
59 |
| - </Text> |
60 |
| - </MenuItem> |
61 |
| - ); |
62 |
| - })} |
63 |
| - </div> |
64 |
| - ))} |
65 |
| - |
66 |
| - <Submenu className='overflow-y-auto z-10' isOpen={isSubmenuOpen}> |
67 |
| - <SubmenuContent onBackClick={() => setIsSubmenuOpen(false)} renderContentFor={renderSubmenuFor} /> |
68 |
| - </Submenu> |
| 60 | + })} |
| 61 | + </div> |
| 62 | + ); |
| 63 | + })} |
69 | 64 | </div>
|
70 | 65 | </div>
|
71 | 66 | );
|
|
0 commit comments