-
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.
refactor(ui): migrate address list component for antd v5
- Loading branch information
Showing
9 changed files
with
194 additions
and
156 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ body { | |
font-family: Noto Sans KR, sans-serif; | ||
min-width: 500px; | ||
height: 475px; | ||
margin: 0; | ||
} | ||
|
||
#root { | ||
|
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1,2 @@ | ||
export { AddressList } from "./AddressList"; | ||
export { ClickToCopyText } from "./ClickToCopyText"; | ||
export * from "./Layout"; | ||
export { AddressList } from "./ui/AddressList"; | ||
export { ClickToCopyText } from "./ui/ClickToCopyText"; |
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,128 @@ | ||
/** | ||
* External modules | ||
*/ | ||
import { Collapse, Typography } from "antd"; | ||
import type { CollapseProps } from "antd"; | ||
import { useMemo } from "react"; | ||
import styled from "styled-components"; | ||
|
||
/** | ||
* Internal modules | ||
*/ | ||
// import "./AddressList.css"; | ||
import type { AddressData } from "@/shared/models/address"; | ||
import { ClickToCopyText } from "../ClickToCopyText"; | ||
import { FeedbackPopover } from "../../FeedbackPopover"; | ||
import type { DisplayOptions } from "@/shared/models/settings"; | ||
|
||
interface Props extends DisplayOptions { | ||
data: AddressData[]; | ||
} | ||
|
||
const EmptyText = styled(Typography.Paragraph)` | ||
text-align: center; | ||
margin-top: 2em; | ||
margin-bottom: 2em !important; | ||
color: rgba(0, 0, 0, 0.6) !important; | ||
> span { | ||
font-size: 12px; | ||
color: rgba(0, 0, 0, 0.3) !important; | ||
} | ||
`; | ||
|
||
interface RowProps { | ||
keyLabel: string; | ||
value: string; | ||
} | ||
|
||
const RowWrapper = styled.div` | ||
display: flex; | ||
align-items: center; | ||
& > div.addr-value { | ||
flex: 1; | ||
} | ||
& > .addr-label { | ||
flex: 0 0 72px; | ||
margin: 0 !important; | ||
} | ||
`; | ||
|
||
const Row = ({ keyLabel, value }: RowProps) => { | ||
return ( | ||
<RowWrapper> | ||
<Typography.Paragraph className="addr-label"> | ||
{keyLabel} | ||
</Typography.Paragraph> | ||
<div className="addr-value"> | ||
<ClickToCopyText>{value}</ClickToCopyText> | ||
</div> | ||
</RowWrapper> | ||
); | ||
}; | ||
|
||
const AddressItemWrapper = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
`; | ||
|
||
interface AddressItemProps extends DisplayOptions { | ||
address: AddressData; | ||
} | ||
|
||
const AddressItem = ({ | ||
address, | ||
engAddrShown, | ||
roadAddrShown, | ||
streetNumAddrShown, | ||
}: AddressItemProps) => { | ||
return ( | ||
<AddressItemWrapper> | ||
<Row keyLabel="์ฐํธ๋ฒํธ: " value={address.zipNo} /> | ||
{roadAddrShown ? <Row keyLabel="๋๋ก๋ช ์ฃผ์: " value={address.roadAddr} /> : null} | ||
{streetNumAddrShown ? <Row keyLabel="์ง๋ฒ์ฃผ์: " value={address.jibunAddr} /> : null} | ||
{engAddrShown ? <Row keyLabel="์๋ฌธ์ฃผ์: " value={address.engAddr} /> : null} | ||
</AddressItemWrapper> | ||
); | ||
}; | ||
|
||
export const AddressList = (props: Props) => { | ||
const { data, engAddrShown, roadAddrShown, streetNumAddrShown } = props; | ||
const listItems: CollapseProps["items"] = useMemo( | ||
() => | ||
data.map((addressData, i) => ({ | ||
key: i, | ||
label: addressData.roadAddr, | ||
children: ( | ||
<AddressItem | ||
address={addressData} | ||
engAddrShown={engAddrShown} | ||
roadAddrShown={roadAddrShown} | ||
streetNumAddrShown={streetNumAddrShown} | ||
/> | ||
), | ||
})), | ||
[data, engAddrShown, roadAddrShown, streetNumAddrShown], | ||
); | ||
|
||
if (!data || !data.length) { | ||
return ( | ||
<EmptyText type="secondary"> | ||
๊ฒ์ ๊ฒฐ๊ณผ๊ฐ ์์ต๋๋ค. | ||
<br /> | ||
<span>(๊ฒ์์ด ์์: ๊ฐ๋จ๋๋ก, ์์๋, ์ด์ฑ ๊ฒ์ ๊ฐ๋ฅ)</span> | ||
<br /> | ||
<FeedbackPopover /> | ||
</EmptyText> | ||
); | ||
} | ||
|
||
return ( | ||
<Collapse | ||
className="address-list" | ||
ghost | ||
items={listItems} | ||
bordered={false} | ||
defaultActiveKey={[0]} | ||
/> | ||
); | ||
}; |
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,43 @@ | ||
/** | ||
* External modules | ||
*/ | ||
import { useCallback, useState } from "react"; | ||
import styled from "styled-components"; | ||
import { Button, Tooltip } from "antd"; | ||
import copy from "copy-to-clipboard"; | ||
|
||
const Text = styled(Button)` | ||
color: rgba(0, 0, 0, 0.65); | ||
`; | ||
|
||
interface Props { | ||
children: string; | ||
} | ||
|
||
export const ClickToCopyText = (props: Props) => { | ||
const { children } = props; | ||
const [copied, setCopied] = useState(false); | ||
|
||
const handleCopyClick = useCallback(() => { | ||
setCopied(true); | ||
copy(children); | ||
}, [children]); | ||
|
||
const handleOpenChange = useCallback((open: boolean) => { | ||
if (!open) { | ||
setTimeout(() => setCopied(false), 100); | ||
} | ||
}, []); | ||
|
||
return ( | ||
<Tooltip | ||
title={!copied ? "ํด๋ฆญํด์ ๋ณต์ฌํ๊ธฐ" : "๋ณต์ฌ์๋ฃ!"} | ||
color={copied ? "green" : "#000"} | ||
onOpenChange={handleOpenChange} | ||
> | ||
<Text type="link" onClick={handleCopyClick}> | ||
{children} | ||
</Text> | ||
</Tooltip> | ||
); | ||
}; |