Skip to content

Commit

Permalink
refactor: Do not import all of React in components
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeroWave022 committed Oct 28, 2024
1 parent 25b88f0 commit fcb0105
Show file tree
Hide file tree
Showing 20 changed files with 99 additions and 102 deletions.
6 changes: 3 additions & 3 deletions src/components/ui/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import { cx } from '@/lib/utils';
import * as AvatarPrimitive from '@radix-ui/react-avatar';
import * as React from 'react';
import { forwardRef } from 'react';

const Avatar = React.forwardRef<
const Avatar = forwardRef<
React.ComponentRef<typeof AvatarPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Root>
>(({ className, ...props }, ref) => (
Expand All @@ -19,7 +19,7 @@ const Avatar = React.forwardRef<
));
Avatar.displayName = AvatarPrimitive.Root.displayName;

const AvatarFallback = React.forwardRef<
const AvatarFallback = forwardRef<
React.ComponentRef<typeof AvatarPrimitive.Fallback>,
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Fallback>
>(({ className, ...props }, ref) => (
Expand Down
1 change: 0 additions & 1 deletion src/components/ui/Badge.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { type VariantProps, cva, cx } from '@/lib/utils';
import type * as React from 'react';

const badgeVariants = cva({
base: 'inline-flex items-center rounded-md border px-2.5 py-0.5 font-semibold text-xs transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2',
Expand Down
4 changes: 2 additions & 2 deletions src/components/ui/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type VariantProps, cva } from '@/lib/utils';
import { Slot } from '@radix-ui/react-slot';
import * as React from 'react';
import { forwardRef } from 'react';

const buttonVariants = cva({
base: 'inline-flex items-center justify-center whitespace-nowrap rounded-md font-medium text-sm 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 @@ -39,7 +39,7 @@ export interface ButtonProps
asChild?: boolean;
}

const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
const Button = forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant, size, asChild = false, ...props }, ref) => {
const Comp = asChild ? Slot : 'button';
return (
Expand Down
37 changes: 18 additions & 19 deletions src/components/ui/Card.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
import { cx } from '@/lib/utils';
import * as React from 'react';
import { forwardRef } from 'react';

type CardTitleProps = {
level?: 'h2' | 'h3' | 'h4';
} & React.HTMLAttributes<HTMLHeadingElement>;

const Card = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cx(
'rounded-lg border bg-card text-card-foreground shadow-sm',
className,
)}
{...props}
/>
));
const Card = forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
({ className, ...props }, ref) => (
<div
ref={ref}
className={cx(
'rounded-lg border bg-card text-card-foreground shadow-sm',
className,
)}
{...props}
/>
),
);
Card.displayName = 'Card';

const CardHeader = React.forwardRef<
const CardHeader = forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
Expand All @@ -32,7 +31,7 @@ const CardHeader = React.forwardRef<
));
CardHeader.displayName = 'CardHeader';

