Skip to content

Commit

Permalink
fixing annoying console errors / warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
danikova committed Nov 30, 2023
1 parent 53c7128 commit 4c5d10c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 29 deletions.
17 changes: 14 additions & 3 deletions src/components/counter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export function Counter() {
if (digits.includes("h"))
_displays.push(
<CounterDisplayNumber
key="d"
key="h"
num={remaining.hours}
tooltip={`${isTMinus ? "Remaining" : "Elapsed"} hours`}
className="px-2"
Expand All @@ -122,10 +122,21 @@ export function Counter() {
className="px-2"
/>
);
const delimiter = <CounterSegment text={":"} className="w-[20px]" />;
return _displays.length
? _displays.reduce(
(acc, val, index) => [...acc, ...(index > 0 ? [delimiter] : []), val],
(acc, val, index) => [
...acc,
...(index > 0
? [
<CounterSegment
key={`del-${index}`}
text={":"}
className="w-[20px]"
/>,
]
: []),
val,
],
[] as JSX.Element[]
)
: _displays;
Expand Down
17 changes: 8 additions & 9 deletions src/components/mode-toggle.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
import { Moon, Sun } from "lucide-react"

import { Button } from "@/components/ui/button"
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import { useTheme } from "@/components/theme-provider"
} from "@/components/ui/dropdown-menu";
import { Moon, Sun } from "lucide-react";
import { Button } from "@/components/ui/button";
import { useTheme } from "@/components/theme-provider";

export function ModeToggle() {
const { setTheme } = useTheme()
const { setTheme } = useTheme();

return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="outline" size="icon">
<Button variant="outline" size="icon" as="div">
<Sun className="h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0" />
<Moon className="absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100" />
<span className="sr-only">Toggle theme</span>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuContent align="end" side="left">
<DropdownMenuItem onClick={() => setTheme("light")}>
Light
</DropdownMenuItem>
Expand All @@ -33,5 +32,5 @@ export function ModeToggle() {
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
)
);
}
2 changes: 1 addition & 1 deletion src/components/picture-upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function PictureUpload({
setIsOpen((old) => !old);
}}
>
<DialogTrigger>
<DialogTrigger asChild>
<Button variant="outline">{btnText}</Button>
</DialogTrigger>
<DialogContent>
Expand Down
4 changes: 2 additions & 2 deletions src/components/settings-toggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export function SettingsToggle() {

return (
<Dialog>
<DialogTrigger>
<Button variant={"outline"} size="icon">
<DialogTrigger asChild>
<Button variant="outline" size="icon" as="div">
<Settings2 className="h-[1.2rem] w-[1.2rem]" />
</Button>
</DialogTrigger>
Expand Down
33 changes: 19 additions & 14 deletions src/components/ui/button.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as React from "react"
import { Slot } from "@radix-ui/react-slot"
import { cva, type VariantProps } from "class-variance-authority"
import * as React from "react";
import { Slot } from "@radix-ui/react-slot";
import { cva, type VariantProps } from "class-variance-authority";

import { cn } from "@/lib/utils"
import { cn } from "@/lib/utils";

const buttonVariants = cva(
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
Expand Down Expand Up @@ -31,26 +31,31 @@ const buttonVariants = cva(
size: "default",
},
}
)
);

export interface ButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
extends React.ButtonHTMLAttributes<HTMLElement>,
VariantProps<typeof buttonVariants> {
asChild?: boolean
asChild?: boolean;
as?: "button" | "div" | "span";
}

const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant, size, asChild = false, ...props }, ref) => {
const Comp = asChild ? Slot : "button"
const Button = React.forwardRef<HTMLElement, ButtonProps>(
(
{ className, variant, size, asChild = false, as = "button", ...props },
ref
) => {
const Comp = asChild ? Slot : as;
return (
<Comp
className={cn(buttonVariants({ variant, size, className }))}
// @ts-ignore
ref={ref}
{...props}
/>
)
);
}
)
Button.displayName = "Button"
);
Button.displayName = "Button";

export { Button, buttonVariants }
export { Button, buttonVariants };

0 comments on commit 4c5d10c

Please sign in to comment.