mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Introducting Switcher component
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
2755f13887
commit
16eacee140
@ -17,6 +17,7 @@ import { HelmCharts } from "./helm-charts";
|
||||
import { KubectlBinaries } from "./kubectl-binaries";
|
||||
import { navigation } from "../../navigation";
|
||||
import { Tab, Tabs } from "../tabs";
|
||||
import { FormSwitch, Switcher } from "../switch";
|
||||
|
||||
enum PreferencesTab {
|
||||
Application = "application",
|
||||
@ -137,11 +138,15 @@ export class Preferences extends React.Component {
|
||||
|
||||
<section id="startup">
|
||||
<h2>Start-up</h2>
|
||||
<SubTitle title="Automatic Start-up"/>
|
||||
<Checkbox
|
||||
<FormSwitch
|
||||
control={
|
||||
<Switcher
|
||||
checked={preferences.openAtLogin}
|
||||
onChange={v => preferences.openAtLogin = v.target.checked}
|
||||
name="startup"
|
||||
/>
|
||||
}
|
||||
label="Automatically start Lens on login"
|
||||
value={preferences.openAtLogin}
|
||||
onChange={v => preferences.openAtLogin = v}
|
||||
/>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
@ -133,6 +133,7 @@
|
||||
font-weight: 600;
|
||||
font-size: 14px;
|
||||
color: var(--textColorDimmed);
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
28
src/renderer/components/switch/form-switcher.tsx
Normal file
28
src/renderer/components/switch/form-switcher.tsx
Normal file
@ -0,0 +1,28 @@
|
||||
import React from "react";
|
||||
import FormControlLabel, { FormControlLabelProps } from "@material-ui/core/FormControlLabel";
|
||||
import { makeStyles } from "@material-ui/styles";
|
||||
|
||||
const useStyles = makeStyles({
|
||||
root: {
|
||||
margin: 0,
|
||||
"& .MuiTypography-root": {
|
||||
fontSize: 14,
|
||||
fontWeight: 500,
|
||||
flex: 1,
|
||||
color: "var(--textColorAccent)"
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
export function FormSwitch(props: FormControlLabelProps) {
|
||||
const classes = useStyles();
|
||||
|
||||
return (
|
||||
<FormControlLabel
|
||||
control={props.control}
|
||||
labelPlacement="start"
|
||||
label={props.label}
|
||||
className={classes.root}
|
||||
/>
|
||||
);
|
||||
}
|
||||
2
src/renderer/components/switch/index.ts
Normal file
2
src/renderer/components/switch/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from "./switcher";
|
||||
export * from "./form-switcher";
|
||||
68
src/renderer/components/switch/switcher.tsx
Normal file
68
src/renderer/components/switch/switcher.tsx
Normal file
@ -0,0 +1,68 @@
|
||||
import React from "react";
|
||||
import { createStyles, withStyles, Theme } from "@material-ui/core/styles";
|
||||
import Switch, { SwitchClassKey, SwitchProps } from "@material-ui/core/Switch";
|
||||
|
||||
interface Styles extends Partial<Record<SwitchClassKey, string>> {
|
||||
focusVisible?: string;
|
||||
}
|
||||
|
||||
interface Props extends SwitchProps {
|
||||
classes: Styles;
|
||||
}
|
||||
|
||||
export const Switcher = withStyles((theme: Theme) =>
|
||||
createStyles({
|
||||
root: {
|
||||
width: 40,
|
||||
height: 24,
|
||||
padding: 0,
|
||||
margin: "0 0 0 8px",
|
||||
},
|
||||
switchBase: {
|
||||
padding: 1,
|
||||
paddingLeft: 4,
|
||||
"&$checked": {
|
||||
transform: "translateX(14px)",
|
||||
color: "white",
|
||||
"& + $track": {
|
||||
backgroundColor: "#52d869",
|
||||
opacity: 1,
|
||||
border: "none",
|
||||
},
|
||||
},
|
||||
"&$focusVisible $thumb": {
|
||||
color: "#52d869",
|
||||
border: "6px solid #fff",
|
||||
},
|
||||
},
|
||||
thumb: {
|
||||
width: 18,
|
||||
height: 18,
|
||||
marginTop: 2,
|
||||
boxShadow: "none"
|
||||
},
|
||||
track: {
|
||||
borderRadius: 26 / 2,
|
||||
backgroundColor: "#72767b",
|
||||
opacity: 1,
|
||||
transition: theme.transitions.create(["background-color", "border"]),
|
||||
},
|
||||
checked: {},
|
||||
focusVisible: {},
|
||||
}),
|
||||
)(({ classes, ...props }: Props) => {
|
||||
return (
|
||||
<Switch
|
||||
focusVisibleClassName={classes.focusVisible}
|
||||
disableRipple
|
||||
classes={{
|
||||
root: classes.root,
|
||||
switchBase: classes.switchBase,
|
||||
thumb: classes.thumb,
|
||||
track: classes.track,
|
||||
checked: classes.checked,
|
||||
}}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user