From 26401bc5e88ae6a42621fce474236d7055a67516 Mon Sep 17 00:00:00 2001
From: Dhaval Vira <32231977+dhavalveera@users.noreply.github.com>
Date: Wed, 19 Jun 2024 17:36:52 +0530
Subject: [PATCH] feat(components): add Clipboard (#1413)
* feat(components): add Clipboard
* PR Build error fixed
* docs typo mistake
* docs typo mistake
* added missing use client in example
* export naming fix
* small change
* Example updated
* moved copyToClipboard function to helpers for the reusability (DRY)
* error handling added to helper function
---
.changeset/poor-tools-hide.md | 5 ++
.../web/content/docs/components/clipboard.mdx | 42 +++++++++++
apps/web/data/docs-sidebar.ts | 1 +
.../web/examples/clipboard/clipboard.root.tsx | 59 +++++++++++++++
.../examples/clipboard/clipboard.withIcon.tsx | 65 +++++++++++++++++
.../clipboard/clipboard.withIconText.tsx | 65 +++++++++++++++++
apps/web/examples/clipboard/index.ts | 3 +
apps/web/examples/index.ts | 1 +
.../Clipboard/Clipboard.stories.tsx | 72 +++++++++++++++++++
.../ui/src/components/Clipboard/Clipboard.tsx | 58 +++++++++++++++
.../Clipboard/ClipboardWithIcon.tsx | 46 ++++++++++++
.../Clipboard/ClipboardWithIconText.tsx | 58 +++++++++++++++
.../ui/src/components/Clipboard/helpers.ts | 15 ++++
packages/ui/src/components/Clipboard/index.ts | 8 +++
.../ui/src/components/Clipboard/theme.tsx | 28 ++++++++
.../src/components/Flowbite/FlowbiteTheme.ts | 2 +
packages/ui/src/index.ts | 1 +
packages/ui/src/theme.ts | 2 +
18 files changed, 531 insertions(+)
create mode 100644 .changeset/poor-tools-hide.md
create mode 100644 apps/web/content/docs/components/clipboard.mdx
create mode 100644 apps/web/examples/clipboard/clipboard.root.tsx
create mode 100644 apps/web/examples/clipboard/clipboard.withIcon.tsx
create mode 100644 apps/web/examples/clipboard/clipboard.withIconText.tsx
create mode 100644 apps/web/examples/clipboard/index.ts
create mode 100644 packages/ui/src/components/Clipboard/Clipboard.stories.tsx
create mode 100644 packages/ui/src/components/Clipboard/Clipboard.tsx
create mode 100644 packages/ui/src/components/Clipboard/ClipboardWithIcon.tsx
create mode 100644 packages/ui/src/components/Clipboard/ClipboardWithIconText.tsx
create mode 100644 packages/ui/src/components/Clipboard/helpers.ts
create mode 100644 packages/ui/src/components/Clipboard/index.ts
create mode 100644 packages/ui/src/components/Clipboard/theme.tsx
diff --git a/.changeset/poor-tools-hide.md b/.changeset/poor-tools-hide.md
new file mode 100644
index 000000000..ac2d1bf43
--- /dev/null
+++ b/.changeset/poor-tools-hide.md
@@ -0,0 +1,5 @@
+---
+"flowbite-react": minor
+---
+
+feat(components): add "Clipboard"
diff --git a/apps/web/content/docs/components/clipboard.mdx b/apps/web/content/docs/components/clipboard.mdx
new file mode 100644
index 000000000..447ac9b4c
--- /dev/null
+++ b/apps/web/content/docs/components/clipboard.mdx
@@ -0,0 +1,42 @@
+---
+title: React Clipboard - Flowbite
+description: Use the clipboard component to copy text, data or lines of code to the clipboard with a single click based on various styles and examples coded with Tailwind CSS and Flowbite
+---
+
+The copy to clipboard component allows you to copy text, lines of code, contact details or any other data to the clipboard with a single click on a trigger element such as a button. This component can be used to copy text from an input field, textarea, code block or even address fields in a form element.
+
+These components are built with Tailwind CSS and Flowbite React and can be found on the internet on websites such as Bitly, Cloudflare, Amazon AWS and almost all open-source projects and documentations.
+
+Import the component from `flowbite-react` to use the clipboard element:
+
+```jsx
+import { Clipboard } from "flowbite-react";
+```
+
+## Default copy to clipboard
+
+Use this example to copy the content of an input text field by clicking on a button and update the button text.
+
+
+
+## Input with copy button
+
+This example can be used to copy the content of an input field by clicking on a button with an icon positioned inside the form element and also show a tooltip with a message when the text has been copied.
+
+
+
+## Copy button with text
+
+Use this example to show a copy button inside the input field with a text label and icon that updates to a success state when the text has been copied.
+
+
+
+## Theme
+
+To learn more about how to customize the appearance of components, please see the [Theme docs](/docs/customize/theme).
+
+
+
+## References
+
+- [Flowbite Datepicker](https://flowbite.com/docs/components/clipboard/)
diff --git a/apps/web/data/docs-sidebar.ts b/apps/web/data/docs-sidebar.ts
index 73af25d81..933eaf146 100644
--- a/apps/web/data/docs-sidebar.ts
+++ b/apps/web/data/docs-sidebar.ts
@@ -63,6 +63,7 @@ export const DOCS_SIDEBAR: DocsSidebarSection[] = [
{ title: "Button group", href: "/docs/components/button-group" },
{ title: "Card", href: "/docs/components/card" },
{ title: "Carousel", href: "/docs/components/carousel" },
+ { title: "Clipboard", href: "/docs/components/clipboard", isNew: true },
{ title: "Datepicker", href: "/docs/components/datepicker", isNew: true },
{ title: "Drawer", href: "/docs/components/drawer", isNew: true },
{ title: "Dropdown", href: "/docs/components/dropdown" },
diff --git a/apps/web/examples/clipboard/clipboard.root.tsx b/apps/web/examples/clipboard/clipboard.root.tsx
new file mode 100644
index 000000000..d48ddc09c
--- /dev/null
+++ b/apps/web/examples/clipboard/clipboard.root.tsx
@@ -0,0 +1,59 @@
+"use client";
+
+import { Clipboard } from "flowbite-react";
+import type { CodeData } from "~/components/code-demo";
+
+const code = `
+"use client";
+
+import { Clipboard } from "flowbite-react"
+
+export function Component() {
+ return (
+