MultipleCheckboxField.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import {Key} from 'react';
  2. import styled from '@emotion/styled';
  3. import space from 'sentry/styles/space';
  4. import CheckboxFancy from '../checkboxFancy/checkboxFancy';
  5. type CheckboxOption<T> = {
  6. title: string;
  7. value: T;
  8. checked?: boolean;
  9. disabled?: boolean;
  10. intermediate?: boolean;
  11. };
  12. type Props<T> = {
  13. choices: CheckboxOption<T>[];
  14. className?: string;
  15. onClick?(item: T);
  16. size?: string;
  17. };
  18. export default function MultipleCheckboxField<T extends Key>(props: Props<T>) {
  19. return (
  20. <div className={props.className}>
  21. {props.choices.map(option => (
  22. <CheckboxWrapper key={option.value.toString()}>
  23. <CheckboxFancy
  24. size={props.size}
  25. isDisabled={option.disabled}
  26. isChecked={option.checked}
  27. isIndeterminate={option.intermediate}
  28. onClick={() => {
  29. props.onClick?.(option.value);
  30. }}
  31. />
  32. <CheckboxText>{option.title}</CheckboxText>
  33. </CheckboxWrapper>
  34. ))}
  35. </div>
  36. );
  37. }
  38. const CheckboxWrapper = styled('div')`
  39. margin-bottom: ${space(2)};
  40. display: flex;
  41. flex-direction: row;
  42. align-items: center;
  43. `;
  44. const CheckboxText = styled('span')`
  45. margin-left: ${space(1)};
  46. `;