Skip to content

Commit

Permalink
Remove lots of unecessary cn
Browse files Browse the repository at this point in the history
  • Loading branch information
oBusk committed May 3, 2023
1 parent 17000ba commit ee44310
Show file tree
Hide file tree
Showing 43 changed files with 117 additions and 133 deletions.
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
"@radix-ui/react-tooltip": "^1.0.5",
"@vercel/analytics": "^1.0.0",
"class-variance-authority": "^0.6.0",
"clsx": "^1.2.1",
"downshift": "^7.6.0",
"gitdiff-parser": "^0.3.1",
"jest": "^29.5.0",
Expand Down
6 changes: 3 additions & 3 deletions src/app/[...parts]/_error/ErrorBox.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { ElementRef, forwardRef } from "react";
import BorderBox, { BorderBoxProps } from "^/components/ui/BorderBox";
import cn from "^/lib/cn";
import { cx } from "^/lib/cva";

export interface ErrorBoxProps extends BorderBoxProps {}

const ErrorBox = forwardRef<ElementRef<typeof BorderBox>, ErrorBoxProps>(
(props, ref) => {
({ className, ...props }, ref) => {
return (
<BorderBox
className={cn("bg-red-200 dark:bg-red-700")}
className={cx("bg-red-200 dark:bg-red-700", className)}
{...props}
ref={ref}
/>
Expand Down
4 changes: 2 additions & 2 deletions src/app/[...parts]/_page/DiffIntro/DiffIntro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
Text,
} from "@chakra-ui/react";
import { ReactNode } from "react";
import cn from "^/lib/cn";
import { cx } from "^/lib/cva";
import { NpmDiffOptions } from "^/lib/npmDiff";
import SimplePackageSpec from "^/lib/SimplePackageSpec";
import contentVisibility from "^/lib/utils/contentVisibility";
Expand Down Expand Up @@ -41,7 +41,7 @@ const DiffIntro = forwardRef<DiffIntroProps, "h2">(
css={{
label: "DiffIntro",
}}
className={cn(contentVisibility("700px"), className)}
className={cx(contentVisibility("700px"), className)}
{...props}
ref={ref}
>
Expand Down
4 changes: 2 additions & 2 deletions src/app/[...parts]/_page/DiffIntro/Options.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Code, Heading, Text } from "@chakra-ui/react";
import { ElementRef, forwardRef } from "react";
import BorderBox, { BorderBoxProps } from "^/components/ui/BorderBox";
import cn from "^/lib/cn";
import { cx } from "^/lib/cva";
import { NpmDiffOptions } from "^/lib/npmDiff";

interface OptionsProps extends BorderBoxProps {
Expand All @@ -18,7 +18,7 @@ const Options = forwardRef<ElementRef<typeof BorderBox>, OptionsProps>(
);

return (
<BorderBox className={cn("my-2", className)} {...props} ref={ref}>
<BorderBox className={cx("my-2", className)} {...props} ref={ref}>
<Heading size="xs" marginBottom="1em">
Options
</Heading>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Box, Skeleton } from "@chakra-ui/react";
import CollapsableBorderBox from "^/components/CollapsableBorderBox";
import cn from "^/lib/cn";
import { cx } from "^/lib/cva";
import contentVisibility from "^/lib/utils/contentVisibility";
import { DiffFileHeaderSkeleton } from "./DiffFileHeader";

Expand All @@ -23,7 +23,7 @@ const FakeCodeRow = ({
export default function DiffFileSkeleton() {
return (
<CollapsableBorderBox
className={cn("my-4 text-base", contentVisibility("700px"))}
className={cx("my-4 text-base", contentVisibility("700px"))}
header={<DiffFileHeaderSkeleton />}
>
<Box
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import "react-diff-view/style/index.css";
import CollapsableBorderBox, {
CollapsableBorderBoxProps,
} from "^/components/CollapsableBorderBox";
import cn from "^/lib/cn";
import { cx } from "^/lib/cva";
import SimplePackageSpec from "^/lib/SimplePackageSpec";
import contentVisibility from "^/lib/utils/contentVisibility";
import countChanges from "^/lib/utils/countChanges";
Expand Down Expand Up @@ -63,7 +63,7 @@ const DiffFile = forwardRef<DiffFileProps, typeof CollapsableBorderBox>(
label: "DiffFile",
margin: "1em 0",
}}
className={cn(contentVisibility("700px", className))}
className={cx(contentVisibility("700px", className))}
header={
<DiffFileHeader
a={a}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Text } from "@chakra-ui/react";
import { FunctionComponent } from "react";
import { HunkData } from "react-diff-view";
import cn from "^/lib/cn";
import contentVisibility from "^/lib/utils/contentVisibility";
import { Decoration, Hunk } from "./react-diff-view";

Expand All @@ -20,7 +19,7 @@ const DiffHunk: FunctionComponent<DiffHunkProps> = ({ hunk }) => (
css={{
label: "DiffHunk",
}}
className={cn(contentVisibility("800px"))}
className={contentVisibility("800px")}
>
<Text padding="10px">{hunk.content}</Text>
</Decoration>
Expand Down
3 changes: 1 addition & 2 deletions src/app/[...parts]/_page/NpmDiff/DiffFiles/DiffFiles.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Box } from "@chakra-ui/react";
import { FunctionComponent } from "react";
import { FileData } from "react-diff-view";
import cn from "^/lib/cn";
import SimplePackageSpec from "^/lib/SimplePackageSpec";
import useViewType from "^/lib/utils/useViewType";
import DiffFileComponent from "./DiffFile";
Expand All @@ -25,7 +24,7 @@ const DiffFiles: FunctionComponent<DiffFilesProps> = ({ a, b, files }) => {
b={b}
file={file}
viewType={viewType}
className={cn("w-full")}
className="w-full"
/>
))}
</Box>
Expand Down
6 changes: 3 additions & 3 deletions src/app/[...parts]/_page/SizeComparison/SizeComparison.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Box, Flex, Heading, Text } from "@chakra-ui/react";
import { FunctionComponent, ReactNode } from "react";
import ExternalLink, { ExternalLinkProps } from "^/components/ExternalLink";
import Span from "^/components/Span";
import cn from "^/lib/cn";
import { cx } from "^/lib/cva";
import { Service, ServiceName, Services } from "^/lib/Services";
import SimplePackageSpec from "^/lib/SimplePackageSpec";
import { prettyByte } from "^/lib/utils/prettyByte";
Expand Down Expand Up @@ -60,7 +60,7 @@ const LinkButton: FunctionComponent<
{...props}
/> */}
<ExternalLink
className={cn("rounded-lg p-2 text-center", className)}
className={cx("rounded-lg p-2 text-center", className)}
href={service.url(pkg)}
{...props}
/>
Expand Down Expand Up @@ -152,7 +152,7 @@ const SizeComparison = ({
</LinkButton>
}
center={
<Box className={cn("p-2")} textAlign="center">
<Box className="p-2" textAlign="center">
{sizeRows.map((sizeRow) => (
<Text key={sizeRow.name}>{sizeRow.name}</Text>
))}
Expand Down
4 changes: 2 additions & 2 deletions src/app/_layout/Footer.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { forwardRef, HTMLAttributes } from "react";
import cn from "^/lib/cn";
import { cx } from "^/lib/cva";

interface FooterProps extends HTMLAttributes<HTMLDivElement> {}

const Footer = forwardRef<HTMLDivElement, FooterProps>(
({ className, ...props }, ref) => (
<footer
className={cn("contain-content flex", className)}
className={cx("contain-content flex", className)}
{...props}
ref={ref}
/>
Expand Down
7 changes: 4 additions & 3 deletions src/app/_layout/Header/ColorModeToggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { useTheme } from "next-themes";
import { forwardRef, useEffect, useState } from "react";
import Button, { ButtonProps } from "^/components/ui/Button";
import Tooltip from "^/components/ui/Tooltip";
import cn from "^/lib/cn";
import { cx } from "^/lib/cva";

export interface ColorModeToggleProps extends ButtonProps {}

const ColorModeToggle = forwardRef<HTMLButtonElement, ColorModeToggleProps>(
({ ...props }, ref) => {
({ className, ...props }, ref) => {
const [mounted, setMounted] = useState(false);
const { setTheme, theme } = useTheme();

Expand All @@ -29,9 +29,10 @@ const ColorModeToggle = forwardRef<HTMLButtonElement, ColorModeToggleProps>(
setTheme(theme === "dark" ? "light" : "dark")
}
aria-label={label}
className={cn(
className={cx(
"transition-opacity duration-500",
!mounted && "opacity-0",
className,
)}
{...props}
ref={ref}
Expand Down
13 changes: 5 additions & 8 deletions src/app/_layout/Header/GithubLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { ElementRef, forwardRef } from "react";
import ExternalLink, { ExternalLinkProps } from "^/components/ExternalLink";
import { buttonVariants } from "^/components/ui/Button";
import Tooltip from "^/components/ui/Tooltip";
import cn from "^/lib/cn";

export interface GithubLinkProps
extends Omit<ExternalLinkProps, "aria-label"> {}
Expand All @@ -14,13 +13,11 @@ const GithubLink = forwardRef<ElementRef<typeof ExternalLink>, GithubLinkProps>(
return (
<Tooltip label={label}>
<ExternalLink
className={cn(
buttonVariants({
className,
variant: "ghost",
size: "xs",
}),
)}
className={buttonVariants({
className,
variant: "ghost",
size: "xs",
})}
aria-label={label}
href="https://github.com/oBusk/npm-diff.app"
{...props}
Expand Down
4 changes: 2 additions & 2 deletions src/app/_layout/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Link from "next/link";
import { forwardRef, HTMLAttributes } from "react";
import Heading from "^/components/ui/Heading";
import cn from "^/lib/cn";
import { cx } from "^/lib/cva";
import ColorModeToggle from "./ColorModeToggle";
import GithubLink from "./GithubLink";
import NavLink from "./NavLink";
Expand All @@ -11,7 +11,7 @@ export interface HeaderProps extends HTMLAttributes<HTMLElement> {}
const Header = forwardRef<HTMLElement, HeaderProps>(
({ className, ...props }, ref) => (
<nav
className={cn(
className={cx(
"sticky inset-x-0 top-0 z-10 flex items-center justify-between px-4 py-6",
className,
)}
Expand Down
5 changes: 2 additions & 3 deletions src/app/_layout/Header/NavLink.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"use client";

import { cva } from "class-variance-authority";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { AnchorHTMLAttributes, forwardRef, useEffect, useState } from "react";
import cn from "^/lib/cn";
import { cva } from "^/lib/cva";

const navLinkVariants = cva(
"block rounded-md transition-all duration-200 focus:outline-none",
Expand Down Expand Up @@ -41,7 +40,7 @@ const NavLink = forwardRef<HTMLAnchorElement, NavLinkProps>(
return (
<Link
href={href}
className={cn(navLinkVariants({ isActive, className }))}
className={navLinkVariants({ isActive, className })}
{...props}
ref={ref}
/>
Expand Down
5 changes: 2 additions & 3 deletions src/app/_page/ExamplesList.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Link from "next/link";
import { ElementRef, forwardRef } from "react";
import Stack, { StackProps } from "^/components/ui/Stack";
import cn from "^/lib/cn";
import EXAMPLES from "^/lib/examples";
import { QueryParams } from "^/lib/query";

Expand Down Expand Up @@ -31,10 +30,10 @@ const ExamplesList = forwardRef<ElementRef<typeof Stack>, ExamplesListProps>(

return (
<Stack align="center" {...props} ref={ref}>
<h2 className={cn("text-xl font-bold")}>Examples</h2>
<h2 className="text-xl font-bold">Examples</h2>
{EXAMPLES.map((ex) => (
<Link
className={cn("my-1 hover:underline")}
className="my-1 hover:underline"
key={ex}
href={{
pathname: `/${ex}`,
Expand Down
5 changes: 2 additions & 3 deletions src/app/_page/Intro.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { forwardRef, HTMLAttributes } from "react";
import ExternalLink from "^/components/ExternalLink";
import Code from "^/components/ui/Code";
import cn from "^/lib/cn";

export interface IntroProps extends HTMLAttributes<HTMLElement> {}

const Intro = forwardRef<HTMLElement, IntroProps>((props, ref) => (
<section {...props} ref={ref}>
<p className={cn("text-center")}>
<p className="text-center">
<ExternalLink href="https://docs.npmjs.com/cli/v7/commands/npm-diff">
<Code>npm diff</Code>
</ExternalLink>{" "}
online!
</p>
<p className={cn("text-center")}>
<p className="text-center">
Web tool to compare versions, or branches, of NPM packages.
</p>
</section>
Expand Down
4 changes: 2 additions & 2 deletions src/app/_page/MainForm/CenterInputAddon.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { forwardRef, HTMLAttributes } from "react";
import cn from "^/lib/cn";
import { cx } from "^/lib/cva";

export interface InputAddonProps extends HTMLAttributes<HTMLDivElement> {}

const CenterInputAddon = forwardRef<HTMLDivElement, InputAddonProps>(
({ className, ...props }, ref) => (
<div
className={cn("h-10 select-none border bg-accent p-2", className)}
className={cx("h-10 select-none border bg-accent p-2", className)}
{...props}
ref={ref}
/>
Expand Down
10 changes: 5 additions & 5 deletions src/app/_page/MainForm/MainForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
TooltipTrigger,
} from "^/components/ui/Tooltip";
import { AutocompleteSuggestion } from "^/lib/autocomplete";
import cn from "^/lib/cn";
import { cx } from "^/lib/cva";
import CenterInputAddon from "./CenterInputAddon";
import SpecInput from "./SpecInput";

Expand Down Expand Up @@ -86,7 +86,7 @@ const MainForm = forwardRef<HTMLFormElement, MainFormProps>(

return (
<form
className={cn(
className={cx(
"flex flex-col lg:flex-row",
"items-center justify-center",
className,
Expand All @@ -108,7 +108,7 @@ const MainForm = forwardRef<HTMLFormElement, MainFormProps>(
}
}}
inputProps={{
className: cn("lg:rounded-r-none", "lg:border-r-0"),
className: "lg:rounded-r-none lg:border-r-0",
...(overrideA
? {
value: overrideA,
Expand All @@ -128,10 +128,10 @@ const MainForm = forwardRef<HTMLFormElement, MainFormProps>(
onInputValueChange={setB}
optionalPackageFilter={bPackageFilter}
wrapperProps={{
className: cn("mt-2", "lg:mt-0"),
className: "mt-2 lg:mt-0",
}}
inputProps={{
className: cn("lg:rounded-l-none", "lg:border-l-0"),
className: "lg:rounded-l-none lg:border-l-0",
...(overrideB
? {
value: overrideB,
Expand Down
5 changes: 2 additions & 3 deletions src/app/_page/MainForm/SpecInput/Combobox/ComboboxInput.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { cva, VariantProps } from "class-variance-authority";
import { ElementRef, forwardRef } from "react";
import Input, { InputProps } from "^/components/ui/Input";
import cn from "^/lib/cn";
import { cva, VariantProps } from "^/lib/cva";

const comboboxInputVariants = cva(null, {
variants: {
Expand All @@ -20,7 +19,7 @@ const ComboboxInput = forwardRef<ElementRef<typeof Input>, ComboboxInputProps>(
<Input
type="text"
ring={false}
className={cn(comboboxInputVariants({ isOpen, className }))}
className={comboboxInputVariants({ isOpen, className })}
ref={ref}
{...props}
/>
Expand Down
Loading

0 comments on commit ee44310

Please sign in to comment.