2021-01-14 18:07:05 +00:00
|
|
|
// Copyright 2019-2021 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2019-01-30 20:15:07 +00:00
|
|
|
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',
|
2021-05-06 00:09:29 +00:00
|
|
|
'on-captcha',
|
2020-10-06 17:06:34 +00:00
|
|
|
'on-progress-dialog',
|
2021-01-29 22:16:48 +00:00
|
|
|
'on-avatar',
|
2020-08-21 22:04:19 +00:00
|
|
|
] as const;
|
|
|
|
export type SpinnerDirection = typeof SpinnerDirections[number];
|
|
|
|
|
2021-01-14 18:07:05 +00:00
|
|
|
export type Props = {
|
2021-05-13 20:57:27 +00:00
|
|
|
ariaLabel?: string;
|
2021-01-29 22:58:28 +00:00
|
|
|
direction?: SpinnerDirection;
|
2021-05-13 20:57:27 +00:00
|
|
|
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-14 18:07:05 +00:00
|
|
|
};
|
2019-01-30 20:15:07 +00:00
|
|
|
|
2021-01-29 22:58:28 +00:00
|
|
|
export const Spinner = ({
|
2021-05-13 20:57:27 +00:00
|
|
|
ariaLabel,
|
|
|
|
direction,
|
2021-01-29 22:58:28 +00:00
|
|
|
moduleClassName,
|
2021-05-13 20:57:27 +00:00
|
|
|
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
|
|
|
)}
|
2021-05-13 20:57:27 +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>
|
|
|
|
);
|
|
|
|
};
|