-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.tsx
More file actions
64 lines (57 loc) · 2.04 KB
/
index.tsx
File metadata and controls
64 lines (57 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import 'react-app-polyfill/ie11';
import * as React from 'react';
import { createRoot } from 'react-dom/client';
import { CacheProvider } from '@emotion/react';
import createCache from '@emotion/cache';
import { Box, Button, ButtonGroup, FormControlLabel, Switch, ThemeProvider, Typography } from '@mui/material';
import ProgressTimer, { type ProgressTimerHandle } from '../src/components';
import darkTheme from './theme';
const muiCache = createCache({
key: 'mui',
prepend: true
});
const App = () => {
const [started, setStarted] = React.useState(false);
const ref = React.useRef<ProgressTimerHandle>(null);
return (
<CacheProvider value={muiCache}>
<ThemeProvider theme={darkTheme}>
<Typography variant="subtitle2" mb={1}>
Click the progress bar to control the timer
</Typography>
<ProgressTimer
ref={ref}
started={started}
duration={5}
label="Label"
/>
<Box display="flex" flexDirection="column" alignItems="center">
<Typography variant="subtitle2" mt={4} mb={1}>
Control Timer with Prop
</Typography>
<FormControlLabel
control={<Switch checked={started} onChange={() => setStarted(!started)} />}
label="Started"
/>
<Typography variant="subtitle2" mt={4} mb={1}>
Control Timer with Ref
</Typography>
<ButtonGroup sx={{ marginBottom: 2 }}>
<Button title="start a stopped timer" onClick={() => ref.current?.start()}>
Start
</Button>
<Button title="stop a running timer" onClick={() => ref.current?.stop()}>
Stop
</Button>
<Button title="restart a running or finished timer" onClick={() => ref.current?.restart()}>
Restart
</Button>
</ButtonGroup>
</Box>
</ThemeProvider>
</CacheProvider>
);
};
const container = document.getElementById('root');
const root = createRoot(container!);
root.render(<App />);