mirror of
https://github.com/supabase/supabase.git
synced 2026-07-02 04:54:28 +08:00
strictNullChecks was off for docs, which lets errors slip through and leads to incorrect required/optional typing on Zod-inferred types. This PR enables strictNullChecks and fixes all the existing violations.
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
import React, { TableHTMLAttributes, useEffect, useRef, useState } from 'react'
|
|
import { cn } from 'ui'
|
|
|
|
type TableProps = TableHTMLAttributes<HTMLTableElement>
|
|
|
|
const Table = ({ children, ...props }: TableProps) => {
|
|
const containerRef = useRef<HTMLDivElement>(null)
|
|
const [showShadow, setShowShadow] = useState(true)
|
|
|
|
const handleScroll = () => {
|
|
const container = containerRef.current
|
|
|
|
if (container) {
|
|
const { scrollWidth, scrollLeft, offsetWidth } = container
|
|
const isAtEnd = scrollWidth - scrollLeft - 2 < offsetWidth
|
|
setShowShadow(!isAtEnd)
|
|
}
|
|
}
|
|
|
|
useEffect(() => {
|
|
const container = containerRef.current
|
|
if (container) {
|
|
container.addEventListener('scroll', handleScroll)
|
|
return () => container.removeEventListener('scroll', handleScroll)
|
|
}
|
|
}, [])
|
|
|
|
return (
|
|
<div className="relative">
|
|
<span
|
|
className={cn(
|
|
'block md:hidden absolute inset-0 left-auto w-5 bg-gradient-to-r from-transparent to-background transition-opacity opacity-100',
|
|
!showShadow && 'opacity-0 duration-300'
|
|
)}
|
|
/>
|
|
<div ref={containerRef} className="w-full overflow-x-auto break-normal">
|
|
<table {...props}>{children}</table>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default Table
|