Skip to content

Commit c9d2214

Browse files
committed
messageの形式を修正
1 parent 1a6eff8 commit c9d2214

3 files changed

Lines changed: 21 additions & 33 deletions

File tree

src/app/uuid/Uuid.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export const Uuid: FC = () => {
2020
const title = 'UUIDの生成';
2121
const { methods, selectData, control, output, onClickGenerateUUID, version, onClickClear } =
2222
useUuid();
23-
const { copy } = useCopy();
2423

2524
const requireName = version === 3 || version === 5;
2625

src/components/common/Form/CopyButton.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ type Props = {
1010
};
1111

1212
export const CopyButton: FC<Props> = ({ copyText, size }) => {
13-
const { copy } = useCopy();
13+
const { copy, contextHolder } = useCopy();
1414

1515
return (
1616
<Tooltip title="コピー">
17+
{contextHolder}
1718
<Button icon={<CopyOutlined />} size={size} onClick={copy(copyText)} />
1819
</Tooltip>
1920
);

src/hooks/useCopy.tsx

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,37 @@
1-
import { useToaster, Message } from 'rsuite';
1+
import { message } from 'antd';
22

33
export const useCopy = () => {
4-
const toaster = useToaster();
5-
const PLACEMENT = 'bottomStart';
6-
const DURATION = 2000;
4+
const [messageApi, contextHolder] = message.useMessage();
5+
const DURATION = 1;
76

87
const copy = (text?: string) => async () => {
98
if (!text || text.trim() === '') {
10-
toaster.push(
11-
<Message showIcon type="warning">
12-
コピーする内容がありません。
13-
</Message>,
14-
{
15-
placement: PLACEMENT,
16-
duration: DURATION,
17-
},
18-
);
9+
messageApi.open({
10+
type: 'warning',
11+
content: 'コピーする内容がありません。',
12+
duration: DURATION,
13+
});
1914
return;
2015
}
2116

2217
try {
2318
await navigator.clipboard.writeText(text);
24-
toaster.push(
25-
<Message showIcon type="success">
26-
コピーしました。
27-
</Message>,
28-
{
29-
placement: PLACEMENT,
30-
duration: DURATION,
31-
},
32-
);
19+
messageApi.open({
20+
type: 'success',
21+
content: 'コピーしました。',
22+
duration: DURATION,
23+
});
3324
} catch (e) {
34-
toaster.push(
35-
<Message showIcon type="error">
36-
コピーに失敗しました。
37-
</Message>,
38-
{
39-
placement: PLACEMENT,
40-
duration: DURATION,
41-
},
42-
);
25+
messageApi.open({
26+
type: 'error',
27+
content: 'コピーに失敗しました。',
28+
duration: DURATION,
29+
});
4330
}
4431
};
4532

4633
return {
4734
copy,
35+
contextHolder,
4836
};
4937
};

0 commit comments

Comments
 (0)