overlay.stories.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import {useTheme} from '@emotion/react';
  2. import styled from '@emotion/styled';
  3. import {FocusScope} from '@react-aria/focus';
  4. import {AnimatePresence} from 'framer-motion';
  5. import DropdownButton from 'sentry/components/dropdownButton';
  6. import {Overlay, PositionWrapper} from 'sentry/components/overlay';
  7. import space from 'sentry/styles/space';
  8. import useOverlay from 'sentry/utils/useOverlay';
  9. export default {
  10. title: 'Components/Buttons/Dropdowns/Overlay',
  11. args: {
  12. offset: 8,
  13. position: 'bottom',
  14. animated: true,
  15. },
  16. argTypes: {
  17. position: {
  18. options: [
  19. 'top',
  20. 'bottom',
  21. 'left',
  22. 'right',
  23. 'top-start',
  24. 'top-end',
  25. 'bottom-start',
  26. 'bottom-end',
  27. 'left-start',
  28. 'left-end',
  29. 'right-start',
  30. 'right-end',
  31. ],
  32. control: {type: 'radio'},
  33. },
  34. },
  35. };
  36. export const _Overlay = ({animated, ...args}) => {
  37. const {isOpen, triggerProps, overlayProps, arrowProps} = useOverlay(args);
  38. const theme = useTheme();
  39. return (
  40. <div>
  41. <DropdownButton {...triggerProps}>Show Overlay</DropdownButton>
  42. <AnimatePresence>
  43. {isOpen && (
  44. <FocusScope contain restoreFocus autoFocus>
  45. <PositionWrapper zIndex={theme.zIndex.dropdown} {...overlayProps}>
  46. <StyledOverlay arrowProps={arrowProps} animated={animated}>
  47. <TextSample>Overlay Content</TextSample>
  48. </StyledOverlay>
  49. </PositionWrapper>
  50. </FocusScope>
  51. )}
  52. </AnimatePresence>
  53. </div>
  54. );
  55. };
  56. const StyledOverlay = styled(Overlay)`
  57. padding: ${space(1)} ${space(1.5)};
  58. `;
  59. const TextSample = styled('p')`
  60. margin: 0;
  61. color: ${p => p.theme.subText};
  62. `;