|
| 1 | +import { InputTypes } from "../constants/input-types"; |
| 2 | +import React from "react"; |
| 3 | + |
| 4 | +// ----------------------------------------------------------------------------------------- |
| 5 | +// #region Interfaces |
| 6 | +// ----------------------------------------------------------------------------------------- |
| 7 | + |
| 8 | +export interface CheckboxInputProperties { |
| 9 | + checked: boolean; |
| 10 | + disabled?: boolean; |
| 11 | + label: string; |
| 12 | + onChange: (e: React.ChangeEvent<HTMLInputElement>) => void; |
| 13 | +} |
| 14 | + |
| 15 | +// #endregion Interfaces |
| 16 | + |
| 17 | +// ----------------------------------------------------------------------------------------- |
| 18 | +// #region Constants |
| 19 | +// ----------------------------------------------------------------------------------------- |
| 20 | + |
| 21 | +const BASE_CLASS_NAME = "e-checkbox"; |
| 22 | + |
| 23 | +// #endregion Constants |
| 24 | + |
| 25 | +// ----------------------------------------------------------------------------------------- |
| 26 | +// #region Component |
| 27 | +// ----------------------------------------------------------------------------------------- |
| 28 | + |
| 29 | +const CheckboxInput: React.FC<CheckboxInputProperties> = ( |
| 30 | + props: CheckboxInputProperties |
| 31 | +) => { |
| 32 | + const { checked, disabled, label, onChange } = props; |
| 33 | + let className = BASE_CLASS_NAME; |
| 34 | + if (disabled) { |
| 35 | + className += " -disabled"; |
| 36 | + } |
| 37 | + |
| 38 | + return ( |
| 39 | + <label className={className}> |
| 40 | + {label} |
| 41 | + <input |
| 42 | + checked={checked} |
| 43 | + disabled={disabled} |
| 44 | + onChange={onChange} |
| 45 | + type={InputTypes.Checkbox} |
| 46 | + value={checked.toString()} |
| 47 | + /> |
| 48 | + <span className={`${BASE_CLASS_NAME}__checkmark`}></span> |
| 49 | + </label> |
| 50 | + ); |
| 51 | +}; |
| 52 | + |
| 53 | +// #endregion Component |
| 54 | + |
| 55 | +// ----------------------------------------------------------------------------------------- |
| 56 | +// #region Export |
| 57 | +// ----------------------------------------------------------------------------------------- |
| 58 | + |
| 59 | +export { CheckboxInput }; |
| 60 | + |
| 61 | +// #endregion Export |
0 commit comments