autofixShowMore.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import {type ReactNode, useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import {Button} from 'sentry/components/button';
  4. import InteractionStateLayer from 'sentry/components/interactionStateLayer';
  5. import {IconChevron} from 'sentry/icons';
  6. import {t} from 'sentry/locale';
  7. import {space} from 'sentry/styles/space';
  8. type AutofixShowMore = {
  9. children: ReactNode;
  10. title: ReactNode;
  11. };
  12. export function AutofixShowMore({children, title}: AutofixShowMore) {
  13. const [isExpanded, setIsExpanded] = useState(false);
  14. return (
  15. <Wrapper>
  16. <Header onClick={() => setIsExpanded(value => !value)}>
  17. <InteractionStateLayer />
  18. <Title>{title}</Title>
  19. <Button
  20. icon={<IconChevron size="xs" direction={isExpanded ? 'up' : 'down'} />}
  21. aria-label={t('Toggle details')}
  22. aria-expanded={isExpanded}
  23. size="zero"
  24. borderless
  25. />
  26. </Header>
  27. {isExpanded ? <Content>{children}</Content> : null}
  28. </Wrapper>
  29. );
  30. }
  31. const Wrapper = styled('div')`
  32. border-top: 1px solid ${p => p.theme.border};
  33. margin-top: ${space(1.5)};
  34. `;
  35. const Title = styled('div')`
  36. font-weight: ${p => p.theme.fontWeightBold};
  37. `;
  38. const Header = styled('div')`
  39. position: relative;
  40. display: grid;
  41. grid-template-columns: 1fr auto;
  42. padding: ${space(1)} ${space(2)};
  43. cursor: pointer;
  44. user-select: none;
  45. `;
  46. const Content = styled('div')`
  47. margin-top: ${space(1)};
  48. `;