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

Unable to use Preline Examples in Remix App #319

Open
dhavalveera opened this issue Mar 28, 2024 · 2 comments
Open

Unable to use Preline Examples in Remix App #319

dhavalveera opened this issue Mar 28, 2024 · 2 comments
Labels
help wanted Extra attention is needed

Comments

@dhavalveera
Copy link

Hello,

I wanted to use Features Nav in my Remix App, and for that I tried to follow this Installation Steps but unfortunately I was failed to use it.

I am able to render the UI exactly as it's Tailwind CSS, but the functionality, I am not able to make it, can anyone help me where I am doing the mistake?

@jahaganiev jahaganiev added the help wanted Extra attention is needed label Mar 28, 2024
@AlexBSoft
Copy link

AlexBSoft commented Mar 29, 2024

I was facing the same problem. Current installation steps are invalid for Remix 2.8.1.

I managed to fix the problem:

  1. Install preline npm install preline

  2. Add the path to Preline UI JavaScript files in your tailwind.config.js file.

// tailwind.config.js
module.exports = {
  content: [
      './node_modules/preline/preline.js',
  ],
  plugins: [
      require('preline/plugin'),
  ],
}
  1. Create preline.client.tsx file for example in ~/components folder. (We will use client module):
import {
    useLocation,
} from "@remix-run/react";
import { useEffect } from "react";

import { IStaticMethods } from "preline/preline";
declare global {
    interface Window {
        HSStaticMethods: IStaticMethods;
    }
}

export default function PrelineScript() {
    const location = useLocation();

    useEffect(() => {
        import("preline/preline");
    }, []);

    useEffect(() => {
        setTimeout(() => {
            window.HSStaticMethods.autoInit();
        }, 100);
    }, [location.pathname]);

    return null;
}
  1. Connect this file in root.tsx:
...
// Import at top of file
import PrelineScript from "~/components/preline.client";

export function Layout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <head>
        <meta charSet="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <Meta />
        <Links />
      </head>
      <body>
        {children}
        <ScrollRestoration />
        <Scripts />
        {/* Add preline script on every page */}
        {PrelineScript && <PrelineScript />}
      </body>
    </html>
  );
}

...

@bluefire2121
Copy link

`declare global {
interface Window {
HSStaticMethods: IStaticMethods;
}
}
if (typeof window !== "undefined") {
await import('preline/preline');
}

export function Layout({ children }: { children: ReactNode }) {
const location = useLocation();

useEffect(() => {
window.HSStaticMethods.autoInit();
}, [location.pathname]);

return ( ... )
`

Replace typeof window !== "undefined" with typeof document !== "undefined" to handle runtimes outside of Node like Deno. Read the Remix Gotchas for more info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants