-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
376 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export { default } from './ProgressBar' | ||
export { ProgressBarProps } from './ProgressBar' | ||
export type { ProgressBarProps } from './ProgressBar' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
packages/components/src/molecules/ProgressStatus/ProgressStatus.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React, { forwardRef, type HTMLAttributes, type ReactNode } from 'react' | ||
import ProgressBar from '../../atoms/ProgressBar' | ||
|
||
export interface ProgressStatusProps extends HTMLAttributes<HTMLDivElement> { | ||
/** | ||
* The progress status value. | ||
*/ | ||
progressValue: number | ||
/** | ||
* The left side element. Most of time it's gonna be a label | ||
*/ | ||
leftSideElement?: string | ReactNode | ||
/** | ||
* The left side element. Most of time it's gonna be a label | ||
*/ | ||
rightSideElement?: string | ReactNode | ||
/** | ||
* Optional test ID for testing. | ||
*/ | ||
testId?: string | ||
} | ||
|
||
export const ProgressStatus = forwardRef<HTMLDivElement, ProgressStatusProps>( | ||
function ProgressStatus( | ||
{ | ||
progressValue, | ||
leftSideElement, | ||
rightSideElement, | ||
testId = 'fs-progress-status', | ||
...props | ||
}, | ||
ref | ||
) { | ||
return ( | ||
<div ref={ref} data-fs-progress-status data-testid={testId} {...props}> | ||
{leftSideElement && <p>{leftSideElement}</p>} | ||
<ProgressBar value={progressValue} /> | ||
{rightSideElement && <p>{rightSideElement}</p>} | ||
</div> | ||
) | ||
} | ||
) | ||
|
||
export default ProgressStatus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default, type ProgressStatusProps } from './ProgressStatus' |
120 changes: 120 additions & 0 deletions
120
packages/components/src/organisms/RatingSummary/RatingSummary.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import React, { forwardRef, type HTMLAttributes } from 'react' | ||
import Rating from '../../molecules/Rating' | ||
import ProgressStatus from '../../molecules/ProgressStatus' | ||
import Icon from '../../atoms/Icon' | ||
import Button from '../../atoms/Button' | ||
|
||
export interface RatingSummaryProps extends HTMLAttributes<HTMLDivElement> { | ||
/** | ||
* The average rating of the product | ||
*/ | ||
average: number | ||
/** | ||
* The total number of reviews of the product | ||
*/ | ||
totalCount: number | ||
/** | ||
* The distribution of the ratings | ||
*/ | ||
distribution: { | ||
starsOne: number | ||
starsTwo: number | ||
starsThree: number | ||
starsFour: number | ||
starsFive: number | ||
} | ||
/** | ||
* The total count text to be displayed after the total count number | ||
* @default 'Reviews' | ||
*/ | ||
totalCountText?: string | ||
/** | ||
* The text to be displayed when there are no reviews | ||
* @default 'No reviews yet' | ||
*/ | ||
zeroCountText?: string | ||
/** | ||
* The text to be displayed on the button for writing a new review | ||
* @default 'Write a review' | ||
*/ | ||
buttonText?: string | ||
/** | ||
* The text to be displayed on the button for writing the very first review | ||
* @default 'Write the first review' | ||
*/ | ||
buttonTextFirstReview?: string | ||
/** | ||
* Optional test ID for testing. | ||
*/ | ||
testId?: string | ||
} | ||
|
||
function buildProgressStatus(key: number, value: number) { | ||
return ( | ||
<ProgressStatus | ||
data-fs-rating-summary-distribution-status | ||
leftSideElement={ | ||
<span data-fs-rating-summary-distribution-key> | ||
<p>{key}</p> | ||
<Icon data-fs-rating-summary-distribution-key-star name="Star" /> | ||
</span> | ||
} | ||
progressValue={value} | ||
rightSideElement={ | ||
<p data-fs-rating-summary-distribution-value>{value}%</p> | ||
} | ||
/> | ||
) | ||
} | ||
|
||
export const RatingSummary = forwardRef<HTMLDivElement, RatingSummaryProps>( | ||
function RatingSummary( | ||
{ | ||
average, | ||
totalCount, | ||
distribution, | ||
testId = 'fs-rating-summary', | ||
totalCountText = 'Reviews', | ||
zeroCountText = 'No reviews yet', | ||
buttonText = 'Write a review', | ||
buttonTextFirstReview = 'Write the first review', | ||
...props | ||
}, | ||
ref | ||
) { | ||
const finalTotalCountText = | ||
totalCount > 0 ? `${totalCount} ${totalCountText}` : zeroCountText | ||
const finalButtonText = totalCount > 0 ? buttonText : buttonTextFirstReview | ||
const formattedAverage = average > 0 ? average.toPrecision(2) : '' | ||
|
||
return ( | ||
<div ref={ref} data-fs-rating-summary data-testid={testId} {...props}> | ||
<div data-fs-rating-summary-header> | ||
<h2 data-fs-rating-summary-header-average>{formattedAverage}</h2> | ||
<Rating data-fs-rating-summary-header-stars value={average} /> | ||
<p data-fs-rating-summary-header-total-count>{finalTotalCountText}</p> | ||
</div> | ||
<div> | ||
<Button | ||
data-fs-rating-summary-button | ||
variant="secondary" | ||
onClick={() => alert('Write a review button clicked!')} | ||
> | ||
{finalButtonText} | ||
</Button> | ||
</div> | ||
{totalCount > 0 && ( | ||
<div data-fs-rating-summary-distribution> | ||
{buildProgressStatus(5, distribution.starsFive)} | ||
{buildProgressStatus(4, distribution.starsFour)} | ||
{buildProgressStatus(3, distribution.starsThree)} | ||
{buildProgressStatus(2, distribution.starsTwo)} | ||
{buildProgressStatus(1, distribution.starsOne)} | ||
</div> | ||
)} | ||
</div> | ||
) | ||
} | ||
) | ||
|
||
export default RatingSummary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default, type RatingSummaryProps } from './RatingSummary' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 5 additions & 1 deletion
6
packages/core/src/components/sections/ReviewsAndRatings/section.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
@layer components { | ||
.section { | ||
// TODO: Ajustar esses componentes para a nova section ReviewsAndRatings | ||
// @import '@faststore/ui/src/components/atoms/Ratings/styles'; | ||
@import '@faststore/ui/src/components/molecules/Rating/styles'; | ||
@import '@faststore/ui/src/components/atoms/ProgressBar/styles'; | ||
@import '@faststore/ui/src/components/molecules/ProgressStatus/styles'; | ||
@import '@faststore/ui/src/components/organisms/RatingSummary/styles'; | ||
@import '@faststore/ui/src/components/atoms/Button/styles'; | ||
} | ||
} |
Oops, something went wrong.