keyValueTable.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import {Fragment} from 'react';
  2. import {Theme} from '@emotion/react';
  3. import styled from '@emotion/styled';
  4. import {space} from 'sentry/styles/space';
  5. type Props = {
  6. keyName: React.ReactNode;
  7. value: React.ReactNode;
  8. type?: undefined | 'error' | 'warning';
  9. };
  10. export const KeyValueTable = styled('dl')<{noMargin?: boolean}>`
  11. display: grid;
  12. grid-template-columns: 50% 50%;
  13. ${p => (p.noMargin ? 'margin-bottom: 0;' : null)}
  14. `;
  15. export function KeyValueTableRow({keyName, value, type}: Props) {
  16. return (
  17. <Fragment>
  18. <Key type={type}>{keyName}</Key>
  19. <Value type={type}>{value}</Value>
  20. </Fragment>
  21. );
  22. }
  23. const commonStyles = ({theme, type}: {type: Props['type']} & {theme: Theme}) => `
  24. font-size: ${theme.fontSizeMedium};
  25. padding: ${space(0.5)} ${space(1)};
  26. font-weight: normal;
  27. line-height: inherit;
  28. ${p => p.theme.overflowEllipsis};
  29. background-color: ${
  30. type === 'error'
  31. ? theme.red100 + ' !important'
  32. : type === 'warning'
  33. ? 'var(--background-warning-default, rgba(245, 176, 0, 0.09)) !important'
  34. : 'inherit'
  35. };
  36. &:nth-of-type(2n-1) {
  37. background-color: ${theme.backgroundSecondary};
  38. }
  39. `;
  40. const Key = styled('dt')<{type: Props['type']}>`
  41. ${commonStyles};
  42. color: ${p => p.theme.textColor};
  43. `;
  44. const Value = styled('dd')<{type: Props['type']}>`
  45. ${commonStyles};
  46. color: ${p => p.theme.subText};
  47. text-align: right;
  48. `;