Skip to content

Commit 777bcae

Browse files
committed
feat: switch
1 parent e18d0cb commit 777bcae

5 files changed

Lines changed: 68 additions & 1 deletion

File tree

package-lock.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"prop-types": "^15.7.2",
7474
"react-modal": "^3.10.1",
7575
"react-select": "^3.0.8",
76+
"react-switch": "^4.0.1",
7677
"typestyle": "^2.0.4"
7778
},
7879
"peerDependencies": {

src/components/formParts/Select.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {Select} from "./Select";
44
export default {
55
component: Select,
66
title: "Select"
7-
}
7+
};
88

99
export const Simple = () => (
1010
<Select
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import * as React from "react";
2+
import {withInitialState} from "../../helpers/withInitialState";
3+
import {Switch} from "./Switch";
4+
5+
export default {
6+
component: Switch,
7+
title: "Switch"
8+
};
9+
10+
export const Simple = ({state, setState}) => (
11+
<Switch
12+
checked={state.checked}
13+
onChange={(checked) => setState({checked})}
14+
/>
15+
);
16+
Simple.story = {
17+
decorators: [withInitialState({checked: false})]
18+
};
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import {Color} from "@crazyfactory/frontend-commons";
2+
import * as React from "react";
3+
const ReactSwitch = require("react-switch");
4+
5+
interface IProps {
6+
checked: boolean;
7+
labelClassName?: string;
8+
labelStyle?: React.CSSProperties;
9+
height?: number;
10+
onChange: (checked: boolean) => void;
11+
switchClassName?: string;
12+
switchStyle?: React.CSSProperties;
13+
width?: number;
14+
}
15+
16+
export class Switch extends React.Component<IProps> {
17+
public static defaultProps: Partial<IProps> = {
18+
height: 20,
19+
width: 48
20+
};
21+
22+
public render(): JSX.Element {
23+
const {labelClassName, labelStyle, ...rest} = this.props;
24+
return (
25+
<label className={labelClassName} style={labelStyle}>
26+
<ReactSwitch
27+
onColor={Color.LIGHT_BLUE}
28+
onHandleColor={Color.BLUE}
29+
handleDiameter={30}
30+
uncheckedIcon={false}
31+
checkedIcon={false}
32+
boxShadow="0px 1px 5px rgba(0, 0, 0, 0.6)"
33+
activeBoxShadow="0px 0px 1px 10px rgba(0, 0, 0, 0.2)"
34+
className="react-switch"
35+
{...rest}
36+
/>
37+
</label>
38+
);
39+
}
40+
}

0 commit comments

Comments
 (0)