Skip to content

Commit

Permalink
feat: use @nextui-org/react package
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Oct 13, 2023
1 parent b408c87 commit e306722
Show file tree
Hide file tree
Showing 10 changed files with 1,502 additions and 381 deletions.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
public-hoist-pattern[]=*@nextui-org/*
6 changes: 3 additions & 3 deletions app/builder.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"use client"

import { Button } from "@nextui-org/button"
import { Input } from "@nextui-org/input"
import { Button, Input } from "@nextui-org/react"
import copy from "copy-to-clipboard"
import { useState, useMemo } from "react"

Expand All @@ -13,10 +12,11 @@ export function Builder() {
}, [repos])
const [copied, setCopied] = useState(false)
return (
<div className="w-full pt-4 md:px-10 flex gap-2 flex-col">
<div className="w-full pt-4 md:px-10 lg:px-[20%] flex gap-2 flex-col">
<Input
value={text}
onChange={(e) => setText(e.target.value)}
placeholder="Input your repo as owner/repo"
className="w-full"
onKeyDown={(e) => {
if (e.key === "Enter") {
Expand Down
12 changes: 6 additions & 6 deletions app/error.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client'
import { useEffect } from 'react'
"use client"

import { useEffect } from "react"

export default function Error({
error,
reset,
Expand All @@ -13,7 +13,7 @@ export default function Error({
// Log the error to an error reporting service
console.error(error)
}, [error])

return (
<div>
<h2>Something went wrong!</h2>
Expand All @@ -27,4 +27,4 @@ export default function Error({
</button>
</div>
)
}
}
17 changes: 9 additions & 8 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,16 @@ export default function RootLayout({
{children}
</main>
<footer className="w-full flex items-center justify-center py-3">
<Link
isExternal
className="flex items-center gap-1 text-current"
href="https://nextui-docs-v2.vercel.app?utm_source=next-app-template"
title="nextui.org homepage"
>
<div className="flex items-center gap-1 text-current">
<span className="text-default-600">Built with ❤ and&nbsp;</span>
<p className="text-primary">NextJS</p>
</Link>
<Link
isExternal
href="https://nextjs.org/"
className="text-primary"
>
NextJS
</Link>
</div>
</footer>
</div>
</Providers>
Expand Down
24 changes: 12 additions & 12 deletions app/providers.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
"use client";
"use client"

import * as React from "react";
import { NextUIProvider } from "@nextui-org/system";
import { ThemeProvider as NextThemesProvider } from "next-themes";
import { ThemeProviderProps } from "next-themes/dist/types";
import * as React from "react"
import { NextUIProvider } from "@nextui-org/react"
import { ThemeProvider as NextThemesProvider } from "next-themes"
import { ThemeProviderProps } from "next-themes/dist/types"

export interface ProvidersProps {
children: React.ReactNode;
themeProps?: ThemeProviderProps;
children: React.ReactNode
themeProps?: ThemeProviderProps
}

export function Providers({ children, themeProps }: ProvidersProps) {
return (
<NextUIProvider>
<NextThemesProvider {...themeProps}>{children}</NextThemesProvider>
</NextUIProvider>
);
return (
<NextUIProvider>
<NextThemesProvider {...themeProps}>{children}</NextThemesProvider>
</NextUIProvider>
)
}
20 changes: 10 additions & 10 deletions components/counter.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"use client";
"use client"

import { useState } from "react";
import { Button } from "@nextui-org/button";
import { useState } from "react"
import { Button } from "@nextui-org/react"

export const Counter = () => {
const [count, setCount] = useState(0);
const [count, setCount] = useState(0)

return (
<Button radius="full" onPress={() => setCount(count + 1)}>
Count is {count}
</Button>
);
};
return (
<Button radius="full" onPress={() => setCount(count + 1)}>
Count is {count}
</Button>
)
}
10 changes: 5 additions & 5 deletions components/navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"use client"

import {
Navbar as NextUINavbar,
NavbarContent,
NavbarBrand,
NavbarItem,
} from "@nextui-org/navbar"
import { Button } from "@nextui-org/button"
import { Link } from "@nextui-org/link"
Button,
Link,
} from "@nextui-org/react"
import { siteConfig } from "@/config/site"
import NextLink from "next/link"
import { ThemeSwitch } from "@/components/theme-switch"
import { GithubIcon, HeartFilledIcon } from "@/components/icons"

Expand Down
138 changes: 72 additions & 66 deletions components/theme-switch.tsx
Original file line number Diff line number Diff line change
@@ -1,77 +1,83 @@
"use client";
"use client"

import { FC } from "react";
import { VisuallyHidden } from "@react-aria/visually-hidden";
import { SwitchProps, useSwitch } from "@nextui-org/switch";
import { useTheme } from "next-themes";
import {useIsSSR} from "@react-aria/ssr";
import clsx from "clsx";
import { FC } from "react"
import { VisuallyHidden } from "@react-aria/visually-hidden"
import { SwitchProps, useSwitch } from "@nextui-org/react"
import { useTheme } from "next-themes"
import { useIsSSR } from "@react-aria/ssr"
import clsx from "clsx"

import { SunFilledIcon, MoonFilledIcon } from "@/components/icons";
import { SunFilledIcon, MoonFilledIcon } from "@/components/icons"

export interface ThemeSwitchProps {
className?: string;
classNames?: SwitchProps["classNames"];
className?: string
classNames?: SwitchProps["classNames"]
}

export const ThemeSwitch: FC<ThemeSwitchProps> = ({
className,
classNames,
className,
classNames,
}) => {
const { theme, setTheme } = useTheme();
const isSSR = useIsSSR();
const { theme, setTheme } = useTheme()
const isSSR = useIsSSR()

const onChange = () => {
theme === "light" ? setTheme("dark") : setTheme("light");
};
const onChange = () => {
theme === "light" ? setTheme("dark") : setTheme("light")
}

const {
Component,
slots,
isSelected,
getBaseProps,
getInputProps,
getWrapperProps,
} = useSwitch({
isSelected: theme === "light" || isSSR,
"aria-label": `Switch to ${theme === "light" || isSSR ? "dark" : "light"} mode`,
onChange,
});
const {
Component,
slots,
isSelected,
getBaseProps,
getInputProps,
getWrapperProps,
} = useSwitch({
isSelected: theme === "light" || isSSR,
"aria-label": `Switch to ${
theme === "light" || isSSR ? "dark" : "light"
} mode`,
onChange,
})

return (
<Component
{...getBaseProps({
className: clsx(
"px-px transition-opacity hover:opacity-80 cursor-pointer",
className,
classNames?.base
),
})}
>
<VisuallyHidden>
<input {...getInputProps()} />
</VisuallyHidden>
<div
{...getWrapperProps()}
className={slots.wrapper({
class: clsx(
[
"w-auto h-auto",
"bg-transparent",
"rounded-lg",
"flex items-center justify-center",
"group-data-[selected=true]:bg-transparent",
"!text-default-500",
"pt-px",
"px-0",
"mx-0",
],
classNames?.wrapper
),
})}
>
{!isSelected || isSSR ? <SunFilledIcon size={22} /> : <MoonFilledIcon size={22} />}
</div>
</Component>
);
};
return (
<Component
{...getBaseProps({
className: clsx(
"px-px transition-opacity hover:opacity-80 cursor-pointer",
className,
classNames?.base
),
})}
>
<VisuallyHidden>
<input {...getInputProps()} />
</VisuallyHidden>
<div
{...getWrapperProps()}
className={slots.wrapper({
class: clsx(
[
"w-auto h-auto",
"bg-transparent",
"rounded-lg",
"flex items-center justify-center",
"group-data-[selected=true]:bg-transparent",
"!text-default-500",
"pt-px",
"px-0",
"mx-0",
],
classNames?.wrapper
),
})}
>
{!isSelected || isSSR ? (
<SunFilledIcon size={22} />
) : (
<MoonFilledIcon size={22} />
)}
</div>
</Component>
)
}
11 changes: 1 addition & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,7 @@
"lint": "next lint"
},
"dependencies": {
"@nextui-org/button": "2.0.18",
"@nextui-org/code": "2.0.16",
"@nextui-org/input": "2.1.6",
"@nextui-org/kbd": "2.0.17",
"@nextui-org/link": "2.0.19",
"@nextui-org/navbar": "2.0.19",
"@nextui-org/snippet": "2.0.22",
"@nextui-org/switch": "2.0.18",
"@nextui-org/system": "2.0.7",
"@nextui-org/theme": "2.1.6",
"@nextui-org/react": "^2.1.13",
"@react-aria/ssr": "^3.7.1",
"@react-aria/visually-hidden": "^3.8.3",
"@types/node": "20.5.7",
Expand Down
Loading

0 comments on commit e306722

Please sign in to comment.