import type {CartLineUpdateInput} from '@shopify/hydrogen/storefront-api-types'; import type {CartLayout, LineItemChildrenMap} from '~/components/CartMain'; import {CartForm, Image, type OptimisticCartLine} from '@shopify/hydrogen'; import {useVariantUrl} from '~/lib/variants'; import {Link} from 'react-router'; import {ProductPrice} from './ProductPrice'; import {useAside} from './Aside'; import type { CartApiQueryFragment, CartLineFragment, } from 'storefrontapi.generated'; export type CartLine = OptimisticCartLine; function optionSummary(selectedOptions: CartLineFragment['merchandise']['selectedOptions']) { if (!selectedOptions?.length) return null; const values = selectedOptions .map((o) => (o.value ?? '').trim()) .filter(Boolean) .filter((v) => v.toLowerCase() !== 'default title'); return values.length ? values.join(' · ') : null; } /** * Trash icon — Figma cart line remove (node 123:13655). */ function TrashIcon() { return ( ); } export function CartLineItem({ layout, line, childrenMap, }: { layout: CartLayout; line: CartLine; childrenMap: LineItemChildrenMap; }) { const {id, merchandise} = line; const {product, title, image, selectedOptions} = merchandise; const lineItemUrl = useVariantUrl(product.handle, selectedOptions); const {close} = useAside(); const lineItemChildren = childrenMap[id]; const childrenLabelId = `cart-line-children-${id}`; const vendorEyebrow = product.vendor?.trim(); const variantLine = optionSummary(selectedOptions); if (layout === 'aside') { return (
  • {image ? {title} : null}
    {vendorEyebrow ?

    {vendorEyebrow}

    : null}

    {product.title}

    {variantLine ?

    {variantLine}

    : null}
    {lineItemChildren ?

    Line items with {product.title}

      {lineItemChildren.map((childLine) => ( ))}
    : null}
  • ); } return (
  • {image && ( {title} )}
    { if (layout === 'aside') { close(); } }} >

    {product.title}

      {selectedOptions .filter( (option) => (option.value ?? '').trim().toLowerCase() !== 'default title', ) .map((option) => (
    • {option.name}: {option.value}
    • ))}
    {lineItemChildren ? (

    Line items with {product.title}

      {lineItemChildren.map((childLine) => ( ))}
    ) : null}
  • ); } function CartLineQuantity({line, layout}: {line: CartLine; layout: CartLayout}) { if (!line || typeof line?.quantity === 'undefined') return null; const {id: lineId, quantity, isOptimistic} = line; const prevQuantity = Number(Math.max(0, quantity - 1).toFixed(0)); const nextQuantity = Number((quantity + 1).toFixed(0)); const wrapClass = layout === 'aside' ? 'cart-line-qty-abiir' : 'cart-line-quantity'; return (
    {layout !== 'aside' ? Quantity: {quantity}    : null} {layout === 'aside' ? {quantity} : ( <>   )} {layout !== 'aside' ? <>   : null}
    ); } function CartLineRemoveButton({ lineIds, disabled, icon = false, }: { lineIds: string[]; disabled: boolean; icon?: boolean; }) { return ( ); } function CartLineUpdateButton({ children, lines, }: { children: React.ReactNode; lines: CartLineUpdateInput[]; }) { const lineIds = lines.map((line) => line.id); return ( {children} ); } function getUpdateKey(lineIds: string[]) { return [CartForm.ACTIONS.LinesUpdate, ...lineIds].join('-'); }