MCPcopy
hub / github.com/primer/react / getGridTemplateFromColumns

Function getGridTemplateFromColumns

packages/react/src/DataTable/useTable.ts:290–330  ·  view source on GitHub ↗
(columns: Array<Column<Data>>)

Source from the content-addressed store, hash-verified

288}
289
290export function getGridTemplateFromColumns<Data extends UniqueRow>(columns: Array<Column<Data>>): string[] {
291 return columns.map(column => {
292 const columnWidth = column.width ?? 'grow'
293 let minWidth = 'auto'
294 let maxWidth = '1fr'
295
296 if (columnWidth === 'auto') {
297 maxWidth = 'auto'
298 }
299
300 // Setting a min-width of 'max-content' ensures that the column will grow to fit the widest cell's content.
301 // However, If the column has a max width, we can't set the min width to `max-content` because
302 // the widest cell's content might overflow the container.
303 if (columnWidth === 'grow' && !column.maxWidth) {
304 minWidth = 'max-content'
305 }
306
307 // Column widths set to "growCollapse" don't need a min width unless one is explicitly provided.
308 if (columnWidth === 'growCollapse') {
309 minWidth = '0'
310 }
311
312 // If a consumer passes `minWidth` or `maxWidth`, we need to override whatever we set above.
313 if (column.minWidth) {
314 minWidth = typeof column.minWidth === 'number' ? `${column.minWidth}px` : column.minWidth
315 }
316
317 if (column.maxWidth) {
318 maxWidth = typeof column.maxWidth === 'number' ? `${column.maxWidth}px` : column.maxWidth
319 }
320
321 // If a consumer is passing one of the shorthand widths or doesn't pass a width at all, we use the
322 // min and max width calculated above to create a minmax() column template value.
323 if (typeof columnWidth !== 'number' && ['grow', 'growCollapse', 'auto'].includes(columnWidth)) {
324 return minWidth === maxWidth ? minWidth : `minmax(${minWidth}, ${maxWidth})`
325 }
326
327 // If we reach this point, the consumer is passing an explicit width value.
328 return typeof columnWidth === 'number' ? `${columnWidth}px` : columnWidth
329 })
330}
331
332// eslint-disable-next-line @typescript-eslint/no-explicit-any
333function get<ObjectType extends Record<string, any>, Path extends string>(

Callers 2

DataTable.test.tsxFile · 0.90
useTableLayoutFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected