2024-08-19 14:02:39 -05:00
|
|
|
import { Button, Text, Tooltip } from '@radix-ui/themes';
|
2024-09-14 19:43:14 -05:00
|
|
|
import type { ComponentProps, ReactNode } from 'react';
|
2024-02-12 19:24:34 -06:00
|
|
|
|
|
|
|
|
export interface TankComponentButtonProps
|
|
|
|
|
extends ComponentProps<typeof Button> {
|
|
|
|
|
selected?: boolean;
|
|
|
|
|
children?: ReactNode;
|
|
|
|
|
discriminator?: ReactNode;
|
|
|
|
|
disabled?: boolean;
|
2024-02-13 19:46:34 -06:00
|
|
|
banner?: string;
|
2024-03-31 19:27:37 -05:00
|
|
|
special?: boolean;
|
2024-08-19 14:02:39 -05:00
|
|
|
tooltip?: string;
|
2024-02-12 19:24:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function TankComponentButton({
|
2024-04-01 19:05:55 -05:00
|
|
|
variant,
|
2024-02-12 19:24:34 -06:00
|
|
|
selected,
|
|
|
|
|
discriminator,
|
2024-03-31 19:27:37 -05:00
|
|
|
special,
|
2024-02-12 19:24:34 -06:00
|
|
|
children,
|
2024-02-13 19:46:34 -06:00
|
|
|
banner,
|
2024-04-01 19:05:55 -05:00
|
|
|
disabled,
|
|
|
|
|
style,
|
2024-08-19 14:02:39 -05:00
|
|
|
tooltip,
|
2024-02-12 19:24:34 -06:00
|
|
|
...props
|
|
|
|
|
}: TankComponentButtonProps) {
|
2024-08-19 14:02:39 -05:00
|
|
|
const button = (
|
2024-02-12 19:24:34 -06:00
|
|
|
<Button
|
|
|
|
|
radius="medium"
|
2024-03-31 19:27:37 -05:00
|
|
|
color={selected ? (special ? 'amber' : undefined) : 'gray'}
|
2024-04-01 19:05:55 -05:00
|
|
|
variant={variant ?? (selected ? 'surface' : 'soft')}
|
2024-02-12 19:24:34 -06:00
|
|
|
style={{
|
|
|
|
|
padding: 0,
|
2024-02-13 09:40:00 -06:00
|
|
|
minWidth: 48,
|
2024-02-12 19:24:34 -06:00
|
|
|
height: 40,
|
|
|
|
|
position: 'relative',
|
2024-02-13 19:46:34 -06:00
|
|
|
overflow: 'hidden',
|
2024-04-01 19:05:55 -05:00
|
|
|
cursor: 'unset',
|
|
|
|
|
pointerEvents: variant === 'ghost' ? 'none' : undefined,
|
|
|
|
|
...style,
|
2024-02-12 19:24:34 -06:00
|
|
|
}}
|
2024-04-01 19:05:55 -05:00
|
|
|
disabled={variant === 'ghost' || disabled}
|
2024-02-13 09:40:00 -06:00
|
|
|
{...props}
|
2024-02-12 19:24:34 -06:00
|
|
|
>
|
2024-02-13 19:46:34 -06:00
|
|
|
{banner !== undefined && (
|
|
|
|
|
<div
|
|
|
|
|
style={{
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
width: '200%',
|
|
|
|
|
height: 12,
|
|
|
|
|
backgroundColor: banner,
|
|
|
|
|
top: '50%',
|
|
|
|
|
left: '-50%',
|
|
|
|
|
transform: 'translateY(-50%) rotate(-22.5deg)',
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
|
2024-04-02 10:21:51 -05:00
|
|
|
{children}
|
|
|
|
|
|
2024-02-12 19:24:34 -06:00
|
|
|
{discriminator !== undefined && (
|
|
|
|
|
<Text
|
|
|
|
|
size="1"
|
|
|
|
|
style={{
|
|
|
|
|
textShadow: '0 0 4px black',
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
top: '50%',
|
|
|
|
|
right: 8,
|
|
|
|
|
textAlign: 'right',
|
|
|
|
|
}}
|
2024-04-01 19:05:55 -05:00
|
|
|
color={variant === 'ghost' ? 'gray' : undefined}
|
2024-02-12 19:24:34 -06:00
|
|
|
>
|
|
|
|
|
{discriminator}
|
|
|
|
|
</Text>
|
|
|
|
|
)}
|
|
|
|
|
</Button>
|
|
|
|
|
);
|
2024-08-19 14:02:39 -05:00
|
|
|
|
|
|
|
|
if (tooltip) return <Tooltip content={tooltip}>{button}</Tooltip>;
|
|
|
|
|
return button;
|
2024-02-12 19:24:34 -06:00
|
|
|
}
|