Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui v2: switches #763

Merged
merged 2 commits into from
Dec 15, 2020
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
28 changes: 28 additions & 0 deletions frontend/packages/core/src/Input/stories/toggle.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as React from "react";
import type { Meta } from "@storybook/react";

import type { SwitchProps } from "../toggle";
import { Switch } from "../toggle";

export default {
title: "Core/Input/Switch",
component: Switch,
name: "Switch",
argTypes: {
onChange: { action: "onChange event" },
},
} as Meta;

const Template = (props: SwitchProps) => <Switch {...props} />;

export const Primary = Template.bind({});

export const Checked = Template.bind({});
Checked.args = {
checked: true,
};

export const Disabled = Template.bind({});
Disabled.args = {
disabled: true,
};
70 changes: 70 additions & 0 deletions frontend/packages/core/src/Input/toggle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import * as React from "react";
import styled from "@emotion/styled";
import type { SwitchProps as MuiSwitchProps } from "@material-ui/core";
import { Switch as MuiSwitch } from "@material-ui/core";

const SwitchContainer = styled(MuiSwitch)({
".MuiSwitch-switchBase": {
":hover": {
backgroundColor: "rgba(13, 16, 48, 0.1)",
},
":focus": {
backgroundColor: "rgba(13, 16, 48, 0.12)",
},
":active": {
backgroundColor: "rgba(13, 16, 48, 0.15)",
},
".MuiSwitch-thumb": {
boxShadow: "0px 1px 1px rgba(0, 0, 0, 0.25)",
color: "#FFFFFF",
},
},
".MuiSwitch-track": {
backgroundColor: "#6E7083",
opacity: 1,
},
".Mui-disabled": {
".MuiSwitch-thumb": {
color: "rgba(248, 248, 249, 1)",
}
},
".Mui-disabled + .MuiSwitch-track": {
backgroundColor: "#E7E7EA",
opacity: 1,
},
".Mui-checked": {
":hover": {
backgroundColor: "rgba(53, 72, 212, 0.05)",
},
":focus": {
backgroundColor: "rgba(53, 72, 212, 0.1)",
},
":active": {
backgroundColor: "rgba(53, 72, 212, 0.2)",
},
".MuiSwitch-thumb": {
color: "#3548D4",
},
},
".Mui-checked + .MuiSwitch-track": {
backgroundColor: "#C2C8F2",
opacity: 1,
},
".Mui-checked.Mui-disabled": {
".MuiSwitch-thumb": {
color: "#E7E7EA",
},
},
".Mui-checked.Mui-disabled + .MuiSwitch-track": {
backgroundColor: "#A3A4B0",
opacity: 1,
},
});

export interface SwitchProps extends Pick<MuiSwitchProps, "checked" | "disabled" | "onChange"> {};

export const Switch = ({...props}: SwitchProps) => (
<SwitchContainer color="default" {...props} />
);

export default Switch;