Skip to content

Commit

Permalink
[Feature] - Layout Shift 개선 (#454)
Browse files Browse the repository at this point in the history
* refactor(AccordionRoot): gap 값 수정

* refactor(TravelogueRegisterPage): layout shift 문제 해결

* refactor(TravelogueEditPage): layout shift 문제 해결

* refactor(TravelPlanRegisterPage): layout shift 문제 해결

* refactor(TravelPlanEditPage): layout shift 문제 해결

* refactor(Input): count 있는 경우 미리 공간 차지하도록 수정

* refactor(Input): input 내부에 있던 characterCount 분리

* test(Input): input 속성 변경에 따른 storybook 속성 수정
  • Loading branch information
simorimi authored Sep 26, 2024
1 parent 946d03e commit 923fdc8
Show file tree
Hide file tree
Showing 15 changed files with 255 additions and 318 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import styled from "@emotion/styled";
export const Layout = styled.div`
display: flex;
flex-direction: column;
gap: 2rem;
gap: ${({ theme }) => theme.spacing.m};
`;
2 changes: 0 additions & 2 deletions frontend/src/components/common/Input/Input.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ type Story = StoryObj<typeof meta>;
export const Default: Story = {
args: {
placeholder: "제목을 입력해 주세요.",
count: 0,
maxCount: 20,
},
};

Expand Down
9 changes: 1 addition & 8 deletions frontend/src/components/common/Input/Input.styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@ import theme from "@styles/theme";

import type { InputVariants } from "./Input.type";

export const InputContainer = styled.div`
display: flex;
flex-direction: column;
gap: 0.8rem;
width: 100%;
`;

export const Label = styled.label`
${({ theme }) => theme.typography.mobile.bodyBold};
color: ${(props) => props.theme.colors.text.primary};
Expand Down Expand Up @@ -43,6 +35,7 @@ export const Input = styled.input<{ variant: InputVariants }>`
if (variant === "none") return noneStyle;
}}
`;

export const roundStyle = css`
border: 0.1rem solid ${theme.colors.border};
Expand Down
16 changes: 3 additions & 13 deletions frontend/src/components/common/Input/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
import { forwardRef } from "react";

import CharacterCount from "../CharacterCount/CharacterCount";
import * as S from "./Input.styled";
import type { InputVariants } from "./Input.type";

interface InputProps extends React.ComponentPropsWithRef<"input"> {
count?: number;
maxCount?: number;
variants?: InputVariants;
}

const Input = forwardRef<HTMLInputElement, InputProps>(
({ count, maxCount, variants = "round", ...props }, ref) => {
return (
<S.InputContainer>
<S.Input variant={variants} {...props} ref={ref} />
{count && maxCount ? <CharacterCount count={count} maxCount={maxCount} /> : null}
</S.InputContainer>
);
},
);
const Input = forwardRef<HTMLInputElement, InputProps>(({ variants = "round", ...props }, ref) => {
return <S.Input variant={variants} {...props} ref={ref} />;
});

Input.displayName = "Input";

Expand Down
8 changes: 8 additions & 0 deletions frontend/src/components/pages/my/MyPage.styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ export const NicknameWrapper = styled.div`
height: 3rem;
`;

export const InputContainer = styled.div`
display: flex;
flex-direction: column;
gap: ${({ theme }) => theme.spacing.s};
width: 100%;
`;

export const inputStyle = css`
${theme.typography.mobile.bodyBold};
width: 12rem;
Expand Down
42 changes: 23 additions & 19 deletions frontend/src/components/pages/my/MyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FormEvent, MouseEvent, useEffect, useState } from "react";
import usePatchNickname from "@queries/usePatchNickname";
import { useUserProfile } from "@queries/useUserProfile";

import { AvatarCircle, Input, Tab, Text } from "@components/common";
import { AvatarCircle, CharacterCount, Input, Tab, Text } from "@components/common";
import MyPageSkeleton from "@components/pages/my/MyPageSkeleton/MyPageSkeleton";

import { ERROR_MESSAGE_MAP } from "@constants/errorMessage";
Expand Down Expand Up @@ -85,24 +85,28 @@ const MyPage = () => {
{nickname}
</Text>
) : (
<Input
placeholder={data?.nickname}
value={nickname}
autoFocus
maxCount={20}
maxLength={20}
count={nickname?.length}
spellCheck={false}
css={S.inputStyle}
onChange={(e) =>
setNickname(
e.target.value.slice(
FORM_VALIDATIONS_MAP.title.minLength,
FORM_VALIDATIONS_MAP.title.maxLength,
),
)
}
/>
<S.InputContainer>
<Input
placeholder={data?.nickname}
value={nickname}
autoFocus
maxLength={20}
spellCheck={false}
css={S.inputStyle}
onChange={(e) =>
setNickname(
e.target.value.slice(
FORM_VALIDATIONS_MAP.title.minLength,
FORM_VALIDATIONS_MAP.title.maxLength,
),
)
}
/>
<CharacterCount
count={nickname?.length}
maxCount={FORM_VALIDATIONS_MAP.title.maxLength}
/>
</S.InputContainer>
)}
</S.NicknameWrapper>
</S.FormWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,29 @@ import { SPACING } from "@styles/tokens";
export const Layout = styled.div`
display: flex;
flex-direction: column;
gap: ${SPACING.xl};
gap: ${({ theme }) => theme.spacing.xl};
padding: ${SPACING.m};
& > :last-child {
margin-top: -${SPACING.xl};
}
padding: ${({ theme }) => theme.spacing.m};
`;

export const AccordionRootContainer = styled.div`
margin-top: ${SPACING.m};
export const InputContainer = styled.div`
display: flex;
flex-direction: column;
gap: ${({ theme }) => theme.spacing.s};
width: 100%;
`;

