diff --git a/.changeset/fresh-flies-wash.md b/.changeset/fresh-flies-wash.md new file mode 100644 index 000000000..1fa3339d3 --- /dev/null +++ b/.changeset/fresh-flies-wash.md @@ -0,0 +1,5 @@ +--- +"@suspensive/react-dom": minor +--- + +feat(react-dom): add `` diff --git a/examples/visualization/src/app/layout.tsx b/examples/visualization/src/app/layout.tsx index 649e13e50..4d891f734 100644 --- a/examples/visualization/src/app/layout.tsx +++ b/examples/visualization/src/app/layout.tsx @@ -51,6 +51,9 @@ export default function RootLayout({ children }: { children: React.ReactNode })
  • {``}
  • +
  • + {``} +
  • diff --git a/examples/visualization/src/app/react-dom/FadeIn/page.tsx b/examples/visualization/src/app/react-dom/FadeIn/page.tsx new file mode 100644 index 000000000..8ddcf1439 --- /dev/null +++ b/examples/visualization/src/app/react-dom/FadeIn/page.tsx @@ -0,0 +1,68 @@ +'use client' + +import { ErrorBoundary, Suspense } from '@suspensive/react' +import { FadeIn } from '@suspensive/react-dom' +import { SuspenseQuery, queryOptions } from '@suspensive/react-query' +import axios from 'axios' +import { delay } from '~/utils' + +const query = { + user: (userId: number) => + queryOptions({ + queryKey: ['users', userId], + queryFn: () => + delay(3000).then(() => + axios + .get<{ + id: number + username: string + maidenName: string + age: number + gender: string + email: string + image: 'https://dummyjson.com/icon/emilys/128' + userAgent: string + }>(`https://dummyjson.com/users/${userId}`) + .then(({ data }) => data) + ), + }), +} + +export default function Page() { + const userId = 1 + + return ( + <>{error.message}}> + + {skeleton} + + } + > + + {({ data: user }) => ( + +

    {user.username}

    +

    {user.userAgent}

    +

    {user.age}

    +

    {user.maidenName}

    +
    + )} +
    +
    +
    + ) +} + +const skeleton = ( +
    +
    +
    +
    +
    +
    +
    +
    +) diff --git a/examples/visualization/src/app/react-dom/InView/page.tsx b/examples/visualization/src/app/react-dom/InView/page.tsx index 85ed5a92d..2667aecfc 100644 --- a/examples/visualization/src/app/react-dom/InView/page.tsx +++ b/examples/visualization/src/app/react-dom/InView/page.tsx @@ -6,7 +6,6 @@ export default function Page() { return (
    {Array.from({ length: 200 }).map((_, i) => ( - // eslint-disable-next-line @eslint-react/no-duplicate-key {({ inView, ref }) => (
    diff --git a/packages/react-dom/src/FadeIn.tsx b/packages/react-dom/src/FadeIn.tsx new file mode 100644 index 000000000..457de9855 --- /dev/null +++ b/packages/react-dom/src/FadeIn.tsx @@ -0,0 +1,34 @@ +import { type CSSProperties, type ComponentPropsWithoutRef, type ElementType } from 'react' +import { useInView } from './useInView' + +type FadInBaseProps = { + delay?: number + duration?: number + timingFunction?: CSSProperties['animationTimingFunction'] +} +type FadeInProps = { + as?: TAs +} & Omit, 'as' | keyof FadInBaseProps> & + FadInBaseProps + +export function FadeIn({ + as, + delay = 0, + duration = 200, + timingFunction = 'linear', + ...rest +}: FadeInProps) { + const Component = as || 'div' + const { inView, ref } = useInView() + return ( + + ) +} diff --git a/packages/react-dom/src/index.ts b/packages/react-dom/src/index.ts index 4ceebec90..0e0c494a3 100644 --- a/packages/react-dom/src/index.ts +++ b/packages/react-dom/src/index.ts @@ -1,2 +1,3 @@ export { InView } from './InView' export { useInView } from './useInView' +export { FadeIn } from './FadeIn'