Some checks failed
No response / noResponse (push) Has been cancelled
CI / Continuous releases (push) Has been cancelled
CI / test-dev (macos-latest) (push) Has been cancelled
CI / test-dev (ubuntu-latest) (push) Has been cancelled
CI / test-dev (windows-latest) (push) Has been cancelled
Maintenance / main (push) Has been cancelled
Scorecards supply-chain security / Scorecards analysis (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
72 lines
1.8 KiB
TypeScript
72 lines
1.8 KiB
TypeScript
import * as React from 'react';
|
|
import { createTheme, ThemeProvider, useColorScheme } from '@mui/material/styles';
|
|
import Stack from '@mui/material/Stack';
|
|
import MenuItem from '@mui/material/MenuItem';
|
|
import Switch from '@mui/material/Switch';
|
|
import Select from '@mui/material/Select';
|
|
import FormControlLabel from '@mui/material/FormControlLabel';
|
|
|
|
const theme = createTheme({
|
|
cssVariables: {
|
|
colorSchemeSelector: '.demo-disable-transition-%s',
|
|
},
|
|
colorSchemes: { dark: true },
|
|
});
|
|
|
|
function ModeSwitcher() {
|
|
const { mode, setMode } = useColorScheme();
|
|
if (!mode) {
|
|
return null;
|
|
}
|
|
return (
|
|
<Select
|
|
value={mode}
|
|
onChange={(event) =>
|
|
setMode(event.target.value as 'system' | 'light' | 'dark')
|
|
}
|
|
sx={{ minWidth: 120 }}
|
|
>
|
|
<MenuItem value="system">System</MenuItem>
|
|
<MenuItem value="light">Light</MenuItem>
|
|
<MenuItem value="dark">Dark</MenuItem>
|
|
</Select>
|
|
);
|
|
}
|
|
|
|
export default function DisableTransitionOnChange() {
|
|
const [disableTransition, setDisableTransition] = React.useState(false);
|
|
return (
|
|
<ThemeProvider
|
|
theme={theme}
|
|
disableNestedContext
|
|
disableTransitionOnChange={disableTransition}
|
|
>
|
|
<Stack
|
|
sx={{
|
|
width: '100%',
|
|
borderRadius: '4px',
|
|
p: 2,
|
|
gap: 2,
|
|
display: 'flex',
|
|
justifyContent: 'center',
|
|
alignItems: 'center',
|
|
bgcolor: 'background.default',
|
|
color: 'text.primary',
|
|
transition: '1s',
|
|
}}
|
|
>
|
|
<ModeSwitcher />
|
|
<FormControlLabel
|
|
control={
|
|
<Switch
|
|
checked={disableTransition}
|
|
onChange={(event) => setDisableTransition(event.target.checked)}
|
|
/>
|
|
}
|
|
label="Disable transition"
|
|
/>
|
|
</Stack>
|
|
</ThemeProvider>
|
|
);
|
|
}
|