Installation
Setting up Preline UI in a Solid.js project using Tailwind CSS.
Please note that the plugin has been tested with the latest version of the framework (v1.8.5). The framework was installed using the standard npm create vite@latest <project-name> -- --template solid
command.
If you are using your own project structure or a different version, pay attention to the file paths and features of your version!
Simple and performant reactivity for building user interfaces. If you haven't set up Tailwind CSS yet, check out Solid.js Tailwind CSS installation guides.
Install preline
via npm or yarn.
// Terminal or Shellnpm install preline // or yarn add preline
Add the path to Preline UI JavaScript files in your tailwind.config.js
file.
// tailwind.config.jsmodule.exports = { content: [ './node_modules/preline/preline.js', ], plugins: [ require('preline/plugin'), ],}
Add the Preline UI JavaScript in your app entry point projects_root_directory/src/index.tsx
import { render } from "solid-js/web";
import { Router } from "@solidjs/router";
...
import "preline/preline";
import App from "./App";
const root = document.getElementById("root");
render(
() => (
<Router>
<App />
</Router>
),
root!
);
Add code that reinitializes the components every time when app is mounted or page was changed projects_root_directory/src/App.tsx
import { createSignal, createEffect } from "solid-js";
import { useLocation } from "@solidjs/router";
import { IStaticMethods } from "preline/preline";
declare global {
interface Window {
HSStaticMethods: IStaticMethods;
}
}
...
const App = () => {
const location = useLocation();
const [_, setLoc] = createSignal(location.pathname);
createEffect(() => {
setLoc(location.pathname);
window.HSStaticMethods.autoInit();
});
return (
...
);
};
export default App;