Replies: 1 comment
|
In the current code, Keep the presence instances stable and let <ClientOnly fallback={<Skeleton boxSize="10" />}>
<IconButton
position="relative"
onClick={toggleColorMode}
aria-label="Toggle color mode"
ref={ref}
{...props}
>
<Presence
as="span"
present={colorMode === "light"}
lazyMount
unmountOnExit
skipAnimationOnMount
position="absolute"
inset="0"
display="inline-flex"
alignItems="center"
justifyContent="center"
animationName={{
_open: "slide-from-top, fade-in",
_closed: "slide-to-bottom, fade-out",
}}
animationDuration="200ms"
>
<LuSun />
</Presence>
<Presence
as="span"
present={colorMode === "dark"}
lazyMount
unmountOnExit
skipAnimationOnMount
position="absolute"
inset="0"
display="inline-flex"
alignItems="center"
justifyContent="center"
animationName={{
_open: "slide-from-top, fade-in",
_closed: "slide-to-bottom, fade-out",
}}
animationDuration="200ms"
>
<LuMoon />
</Presence>
</IconButton>
</ClientOnly>
The important part is removing References: Chakra Presence contract and Ark UI's official |
Uh oh!
There was an error while loading. Please reload this page.
Here is the particular snippet that I am trying to rewrite in Chakra v3 from Chakra v2, and without Framer Motion:
https://github.com/craftzdog/craftzdog-homepage/blob/ada0276d9ff6242597521a8c96a77c7058c74e4f/components/theme-toggle-button.js#L9-L25
I've repurposed the generated code in
components/ui/color-mode.tsx(generated bynpx chakra snippetCLI), trying to usePresencecomponent from Chakra:The problem is that, since
IconButtonis wrapped insideClientOnly, it loads theSkeletoncomponent, then unmount and mounts theIconButtoncomponent, causing the animation to trigger. I want it such that the animation only trigger when I'm clicking the button. Is it possible to achieve what I am trying to go for?Alternatively, can we make use of data-* attribute here? I feel like using a state for this simple toggle might probably not be a good idea. Maybe there's a way to have a ref pointing to ClientOnly that I can use to tell when the IconButton element was mounted?
All reactions