import { Box, Typography, LinearProgress, CircularProgress } from '@mui/material';
import clsx from 'clsx';
import './rds-loader.scss';
export interface RdsLoaderProps {
variant?: 'linear' | 'circular';
size?: 'small' | 'medium' | 'large';
color?: 'primary' | 'secondary' | 'error' | 'warning' | 'info' | 'success';
value?: number;
label?: string;
overlay?: boolean;
thickness?: number;
type?: string;
}
const RdsLoader = (props: RdsLoaderProps) => {
if (props.type) {
const size = props.size || "medium";
let type = props.type;
if (type.startsWith('loader-')) {
type = type.replace(/^loader-/, '');
}
const loaderClass = `rds-loader__${type}`;
const sizeClass = `loader-${size}`;
const classes = clsx(loaderClass, sizeClass);
return (
{typeof props.label === 'string' && props.label && (
{props.label}
)}
);
}
const {
variant = 'circular',
size = 'medium',
color = 'primary',
value,
label,
overlay = false,
thickness = 3.6,
} = props;
// Overlay sits on a dark backdrop — keep label/value text light for contrast in light mode
const overlayTextSx = overlay
? { color: 'var(--rds-neutral-0, #fff)' }
: undefined;
const getSizeValue = () => {
if (variant === 'circular') {
switch (size) {
case 'small':
return 24;
case 'medium':
return 40;
case 'large':
return 56;
default:
return 40;
}
}
return undefined;
};
const renderLoader = () => {
if (variant === 'linear') {
return (
{typeof label === 'string' && label && (
{label}
)}
{value !== undefined && (
{Math.round(value)}%
)}
);
}
return (
{typeof label === 'string' && label && (
{label}
)}
{value !== undefined && (
{Math.round(value)}%
)}
);
};
const loaderElement = renderLoader();
if (overlay) {
return (
{loaderElement}
);
}
return loaderElement;
};
RdsLoader.displayName = 'RdsLoader';
export default RdsLoader;