-
-
Notifications
You must be signed in to change notification settings - Fork 73
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
10 changed files
with
126 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,4 +116,5 @@ enum QuestionType { | |
EMOJI | ||
INPUT | ||
CHOICE | ||
RATE | ||
} |
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
52 changes: 52 additions & 0 deletions
52
src/features/surveys/components/AnswersComponent/RateComponent/RateComponent.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,52 @@ | ||
import React, { useState } from 'react'; | ||
import useTranslation from 'next-translate/useTranslation'; | ||
import StarComponent from 'features/surveys/components/AnswersComponent/RateComponent/StarComponent/StarComponent'; | ||
import clsx from 'clsx'; | ||
|
||
interface RateAnswersComponentProps { | ||
handleAnswerChange: (answer: string, questionId: string) => void; | ||
answer?: string; | ||
questionId: string; | ||
isSubmitted: boolean; | ||
isRequired: boolean; | ||
} | ||
|
||
export default function RateAnswersComponent({ | ||
handleAnswerChange, | ||
answer, | ||
questionId, | ||
isSubmitted, | ||
isRequired, | ||
}: RateAnswersComponentProps) { | ||
const { t } = useTranslation('survey'); | ||
|
||
const [hoveredIndex, setHoveredIndex] = useState<number | null>(null); | ||
|
||
return ( | ||
<> | ||
<div className="flex items-center justify-center"> | ||
{[...Array(5)].map((_, index) => ( | ||
<StarComponent | ||
key={index} | ||
classNames={clsx( | ||
answer && index < +answer ? 'text-yellow-400' : 'text-gray-300', | ||
hoveredIndex !== null | ||
? hoveredIndex >= index | ||
? '!text-yellow-400' | ||
: '!text-gray-300' | ||
: '' | ||
)} | ||
onMouseEnter={() => setHoveredIndex(index)} | ||
onMouseLeave={() => setHoveredIndex(null)} | ||
onClick={() => | ||
handleAnswerChange((index + 1).toString(), questionId) | ||
} | ||
/> | ||
))} | ||
</div> | ||
{isSubmitted && !answer && isRequired && ( | ||
<p className="mt-4 text-sm text-red-500">{t('requiredField')}</p> | ||
)} | ||
</> | ||
); | ||
} |
35 changes: 35 additions & 0 deletions
35
...eatures/surveys/components/AnswersComponent/RateComponent/StarComponent/StarComponent.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,35 @@ | ||
import clsx from 'clsx'; | ||
import React from 'react'; | ||
|
||
interface StarComponentProps { | ||
classNames?: string; | ||
onMouseEnter: () => void; | ||
onMouseLeave: () => void; | ||
onClick: () => void; | ||
} | ||
|
||
export default function StarComponent({ | ||
classNames, | ||
onMouseEnter, | ||
onMouseLeave, | ||
onClick, | ||
}: StarComponentProps) { | ||
return ( | ||
<div | ||
onMouseEnter={onMouseEnter} | ||
onMouseLeave={onMouseLeave} | ||
className="cursor-pointer px-1" | ||
onClick={onClick} | ||
> | ||
<svg | ||
className={clsx('h-5 w-5', classNames)} | ||
aria-hidden="true" | ||
xmlns="http://www.w3.org/2000/svg" | ||
fill="currentColor" | ||
viewBox="0 0 22 20" | ||
> | ||
<path d="M20.924 7.625a1.523 1.523 0 0 0-1.238-1.044l-5.051-.734-2.259-4.577a1.534 1.534 0 0 0-2.752 0L7.365 5.847l-5.051.734A1.535 1.535 0 0 0 1.463 9.2l3.656 3.563-.863 5.031a1.532 1.532 0 0 0 2.226 1.616L11 17.033l4.518 2.375a1.534 1.534 0 0 0 2.226-1.617l-.863-5.03L20.537 9.2a1.523 1.523 0 0 0 .387-1.575Z" /> | ||
</svg> | ||
</div> | ||
); | ||
} |
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
3 changes: 3 additions & 0 deletions
3
src/features/surveys/components/QuestionBlocks/RateQuestionBlock/RateQuestionBlock.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,3 @@ | ||
export default function RateQuestionBlock() { | ||
return null; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { StarIcon } from '@heroicons/react/solid'; | ||
import React from 'react'; | ||
|
||
export default function RateIcon() { | ||
return <StarIcon />; | ||
} |
2007a94
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.
Successfully deployed to the following URLs:
formslab – ./
formslab-git-main-ryczko.vercel.app
formslab-ryczko.vercel.app
formslab.vercel.app