Commit 82b8572e authored by 吴永生#A02208's avatar 吴永生#A02208

fix: MySwitch组件开发

parent 6d76e3a4
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: 吴永生#A02208 yongsheng.wu@wholion.com * @Author: 吴永生#A02208 yongsheng.wu@wholion.com
* @Date: 2021-12-04 15:46:25 * @Date: 2021-12-04 15:46:25
* @LastEditors: 吴永生#A02208 yongsheng.wu@wholion.com * @LastEditors: 吴永生#A02208 yongsheng.wu@wholion.com
* @LastEditTime: 2022-07-21 15:54:59 * @LastEditTime: 2022-07-21 18:00:58
* @FilePath: /lionet-slb-pc/src/components/SearchView/components/Collapse.tsx * @FilePath: /lionet-slb-pc/src/components/SearchView/components/Collapse.tsx
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/ */
...@@ -67,6 +67,17 @@ export default function MySelect(props: IProps) { ...@@ -67,6 +67,17 @@ export default function MySelect(props: IProps) {
}, },
}, },
MuiMenuItem: {
styleOverrides: {
root: {
":hover": {
backgroundColor: "#ECF4FF ",
color: "#1370FF",
},
},
},
},
MuiOutlinedInput: { MuiOutlinedInput: {
styleOverrides: { styleOverrides: {
root: { root: {
......
import * as React from 'react'; /*
import Switch from '@mui/material/Switch'; * @Author: 吴永生#A02208 yongsheng.wu@wholion.com
* @Date: 2022-07-11 11:56:58
* @LastEditors: 吴永生#A02208 yongsheng.wu@wholion.com
* @LastEditTime: 2022-07-21 18:30:18
* @FilePath: /bkunyun/src/components/mui/MySwitch.tsx
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
import * as React from "react";
import Switch, { SwitchProps } from "@mui/material/Switch";
import { ThemeProvider, createTheme } from "@mui/material/styles"; import { ThemeProvider, createTheme } from "@mui/material/styles";
interface IMySwitchProps extends SwitchProps {
type IMySwitchProps = { value: boolean;
value: boolean; onChange?: any;
onChange?: any; disabled?: boolean;
disabled?: boolean;
} }
const theme = createTheme({ const theme = createTheme({
...@@ -15,46 +21,59 @@ const theme = createTheme({ ...@@ -15,46 +21,59 @@ const theme = createTheme({
MuiSwitch: { MuiSwitch: {
styleOverrides: { styleOverrides: {
root: { root: {
height: '22px', boxSizing: "border-box",
width: '40px', padding: "0",
boxSizing: 'border-box', },
padding: '0', switchBase: {
top: "4px",
left: "4px",
padding: 0,
"&.Mui-checked": {
left: "2px",
"& + .MuiSwitch-track": {
backgroundColor: "#1370ff",
opacity: 1,
},
},
},
thumb: {
width: "14px",
height: "14px",
color: "#fff",
},
track: {
borderRadius: "11px",
backgroundColor: "#E6E8EB",
opacity: 1,
}, },
switchBase:{
top: '4px',
left: '4px',
padding: 0,
'&.Mui-checked': {
left: '2px',
'& + .MuiSwitch-track': {
opacity: 1,
}
},
},
thumb: {
width: '14px',
height: '14px',
color: '#fff'
},
track: {
borderRadius: '11px',
backgroundColor: "#E6E8EB",
opacity: 1,
},
}, },
}, },
}, },
}); });
const MySwitch = (props: IMySwitchProps) => { const MySwitch = (props: IMySwitchProps) => {
const {value, onChange, disabled= false} = props; const { value, onChange, disabled = false, size, ...other } = props;
return ( return (
<ThemeProvider theme={theme}> <ThemeProvider theme={theme}>
<Switch checked={value} disabled={disabled} onChange={onChange} /> <Switch
</ThemeProvider> checked={value}
) disabled={disabled}
} onChange={onChange}
sx={
size === "medium"
? {
width: 44,
height: 24,
}
: {
width: 40,
height: 22,
}
}
{...other}
/>
</ThemeProvider>
);
};
export default MySwitch; export default MySwitch;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment