signal-desktop/ts/components/Spinner.tsx

75 lines
1.9 KiB
TypeScript
Raw Normal View History

// Copyright 2019-2021 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
import React from 'react';
import classNames from 'classnames';
2021-05-11 00:50:43 +00:00
import { getClassNamesFor } from '../util/getClassNamesFor';
2020-08-21 22:04:19 +00:00
export const SpinnerSvgSizes = ['small', 'normal'] as const;
export type SpinnerSvgSize = typeof SpinnerSvgSizes[number];
export const SpinnerDirections = [
'outgoing',
'incoming',
'on-background',
'on-captcha',
2020-10-06 17:06:34 +00:00
'on-progress-dialog',
'on-avatar',
2020-08-21 22:04:19 +00:00
] as const;
export type SpinnerDirection = typeof SpinnerDirections[number];
export type Props = {
ariaLabel?: string;
2021-01-29 22:58:28 +00:00
direction?: SpinnerDirection;
moduleClassName?: string;
role?: string;
2019-06-26 19:33:13 +00:00
size?: string;
2020-08-21 22:04:19 +00:00
svgSize: SpinnerSvgSize;
};
2021-01-29 22:58:28 +00:00
export const Spinner = ({
ariaLabel,
direction,
2021-01-29 22:58:28 +00:00
moduleClassName,
role,
2021-01-29 22:58:28 +00:00
size,
svgSize,
2021-05-11 00:50:43 +00:00
}: Props): JSX.Element => {
const getClassName = getClassNamesFor('module-spinner', moduleClassName);
return (
2020-09-12 00:46:52 +00:00
<div
className={classNames(
2021-05-11 00:50:43 +00:00
getClassName('__container'),
getClassName(`__container--${svgSize}`),
getClassName(direction && `__container--${direction}`),
getClassName(direction && `__container--${svgSize}-${direction}`)
2020-09-12 00:46:52 +00:00
)}
role={role}
aria-label={ariaLabel}
2021-05-11 00:50:43 +00:00
style={{
height: size,
width: size,
}}
>
<div
className={classNames(
getClassName('__circle'),
getClassName(`__circle--${svgSize}`),
getClassName(direction && `__circle--${direction}`),
getClassName(direction && `__circle--${svgSize}-${direction}`)
)}
/>
<div
className={classNames(
getClassName('__arc'),
getClassName(`__arc--${svgSize}`),
getClassName(direction && `__arc--${direction}`),
getClassName(direction && `__arc--${svgSize}-${direction}`)
)}
/>
</div>
);
};