|
| 1 | +import { useEffect } from 'react' |
| 2 | +import { useRouter } from 'next/router' |
| 3 | +import { animated, useSpring } from '@react-spring/web' |
| 4 | +import styled from 'styled-components' |
| 5 | + |
| 6 | +export const FeedbackPopover = () => { |
| 7 | + const { pathname } = useRouter() |
| 8 | + |
| 9 | + const [styles, api] = useSpring(() => ({ |
| 10 | + from: { |
| 11 | + y: '110%', |
| 12 | + }, |
| 13 | + })) |
| 14 | + |
| 15 | + useEffect(() => { |
| 16 | + api.start({ |
| 17 | + to: { |
| 18 | + y: '0', |
| 19 | + }, |
| 20 | + delay: 800, |
| 21 | + }) |
| 22 | + }, [pathname]) |
| 23 | + |
| 24 | + const handleClose = () => |
| 25 | + api.start({ |
| 26 | + to: { |
| 27 | + y: '110%', |
| 28 | + }, |
| 29 | + }) |
| 30 | + |
| 31 | + return ( |
| 32 | + <Popover style={styles}> |
| 33 | + <PopoverContent> |
| 34 | + <PopoverCloseButton aria-label="Close popover" onClick={handleClose}> |
| 35 | + <svg |
| 36 | + width="15" |
| 37 | + height="15" |
| 38 | + viewBox="0 0 15 15" |
| 39 | + fill="none" |
| 40 | + xmlns="http://www.w3.org/2000/svg"> |
| 41 | + <path |
| 42 | + d="M11.7816 4.03157C12.0062 3.80702 12.0062 3.44295 11.7816 3.2184C11.5571 2.99385 11.193 2.99385 10.9685 3.2184L7.50005 6.68682L4.03164 3.2184C3.80708 2.99385 3.44301 2.99385 3.21846 3.2184C2.99391 3.44295 2.99391 3.80702 3.21846 4.03157L6.68688 7.49999L3.21846 10.9684C2.99391 11.193 2.99391 11.557 3.21846 11.7816C3.44301 12.0061 3.80708 12.0061 4.03164 11.7816L7.50005 8.31316L10.9685 11.7816C11.193 12.0061 11.5571 12.0061 11.7816 11.7816C12.0062 11.557 12.0062 11.193 11.7816 10.9684L8.31322 7.49999L11.7816 4.03157Z" |
| 43 | + fill="currentColor" |
| 44 | + fill-rule="evenodd" |
| 45 | + clip-rule="evenodd"></path> |
| 46 | + </svg> |
| 47 | + </PopoverCloseButton> |
| 48 | + <PopoverTitle>Struggling to find what you want?</PopoverTitle> |
| 49 | + <PopoverCopy> |
| 50 | + {`We're interested in hearing your feedback for our documentation! Have your voice heard by commenting in this `} |
| 51 | + <a href="https://github.com/pmndrs/react-spring/issues/1799">issue</a> |
| 52 | + </PopoverCopy> |
| 53 | + </PopoverContent> |
| 54 | + </Popover> |
| 55 | + ) |
| 56 | +} |
| 57 | + |
| 58 | +const Popover = styled(animated.div)` |
| 59 | + position: fixed; |
| 60 | + bottom: 0; |
| 61 | + right: 12px; |
| 62 | + padding: 24px 32px 32px; |
| 63 | + border-top-right-radius: 8px; |
| 64 | + border-top-left-radius: 8px; |
| 65 | + background: ${props => props.theme.colors.steel}; |
| 66 | + color: ${props => props.theme.colors.white}; |
| 67 | + width: 360px; |
| 68 | + box-shadow: 0px -2px 15px 2px rgba(0, 0, 0, 0.5); |
| 69 | +` |
| 70 | + |
| 71 | +const PopoverContent = styled.div` |
| 72 | + position: relative; |
| 73 | + padding-top: 12px; |
| 74 | +` |
| 75 | + |
| 76 | +const PopoverTitle = styled.h2` |
| 77 | + font-size: ${props => props.theme.fontSizes['XS']}; |
| 78 | + font-weight: 500; |
| 79 | + margin-bottom: 12px; |
| 80 | + letter-spacing: 0.02em; |
| 81 | +` |
| 82 | + |
| 83 | +const PopoverCopy = styled.p` |
| 84 | + font-size: ${props => props.theme.fontSizes['XS']}; |
| 85 | + line-height: ${props => props.theme.lineHeights['XS']}; |
| 86 | + letter-spacing: 0.02em; |
| 87 | +
|
| 88 | + & > a { |
| 89 | + font-weight: 500; |
| 90 | + text-decoration: ${props => `underline ${props.theme.colors.red}`}; |
| 91 | + } |
| 92 | +
|
| 93 | + & > a:visited { |
| 94 | + color: inherit; |
| 95 | + } |
| 96 | +` |
| 97 | + |
| 98 | +const PopoverCloseButton = styled.button` |
| 99 | + color: ${props => props.theme.colors.white}; |
| 100 | + border: none; |
| 101 | + background: transparent; |
| 102 | + cursor: pointer; |
| 103 | + display: flex; |
| 104 | + justify-content: center; |
| 105 | + align-items: center; |
| 106 | + padding: 0; |
| 107 | + margin: 0; |
| 108 | + height: 40px; |
| 109 | + width: 40px; |
| 110 | + position: absolute; |
| 111 | + right: -18px; |
| 112 | + top: -16px; |
| 113 | +` |
0 commit comments