Skip to content

Commit ee6f1f6

Browse files
이정원이정원
authored andcommitted
feat: 입력창 숫자 포맷팅, padding값 조정
1 parent e3e7509 commit ee6f1f6

File tree

7 files changed

+79
-28
lines changed

7 files changed

+79
-28
lines changed

src/common/components/TagOptionBtn/style.css.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const rightIcon = cva({
6666
width: '1.52225rem',
6767
height: '1.52225rem',
6868
padding: '0.125rem',
69-
borderRadius: '0.76113rem',
69+
borderRadius: 'full',
7070
transition: 'all 0.3s ease-in-out',
7171
},
7272
variants: {
Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,38 @@
1+
import { useState } from 'react';
12
import * as s from './style.css';
23

3-
const InputField = () => {
4-
return <input className={s.Container}></input>;
4+
interface InputProps {
5+
isPrice?: boolean;
6+
}
7+
8+
const InputField = ({ isPrice = false }: InputProps) => {
9+
const [price, setPrice] = useState('');
10+
11+
const handleSetPrice = (event: React.ChangeEvent<HTMLInputElement>) => {
12+
let raw = event.target.value.replace(/,/g, '');
13+
14+
if (!/^\d*$/.test(raw)) return; // 숫자가 아니면 무시
15+
16+
const number = Number(raw);
17+
18+
if (isNaN(number)) {
19+
setPrice('');
20+
} else {
21+
setPrice(number.toLocaleString('ko-KR'));
22+
}
23+
24+
// TODO: 현재 입력값은 string
25+
// 백엔드에 보낼 때 number로 재변환하기
26+
// const numericPrice = Number(price.replace(/,/g, ''));
27+
};
28+
29+
return <input
30+
className={s.Container({ isPrice })}
31+
value={isPrice ? price : undefined}
32+
onChange={isPrice ? handleSetPrice : undefined}
33+
inputMode={isPrice ? 'numeric' : 'text'}
34+
pattern={isPrice ? '[0-9]*' : undefined}
35+
></input>;
536
};
637

738
export default InputField;
Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,28 @@
1-
import { css } from '@styled-system/css';
1+
import { cva } from '@styled-system/css';
22

3-
export const Container = css({
4-
height: '2.75rem',
5-
width: '100%',
6-
backgroundColor: '#2C2C2E',
7-
borderRadius: '0.375rem',
3+
export const Container = cva({
4+
base: {
5+
height: '2.75rem',
6+
backgroundColor: '#2C2C2E',
7+
width: '100%',
8+
padding: '0rem 1rem',
9+
borderRadius: '0.375rem',
10+
color: '100',
11+
opacity: '0.9',
12+
fontFamily: 'Pretendard',
13+
fontSize: '1rem',
14+
fontStyle: 'normal',
15+
fontWeight: '400',
16+
lineHeight: '1.4',
17+
},
18+
variants: {
19+
isPrice: {
20+
true: {
21+
textAlign: 'end',
22+
},
23+
false: {
24+
textAlign: 'start',
25+
},
26+
},
27+
},
828
});

src/features/post/components/StepFunnel/step4.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@ import {
1010
} from '@/libs/types/post';
1111
import { useState } from 'react';
1212

13+
const renderChipGroup = <T extends string>(
14+
map: Record<T, string>,
15+
selected: T | null,
16+
setSelected: React.Dispatch<React.SetStateAction<T | null>>,
17+
) => (
18+
<div className={s.ChipColumn}>
19+
{(Object.keys(map) as T[]).map(key => (
20+
<Chip key={key} isSelected={selected === key} onClick={() => setSelected(selected === key ? null : key)}>
21+
{map[key]}
22+
</Chip>
23+
))}
24+
</div>
25+
);
26+
1327
const Step4 = () => {
1428
const [selectedSizes, setSelectedSizes] = useState<SizeType | null>(null);
1529
const [selectedColors, setSelectedColors] = useState<ColorType | null>(null);
1630
const [selectedQualities, setSelectedQualities] = useState<QualityType | null>(null);
1731

18-
const renderChipGroup = <T extends string>(
19-
map: Record<T, string>,
20-
selected: T | null,
21-
setSelected: React.Dispatch<React.SetStateAction<T | null>>,
22-
) => (
23-
<div className={s.ChipColumn}>
24-
{(Object.keys(map) as T[]).map(key => (
25-
<Chip key={key} isSelected={selected === key} onClick={() => setSelected(selected === key ? null : key)}>
26-
{map[key]}
27-
</Chip>
28-
))}
29-
</div>
30-
);
31-
3232
return (
3333
<div>
3434
<header className={s.Head}>태그를 선택해 주세요</header>

src/features/post/components/StepFunnel/step6.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ const Rental = () => {
1515
<div className={s.HeaderInputField}>
1616
<span>대여료를 입력해 주세요</span>
1717
<div className={s.PriceInputField}>
18-
<InputField />
18+
<InputField isPrice={true} />
1919
</div>
2020
</div>
2121
<div className={s.HeaderInputField}>
2222
<span>보증금을 입력해 주세요</span>
2323
<div className={s.PriceInputField}>
24-
<InputField />
24+
<InputField isPrice={true} />
2525
</div>
2626
</div>
2727
</div>
@@ -43,7 +43,7 @@ const Sale = () => {
4343
<div className={s.HeaderInputField}>
4444
<span>판매 금액을 입력해 주세요</span>
4545
<div className={s.PriceInputField}>
46-
<InputField />
46+
<InputField isPrice={true}/>
4747
</div>
4848
</div>
4949
<span className={s.CanDeal} onClick={handleCanDeal}>

src/features/post/components/TypeCard/style.css.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const Icon = cva({
1616
width: '1.52225rem',
1717
height: '1.52225rem',
1818
padding: '0.125rem',
19-
borderRadius: '0.76113rem',
19+
borderRadius: 'full',
2020
transition: 'all 0.3s ease-in-out',
2121
},
2222
variants: {

src/libs/types/post.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ export const POST_TYPES_MAP = {
33
RENTAL: '대여',
44
};
55
export const PRODUCT_TYPES_MAP = {
6-
HOCKEY: '아이스하키',
76
SOCCER: '축구',
87
BASKETBALL: '농구',
98
BASEBALL: '야구',
9+
HOCKEY: '아이스하키',
1010
VARSITY_JACKET: '과잠',
1111
ACCESSORY: '악세사리',
1212
SELF_MADE: '자체제작',

0 commit comments

Comments
 (0)