Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs][joy-ui] Integrate a count-up feature to the Circular Progress #38724

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import Box from '@mui/joy/Box';
import Button from '@mui/joy/Button';
import CircularProgress from '@mui/joy/CircularProgress';
import Stack from '@mui/joy/Stack';
import Typography from '@mui/joy/Typography';
import * as React from 'react';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move React import to the top for codebase consistency?

import { useCountUp } from 'use-count-up';
Copy link
Member

@siriwatknp siriwatknp Aug 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add use-count-up to docs/package.json, then run yarn install.


export default function CircularProgressDeterminate() {
const [isLoading, setIsLoading] = React.useState(false);

const { value: value1 } = useCountUp({
isCounting: isLoading,
duration: 1,
start: 0,
end: 25,
});

const { value: value2, reset } = useCountUp({
isCounting: true,
duration: 1,
start: 0,
end: 75,
});

return (
<Box sx={{ display: 'flex', gap: 2, alignItems: 'center', flexWrap: 'wrap' }}>
<Stack sx={{ gap: 2 }}>
<CircularProgress size="lg" determinate value={value1}>
<Typography>{value1}%</Typography>
</CircularProgress>
<Button size="sm" onClick={() => setIsLoading(true)}>
Start
</Button>
</Stack>
<Stack sx={{ gap: 2 }}>
<CircularProgress size="lg" determinate value={value2}>
<Typography>{value2}%</Typography>
</CircularProgress>
<Button size="sm" onClick={reset}>
Reset
</Button>
</Stack>
</Box>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import Box from '@mui/joy/Box';
import Button from '@mui/joy/Button';
import CircularProgress from '@mui/joy/CircularProgress';
import Stack from '@mui/joy/Stack';
import Typography from '@mui/joy/Typography';
import * as React from 'react';
import { useCountUp } from 'use-count-up';

export default function CircularProgressDeterminate() {
const [isLoading, setIsLoading] = React.useState(false);

const { value: value1 } = useCountUp({
isCounting: isLoading,
duration: 1,
start: 0,
end: 25,
});

const { value: value2, reset } = useCountUp({
isCounting: true,
duration: 1,
start: 0,
end: 75,
});

return (
<Box sx={{ display: 'flex', gap: 2, alignItems: 'center', flexWrap: 'wrap' }}>
<Stack sx={{ gap: 2 }}>
<CircularProgress size="lg" determinate value={value1}>
<Typography>{value1}%</Typography>
</CircularProgress>
<Button size="sm" onClick={() => setIsLoading(true)}>
Start
</Button>
</Stack>
<Stack sx={{ gap: 2 }}>
<CircularProgress size="lg" determinate value={value2}>
<Typography>{value2}%</Typography>
</CircularProgress>
<Button size="sm" onClick={reset}>
Reset
</Button>
</Stack>
</Box>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<CircularProgress size="lg" determinate value={value1}>
<Typography>{value1}%</Typography>
</CircularProgress>
<CircularProgress size="lg" determinate value={value2}>
<Typography>{value2}%</Typography>
</CircularProgress>
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ You can use these to customize the component with both the `sx` prop and the the

{{"demo": "CircularProgressVariables.js", "hideToolbar": true, "bg": "gradient"}}

## Common examples

### Count up feature
Copy link
Member

@siriwatknp siriwatknp Aug 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Common examples
### Count up feature
## 3rd-party integration
### use-count-up

@danilo-leal What do you think about grouping 3rd-party libraries in h2?

We have a similar thing on input but it is h3.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd still leave it in the Common examples, as it would be more consistent with the Input. Maybe the "Third-party integration" title works but it isn't immediately clear when compared to "Third-party formatting" (Input's case). 🤔


Using the [use-count-up](https://www.npmjs.com/package/use-count-up) package, you can create a counting animation by providing `start`, `end`, and `duration` values.

{{"demo": "CircularProgressCountUp.js"}}

## Accessibility

Out of the box, the `aria-valuenow` attribute will indicate the current value of the progress bar only when the value is not indeterminate.
Expand Down