Debian Codegraph @

node/@patternfly/react-core/src/components/Spinner/Spinner.tsx

raw
1 import styles from '@patternfly/react-styles/css/components/Spinner/spinner';
2 import { css } from '@patternfly/react-styles';
3 import cssDiameter from '@patternfly/react-tokens/dist/esm/c_spinner_diameter';
4
5 export enum spinnerSize {
6 sm = 'sm',
7 md = 'md',
8 lg = 'lg',
9 xl = 'xl'
10 }
11
12 export interface SpinnerProps extends React.SVGProps<SVGSVGElement> {
13 /** Additional classes added to the Spinner. */
14 className?: string;
15 /** Size variant of progress. */
16 size?: 'sm' | 'md' | 'lg' | 'xl';
17 /** Text describing that current loading status or progress */
18 'aria-valuetext'?: string;
19 /** Diameter of spinner set as CSS variable */
20 diameter?: string;
21 /** Indicates the spinner is inline and the size should inherit the text font size. This will override the size prop. */
22 isInline?: boolean;
23 /** Accessible label to describe what is loading */
24 'aria-label'?: string;
25 /** Id of element which describes what is being loaded */
26 'aria-labelledBy'?: string;
27 }
28
29 export const Spinner: React.FunctionComponent<SpinnerProps> = ({
30 className = '',
31 size = 'xl',
32 'aria-valuetext': ariaValueText = 'Loading...',
33 diameter,
34 isInline = false,
35 'aria-label': ariaLabel,
36 'aria-labelledBy': ariaLabelledBy,
37 ...props
38 }: SpinnerProps) => (
39 <svg
40 className={css(styles.spinner, isInline ? styles.modifiers.inline : styles.modifiers[size], className)}
41 role="progressbar"
42 aria-valuetext={ariaValueText}
43 viewBox="0 0 100 100"
44 {...(diameter && { style: { [cssDiameter.name]: diameter } as React.CSSProperties })}
45 {...(ariaLabel && { 'aria-label': ariaLabel })}
46 {...(ariaLabelledBy && { 'aria-labelledBy': ariaLabelledBy })}
47 {...(!ariaLabel && !ariaLabelledBy && { 'aria-label': 'Contents' })}
48 {...props}
49 >
50 <circle className={styles.spinnerPath} cx="50" cy="50" r="45" fill="none" />
51 </svg>
52 );
53 Spinner.displayName = 'Spinner';