Skip to content

Commit 6ef4bfe

Browse files
authoredMar 14, 2025··
fix(structure): some touches to version chips (#8933)
1 parent 7fe26cb commit 6ef4bfe

File tree

2 files changed

+35
-58
lines changed

2 files changed

+35
-58
lines changed
 

‎packages/sanity/src/core/releases/components/ReleaseAvatar.tsx

+14-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@ import {DotIcon} from '@sanity/icons'
22
import {type BadgeTone, Box, Text} from '@sanity/ui'
33
import {type CSSProperties} from 'react'
44

5+
export const ReleaseAvatarIcon = ({tone}: {tone: BadgeTone}) => {
6+
return (
7+
<DotIcon
8+
data-testid={`release-avatar-${tone}`}
9+
style={
10+
{
11+
'--card-icon-color': `var(--card-badge-${tone}-icon-color)`,
12+
} as CSSProperties
13+
}
14+
/>
15+
)
16+
}
17+
518
/** @internal */
619
export function ReleaseAvatar({
720
fontSize = 1,
@@ -15,14 +28,7 @@ export function ReleaseAvatar({
1528
return (
1629
<Box flex="none" padding={padding} style={{borderRadius: 3}}>
1730
<Text size={fontSize}>
18-
<DotIcon
19-
data-testid={`release-avatar-${tone}`}
20-
style={
21-
{
22-
'--card-icon-color': `var(--card-badge-${tone}-icon-color)`,
23-
} as CSSProperties
24-
}
25-
/>
31+
<ReleaseAvatarIcon tone={tone} />
2632
</Text>
2733
</Box>
2834
)

‎packages/sanity/src/core/releases/components/documentHeader/VersionChip.tsx

+21-50
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
import {LockIcon} from '@sanity/icons'
22
import {
33
type BadgeTone,
4-
Box,
54
Button, // eslint-disable-line no-restricted-imports
6-
Flex,
7-
Text,
85
useClickOutsideEvent,
96
useGlobalKeyDown,
107
useToast,
118
} from '@sanity/ui'
12-
// eslint-disable-next-line camelcase
139
import {
1410
memo,
1511
type MouseEvent,
@@ -20,7 +16,7 @@ import {
2016
useRef,
2117
useState,
2218
} from 'react'
23-
import {css, styled} from 'styled-components'
19+
import {styled} from 'styled-components'
2420

2521
import {Popover, Tooltip} from '../../../../ui-components'
2622
import {useTranslation} from '../../../i18n/hooks/useTranslation'
@@ -30,37 +26,21 @@ import {useVersionOperations} from '../../hooks/useVersionOperations'
3026
import {type ReleaseDocument, type ReleaseState} from '../../store/types'
3127
import {getReleaseIdFromReleaseDocumentId} from '../../util/getReleaseIdFromReleaseDocumentId'
3228
import {DiscardVersionDialog} from '../dialog/DiscardVersionDialog'
33-
import {ReleaseAvatar} from '../ReleaseAvatar'
29+
import {ReleaseAvatarIcon} from '../ReleaseAvatar'
3430
import {VersionContextMenu} from './contextMenu/VersionContextMenu'
3531
import {CopyToNewReleaseDialog} from './dialog/CopyToNewReleaseDialog'
3632

37-
interface ChipStyleProps {
38-
$isArchived?: boolean
39-
}
33+
const ChipButtonContainer = styled.span`
34+
display: inline-flex;
35+
--border-color: var(--card-border-color);
36+
`
4037

41-
const ChipButton = styled(Button)<ChipStyleProps>(({$isArchived}) => {
42-
return css`
43-
flex: none;
44-
transition: none;
45-
cursor: pointer;
46-
47-
// target enabled state
48-
&:not([data-disabled='true']) {
49-
--card-border-color: var(--card-badge-default-bg-color);
50-
}
51-
52-
&[data-disabled='true'] {
53-
color: var(--card-muted-fg-color);
54-
cursor: default;
55-
56-
// archived will be disabled but should have bg color
57-
${$isArchived &&
58-
css`
59-
background-color: var(--card-badge-default-bg-color);
60-
`}
61-
}
62-
`
63-
})
38+
const ChipButton = styled(Button)`
39+
flex: none;
40+
transition: none;
41+
cursor: pointer;
42+
--card-border-color: var(--border-color);
43+
`
6444

6545
/**
6646
* @internal
@@ -208,35 +188,26 @@ export const VersionChip = memo(function VersionChip(props: {
208188
<>
209189
<Tooltip content={tooltipContent} fallbackPlacements={[]} portal placement="bottom">
210190
{/* This span is needed to make the tooltip work in disabled buttons */}
211-
<span style={{display: 'inline-flex'}}>
191+
<ChipButtonContainer>
212192
<ChipButton
213193
data-testid={`document-header-${text.replaceAll(' ', '-')}-chip`}
214194
ref={chipRef}
215195
disabled={disabled}
216-
mode="bleed"
196+
mode={disabled ? 'ghost' : 'bleed'}
217197
onClick={onClick}
218198
selected={selected}
219199
tone={tone}
220200
onContextMenu={contextMenuHandler}
221-
padding={2}
201+
paddingY={2}
202+
paddingLeft={2}
222203
paddingRight={3}
204+
space={2}
223205
radius="full"
224-
$isArchived={releaseState === 'archived'}
225-
text={
226-
<Flex align="center" gap={1}>
227-
<ReleaseAvatar padding={1} tone={tone} />
228-
<Box flex="none" padding={1}>
229-
<Text size={1}>{text}</Text>
230-
</Box>
231-
{locked && (
232-
<Box paddingRight={1}>
233-
<LockIcon />
234-
</Box>
235-
)}
236-
</Flex>
237-
}
206+
icon={<ReleaseAvatarIcon tone={tone} />}
207+
iconRight={locked && <LockIcon />}
208+
text={text}
238209
/>
239-
</span>
210+
</ChipButtonContainer>
240211
</Tooltip>
241212

242213
<Popover

0 commit comments

Comments
 (0)
Please sign in to comment.