-
-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: migrate to chakra-ui v3 (#151)
- Loading branch information
1 parent
aa054ec
commit 1a73290
Showing
27 changed files
with
2,688 additions
and
1,857 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { Home } from '~/lib/pages/home'; | ||
import { Home } from '@/lib/pages/home'; | ||
|
||
export default Home; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import type { ButtonProps as ChakraButtonProps } from '@chakra-ui/react'; | ||
import { | ||
AbsoluteCenter, | ||
Button as ChakraButton, | ||
Span, | ||
Spinner, | ||
} from '@chakra-ui/react'; | ||
import { forwardRef } from 'react'; | ||
|
||
interface ButtonLoadingProps { | ||
loading?: boolean; | ||
loadingText?: React.ReactNode; | ||
} | ||
|
||
export interface ButtonProps extends ChakraButtonProps, ButtonLoadingProps {} | ||
|
||
export const Button = forwardRef<HTMLButtonElement, ButtonProps>( | ||
function Button(props, ref) { | ||
const { loading, disabled, loadingText, children, ...rest } = props; | ||
return ( | ||
<ChakraButton disabled={loading || disabled} ref={ref} {...rest}> | ||
{loading && !loadingText ? ( | ||
<> | ||
<AbsoluteCenter display="inline-flex"> | ||
<Spinner size="inherit" color="inherit" /> | ||
</AbsoluteCenter> | ||
<Span opacity={0}>{children}</Span> | ||
</> | ||
) : loading && loadingText ? ( | ||
<> | ||
<Spinner size="inherit" color="inherit" /> | ||
{loadingText} | ||
</> | ||
) : ( | ||
children | ||
)} | ||
</ChakraButton> | ||
); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
'use client'; | ||
|
||
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 />; | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-object-type | ||
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> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use client'; | ||
|
||
import { ChakraProvider } from '@chakra-ui/react'; | ||
|
||
import customTheme from '@/lib/styles/theme'; | ||
|
||
import { ColorModeProvider } from './color-mode'; | ||
|
||
export function Provider(props: React.PropsWithChildren) { | ||
return ( | ||
<ChakraProvider value={customTheme}> | ||
<ColorModeProvider>{props.children}</ColorModeProvider> | ||
</ChakraProvider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Tooltip as ChakraTooltip, Portal } from '@chakra-ui/react'; | ||
import { forwardRef } from 'react'; | ||
|
||
export interface TooltipProps extends ChakraTooltip.RootProps { | ||
showArrow?: boolean; | ||
portalled?: boolean; | ||
portalRef?: React.RefObject<HTMLElement>; | ||
content: React.ReactNode; | ||
contentProps?: ChakraTooltip.ContentProps; | ||
disabled?: boolean; | ||
} | ||
|
||
export const Tooltip = forwardRef<HTMLDivElement, TooltipProps>( | ||
function Tooltip(props, ref) { | ||
const { | ||
showArrow, | ||
children, | ||
disabled, | ||
portalled, | ||
content, | ||
contentProps, | ||
portalRef, | ||
...rest | ||
} = props; | ||
|
||
if (disabled) return children; | ||
|
||
return ( | ||
<ChakraTooltip.Root {...rest}> | ||
<ChakraTooltip.Trigger asChild>{children}</ChakraTooltip.Trigger> | ||
<Portal disabled={!portalled} container={portalRef}> | ||
<ChakraTooltip.Positioner> | ||
<ChakraTooltip.Content ref={ref} {...contentProps}> | ||
{showArrow && ( | ||
<ChakraTooltip.Arrow> | ||
<ChakraTooltip.ArrowTip /> | ||
</ChakraTooltip.Arrow> | ||
)} | ||
{content} | ||
</ChakraTooltip.Content> | ||
</ChakraTooltip.Positioner> | ||
</Portal> | ||
</ChakraTooltip.Root> | ||
); | ||
} | ||
); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.