HorizontalGroup.tsx 833 B

123456789101112131415161718192021222324252627282930313233
  1. import { css, cx } from '@emotion/css';
  2. import React from 'react';
  3. import { GrafanaTheme2 } from '@grafana/data';
  4. import { useTheme2 } from '@grafana/ui';
  5. interface HorizontalGroupProps {
  6. children: React.ReactNode;
  7. wrap?: boolean;
  8. className?: string;
  9. }
  10. export const HorizontalGroup = ({ children, wrap, className }: HorizontalGroupProps) => {
  11. const theme = useTheme2();
  12. const styles = getStyles(theme, wrap);
  13. return <div className={cx(styles.container, className)}>{children}</div>;
  14. };
  15. const getStyles = (theme: GrafanaTheme2, wrap?: boolean) => ({
  16. container: css`
  17. display: flex;
  18. flex-direction: row;
  19. flex-wrap: ${wrap ? 'wrap' : 'no-wrap'};
  20. & > * {
  21. margin-bottom: ${theme.spacing()};
  22. margin-right: ${theme.spacing()};
  23. }
  24. & > *:last-child {
  25. margin-right: 0;
  26. }
  27. `,
  28. });