UNPKG

@commercelayer/react-components

Version:
2 lines 825 B
"use client"; import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import{defaultGiftCardImgUrl,defaultImgUrl}from"../../utils/placeholderImages";import Parent from"../utils/Parent";export function LineItemImage(props){const{placeholder,children,...p}=props,{lineItem}=useContext(LineItemChildrenContext),itemType=lineItem?.item_type;let src=lineItem?.image_url;src||(placeholder?.[itemType]?src=placeholder?.[itemType]:src=itemType==="gift_cards"?defaultGiftCardImgUrl:defaultImgUrl);const parenProps={lineItem,src,placeholder,...p};return children?_jsx(Parent,{...parenProps,children}):src?_jsx("img",{"data-testid":`line-item-image-${lineItem?.sku_code??""}`,alt:lineItem?.name??"",src,...p}):null}export default LineItemImage;