@podoba/react 0.0.48 → 0.0.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@podoba/react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.49",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "podoba React components — React Aria Components + Tailwind primitives + layout, built with uic.",
|
|
6
6
|
"repository": {
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"typecheck": "tsc --build"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@podoba/tokens": "^0.0.
|
|
32
|
-
"@podoba/tailwind": "^0.0.
|
|
31
|
+
"@podoba/tokens": "^0.0.49",
|
|
32
|
+
"@podoba/tailwind": "^0.0.49",
|
|
33
33
|
"react-aria-components": "1.18.0",
|
|
34
34
|
"class-variance-authority": "0.7.1",
|
|
35
35
|
"clsx": "2.1.1",
|
|
@@ -39,10 +39,14 @@ function Composed() {
|
|
|
39
39
|
</tr>
|
|
40
40
|
</TableHead>
|
|
41
41
|
<TableBody>
|
|
42
|
-
<TableRow>
|
|
42
|
+
<TableRow onPress={() => {}} aria-label="Open Editor">
|
|
43
43
|
<TableRowHeader>Editor</TableRowHeader>
|
|
44
44
|
<TableCell align="right">4</TableCell>
|
|
45
45
|
</TableRow>
|
|
46
|
+
<TableRow>
|
|
47
|
+
<TableRowHeader>Viewer</TableRowHeader>
|
|
48
|
+
<TableCell align="right">12</TableCell>
|
|
49
|
+
</TableRow>
|
|
46
50
|
</TableBody>
|
|
47
51
|
</TableRoot>
|
|
48
52
|
</TableScroll>
|
package/src/components/table.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useMemo, useState, type CSSProperties, type HTMLAttributes, type ReactNode, type ThHTMLAttributes } from 'react'
|
|
1
|
+
import { useMemo, useState, type ComponentProps, type CSSProperties, type HTMLAttributes, type ReactNode, type ThHTMLAttributes } from 'react'
|
|
2
2
|
import { uic } from '../utils/uic'
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -39,8 +39,7 @@ export const TableHead = uic('thead', { displayName: 'TableHead', baseClass: 'bo
|
|
|
39
39
|
|
|
40
40
|
export const TableBody = uic('tbody', { displayName: 'TableBody' })
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
export const TableRow = uic('tr', {
|
|
42
|
+
const TableRowBase = uic('tr', {
|
|
44
43
|
displayName: 'TableRow',
|
|
45
44
|
baseClass: 'border-b border-border-muted outline-none last:border-b-0',
|
|
46
45
|
variants: {
|
|
@@ -50,6 +49,41 @@ export const TableRow = uic('tr', {
|
|
|
50
49
|
},
|
|
51
50
|
})
|
|
52
51
|
|
|
52
|
+
export type TableRowProps = ComponentProps<typeof TableRowBase> & {
|
|
53
|
+
/**
|
|
54
|
+
* Makes the whole row one pressable control: pointer, hover fill, inset focus ring,
|
|
55
|
+
* `tabIndex={0}`, `role="button"` and Enter/Space activation. Name it with
|
|
56
|
+
* `aria-label`, since the button role hides the cells from assistive tech.
|
|
57
|
+
*/
|
|
58
|
+
onPress?: () => void
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** A body row. `onPress` turns it into a pressable row; without it the row is plain. */
|
|
62
|
+
export function TableRow({ onPress, onClick, onKeyDown, ...rest }: TableRowProps) {
|
|
63
|
+
if (!onPress) return <TableRowBase onClick={onClick} onKeyDown={onKeyDown} {...rest} />
|
|
64
|
+
return (
|
|
65
|
+
<TableRowBase
|
|
66
|
+
tabIndex={0}
|
|
67
|
+
role="button"
|
|
68
|
+
{...rest}
|
|
69
|
+
interactive
|
|
70
|
+
onClick={(event) => {
|
|
71
|
+
onClick?.(event)
|
|
72
|
+
if (!event.defaultPrevented) onPress()
|
|
73
|
+
}}
|
|
74
|
+
onKeyDown={(event) => {
|
|
75
|
+
onKeyDown?.(event)
|
|
76
|
+
// Keys pressed in a control inside the row belong to that control.
|
|
77
|
+
if (event.defaultPrevented || event.target !== event.currentTarget) return
|
|
78
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
79
|
+
event.preventDefault()
|
|
80
|
+
onPress()
|
|
81
|
+
}
|
|
82
|
+
}}
|
|
83
|
+
/>
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
|
|
53
87
|
/** A column header cell: mono label in the muted ink. A row's own header is `TableRowHeader`. */
|
|
54
88
|
export const TableHeaderCell = uic('th', {
|
|
55
89
|
displayName: 'TableHeaderCell',
|
|
@@ -256,25 +290,7 @@ export function Table<Row>({
|
|
|
256
290
|
sorted.map((row, index) => {
|
|
257
291
|
const rowProps = getRowProps?.(row)
|
|
258
292
|
return (
|
|
259
|
-
<TableRow
|
|
260
|
-
key={rowKey(row, index)}
|
|
261
|
-
{...rowProps}
|
|
262
|
-
interactive={interactive}
|
|
263
|
-
{...(interactive
|
|
264
|
-
? {
|
|
265
|
-
// A pressable row is one control; callers name it via `getRowProps` (`aria-label`).
|
|
266
|
-
tabIndex: 0,
|
|
267
|
-
role: 'button',
|
|
268
|
-
onClick: () => onRowClick?.(row),
|
|
269
|
-
onKeyDown: (event: React.KeyboardEvent) => {
|
|
270
|
-
if (event.key === 'Enter' || event.key === ' ') {
|
|
271
|
-
event.preventDefault()
|
|
272
|
-
onRowClick?.(row)
|
|
273
|
-
}
|
|
274
|
-
},
|
|
275
|
-
}
|
|
276
|
-
: {})}
|
|
277
|
-
>
|
|
293
|
+
<TableRow key={rowKey(row, index)} {...rowProps} onPress={interactive ? () => onRowClick?.(row) : undefined}>
|
|
278
294
|
{columns.map((column) => (
|
|
279
295
|
<TableCell key={column.key} align={column.align ?? 'left'}>
|
|
280
296
|
{column.render ? column.render(row) : String(defaultSortValue(column, row))}
|