import { useEffect, useId, useState } from 'react';
import classnames from 'classnames';
import vrLightDesignTokens from '@swipebox/morphe-design-tokens/dist/json/vr-theme/variables-light.json';
import styles from './VRSpinner.css';
import Box from '../Box';
import { useDefaultLabelContext } from '../contexts/DefaultLabelProvider';
import Flex from '../Flex';
import TextUI from '../TextUI';
const SIZE_NAME_TO_PIXEL = {
sm: 32,
lg: 56,
} as const;
type SpinnerBodyProps = {
accessibilityDescribedby?: string;
accessibilityLabel: string;
delay: boolean;
show: boolean;
size: 'sm' | 'lg';
color: 'default' | 'grayscale' | 'white';
onExitAnimationEnd: () => void;
};
function SpinnerBody({
accessibilityDescribedby,
accessibilityLabel,
delay,
show,
size,
color,
onExitAnimationEnd,
}: SpinnerBodyProps) {
const colorWhite = color === 'white' && vrLightDesignTokens['sema-color-background-light'];
const colorGrayscale = color === 'grayscale' && vrLightDesignTokens['base-color-grayscale-350'];
const nonDefaultSpinnerColor =
colorWhite || colorGrayscale
? ({
'--comp-spinner-color-background-1': colorWhite || colorGrayscale,
'--comp-spinner-color-background-2': colorWhite || colorGrayscale,
'--comp-spinner-color-background-3': colorWhite || colorGrayscale,
} as React.CSSProperties)
: {};
return (
);
}
type Props = {
accessibilityLabel?: string;
label?: string;
delay?: boolean;
show: boolean;
size?: 'sm' | 'lg';
color?: 'default' | 'grayscale' | 'white';
};
export default function Spinner({
accessibilityLabel,
delay = true,
label,
show: showProp,
size = 'lg',
color = 'default',
}: Props) {
const [show, setShow] = useState(showProp);
const { accessibilityLabel: accessibilityLabelDefault } = useDefaultLabelContext('Spinner');
const id = useId();
const unmountSpinner = () => {
if (!showProp) setShow(false);
};
useEffect(() => {
if (showProp) setShow(showProp);
}, [showProp]);
if (!show) return null;
return label ? (
{label}
) : (
);
}
Spinner.displayName = 'Spinner';