DetailsField.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { css, cx } from '@emotion/css';
  2. import React, { FC } from 'react';
  3. import { GrafanaTheme2 } from '@grafana/data';
  4. import { useStyles2 } from '@grafana/ui';
  5. interface Props {
  6. label: React.ReactNode;
  7. className?: string;
  8. horizontal?: boolean;
  9. }
  10. export const DetailsField: FC<Props> = ({ className, label, horizontal, children }) => {
  11. const styles = useStyles2(getStyles);
  12. return (
  13. <div className={cx(className, styles.field, horizontal ? styles.fieldHorizontal : styles.fieldVertical)}>
  14. <div>{label}</div>
  15. <div>{children}</div>
  16. </div>
  17. );
  18. };
  19. const getStyles = (theme: GrafanaTheme2) => ({
  20. fieldHorizontal: css`
  21. flex-direction: row;
  22. ${theme.breakpoints.down('md')} {
  23. flex-direction: column;
  24. }
  25. `,
  26. fieldVertical: css`
  27. flex-direction: column;
  28. `,
  29. field: css`
  30. display: flex;
  31. margin: ${theme.spacing(2)} 0;
  32. & > div:first-child {
  33. width: 110px;
  34. padding-right: ${theme.spacing(1)};
  35. font-size: ${theme.typography.size.sm};
  36. font-weight: ${theme.typography.fontWeightBold};
  37. line-height: 1.8;
  38. }
  39. & > div:nth-child(2) {
  40. flex: 1;
  41. color: ${theme.colors.text.secondary};
  42. }
  43. `,
  44. });