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 10 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
89 changes: 89 additions & 0 deletions src/components/PurchaseSummary/PurchaseSummary.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { Meta, StoryObj } from '@storybook/react'
Copy link
Contributor

Choose a reason for hiding this comment

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

index.stories.tsx

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 = {
Copy link
Contributor

Choose a reason for hiding this comment

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

This name is used when displaying stories. It would be interesting to use WithDiscounts and WithoutDiscounts discounts. (or something similar)
This will be displayed as: With Discouts, Without Discouts.

args: {
productsLabel: 'Valor dos produtos',
deliveryValue: 'Valor da entrega',
totalitems: 2,
labelItensText: 'itens',
productsPrice: 178.6,
deliveryCost: 15.0,
totalDiscount: 29.35,
totalPrice: 90,
installmentPayment: '2x de 59,85 sem juros',
discounts: [],
joelsalmeida marked this conversation as resolved.
Show resolved Hide resolved
},
render: (args) => <PurchaseSummary {...args} />,
}

export const Default: Story = {
name: 'Default',
args: {
title: '',
productsLabel: 'Valor dos produtos',
deliveryValue: 'Valor da entrega',
totalitems: 1,
labelItensText: 'item',
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'
joelsalmeida marked this conversation as resolved.
Show resolved Hide resolved
import { Colors, mediaQueries } from '../../../tokens'

export const AccordionContainer = styled.div`
Copy link
Contributor

Choose a reason for hiding this comment

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

All styled components come with the Styled suffix. (AccordionContainerStyled, AccordionHeaderStyled, AccordionContentStyled...)
This way it is easier to differentiate common components from styled components.

margin: 0;
padding: 0;
box-sizing: border-box;
font-size: 14px;
`

export const AccordionHeader = styled.div`
width: 100%;
background-color: ${Colors.light.neutral.neutral100};
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: ${Colors.light.action.action100};
}
`
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 = {
title: string
value: number | string
listDiscount?: Array<DiscountItem>
}

export type { PurchaseSummaryAccordionProps }
81 changes: 81 additions & 0 deletions src/components/PurchaseSummary/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import React from 'react'
joelsalmeida marked this conversation as resolved.
Show resolved Hide resolved
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> = ({
title,
productsLabel,
deliveryValue,
totalitems,
joelsalmeida marked this conversation as resolved.
Show resolved Hide resolved
labelItensText,
productsPrice,
deliveryCost,
totalDiscount,
totalPrice,
installmentPayment,
discounts,
}) => {
const hasDiscounts = discounts && discounts.length > 0;

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

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

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

<LineDivider />

<Footer>
<FooterTitle>Total</FooterTitle>
<FooterItems>
<Total>R${totalPrice}</Total>
{installmentPayment && <PaymentInstallments>{installmentPayment}</PaymentInstallments>}
</FooterItems>
</Footer>
</Container>
)
}

export { PurchaseSummary }
Loading