Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update #63

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21,799 changes: 0 additions & 21,799 deletions .decofile.json

This file was deleted.

5 changes: 3 additions & 2 deletions components/container/Container.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Section } from "$live/blocks/section.ts";
import { headerHeight } from "$store/components/header/constants.ts";
import { clx } from "deco-sites/hospitalar/sdk/clx.tsx";

export type VerticalSpacing = "top" | "bottom" | "both" | "none";
export type ShadowSize =
Expand Down Expand Up @@ -50,10 +51,10 @@ function Container({ sections, isHeader = false }: Props) {
},
) => (
<div
class={`w-full
class={clx(`w-full
${VERTICAL_SPACING[verticalSpacing]}
${SPACING[spacing]}
${SHADOW_SIZE[shadow]}`}
${SHADOW_SIZE[shadow]}`)}
style={backgroundColor && { background: `${backgroundColor}` }}
>
{withContainer
Expand Down
9 changes: 5 additions & 4 deletions components/product/ProductCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Image from "deco-sites/std/components/Image.tsx";
import DiscountBadge from "./DiscountBadge.tsx";
import TagWarning from "deco-sites/hospitalar/components/ui/TagWarning.tsx";
import FreeShipping from "deco-sites/hospitalar/components/product/FreeShipping.tsx";
import { clx } from "deco-sites/hospitalar/sdk/clx.tsx";

export interface Layout {
basics?: {
Expand Down Expand Up @@ -250,7 +251,7 @@ function ProductCard(
>
{/* Wishlist button */}
<div
class={`absolute top-2 z-10
class={clx(`absolute top-2 z-10
${l?.elementsPositions?.favoriteIcon === "Top left"
? "left-2"
: "right-2"
Expand All @@ -259,7 +260,7 @@ function ProductCard(
? ""
: ""
}
`}
`)}
>
<WishlistIcon productGroupID={productGroupID} productID={productID} />
</div>
Expand All @@ -273,7 +274,7 @@ function ProductCard(
alt={front.alternateName}
width={WIDTH}
height={HEIGHT}
class={`
class={clx(`
absolute rounded-lg w-full
${(!l?.onMouseOver?.image ||
l?.onMouseOver?.image == "Change image")
Expand All @@ -284,7 +285,7 @@ function ProductCard(
? "duration-100 transition-scale scale-100 lg:group-hover:scale-105"
: ""
}
`}
`)}
sizes="(max-width: 640px) 50vw, 20vw"
preload={preload}
loading={preload ? "eager" : "lazy"}
Expand Down
156 changes: 121 additions & 35 deletions components/product/ProductShelf.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { useOffer } from "$store/sdk/useOffer.ts";
import type { Product } from "apps/commerce/types.ts";
import { mapProductToAnalyticsItem } from "apps/commerce/utils/productToAnalyticsItem.ts";
import { useId } from "preact/hooks";
import { clx } from "deco-sites/hospitalar/sdk/clx.tsx";
import { FnContext, SectionProps } from "deco/mod.ts";

export interface Props {
products: LoaderReturnType<Product[] | null>;
Expand All @@ -31,19 +33,24 @@ export interface Props {
showPaginationArrows?: ResponsiveConditionals;
cardLayout?: CardLayout;
IdCollection?: string;
/**@title Slide de 2 linhas? */
slideTwoRow?:boolean;
}

interface DotsProps {
images?: Product[];
interval?: number;
className: string;
slideTwoRow?:boolean;
}

function Dots({ images, interval = 0 }: DotsProps) {
function Dots({ images, interval = 0, slideTwoRow }: DotsProps) {
return (
<>
<ul
class={`carousel justify-center col-span-full gap-2 z-10 row-start-4`}
class={clx(`${slideTwoRow
? 'absolute -bottom-12 lg:bottom-[0] w-full flex gap-x-[0.5rem] justify-center'
: 'carousel justify-center col-span-full gap-2 z-10 row-start-4 max-lg:mt-[0.625rem]'}`)}
>
{images?.map((_, index) => (
<li class="carousel-item">
Expand All @@ -66,22 +73,44 @@ function Dots({ images, interval = 0 }: DotsProps) {
);
}

function ProductShelf({
products,
title,
layout,
cardLayout,
showPaginationArrows,
IdCollection,
}: Props) {

function ProductShelf(props: SectionProps<ReturnType<typeof loader>>) {
const id = useId();
const {
products,
title,
layout,
cardLayout,
showPaginationArrows,
IdCollection,
slideTwoRow = false,
device} = props;

if (!products || products.length === 0) {
return null;
}


function redesignArray( products: [] ): [Product[]]{
let arrayProducts = [];

products.forEach(( product, index )=>{
if( index === 0 || index % 2 === 0 ){
arrayProducts.push( [ product ] )
}
else if( index % 2 !== 0 ){
arrayProducts[arrayProducts.length -1].push( product );
}
})

return arrayProducts;
}

return (
<div class="w-full pb-8 flex flex-col lg:gap-7 lg:pb-10">
<div
class={clx(`${slideTwoRow
? 'container w-full m-auto px-5 max-lg:mb-20 max-lg:mt-10'
: 'w-full pb-8 flex flex-col lg:gap-7 lg:pb-10' }`)}>
<div class="flex items-center justify-between relative pb-3">
<Header
title={title || ""}
Expand All @@ -94,32 +123,82 @@ function ProductShelf({

<div
id={id}
class="grid grid-cols-[48px_1fr_48px] px-0 grid-rows-[1fr_48px_1fr_48px]"
class={clx(`${slideTwoRow
? 'container flex w-full relative'
: 'grid grid-cols-[48px_1fr_48px] px-0 grid-rows-[1fr_48px_1fr_48px]'}`)}
>
<Slider class="carousel carousel-start gap-6 col-span-full row-span-full py-2 mb-12">
{products?.map((product, index) => (
<Slider.Item
index={index}
class="carousel-item w-[270px]"
>
<ProductCard
product={product}
itemListName={title}
layout={cardLayout}
IdCollection={IdCollection ?? "156"}
tagWarningWidth="80%"
/>
</Slider.Item>
))}
</Slider>

{slideTwoRow
? (
<Slider
class={clx(`container carousel carousel-start flex max-lg:overflow-hidden`)}>

{device === 'mobile' && products?.map((product, index) => {
return(
<Slider.Item
index={index}
class={clx(`carousel-item w-[335px]`)}
>
<ProductCard
product={product}
itemListName={title}
layout={cardLayout}
IdCollection={IdCollection ?? "156"}
tagWarningWidth="80%"
/>
</Slider.Item>
)
})}
{ slideTwoRow && device === 'desktop' && redesignArray(products).map(( produtosInternos , index) => {
return(
<Slider.Item
index={index}
class={clx(`carousel-item w-[calc(100%_/_4)] flex flex-col`)}
>
{ produtosInternos?.map(( product )=>(
<ProductCard
product={product}
itemListName={title}
layout={cardLayout}
IdCollection={IdCollection ?? "156"}
tagWarningWidth="80%"
/>
)) }
</Slider.Item>
)
})}
</Slider>
)
: (
<Slider
class={clx(`container carousel carousel-start gap-6 col-span-full row-span-full py-2 mb-8 lg:mb-0'}`)}>
{products?.map((product, index) => {
return(
<Slider.Item
index={index}
class={clx(`carousel-item lg:w-[270px] ${slideTwoRow ? 'max-lg:w-[335px]' : ''}`)}
>
<ProductCard
product={product}
itemListName={title}
layout={cardLayout}
IdCollection={IdCollection ?? "156"}
tagWarningWidth="80%"
/>
</Slider.Item>
)
})}
</Slider>
)
}

<>
<div
class={`flex items-center justify-center z-10 col-start-1 row-start-2 ${
class={clx(`flex items-center justify-center z-10 col-start-1 row-start-2 ${
CONDITIONAL_RESPONSIVE_PARAMS[
showPaginationArrows ? showPaginationArrows : "Always"
]
}`}
]}
${slideTwoRow ? 'absolute top-2/4 -translate-y-1/2 max-lg:left-5' : ''}`)}
>
<Slider.PrevButton
style={{
Expand All @@ -134,12 +213,11 @@ function ProductShelf({
</Slider.PrevButton>
</div>
<div
class={`flex items-center justify-center z-10 col-start-3 row-start-2 ${
class={clx(`flex items-center justify-center z-10 col-start-3 row-start-2 ${
CONDITIONAL_RESPONSIVE_PARAMS[
showPaginationArrows ? showPaginationArrows : "Always"
]
}`}
>
]}
${slideTwoRow ? 'absolute top-2/4 -translate-y-1/2 lg:right-0 right-5' : ''}`)}>
<Slider.NextButton
style={{
minHeight: "28px",
Expand All @@ -155,6 +233,7 @@ function ProductShelf({
<Dots
images={products}
className={CONDITIONAL_RESPONSIVE_PARAMS["Always"]}
slideTwoRow={slideTwoRow}
/>
</>

Expand Down Expand Up @@ -188,4 +267,11 @@ function ProductShelf({
);
}

export const loader = (props: Props, _req: Request, ctx: FnContext) => {
return {
...props,
device: ctx.device,
};
};

export default ProductShelf;
83 changes: 83 additions & 0 deletions components/ui/CustomBefefitsDesktop.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import Image from "apps/website/components/Image.tsx";
import type { ImageWidget } from "apps/admin/widgets.ts";
import { clx } from "deco-sites/hospitalar/sdk/clx.tsx";

interface TextGeneric{
/**@title Título */
title?: string;
/**@title Descrição */
description?: string;
}

/**@titleBy alt */
interface ImageGeneric{
/**@title Nome da Imagem */
alt?: string;
/**@title Imagem */
src?:ImageWidget;
/**
* @title Largura
* @description (ex: 250)
* */
width?: number;
/**
* @title altura
* @description (ex: 250)
* */
height?:number;
}

interface Icon{
/**@title Imagem */
image?: ImageGeneric;
/**@title Texto */
text?: TextGeneric;
}

interface Props{
/**
* @title Imagem
* @maxItems 4
*/
icon?: Icon[];
}

function CustomBefefitsDesktop( { icon } : Props ){
return(
<>
<div
class={clx(`container w-full px-5 mx-[auto] my-[2.5rem]`)}>
<div
class={clx(`flex justify-between`)}>
{icon && icon.length > 0 && icon.map(( item, index )=>{
return(
<>
<div class={clx(`flex gap-x-[0.875rem]`)}>
{item.image && item.image.src && item.image.width && item.image.height && (
<Image
src={item.image.src}
width={item.image.width}
height={item.image?.height}
alt={item.image?.alt || `Ícone Benefícios ${index}`}
loading="lazy"
/>
) }

{item.text && item.text.title && item.text.description && (
<div>
<p class={clx(`font-bold text-[1.188rem] leading-[1.544rem]`)}> { item.text.title } </p>
<p class={clx(`font-normal text-base leading-[1.25rem]`)}> { item.text.description } </p>
</div>
)}

</div>
</>
)
})}
</div>
</div>
</>
)
}

export default CustomBefefitsDesktop;
Loading
Loading