From b7c379219261aa015caecae3a310c3b724a39085 Mon Sep 17 00:00:00 2001 From: Dhaval Vira Date: Mon, 3 Jun 2024 06:50:53 +0530 Subject: [PATCH] moved copyToClipboard function to helpers for the reusability (DRY) --- .changeset/poor-tools-hide.md | 2 +- packages/ui/src/components/Clipboard/Clipboard.tsx | 14 +++++++------- .../src/components/Clipboard/ClipboardWithIcon.tsx | 14 +++++++------- .../components/Clipboard/ClipboardWithIconText.tsx | 14 +++++++------- packages/ui/src/components/Clipboard/helpers.ts | 7 +++++++ 5 files changed, 29 insertions(+), 22 deletions(-) create mode 100644 packages/ui/src/components/Clipboard/helpers.ts diff --git a/.changeset/poor-tools-hide.md b/.changeset/poor-tools-hide.md index 69a7f7542..ac2d1bf43 100644 --- a/.changeset/poor-tools-hide.md +++ b/.changeset/poor-tools-hide.md @@ -1,5 +1,5 @@ --- -"flowbite-react": patch +"flowbite-react": minor --- feat(components): add "Clipboard" diff --git a/packages/ui/src/components/Clipboard/Clipboard.tsx b/packages/ui/src/components/Clipboard/Clipboard.tsx index 941629c8d..a32914e83 100644 --- a/packages/ui/src/components/Clipboard/Clipboard.tsx +++ b/packages/ui/src/components/Clipboard/Clipboard.tsx @@ -10,6 +10,7 @@ import { ClipboardWithIcon } from "./ClipboardWithIcon"; import type { FlowbiteClipboardWithIconTheme } from "./ClipboardWithIcon"; import { ClipboardWithIconText } from "./ClipboardWithIconText"; import type { FlowbiteClipboardWithIconTextTheme } from "./ClipboardWithIconText"; +import { copyToClipboard } from "./helpers"; export interface FlowbiteClipboardTheme { button: { @@ -32,15 +33,14 @@ const ClipboardComponent = forwardRef( const theme = mergeDeep(getTheme().clipboard.button, customTheme); - const copyToClipboard = () => { - setIsJustCopied(true); - navigator?.clipboard?.writeText(valueToCopy); - setTimeout(() => setIsJustCopied(false), 4000); - }; - return ( - diff --git a/packages/ui/src/components/Clipboard/ClipboardWithIcon.tsx b/packages/ui/src/components/Clipboard/ClipboardWithIcon.tsx index 184550109..574c8fa66 100644 --- a/packages/ui/src/components/Clipboard/ClipboardWithIcon.tsx +++ b/packages/ui/src/components/Clipboard/ClipboardWithIcon.tsx @@ -6,6 +6,7 @@ import { twMerge } from "tailwind-merge"; import { mergeDeep } from "../../helpers/merge-deep"; import { getTheme } from "../../theme-store"; import type { DeepPartial } from "../../types"; +import { copyToClipboard } from "./helpers"; export interface FlowbiteClipboardWithIconTheme { base: string; @@ -27,14 +28,13 @@ export const ClipboardWithIcon = forwardRef { - setIsJustCopied(true); - navigator?.clipboard?.writeText(valueToCopy); - setTimeout(() => setIsJustCopied(false), 4000); - }; - return ( -