Skip to content

Commit

Permalink
Change variant prop into determinate boolean prop
Browse files Browse the repository at this point in the history
  • Loading branch information
hbjORbj committed Aug 11, 2022
1 parent b70371f commit 2d52619
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
38 changes: 21 additions & 17 deletions packages/mui-joy/src/CircularProgress/CircularProgress.tsx
Expand Up @@ -40,12 +40,16 @@ const circularDashKeyframe = keyframes`
`;

const useUtilityClasses = (ownerState: CircularProgressProps) => {
const { variant, color } = ownerState;
const { determinate, color } = ownerState;

const slots = {
root: ['root', variant, color && `color${capitalize(color)}`],
root: [
'root',
determinate ? 'determinate' : 'indeterminate',
color && `color${capitalize(color)}`,
],
svg: ['svg'],
circle: ['circle', variant && `circle${capitalize(variant)}`],
circle: ['circle', determinate ? `circleDeterminate` : 'circleIndeterminate'],
};

return composeClasses(slots, getCircularProgressUtilityClass, {});
Expand All @@ -60,7 +64,7 @@ const CircularProgressRoot = styled('span', {
return [
{
display: 'inline-block',
...(ownerState.variant === 'determinate' && {
...(ownerState.determinate && {
transition: 'transform 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms',
}),
color: theme.vars.palette[ownerState.color!].mainChannel,
Expand All @@ -80,7 +84,7 @@ const CircularProgressRoot = styled('span', {
];
},
({ ownerState }) =>
ownerState.variant === 'indeterminate' &&
!ownerState.determinate &&
css`
animation: ${circularRotateKeyframe} 1.4s linear infinite;
`,
Expand All @@ -103,17 +107,17 @@ const CircularProgressCircle = styled('circle', {
stroke: theme.vars.palette[ownerState.color!]['500'],
// Use butt to follow the specification, by chance, it's already the default CSS value.
// strokeLinecap: 'butt',
...(ownerState.variant === 'determinate' && {
...(ownerState.determinate && {
transition: 'stroke-dashoffset 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms',
}),
...(ownerState.variant === 'indeterminate' && {
...(!ownerState.determinate && {
// Some default value that looks fine waiting for the animation to kicks in.
strokeDasharray: '80px, 200px',
strokeDashoffset: 0, // Add the unit to fix a Edge 16 and below bug.
}),
}),
({ ownerState }) =>
ownerState.variant === 'indeterminate' &&
!ownerState.determinate &&
css`
animation: ${circularDashKeyframe} 1.4s ease-in-out infinite;
`,
Expand All @@ -135,7 +139,7 @@ const CircularProgress = React.forwardRef(function CircularProgress(inProps, ref
thickness = 3.6,
style,
value = 0,
variant = 'indeterminate',
determinate = false,
...other
} = props;

Expand All @@ -145,7 +149,7 @@ const CircularProgress = React.forwardRef(function CircularProgress(inProps, ref
size,
thickness,
value,
variant,
determinate,
};

const classes = useUtilityClasses(ownerState);
Expand All @@ -154,7 +158,7 @@ const CircularProgress = React.forwardRef(function CircularProgress(inProps, ref
const rootStyle: { transform?: string } = {};
const rootProps: { 'aria-valuenow'?: number } = {};

if (variant === 'determinate') {
if (determinate) {
const circumference = 2 * Math.PI * ((SIZE - thickness) / 2);
circleStyle.strokeDasharray = circumference.toFixed(3);
rootProps['aria-valuenow'] = Math.round(value);
Expand Down Expand Up @@ -210,6 +214,12 @@ CircularProgress.propTypes /* remove-proptypes */ = {
* @default 'primary'
*/
color: PropTypes.oneOf(['danger', 'info', 'neutral', 'primary', 'success', 'warning']),
/**
* The boolean to select a variant.
* Use indeterminate when there is no progress value.
* @default false
*/
determinate: PropTypes.bool,
/**
* The size of the component.
* It accepts theme values between 'sm' and 'lg'.
Expand Down Expand Up @@ -239,12 +249,6 @@ CircularProgress.propTypes /* remove-proptypes */ = {
* @default 0
*/
value: PropTypes.number,
/**
* The variant to use.
* Use indeterminate when there is no progress value.
* @default 'indeterminate'
*/
variant: PropTypes.oneOf(['determinate', 'indeterminate']),
} as any;

export default CircularProgress;
12 changes: 6 additions & 6 deletions packages/mui-joy/src/CircularProgress/CircularProgressProps.ts
Expand Up @@ -14,6 +14,12 @@ export interface CircularProgressTypeMap<P = {}, D extends React.ElementType = '
* @default 'primary'
*/
color?: OverridableStringUnion<ColorPaletteProp, CircularProgressPropsColorOverrides>;
/**
* The boolean to select a variant.
* Use indeterminate when there is no progress value.
* @default false
*/
determinate?: true | false;
/**
* The size of the component.
* It accepts theme values between 'sm' and 'lg'.
Expand All @@ -35,12 +41,6 @@ export interface CircularProgressTypeMap<P = {}, D extends React.ElementType = '
* @default 0
*/
value?: number;
/**
* The variant to use.
* Use indeterminate when there is no progress value.
* @default 'indeterminate'
*/
variant?: 'determinate' | 'indeterminate';
};
defaultComponent: D;
}
Expand Down

0 comments on commit 2d52619

Please sign in to comment.