Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function Sidebar({ children }: { children: React.ReactNode }) {
<div
className={cn(
sidebarWrapperClass,
'text-sans-md text-raise flex flex-col overflow-y-auto overscroll-none',
'text-sans-md text-raise flex flex-col overflow-y-auto overscroll-contain',
!mobileNavOpen && 'max-1000:-translate-x-full'
)}
>
Expand Down
71 changes: 0 additions & 71 deletions app/table/Table.browser.spec.tsx

This file was deleted.

61 changes: 13 additions & 48 deletions app/table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,19 @@
* Copyright Oxide Computer Company
*/
import { flexRender, type Table as TableInstance } from '@tanstack/react-table'
import cn from 'classnames'
import type { JSX } from 'react'

import { Table as UITable } from '~/ui/lib/Table'

export type TableProps<TData> = JSX.IntrinsicElements['table'] & {
rowClassName?: string
rowHeight?: 'small' | 'large'
table: TableInstance<TData>
singleSelect?: boolean
multiSelect?: boolean
}

/** Render a React Table table instance */
export const Table = <TData,>({
rowClassName,
rowHeight = 'small',
table,
singleSelect,
multiSelect,
...tableProps
}: TableProps<TData>) => (
<UITable {...tableProps}>
Expand Down Expand Up @@ -53,47 +46,19 @@ export const Table = <TData,>({
))}
</UITable.Header>
<UITable.Body>
{table.getRowModel().rows.map((row) => {
// For single-select, the entire row is clickable
const rowProps =
singleSelect && row.getCanSelect() // this means single-select only
? {
className: cn(rowClassName, 'cursor-pointer'),
selected: row.getIsSelected(),
// select only this row
onClick: () => table.setRowSelection(() => ({ [row.id]: true })),
}
: {
className: rowClassName,
selected:
multiSelect && row.getCanMultiSelect() ? row.getIsSelected() : undefined,
}

// For multi-select, assume the first cell is the checkbox and make the
// whole cell clickable
const firstCellProps =
multiSelect && row.getCanMultiSelect()
? {
className: 'cursor-pointer',
onClick: () => row.toggleSelected(),
}
: {}

return (
<UITable.Row key={row.id} {...rowProps}>
{row.getAllCells().map((cell, i) => (
<UITable.Cell
key={cell.column.id}
{...(i === 0 ? firstCellProps : {})}
className={cell.column.columnDef.meta?.tdClassName}
height={rowHeight}
>
{flexRender(cell.column.columnDef.cell, cell.getContext())}
</UITable.Cell>
))}
</UITable.Row>
)
})}
{table.getRowModel().rows.map((row) => (
<UITable.Row key={row.id}>
{row.getAllCells().map((cell) => (
<UITable.Cell
key={cell.column.id}
className={cell.column.columnDef.meta?.tdClassName}
height={rowHeight}
>
{flexRender(cell.column.columnDef.cell, cell.getContext())}
</UITable.Cell>
))}
</UITable.Row>
))}
</UITable.Body>
</UITable>
)
38 changes: 0 additions & 38 deletions app/table/columns/select-col.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion app/ui/lib/CardBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ CardBlock.Header = ({ title, description, children, titleId }: HeaderProps) => (
)

// If there's a table with a scrollbar we want to avoid it adding extra padding at the bottom
CardBlock.Body = classed.div`px-5 py-4 space-y-4 [&>*:last-child[data-simplebar]]:pb-3 [&>*:last-child[data-simplebar]]:-mb-3`
CardBlock.Body = classed.div`px-5 py-4 space-y-4 [&>.ox-table-scroller:last-child]:pb-1 [&>.ox-table-scroller:last-child]:-mb-3`

CardBlock.Footer = classed.footer`flex items-center justify-between px-5 pt-4 text-secondary`

Expand Down
2 changes: 1 addition & 1 deletion app/ui/lib/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function Modal({
)
}

Modal.Body = classed.div`py-2 overflow-y-auto overscroll-none`
Modal.Body = classed.div`py-2 overflow-y-auto overscroll-contain`

Modal.Section = classed.div`p-4 space-y-4 border-b border-secondary text-default last-of-type:border-none text-sans-md`

