Move "core" folder out of "features" into "base"
This commit is contained in:
55
src/base/components/buttons/ButtonSelect.tsx
Normal file
55
src/base/components/buttons/ButtonSelect.tsx
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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';
|
||||
import { CustomTooltip } from '@/base/components/CustomTooltip.tsx';
|
||||
import { MultiValueButtonProps } from '@/base/Base.types.ts';
|
||||
import { Superscript } from '@/base/components/texts/Superscript.tsx';
|
||||
|
||||
export const ButtonSelect = <Value extends string | number>({
|
||||
value,
|
||||
values,
|
||||
defaultValue,
|
||||
setValue,
|
||||
valueToDisplayData,
|
||||
isDefaultable,
|
||||
onDefault,
|
||||
}: MultiValueButtonProps<Value>) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<Stack sx={{ flexDirection: 'row', flexWrap: 'wrap', gap: 1 }}>
|
||||
{isDefaultable && (
|
||||
<Button key="default" onClick={onDefault} variant={value === undefined ? 'contained' : 'outlined'}>
|
||||
{t('global.label.default')}
|
||||
</Button>
|
||||
)}
|
||||
{values.map((displayValue) => {
|
||||
const isDefault = value === undefined && displayValue === defaultValue;
|
||||
|
||||
const text = valueToDisplayData[displayValue].isTitleString
|
||||
? valueToDisplayData[displayValue].title
|
||||
: t(valueToDisplayData[displayValue].title);
|
||||
|
||||
return (
|
||||
<CustomTooltip key={displayValue} title={isDefault ? t('reader.settings.active_setting') : ''}>
|
||||
<Button
|
||||
onClick={() => setValue(displayValue)}
|
||||
variant={displayValue === value ? 'contained' : 'outlined'}
|
||||
startIcon={valueToDisplayData[displayValue].icon}
|
||||
>
|
||||
{isDefault ? <Superscript i18nKey="global.label.footnote" value={text} /> : text}
|
||||
</Button>
|
||||
</CustomTooltip>
|
||||
);
|
||||
})}
|
||||
</Stack>
|
||||
);
|
||||
};
|
||||
32
src/base/components/buttons/CustomButton.tsx
Normal file
32
src/base/components/buttons/CustomButton.tsx
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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 Button, { ButtonProps } from '@mui/material/Button';
|
||||
import Stack from '@mui/material/Stack';
|
||||
import { ForwardedRef, forwardRef } from 'react';
|
||||
|
||||
export const CustomButton = forwardRef(
|
||||
<C extends React.ElementType>(
|
||||
{ children, ...props }: ButtonProps<C, { component?: C }>,
|
||||
ref: ForwardedRef<HTMLButtonElement | null>,
|
||||
) => (
|
||||
<Button ref={ref} {...props}>
|
||||
<Stack
|
||||
direction="row"
|
||||
sx={{
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
gap: 1,
|
||||
flexWrap: 'wrap',
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</Stack>
|
||||
</Button>
|
||||
),
|
||||
);
|
||||
29
src/base/components/buttons/CustomButtonIcon.tsx
Normal file
29
src/base/components/buttons/CustomButtonIcon.tsx
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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 Button, { ButtonProps } from '@mui/material/Button';
|
||||
import { ForwardedRef, forwardRef } from 'react';
|
||||
|
||||
export const CustomButtonIcon = forwardRef(
|
||||
<C extends React.ElementType>(
|
||||
{ children, ...props }: ButtonProps<C, { component?: C }>,
|
||||
ref: ForwardedRef<HTMLButtonElement | null>,
|
||||
) => (
|
||||
<Button
|
||||
ref={ref}
|
||||
{...props}
|
||||
sx={{
|
||||
minWidth: 'unset',
|
||||
px: '10px',
|
||||
...props.sx,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</Button>
|
||||
),
|
||||
);
|
||||
37
src/base/components/buttons/ResetButton.tsx
Normal file
37
src/base/components/buttons/ResetButton.tsx
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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 Button, { ButtonProps } from '@mui/material/Button';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import RestartAltIcon from '@mui/icons-material/RestartAlt';
|
||||
import IconButton, { IconButtonProps } from '@mui/material/IconButton';
|
||||
import { CustomTooltip } from '@/base/components/CustomTooltip.tsx';
|
||||
|
||||
type PropsIconButton = { asIconButton: true } & IconButtonProps;
|
||||
type PropsButton = { asIconButton?: false } & ButtonProps;
|
||||
type Props = PropsIconButton | PropsButton;
|
||||
|
||||
export const ResetButton = ({ asIconButton, ...props }: Props) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
if (asIconButton) {
|
||||
return (
|
||||
<CustomTooltip title={t('global.button.reset')}>
|
||||
<IconButton color="inherit" {...props}>
|
||||
<RestartAltIcon />
|
||||
</IconButton>
|
||||
</CustomTooltip>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Button startIcon={<RestartAltIcon />} {...(props as ButtonProps)}>
|
||||
{t('global.button.reset')}
|
||||
</Button>
|
||||
);
|
||||
};
|
||||
23
src/base/components/buttons/StyledFab.tsx
Normal file
23
src/base/components/buttons/StyledFab.tsx
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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 Fab from '@mui/material/Fab';
|
||||
import { styled } from '@mui/material/styles';
|
||||
|
||||
export const DEFAULT_FAB_STYLE = {
|
||||
position: 'fixed',
|
||||
height: '48px',
|
||||
right: '48px',
|
||||
bottom: '28px',
|
||||
} as const;
|
||||
|
||||
export const DEFAULT_FULL_FAB_HEIGHT = `calc(${DEFAULT_FAB_STYLE.bottom} + ${DEFAULT_FAB_STYLE.height})`;
|
||||
|
||||
export const StyledFab = styled(Fab)({
|
||||
...DEFAULT_FAB_STYLE,
|
||||
}) as typeof Fab;
|
||||
86
src/base/components/buttons/ValueRotationButton.tsx
Normal file
86
src/base/components/buttons/ValueRotationButton.tsx
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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 { useTranslation } from 'react-i18next';
|
||||
import { ReactNode, useMemo } from 'react';
|
||||
import Button from '@mui/material/Button';
|
||||
import { CustomTooltip } from '@/base/components/CustomTooltip.tsx';
|
||||
import { MultiValueButtonProps } from '@/base/Base.types.ts';
|
||||
import { getNextRotationValue } from '@/base/utils/ValueRotationButton.utils.ts';
|
||||
import { Superscript } from '@/base/components/texts/Superscript.tsx';
|
||||
|
||||
export const ValueRotationButton = <Value extends string | number>({
|
||||
tooltip,
|
||||
value,
|
||||
defaultValue,
|
||||
values,
|
||||
setValue,
|
||||
valueToDisplayData,
|
||||
isDefaultable,
|
||||
onDefault,
|
||||
defaultIcon,
|
||||
}: MultiValueButtonProps<Value> & { defaultIcon?: ReactNode }) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const isDefault = value === undefined;
|
||||
const indexOfValue = useMemo(() => {
|
||||
if (isDefault) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return values.indexOf(value);
|
||||
}, [value, values]);
|
||||
|
||||
return (
|
||||
<CustomTooltip title={tooltip}>
|
||||
{isDefault ? (
|
||||
<Button
|
||||
onClick={() => setValue(values[0])}
|
||||
sx={{ justifyContent: 'start', textTransform: 'unset', flexGrow: 1 }}
|
||||
variant="contained"
|
||||
startIcon={defaultIcon}
|
||||
size="large"
|
||||
>
|
||||
{defaultValue === undefined ? (
|
||||
t('global.label.default')
|
||||
) : (
|
||||
<Superscript
|
||||
i18nKey="settings.default_value"
|
||||
value={
|
||||
valueToDisplayData[defaultValue].isTitleString
|
||||
? valueToDisplayData[defaultValue].title
|
||||
: t(valueToDisplayData[defaultValue].title)
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
onClick={() => {
|
||||
const nextValue = getNextRotationValue(indexOfValue, values, isDefaultable);
|
||||
|
||||
if (nextValue === undefined) {
|
||||
onDefault?.();
|
||||
return;
|
||||
}
|
||||
|
||||
setValue(nextValue);
|
||||
}}
|
||||
sx={{ justifyContent: 'start', textTransform: 'unset', flexGrow: 1 }}
|
||||
variant="contained"
|
||||
startIcon={valueToDisplayData[value].icon}
|
||||
size="large"
|
||||
>
|
||||
{valueToDisplayData[value].isTitleString
|
||||
? valueToDisplayData[value].title
|
||||
: t(valueToDisplayData[value].title)}
|
||||
</Button>
|
||||
)}
|
||||
</CustomTooltip>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user