github.com/freiheit-com/kuberpult@v1.24.2-0.20240328135542-315d5630abe6/services/frontend-service/src/ui/components/dropdown/checkbox.tsx (about)

     1  /*This file is part of kuberpult.
     2  
     3  Kuberpult is free software: you can redistribute it and/or modify
     4  it under the terms of the Expat(MIT) License as published by
     5  the Free Software Foundation.
     6  
     7  Kuberpult is distributed in the hope that it will be useful,
     8  but WITHOUT ANY WARRANTY; without even the implied warranty of
     9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    10  MIT License for more details.
    11  
    12  You should have received a copy of the MIT License
    13  along with kuberpult. If not, see <https://directory.fsf.org/wiki/License:Expat>.
    14  
    15  Copyright 2023 freiheit.com*/
    16  
    17  import * as React from 'react';
    18  import { Button } from '../button';
    19  import { useCallback } from 'react';
    20  
    21  export type CheckboxProps = {
    22      onClick?: (id: string) => void;
    23      classes?: string;
    24      id: string;
    25      enabled: boolean;
    26      label: string;
    27  };
    28  
    29  export const Checkbox: React.FC<CheckboxProps> = (props) => {
    30      const onClick = useCallback(() => {
    31          if (props.onClick) {
    32              props.onClick(props.id);
    33          }
    34      }, [props]);
    35      return (
    36          <label>
    37              <div className={'checkbox-wrapper'}>
    38                  <Button
    39                      onClick={onClick}
    40                      className={'test-button-checkbox id-' + props.id + ' ' + (props.enabled ? 'enabled' : 'disabled')}
    41                      label={props.enabled ? '☑' : '☐'}
    42                  />
    43                  {props.label}
    44              </div>
    45          </label>
    46      );
    47  };