import { ChangeEvent } from 'react'; import React, { FC, memo, useCallback } from '../../lib/teact/teact'; import buildClassName from '../../util/buildClassName'; import useLang from '../../hooks/useLang'; import renderText from '../common/helpers/renderText'; import Spinner from './Spinner'; import './Checkbox.scss'; type OwnProps = { id?: string; name?: string; value?: string; label: string; subLabel?: string; checked: boolean; disabled?: boolean; round?: boolean; blocking?: boolean; isLoading?: boolean; withCheckedCallback?: boolean; onChange?: (e: ChangeEvent) => void; onCheck?: (isChecked: boolean) => void; }; const Checkbox: FC = ({ id, name, value, label, subLabel, checked, disabled, round, blocking, isLoading, onChange, onCheck, }) => { const lang = useLang(); const handleChange = useCallback((event: ChangeEvent) => { if (onChange) { onChange(event); } if (onCheck) { onCheck(event.currentTarget.checked); } }, [onChange, onCheck]); const className = buildClassName( 'Checkbox', disabled && 'disabled', round && 'round', isLoading && 'loading', blocking && 'blocking', ); return ( ); }; export default memo(Checkbox);