feat: add AR launch button

This commit is contained in:
rajun 2026-10-27 16:28:52 +05:30
parent 69f9b9bc1e
commit 9799ffdf14

View File

@ -0,0 +1,61 @@
import type { CSSProperties } from 'react';
import { Box, Loader2 } from 'lucide-react';
import { Button } from '~/components/ui/button';
import { Text } from '~/components/ui/text';
import { AR_BUTTON_LABEL } from '~/data/ar-viewer/constants';
import { BUTTON_SIZES } from '~/data/projects/constants';
import { cn } from '~/lib/utils';
import type { ButtonStyle } from '~/types/project';
// Measurements for the chosen size: a pill preset, or the project's exact custom values
function boxStyle({ size = 'md', custom }: ButtonStyle): CSSProperties {
if (size === 'custom' && custom) {
return {
height: custom.height,
width: custom.width ?? undefined,
paddingInline: custom.paddingX,
borderRadius: custom.radius,
border: custom.borderWidth ? `${custom.borderWidth}px solid ${custom.borderColor}` : undefined,
};
}
const { height, paddingX } = BUTTON_SIZES[size === 'sm' || size === 'lg' ? size : 'md'];
return { height, paddingInline: paddingX };
}
interface ArLaunchButtonProps {
style?: ButtonStyle;
launching?: boolean;
hint?: string | null;
onLaunch?: () => void;
// Placement of the button row, e.g. over the model
className?: string;
}
// "View in your space" button; takes the client's colour, text colour, label and size when the project sets them
export function ArLaunchButton({ style = {}, launching, hint, onLaunch, className }: ArLaunchButtonProps) {
const preview = !onLaunch;
return (
<div className={cn('flex justify-center px-4 pt-2 pb-[max(1.625rem,env(safe-area-inset-bottom))]', className)}>
<Button
size='pill'
disabled={launching}
onClick={onLaunch}
tabIndex={preview ? -1 : undefined}
aria-hidden={preview || undefined}
style={{ backgroundColor: style.color, color: style.textColor, ...boxStyle(style) }}
className={cn(
'max-w-full',
style.color && 'hover:brightness-110',
hint && 'min-w-64',
style.size === 'full' && 'w-full',
preview ? 'pointer-events-none' : 'pointer-events-auto',
)}
>
{launching ? <Loader2 size={16} className='animate-spin' /> : <Box size={16} />}
<Text as='span' variant='inherit' tone='inherit' truncate>
{hint ?? style.label ?? AR_BUTTON_LABEL}
</Text>
</Button>
</div>
);
}