import type { FC, ReactNode } from 'react'; import { Suspense } from 'react'; import styled, { css, keyframes } from 'styled-components'; import tw from 'twin.macro'; import ErrorBoundary from '@/components/elements/ErrorBoundary'; export type SpinnerSize = 'small' | 'base' | 'large'; interface Props { children?: ReactNode; size?: SpinnerSize; centered?: boolean; isBlue?: boolean; } interface Spinner extends FC { Size: Record<'SMALL' | 'BASE' | 'LARGE', SpinnerSize>; Suspense: FC; } const spin = keyframes` to { transform: rotate(360deg); } `; // noinspection CssOverwrittenProperties const SpinnerComponent = styled.div` ${tw`w-8 h-8`}; border-width: 3px; border-radius: 50%; animation: ${spin} 1s cubic-bezier(0.55, 0.25, 0.25, 0.7) infinite; ${props => props.size === 'small' ? tw`w-4 h-4 border-2` : props.size === 'large' ? css` ${tw`w-16 h-16`}; border-width: 6px; ` : null}; border-color: ${props => (!props.isBlue ? 'rgba(255, 255, 255, 0.2)' : 'hsla(212, 92%, 43%, 0.2)')}; border-top-color: ${props => (!props.isBlue ? 'rgb(255, 255, 255)' : 'hsl(212, 92%, 43%)')}; `; const Spinner: Spinner = ({ centered, ...props }) => centered ? (
) : ( ); Spinner.displayName = 'Spinner'; Spinner.Size = { SMALL: 'small', BASE: 'base', LARGE: 'large', }; Spinner.Suspense = ({ children, centered = true, size = Spinner.Size.LARGE, ...props }) => ( }> {children} ); Spinner.Suspense.displayName = 'Spinner.Suspense'; export default Spinner;