mirror of
https://github.com/lux-tel/session-desktop.git
synced 2026-10-30 20:33:24 +00:00
44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
import type { MouseEvent, ReactNode, SessionDataTestId } from 'react';
|
|
import styled from 'styled-components';
|
|
import { useIsDarkTheme } from '../../../state/theme/selectors/theme';
|
|
import { StyledPanelButton, StyledContent } from './PanelButton';
|
|
import { StyledPanelButtonSeparator } from './StyledPanelButtonGroupSeparator';
|
|
|
|
const StyledActionContainer = styled.div`
|
|
display: flex;
|
|
align-items: center;
|
|
flex-shrink: 0;
|
|
pointer-events: none; // let the container handle the event (otherwise we get 2 onClick events, cancelling each others)
|
|
`;
|
|
|
|
export type GenericPanelButtonProps = {
|
|
textElement: ReactNode;
|
|
actionElement: ReactNode;
|
|
onClick: undefined | ((e: MouseEvent<any>) => void | Promise<void>);
|
|
rowDataTestId: SessionDataTestId;
|
|
};
|
|
|
|
export const GenericPanelButtonWithAction = (props: GenericPanelButtonProps) => {
|
|
const { actionElement, rowDataTestId, textElement, onClick } = props;
|
|
const isDarkTheme = useIsDarkTheme();
|
|
const disabled = !onClick;
|
|
|
|
return (
|
|
<>
|
|
<StyledPanelButton
|
|
disabled={disabled}
|
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
onClick={onClick}
|
|
data-testid={rowDataTestId}
|
|
$isDarkTheme={isDarkTheme}
|
|
>
|
|
<StyledContent disabled={disabled}>
|
|
{textElement}
|
|
<StyledActionContainer>{actionElement}</StyledActionContainer>
|
|
</StyledContent>
|
|
</StyledPanelButton>
|
|
<StyledPanelButtonSeparator />
|
|
</>
|
|
);
|
|
};
|