Skip to content

Commit

Permalink
messageの形式を修正
Browse files Browse the repository at this point in the history
  • Loading branch information
su-u committed Dec 27, 2023
1 parent 1a6eff8 commit c9d2214
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 33 deletions.
1 change: 0 additions & 1 deletion src/app/uuid/Uuid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export const Uuid: FC = () => {
const title = 'UUIDの生成';
const { methods, selectData, control, output, onClickGenerateUUID, version, onClickClear } =
useUuid();
const { copy } = useCopy();

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

Expand Down
3 changes: 2 additions & 1 deletion src/components/common/Form/CopyButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ type Props = {
};

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

return (
<Tooltip title="コピー">
{contextHolder}
<Button icon={<CopyOutlined />} size={size} onClick={copy(copyText)} />
</Tooltip>
);
Expand Down
50 changes: 19 additions & 31 deletions src/hooks/useCopy.tsx
Original file line number Diff line number Diff line change
@@ -1,49 +1,37 @@
import { useToaster, Message } from 'rsuite';
import { message } from 'antd';

export const useCopy = () => {
const toaster = useToaster();
const PLACEMENT = 'bottomStart';
const DURATION = 2000;
const [messageApi, contextHolder] = message.useMessage();
const DURATION = 1;

const copy = (text?: string) => async () => {
if (!text || text.trim() === '') {
toaster.push(
<Message showIcon type="warning">
コピーする内容がありません。
</Message>,
{
placement: PLACEMENT,
duration: DURATION,
},
);
messageApi.open({
type: 'warning',
content: 'コピーする内容がありません。',
duration: DURATION,
});
return;
}

try {
await navigator.clipboard.writeText(text);
toaster.push(
<Message showIcon type="success">
コピーしました。
</Message>,
{
placement: PLACEMENT,
duration: DURATION,
},
);
messageApi.open({
type: 'success',
content: 'コピーしました。',
duration: DURATION,
});
} catch (e) {
toaster.push(
<Message showIcon type="error">
コピーに失敗しました。
</Message>,
{
placement: PLACEMENT,
duration: DURATION,
},
);
messageApi.open({
type: 'error',
content: 'コピーに失敗しました。',
duration: DURATION,
});
}
};

return {
copy,
contextHolder,
};
};

1 comment on commit c9d2214

@vercel
Copy link

@vercel vercel bot commented on c9d2214 Dec 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

tools-su-u-dev – ./

tools-su-u-dev.vercel.app
tools-su-u-dev-git-main-su-u.vercel.app
tools-su-u-dev-su-u.vercel.app
tools.su-u.dev

Please sign in to comment.