|
| 1 | +/* eslint-disable camelcase */ |
| 2 | +import {RemoveIcon} from '@sanity/icons' |
| 3 | +import {useTelemetry} from '@sanity/telemetry/react' |
| 4 | +import {Box, Card, Stack, Text} from '@sanity/ui' |
| 5 | +// eslint-disable-next-line camelcase |
| 6 | +import {getTheme_v2} from '@sanity/ui/theme' |
| 7 | +import {useEffect} from 'react' |
| 8 | +import {useTranslation} from 'sanity' |
| 9 | +import {css, keyframes, styled} from 'styled-components' |
| 10 | + |
| 11 | +import {Button, Popover} from '../../../ui-components' |
| 12 | +import {SANITY_VERSION} from '../../version' |
| 13 | +import {ProductAnnouncementCardSeen} from './__telemetry__/studioAnnouncements.telemetry' |
| 14 | + |
| 15 | +const keyframe = keyframes` |
| 16 | + 0% { |
| 17 | + background-position: 100%; |
| 18 | + } |
| 19 | + 100% { |
| 20 | + background-position: -100%; |
| 21 | + } |
| 22 | +` |
| 23 | + |
| 24 | +const Root = styled.div((props) => { |
| 25 | + const theme = getTheme_v2(props.theme) |
| 26 | + const cardHoverBg = theme.color.selectable.default.hovered.bg |
| 27 | + const cardNormalBg = theme.color.selectable.default.enabled.bg |
| 28 | + |
| 29 | + return css` |
| 30 | + position: relative; |
| 31 | + cursor: pointer; |
| 32 | + // hide the close button |
| 33 | + #close-floating-button { |
| 34 | + opacity: 0; |
| 35 | + transition: opacity 0.2s; |
| 36 | + } |
| 37 | +
|
| 38 | + &:hover { |
| 39 | + > [data-ui='whats-new-card'] { |
| 40 | + --card-bg-color: ${cardHoverBg}; |
| 41 | + box-shadow: inset 0 0 2px 1px var(--card-skeleton-color-to); |
| 42 | + background-image: linear-gradient( |
| 43 | + to right, |
| 44 | + var(--card-bg-color), |
| 45 | + var(--card-bg-color), |
| 46 | + ${cardNormalBg}, |
| 47 | + var(--card-bg-color), |
| 48 | + var(--card-bg-color), |
| 49 | + var(--card-bg-color) |
| 50 | + ); |
| 51 | + background-position: 100%; |
| 52 | + background-size: 200% 100%; |
| 53 | + background-attachment: fixed; |
| 54 | + animation-name: ${keyframe}; |
| 55 | + animation-timing-function: ease-in; |
| 56 | + animation-iteration-count: infinite; |
| 57 | + animation-duration: 2000ms; |
| 58 | + } |
| 59 | + #close-floating-button { |
| 60 | + opacity: 1; |
| 61 | + background: transparent; |
| 62 | +
|
| 63 | + &:hover { |
| 64 | + transition: all 0.2s; |
| 65 | + box-shadow: 0 0 0 1px ${theme.color.selectable.default.hovered.border}; |
| 66 | + } |
| 67 | + } |
| 68 | + } |
| 69 | + ` |
| 70 | +}) |
| 71 | + |
| 72 | +const ButtonRoot = styled.div` |
| 73 | + z-index: 1; |
| 74 | + position: absolute; |
| 75 | + top: 4px; |
| 76 | + right: 6px; |
| 77 | +` |
| 78 | + |
| 79 | +interface StudioAnnouncementCardProps { |
| 80 | + title: string |
| 81 | + id: string |
| 82 | + name: string |
| 83 | + isOpen: boolean |
| 84 | + preHeader: string |
| 85 | + onCardClick: () => void |
| 86 | + onCardDismiss: () => void |
| 87 | +} |
| 88 | + |
| 89 | +/** |
| 90 | + * @internal |
| 91 | + * @hidden |
| 92 | + */ |
| 93 | +export function StudioAnnouncementsCard({ |
| 94 | + title, |
| 95 | + id, |
| 96 | + isOpen, |
| 97 | + name, |
| 98 | + preHeader, |
| 99 | + onCardClick, |
| 100 | + onCardDismiss, |
| 101 | +}: StudioAnnouncementCardProps) { |
| 102 | + const {t} = useTranslation() |
| 103 | + const telemetry = useTelemetry() |
| 104 | + |
| 105 | + useEffect(() => { |
| 106 | + if (isOpen) { |
| 107 | + telemetry.log(ProductAnnouncementCardSeen, { |
| 108 | + announcement_id: id, |
| 109 | + announcement_title: title, |
| 110 | + announcement_internal_name: name, |
| 111 | + source: 'studio', |
| 112 | + studio_version: SANITY_VERSION, |
| 113 | + }) |
| 114 | + } |
| 115 | + }, [telemetry, id, title, isOpen, name]) |
| 116 | + |
| 117 | + return ( |
| 118 | + <Popover |
| 119 | + open={isOpen} |
| 120 | + shadow={3} |
| 121 | + portal |
| 122 | + style={{ |
| 123 | + bottom: 12, |
| 124 | + left: 12, |
| 125 | + top: 'none', |
| 126 | + }} |
| 127 | + width={0} |
| 128 | + placement="bottom-start" |
| 129 | + content={ |
| 130 | + <Root data-ui="whats-new-root"> |
| 131 | + <Card |
| 132 | + data-ui="whats-new-card" |
| 133 | + padding={3} |
| 134 | + radius={3} |
| 135 | + onClick={onCardClick} |
| 136 | + role="button" |
| 137 | + aria-label={t('announcement.floating-button.open-label')} |
| 138 | + > |
| 139 | + <Stack space={3}> |
| 140 | + <Box marginRight={6}> |
| 141 | + <Text as={'h3'} size={1} muted> |
| 142 | + {preHeader} |
| 143 | + </Text> |
| 144 | + </Box> |
| 145 | + <Text size={1} weight="medium"> |
| 146 | + {title} |
| 147 | + </Text> |
| 148 | + </Stack> |
| 149 | + </Card> |
| 150 | + <ButtonRoot> |
| 151 | + <Button |
| 152 | + id="close-floating-button" |
| 153 | + mode="bleed" |
| 154 | + onClick={onCardDismiss} |
| 155 | + icon={RemoveIcon} |
| 156 | + tone="default" |
| 157 | + aria-label={t('announcement.floating-button.dismiss-label')} |
| 158 | + tooltipProps={{ |
| 159 | + content: t('announcement.floating-button.dismiss'), |
| 160 | + }} |
| 161 | + /> |
| 162 | + </ButtonRoot> |
| 163 | + </Root> |
| 164 | + } |
| 165 | + /> |
| 166 | + ) |
| 167 | +} |
0 commit comments