2022-11-24 09:41:03 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) Contributors to the Suwayomi project
|
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
2023-05-18 13:17:41 +02:00
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
2022-11-24 09:41:03 +01:00
|
|
|
|
2024-04-14 15:50:12 +02:00
|
|
|
import Stack from '@mui/material/Stack';
|
|
|
|
|
import Tab from '@mui/material/Tab';
|
|
|
|
|
import Tabs from '@mui/material/Tabs';
|
2022-11-24 09:41:03 +01:00
|
|
|
import React, { useState } from 'react';
|
2024-01-02 23:32:49 +01:00
|
|
|
import { TabPanel } from '@/components/tabs/TabPanel.tsx';
|
2023-10-28 00:32:02 +02:00
|
|
|
import { OptionsPanel } from '@/components/molecules/OptionsPanel';
|
2022-11-24 09:41:03 +01:00
|
|
|
|
2023-02-06 10:06:33 +01:00
|
|
|
interface IProps<T = string> {
|
|
|
|
|
open: boolean;
|
|
|
|
|
onClose: () => void;
|
|
|
|
|
tabs: T[];
|
|
|
|
|
tabTitle: (key: T) => React.ReactNode;
|
|
|
|
|
tabContent: (key: T) => React.ReactNode;
|
|
|
|
|
minHeight?: number;
|
2022-11-24 09:41:03 +01:00
|
|
|
}
|
|
|
|
|
|
2023-10-28 00:32:02 +02:00
|
|
|
export const OptionsTabs = <T extends string = string>({
|
2023-02-06 10:06:33 +01:00
|
|
|
open,
|
|
|
|
|
onClose,
|
|
|
|
|
tabs,
|
|
|
|
|
tabTitle,
|
|
|
|
|
tabContent,
|
|
|
|
|
minHeight,
|
2022-11-24 09:41:03 +01:00
|
|
|
}: IProps<T>) => {
|
|
|
|
|
const [tabNum, setTabNum] = useState(0);
|
|
|
|
|
|
|
|
|
|
return (
|
2023-02-06 10:06:33 +01:00
|
|
|
<OptionsPanel open={open} onClose={onClose} minHeight={minHeight}>
|
2022-11-24 09:41:03 +01:00
|
|
|
<Tabs
|
|
|
|
|
value={tabNum}
|
|
|
|
|
variant="fullWidth"
|
|
|
|
|
onChange={(e, newTab) => setTabNum(newTab)}
|
|
|
|
|
indicatorColor="primary"
|
|
|
|
|
textColor="primary"
|
|
|
|
|
>
|
|
|
|
|
{tabs.map((tab, tabIndex) => (
|
|
|
|
|
<Tab key={tab} value={tabIndex} label={tabTitle(tab)} />
|
|
|
|
|
))}
|
|
|
|
|
</Tabs>
|
|
|
|
|
{tabs.map((tab, tabIndex) => (
|
|
|
|
|
<TabPanel key={tab} index={tabIndex} currentIndex={tabNum}>
|
2023-02-06 10:06:33 +01:00
|
|
|
<Stack sx={{ px: 3, py: 1, minHeight }}>{tabContent(tab)}</Stack>
|
2022-11-24 09:41:03 +01:00
|
|
|
</TabPanel>
|
|
|
|
|
))}
|
|
|
|
|
</OptionsPanel>
|
|
|
|
|
);
|
|
|
|
|
};
|