2023-09-15 20:42:38 -07:00
|
|
|
import { MouseEvent, ReactNode, Ref, forwardRef } from 'react';
|
2023-07-23 12:23:18 +00:00
|
|
|
import { Button, type ButtonProps as MantineButtonProps } from '@mantine/core';
|
|
|
|
|
import { Tooltip } from '/@/renderer/components/tooltip';
|
|
|
|
|
import styled from 'styled-components';
|
|
|
|
|
|
|
|
|
|
interface StyledButtonProps extends MantineButtonProps {
|
|
|
|
|
$active?: boolean;
|
2023-09-15 20:42:38 -07:00
|
|
|
children: ReactNode;
|
|
|
|
|
onClick?: (e: MouseEvent<HTMLButtonElement, MouseEvent>) => void;
|
|
|
|
|
onMouseDown?: (e: MouseEvent<HTMLButtonElement, MouseEvent>) => void;
|
2023-07-23 12:23:18 +00:00
|
|
|
ref: Ref<HTMLButtonElement>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ButtonProps extends StyledButtonProps {
|
|
|
|
|
tooltip: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const StyledButton = styled(Button)<StyledButtonProps>`
|
|
|
|
|
svg {
|
|
|
|
|
display: flex;
|
|
|
|
|
fill: ${({ $active: active }) =>
|
|
|
|
|
active ? 'var(--primary-color)' : 'var(--playerbar-btn-fg)'};
|
|
|
|
|
stroke: var(--playerbar-btn-fg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
|
background: var(--playerbar-btn-bg-hover);
|
|
|
|
|
|
|
|
|
|
svg {
|
|
|
|
|
fill: ${({ $active: active }) =>
|
|
|
|
|
active
|
|
|
|
|
? 'var(--primary-color) !important'
|
|
|
|
|
: 'var(--playerbar-btn-fg-hover) !important'};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
export const RemoteButton = forwardRef<HTMLButtonElement, ButtonProps>(
|
|
|
|
|
({ children, tooltip, ...props }: ButtonProps, ref) => {
|
|
|
|
|
return (
|
|
|
|
|
<Tooltip
|
|
|
|
|
withinPortal
|
|
|
|
|
label={tooltip}
|
|
|
|
|
>
|
|
|
|
|
<StyledButton
|
|
|
|
|
{...props}
|
|
|
|
|
ref={ref}
|
|
|
|
|
>
|
|
|
|
|
{children}
|
|
|
|
|
</StyledButton>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
RemoteButton.defaultProps = {
|
|
|
|
|
$active: false,
|
|
|
|
|
onClick: undefined,
|
|
|
|
|
onMouseDown: undefined,
|
|
|
|
|
};
|