const CardTitle = React.forwardRef<HTMLParagraphElement, CardTitleProps>(
const CardTitle = forwardRef<HTMLParagraphElement, CardTitleProps>(
({ level = 'h3', className, ...props }, ref) => {
const Component = level;

Expand All @@ -50,7 +49,7 @@ const CardTitle = React.forwardRef<HTMLParagraphElement, CardTitleProps>(
);
CardTitle.displayName = 'CardTitle';

const CardDescription = React.forwardRef<
const CardDescription = forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLParagraphElement>
>(({ className, ...props }, ref) => (
Expand All @@ -62,15 +61,15 @@ const CardDescription = React.forwardRef<
));
CardDescription.displayName = 'CardDescription';

const CardContent = React.forwardRef<
const CardContent = forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div ref={ref} className={cx('p-6 pt-0', className)} {...props} />
));
CardContent.displayName = 'CardContent';

const CardFooter = React.forwardRef<
const CardFooter = forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
Expand Down
6 changes: 3 additions & 3 deletions src/components/ui/Combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '@/components/ui/Popover';
import { cx } from '@/lib/utils';
import { CheckIcon, ChevronsUpDownIcon } from 'lucide-react';
import * as React from 'react';
import { useState } from 'react';

type ComboboxProps = {
choices: {
Expand All @@ -42,8 +42,8 @@ function Combobox({
initialValue,
ariaLabel,
}: ComboboxProps) {
const [open, setOpen] = React.useState(false);
const [value, setValue] = React.useState<string | null>(initialValue ?? '');
const [open, setOpen] = useState(false);
const [value, setValue] = useState<string | null>(initialValue ?? '');

return (
<Popover open={open} onOpenChange={setOpen}>
Expand Down
16 changes: 8 additions & 8 deletions src/components/ui/Command.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { cx } from '@/lib/utils';
import type { DialogProps } from '@radix-ui/react-dialog';
import { Command as CommandPrimitive } from 'cmdk';
import { SearchIcon } from 'lucide-react';
import * as React from 'react';
import { forwardRef } from 'react';

const Command = React.forwardRef<
const Command = forwardRef<
React.ComponentRef<typeof CommandPrimitive>,
React.ComponentPropsWithoutRef<typeof CommandPrimitive>
>(({ className, ...props }, ref) => (
Expand Down Expand Up @@ -36,7 +36,7 @@ const CommandDialog = ({ children, ...props }: CommandDialogProps) => {
);
};

const CommandInput = React.forwardRef<
const CommandInput = forwardRef<
React.ComponentRef<typeof CommandPrimitive.Input>,
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Input>
>(({ className, ...props }, ref) => (
Expand All @@ -55,7 +55,7 @@ const CommandInput = React.forwardRef<

CommandInput.displayName = CommandPrimitive.Input.displayName;

const CommandList = React.forwardRef<
const CommandList = forwardRef<
React.ComponentRef<typeof CommandPrimitive.List>,
React.ComponentPropsWithoutRef<typeof CommandPrimitive.List>
>(({ className, ...props }, ref) => (
Expand All @@ -68,7 +68,7 @@ const CommandList = React.forwardRef<

CommandList.displayName = CommandPrimitive.List.displayName;

const CommandEmpty = React.forwardRef<
const CommandEmpty = forwardRef<
React.ComponentRef<typeof CommandPrimitive.Empty>,
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Empty>
>((props, ref) => (
Expand All @@ -81,7 +81,7 @@ const CommandEmpty = React.forwardRef<

CommandEmpty.displayName = CommandPrimitive.Empty.displayName;

const CommandGroup = React.forwardRef<
const CommandGroup = forwardRef<
React.ComponentRef<typeof CommandPrimitive.Group>,
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Group>
>(({ className, ...props }, ref) => (
Expand All @@ -97,7 +97,7 @@ const CommandGroup = React.forwardRef<

CommandGroup.displayName = CommandPrimitive.Group.displayName;

const CommandSeparator = React.forwardRef<
const CommandSeparator = forwardRef<
React.ComponentRef<typeof CommandPrimitive.Separator>,
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Separator>
>(({ className, ...props }, ref) => (
Expand All @@ -109,7 +109,7 @@ const CommandSeparator = React.forwardRef<
));
CommandSeparator.displayName = CommandPrimitive.Separator.displayName;

const CommandItem = React.forwardRef<
const CommandItem = forwardRef<
React.ComponentRef<typeof CommandPrimitive.Item>,
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Item>
>(({ className, ...props }, ref) => (
Expand Down
10 changes: 5 additions & 5 deletions src/components/ui/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { cx } from '@/lib/utils';
import * as DialogPrimitive from '@radix-ui/react-dialog';
import { XIcon } from 'lucide-react';
import * as React from 'react';
import { forwardRef } from 'react';

const Dialog = DialogPrimitive.Root;

Expand All @@ -13,7 +13,7 @@ const DialogPortal = DialogPrimitive.Portal;

const DialogClose = DialogPrimitive.Close;

const DialogOverlay = React.forwardRef<
const DialogOverlay = forwardRef<
React.ComponentRef<typeof DialogPrimitive.Overlay>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
>(({ className, ...props }, ref) => (
Expand All @@ -28,7 +28,7 @@ const DialogOverlay = React.forwardRef<
));
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;

const DialogContent = React.forwardRef<
const DialogContent = forwardRef<
React.ComponentRef<typeof DialogPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
>(({ className, children, ...props }, ref) => (
Expand Down Expand Up @@ -80,7 +80,7 @@ const DialogFooter = ({
);
DialogFooter.displayName = 'DialogFooter';

const DialogTitle = React.forwardRef<
const DialogTitle = forwardRef<
React.ComponentRef<typeof DialogPrimitive.Title>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
>(({ className, ...props }, ref) => (
Expand All @@ -95,7 +95,7 @@ const DialogTitle = React.forwardRef<
));
DialogTitle.displayName = DialogPrimitive.Title.displayName;

const DialogDescription = React.forwardRef<
const DialogDescription = forwardRef<
React.ComponentRef<typeof DialogPrimitive.Description>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
>(({ className, ...props }, ref) => (
Expand Down
10 changes: 5 additions & 5 deletions src/components/ui/Drawer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import * as React from 'react';
import { forwardRef } from 'react';
import { Drawer as DrawerPrimitive } from 'vaul';

import { cx } from '@/lib/utils';
Expand All @@ -22,7 +22,7 @@ const DrawerPortal = DrawerPrimitive.Portal;

const DrawerClose = DrawerPrimitive.Close;

const DrawerOverlay = React.forwardRef<
const DrawerOverlay = forwardRef<
React.ComponentRef<typeof DrawerPrimitive.Overlay>,
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Overlay>
>(({ className, ...props }, ref) => (
Expand All @@ -34,7 +34,7 @@ const DrawerOverlay = React.forwardRef<
));
DrawerOverlay.displayName = DrawerPrimitive.Overlay.displayName;

const DrawerContent = React.forwardRef<
const DrawerContent = forwardRef<
React.ComponentRef<typeof DrawerPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Content>
>(({ className, children, ...props }, ref) => (
Expand Down Expand Up @@ -77,7 +77,7 @@ const DrawerFooter = ({
);
DrawerFooter.displayName = 'DrawerFooter';

const DrawerTitle = React.forwardRef<
const DrawerTitle = forwardRef<
React.ComponentRef<typeof DrawerPrimitive.Title>,
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Title>
>(({ className, ...props }, ref) => (
Expand All @@ -92,7 +92,7 @@ const DrawerTitle = React.forwardRef<
));
DrawerTitle.displayName = DrawerPrimitive.Title.displayName;

const DrawerDescription = React.forwardRef<
const DrawerDescription = forwardRef<
React.ComponentRef<typeof DrawerPrimitive.Description>,
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Description>
>(({ className, ...props }, ref) => (
Expand Down
18 changes: 9 additions & 9 deletions src/components/ui/DropdownMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';
import { CheckIcon, ChevronRightIcon, CircleIcon } from 'lucide-react';
import * as React from 'react';
import { forwardRef } from 'react';

import { cx } from '@/lib/utils';

Expand All @@ -18,7 +18,7 @@ const DropdownMenuSub = DropdownMenuPrimitive.Sub;

const DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup;

const DropdownMenuSubTrigger = React.forwardRef<
const DropdownMenuSubTrigger = forwardRef<
React.ComponentRef<typeof DropdownMenuPrimitive.SubTrigger>,
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubTrigger> & {
inset?: boolean;
Expand All @@ -40,7 +40,7 @@ const DropdownMenuSubTrigger = React.forwardRef<
DropdownMenuSubTrigger.displayName =
DropdownMenuPrimitive.SubTrigger.displayName;

const DropdownMenuSubContent = React.forwardRef<
const DropdownMenuSubContent = forwardRef<
React.ComponentRef<typeof DropdownMenuPrimitive.SubContent>,
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubContent>
>(({ className, ...props }, ref) => (
Expand All @@ -56,7 +56,7 @@ const DropdownMenuSubContent = React.forwardRef<
DropdownMenuSubContent.displayName =
DropdownMenuPrimitive.SubContent.displayName;

const DropdownMenuContent = React.forwardRef<
const DropdownMenuContent = forwardRef<
React.ComponentRef<typeof DropdownMenuPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Content>
>(({ className, sideOffset = 4, ...props }, ref) => (
Expand All @@ -74,7 +74,7 @@ const DropdownMenuContent = React.forwardRef<
));
DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName;

const DropdownMenuItem = React.forwardRef<
const DropdownMenuItem = forwardRef<
React.ComponentRef<typeof DropdownMenuPrimitive.Item>,
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Item> & {
inset?: boolean;
Expand All @@ -92,7 +92,7 @@ const DropdownMenuItem = React.forwardRef<
));
DropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName;

const DropdownMenuCheckboxItem = React.forwardRef<
const DropdownMenuCheckboxItem = forwardRef<
React.ComponentRef<typeof DropdownMenuPrimitive.CheckboxItem>,
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.CheckboxItem>
>(({ className, children, checked, ...props }, ref) => (
Expand All @@ -116,7 +116,7 @@ const DropdownMenuCheckboxItem = React.forwardRef<
DropdownMenuCheckboxItem.displayName =
DropdownMenuPrimitive.CheckboxItem.displayName;

const DropdownMenuRadioItem = React.forwardRef<
const DropdownMenuRadioItem = forwardRef<
React.ComponentRef<typeof DropdownMenuPrimitive.RadioItem>,
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.RadioItem>
>(({ className, children, ...props }, ref) => (
Expand All @@ -138,7 +138,7 @@ const DropdownMenuRadioItem = React.forwardRef<
));
DropdownMenuRadioItem.displayName = DropdownMenuPrimitive.RadioItem.displayName;

const DropdownMenuLabel = React.forwardRef<
const DropdownMenuLabel = forwardRef<
React.ComponentRef<typeof DropdownMenuPrimitive.Label>,
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Label> & {
inset?: boolean;
Expand All @@ -156,7 +156,7 @@ const DropdownMenuLabel = React.forwardRef<
));
DropdownMenuLabel.displayName = DropdownMenuPrimitive.Label.displayName;

const DropdownMenuSeparator = React.forwardRef<
const DropdownMenuSeparator = forwardRef<
React.ComponentRef<typeof DropdownMenuPrimitive.Separator>,
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Separator>
>(({ className, ...props }, ref) => (
Expand Down
Loading

0 comments on commit fcb0105

Please sign in to comment.