forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docs][joy-ui] Add
use-count-up
integration with the Circular Progr…
…ess (mui#38952)
- Loading branch information
1 parent
4e46478
commit 1faea19
Showing
4 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
docs/data/joy/components/circular-progress/CircularProgressCountUp.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import * as React from 'react'; | ||
import Stack from '@mui/joy/Stack'; | ||
import Button from '@mui/joy/Button'; | ||
import Typography from '@mui/joy/Typography'; | ||
import CircularProgress from '@mui/joy/CircularProgress'; | ||
import { useCountUp } from 'use-count-up'; | ||
|
||
export default function CircularProgressCountUp() { | ||
const [isLoading, setIsLoading] = React.useState(false); | ||
const [buttonLabel, setButtonLabel] = React.useState('Start'); | ||
|
||
const { value: value1, reset: resetValue1 } = useCountUp({ | ||
isCounting: isLoading, | ||
duration: 1, | ||
start: 0, | ||
end: 25, | ||
onComplete: () => { | ||
setIsLoading(false); | ||
setButtonLabel('Reset'); | ||
}, | ||
}); | ||
|
||
const { value: value2, reset } = useCountUp({ | ||
isCounting: true, | ||
duration: 1, | ||
start: 0, | ||
end: 75, | ||
}); | ||
|
||
const handleButtonClick = () => { | ||
if (isLoading) { | ||
setIsLoading(false); | ||
setButtonLabel('Start'); | ||
resetValue1(); | ||
} else if (buttonLabel === 'Reset') { | ||
setButtonLabel('Start'); | ||
resetValue1(); | ||
} else { | ||
setIsLoading(true); | ||
setButtonLabel('Reset'); | ||
} | ||
}; | ||
|
||
return ( | ||
<Stack direction="row" alignItems="center" flexWrap="wrap" spacing={8}> | ||
<Stack spacing={2}> | ||
<CircularProgress size="lg" determinate value={value1}> | ||
<Typography>{value1}%</Typography> | ||
</CircularProgress> | ||
<Button | ||
size="sm" | ||
variant="outlined" | ||
color="neutral" | ||
onClick={handleButtonClick} | ||
> | ||
{buttonLabel} | ||
</Button> | ||
</Stack> | ||
<Stack spacing={2}> | ||
<CircularProgress size="lg" determinate value={value2}> | ||
<Typography>{value2}%</Typography> | ||
</CircularProgress> | ||
<Button size="sm" variant="outlined" color="neutral" onClick={reset}> | ||
Reload | ||
</Button> | ||
</Stack> | ||
</Stack> | ||
); | ||
} |
69 changes: 69 additions & 0 deletions
69
docs/data/joy/components/circular-progress/CircularProgressCountUp.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import * as React from 'react'; | ||
import Stack from '@mui/joy/Stack'; | ||
import Button from '@mui/joy/Button'; | ||
import Typography from '@mui/joy/Typography'; | ||
import CircularProgress from '@mui/joy/CircularProgress'; | ||
import { useCountUp } from 'use-count-up'; | ||
|
||
export default function CircularProgressCountUp() { | ||
const [isLoading, setIsLoading] = React.useState(false); | ||
const [buttonLabel, setButtonLabel] = React.useState('Start'); | ||
|
||
const { value: value1, reset: resetValue1 } = useCountUp({ | ||
isCounting: isLoading, | ||
duration: 1, | ||
start: 0, | ||
end: 25, | ||
onComplete: () => { | ||
setIsLoading(false); | ||
setButtonLabel('Reset'); | ||
}, | ||
}); | ||
|
||
const { value: value2, reset } = useCountUp({ | ||
isCounting: true, | ||
duration: 1, | ||
start: 0, | ||
end: 75, | ||
}); | ||
|
||
const handleButtonClick = () => { | ||
if (isLoading) { | ||
setIsLoading(false); | ||
setButtonLabel('Start'); | ||
resetValue1(); | ||
} else if (buttonLabel === 'Reset') { | ||
setButtonLabel('Start'); | ||
resetValue1(); | ||
} else { | ||
setIsLoading(true); | ||
setButtonLabel('Reset'); | ||
} | ||
}; | ||
|
||
return ( | ||
<Stack direction="row" alignItems="center" flexWrap="wrap" spacing={8}> | ||
<Stack spacing={2}> | ||
<CircularProgress size="lg" determinate value={value1 as number}> | ||
<Typography>{value1}%</Typography> | ||
</CircularProgress> | ||
<Button | ||
size="sm" | ||
variant="outlined" | ||
color="neutral" | ||
onClick={handleButtonClick} | ||
> | ||
{buttonLabel} | ||
</Button> | ||
</Stack> | ||
<Stack spacing={2}> | ||
<CircularProgress size="lg" determinate value={value2 as number}> | ||
<Typography>{value2}%</Typography> | ||
</CircularProgress> | ||
<Button size="sm" variant="outlined" color="neutral" onClick={reset}> | ||
Reload | ||
</Button> | ||
</Stack> | ||
</Stack> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters