feishin/src/renderer/features/player/components/player-button.tsx

87 lines
2.7 KiB
TypeScript
Raw Normal View History

import clsx from 'clsx';
2025-06-24 20:31:33 -07:00
import { t } from 'i18next';
import { forwardRef, ReactNode } from 'react';
import styles from './player-button.module.css';
import { ActionIcon, ActionIconProps } from '/@/shared/components/action-icon/action-icon';
import { Tooltip, TooltipProps } from '/@/shared/components/tooltip/tooltip';
2022-12-19 15:59:14 -08:00
interface PlayerButtonProps extends Omit<ActionIconProps, 'icon' | 'variant'> {
2023-07-01 19:10:05 -07:00
icon: ReactNode;
isActive?: boolean;
2023-07-01 19:10:05 -07:00
tooltip?: Omit<TooltipProps, 'children'>;
variant: 'main' | 'secondary' | 'tertiary';
2022-12-19 15:59:14 -08:00
}
2025-06-24 20:31:33 -07:00
export const PlayerButton = forwardRef<HTMLButtonElement, PlayerButtonProps>(
({ icon, isActive, tooltip, variant, ...rest }: PlayerButtonProps, ref) => {
2023-07-01 19:10:05 -07:00
if (tooltip) {
return (
<Tooltip {...tooltip}>
2025-06-24 20:31:33 -07:00
<ActionIcon
className={clsx({
2025-06-24 20:31:33 -07:00
[styles.active]: isActive,
})}
ref={ref}
2025-06-24 20:31:33 -07:00
{...rest}
onClick={(e) => {
e.stopPropagation();
rest.onClick?.(e);
}}
variant="subtle"
2023-07-01 19:10:05 -07:00
>
2025-06-24 20:31:33 -07:00
{icon}
</ActionIcon>
2023-07-01 19:10:05 -07:00
</Tooltip>
);
}
return (
2025-06-24 20:31:33 -07:00
<ActionIcon
className={clsx(styles.playerButton, styles[variant], {
[styles.active]: isActive,
})}
ref={ref}
2025-06-24 20:31:33 -07:00
{...rest}
onClick={(e) => {
e.stopPropagation();
rest.onClick?.(e);
}}
variant="subtle"
2023-05-21 07:33:22 -07:00
>
2025-06-24 20:31:33 -07:00
{icon}
</ActionIcon>
2023-07-01 19:10:05 -07:00
);
},
2023-05-21 07:33:22 -07:00
);
2025-06-24 20:31:33 -07:00
interface PlayButtonProps extends Omit<ActionIconProps, 'icon' | 'variant'> {
isPaused?: boolean;
}
export const PlayButton = forwardRef<HTMLButtonElement, PlayButtonProps>(
2025-07-07 23:20:05 -07:00
({ isPaused, onClick, ...props }: PlayButtonProps, ref) => {
return (
<ActionIcon
className={styles.main}
icon={isPaused ? 'mediaPlay' : 'mediaPause'}
iconProps={{
size: 'lg',
}}
2025-07-07 23:20:05 -07:00
onClick={(e) => {
e.stopPropagation();
onClick?.(e);
}}
ref={ref}
tooltip={{
label: isPaused
? (t('player.play', { postProcess: 'sentenceCase' }) as string)
: (t('player.pause', { postProcess: 'sentenceCase' }) as string),
}}
{...props}
/>
);
},
);