detailLabel.tsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import {Fragment} from 'react';
  2. import {css} from '@emotion/react';
  3. import styled from '@emotion/styled';
  4. import {Tag} from 'sentry/components/core/badge/tag';
  5. import {space} from 'sentry/styles/space';
  6. type Props = {
  7. /**
  8. * The left-hand aligned label
  9. */
  10. title: React.ReactNode;
  11. children?: React.ReactNode;
  12. /**
  13. * Display the value with display: flex with a gap
  14. */
  15. multiLine?: boolean;
  16. /**
  17. * Pass a boolean to render 'yes' or 'no' as the child for true / false
  18. */
  19. yesNo?: boolean;
  20. };
  21. /**
  22. * Detail label is used within DetailList
  23. */
  24. function DetailLabel({title, yesNo, multiLine, children}: Props) {
  25. return (
  26. <Fragment>
  27. <dt>{title}:</dt>
  28. <Value multiLine={!!multiLine}>
  29. {yesNo !== undefined &&
  30. (yesNo ? <Tag type="success">yes</Tag> : <Tag type="error">no</Tag>)}
  31. {children}
  32. </Value>
  33. </Fragment>
  34. );
  35. }
  36. const Value = styled('dd')<{multiLine: boolean}>`
  37. ${p =>
  38. p.multiLine &&
  39. css`
  40. display: flex;
  41. flex-direction: column;
  42. gap: ${space(0.5)};
  43. `};
  44. `;
  45. export default DetailLabel;