Skip to content

Commit

Permalink
Merge pull request #50 from nan-noo/issue42
Browse files Browse the repository at this point in the history
Issue42 별 컴포넌트 구현
  • Loading branch information
uk960214 authored Jun 13, 2022
2 parents 8ff44f1 + a29c4cd commit 340dbd5
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 28 deletions.
19 changes: 19 additions & 0 deletions src/components/Star.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import styled from "styled-components";

const StarContainer = styled.span`
font-size: 1.5rem;
color: ${({ theme }) => theme.yellow};
`;

const EMPTY_STAR_ICON = "\u2606";
const FILLED_STAR_ICON = "\u2605";

function Star({ isFilled = false }) {
return (
<StarContainer>
{isFilled ? FILLED_STAR_ICON : EMPTY_STAR_ICON}
</StarContainer>
);
}

export default Star;
7 changes: 2 additions & 5 deletions src/components/StarRating.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState } from "react";
import styled from "styled-components";
import Star from "./Star";

export const Container = styled.div`
display: flex;
Expand All @@ -19,8 +20,6 @@ type Props = {
};

const MAX_RATING = 5;
const EMPTY_STAR_ICON = "\u2606";
const FILLED_STAR_ICON = "\u2605";

function StarRating({ rating = 0, setRating }: Props) {
const [hoverRating, setHoverRating] = useState<null | number>(null);
Expand All @@ -47,9 +46,7 @@ function StarRating({ rating = 0, setRating }: Props) {
onMouseEnter={handleStarHover(index)}
onMouseLeave={resetStarHover}
>
{index > (hoverRating ?? rating)
? EMPTY_STAR_ICON
: FILLED_STAR_ICON}
{index > (hoverRating ?? rating) ? <Star /> : <Star isFilled />}
</StarButton>
);
})}
Expand Down
13 changes: 2 additions & 11 deletions src/components/StoreDetailTitle.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import styled from "styled-components";
import Star from "./Star";
interface StoreDetailTitleProps {
storeInfo: {
name: string;
Expand All @@ -20,16 +21,6 @@ const TitleRatingWrapper = styled.div`
justify-content: space-between;
`;

const StarWrapper = styled.span`
justify-content: center;
text-align: center;
font-size: 1.5rem;
//TODO: 별 색깔 const로 빼기
color: #e6d706;
`;

const FILLED_STAR_ICON = "\u2605";

const DescriptionWrapper = styled.div`
width: 100%;
overflow: hidden;
Expand All @@ -44,7 +35,7 @@ function StoreDetailTitle({ storeInfo }: StoreDetailTitleProps) {
<TitleRatingWrapper>
<h2>{name}</h2>
<div>
<StarWrapper>{FILLED_STAR_ICON}</StarWrapper>
<Star isFilled />
<span>{rating}</span>
</div>
</TitleRatingWrapper>
Expand Down
10 changes: 6 additions & 4 deletions src/components/StoreListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import styled from "styled-components";
import Star from "./Star";

export interface StoreListItemProps {
thumbnailUrl: string;
Expand Down Expand Up @@ -48,11 +49,8 @@ const ListItemDistance = styled.p`

const ListItemStars = styled.div`
font-size: 1.5rem;
color: #e6d706;
`;

const FILLED_STAR_ICON = "\u2605";

function StoreListItem({
thumbnailUrl,
name,
Expand All @@ -76,7 +74,11 @@ function StoreListItem({
{campus} 캠퍼스 기준 {distance}km
</ListItemDistance>
</div>
<ListItemStars>{FILLED_STAR_ICON.repeat(starCount)}</ListItemStars>
<ListItemStars>
{Array.from({ length: starCount }).map(() => (
<Star isFilled />
))}
</ListItemStars>
</div>
</ListItemContainer>
);
Expand Down
9 changes: 2 additions & 7 deletions src/components/StoreReviewItem.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import styled from "styled-components";
import Star from "./Star";

interface StoreReviewItemProps {
reviewInfo: {
Expand Down Expand Up @@ -37,8 +38,6 @@ const ReviewContentWrapper = styled.div`
width: 80%;
`;

const FILLED_STAR_ICON = "\u2605";

const Header = styled.header`
display: flex;
flex-direction: row;
Expand All @@ -49,10 +48,6 @@ const HeaderLeftWrapper = styled.div`
margin-top: 0.4rem;
`;

const StarWrapper = styled.span`
color: #e6d706;
`;

const MenuWrapper = styled.div`
border: 1px solid ${({ theme }) => theme.secondary};
border-radius: 22px;
Expand All @@ -75,7 +70,7 @@ function StoreReviewItem({ reviewInfo }: StoreReviewItemProps) {
<ReviewContentWrapper>
<Header>
<HeaderLeftWrapper>
<StarWrapper>{FILLED_STAR_ICON}</StarWrapper>
<Star isFilled />
<span>X {rating}</span>
</HeaderLeftWrapper>
<MenuWrapper>{menuName}</MenuWrapper>
Expand Down
28 changes: 28 additions & 0 deletions src/stories/Star.stories.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Star from "../components/Star";

export default {
title: "Component/Star",
component: Star,
argTypes: {
isFilled: { controls: "boolean" },
},
};

const Template = (args) => <Star {...args} />;

export const Default = Template.bind({});
Default.args = {
isFilled: true,
};

export const FilledStar = Template.bind({});
FilledStar.args = {
isFilled: true,
};
FilledStar.parameters = { controls: { exclude: ["isFilled"] } };

export const OutlinedStar = Template.bind({});
OutlinedStar.args = {
isFilled: false,
};
OutlinedStar.parameters = { controls: { exclude: ["isFilled"] } };
7 changes: 6 additions & 1 deletion src/stories/StarRating.stories.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { useState } from "react";

import StarRating from "../components/StarRating";

export default {
title: "Component/StarRating",
component: StarRating,
};

const Template = (args) => <StarRating />;
const Template = () => {
const [rating, setRating] = useState(4);
return <StarRating rating={rating} setRating={setRating} />;
};

export const Default = Template.bind({});
2 changes: 2 additions & 0 deletions src/style/Theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const COLORS = {
GRAY: "#8D8D8D",
BLACK: "#121212",
WHITE: "#F8F8FA",
YELLOW: "#E6D706",
};

export const theme = {
Expand All @@ -12,4 +13,5 @@ export const theme = {
secondary: COLORS.GRAY,
black: COLORS.BLACK,
white: COLORS.WHITE,
yellow: COLORS.YELLOW,
};

0 comments on commit 340dbd5

Please sign in to comment.