The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
feat(ui): prose table component (#51794)
Anthony Lio3d326d7644f4
diff --git a/apps/docs/app/guides/local-development/cli/config/page.tsx b/apps/docs/app/guides/local-development/cli/config/page.tsxindex f01fe0562a1..01436f1b673 100644--- a/apps/docs/app/guides/local-development/cli/config/page.tsx+++ b/apps/docs/app/guides/local-development/cli/config/page.tsx@@ -4,7 +4,7 @@ import { genGuideMeta } from '~/features/docs/GuidesMdx.utils'import type { Parameter } from '~/lib/refGenerator/refTypes'import specFile from '~/spec/cli_v1_config.yaml' with { type: 'yml' }import ReactMarkdown from 'react-markdown'-import { Heading } from 'ui'+import { Heading, Table } from 'ui'import { CodeBlock } from 'ui-patterns/CodeBlock'const meta = {@@ -54,7 +54,7 @@ function Info({ parameter }: { parameter: Parameter }) {<div className="border-b pb-8" key={parameter.id}><div className=" mb-16"><div>- <table className="table-auto">+ <Table prose className="table-auto"><thead><tr><th className="text-left">Name</th>@@ -69,7 +69,7 @@ function Info({ parameter }: { parameter: Parameter }) {<td>{parameter.required !== undefined && parameter.required.toString()}</td></tr></tbody>- </table>+ </Table></div><div className="mb-4 scroll-mt-16 mt-0 "><p className="text-sm font-bold uppercase">Description</p>diff --git a/apps/docs/components/RealtimeLimitsEstimator/RealtimeLimitsEstimator.tsx b/apps/docs/components/RealtimeLimitsEstimator/RealtimeLimitsEstimator.tsxindex a1e5e965e52..10f909e37f2 100644--- a/apps/docs/components/RealtimeLimitsEstimator/RealtimeLimitsEstimator.tsx+++ b/apps/docs/components/RealtimeLimitsEstimator/RealtimeLimitsEstimator.tsx@@ -12,6 +12,7 @@ import {SelectItem,SelectTrigger,SelectValue,+ Table,} from 'ui'import {@@ -113,7 +114,7 @@ export default function RealtimeLimitsEstimater({}) {Current maximum possible throughput</span>- <table className="table-auto">+ <Table prose className="table-auto"><thead><tr>{THROUGHPUT_METRIC_HEADINGS.map((heading) => (@@ -133,7 +134,7 @@ export default function RealtimeLimitsEstimater({}) {<td className="border px-4 py-2">{limits.p95Latency}ms</td></tr></tbody>- </table>+ </Table></div>)}@@ -160,7 +161,7 @@ export default function RealtimeLimitsEstimater({}) {<span className="block font-heading font-semibold text-lg mt-9 mb-[18px] text-foreground">{COMPUTE_LABELS[computeAddOn]}</span>- <table className="table-auto">+ <Table prose className="table-auto"><thead><tr>{THROUGHPUT_TABLE_HEADINGS.map((heading) => (@@ -188,7 +189,7 @@ export default function RealtimeLimitsEstimater({}) {</tr>))}</tbody>- </table>+ </Table></div>))}</div>diff --git a/apps/docs/components/Table.tsx b/apps/docs/components/Table.tsxdeleted file mode 100644index 4fa967d90b6..00000000000--- a/apps/docs/components/Table.tsx+++ /dev/null@@ -1,45 +0,0 @@-'use client'--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-linear-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 Tablediff --git a/apps/docs/features/docs/MdxBase.shared.tsx b/apps/docs/features/docs/MdxBase.shared.tsxindex a5247885ee6..84f6027114f 100644--- a/apps/docs/features/docs/MdxBase.shared.tsx+++ b/apps/docs/features/docs/MdxBase.shared.tsx@@ -20,7 +20,6 @@ import { RealtimeLimitsEstimator } from '~/components/RealtimeLimitsEstimator'import { RegionsList, SmartRegionsList } from '~/components/RegionsList'import { SharedData } from '~/components/SharedData'import { StepHikeCompact } from '~/components/StepHikeCompact'-import Table from '~/components/Table'import { TerraformProviderSchema } from '~/components/TerraformProviderSchema'import { WrapperDashboardIntegration } from '~/components/WrapperDashboardIntegration'import { CodeSampleDummy, CodeSampleWrapper } from '~/features/directives/CodeSample.client'@@ -34,7 +33,7 @@ import { YouTube } from '~/features/ui/YouTube'import { ArrowDown, Check, X } from 'lucide-react'import Link from 'next/link'import { type ComponentPropsWithoutRef } from 'react'-import { Badge, Button, Heading } from 'ui'+import { Badge, Button, Heading, Table } from 'ui'import { Admonition, type AdmonitionProps } from 'ui-patterns/Admonition'import { GlassPanel } from 'ui-patterns/GlassPanel'import SqlToRest from 'ui-patterns/SqlToRest'@@ -137,7 +136,7 @@ const components = {</Heading>),pre: Pre,- table: Table,+ table: (props: ComponentPropsWithoutRef<'table'>) => <Table prose {...props} />,/*** Force inline code tags to go sync, this prevents Heading anchor resolution fail due to* our CodeBlock component being async. We need to find a better solution for more futurediff --git a/apps/docs/styles/globals.css b/apps/docs/styles/globals.cssindex 6895f7bc4f6..d933c406ab6 100644--- a/apps/docs/styles/globals.css+++ b/apps/docs/styles/globals.css@@ -346,19 +346,6 @@ th code {@apply text-nowrap;}-/*- * First column (e.g. variable names): wrap at word boundaries, not mid-token.- */-.prose :where(td:first-child) code {- @apply break-normal break-words whitespace-normal;-}--.prose table td:first-child,-.prose table th:first-child {- min-width: 12rem;- width: 30%;-}-/* Zoomable image */[data-rmiz-modal]:focus,diff --git a/apps/kb/src/pages/guides/[...slug].astro b/apps/kb/src/pages/guides/[...slug].astroindex 371f5d95439..26cfa3683e8 100644--- a/apps/kb/src/pages/guides/[...slug].astro+++ b/apps/kb/src/pages/guides/[...slug].astro@@ -1,5 +1,7 @@---import { getCollection, render } from 'astro:content'+import { createElement, type ComponentProps } from 'react'+import { Table } from 'ui'import { Admonition } from 'ui-patterns/Admonition'import ArticleLayout from '../../layouts/ArticleLayout.astro'@@ -22,6 +24,8 @@ const toc = headings.filter((heading) => heading.depth === 2 || heading.depth === 3).map((heading) => ({ title: heading.text, url: `#${heading.slug}`, depth: heading.depth }))+const ProseTable = (props: ComponentProps<'table'>) => createElement(Table, { prose: true, ...props })+// guide.filePath is relative to the kb app root, e.g. "src/content/guides/foo.mdx"const viewGitHubLink = `https://github.com/supabase/supabase/blob/master/apps/kb/${guide.filePath}`@@ -46,5 +50,5 @@ const jsonLd = [toc={toc}related={related}>- <Content components={{ Admonition }} />+ <Content components={{ Admonition, table: ProseTable }} /></ArticleLayout>diff --git a/packages/config/css/utilities.css b/packages/config/css/utilities.cssindex 755d29e45fb..94ad7979ea7 100644--- a/packages/config/css/utilities.css+++ b/packages/config/css/utilities.css@@ -100,6 +100,79 @@mask-image: linear-gradient(to left, white 98%, transparent 100%);}+/*+ * Fades the left or right edge of a horizontal scroll area when more content is on that side+ */+@property --scroll-fade-start {+ syntax: '<length>';+ initial-value: 0px;+ inherits: false;+}++@property --scroll-fade-end {+ syntax: '<length>';+ initial-value: 0px;+ inherits: false;+}++/* each fade changes size over the first or last 48px of the scroll */+@keyframes scroll-fade-start {+ from {+ --scroll-fade-start: 0px;+ }+ to {+ --scroll-fade-start: 32px;+ }+}++@keyframes scroll-fade-end {+ from {+ --scroll-fade-end: 32px;+ }+ to {+ --scroll-fade-end: 0px;+ }+}++@utility scroll-fade-x {+ --scroll-shadow: rgb(0 0 0 / 0.05);+ background:+ linear-gradient(to right, var(--background) 40%, transparent) left / 40px 100% local,+ linear-gradient(to left, var(--background) 40%, transparent) right / 40px 100% local,+ linear-gradient(to right, var(--scroll-shadow), transparent) left / 24px 100% scroll,+ linear-gradient(to left, var(--scroll-shadow), transparent) right / 24px 100% scroll;+ background-repeat: no-repeat;++ @variant dark {+ --scroll-shadow: rgb(0 0 0 / 0.2);+ }++ @supports (animation-timeline: scroll()) {+ background: none;+ mask-image: linear-gradient(+ to right,+ transparent 0,+ rgb(0 0 0 / 0.15) calc(var(--scroll-fade-start) * 0.25),+ rgb(0 0 0 / 0.5) calc(var(--scroll-fade-start) * 0.5),+ rgb(0 0 0 / 0.85) calc(var(--scroll-fade-start) * 0.75),+ #000 var(--scroll-fade-start),+ #000 calc(100% - var(--scroll-fade-end)),+ rgb(0 0 0 / 0.85) calc(100% - var(--scroll-fade-end) * 0.75),+ rgb(0 0 0 / 0.5) calc(100% - var(--scroll-fade-end) * 0.5),+ rgb(0 0 0 / 0.15) calc(100% - var(--scroll-fade-end) * 0.25),+ transparent 100%+ );+ /* use longhands. the kb build merges the shorthand and the timeline, and browsers reject the result */+ animation-name: scroll-fade-start, scroll-fade-end;+ animation-timing-function: linear;+ animation-fill-mode: both;+ animation-timeline: scroll(self inline);+ animation-range:+ 0 48px,+ calc(100% - 48px) 100%;+ }+}+/** Functional color utilities. The `--value(--color-*)` token accepts any* registered --color-* design token (e.g. highlight-foreground-light).diff --git a/packages/ui/src/components/ShadowScrollArea/index.tsx b/packages/ui/src/components/ShadowScrollArea/index.tsxindex cfe489176cf..cdd4e076b79 100644--- a/packages/ui/src/components/ShadowScrollArea/index.tsx+++ b/packages/ui/src/components/ShadowScrollArea/index.tsx@@ -30,13 +30,11 @@ const ShadowScrollArea = React.forwardRef<HTMLDivElement, ShadowScrollAreaProps>'[&_td:last-child]:before:absolute [&_td:last-child]:before:top-0 [&_td:last-child]:before:-left-6','[&_td:last-child]:before:bottom-0 [&_td:last-child]:before:w-6 [&_td:last-child]:before:bg-linear-to-l','[&_td:last-child]:before:from-black/5 dark:[&_td:last-child]:before:from-black/20 [&_td:last-child]:before:to-transparent',- '[&_td:last-child]:before:opacity-0 [&_td:last-child]:before:transition-all [&_td:last-child]:before:duration-400',- '[&_td:last-child]:before:easing-[0.24, 0.25, 0.05, 1] [&_td:last-child]:before:z-39',+ '[&_td:last-child]:before:opacity-0 [&_td:last-child]:before:z-39','[&_th:last-child]:before:absolute [&_th:last-child]:before:top-0 [&_th:last-child]:before:-left-6','[&_th:last-child]:before:bottom-0 [&_th:last-child]:before:w-6 [&_th:last-child]:before:bg-linear-to-l','[&_th:last-child]:before:from-black/5 dark:[&_th:last-child]:before:from-black/20 [&_th:last-child]:before:to-transparent',- '[&_th:last-child]:before:opacity-0 [&_th:last-child]:before:transition-all [&_th:last-child]:before:duration-400',- '[&_th:last-child]:before:easing-[0.24, 0.25, 0.05, 1] [&_th:last-child]:before:z-39'+ '[&_th:last-child]:before:opacity-0 [&_th:last-child]:before:z-39')return (@@ -44,8 +42,8 @@ const ShadowScrollArea = React.forwardRef<HTMLDivElement, ShadowScrollAreaProps><divclassName={cn('absolute inset-0 pointer-events-none z-38',- 'before:absolute before:top-0 before:right-0 before:bottom-0 before:w-6 before:bg-linear-to-l before:from-black/5 dark:before:from-black/20 before:to-transparent before:opacity-0 before:transition-all before:duration-400 before:easing-[0.24, 0.25, 0.05, 1]',- 'after:absolute after:top-0 after:left-0 after:bottom-0 after:w-6 after:bg-linear-to-r after:from-black/5 dark:after:from-black/20 after:to-transparent after:opacity-0 after:transition-all after:duration-400 after:easing-[0.24, 0.25, 0.05, 1]',+ 'before:absolute before:top-0 before:right-0 before:bottom-0 before:w-6 before:bg-linear-to-l before:from-black/5 dark:before:from-black/20 before:to-transparent before:opacity-0',+ 'after:absolute after:top-0 after:left-0 after:bottom-0 after:w-6 after:bg-linear-to-r after:from-black/5 dark:after:from-black/20 after:to-transparent after:opacity-0',hasHorizontalScroll && 'hover:before:opacity-100 hover:after:opacity-100',canScrollRight && 'before:opacity-100',canScrollLeft && 'after:opacity-100'diff --git a/packages/ui/src/components/shadcn/ui/table.tsx b/packages/ui/src/components/shadcn/ui/table.tsxindex 295686e4407..f2e4d65c1e7 100644--- a/packages/ui/src/components/shadcn/ui/table.tsx+++ b/packages/ui/src/components/shadcn/ui/table.tsx@@ -1,43 +1,47 @@+import { cva, type VariantProps } from 'class-variance-authority'import { ArrowDown, ArrowUp, ChevronsUpDown } from 'lucide-react'-import type { ComponentProps } from 'react'-import * as React from 'react'+import type { ComponentProps, ComponentPropsWithRef, ReactNode } from 'react'import { cn } from '../../../lib/utils/cn'import { ShadowScrollArea } from '../../ShadowScrollArea'-interface TableProps extends React.HTMLAttributes<HTMLTableElement> {+const tableVariants = cva('group/table w-full caption-bottom', {+ variants: {+ prose: {+ true: cn(+ 'my-0',+ '[&_td:first-child_code]:whitespace-nowrap',+ '[&_td:not(:first-child)_code]:break-all',+ '[&_td]:box-content [&_td]:min-w-18',+ '[&_:is(th,td):not(:last-child)]:pr-8',+ '[&_th]:whitespace-nowrap'+ ),+ false: 'text-sm',+ },+ },+ defaultVariants: { prose: false },+})++interface TableProps extends ComponentPropsWithRef<'table'>, VariantProps<typeof tableVariants> {containerProps?: Partial<ComponentProps<typeof ShadowScrollArea>>}-const Table = React.forwardRef<HTMLTableElement, TableProps>(- ({ className, containerProps, ...props }, ref) => {- return (- <ShadowScrollArea {...containerProps}>- <table- ref={ref}- className={cn('group/table w-full caption-bottom text-sm', className)}- {...props}- />- </ShadowScrollArea>- )- }+const Table = ({ className, containerProps, prose, ...props }: TableProps) => {+ const table = <table className={cn(tableVariants({ prose }), className)} {...props} />++ // prose pages can render without hydration, so prose uses a css-only scroll fade. other tables+ // keep ShadowScrollArea for its sticky last column+ if (prose) return <div className="my-7 overflow-x-auto scroll-fade-x">{table}</div>++ return <ShadowScrollArea {...containerProps}>{table}</ShadowScrollArea>+}++const TableHeader = ({ className, ...props }: ComponentPropsWithRef<'thead'>) => (+ <thead className={cn('[&_tr]:border-b [&>tr]:bg-200', className)} {...props} />)-Table.displayName = 'Table'--const TableHeader = React.forwardRef<- HTMLTableSectionElement,- React.HTMLAttributes<HTMLTableSectionElement>->(({ className, ...props }, ref) => (- <thead ref={ref} className={cn('[&_tr]:border-b [&>tr]:bg-200', className)} {...props} />-))-TableHeader.displayName = 'TableHeader'--const TableBody = React.forwardRef<- HTMLTableSectionElement,- React.HTMLAttributes<HTMLTableSectionElement>->(({ className, ...props }, ref) => (++const TableBody = ({ className, ...props }: ComponentPropsWithRef<'tbody'>) => (<tbody- ref={ref}className={cn('[&_tr:last-child]:border-0',// :where() keeps this at lower specificity than a row's own hover:* class, so rows can opt out (e.g. loading/empty states)@@ -46,34 +50,18 @@ const TableBody = React.forwardRef<)}{...props}/>-))-TableBody.displayName = 'TableBody'--const TableFooter = React.forwardRef<- HTMLTableSectionElement,- React.HTMLAttributes<HTMLTableSectionElement>->(({ className, ...props }, ref) => (- <tfoot ref={ref} className={cn('border-t font-medium', className)} {...props} />-))-TableFooter.displayName = 'TableFooter'--const TableRow = React.forwardRef<HTMLTableRowElement, React.HTMLAttributes<HTMLTableRowElement>>(- ({ className, ...props }, ref) => (- <tr- ref={ref}- className={cn('border-b group data-[state=selected]:bg-muted', className)}- {...props}- />- ))-TableRow.displayName = 'TableRow'-const TableHead = React.forwardRef<- HTMLTableCellElement,- React.ThHTMLAttributes<HTMLTableCellElement>->(({ className, ...props }, ref) => (+const TableFooter = ({ className, ...props }: ComponentPropsWithRef<'tfoot'>) => (+ <tfoot className={cn('border-t font-medium', className)} {...props} />+)++const TableRow = ({ className, ...props }: ComponentPropsWithRef<'tr'>) => (+ <tr className={cn('border-b group data-[state=selected]:bg-muted', className)} {...props} />+)++const TableHead = ({ className, ...props }: ComponentPropsWithRef<'th'>) => (<th- ref={ref}className={cn('h-10 px-4 text-left align-middle heading-meta whitespace-nowrap text-foreground-lighter [&:has([role=checkbox])]:pr-0',// Transition text color when NoSearchResults or NoFilterResults empty state is shown@@ -82,14 +70,13 @@ const TableHead = React.forwardRef<)}{...props}/>-))-TableHead.displayName = 'TableHead'+)interface TableHeadSortProps<TColumn extends string = string> {column: TColumncurrentSort: stringonSortChange: (column: TColumn) => void- children: React.ReactNode+ children: ReactNodeclassName?: string}@@ -152,24 +139,15 @@ function TableHeadSort<TColumn extends string = string>({}TableHeadSort.displayName = 'TableHeadSort'-const TableCell = React.forwardRef<- HTMLTableCellElement,- React.TdHTMLAttributes<HTMLTableCellElement>->(({ className, ...props }, ref) => (+const TableCell = ({ className, ...props }: ComponentPropsWithRef<'td'>) => (<td- ref={ref}className={cn('transition-colors p-4 align-middle [&:has([role=checkbox])]:pr-0', className)}{...props}/>-))-TableCell.displayName = 'TableCell'+)-const TableCaption = React.forwardRef<- HTMLTableCaptionElement,- React.HTMLAttributes<HTMLTableCaptionElement>->(({ className, ...props }, ref) => (+const TableCaption = ({ className, ...props }: ComponentPropsWithRef<'caption'>) => (<caption- ref={ref}className={cn('border-t', // TableCaption is aligned by parent Table at caption-bottom'p-4 text-sm text-foreground-muted', // Match styling of TableCell@@ -178,8 +156,7 @@ const TableCaption = React.forwardRef<// Should only contain inline elements{...props}/>-))-TableCaption.displayName = 'TableCaption'+)export {Table,