-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
207 additions
and
18 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
22 changes: 22 additions & 0 deletions
22
src/components/domain/TextEditable/TextEditable.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,22 @@ | ||
import type { Meta, StoryObj } from '@storybook/react' | ||
import TextEditable from './TextEditable' | ||
|
||
const meta = { | ||
title: 'DOMAIN/TextEditable', | ||
component: TextEditable, | ||
tags: ['autodocs'], | ||
argTypes: {}, | ||
} satisfies Meta<typeof TextEditable> | ||
|
||
export default meta | ||
type Story = StoryObj<typeof meta> | ||
|
||
export const Normal: Story = { | ||
args: { | ||
defaultText: 'text', | ||
changedSuccessfully: true, | ||
onChangeHandler: () => { | ||
alert('changed') | ||
}, | ||
}, | ||
} |
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,69 @@ | ||
'use client' | ||
|
||
import React, { useEffect, useState } from 'react' | ||
import Image from 'next/image' | ||
import Button from '@/components/ui/Button' | ||
import Input from '@/components/ui/Input' | ||
import Assets from '@/config/assets' | ||
import { cn } from '@/utils' | ||
|
||
type TextEditablePropsType = { | ||
onChangeHandler: (_text: string) => void | ||
changedSuccessfully: boolean | ||
defaultText?: string | ||
} | ||
|
||
const TextEditable = ({ | ||
onChangeHandler, | ||
changedSuccessfully, | ||
defaultText = '닉네임', | ||
}: TextEditablePropsType) => { | ||
const [isEditing, setIsEditing] = useState(false) | ||
const [value, setValue] = useState(defaultText) | ||
|
||
useEffect(() => { | ||
if (!changedSuccessfully) { | ||
setValue(() => defaultText) | ||
} | ||
}, [changedSuccessfully, defaultText]) | ||
|
||
const onChangeInput = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
setValue(event.target.value) | ||
} | ||
|
||
return ( | ||
<div className="relative flex flex-row items-center justify-center gap-1"> | ||
<Input | ||
border={isEditing ? 'bottom' : 'none'} | ||
disabled={!isEditing} | ||
value={value} | ||
className="overflow-hidden text-center cursor-default w-fit line-clamp-1" | ||
onChange={onChangeInput} | ||
/> | ||
<Button | ||
onClick={() => { | ||
if (isEditing) { | ||
onChangeHandler(value) | ||
} | ||
setIsEditing((prev) => !prev) | ||
}} | ||
variant={isEditing ? 'primary' : null} | ||
size={isEditing ? 'sm' : 'icon_sm'} | ||
className={cn(!isEditing && 'absolute right-0 cursor-pointer')} | ||
asChild | ||
> | ||
{isEditing ? ( | ||
<span className="break-keep">완료</span> | ||
) : ( | ||
<Image | ||
src={Assets.editMemoIcon} | ||
className="bg-background-color" | ||
alt={'edit-text'} | ||
/> | ||
)} | ||
</Button> | ||
</div> | ||
) | ||
} | ||
|
||
export default TextEditable |
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 @@ | ||
import TextEditable from './TextEditable' | ||
|
||
export default TextEditable |
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
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
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
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
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,11 @@ | ||
interface User { | ||
userId: number | ||
accountId: string | ||
nickname: string | ||
role: 'USER' | 'ADMIN' | ||
createdDate: string | ||
modifiedDate: string | ||
profileImg?: string | ||
} | ||
|
||
export type { User } |