@workday/canvas-kit-react
Version:
The parent module that contains all Workday Canvas Kit React components
27 lines (26 loc) • 1.48 kB
JavaScript
import React from 'react';
import { mergeStyles } from '@workday/canvas-kit-react/layout';
import { createComponent } from '@workday/canvas-kit-react/common';
import { createStencil, createVars } from '@workday/canvas-kit-styling';
const tableRowChildrenVars = createVars({ id: "afe05d", args: ["cellNumber"] });
// Styles for rows including dynamic sizing for amount of cells within a row
const tableRowStencil = createStencil({
base: { name: "d5h45t", styles: "box-sizing:border-box;display:grid;grid-auto-flow:column;grid-template-columns:repeat(var(--cellNumber-afe05d), minmax(10rem, 1fr));" }
}, "table-row-787c4d");
export const TableRow = createComponent('tr')({
displayName: 'Table.Row',
Component: ({ children, ...elemProps }, ref, Element) => {
// This calculates the amount of valid React children cells within the row and will update the gridTemplateColumns style property with that amount of cells within the row
const validChildren = (children) => {
return React.Children.toArray(children).filter(child => React.isValidElement(child));
};
/**
* This is the calculated amount of valid React children
*/
const childrenArray = validChildren(children).length;
return (React.createElement(Element, { ref: ref, ...mergeStyles(elemProps, [
tableRowStencil(),
{ [tableRowChildrenVars.cellNumber]: childrenArray },
]) }, children));
},
});