JimmFly
2024-02-23 06:18:25 +00:00
parent c22216c71a
commit 4ea4a2d25f
13 changed files with 251 additions and 71 deletions
@@ -69,6 +69,8 @@ export const modalFooter = style({
export const confirmModalContent = style({
marginTop: '12px',
marginBottom: '20px',
height: '100%',
overflowY: 'auto',
});
export const confirmModalContainer = style({
display: 'flex',
@@ -43,3 +43,7 @@ export const switchCheckedStyle = style({
},
},
});
export const switchDisabledStyle = style({
cursor: 'not-allowed',
opacity: 0.5,
});
@@ -13,6 +13,7 @@ export type SwitchProps = Omit<HTMLAttributes<HTMLLabelElement>, 'onChange'> & {
checked?: boolean;
onChange?: (checked: boolean) => void;
children?: ReactNode;
disabled?: boolean;
};
export const Switch = ({
@@ -20,6 +21,7 @@ export const Switch = ({
onChange: onChangeProp,
children,
className,
disabled,
...otherProps
}: SwitchProps) => {
const [checkedState, setCheckedState] = useState(checkedProp);
@@ -27,11 +29,14 @@ export const Switch = ({
const checked = onChangeProp ? checkedProp : checkedState;
const onChange = useCallback(
(event: React.ChangeEvent<HTMLInputElement>) => {
if (disabled) {
return;
}
const newChecked = event.target.checked;
if (onChangeProp) onChangeProp(newChecked);
else setCheckedState(newChecked);
},
[onChangeProp]
[disabled, onChangeProp]
);
return (
@@ -47,6 +52,7 @@ export const Switch = ({
<span
className={clsx(styles.switchStyle, {
[styles.switchCheckedStyle]: checked,
[styles.switchDisabledStyle]: disabled,
})}
/>
</label>