Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(frontend): cover sticky table header seam
Josuéc9409f93ffae
diff --git a/control-ui/components/__tests__/FrontendComponents.test.tsx b/control-ui/components/__tests__/FrontendComponents.test.tsxindex 5e448bd81..caafe541b 100644--- a/control-ui/components/__tests__/FrontendComponents.test.tsx+++ b/control-ui/components/__tests__/FrontendComponents.test.tsx@@ -1,5 +1,5 @@import { describe, expect, it, vi } from 'vitest'-import { fireEvent, render, screen, within } from '@testing-library/react'+import { fireEvent, render, screen, waitFor, within } from '@testing-library/react'import { readFileSync } from 'node:fs'import { resolve } from 'node:path'import {@@ -121,7 +121,7 @@ describe('shared frontend components', () => {expect(screen.getByRole('tooltip')).toHaveTextContent(longDescription)})- it('keeps table paint contracts compatible with supported browsers', () => {+ it('keeps table paint contracts compatible with supported browsers', async () => {const frontendStyles = readFileSync(resolve(process.cwd(), '../packages/frontend-components/styles.css'),'utf8'@@ -139,6 +139,44 @@ describe('shared frontend components', () => {expect(descriptionCellRule).toContain('overflow: visible;')expect(descriptionCellRule).toContain('-webkit-line-clamp: unset;')expect(descriptionCellRule).toContain('line-clamp: unset;')++ const seamShadow = '0 -0.375rem 0 var(--eft-surface-muted), inset 0 -1px 0 var(--eft-border)'+ const { unmount } = render(+ <DataTable>+ <thead>+ <tr>+ <TableHeaderCell label="Unwrapped seam" />+ </tr>+ </thead>+ </DataTable>+ )++ expect(screen.getByRole('columnheader', { name: 'Unwrapped seam' })).not.toHaveStyle({+ boxShadow: seamShadow,+ })+ unmount()++ render(+ <div className="eft-table-viewport">+ <DataTable>+ <thead>+ <tr>+ <TableHeaderCell label="Paint seam" />+ <th>Raw seam</th>+ </tr>+ </thead>+ </DataTable>+ </div>+ )++ await waitFor(() => {+ expect(screen.getByRole('columnheader', { name: 'Paint seam' })).toHaveStyle({+ boxShadow: seamShadow,+ })+ expect(screen.getByRole('columnheader', { name: 'Raw seam' })).toHaveStyle({+ boxShadow: seamShadow,+ })+ })})it('opens one accessible action menu and executes its destructive action', () => {diff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex 2f588c107..0a6daf236 100644--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-ui",- "version": "0.1.539",+ "version": "0.1.542","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.539",+ "version": "0.1.542","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/frontend-components": "file:../packages/frontend-components",diff --git a/control-ui/package.json b/control-ui/package.jsonindex fb3cfdfe0..c4fca1b77 100644--- a/control-ui/package.json+++ b/control-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-ui",- "version": "0.1.539",+ "version": "0.1.542","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",diff --git a/packages/frontend-components/src/index.tsx b/packages/frontend-components/src/index.tsxindex fba3973b6..02cd03d04 100644--- a/packages/frontend-components/src/index.tsx+++ b/packages/frontend-components/src/index.tsx@@ -1,13 +1,20 @@'use client'import {+ type CSSProperties,+ Children,type HTMLAttributes,type KeyboardEvent,+ type ReactElement,type ReactNode,type TableHTMLAttributes,type TdHTMLAttributes,type ThHTMLAttributes,+ cloneElement,+ createContext,+ isValidElement,useCallback,+ useContext,useEffect,useId,useLayoutEffect,@@ -26,6 +33,48 @@ function classNames(...values: Array<string | false | null | undefined>) {return values.filter(Boolean).join(' ')}+const tableHeaderSeamStyle: CSSProperties = {+ boxShadow: '0 -0.375rem 0 var(--eft-surface-muted), inset 0 -1px 0 var(--eft-border)',+}++const TableHeaderSeamContext = createContext(false)++type HeaderPaintElementProps = {+ children?: ReactNode+ style?: CSSProperties+}++function tableHeaderStyle(style: CSSProperties | undefined, enabled: boolean) {+ return enabled ? { ...tableHeaderSeamStyle, ...style } : style+}++function withTableHeaderSeam(children: ReactNode, enabled: boolean): ReactNode {+ if (!enabled) return children+ return Children.map(children, child => {+ if (!isValidElement<HeaderPaintElementProps>(child) || child.type !== 'thead') return child+ return cloneElement(child, undefined, withHeaderCellSeam(child.props.children, enabled))+ })+}++function withHeaderCellSeam(children: ReactNode, enabled: boolean): ReactNode {+ return Children.map(children, child => {+ if (!isValidElement<HeaderPaintElementProps>(child)) return child++ if (child.type === 'th') {+ return cloneElement(child, {+ style: tableHeaderStyle(child.props.style, enabled),+ })+ }++ if (child.props.children === undefined) return child+ return cloneElement(+ child as ReactElement<HeaderPaintElementProps>,+ undefined,+ withHeaderCellSeam(child.props.children, enabled)+ )+ })+}+export type DataViewHeaderProps = {actions?: ReactNodeclassName?: string@@ -112,12 +161,28 @@ export function RecordListRow({ className, ...props }: HTMLAttributes<HTMLDivEle}export function DataTable({+ children,className,variant = 'standard',...props}: TableHTMLAttributes<HTMLTableElement> & { variant?: TableVariant }) {+ const tableRef = useRef<HTMLTableElement | null>(null)+ const [paintHeaderSeam, setPaintHeaderSeam] = useState(false)++ useLayoutEffect(() => {+ setPaintHeaderSeam(Boolean(tableRef.current?.closest('.eft-table-viewport')))+ }, [])+return (- <table {...props} className={classNames('eft-table', `eft-table--${variant}`, className)} />+ <table+ {...props}+ className={classNames('eft-table', `eft-table--${variant}`, className)}+ ref={tableRef}+ >+ <TableHeaderSeamContext.Provider value={paintHeaderSeam}>+ {withTableHeaderSeam(children, paintHeaderSeam)}+ </TableHeaderSeamContext.Provider>+ </table>)}@@ -183,6 +248,7 @@ export function TableHeaderCell({sortLabel,...props}: TableHeaderCellProps) {+ const paintHeaderSeam = useContext(TableHeaderSeamContext)const ariaSort = activeDirection? activeDirection === 'asc'? 'ascending'@@ -204,6 +270,7 @@ export function TableHeaderCell({aria-sort={ariaSort}className={classNames(`eft-table__header--${kind}`, className)}scope={props.scope ?? 'col'}+ style={tableHeaderStyle(props.style, paintHeaderSeam)}>{onSort && sortLabel ? (<span className="eft-table__sort-group">