Skip to content

Commit

Permalink
Merge pull request #37 from ivalshamkya/development
Browse files Browse the repository at this point in the history
feat: show toast after copycode clicked
  • Loading branch information
ivalshamkya authored Mar 5, 2024
2 parents fe1fb38 + 34ab3c3 commit d907098
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 59 deletions.
3 changes: 0 additions & 3 deletions apps/www/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import type { Metadata } from "next";
import {
Inter,
IBM_Plex_Mono,
Darker_Grotesque,
Bricolage_Grotesque,
} from "next/font/google";
import "./globals.css";
Expand Down
1 change: 0 additions & 1 deletion apps/www/src/components/Components.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from "react";
import Code from "@/components/Code";
import ComponentWrapper from "@/components/ComponentWrapper";
import CopyCode from "@/components/CopyCode";
Expand Down
90 changes: 63 additions & 27 deletions apps/www/src/components/CopyCode.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,66 @@
'use client';
'use client'
import React, { useState } from "react";
import Button from "./neobruu/Button";
import { IoCheckmark, IoCopy } from "react-icons/io5";

export default function CopyCode({ code }: { code: string }) {
const [isClicked, setIsClicked] = useState(false);

const handleClick = () => {
navigator.clipboard
.writeText(code)
.then(() => {
setIsClicked(true);
setTimeout(() => {
setIsClicked(false);
}, 2500);
})
.catch(() => {
alert(
"Your device doesn't support navigator api, so you'll have to manually select and copy the code.",
);
});
};

return (
<Button rounded="md" variant="yellow" onClick={handleClick}>
{isClicked ? <IoCheckmark /> : <IoCopy />}
</Button>
);
import { IoCopy } from "react-icons/io5";
import { IoMdCheckmark, IoMdCheckmarkCircle } from "react-icons/io";
import Toast from "./neobruu/Toast";

export interface ButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement> {
code: string,
}


const CopyCode = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ className, children, code, ...props }, ref) => {
const [isClicked, setIsClicked] = useState(false);
const [showToast, setShowToast] = useState(false);

const handleShowToast = () => {
setShowToast(true);
};

const handleClick = () => {
handleShowToast();
navigator.clipboard
.writeText(code)
.then(() => {
setIsClicked(true);
setTimeout(() => {
setIsClicked(false);
}, 2500);
})
.catch(() => {
alert(
"Your device doesn't support navigator api, so you'll have to manually select and copy the code.",
);
});
};

return (
<>
<Button rounded="md" variant="yellow" onClick={handleClick}>
{isClicked ? <IoMdCheckmark className="w-5 h-5" /> : <IoCopy />}
</Button>

{showToast && (
<Toast
variant="primary"
duration={3000}
active={showToast}
setActive={setShowToast}
>
<div className="flex items-center gap-3 p-1">
<IoMdCheckmarkCircle className="w-6 h-6"/>
<p className="text-sm">Copied to clipboard</p>
</div>
</Toast>
)}
</>
);
}
)

CopyCode.displayName = "Copy Code";

