Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion examples/material-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"@emotion/react": "11.14.0",
"@emotion/styled": "11.14.1",
"@mui/material": "7.3.4",
"@mui/styles": "6.4.8",
"@tanem/react-nprogress": "latest",
"@types/jest": "30.0.0",
"@types/node": "22.18.9",
Expand Down
31 changes: 13 additions & 18 deletions examples/material-ui/src/Progress.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
import Container from '@mui/material/Container'
import LinearProgress from '@mui/material/LinearProgress'
import { makeStyles, Theme } from '@mui/styles'
import { useNProgress } from '@tanem/react-nprogress'
import React from 'react'

const useStyles = makeStyles<
Theme,
Pick<ReturnType<typeof useNProgress>, 'animationDuration' | 'isFinished'>
>({
bar: ({ animationDuration }) => ({
transitionDuration: `${animationDuration}ms`,
}),
container: ({ animationDuration, isFinished }) => ({
opacity: isFinished ? 0 : 1,
pointerEvents: 'none',
transition: `opacity ${animationDuration}ms linear`,
}),
})

const Progress: React.FC<{ isAnimating: boolean }> = ({ isAnimating }) => {
const { animationDuration, isFinished, progress } = useNProgress({
isAnimating,
})
const classes = useStyles({ animationDuration, isFinished })

return (
<Container classes={{ root: classes.container }} disableGutters={true}>
<Container
disableGutters={true}
sx={{
opacity: isFinished ? 0 : 1,
pointerEvents: 'none',
transition: `opacity ${animationDuration}ms linear`,
}}
>
<LinearProgress
classes={{ bar1Determinate: classes.bar }}
sx={{
'& .MuiLinearProgress-bar1Determinate': {
transitionDuration: `${animationDuration}ms`,
},
}}
value={progress * 100}
variant="determinate"
/>
Expand Down
33 changes: 16 additions & 17 deletions examples/material-ui/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
import { GlobalStyles } from '@mui/material'
import Button from '@mui/material/Button'
import Container from '@mui/material/Container'
import { makeStyles } from '@mui/styles'
import React, { useState } from 'react'
import { createRoot } from 'react-dom/client'

import Progress from './Progress'

const useStyles = makeStyles({
'@global': {
body: {
margin: 0,
},
},
container: {
alignItems: 'center',
display: 'flex',
height: '100vh',
justifyContent: 'center',
},
})

const App: React.FC = () => {
const classes = useStyles()
const [state, setState] = useState({
isAnimating: false,
key: 0,
})

return (
<>
<GlobalStyles
styles={{
body: {
margin: 0,
},
}}
/>
<Progress isAnimating={state.isAnimating} key={state.key} />
<Container classes={{ root: classes.container }}>
<Container
sx={{
alignItems: 'center',
display: 'flex',
height: '100vh',
justifyContent: 'center',
}}
>
<Button
onClick={() => {
setState((prevState) => ({
Expand Down
6 changes: 2 additions & 4 deletions examples/umd-dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
],
"version": "0.1.0",
"private": true,
"main": "index.html",
"scripts": {
"start": "parcel index.html --open",
"build": "parcel build index.html"
"start": "npx serve . --single --listen 1234"
},
"devDependencies": {
"parcel-bundler": "1.12.5"
"serve": "^14.2.0"
}
}
6 changes: 2 additions & 4 deletions examples/umd-prod/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
],
"version": "0.1.0",
"private": true,
"main": "index.html",
"scripts": {
"start": "parcel index.html --open",
"build": "parcel build index.html"
"start": "npx serve . --single --listen 1235"
},
"devDependencies": {
"parcel-bundler": "1.12.5"
"serve": "^14.2.0"
}
}