UNPKG

@commercelayer/react-components

Version:
2 lines 1.45 kB
"use client"; import{createElement as _createElement}from"react";import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";import{useContext}from"react";import Parent from"../utils/Parent";import OrderListChildrenContext from"../../context/OrderListChildrenContext";import isDate from"../../utils/isDate";import last from"lodash/last";import{flexRender}from"@tanstack/react-table";export function OrderListRow({field,children,...p}){const{order,row,showActions,actionsComponent,actionsContainerClassName}=useContext(OrderListChildrenContext),cell=row?.getVisibleCells().filter(cell2=>cell2.column.id===field),isLastRow=last(row?.getVisibleCells())?.column.id===field,As="td",ActionRow=()=>showActions&&isLastRow&&actionsComponent&&_jsx(As,{"data-testid":"action-cell",...p,className:actionsContainerClassName,children:_jsx(Parent,{...parentProps,children:actionsComponent})})||null,parentProps={...p,field,order,row,cell};return children?_jsxs(_Fragment,{children:[_jsx(As,{children:_jsx(Parent,{...parentProps,children})}),_jsx(ActionRow,{})]}):_jsxs(_Fragment,{children:[cell?.map((cell2,k)=>{const cellValue=cell2.getValue(),value=isDate(cellValue)?new Date(Date.parse(cellValue)).toLocaleString():flexRender(cell2.column.columnDef.cell,cell2.getContext());return _createElement(As,{"data-testid":`cell-${k}`,...p,key:cell2.id},value)}),_jsx(ActionRow,{})]})}OrderListRow.displayName="OrderListRow";export default OrderListRow;