keyValueTable.tsx 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. };
  9. export const KeyValueTable = styled('dl')<{noMargin?: boolean}>`
  10. display: grid;
  11. grid-template-columns: 50% 50%;
  12. ${p => (p.noMargin ? 'margin-bottom: 0;' : null)}
  13. `;
  14. export function KeyValueTableRow({keyName, value}: Props) {
  15. return (
  16. <Fragment>
  17. <Key>{keyName}</Key>
  18. <Value>{value}</Value>
  19. </Fragment>
  20. );
  21. }
  22. const commonStyles = ({theme}: {theme: Theme}) => `
  23. font-size: ${theme.fontSizeMedium};
  24. padding: ${space(0.5)} ${space(1)};
  25. font-weight: normal;
  26. line-height: inherit;
  27. ${p => p.theme.overflowEllipsis};
  28. &:nth-of-type(2n-1) {
  29. background-color: ${theme.backgroundSecondary};
  30. }
  31. `;
  32. const Key = styled('dt')`
  33. ${commonStyles};
  34. color: ${p => p.theme.textColor};
  35. `;
  36. const Value = styled('dd')`
  37. ${commonStyles};
  38. color: ${p => p.theme.subText};
  39. text-align: right;
  40. `;