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

feat: client only component #2

Merged
merged 1 commit into from
May 17, 2024
Merged
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
28 changes: 28 additions & 0 deletions app/utils/misc.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useFormAction, useNavigation } from '@remix-run/react'
import { useHydrated } from 'remix-utils/use-hydrated'

Check warning on line 2 in app/utils/misc.tsx

View workflow job for this annotation

GitHub Actions / ⬣ ESLint

`remix-utils/use-hydrated` import should occur after import of `react`

Check warning on line 2 in app/utils/misc.tsx

View workflow job for this annotation

GitHub Actions / ⬣ ESLint

`remix-utils/use-hydrated` import should occur after import of `react`
import { clsx, type ClassValue } from 'clsx'
import { useEffect, useMemo, useRef, useState } from 'react'
import { useSpinDelay } from 'spin-delay'
Expand All @@ -13,6 +14,33 @@
return `/resources/note-images/${imageId}`
}

// credit: https://www.jacobparis.com/content/remix-progressive-client-only
export function ProgressiveClientOnly({
children,
className = '',
defaultShow = false,
}: {
children: React.ReactNode | (() => React.ReactNode)
className?: string
defaultShow?: boolean
}) {
const isHydrated = useHydrated()
return (
<div
className={
isHydrated
? className
: defaultShow
? // Create these animations in CSS or your tailwind config
'[animation:disappear_1000ms]'
: '[animation:appear_1000ms]'
}
>
{typeof children === 'function' ? children() : children}
</div>
)
}

export function getErrorMessage(error: unknown) {
if (typeof error === 'string') return error
if (
Expand Down
24 changes: 24 additions & 0 deletions tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,30 @@ export const marketingPreset = {
'slide-left': 'slide-left 0.3s ease-out',
'slide-top': 'slide-top 0.3s ease-out',
},
appear: {
"0%, 99%": {
height: "0",
width: "0",
opacity: "0",
},
"100%": {
height: "auto",
width: "auto",
opacity: "1",
},
},
disappear: {
"0%, 99%": {
height: "auto",
width: "auto",
opacity: "1",
},
"100%": {
height: "0",
width: "0",
opacity: "0",
},
},
},
},
} satisfies Omit<Config, 'content'>
Expand Down
Loading