Expand Down
2 changes: 1 addition & 1 deletion app/ui/lib/Popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function Popover(props: PopoverProps) {
<div
{...popoverProps}
ref={ref}
className="bg-raise light:bg-default shadow-menu absolute z-(--z-popover) my-2 overflow-auto rounded-lg"
className="bg-raise light:bg-default shadow-menu absolute z-(--z-popover) my-2 overflow-auto overscroll-none rounded-lg"
>
<DismissButton onDismiss={state.close} />
{children}
Expand Down
2 changes: 1 addition & 1 deletion app/ui/lib/SideModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export const ResourceLabel = classed.h3`mt-1.5 flex items-center gap-1.5 text-sa

SideModal.Body = ({ children }: { children?: ReactNode }) => (
<div
className="body border-t-secondary relative h-full overflow-y-auto overscroll-none border-t pt-8 pb-12"
className="body border-t-secondary relative h-full overflow-y-auto overscroll-contain border-t pt-8 pb-12"
data-testid="sidemodal-scroll-container"
>
{children}
Expand Down
57 changes: 15 additions & 42 deletions app/ui/lib/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@
* Copyright Oxide Computer Company
*/
import cn from 'classnames'
import React, { type JSX, type ReactElement } from 'react'
import SimpleBar from 'simplebar-react'
import type { JSX } from 'react'

import { classed } from '~/util/classed'

export type TableProps = JSX.IntrinsicElements['table']
/** `className` goes on the outer box so sizing classes also size the frame */
export function Table({ className, ...props }: TableProps) {
return (
<SimpleBar className="overflow-x-auto rounded-md pb-4" autoHide={false}>
<table
className={cn(className, 'ox-table text-sans-md w-full border-separate')}
{...props}
/>
</SimpleBar>
// a utility, not in table.css, so CardBlock.Body can override it
<div className={cn('ox-table-scroller pb-2', className)}>
<div className="ox-table-grid">
<table className="ox-table text-sans-md w-full" {...props} />
<div className="ox-table-frame" aria-hidden />
</div>
</div>
)
}

Expand All @@ -38,7 +39,7 @@ Table.HeadCell = ({ className, children, ...props }: TableHeadCellProps) => (
<th
className={cn(
className,
'text-mono-sm bg-secondary border-default h-9 border-y pr-px pl-0 text-left'
'text-mono-sm bg-secondary border-default h-9 border-y pr-px pl-0 text-left first:*:border-l-0'
)}
{...props}
>
Expand All @@ -48,45 +49,17 @@ Table.HeadCell = ({ className, children, ...props }: TableHeadCellProps) => (
</th>
)

export type TableRowProps = JSX.IntrinsicElements['tr'] & {
selected?: boolean
}
Table.Row = ({ className, selected, ...props }: TableRowProps) => (
<tr className={cn('bg-default', className, selected && 'is-selected')} {...props} />
export type TableRowProps = JSX.IntrinsicElements['tr']
Table.Row = ({ className, ...props }: TableRowProps) => (
<tr className={cn('bg-default', className)} {...props} />
)

type RowElt = ReactElement<TableRowProps>

export type TableBodyProps = JSX.IntrinsicElements['tbody']
Table.Body = ({ className, children, ...props }: TableBodyProps) => {
const rows = React.Children.toArray(children).map((c, i, siblings) => {
const child = c as RowElt
const beforeSelected = (siblings[i - 1] as RowElt | undefined)?.props.selected
const afterSelected = (siblings[i + 1] as RowElt | undefined)?.props.selected
const className =
child.props.selected && (beforeSelected || afterSelected)
? cn(
child.props.className,
'multi-selection',
!beforeSelected && 'selection-start',
!afterSelected && 'selection-end'
)
: child.props.className
return React.cloneElement(child, { ...child.props, className })
})
return (
<tbody className={className} {...props}>
{rows}
</tbody>
)
}
Table.Body = (props: TableBodyProps) => <tbody {...props} />

export type TableCellProps = JSX.IntrinsicElements['td'] & { height?: 'small' | 'large' }
Table.Cell = ({ height = 'small', className, children, ...props }: TableCellProps) => (
<td
className={cn(className, 'text-raise border-default pl-0 first:*:border-l-0')}
{...props}
>
<td className={cn(className, 'text-raise pl-0 first:*:border-l-0')} {...props}>
<div
className={cn(
'border-secondary relative flex items-center overflow-hidden border-b border-l px-3 py-2',
Expand Down
1 change: 1 addition & 0 deletions app/ui/styles/components/menu-button.css
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
.dropdown-menu-content,
.popover-panel {
animation: slide-down 0.1s var(--ease-out-quad);
overscroll-behavior: none;
}

@media (prefers-reduced-motion) {
Expand Down
1 change: 1 addition & 0 deletions app/ui/styles/components/menu-list.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

.ox-menu {
@apply bg-raise light:bg-default !max-h-[17.5rem] rounded-md p-px;
overscroll-behavior: none;
}

.ox-menu-item {
Expand Down
Loading
Loading