fix(ui): improve banner carousel styling and dismiss functionality (#8225)
* fix(ui): improve banner carousel styling and dismiss functionality - Fix dismiss button not working by adding version-based filtering - Use CSS Grid stack technique to auto-size carousel to tallest card - Fix spacing issues on narrow widths with reduced margins/padding - Add hover underline for links in banner descriptions - Prevent header icon from shrinking on narrow screens - Remove bottom margin from markdown paragraphs - Clean up navigation footer styling * chore: add changeset
This commit is contained in:
1 parent
8a9e03c8ff
commit
8f1405b881
3 files changed
+109
-51
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"claude-dev": patch
|
||||
---
|
||||
|
||||
Fix banner carousel styling and dismiss functionality
|
||||
@@ -53,6 +53,25 @@ export const WelcomeSection: React.FC<WelcomeSectionProps> = ({
|
||||
hideAnnouncement()
|
||||
}, [hideAnnouncement])
|
||||
|
||||
/**
|
||||
* Check if a banner has been dismissed based on its version
|
||||
*/
|
||||
const isBannerDismissed = useCallback(
|
||||
(bannerId: string): boolean => {
|
||||
if (bannerId.startsWith("info-banner")) {
|
||||
return (lastDismissedInfoBannerVersion ?? 0) >= CURRENT_INFO_BANNER_VERSION
|
||||
}
|
||||
if (bannerId.startsWith("new-model")) {
|
||||
return (lastDismissedModelBannerVersion ?? 0) >= CURRENT_MODEL_BANNER_VERSION
|
||||
}
|
||||
if (bannerId.startsWith("cli-")) {
|
||||
return (lastDismissedCliBannerVersion ?? 0) >= CURRENT_CLI_BANNER_VERSION
|
||||
}
|
||||
return false
|
||||
},
|
||||
[lastDismissedInfoBannerVersion, lastDismissedModelBannerVersion, lastDismissedCliBannerVersion],
|
||||
)
|
||||
|
||||
/**
|
||||
* Banner configuration from backend
|
||||
* In production, this would come from an API/gRPC call
|
||||
@@ -61,6 +80,10 @@ export const WelcomeSection: React.FC<WelcomeSectionProps> = ({
|
||||
const bannerConfig = useMemo((): BannerCardData[] => {
|
||||
// Filter banners based on version tracking and user status
|
||||
return BANNER_DATA.filter((banner) => {
|
||||
if (isBannerDismissed(banner.id)) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (banner.isClineUserOnly !== undefined) {
|
||||
return banner.isClineUserOnly === !!clineUser
|
||||
}
|
||||
@@ -71,7 +94,7 @@ export const WelcomeSection: React.FC<WelcomeSectionProps> = ({
|
||||
|
||||
return true
|
||||
})
|
||||
}, [lastDismissedInfoBannerVersion, lastDismissedCliBannerVersion, lastDismissedModelBannerVersion, clineUser])
|
||||
}, [isBannerDismissed, clineUser])
|
||||
|
||||
/**
|
||||
* Action handler - maps action types to actual implementations
|
||||
|
||||
@@ -22,24 +22,68 @@ interface BannerCarouselProps {
|
||||
banners: BannerData[]
|
||||
}
|
||||
|
||||
interface BannerCardContentProps {
|
||||
banner: BannerData
|
||||
isActive: boolean
|
||||
isTransitioning: boolean
|
||||
showDismissButton: boolean
|
||||
}
|
||||
|
||||
const BannerCardContent: React.FC<BannerCardContentProps> = ({ banner, isActive, isTransitioning, showDismissButton }) => {
|
||||
const [markdownContent, setMarkdown] = useRemark()
|
||||
|
||||
useEffect(() => {
|
||||
setMarkdown(typeof banner.description === "string" ? banner.description : "")
|
||||
}, [banner.description, setMarkdown])
|
||||
|
||||
return (
|
||||
<div
|
||||
className="p-3"
|
||||
style={{
|
||||
gridArea: "stack",
|
||||
opacity: isActive && !isTransitioning ? 1 : 0,
|
||||
transition: "opacity 0.4s ease-in-out",
|
||||
pointerEvents: isActive ? "auto" : "none",
|
||||
}}>
|
||||
{/* Title with optional icon */}
|
||||
<h3
|
||||
className="font-semibold mb-2 flex items-center gap-2 text-base"
|
||||
style={{ paddingRight: showDismissButton ? "24px" : "0" }}>
|
||||
<span className="shrink-0">{banner.icon}</span>
|
||||
{banner.title}
|
||||
</h3>
|
||||
|
||||
{/* Description */}
|
||||
<div className="text-sm text-description leading-relaxed [&>*:last-child]:mb-0 [&_a]:hover:underline">
|
||||
{markdownContent}
|
||||
</div>
|
||||
|
||||
{/* Action buttons */}
|
||||
{banner.actions?.length ? (
|
||||
<div className="flex flex-wrap gap-2 mt-3">
|
||||
{banner.actions.map((action) => (
|
||||
<Button disabled={action.disabled} key={action.label} onClick={action.onClick} size="sm">
|
||||
{action.label}
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export const BannerCarousel: React.FC<BannerCarouselProps> = ({ banners }) => {
|
||||
const [currentIndex, setCurrentIndex] = useState(0)
|
||||
const [isPaused, setIsPaused] = useState(false)
|
||||
const [isTransitioning, setIsTransitioning] = useState(false)
|
||||
const autoPlayIntervalRef = useRef<NodeJS.Timeout | null>(null)
|
||||
|
||||
const [currentBannerMarkdownText, setMarkdown] = useRemark()
|
||||
|
||||
// Compute a safe index that's always within bounds
|
||||
const safeCurrentIndex = useMemo(
|
||||
() => (banners.length === 0 ? 0 : Math.min(currentIndex, banners.length - 1)),
|
||||
[currentIndex, banners.length],
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
setMarkdown(typeof banners?.[safeCurrentIndex]?.description === "string" ? banners[safeCurrentIndex].description : "")
|
||||
}, [banners, safeCurrentIndex, setMarkdown])
|
||||
|
||||
const transitionToIndex = useCallback((newIndex: number) => {
|
||||
setIsTransitioning(true)
|
||||
setTimeout(() => {
|
||||
@@ -98,22 +142,24 @@ export const BannerCarousel: React.FC<BannerCarouselProps> = ({ banners }) => {
|
||||
return null
|
||||
}
|
||||
|
||||
const showDismissButton = safeCurrentIndex === banners.length - 1 && currentBanner.onDismiss
|
||||
|
||||
return (
|
||||
<div
|
||||
aria-label="Announcements"
|
||||
aria-live="polite"
|
||||
aria-roledescription="carousel"
|
||||
className="mx-4 mb-4 mt-9"
|
||||
className="mx-3 mb-3"
|
||||
onMouseEnter={() => setIsPaused(true)}
|
||||
onMouseLeave={() => setIsPaused(false)}
|
||||
role="region">
|
||||
{/* Card container with unified styling */}
|
||||
{/* Card container */}
|
||||
<div className="relative bg-muted rounded-sm">
|
||||
{/* Dismiss button - only show on last card, dismisses ALL banners */}
|
||||
{safeCurrentIndex === banners.length - 1 && currentBanner.onDismiss && (
|
||||
{showDismissButton && (
|
||||
<Button
|
||||
aria-label="Dismiss all banners"
|
||||
className="absolute top-2 right-2 z-10"
|
||||
className="absolute top-2.5 right-2 z-10"
|
||||
data-testid="banner-dismiss-button"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
@@ -126,56 +172,40 @@ export const BannerCarousel: React.FC<BannerCarouselProps> = ({ banners }) => {
|
||||
</Button>
|
||||
)}
|
||||
|
||||
{/* Card content with fixed height and fade transition */}
|
||||
<div
|
||||
className="p-4"
|
||||
style={{
|
||||
height: "144px",
|
||||
overflow: "hidden",
|
||||
opacity: isTransitioning ? 0 : 1,
|
||||
transition: "opacity 0.4s ease-in-out",
|
||||
}}>
|
||||
{/* Title with optional icon */}
|
||||
<h3
|
||||
className="font-semibold mb-3 flex items-center gap-2"
|
||||
style={{
|
||||
fontSize: "16px",
|
||||
paddingRight: safeCurrentIndex === banners.length - 1 && currentBanner.onDismiss ? "24px" : "0",
|
||||
}}>
|
||||
{currentBanner.icon}
|
||||
{currentBanner.title}
|
||||
</h3>
|
||||
{/* Card content - grid stack makes container size to tallest */}
|
||||
<div className="grid" style={{ gridTemplateAreas: "'stack'" }}>
|
||||
{banners.map((banner, idx) => {
|
||||
const isActive = idx === safeCurrentIndex
|
||||
const isLastBanner = idx === banners.length - 1
|
||||
const showDismiss = isLastBanner && banner.onDismiss
|
||||
|
||||
{/* Description */}
|
||||
<div className="text-base mb-4 text-description">{currentBannerMarkdownText}</div>
|
||||
|
||||
{/* Action buttons */}
|
||||
{currentBanner.actions?.length ? (
|
||||
<div className="flex gap-3 mt-4">
|
||||
{currentBanner.actions.map((action, idx) => (
|
||||
<Button disabled={action.disabled} key={idx} onClick={action.onClick}>
|
||||
{action.label}
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
return (
|
||||
<BannerCardContent
|
||||
banner={banner}
|
||||
isActive={isActive}
|
||||
isTransitioning={isTransitioning}
|
||||
key={banner.id}
|
||||
showDismissButton={!!showDismiss}
|
||||
/>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
|
||||
{/* Navigation footer - only show if more than 1 banner */}
|
||||
{banners.length > 1 && (
|
||||
<div className="flex justify-between items-center px-4 py-1 border-t-1 border-t-description/20">
|
||||
<div className="flex justify-between items-center px-3 py-1.5 border-t border-description/15">
|
||||
{/* Page indicator */}
|
||||
<div className="text-base font-medium text-description">
|
||||
{safeCurrentIndex + 1}/{banners.length}
|
||||
<div className="text-sm text-description">
|
||||
{safeCurrentIndex + 1} / {banners.length}
|
||||
</div>
|
||||
|
||||
{/* Navigation arrows */}
|
||||
<div className="flex -mr-3 mt-1">
|
||||
<Button aria-label="Previous banner" onClick={handlePrevious} variant="icon">
|
||||
<ChevronLeft className="size-5 stroke-2" />
|
||||
<div className="flex gap-0.5">
|
||||
<Button aria-label="Previous banner" onClick={handlePrevious} size="icon" variant="icon">
|
||||
<ChevronLeft className="size-4" />
|
||||
</Button>
|
||||
<Button aria-label="Next banner" onClick={handleNext} variant="icon">
|
||||
<ChevronRight className="size-5 stroke-2" />
|
||||
<Button aria-label="Next banner" onClick={handleNext} size="icon" variant="icon">
|
||||
<ChevronRight className="size-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user