export default CopyCode
21 changes: 10 additions & 11 deletions apps/www/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,29 @@ import Badge from "@/components/neobruu/Badge";
export default function Sidebar() {
const pathname = usePathname();
const isActive = (route: string) => pathname === route;
const year = new Date().getFullYear();

return (
<aside className="scrollbar fixed top-20 h-[calc(100vh-80px)] max-h-[calc(100vh-80px)] w-[303px] py-7 bg-[#ff7a7a] overflow-y-auto border-r-4 border-black">
<div className="block border-black p-4 text-xl font-bold uppercase">
<aside className="scrollbar fixed top-20 h-[calc(100vh-80px)] max-h-[calc(100vh-80px)] w-[303px] py-7 bg-[#5545ff] overflow-y-auto border-r-4 border-black">
<div className="block border-black p-4 text-xl text-white font-bold uppercase">
Getting Started
</div>
<Link
href={`/docs`}
className={`block border-black p-3 pl-7 text-base hover:bg-[#ff4242]/70 ${
isActive("/docs") ? "font-bold text-white" : ""
className={`block border-black text-white p-3 pl-7 text-base hover:bg-[#ff4242]/70 ${
isActive("/docs") ? "font-bold" : "font-extralight"
}`}
>
Introduction
</Link>
<Link
href={`/docs/installation`}
className={`block border-black p-3 pl-7 text-base hover:bg-[#ff4242]/70 ${
isActive("/docs/installation") ? "font-bold text-white" : ""
className={`block border-black p-3 pl-7 text-white text-base hover:bg-[#ff4242]/70 ${
isActive("/docs/installation") ? "font-bold" : "font-extralight"
}`}
>
Installation
</Link>
<div className="block border-black p-4 text-xl font-bold uppercase">
<div className="block border-black p-4 text-xl text-white font-bold uppercase">
Components
</div>
{components.map((item, index) => (
Expand All @@ -40,10 +39,10 @@ export default function Sidebar() {
className={`flex gap-2 border-black p-3 pl-7 text-base hover:bg-[#ff4242]/70`}
>
<span
className={`${
className={`text-white ${
isActive(`/docs/components/${item.name}`)
? "font-medium text-white"
: ""
? "font-bold"
: "font-extralight"
}`}
>
{item.name}
Expand Down
21 changes: 6 additions & 15 deletions apps/www/src/components/example/AccordionExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ export default function AccordionExample() {
<Accordion.Item value="1">
<Accordion.Trigger>Question 1</Accordion.Trigger>
<Accordion.Content>
<h1 className="text-xl">Lorem</h1>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Possimus
atque error aperiam consectetur excepturi. Quod, eaque. Libero,
non illo vero accusantium consectetur, iure tempora commodi quo
quibusdam, fuga dolore in?
</p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Iusto
accusantium impedit corporis magnam esse pariatur libero sint
mollitia veniam, sed quos hic voluptatibus molestias porro ab.
Possimus ratione commodi dolorem.
</Accordion.Content>
</Accordion.Item>
<Accordion.Item value="2">
Expand All @@ -23,10 +20,7 @@ export default function AccordionExample() {
Lorem ipsum dolor sit amet consectetur adipisicing elit. Iusto
accusantium impedit corporis magnam esse pariatur libero sint
mollitia veniam, sed quos hic voluptatibus molestias porro ab.
Possimus ratione commodi dolorem. Lorem ipsum dolor sit amet
consectetur, adipisicing elit. Doloribus corporis ipsam aperiam
assumenda molestiae minima, ipsum dolore adipisci, quod doloremque
nam deserunt porro nostrum ut iste tenetur placeat nulla numquam!
Possimus ratione commodi dolorem.
</Accordion.Content>
</Accordion.Item>
<Accordion.Item value="3">
Expand All @@ -35,10 +29,7 @@ export default function AccordionExample() {
Lorem ipsum dolor sit amet consectetur adipisicing elit. Iusto
accusantium impedit corporis magnam esse pariatur libero sint
mollitia veniam, sed quos hic voluptatibus molestias porro ab.
Possimus ratione commodi dolorem. Lorem ipsum dolor sit amet
consectetur, adipisicing elit. Doloribus corporis ipsam aperiam
assumenda molestiae minima, ipsum dolore adipisci, quod doloremque
nam deserunt porro nostrum ut iste tenetur placeat nulla numquam!
Possimus ratione commodi dolorem.
</Accordion.Content>
</Accordion.Item>
</Accordion>
Expand Down
1 change: 0 additions & 1 deletion apps/www/src/components/example/ToastExample.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use client';
import { useState } from "react";
import { HiExclamation } from "react-icons/hi";

import Toast from "@/components/neobruu/Toast";
import Button from "@/components/neobruu/Button";
Expand Down
2 changes: 1 addition & 1 deletion apps/www/src/components/neobruu/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { InputHTMLAttributes } from "react";
import React from "react";
import { VariantProps, cva } from "class-variance-authority";
import { cn } from "@/lib/utils";

Expand Down

0 comments on commit d907098

Please sign in to comment.