Skip to content

Commit adb9d76

Browse files
committed
Make column resizable optional and font customisable
1 parent 4771cad commit adb9d76

5 files changed

Lines changed: 26 additions & 33 deletions

File tree

src/table/ColumnHeader.tsx

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Show } from 'solid-js'
12
import { Dynamic } from 'solid-js/web'
23
import { PositionedColumn } from './types'
34
import { Renameable } from 'src/components/Renameable'
@@ -8,6 +9,7 @@ export interface ColumnHeaderProps<K, T> {
89
column: PositionedColumn<K, T>
910
height: number
1011
columnsEditable?: boolean
12+
columnsResizeable?: boolean
1113
setColumnName?: (id: K, name: string) => void
1214
setColumnSize?: (id: K, width: number) => void
1315
resetColumnSize?: (id: K) => void
@@ -37,20 +39,22 @@ export function ColumnHeader<K, T>(props: ColumnHeaderProps<K, T>) {
3739
<Dynamic component={props.column.icon} />
3840
</div>
3941
</div>
40-
<ResizeBar
41-
style={{
42-
position: 'absolute',
43-
top: '0',
44-
margin: '0 0 0 -4px',
45-
width: '9px',
46-
height: `${props.height - 1}px`,
47-
transform: `translate(${props.column.right}px, 0px)`,
48-
'z-index': 10,
49-
}}
50-
size={props.column.width}
51-
setSize={width => props.setColumnSize?.(props.column.id, width)}
52-
resetSize={() => props.resetColumnSize?.(props.column.id)}
53-
/>
42+
<Show when={props.columnsResizeable}>
43+
<ResizeBar
44+
style={{
45+
position: 'absolute',
46+
top: '0',
47+
margin: '0 0 0 -4px',
48+
width: '9px',
49+
height: `${props.height - 1}px`,
50+
transform: `translate(${props.column.right}px, 0px)`,
51+
'z-index': 10,
52+
}}
53+
size={props.column.width}
54+
setSize={width => props.setColumnSize?.(props.column.id, width)}
55+
resetSize={() => props.resetColumnSize?.(props.column.id)}
56+
/>
57+
</Show>
5458
</>
5559
)
5660
}

src/table/Table.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
:root {
2+
--solid-tabular-font: 0.875rem 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
23
--solid-tabular-bg-color: oklch(92.8% 0.006 264.531);
34
--solid-tabular-text-color: black;
45
--solid-tabular-cell-color: white;
@@ -32,6 +33,8 @@
3233
outline: none;
3334
user-select: none;
3435
text-align: left;
36+
font: var(--solid-tabular-font);
37+
font-variant-numeric: tabular-nums;
3538
background-color: var(--solid-tabular-bg-color);
3639
color: var(--solid-tabular-text-color);
3740

src/table/Table.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
1-
import {
2-
For,
3-
Show,
4-
createMemo,
5-
createSignal,
6-
mapArray,
7-
onMount,
8-
onCleanup,
9-
createEffect,
10-
} from 'solid-js'
1+
import { For, Show, createMemo, createSignal, mapArray, createEffect } from 'solid-js'
112
import { createVirtualizer } from '@tanstack/solid-virtual'
123
import { DragMode, type ActiveRange, type CellIndex, type Column } from './types'
134
import { devicePixelRatio, createSize } from 'src/lib/devicePixelRatio'
@@ -40,6 +31,8 @@ export interface TableProps<K = string, T = string> {
4031
rowsEditable?: boolean
4132
/** Whether cells can be edited. */
4233
cellsEditable?: boolean
34+
/** Whether columns can be resized. */
35+
columnsResizeable?: boolean
4336
/** Height of cells in pixels. */
4437
cellHeight?: number
4538
/** The state of the selected cell or cells in the table. */
@@ -578,6 +571,7 @@ export default function Table<K = string, T = unknown>(props: TableProps<K, T>)
578571
column={column}
579572
height={colHeaderHeight()}
580573
columnsEditable={props.columnsEditable}
574+
columnsResizeable={props.columnsResizeable}
581575
setColumnName={props.setColumnName}
582576
setColumnSize={props.setColumnSize}
583577
resetColumnSize={props.resetColumnSize}

stories/Basic.stories.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ export const BasicUsage: Story = {
4848
return newMap
4949
})
5050
}
51-
cellsEditable
52-
rowsEditable
53-
columnsEditable
5451
/>
5552
</div>
5653
)

stories/main.css

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@ body {
44

55
.table-wrap {
66
height: 100%;
7-
border: 2px solid black; /* oklch(48.011% 0.08557 182.905); */
87
border-radius: 6px;
98
overflow: hidden;
10-
font-size: 14px;
11-
/* --solid-tabular-accent-color: oklch(60% 0.118 184.704);
12-
--solid-tabular-font-size-row-num: 12px;
13-
--solid-tabular-text-color: red;
14-
--solid-tabular-rownum-color: blue; */
9+
/* --solid-tabular-accent-color: oklch(60% 0.118 184.704); */
1510
}

0 commit comments

Comments
 (0)