Skip to content

Commit 9da2c52

Browse files
authored
Merge pull request #1198 from interval/table-cell-bgcolor
Support highlight colors on table cells
2 parents b69f0a9 + 6619ba4 commit 9da2c52

3 files changed

Lines changed: 101 additions & 3 deletions

File tree

src/examples/basic/table.ts

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { IntervalActionDefinition } from '@interval/sdk/src/types'
2-
import { IntervalActionHandler, Page, Layout, io } from '../..'
2+
import { IntervalActionHandler, Action, Page, Layout, io } from '../..'
33
import { faker } from '@faker-js/faker'
44
import fakeUsers from '../utils/fakeUsers'
55
import { generateRows } from '../utils/helpers'
@@ -65,6 +65,7 @@ export const display_table: IntervalActionHandler = async io => {
6565
url: row.image,
6666
size: 'small',
6767
},
68+
backgroundColor: 'rgba(0, 60, 255, 0.3)',
6869
}),
6970
},
7071
{
@@ -116,6 +117,88 @@ export const display_table: IntervalActionHandler = async io => {
116117
})
117118
}
118119

120+
export const highlighted_rows = new Action(async () => {
121+
const data = generateRows(50)
122+
123+
const backgroundColor = await io.input.text('Background color', {
124+
helpText: 'CSS string value',
125+
defaultValue: 'rgba(0, 60, 255, 0.3)',
126+
})
127+
128+
await io.select.table('Select users', {
129+
data,
130+
defaultPageSize: 50,
131+
columns: [
132+
{
133+
label: 'User',
134+
renderCell: row => ({
135+
label: row.name,
136+
image: {
137+
alt: 'Alt tag',
138+
url: row.image,
139+
size: 'small',
140+
},
141+
backgroundColor: row.boolean ? backgroundColor : undefined,
142+
}),
143+
},
144+
{
145+
label: 'Email',
146+
renderCell: row => ({
147+
url: `mailto:${row.email}`,
148+
label: row.email,
149+
backgroundColor: row.boolean ? backgroundColor : undefined,
150+
}),
151+
},
152+
{
153+
label: 'Description',
154+
accessorKey: 'description',
155+
renderCell: row => ({
156+
label: row.description,
157+
backgroundColor: row.boolean ? backgroundColor : undefined,
158+
}),
159+
},
160+
{
161+
label: 'Date',
162+
accessorKey: 'date',
163+
renderCell: row => ({
164+
label: row.date,
165+
backgroundColor: row.boolean ? backgroundColor : undefined,
166+
}),
167+
},
168+
],
169+
rowMenuItems: row => [
170+
{
171+
label: 'Edit',
172+
route: 'edit_user',
173+
params: { email: row.email },
174+
},
175+
{
176+
label: 'Edit',
177+
route: 'edit_user',
178+
params: { email: row.email },
179+
disabled: true,
180+
},
181+
{
182+
label: 'Delete',
183+
route: 'delete_user',
184+
params: { email: row.email },
185+
theme: 'danger',
186+
},
187+
{
188+
label: 'Delete',
189+
route: 'delete_user',
190+
params: { email: row.email },
191+
theme: 'danger',
192+
disabled: true,
193+
},
194+
{
195+
label: 'External',
196+
url: 'https://google.com',
197+
},
198+
],
199+
})
200+
})
201+
119202
export const multiple_tables: IntervalActionHandler = async io => {
120203
await io.group([
121204
io.display.table('Display users', {

src/ioSchema.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,19 @@ export const richSelectOption = z
175175

176176
export type RichSelectOption = z.infer<typeof richSelectOption>
177177

178+
export const highlightColor = z.enum([
179+
'red',
180+
'orange',
181+
'yellow',
182+
'green',
183+
'blue',
184+
'purple',
185+
'pink',
186+
'gray',
187+
])
188+
189+
export type HighlightColor = z.infer<typeof highlightColor>
190+
178191
// non-primitive display types such as links, images, etc.
179192
export const advancedPrimitive = z.object({
180193
label: z.string().optional(),
@@ -211,6 +224,7 @@ export const tableRowValue = z.union([
211224
action: z.string().optional(),
212225
route: z.string().optional(),
213226
params: serializableRecord.optional(),
227+
backgroundColor: highlightColor.optional(),
214228
}),
215229
])
216230

src/types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import type {
1919
SerializableRecord,
2020
LegacyLinkProps,
2121
T_IO_MULTIPLEABLE_METHOD_NAMES,
22+
HighlightColor,
2223
} from './ioSchema'
2324
import type {
2425
AccessControlDefinition,
@@ -518,10 +519,10 @@ export type TableColumnResult =
518519
} & ({ url: string } | { buffer: Buffer })
519520
url?: string
520521
route?: string
521-
// Deprecated in favor of `route`
522-
// TODO: Add TS deprecation soon
522+
/** @deprecated Please use `route` instead. */
523523
action?: string
524524
params?: z.infer<typeof serializableRecord>
525+
highlightColor?: HighlightColor
525526
}
526527
| TableCellValue
527528

0 commit comments

Comments
 (0)