mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add custon onChange event with checked prop
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
8a02c5c0e0
commit
d8f6ae4fa9
@ -21,17 +21,18 @@
|
|||||||
|
|
||||||
import styles from "./switch.module.scss";
|
import styles from "./switch.module.scss";
|
||||||
|
|
||||||
import React from "react";
|
import React, { ChangeEvent, HTMLProps } from "react";
|
||||||
import { cssNames } from "../../utils";
|
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 (
|
return (
|
||||||
<label className={cssNames(styles.Switch, { [styles.disabled]: disabled })} data-testid="switch">
|
<label className={cssNames(styles.Switch, { [styles.disabled]: disabled })} data-testid="switch">
|
||||||
{children}
|
{children}
|
||||||
<input type="checkbox" role="switch" disabled={disabled} {...props}/>
|
<input type="checkbox" role="switch" disabled={disabled} onChange={(event) => onChange(props.checked, event)} {...props}/>
|
||||||
</label>
|
</label>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user