Skip to content

Commit

Permalink
refactor(ui): migrate address list component for antd v5
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaewoook committed Jun 23, 2024
1 parent 9c6aab8 commit 138bc13
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 156 deletions.
1 change: 1 addition & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ body {
font-family: Noto Sans KR, sans-serif;
min-width: 500px;
height: 475px;
margin: 0;
}

#root {
Expand Down
22 changes: 16 additions & 6 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Layout as _Layout } from "antd";
import { ConfigProvider, Layout as _Layout, ThemeConfig } from "antd";
import { RecoilRoot } from "recoil";
import styled from "styled-components";

Expand All @@ -12,14 +12,24 @@ export const Layout = styled(_Layout)`
overflow: hidden;
`;

const theme: ThemeConfig = {
components: {
Collapse: {
contentPadding: "0 16px",
},
},
};

export const App = () => {
return (
<RecoilRoot>
<Layout>
<Header />
<Content />
<Footer />
</Layout>
<ConfigProvider theme={theme}>
<Layout>
<Header />
<Content />
<Footer />
</Layout>
</ConfigProvider>
</RecoilRoot>
);
};
26 changes: 0 additions & 26 deletions src/components/AddressList/AddressList.css

This file was deleted.

78 changes: 0 additions & 78 deletions src/components/AddressList/index.tsx

This file was deleted.

39 changes: 0 additions & 39 deletions src/components/ClickToCopyText.tsx

This file was deleted.

5 changes: 2 additions & 3 deletions src/components/index.ts
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";
8 changes: 4 additions & 4 deletions src/components/popup/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { useRecoilValue } from "recoil";
import styled from "styled-components";

import { AddressList } from "../AddressList";
import { AddressList } from "../ui/AddressList";
import { useAddressSearch } from "@/hooks/useAddressSearch";
import { useSettings } from "@/hooks/useSettings";
import { addressListState } from "@/states/address";
Expand Down Expand Up @@ -130,9 +130,9 @@ export const Content = () => {
<ListTop addressData={addressList} onResetClick={handleResetClick} />
<AddressList
data={addressList}
showEngAddr={addressDisplayOptions.engAddrShown}
showRoadAddr={addressDisplayOptions.roadAddrShown}
showLegacyAddr={addressDisplayOptions.streetNumAddrShown}
engAddrShown={addressDisplayOptions.engAddrShown}
roadAddrShown={addressDisplayOptions.roadAddrShown}
streetNumAddrShown={addressDisplayOptions.streetNumAddrShown}
/>
{searching ? (
<Spinner />
Expand Down
128 changes: 128 additions & 0 deletions src/components/ui/AddressList/index.tsx
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]}
/>
);
};
43 changes: 43 additions & 0 deletions src/components/ui/ClickToCopyText.tsx
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>
);
};

0 comments on commit 138bc13

Please sign in to comment.