Add custon onChange event with checked prop

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev committed 2021-12-29 15:56:50 +03:00
1 parent 8a02c5c0e0
commit d8f6ae4fa9
1 file changed
+5 -4
+5 -4
View File
@@ -21,17 +21,18 @@
import styles from "./switch.module.scss";
import React from "react";
import React, { ChangeEvent, HTMLProps } from "react";
import { cssNames } from "../../utils";
interface Props extends React.HTMLProps<HTMLInputElement> {
interface Props extends Omit<HTMLProps<HTMLInputElement>, "onChange"> {
onChange?: (checked: boolean, event: ChangeEvent<HTMLInputElement>) => void;
}
export function Switch({ children, disabled, ...props }: Props) {
export function Switch({ children, disabled, onChange, ...props }: Props) {
return (
<label className={cssNames(styles.Switch, { [styles.disabled]: disabled })} data-testid="switch">
{children}
<input type="checkbox" role="switch" disabled={disabled} {...props}/>
<input type="checkbox" role="switch" disabled={disabled} onChange={(event) => onChange(props.checked, event)} {...props}/>
</label>
);
}