2024-10-03 04:03:04 +02: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
|
|
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import Stack from '@mui/material/Stack';
|
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
|
import Button from '@mui/material/Button';
|
2024-12-13 01:52:28 +01:00
|
|
|
import Tooltip from '@mui/material/Tooltip';
|
2024-11-04 18:00:35 +01:00
|
|
|
import { MultiValueButtonProps } from '@/modules/core/Core.types.ts';
|
2024-10-03 04:03:04 +02:00
|
|
|
|
|
|
|
|
export const ButtonSelect = <Value extends string | number>({
|
|
|
|
|
value,
|
|
|
|
|
values,
|
2024-12-13 01:52:28 +01:00
|
|
|
defaultValue,
|
2024-10-03 04:03:04 +02:00
|
|
|
setValue,
|
|
|
|
|
valueToDisplayData,
|
2024-11-04 18:00:35 +01:00
|
|
|
isDefaultable,
|
|
|
|
|
onDefault,
|
|
|
|
|
}: MultiValueButtonProps<Value>) => {
|
2024-10-03 04:03:04 +02:00
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Stack sx={{ flexDirection: 'row', flexWrap: 'wrap', gap: 1 }}>
|
2024-11-04 18:00:35 +01:00
|
|
|
{isDefaultable && (
|
|
|
|
|
<Button key="default" onClick={onDefault} variant={value === undefined ? 'contained' : 'outlined'}>
|
|
|
|
|
{t('global.label.default')}
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
2024-12-13 01:52:28 +01:00
|
|
|
{values.map((displayValue) => {
|
|
|
|
|
const isDefault = value === undefined && displayValue === defaultValue;
|
|
|
|
|
|
|
|
|
|
const text = valueToDisplayData[displayValue].isTitleString
|
|
|
|
|
? valueToDisplayData[displayValue].title
|
|
|
|
|
: t(valueToDisplayData[displayValue].title);
|
|
|
|
|
const defaultValueText = t('global.label.footnote', { text });
|
|
|
|
|
const finalText = isDefault ? defaultValueText : text;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Tooltip key={displayValue} title={isDefault ? t('reader.settings.active_setting') : ''}>
|
|
|
|
|
<Button
|
|
|
|
|
onClick={() => setValue(displayValue)}
|
|
|
|
|
variant={displayValue === value ? 'contained' : 'outlined'}
|
|
|
|
|
startIcon={valueToDisplayData[displayValue].icon}
|
|
|
|
|
>
|
|
|
|
|
{finalText}
|
|
|
|
|
</Button>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
);
|
|
|
|
|
})}
|
2024-10-03 04:03:04 +02:00
|
|
|
</Stack>
|
|
|
|
|
);
|
|
|
|
|
};
|