-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from boostcampwm-2022/feat/PaceInput
PaceInput ์ปดํฌ๋ํธ ์์ฑ
- Loading branch information
Showing
10 changed files
with
123 additions
and
41 deletions.
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
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,34 @@ | ||
import styled from "styled-components"; | ||
import { COLOR } from "styles/color"; | ||
|
||
export const InputWrapper = styled.div<{ width: string }>` | ||
display: flex; | ||
padding: 16px; | ||
border-bottom: ${`1px solid ${COLOR.BABY_BLUE}`}; | ||
width: ${({ width }) => width}; | ||
input { | ||
color: ${COLOR.BLACK}; | ||
border: none; | ||
:focus { | ||
outline: none; | ||
} | ||
::placeholder { | ||
color: ${COLOR.BABY_BLUE}; | ||
} | ||
/* Chrome, Safari, Edge, Opera */ | ||
::-webkit-outer-spin-button, | ||
::-webkit-inner-spin-button { | ||
-webkit-appearance: none; | ||
margin: 0; | ||
} | ||
/* Firefox */ | ||
[type="number"] { | ||
-moz-appearance: textfield; | ||
} | ||
} | ||
p { | ||
color: ${COLOR.BABY_BLUE}; | ||
text-align: right; | ||
width: 20%; | ||
} | ||
`; |
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
11 changes: 11 additions & 0 deletions
11
client/src/components/Input/PaceInput/PaceInput.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,11 @@ | ||
import React from "react"; | ||
import { ComponentStory, ComponentMeta } from "@storybook/react"; | ||
|
||
import PaceInput from "./PaceInput"; | ||
|
||
export default { | ||
title: "Input/PaceInput", | ||
component: PaceInput, | ||
} as ComponentMeta<typeof PaceInput>; | ||
|
||
export const Template: ComponentStory<typeof PaceInput> = (args) => <PaceInput {...args} />; |
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,51 @@ | ||
import { ERROR } from "#constants/errorMessage"; | ||
import { ChangeEventHandler, FormEventHandler, useCallback } from "react"; | ||
import { InputWrapper } from "../Input.style"; | ||
|
||
interface PaceInputProps { | ||
width?: string; | ||
onChangeMinute: ChangeEventHandler<HTMLInputElement>; | ||
onChangeSecond: ChangeEventHandler<HTMLInputElement>; | ||
} | ||
|
||
const PaceInput = ({ width, onChangeMinute, onChangeSecond }: PaceInputProps) => { | ||
const onInput: FormEventHandler<HTMLInputElement> = useCallback((e) => { | ||
const value = e.currentTarget.value; | ||
if (value.length > 1 && value[0] === "0") { | ||
e.currentTarget.value = value.slice(1); | ||
} | ||
if (Number(value) > 60) { | ||
alert(ERROR.INVALID_MINUTE_VALUE); | ||
e.currentTarget.value = "60"; | ||
} | ||
if (Number(value) < 0) { | ||
alert(ERROR.INVALID_MINUTE_VALUE); | ||
e.currentTarget.value = "0"; | ||
} | ||
}, []); | ||
return ( | ||
<InputWrapper width={width ?? "100%"}> | ||
<input | ||
onInput={onInput} | ||
onChange={onChangeMinute} | ||
min="1" | ||
max="60" | ||
type="number" | ||
style={{ width: "40%" }} | ||
/> | ||
<p style={{ marginRight: "1rem" }}>๋ถ</p> | ||
<input | ||
onInput={onInput} | ||
onChange={onChangeSecond} | ||
min="1" | ||
max="60" | ||
type="number" | ||
style={{ width: "40%" }} | ||
/> | ||
<p style={{ marginRight: "1rem" }}>์ด</p> | ||
<p>/km</p> | ||
</InputWrapper> | ||
); | ||
}; | ||
|
||
export default PaceInput; |
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,3 @@ | ||
export enum ERROR { | ||
INVALID_MINUTE_VALUE = "1 ์ด์ 60 ์ดํ์ ์ซ์๋ง ์ ๋ ฅ ๊ฐ๋ฅํฉ๋๋ค.", | ||
} |
File renamed without changes.
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,15 @@ | ||
import { ChangeEventHandler, useCallback, useState } from "react"; | ||
|
||
const usePaceInput = () => { | ||
const [pace, setPace] = useState({ minute: 0, second: 0 }); | ||
const onChangeMinute: ChangeEventHandler<HTMLInputElement> = useCallback((e) => { | ||
setPace((prev) => ({ ...prev, minute: Number(e.target.value) })); | ||
}, []); | ||
|
||
const onChangeSecond: ChangeEventHandler<HTMLInputElement> = useCallback((e) => { | ||
setPace((prev) => ({ ...prev, second: Number(e.target.value) })); | ||
}, []); | ||
return { pace, onChangeMinute, onChangeSecond }; | ||
}; | ||
|
||
export default usePaceInput; |
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