Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chakra v3 update #89

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,190 changes: 601 additions & 589 deletions example/index.tsx

Large diffs are not rendered by default.

111 changes: 77 additions & 34 deletions example/package-lock.json

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

5 changes: 3 additions & 2 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"preview": "vite preview"
},
"dependencies": {
"next-themes": "^0.3.0",
"react-app-polyfill": "^1.0.6",
"react-github-btn": "^1.4.0"
},
Expand All @@ -20,8 +21,8 @@
"scheduler/tracing": "../node_modules/scheduler/tracing-profiling"
},
"devDependencies": {
"@types/react": "^17.0.15",
"@types/react-dom": "^17.0.9",
"@types/react": "^18.3.5",
"@types/react-dom": "^18.3.0",
"typescript": "^4",
"vite": "latest",
"vite-preset-react": "latest"
Expand Down
66 changes: 66 additions & 0 deletions example/snippets/color-mode.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"use client"

import React from "react"
import type { IconButtonProps } from "@chakra-ui/react"
// import { ClientOnly, IconButton, Skeleton } from "@chakra-ui/react"
import { ThemeProvider, useTheme } from "next-themes"
import type { ThemeProviderProps } from "next-themes/dist/types"
// import { forwardRef } from "react"
// import { LuMoon, LuSun } from "react-icons/lu"

export function ColorModeProvider(props: ThemeProviderProps) {
return (
<ThemeProvider attribute="class" disableTransitionOnChange {...props} />
)
}

export function useColorMode() {
const { resolvedTheme, setTheme } = useTheme()
const toggleColorMode = () => {
setTheme(resolvedTheme === "light" ? "dark" : "light")
}
return {
colorMode: resolvedTheme,
setColorMode: setTheme,
toggleColorMode,
}
}

export function useColorModeValue<T>(light: T, dark: T) {
const { colorMode } = useColorMode()
return colorMode === "light" ? light : dark
}

// export function ColorModeIcon() {
// const { colorMode } = useColorMode()
// return colorMode === "light" ? <LuSun /> : <LuMoon />
// }

interface ColorModeButtonProps extends Omit<IconButtonProps, "aria-label"> {}

// export const ColorModeButton = forwardRef<
// HTMLButtonElement,
// ColorModeButtonProps
// >(function ColorModeButton(props, ref) {
// const { toggleColorMode } = useColorMode()
// return (
// <ClientOnly fallback={<Skeleton boxSize="8" />}>
// <IconButton
// onClick={toggleColorMode}
// variant="ghost"
// aria-label="Toggle color mode"
// size="sm"
// ref={ref}
// {...props}
// css={{
// _icon: {
// width: "5",
// height: "5",
// },
// }}
// >
// <ColorModeIcon />
// </IconButton>
// </ClientOnly>
// )
// })
62 changes: 62 additions & 0 deletions example/snippets/dialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import React from "react"
import { Dialog as ChakraDialog, Portal } from "@chakra-ui/react"
import { forwardRef } from "react"
import { CloseButton } from "../../src/components/snippets/close-button"

interface DialogContentProps extends ChakraDialog.ContentProps {
portalled?: boolean
portalRef?: React.RefObject<HTMLElement>
backdrop?: boolean
}

export const DialogContent = forwardRef<HTMLDivElement, DialogContentProps>(
function DialogContent(props, ref) {
const {
children,
portalled = true,
portalRef,
backdrop = true,
...rest
} = props

return (
<Portal disabled={!portalled} container={portalRef}>
{backdrop && <ChakraDialog.Backdrop />}
<ChakraDialog.Positioner>
<ChakraDialog.Content ref={ref} {...rest} asChild={false}>
{children}
</ChakraDialog.Content>
</ChakraDialog.Positioner>
</Portal>
)
},
)

export const DialogCloseTrigger = forwardRef<
HTMLButtonElement,
ChakraDialog.CloseTriggerProps
>(function DialogCloseTrigger(props, ref) {
return (
<ChakraDialog.CloseTrigger
position="absolute"
top="2"
insetEnd="2"
{...props}
asChild
>
<CloseButton size="sm" ref={ref}>
{props.children}
</CloseButton>
</ChakraDialog.CloseTrigger>
)
})

export const DialogRoot = ChakraDialog.Root
export const DialogFooter = ChakraDialog.Footer
export const DialogHeader = ChakraDialog.Header
export const DialogBody = ChakraDialog.Body
export const DialogBackdrop = ChakraDialog.Backdrop
export const DialogTitle = ChakraDialog.Title
export const DialogDescription = ChakraDialog.Description
export const DialogTrigger = ChakraDialog.Trigger
export const DialogActionTrigger = ChakraDialog.ActionTrigger
12 changes: 12 additions & 0 deletions example/snippets/provider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"use client"

import { ChakraProvider, defaultSystem } from "@chakra-ui/react"
import { ColorModeProvider } from "./color-mode"

export function Provider(props: React.PropsWithChildren) {
return (
<ChakraProvider value={defaultSystem}>
<ColorModeProvider>{props.children}</ColorModeProvider>
</ChakraProvider>
)
}
Loading