Skip to content

Commit 4d00b8b

Browse files
committed
main 🧊 add copy for use clipboard
1 parent 8301c8f commit 4d00b8b

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

‎packages/core/src/bundle/hooks/useClipboard/useClipboard.js

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useCallback, useEffect, useState } from 'react';
1+
import { useEffect, useState } from 'react';
22
import { usePermission } from '../usePermission/usePermission';
33
export const isPermissionAllowed = (status) => status === 'granted' || status === 'prompt';
44
export const legacyCopyToClipboard = (value) => {
@@ -53,7 +53,7 @@ export const useClipboard = (params) => {
5353
document.removeEventListener('cut', set);
5454
};
5555
}, [enabled]);
56-
const copy = useCallback(async (value) => {
56+
const copy = async (value) => {
5757
try {
5858
if (supported || isPermissionAllowed(clipboardWritePermissionWrite.state)) {
5959
await navigator.clipboard.writeText(value);
@@ -66,6 +66,19 @@ export const useClipboard = (params) => {
6666
legacyCopyToClipboard(value);
6767
}
6868
setValue(value);
69-
}, []);
69+
};
7070
return { supported, value, copy };
7171
};
72+
export const copy = async (value) => {
73+
try {
74+
try {
75+
await navigator.clipboard.writeText(value);
76+
}
77+
catch {
78+
return legacyCopyToClipboard(value);
79+
}
80+
}
81+
catch {
82+
return legacyCopyToClipboard(value);
83+
}
84+
};

‎packages/core/src/hooks/useClickOutside/useClickOutside.demo.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const Demo = () => {
2020
<div
2121
ref={clickOutsideRef}
2222
className={cn(
23-
'relative flex flex-col items-center justify-center rounded-lg border border-red-500 p-12',
23+
'relative flex flex-col items-center justify-center rounded-xl border-2 border-red-500 p-12',
2424
{ 'border-green-500': counter.value > 5 }
2525
)}
2626
>

‎packages/core/src/hooks/useClipboard/useClipboard.ts

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useCallback, useEffect, useState } from 'react';
1+
import { useEffect, useState } from 'react';
22

33
import { usePermission } from '../usePermission/usePermission';
44

@@ -76,7 +76,7 @@ export const useClipboard = (params?: UseCopyToClipboardParams): UseCopyToClipbo
7676
};
7777
}, [enabled]);
7878

79-
const copy = useCallback(async (value: string) => {
79+
const copy = async (value: string) => {
8080
try {
8181
if (supported || isPermissionAllowed(clipboardWritePermissionWrite.state)) {
8282
await navigator.clipboard.writeText(value);
@@ -88,7 +88,19 @@ export const useClipboard = (params?: UseCopyToClipboardParams): UseCopyToClipbo
8888
}
8989

9090
setValue(value);
91-
}, []);
91+
};
9292

9393
return { supported, value, copy };
9494
};
95+
96+
export const copy = async (value: string) => {
97+
try {
98+
try {
99+
await navigator.clipboard.writeText(value);
100+
} catch {
101+
return legacyCopyToClipboard(value);
102+
}
103+
} catch {
104+
return legacyCopyToClipboard(value);
105+
}
106+
};

‎packages/docs/app/functions/hooks/[name].paths.mts

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export default {
104104
example,
105105
description: jsdoc.description.description,
106106
category: jsdoc.category!.name,
107-
lastModified: new Date(lastCommit.date).getTime(),
107+
lastModified: new Date(lastCommit?.date ?? new Date()).getTime(),
108108
usage,
109109
apiParameters: jsdoc.apiParameters ?? [],
110110
contributors

0 commit comments

Comments
 (0)