UNPKG

@commercelayer/react-components

Version:
2 lines 820 B
"use client"; import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useState,useEffect}from"react";import Parent from"../utils/Parent";import getLineItemsCount from"../../utils/getLineItemsCount";import LineItemContext from"../../context/LineItemContext";export function LineItemsEmpty(props){const{children,text="Your shopping bag is empty",...p}=props,{lineItems}=useContext(LineItemContext),[quantity,setQuantity]=useState(),emptyText=quantity===0?_jsx("span",{...p,children:text}):null;useEffect(()=>{if(lineItems)if(lineItems.length>0){const qty=getLineItemsCount({lineItems:lineItems||[]});setQuantity(qty)}else setQuantity(0);return()=>{setQuantity(void 0)}},[lineItems]);const parentProps={quantity,text,...p};return children?_jsx(Parent,{...parentProps,children}):emptyText}export default LineItemsEmpty;