@@ -5,39 +5,56 @@ import {
5
5
type ForwardedRef ,
6
6
forwardRef ,
7
7
type ReactNode ,
8
+ useCallback ,
8
9
useLayoutEffect ,
9
10
useMemo ,
10
11
useRef ,
11
12
useState ,
12
13
} from 'react'
13
14
import { IntentLink } from 'sanity/router'
15
+ import { styled } from 'styled-components'
14
16
15
17
import { useTranslation } from '../../i18n/hooks/useTranslation'
16
18
import { RELEASES_INTENT } from '../../releases/plugin'
17
19
import { isReleaseDocument , type ReleaseDocument } from '../../releases/store/types'
18
20
import { getReleaseIdFromReleaseDocumentId } from '../../releases/util/getReleaseIdFromReleaseDocumentId'
19
21
import { isDraftPerspective , isPublishedPerspective } from '../../releases/util/util'
22
+ import { oversizedButtonStyle } from '../styles'
20
23
import { type SelectedPerspective } from '../types'
21
24
25
+ const OversizedButton = styled ( IntentLink ) `
26
+ ${ oversizedButtonStyle }
27
+ `
28
+
22
29
function AnimatedTextWidth ( { children, text} : { children : ReactNode ; text : string } ) {
23
30
const textRef = useRef < HTMLDivElement > ( null )
24
31
const [ containerWidth , setContainerWidth ] = useState < null | number > ( null ) // in pixels
32
+ const [ isAnimating , setIsAnimating ] = useState ( false )
25
33
26
34
useLayoutEffect ( ( ) => {
27
35
if ( ! textRef . current ) return
28
36
const newWidth = textRef . current . offsetWidth
29
37
setContainerWidth ( newWidth )
30
38
} , [ text ] )
31
39
40
+ const onAnimationStart = useCallback ( ( ) => {
41
+ setIsAnimating ( true )
42
+ } , [ ] )
43
+ const onAnimationComplete = useCallback ( ( ) => {
44
+ setIsAnimating ( false )
45
+ } , [ ] )
46
+
32
47
return (
33
48
< motion . div
34
49
style = { {
35
50
display : 'inline-block' ,
36
- overflow : 'hidden' ,
37
51
width : containerWidth === null ? 'auto' : containerWidth , // use auto on first render
52
+ overflow : isAnimating ? 'hidden' : 'visible' ,
38
53
} }
39
54
animate = { { width : containerWidth || 'auto' } }
40
55
transition = { { type : 'spring' , bounce : 0 , duration : 0.3 } }
56
+ onAnimationStart = { onAnimationStart }
57
+ onAnimationComplete = { onAnimationComplete }
41
58
>
42
59
< div ref = { textRef } style = { { display : 'inline-block' , whiteSpace : 'nowrap' } } >
43
60
{ children }
@@ -57,14 +74,14 @@ const ReleasesLink = ({selectedPerspective}: {selectedPerspective: ReleaseDocume
57
74
linkRef : ForwardedRef < HTMLAnchorElement > ,
58
75
) {
59
76
return (
60
- < IntentLink
77
+ < OversizedButton
61
78
{ ...intentProps }
62
79
ref = { linkRef }
63
80
intent = { RELEASES_INTENT }
64
81
params = { { id : getReleaseIdFromReleaseDocumentId ( selectedPerspective . _id ) } }
65
82
>
66
83
{ children }
67
- </ IntentLink >
84
+ </ OversizedButton >
68
85
)
69
86
} ) ,
70
87
[ selectedPerspective ] ,
@@ -76,10 +93,9 @@ const ReleasesLink = ({selectedPerspective}: {selectedPerspective: ReleaseDocume
76
93
data-as = "a"
77
94
rel = "noopener noreferrer"
78
95
mode = "bleed"
79
- padding = { 3 }
80
- className = "p-menu-btn small"
96
+ padding = { 2 }
81
97
radius = "full"
82
- style = { { maxWidth : '180px' , overflow : 'hidden' , textOverflow : 'ellipsis' } }
98
+ style = { { maxWidth : '180px' , textOverflow : 'ellipsis' } }
83
99
text = { selectedPerspective . metadata ?. title || t ( 'release.placeholder-untitled-release' ) }
84
100
/>
85
101
)
@@ -97,12 +113,7 @@ export function CurrentGlobalPerspectiveLabel({
97
113
text = { isReleaseDocument ( selectedPerspective ) ? selectedPerspective . _id : selectedPerspective }
98
114
>
99
115
{ isPublishedPerspective ( selectedPerspective ) || isDraftPerspective ( selectedPerspective ) ? (
100
- < Card
101
- tone = "inherit"
102
- padding = { 3 }
103
- className = "p-menu-btn"
104
- style = { { userSelect : 'none' , overflow : 'hidden' } }
105
- >
116
+ < Card tone = "inherit" padding = { 2 } style = { { userSelect : 'none' , overflow : 'hidden' } } >
106
117
< Text size = { 1 } textOverflow = "ellipsis" weight = "medium" >
107
118
{ isPublishedPerspective ( selectedPerspective )
108
119
? t ( 'release.chip.published' )
0 commit comments