@@ -7,9 +7,11 @@ import Stack from "@mui/material/Stack";
77import Typography from "@mui/material/Typography" ;
88import Divider from "@mui/material/Divider" ;
99import { useTheme } from "@mui/material/styles" ;
10+ import { useTranslation } from "gatsby-plugin-react-i18next" ;
1011
1112import { RepoNavLink , RepoNav } from "shared/interface" ;
1213import LinkComponent from "components/Link" ;
14+ import PreviewBadge from "components/Badge/PreviewBadge" ;
1315import { scrollToElementIfInView } from "shared/utils" ;
1416import { alpha , Chip } from "@mui/material" ;
1517
@@ -190,6 +192,8 @@ export default function ControlledTreeView(props: {
190192 } ) ;
191193
192194 const theme = useTheme ( ) ;
195+ const { t } = useTranslation ( ) ;
196+ const previewBadgeLabel = t ( "navbar.badge.preview" ) ;
193197 const [ disableTransition , setDisableTransition ] = React . useState ( false ) ;
194198 const previousUrlRef = React . useRef < string | null > ( null ) ;
195199
@@ -313,7 +317,7 @@ export default function ControlledTreeView(props: {
313317 ) : (
314318 < Box sx = { { flexShrink : 0 } } width = { 16 } height = { 16 } />
315319 ) }
316- { generateItemLabel ( item ) }
320+ { generateItemLabel ( item , previewBadgeLabel ) }
317321 </ Stack >
318322 ) ;
319323 } ;
@@ -389,10 +393,22 @@ export default function ControlledTreeView(props: {
389393 ) ;
390394}
391395
392- const generateItemLabel = ( { content : contents , tag } : RepoNavLink ) => {
393- const tagQuery = new URLSearchParams ( tag ?. query ) ;
394- const tagColor = tagQuery . get ( "color" ) ;
395- const tagColor02 = tagColor && alpha ( tagColor , 0.2 ) ;
396+ const generateItemLabel = (
397+ { content : contents , tag } : RepoNavLink ,
398+ previewBadgeLabel : string
399+ ) => {
400+ const normalizedTagValue = tag ?. value ?. trim ( ) . toUpperCase ( ) ;
401+ const isPreviewTag = normalizedTagValue === "PREVIEW" ;
402+ let tagColor : string | null = null ;
403+ let tagColor02 : string | null = null ;
404+
405+ // PREVIEW intentionally ignores source color overrides to match shared badges.
406+ if ( tag && ! isPreviewTag ) {
407+ const tagQuery = new URLSearchParams ( tag . query ?? "" ) ;
408+ tagColor = tagQuery . get ( "color" ) ;
409+ tagColor02 = tagColor ? alpha ( tagColor , 0.2 ) : null ;
410+ }
411+
396412 return (
397413 < Stack sx = { { width : "100%" } } direction = "row" gap = "4px" >
398414 < Box
@@ -422,7 +438,9 @@ const generateItemLabel = ({ content: contents, tag }: RepoNavLink) => {
422438 ) ;
423439 } ) }
424440 </ Box >
425- { tag && (
441+ { tag && isPreviewTag ? (
442+ < PreviewBadge label = { previewBadgeLabel } />
443+ ) : tag ? (
426444 < Chip
427445 label = { tag . value }
428446 variant = "outlined"
@@ -438,7 +456,7 @@ const generateItemLabel = ({ content: contents, tag }: RepoNavLink) => {
438456 fontWeight : 500 ,
439457 } }
440458 />
441- ) }
459+ ) : null }
442460 </ Stack >
443461 ) ;
444462} ;
0 commit comments