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

Tec 4141 front resumo componentes de subtotais ds #24

Merged
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chardonnay",
"version": "1.0.22",
"version": "1.0.23",
"description": "A mobile first frontend framework made with wine",
"homepage": "https://vissimo-group.github.io/chardonnay/",
"main": "./dist/index.js",
Expand Down
87 changes: 87 additions & 0 deletions src/components/PurchaseSummary/PurchaseSummary.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { Meta, StoryObj } from '@storybook/react'
import { PurchaseSummary } from './index'
import { PurchaseSummaryProps } from './type'

export default {
title: 'Components/PurchaseSummary',
component: PurchaseSummary,
tags: ['autodocs'],
argTypes: {
description: {
control: 'text',
},
totalitems: {
control: 'text',
},
productsPrice: {
control: 'number',
},
deliveryCost: {
control: 'number',
},
totalDiscount: {
control: 'number',
},
totalPrice: {
control: 'number',
},
installmentPayment: {
control: 'text',
},
discounts: {
control: 'object',
},
},
decorators: [
(Story) => (
<div style={{ padding: '16px', backgroundColor: '#f0f0f0' }}>
<Story />
</div>
),
],
} as Meta<PurchaseSummaryProps>

type Story = StoryObj<PurchaseSummaryProps>

export const EmptyDiscounts: Story = {
args: {
productsLabel: 'Valor dos produtos',
deliveryValue: 'Valor da entrega',
totalitems: 2,
productsPrice: 178.6,
deliveryCost: 15.0,
totalDiscount: 29.35,
totalPrice: 90,
installmentPayment: '2x de 59,85 sem juros',
discounts: [],
},
render: (args) => <PurchaseSummary {...args} />,
}

export const Default: Story = {
name: 'Default',
args: {
title: '',
productsLabel: 'Valor dos produtos',
deliveryValue: 'Valor da entrega',
totalitems: 1,
productsPrice: 178.6,
deliveryCost: 15.0,
totalDiscount: 29.35,
totalPrice: 90,
installmentPayment: '2x de 59,85 sem juros',
discounts: [
{
id: 1,
title: 'Cupom de desconto',
value: '31,00',
},
{
id: 2,
title: 'Cashback',
value: '11,50',
},
],
},
render: (args) => <PurchaseSummary {...args} />,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { useState } from 'react'
import { ChevronDown, ChevronUp } from 'semillon'
import {
AccordionContainer,
AccordionHeader,
AccordionContent,
AccordionItem,
} from './style'
import { PurchaseSummaryAccordionProps } from './type'

export function PurchaseSummaryAccordion({
title,
value,
listDiscount,
}: PurchaseSummaryAccordionProps) {
const [isOpen, setIsOpen] = useState(false)

const toggleAccordion = () => {
setIsOpen(!isOpen)
}

return (
<AccordionContainer>
<AccordionHeader onClick={toggleAccordion}>
<span>{title}</span>
<span className="chevronIcon">
{isOpen ? (
<ChevronDown size={16} color="#1C1C1C" />
) : (
<ChevronUp size={16} color="#1C1C1C" />
)}
</span>
<span className="priceHeader">-{value}</span>
</AccordionHeader>

{isOpen && listDiscount && listDiscount.length > 0 && (
<AccordionContent>
<ul>
{listDiscount.map((item) => (
<AccordionItem key={item.id}>
<li>{item.title}</li>
<span className="itemValue">-R$ {item.value}</span>
</AccordionItem>
))}
</ul>
</AccordionContent>
)}
</AccordionContainer>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import styled from 'styled-components'
import { Colors, mediaQueries } from '../../../tokens'

export const AccordionContainer = styled.div`
margin: 0;
padding: 0;
box-sizing: border-box;
font-size: 14px;
`

export const AccordionHeader = styled.div`
width: 100%;
background-color: ${Colors.light.neutral.neutral100};
juninhokaponne marked this conversation as resolved.
Show resolved Hide resolved
color: ${Colors.light.neutral.neutral500};

display: flex;
justify-content: space-between;
cursor: pointer;
margin-bottom: 8px !important;

.chevronIcon {
color: ${Colors.light.neutral.neutral100};
font-size: 14px;
cursor: pointer;
display: flex;
align-items: center;
margin-left: 7px;
}

.priceHeader {
margin-left: auto;
cursor: pointer;
color: ${Colors.light.feedback.feedbackInfo100};
}
`

export const AccordionContent = styled.div`
display: flex;
flex-direction: column;
justify-content: space-between;

ul {
padding: 0 0 0 11px;
margin: 0;
}

@media screen and (max-width: ${mediaQueries.screenXxs}) {
ul {
padding: 0 0 0 8px;
font-size: 12px;

li {
font-size: 12px;
}
}
}
`

export const AccordionItem = styled.li`
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
padding-left: 16px;

li {
font-size: 14px;
color: ${Colors.light.neutral.neutral500};
padding-left: 8px;
}

.itemValue {
color: #03A678;
}
`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We always use the export pattern at the end of the file.
export { AccordionHeaderStyled, AccordionContentStyled, ... }

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { DiscountItem } from '../type'

type PurchaseSummaryAccordionProps = {
samuelvermeuln marked this conversation as resolved.
Show resolved Hide resolved
title: string
value: number | string
listDiscount: Array<DiscountItem>
}

export type { PurchaseSummaryAccordionProps }
85 changes: 85 additions & 0 deletions src/components/PurchaseSummary/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import React from 'react'
import { PurchaseSummaryProps } from './type'
import {
Container,
Title,
ItemContainer,
ItemText,
ProductsPrice,
DeliveryPrice,
ItemsTitle,
LineDivider,
Footer,
FooterItems,
FooterTitle,
PaymentInstallments,
Total,
} from './style'

import { PurchaseSummaryAccordion } from './PurchaseSummaryAccordion/index'

const PurchaseSummary: React.FC<PurchaseSummaryProps> = ({
samuelvermeuln marked this conversation as resolved.
Show resolved Hide resolved
title,
productsLabel,
deliveryValue,
totalitems,
productsPrice,
deliveryCost,
totalDiscount,
totalPrice,
installmentPayment,
discounts,
}) => {
const itemsTitleText = totalitems <= 1 ? 'item' : 'itens';
const hasDiscounts = discounts && discounts.length > 0;

const formatPrice = (price: number): string => {
samuelvermeuln marked this conversation as resolved.
Show resolved Hide resolved
return `R$ ${price.toFixed(2).replace('.', ',')}`;
};

return (
<Container>
{title && <Title>{title}</Title>}
<ItemContainer>
<ItemText>
{productsLabel}
<ItemsTitle>
({totalitems} {itemsTitleText})
</ItemsTitle>
<ProductsPrice>{formatPrice(productsPrice)}</ProductsPrice>
</ItemText>
</ItemContainer>

{deliveryValue && (
<ItemContainer>
<ItemText>
{deliveryValue}
<DeliveryPrice >{formatPrice(deliveryCost)}</DeliveryPrice>
</ItemText>
</ItemContainer>
)}

{hasDiscounts && (
<ItemContainer>
<PurchaseSummaryAccordion
title="Total de descontos"
value={formatPrice(totalDiscount)}
listDiscount={discounts}
/>
</ItemContainer>
)}

<LineDivider />

<Footer>
<FooterTitle>Total</FooterTitle>
<FooterItems>
<Total>R${totalPrice.toFixed(2).replace('.', ',')}</Total>
{installmentPayment && <PaymentInstallments>{installmentPayment}</PaymentInstallments>}
</FooterItems>
</Footer>
</Container>
)
}

export { PurchaseSummary }
Loading