@lanaco/lnc-react-ui
Version:
React component library
366 lines (315 loc) • 15.6 kB
JavaScript
"use strict";const r=require("react/jsx-runtime"),l=require("react"),N=require("./emotion-styled.browser.esm-DwHBgTPn.cjs"),I=require("./breakpoints-CcVm-gVm.cjs"),t=require("./utils-BK6B_Y9X.cjs"),$e=require("./index-DOkcmaFO.cjs"),z=require("./Badge.cjs"),Ee=require("./Popover.cjs"),Fe=require("./PopoverTrigger.cjs"),ze=require("./PopoverContent.cjs"),De=require("./useDetectMobile-DYV6V1yw.cjs"),J=require("./Icon.cjs"),h=require("./style-17Ie7d9D.cjs"),Ve=N.styled.a`
display: flex;
flex-direction: column;
gap: 0.5rem;
cursor: pointer;
overflow: hidden;
width: 100%;
text-decoration: none;
color: var(--gray-950, #14161a);
position: relative;
& .prevent-el {
height: 0;
width: 0;
}
& .seller {
text-transform: uppercase;
${t.truncateText()}
color: var(--gray-500);
font-size: 0.625rem;
font-weight: 400;
}
& .wrapper-card-1 {
display: flex;
flex-direction: column;
gap: 0.12rem;
}
& .wrapper-card-2 {
display: flex;
flex-direction: column;
gap: 0;
}
& .wrapper-card-3 {
display: flex;
flex-wrap: wrap;
gap: 0.25rem;
& > div {
& > div {
width: 100% !important;
}
}
}
& .tag {
height: 1.5rem;
gap: 0.25rem;
padding: 0.25rem 0.375rem;
border-radius: 0.375rem;
background: #f9fafb;
border: 1px solid var(--gray-95012, #14161a1f);
font-weight: 400;
font-size: 0.75rem;
line-height: 1rem;
letter-spacing: 0.025rem;
color: var(--gray-950, #14161a);
white-space: nowrap;
flex: 0 0 auto;
& i {
color: var(--yellow-500, #f59e0b);
}
}
& .card-title {
font-size: 0.875rem;
font-weight: 600;
${t.truncateTextInRows(2)}
}
& .price-text {
font-size: 1rem;
font-weight: 600;
${t.truncateText()}
display: flex;
align-items: end;
gap: 0.5rem;
color: var(--gray-950, #14161a);
&.new-price {
color: var(--danger-600, #e11d48);
}
& .full-price {
text-decoration: line-through;
font-size: 0.75rem;
font-weight: 400;
padding-bottom: 0.125rem;
color: var(--gray-600, #676e79);
${t.truncateText()}
}
}
& .location-text {
font-size: 0.75rem;
font-weight: 400;
color: var(--gray-600, #676e79);
${t.truncateText()}
}
& .tags-wrapper {
display: flex;
gap: 0.5rem;
}
& .tags-popover__trigger {
display: flex;
gap: 0.25rem;
}
& .campaign-badges {
position: absolute;
top: 0.5rem;
left: 0.75rem;
display: flex;
gap: 0.25rem;
flex-wrap: wrap;
justify-content: flex-start;
z-index: 1;
width: max-content;
max-width: 7rem;
}
& .campaign-badge {
width: fit-content;
height: 1.5rem;
border-radius: 0.25rem;
display: flex;
align-items: center;
justify-content: center;
color: white;
font-size: 1rem;
padding-inline: 0.15rem;
i {
::before {
margin-inline: 0;
}
}
}
& .campaign-badge-adddiscount {
background-color: #f43f5e;
}
& .campaign-badge-freeshipping {
background-color: #1abc86;
}
& .campaign-badge-freequantity {
background-color: #2691d9;
}
& .campaign-badge-includegifts {
background-color: #8b5cf6;
}
& .campaign-badge-urgent {
background-color: #e11d48;
width: fit-content;
padding-inline: 0.5rem;
}
@media ${I.down("S")} {
overflow: visible;
& .wrapper-card-3 {
flex-wrap: nowrap;
justify-content: flex-start;
overflow-x: scroll;
width: 8.875rem !important;
-webkit-overflow-scrolling: touch;
::-webkit-scrollbar {
-webkit-appearance: none;
}
-ms-overflow-style: none;
/* Internet Explorer 10+ */
scrollbar-width: none;
/* Firefox */
&::-webkit-scrollbar {
display: none;
/* Safari and Chrome */
}
& > div {
& > div {
width: 8.875rem !important;
}
}
}
& .tags-popover__trigger {
overflow-x: scroll;
justify-content: flex-start;
width: 100%;
-webkit-overflow-scrolling: touch;
::-webkit-scrollbar {
-webkit-appearance: none;
}
-ms-overflow-style: none;
/* Internet Explorer 10+ */
scrollbar-width: none;
/* Firefox */
&::-webkit-scrollbar {
display: none;
/* Safari and Chrome */
}
}
& .price-text {
font-size: 0.875rem;
font-weight: 600;
& .full-price {
display: none;
}
}
}
&:hover .product-image-wrapper img {
transform: scale(1.1);
}
`,Re=N.styled.div`
position: relative;
overflow: hidden;
border-radius: 0.75rem;
width: 100%;
aspect-ratio: 1 / 1;
border: 1px solid #0c15201f;
& .bookmarking-btn {
position: absolute;
right: 0.5rem;
top: 0.5rem;
z-index: 1;
/* Always visible (no longer hover-only on desktop) so the
add-to-cart / save action is discoverable at first glance. */
display: flex;
align-items: center;
justify-content: center;
width: 2.25rem;
height: 2.25rem;
border-radius: ${d=>t.getBorderRadiusValueWithUnits(d.theme,"curved")};
border: 1px solid var(--gray-95008);
background-color: white;
color: var(--gray-950);
transition: transform 0.2s ease;
&:hover {
transform: scale(1.05);
background-color: white;
}
i {
color: #14161a;
font-size: 1.1rem;
line-height: 1;
}
}
& img {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
border-radius: 0.75rem;
transition: var(--transition, all 0.3s ease);
}
@media ${I.down("S")} {
& img {
width: 8.875rem;
height: 8.875rem;
min-width: 8.875rem;
min-height: 8.875rem;
object-fit: cover;
}
& .bookmarking-btn {
display: flex;
bottom: 0.5rem;
top: unset;
}
}
`,qe=N.styled.div`
background: var(--white, #fff);
z-index: 1;
border: 1px solid var(--gray-200, #dddfe4);
border-radius: 0.5rem;
line-height: 1rem;
position: absolute;
padding: 0.5rem 0.75rem;
top: 0.5rem;
left: 25%;
transform: translateX(-50%);
min-width: 13rem;
&::before,
&::after {
content: "";
position: absolute;
left: 50%;
transform: translateX(-50%);
border-style: solid;
border-width: 0.625rem;
}
&::after {
top: -1.1875rem;
border-color: transparent transparent var(--white, #fff) transparent;
}
&::before {
top: -1.25rem;
border-color: transparent transparent var(--gray-200, #dddfe4) transparent;
}
& .tags-popover__content {
display: flex;
flex-wrap: wrap;
flex-direction: column;
gap: 0.375rem;
font-size: 0.75rem;
font-weight: 400;
& .tags-popover__name {
color: var(--gray-600, #676e79);
}
& .tags-popover__value {
color: var(--gray-950, #14161a);
}
}
`,Ie=N.styled.div`
display: flex;
align-items: center;
gap: 0.25rem;
color: var(--gray-500);
font-size: 0.75rem;
font-weight: 500;
& i {
font-size: 1rem;
color: var(--warning-500, #F59E0B);
}
`,Oe=l.forwardRef(({sponsoredText:d="Sponsored"},w)=>r.jsxs(Ie,{ref:w,className:"sponsored-line",children:[r.jsx("i",{className:"mng-lnc-paw2"}),r.jsx("span",{children:d})]})),Ue="Vehicles_Cars",Be="Vehicles_Motorcycles",We="Vehicles_Trucks",Me="Vehicles_AgriculturalMachines_Tractors",Te="Vehicles_ConstructionMachines",Ge="Vehicles_Bus",Le="Vehicles_Campers",Ae="RealEstates_",s={Mileage:{icon:"mng-lnc-road",measure:"km"},YearOfProduction:{icon:"mng-lnc-calendar",measure:""},Fuel:{icon:"mng-lnc-gas-station",measure:""},EnginePowerKW:{icon:"mng-lnc-engine",measure:"kW"},Transmission:{icon:"mng-lnc-transmission",measure:""},Model:{icon:"mng-lnc-application",measure:""},Brand:{icon:"mng-lnc-car--front",measure:""},SurfaceArea:{icon:"mng-lnc-right-angle",measure:""},Floor:{icon:"mng-lnc-elevator",measure:""},FurnishedCondition:{icon:"mng-lnc-sofa-01",measure:""},AdType:{icon:"mng-lnc-notes",measure:""},NumberOfRooms:{icon:"mng-lnc-meeting-room",measure:""},HeatingType:{icon:"mng-lnc-heat",measure:""},AirConditioning:{icon:"mng-lnc-air-conditioner",measure:""},Type:{icon:"mng-lnc-house-building",measure:""},Parking:{icon:"mng-lnc-parking-area-circle",measure:""},Internet:{icon:"mng-lnc-wifi-02",measure:""},State:{icon:"mng-lnc-settings-1",measure:""},NumberOfPremises:{icon:"mng-lnc-meeting-room",measure:""},Pool:{icon:"mng-lnc-pool",measure:""},Approach:{icon:"mng-lnc-driveway",measure:""},NumberOfBeds:{icon:"mng-lnc-bed",measure:""},Kitchen:{icon:"mng-lnc-fridge",measure:""},BathroomToilet:{icon:"mng-lnc-bath",measure:""},default:{icon:" mng-lnc-clock--filled",measure:""}},y={ADDDISCOUNT:" mng-lnc-percentage",URGENT:" mng-lnc-flash",FREEQUANTITY:" mng-lnc-3d-software",INCLUDEGIFTS:" mng-lnc-gift",FREESHIPPING:" mng-lnc-delivery--parcel"},Xe=l.forwardRef((d,w)=>{const{uuid:m,sellerUuid:D,name:Z,price:S=0,sellingPrice:C,currency:_,isNegotiable:P,isFree:$,imageUrl:ee,location:re,sponsored:ne,imageComponent:O,freeText:oe="Free",negotiableText:te="Negotiable",tags:o=[],categoryCode:E,categoryName:ie,condition:U,quantity:V,trade:B,sponsoredText:se,forCart:ae,forOrder:ce,contactSeller:le,hasVariants:de,hasQuantities:me,status:pe,onBookmark:R=()=>{},actionComponent:b,bookmarked:W,bookmarkLists:ge,metadata:x,sellerName:M,nameSlug:F,onSelectCard:ue=()=>{},activeSalesPackages:p,urgentText:he="Urgent",LinkComponent:T,hasFreeShipping:fe}=d,ve=T||"a",q=De.useDetectMobile(),we=()=>{var c;if(!t.isDefined(b))return r.jsx(r.Fragment,{});const e=b,n=(c=b==null?void 0:b.props)==null?void 0:c.children,i=l.cloneElement(n,{key:`bookmark_pr__${W}`,bookmarked:W,productUuid:m,onAddToBookmark:()=>R(!0,m),onRemoveFromBookmark:()=>R(!1,m),bookmarkedUuidList:ge,sellerUuid:D,handleBookmarking:R,forCart:ae,forOrder:ce,contactSeller:le,hasVariants:de,status:pe,quantity:V,hasQuantities:me,productBasicInfo:{uuid:m,price:S,sellingPrice:C,categoryCode:E,categoryName:ie,currency:_,isNegotiable:P,isFree:$}});return l.cloneElement(e,void 0,i)},G=[Ue,Be,We,Me,Te,Ge,Le,Ae].some(e=>E==null?void 0:E.includes(e)),[be,L]=l.useState(!1),xe=()=>{L(!0)},je=()=>{L(!1)},a=l.useRef(null),f=l.useRef([]),[ye,A]=l.useState(o==null?void 0:o.length),Ce=()=>{var c,j,k;if(!(a!=null&&a.current)||((c=f==null?void 0:f.current)==null?void 0:c.length)===0)return;if(q){A(o==null?void 0:o.length);return}const e=(j=a==null?void 0:a.current)==null?void 0:j.offsetWidth;let n=0,i=0;for(let g=0;g<(o==null?void 0:o.length);g++){const v=((k=f==null?void 0:f.current[g])==null?void 0:k.offsetWidth)||0,u=n+v+4;if(u<=e)n+=u,i++;else break}A(i)};l.useEffect(()=>{const e=a==null?void 0:a.current;if(!e)return;const n=new ResizeObserver(()=>{Ce()});return n.observe(e),()=>{n.disconnect()}},[o,q]);const _e=()=>{var e;return r.jsx("div",{className:"tags-popover__trigger",children:(e=o==null?void 0:o.slice(0,ye))==null?void 0:e.map((n,i)=>{var v,u,H,K,Q;const c=((v=s==null?void 0:s[n==null?void 0:n.code])==null?void 0:v.icon)??((u=s==null?void 0:s.default)==null?void 0:u.icon)??"",j=((H=n==null?void 0:n.measurementUnit)==null?void 0:H.symbol)??((K=s==null?void 0:s[n==null?void 0:n.code])==null?void 0:K.measure)??"",g=[(n==null?void 0:n.value)??((Q=n==null?void 0:n.multiOptions)==null?void 0:Q[0])??"",j].filter(Boolean).join(" ");return r.jsxs(z,{ref:Pe=>f.current[i]=Pe,className:"tag",children:[r.jsx("i",{className:c}),g]},`detailed-products-section-tag__${i+1}`)})})},ke=()=>r.jsx("div",{className:"tags-popover__content",children:o==null?void 0:o.map((e,n)=>{var g,v,u;const i=((g=e==null?void 0:e.measurementUnit)==null?void 0:g.symbol)??((v=s==null?void 0:s[e==null?void 0:e.code])==null?void 0:v.measure)??"",j=[(e==null?void 0:e.value)??((u=e==null?void 0:e.multiOptions)==null?void 0:u[0])??"",i].filter(Boolean).join(" "),k=e==null?void 0:e.name;return r.jsxs("div",{children:[r.jsx("span",{className:"tags-popover__name",children:`${k}: `}),r.jsx("span",{className:"tags-popover__value",children:j})]},`detailed-products-section-tag-dropdown__${n+1}`)})}),Ne=()=>r.jsxs(r.Fragment,{children:[U&&r.jsx(z,{className:"tag",children:U},"detailed-products-section-tag__condition"),V&&r.jsx(z,{className:"tag",children:V},"detailed-products-section-tag__quantity"),B&&r.jsx(z,{className:"tag",children:B},"detailed-products-section-tag__trade")]}),X=S>0&&_&&P!==!0&&$!==!0&&S!==C,Se=p==null?void 0:p.some(e=>(e==null?void 0:e.salesPackageCode)==="FreeShipping"),Y=fe===!0&&!Se;return r.jsxs(Ve,{ref:a,className:"product-card","data-accessor":x==null?void 0:x.accessor,name:x==null?void 0:x.name,onClick:e=>ue(e,a),as:ve,...T?{to:`/product/${t.isDefinedNotEmptyString(F)?`${F}-`:""}${m}`}:{href:`/product/${t.isDefinedNotEmptyString(F)?`${F}-`:""}${m}`},children:[r.jsxs(Re,{className:"product-image-wrapper",children:[t.isDefined(b)&&r.jsx("div",{className:"prevent-el",onClick:e=>{e==null||e.preventDefault(),e==null||e.stopPropagation()},children:r.jsx(we,{})}),t.isDefined(O)?O:r.jsx($e.ProductImageWrapper,{src:ee})]}),(Y||p&&p.length>0)&&r.jsxs("div",{className:"campaign-badges",children:[Y&&r.jsx("div",{className:"campaign-badge campaign-badge-freeshipping",children:r.jsx(J,{icon:y==null?void 0:y.FREESHIPPING,sizeInUnits:"1rem"})}),p==null?void 0:p.map((e,n)=>{var i,c;return r.jsxs("div",{className:`campaign-badge campaign-badge-${(i=e==null?void 0:e.salesPackageCode)==null?void 0:i.toLowerCase()}`,children:[(e==null?void 0:e.salesPackageCode)!=="Urgent"&&r.jsx(J,{icon:y==null?void 0:y[(c=e==null?void 0:e.salesPackageCode)==null?void 0:c.toUpperCase()],sizeInUnits:"1rem"}),(e==null?void 0:e.salesPackageCode)==="Urgent"&&r.jsx(r.Fragment,{children:he})]},n)})]}),r.jsxs("div",{className:"wrapper-card-1",children:[r.jsx("div",{className:"seller",title:M,children:M}),r.jsx("div",{className:"card-title",children:Z})]}),r.jsxs("div",{className:"wrapper-card-3",onClick:e=>{e==null||e.preventDefault(),e==null||e.stopPropagation()},children:[G&&r.jsx("div",{...q?{}:{onMouseEnter:xe,onMouseLeave:je},children:r.jsxs(Ee,{placement:"bottom",open:be,children:[r.jsx(Fe,{children:_e()}),r.jsx(ze,{style:{all:"unset"},children:r.jsx(qe,{children:ke()})})]})}),!G&&Ne()]}),r.jsxs("div",{className:"wrapper-card-2",children:[r.jsxs("div",{className:`price-text ${X?"new-price":""}`,children:[C>0&&_&&P!==!0&&$!==!0&&r.jsx("div",{children:`${t.formatPrice(C)} ${t.GetCurrencySymbol(_)}`}),X&&r.jsx("div",{className:`${C>0?"full-price":""}`,children:`${t.formatPrice(S)} ${t.GetCurrencySymbol(_)}`}),P&&te,$&&oe]}),r.jsx("div",{className:"location-text",children:re})]}),ne===!0&&r.jsx(Oe,{sponsoredText:se})]})}),Ye=N.styled(h.SkeletonAnimationContainer)`
@media ${I.down("S")} {
& > div {
&:nth-of-type(even) {
display: none;
}
}
}
`,He=({keyPrefix:d})=>r.jsx(Ye,{children:[1,2,3,4,5].map(w=>r.jsxs(h.SkeletonColumnContainer,{gap:"0.5rem",children:[r.jsx(h.SkeletonSquare,{size:"13.75rem"}),r.jsx(h.SkeletonRect,{width:"100%"}),r.jsxs(h.SkeletonContainer,{gap:"0.5rem",children:[r.jsx(h.SkeletonRect,{width:"100%",height:"1rem"}),r.jsx(h.SkeletonRect,{width:"100%",height:"1rem"})]}),r.jsx(h.SkeletonRect,{width:"100%",height:"2rem"})]},`${d}-${w}`))}),Ke=({keyPrefix:d,isLoading:w=!1,fallbackComponent:m=r.jsx(r.Fragment,{}),children:D})=>r.jsx(l.Suspense,{fallbackComponent:m,children:w===!0?r.jsx(He,{keyPrefix:d}):D});exports.DetailedProductCard=Xe;exports.SuspenseDetailedProductCard=Ke;