Skip to content

Commit 09214a7

Browse files
authored
Merge pull request #2 from lsbyerley/dev
feat: client only component
2 parents fbe5ea2 + 31355f7 commit 09214a7

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

app/utils/misc.tsx

+28
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useFormAction, useNavigation } from '@remix-run/react'
2+
import { useHydrated } from 'remix-utils/use-hydrated'
23
import { clsx, type ClassValue } from 'clsx'
34
import { useEffect, useMemo, useRef, useState } from 'react'
45
import { useSpinDelay } from 'spin-delay'
@@ -13,6 +14,33 @@ export function getNoteImgSrc(imageId: string) {
1314
return `/resources/note-images/${imageId}`
1415
}
1516

17+
// credit: https://www.jacobparis.com/content/remix-progressive-client-only
18+
export function ProgressiveClientOnly({
19+
children,
20+
className = '',
21+
defaultShow = false,
22+
}: {
23+
children: React.ReactNode | (() => React.ReactNode)
24+
className?: string
25+
defaultShow?: boolean
26+
}) {
27+
const isHydrated = useHydrated()
28+
return (
29+
<div
30+
className={
31+
isHydrated
32+
? className
33+
: defaultShow
34+
? // Create these animations in CSS or your tailwind config
35+
'[animation:disappear_1000ms]'
36+
: '[animation:appear_1000ms]'
37+
}
38+
>
39+
{typeof children === 'function' ? children() : children}
40+
</div>
41+
)
42+
}
43+
1644
export function getErrorMessage(error: unknown) {
1745
if (typeof error === 'string') return error
1846
if (

tailwind.config.ts

+24
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,30 @@ export const marketingPreset = {
2525
'slide-left': 'slide-left 0.3s ease-out',
2626
'slide-top': 'slide-top 0.3s ease-out',
2727
},
28+
appear: {
29+
"0%, 99%": {
30+
height: "0",
31+
width: "0",
32+
opacity: "0",
33+
},
34+
"100%": {
35+
height: "auto",
36+
width: "auto",
37+
opacity: "1",
38+
},
39+
},
40+
disappear: {
41+
"0%, 99%": {
42+
height: "auto",
43+
width: "auto",
44+
opacity: "1",
45+
},
46+
"100%": {
47+
height: "0",
48+
width: "0",
49+
opacity: "0",
50+
},
51+
},
2852
},
2953
},
3054
} satisfies Omit<Config, 'content'>

0 commit comments

Comments
 (0)