-
Notifications
You must be signed in to change notification settings - Fork 2
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
8 changed files
with
666 additions
and
43 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
67 changes: 67 additions & 0 deletions
67
src/components/CourseDetails/RatingStar/StarInput/index.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,67 @@ | ||
import styled from '@emotion/styled'; | ||
import { css } from '@emotion/react'; | ||
import { FaStar, FaStarHalf } from 'react-icons/fa'; | ||
import React from 'react'; | ||
|
||
interface StarInputProps { | ||
onClickRating: (value: number) => void; | ||
value: number; | ||
isHalf: boolean; | ||
} | ||
|
||
const Input = styled.input` | ||
display: none; | ||
`; | ||
|
||
const Label = styled.label<{ isHalf: boolean }>` | ||
cursor: pointer; | ||
font-size: 24px; | ||
color: #f1f2f4; | ||
${({ isHalf }) => | ||
isHalf && | ||
css` | ||
position: absolute; | ||
width: 12px; | ||
overflow: hidden; | ||
&:nth-of-type(10) { | ||
transform: translate(-108px); | ||
} | ||
&:nth-of-type(8) { | ||
transform: translate(-84px); | ||
} | ||
&:nth-of-type(6) { | ||
transform: translate(-60px); | ||
} | ||
&:nth-of-type(4) { | ||
transform: translate(-36px); | ||
} | ||
&:nth-of-type(2) { | ||
transform: translate(-12px); | ||
} | ||
`} | ||
`; | ||
|
||
export default function StarInput({ | ||
onClickRating, | ||
value, | ||
isHalf, | ||
}: StarInputProps) { | ||
const handleClickRatingInput = () => { | ||
onClickRating(value); | ||
}; | ||
|
||
return ( | ||
<> | ||
<Input type="radio" name="rating" id={`star${value}`} value={value} /> | ||
<Label | ||
onClick={() => handleClickRatingInput()} | ||
isHalf={isHalf} | ||
htmlFor={`star${value}`} | ||
> | ||
{isHalf ? <FaStarHalf /> : <FaStar />} | ||
</Label> | ||
</> | ||
); | ||
} |
49 changes: 49 additions & 0 deletions
49
src/components/CourseDetails/RatingStar/StarRating/index.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,49 @@ | ||
import styled from '@emotion/styled'; | ||
import StarInput from '../StarInput'; | ||
|
||
interface StarRatingProps { | ||
currentRating: number; | ||
onRatingChange: (value: number) => void; | ||
} | ||
|
||
const Base = styled.section` | ||
display: flex; | ||
align-items: center; | ||
gap: 8px; | ||
`; | ||
|
||
const RatingField = styled.fieldset` | ||
position: relative; | ||
display: flex; | ||
align-items: center; | ||
flex-direction: row-reverse; | ||
border: none; | ||
transform: translateY(2px); | ||
input:checked ~ label, | ||
label:hover, | ||
label:hover ~ label { | ||
transition: 0.2s; | ||
color: #75abff; | ||
} | ||
`; | ||
|
||
export default function StarRating({ | ||
currentRating, | ||
onRatingChange, | ||
}: StarRatingProps) { | ||
return ( | ||
<Base> | ||
<RatingField> | ||
{[5, 4.5, 4, 3.5, 3, 2.5, 2, 1.5, 1, 0.5].map(value => ( | ||
<StarInput | ||
key={value} | ||
onClickRating={onRatingChange} | ||
value={value} | ||
isHalf={value % 1 !== 0} | ||
/> | ||
))} | ||
</RatingField> | ||
</Base> | ||
); | ||
} |
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