-
Notifications
You must be signed in to change notification settings - Fork 6
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
feat-fe: 평가 필터 팝오버 컴포넌트 구현 #804
Merged
Merged
Changes from 6 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c8a6918
Create draft PR for #803
github-actions[bot] 14c8aae
chore: storybook action addom 의존성 설치 및 설정
lurgi 5cca360
feat: Slider Atom 구현
lurgi 9d98100
feat: RatingFilterContext 구현
lurgi 6d4aeb1
feat: RatingFilter 구현
lurgi 8e8ca62
feat: Popover 구현
lurgi 1d8b4a3
feat: Slider isDIsabled prop 추가
lurgi 4d7bb47
feat: Popover Provider 구현 및 피드백 적용
lurgi bc92eca
feat: ratingFilter 컴포넌트 별추가
lurgi 7b6abaa
feat: RatingFilter 초기화 버튼 구현
lurgi 7be9833
feat: 포매팅 제한 분기처리
lurgi c37e872
refactor: 스타일 코드 변경
lurgi 51f1b5e
feat: 실제 필터링 state초기화 삭제
lurgi ce73bcc
feat: Slider Component 제어 컴포넌트로 변경
lurgi d666b7a
Merge branch 'fe/develop' into fe-803-ATING_FILTER_POPOVER
lurgi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
83 changes: 83 additions & 0 deletions
83
frontend/src/components/_common/atoms/Slider/Slider.stories.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,83 @@ | ||
/* eslint-disable react/jsx-one-expression-per-line */ | ||
import { action } from '@storybook/addon-actions'; | ||
import { useState } from 'react'; | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
import Slider from '.'; | ||
|
||
const meta: Meta<typeof Slider> = { | ||
title: 'Common/Atoms/Slider', | ||
component: Slider, | ||
argTypes: { | ||
onRangeChange: { action: 'rangeChanged' }, | ||
}, | ||
decorators: [ | ||
(Story, context) => { | ||
const [range, setRange] = useState({ | ||
min: context.args.initialMin, | ||
max: context.args.initialMax, | ||
}); | ||
|
||
const handleRangeChange = (min: number, max: number) => { | ||
setRange({ min, max }); | ||
action('rangeChanged')(`최대값은 ${max}, 최소값은 ${min}`); | ||
}; | ||
|
||
return ( | ||
<div style={{ width: '300px' }}> | ||
<Story | ||
args={{ | ||
...context.args, | ||
onRangeChange: handleRangeChange, | ||
}} | ||
/> | ||
<div style={{ marginTop: '20px' }}> | ||
Current Range: {range.min.toFixed(2)} - {range.max.toFixed(2)} | ||
</div> | ||
</div> | ||
); | ||
}, | ||
], | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof Slider>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
min: 0, | ||
max: 5, | ||
step: 0.5, | ||
initialMin: 0, | ||
initialMax: 5, | ||
}, | ||
}; | ||
|
||
export const DecimalStep: Story = { | ||
args: { | ||
min: 0, | ||
max: 5, | ||
step: 0.1, | ||
initialMin: 0, | ||
initialMax: 5, | ||
}, | ||
}; | ||
|
||
export const NarrowRange: Story = { | ||
args: { | ||
min: 0, | ||
max: 100, | ||
step: 1, | ||
initialMin: 40, | ||
initialMax: 60, | ||
}, | ||
}; | ||
|
||
export const CustomRange: Story = { | ||
args: { | ||
min: -50, | ||
max: 50, | ||
step: 5, | ||
initialMin: -25, | ||
initialMax: 25, | ||
}, | ||
}; |
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,57 @@ | ||
import React, { useState } from 'react'; | ||
import S from './style'; | ||
|
||
interface SliderProps { | ||
min: number; | ||
max: number; | ||
step: number; | ||
initialMin: number; | ||
initialMax: number; | ||
onRangeChange: (min: number, max: number) => void; | ||
} | ||
|
||
export default function Slider({ min, max, step, initialMin, initialMax, onRangeChange }: SliderProps) { | ||
const [minValue, setMinValue] = useState(initialMin); | ||
const [maxValue, setMaxValue] = useState(initialMax); | ||
|
||
const handleMinChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
const newMinValue = Math.min(Number(e.target.value), Number(maxValue - step)); | ||
setMinValue(newMinValue); | ||
onRangeChange(newMinValue, maxValue); | ||
}; | ||
|
||
const handleMaxChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
const newMaxValue = Math.max(Number(e.target.value), Number(minValue + step)); | ||
setMaxValue(newMaxValue); | ||
onRangeChange(minValue, newMaxValue); | ||
}; | ||
|
||
const sliderRangeLeft = ((minValue - min) / (max - min)) * 100; | ||
const sliderRangeRight = 100 - ((maxValue - min) / (max - min)) * 100; | ||
|
||
return ( | ||
<S.SliderContainer> | ||
<S.SliderTrack /> | ||
<S.SliderRange | ||
left={sliderRangeLeft} | ||
right={sliderRangeRight} | ||
/> | ||
<S.SliderThumb | ||
type="range" | ||
min={min} | ||
max={max} | ||
step={step} | ||
value={minValue} | ||
onChange={handleMinChange} | ||
/> | ||
<S.SliderThumb | ||
type="range" | ||
min={min} | ||
max={max} | ||
step={step} | ||
value={maxValue} | ||
onChange={handleMaxChange} | ||
/> | ||
</S.SliderContainer> | ||
); | ||
} |
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,78 @@ | ||
import styled from '@emotion/styled'; | ||
|
||
const SliderContainer = styled.div` | ||
position: relative; | ||
width: 100%; | ||
height: 2rem; | ||
`; | ||
|
||
const SliderTrack = styled.div` | ||
position: absolute; | ||
top: 50%; | ||
transform: translateY(-50%); | ||
|
||
width: 100%; | ||
height: 0.6rem; | ||
border-radius: 0.3rem; | ||
|
||
background-color: ${({ theme }) => theme.baseColors.grayscale[200]}; | ||
`; | ||
|
||
const SliderRange = styled.div<{ left: number; right: number }>` | ||
position: absolute; | ||
top: 50%; | ||
left: ${({ left }) => `${left}%`}; | ||
right: ${({ right }) => `${right}%`}; | ||
transform: translateY(-50%); | ||
|
||
height: 0.6rem; | ||
border-radius: 0.3rem; | ||
background-color: ${({ theme }) => theme.baseColors.purplescale[200]}; | ||
`; | ||
|
||
const SliderThumb = styled.input` | ||
position: absolute; | ||
top: 50%; | ||
width: 100%; | ||
height: 0; | ||
background: transparent; | ||
pointer-events: none; | ||
|
||
-webkit-appearance: none; | ||
appearance: none; | ||
|
||
&::-moz-range-thumb { | ||
width: 1.6rem; | ||
aspect-ratio: 1/1; | ||
background: ${({ theme }) => theme.baseColors.grayscale[50]}; | ||
cursor: pointer; | ||
pointer-events: auto; | ||
|
||
border: 0.4rem solid ${({ theme }) => theme.baseColors.purplescale[700]}; | ||
border-radius: 100%; | ||
} | ||
|
||
&::-webkit-slider-thumb { | ||
width: 1.6rem; | ||
aspect-ratio: 1/1; | ||
background: ${({ theme }) => theme.baseColors.grayscale[50]}; | ||
cursor: pointer; | ||
border-radius: 100%; | ||
pointer-events: auto; | ||
|
||
border: 0.4rem solid ${({ theme }) => theme.baseColors.purplescale[700]}; | ||
border-radius: 100%; | ||
|
||
-webkit-appearance: none; | ||
appearance: none; | ||
} | ||
`; | ||
|
||
const S = { | ||
SliderContainer, | ||
SliderTrack, | ||
SliderRange, | ||
SliderThumb, | ||
}; | ||
|
||
export default S; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Firefox에서 시험해보면 아래 이미지와 같이 SliderThumb 요소가 찌그러집니다.
요 부분에 한해서 width를 1rem으로 맞춰주면 정상적으로 출력되네요 :)
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.
와 ㅋㅋ 환경별로 코드가 달라진다는게 진짜 이상하네용..