Skip to content
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 15 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions frontend/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const config: StorybookConfig = {
'@storybook/addon-essentials',
'@chromatic-com/storybook',
'@storybook/addon-interactions',
'@storybook/addon-actions',
'storybook-addon-remix-react-router',
],
framework: {
Expand Down
43 changes: 32 additions & 11 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.6.0",
"@playwright/test": "^1.47.2",
"@storybook/addon-actions": "^8.3.5",
"@storybook/addon-essentials": "^8.2.1",
"@storybook/addon-interactions": "^8.2.1",
"@storybook/addon-links": "^8.2.1",
Expand Down
83 changes: 83 additions & 0 deletions frontend/src/components/_common/atoms/Slider/Slider.stories.tsx
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,
},
};
57 changes: 57 additions & 0 deletions frontend/src/components/_common/atoms/Slider/index.tsx
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>
);
}
78 changes: 78 additions & 0 deletions frontend/src/components/_common/atoms/Slider/style.ts
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Firefox에서 시험해보면 아래 이미지와 같이 SliderThumb 요소가 찌그러집니다.

image

요 부분에 한해서 width를 1rem으로 맞춰주면 정상적으로 출력되네요 :)

image
Suggested change
width: 1.6rem;
width: 1rem;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

와 ㅋㅋ 환경별로 코드가 달라진다는게 진짜 이상하네용..

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;
Loading
Loading