export const PageInfoContainer = styled.div`
display: flex;
flex-direction: column;
gap: ${SPACING.s};
gap: ${({ theme }) => theme.spacing.s};
`;

export const StartDateContainer = styled.div`
display: flex;
flex-direction: column;
gap: ${SPACING.s};
`;

export const LoadingWrapper = styled.div`
width: 100%;
height: 5.6rem;
gap: ${({ theme }) => theme.spacing.s};
`;

export const addDayButtonStyle = css`
Expand All @@ -47,26 +42,7 @@ export const addButtonStyle = css`
width: 100%;
height: 4rem;
margin-bottom: ${SPACING.xl};
padding: 1.2rem 1.6rem;
border: 0.1rem solid ${theme.colors.border};
border: 1px solid ${theme.colors.border};
border-radius: ${SPACING.s};
`;

export const loadingButtonStyle = css`
margin-top: ${SPACING.xl};
`;

export const startDateInputStyle = css`
margin: 0 0 ${SPACING.xl};
`;

export const calendarStyle = css`
margin-bottom: ${SPACING.xl};
`;

export const accordionRootStyle = css`
& > :last-child {
margin-bottom: ${SPACING.xl};
}
`;
76 changes: 39 additions & 37 deletions frontend/src/components/pages/travelPlanEdit/TravelPlanEditPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { usePutTravelPlan } from "@queries/usePutTravelPlan";
import {
Accordion,
Button,
CharacterCount,
GoogleMapLoadScript,
IconButton,
Input,
Expand Down Expand Up @@ -140,15 +141,19 @@ const TravelPlanEditPage = () => {
<PageInfo mainText="여행 계획 수정" />
<TextField title="제목" isRequired>
{(id) => (
<Input
id={id}
value={title}
maxLength={FORM_VALIDATIONS_MAP.title.maxLength}
placeholder="여행 계획 제목을 입력해주세요"
count={title.length}
maxCount={FORM_VALIDATIONS_MAP.title.maxLength}
onChange={handleChangeTitle}
/>
<S.InputContainer>
<Input
id={id}
value={title}
maxLength={FORM_VALIDATIONS_MAP.title.maxLength}
placeholder="여행 계획 제목을 입력해주세요"
onChange={handleChangeTitle}
/>
<CharacterCount
count={title.length}
maxCount={FORM_VALIDATIONS_MAP.title.maxLength}
/>
</S.InputContainer>
)}
</TextField>

Expand All @@ -165,35 +170,32 @@ const TravelPlanEditPage = () => {
onClick={handleInputClick}
readOnly
placeholder="시작일을 입력해주세요"
css={S.startDateInputStyle}
/>
{isShowCalendar && (
<Calendar
onSelectDate={handleSelectDate}
onClose={() => setIsShowCalendar((prev) => !prev)}
css={S.calendarStyle}
/>
)}
</>
)}
</TextField>
<S.AccordionRootContainer>

<div>
<GoogleMapLoadScript
loadingElement={
<S.LoadingWrapper>
<IconButton
size="16"
iconType="plus"
position="left"
css={[S.addButtonStyle, S.loadingButtonStyle]}
onClick={() => onAddDay()}
>
<Text textType="bodyBold">일자 추가하기</Text>
</IconButton>
</S.LoadingWrapper>
<IconButton
size="16"
iconType="plus"
position="left"
css={S.addButtonStyle}
onClick={() => onAddDay()}
>
<Text textType="bodyBold">일자 추가하기</Text>
</IconButton>
}
>
<Accordion.Root css={S.accordionRootStyle}>
<Accordion.Root>
{travelPlanDays.map((travelDay, dayIndex) => (
<TravelPlanDayAccordion
key={travelDay.id}
Expand All @@ -208,21 +210,21 @@ const TravelPlanEditPage = () => {
onAddPlaceTodo={onAddPlaceTodo}
/>
))}
<IconButton
size="16"
iconType="plus"
position="left"
css={S.addButtonStyle}
onClick={onAddDay}
>
<Text textType="bodyBold">일자 추가하기</Text>
</IconButton>
</Accordion.Root>
<IconButton
size="16"
iconType="plus"
position="left"
css={[S.addButtonStyle]}
onClick={() => onAddDay()}
>
<Text textType="bodyBold">일자 추가하기</Text>
</IconButton>
</GoogleMapLoadScript>
<Button variants="primary" onClick={handleOpenBottomSheet}>
수정
</Button>
</S.AccordionRootContainer>
</div>
<Button variants="primary" onClick={handleOpenBottomSheet}>
수정
</Button>
</S.Layout>

<ModalBottomSheet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const PlaceTodoListItem = ({ todo, onChangeContent, onDeleteTodo }: PlaceTodoLis
value={todo?.content}
placeholder="할 일을 입력해주세요."
onChange={onChangeContent}
maxCount={20}
autoFocus
variants="none"
spellCheck="false"
Expand Down
Loading

0 comments on commit 923fdc8

Please sign in to comment.