-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from 10 commits
a5d7b93
bb237c8
acb6c7a
ff81386
7ccbe56
94825c4
6d9ebc7
8d43001
6fd9bf1
9b2fe88
247d210
da04e91
af34aed
a55ae12
0dc90fc
6617a3b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
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 = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) |
||
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` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All styled components come with the Styled suffix. (AccordionContainerStyled, AccordionHeaderStyled, AccordionContentStyled...) |
||
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}; | ||
} | ||
` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We always use the export pattern at the end of the file. |
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 } |
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 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
index.stories.tsx