-
-
Notifications
You must be signed in to change notification settings - Fork 624
Expand file tree
/
Copy pathBottomActionsTabs.tsx
More file actions
99 lines (87 loc) · 2.74 KB
/
Copy pathBottomActionsTabs.tsx
File metadata and controls
99 lines (87 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import React from 'react';
import classNames from 'classnames';
import useTranslation from 'next-translate/useTranslation';
import styles from './TranslationViewCell.module.scss';
import Separator, { SeparatorWeight } from '@/components/dls/Separator/Separator';
import Scrollable from '@/dls/Scrollable/Scrollable';
import EventName from '@/utils/event-names';
import { isRTLLocale } from '@/utils/locale';
export enum TabId {
TAFSIR = 'tafsir',
LAYERS = 'layers',
REFLECTIONS = 'reflections',
LESSONS = 'lessons',
ANSWERS = 'answers',
QIRAAT = 'qiraat',
HADITH = 'hadith',
RELATED_VERSES = 'related-verses',
}
export interface TabConfig {
id: TabId;
label: string;
icon: JSX.Element;
onClick: (e: React.MouseEvent | React.KeyboardEvent) => void;
condition: boolean | undefined;
isAdditionalTab?: boolean;
}
interface BottomActionsTabsProps {
tabs: TabConfig[];
isTranslationView: boolean;
className?: string;
}
const BottomActionsTabs: React.FC<BottomActionsTabsProps> = ({
tabs,
isTranslationView,
className,
}) => {
const { lang } = useTranslation('common');
const isRTL = isRTLLocale(lang);
const handleTabClick = (
e: React.MouseEvent,
onClick: (e: React.MouseEvent | React.KeyboardEvent) => void,
) => {
onClick(e);
};
const handleTabKeyDown = (
e: React.KeyboardEvent,
onClick: (e: React.MouseEvent | React.KeyboardEvent) => void,
) => {
onClick(e);
};
const filteredTabs = React.useMemo(() => tabs.filter((tab) => tab.condition !== false), [tabs]);
return (
<Scrollable
containerClassName={styles.tabContainerWrapper}
className={classNames(styles.tabsContainer, className, {
[styles.center]: !isTranslationView,
})}
eventName={EventName.QURAN_READER_BOTTOM_ACTION_SCROLLABLE}
>
{filteredTabs.map((tab, index) => (
<React.Fragment key={tab.id}>
<div
className={classNames(styles.tabItem, {
[styles.tabItemRTL]: isRTL,
[styles.semibold]: tab.isAdditionalTab,
})}
data-testid={`bottom-action-tab-${tab.id}`}
onClick={(e) => handleTabClick(e, tab.onClick)}
onKeyDown={(e) => handleTabKeyDown(e, tab.onClick)}
role="button"
tabIndex={0}
aria-label={tab.label}
>
<span className={styles.tabIcon}>{tab.icon}</span>
<span className={styles.tabLabel}>{tab.label}</span>
</div>
{index < filteredTabs.length - 1 && (
<div className={styles.separatorContainer}>
<Separator isVertical weight={SeparatorWeight.SemiBold} />
</div>
)}
</React.Fragment>
))}
</Scrollable>
);
};
export default BottomActionsTabs;