Files
supabase/apps/www/components/Panel/Panel.tsx
kemal.earth ae7b9ee245 fix(www): inner border radii for homepage cards (#50987)
## Problem

Looks like they broke when something else got updated.

## Solution

Fixes width some CSS var magic that should inherit whatever the outer
radii is.

| Before | After |
|--------|--------|
| <img width="1186" height="170" alt="Screenshot 2026-09-28 at 17 36 18"
src="https://github.com/user-attachments/assets/69ba7e37-d57e-4c86-a668-fa707cf80ccb"
/> | <img width="1182" height="180" alt="Screenshot 2026-09-28 at 17 36
26"
src="https://github.com/user-attachments/assets/de23b3fe-2b92-440d-b01f-57cd71e95971"
/> |


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Style**
* Updated panel corner radii to scale at medium screen sizes, with the
inner corners kept slightly smaller than the outer corners.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-09-28 18:18:37 +01:00

114 lines
3.5 KiB
TypeScript

'use client'
import { detectBrowser, isBrowser } from 'common'
import { motion } from 'framer-motion'
import React, { PropsWithChildren, useEffect, useRef } from 'react'
import { cn } from 'ui'
interface Props {
outerClassName?: string
innerClassName?: string
hasActiveOnHover?: boolean
activeColor?: 'default' | 'brand'
hasShimmer?: boolean
hasInnerShimmer?: boolean
shimmerFromColor?: string
shimmerToColor?: string
style?: React.CSSProperties
innerStyle?: React.CSSProperties
hasMotion?: boolean
}
const Panel = ({
outerClassName,
innerClassName,
hasActiveOnHover = false,
activeColor = 'default',
hasShimmer = false,
hasInnerShimmer = false,
shimmerFromColor,
shimmerToColor,
hasMotion = false,
children,
style,
innerStyle,
}: PropsWithChildren<Props>) => {
const outerRef = useRef(null)
const innerRef = useRef(null)
const Component = hasMotion ? motion.div : 'div'
const isSafari = isBrowser && detectBrowser() === 'Safari'
const trackCursor = hasShimmer || hasInnerShimmer
const handleGlow = (event: any) => {
if (!outerRef.current || !innerRef.current) return
const outerElement = outerRef.current as HTMLDivElement
const innerElement = innerRef.current as HTMLDivElement
const { x: elX, y: elY, width, height } = outerElement.getBoundingClientRect()
const x = event.clientX - elX
const y = event.clientY - elY
const isActive = x > -0 && x < width + 0 && y > -0 && y < height + 0
if (hasShimmer) {
const activeGlow =
hasActiveOnHover && isActive
? `radial-gradient(65rem circle at ${x}px ${y}px, ${
activeColor === 'brand' ? 'var(--color-brand-900)' : 'var(--border-stronger)'
}, transparent), `
: ''
outerElement.style.backgroundImage = `
${activeGlow}radial-gradient(30rem circle at ${x}px ${y}px, ${
shimmerFromColor ?? 'var(--border-strong)'
}, ${shimmerToColor ?? 'var(--background-surface-300)'})`
}
if (hasInnerShimmer) {
innerElement.style.backgroundImage = isActive
? `radial-gradient(7rem circle at ${x}px ${y}px, var(--background-surface-300), transparent), radial-gradient(20rem circle at ${x}px ${y}px, var(--background-surface-200), transparent)`
: ''
}
}
useEffect(() => {
if (!isBrowser || trackCursor || isSafari) return
window.addEventListener('mousemove', handleGlow)
return () => {
window.removeEventListener('mousemove', handleGlow)
}
}, [])
return (
<Component
ref={outerRef}
className={cn(
'group/panel relative [--panel-radius:var(--radius-lg)] md:[--panel-radius:var(--radius-xl)] rounded-(--panel-radius) p-px bg-surface-75 bg-linear-to-b from-border to-border/50 dark:to-surface-100 transition-all hover:shadow-md',
!trackCursor && hasActiveOnHover
? activeColor === 'brand'
? 'hover:bg-none hover:bg-brand-default!'
: 'hover:bg-none hover:bg-border-stronger!'
: '',
outerClassName
)}
{...(hasMotion ? { whileHover: 'hover', animate: 'initial' } : undefined)}
style={style}
>
<div
className={cn(
'relative z-10 w-full h-full rounded-[calc(var(--panel-radius)-1px)] bg-surface-75 overflow-hidden text-foreground-light',
innerClassName
)}
style={innerStyle}
>
{children}
<div
ref={innerRef}
className="absolute z-10 inset-0 w-full h-full pointer-events-none opacity-20"
/>
</div>
</Component>
)
}
export default Panel