Use with AdonisJS - Flowbite React
Learn how to install Flowbite React for your AdonisJS project and start developing modern full-stack web applications
#
Using the CLIRun the following command to scaffold a new Flowbite React
project using AdonisJS
:
# npm
npm create flowbite-react@latest -- --template adonisjs
# yarn
yarn create flowbite-react --template adonisjs
# pnpm
pnpm create flowbite-react@latest --template adonisjs
# bun
bun create flowbite-react@latest --template adonisjs
Manual Installation
#
Create projectRun the following command to create a new AdonisJS project using the CLI:
npm init adonisjs@latest -- -K=inertia --adapter=react --ssr --install
#
Setup Tailwind CSS- Install
tailwindcss
and its peer dependencies:
npm i -D tailwindcss postcss autoprefixer
- Generate
tailwind.config.js
andpostcss.config.js
files:
npx tailwindcss init -p
- Add the paths to all of your template files in your
tailwind.config.js
file:
/** @type {import('tailwindcss').Config} */
export default {
content: ["./inertia/**/*.{js,ts,jsx,tsx}", "./resources/**/*.{edge,js,ts,jsx,tsx}"],
theme: {
extend: {},
},
plugins: [],
};
- Add the
@tailwind
directives for each of Tailwind's layers to your./inertia/css/app.css
file:
@tailwind base;
@tailwind components;
@tailwind utilities;
#
Install Flowbite React- Run the following command to install
flowbite-react
:
npm i flowbite-react
- Add the Flowbite React
content
path andplugin
totailwind.config.js
:
import flowbite from "flowbite-react/tailwind";
/** @type {import('tailwindcss').Config} */
export default {
content: [
// ...
flowbite.content(),
],
plugins: [
// ...
flowbite.plugin(),
],
};
#
Dark modeIn server side rendered applications, such as AdonisJS, to avoid page flicker (if dark
mode is set) before AdonisJS hydrates the content, ThemeModeScript
component must be rendered (see implementation below).
ThemeModeScript
renders a script tag that sets dark
or removes dark
from <html>
element before hydration occurs.
#
Configure- Import and render
ThemeModeScript
in the return body ofsetup
function:
// inertia/app/ssr.tsx
import { createInertiaApp } from "@inertiajs/react";
import { ThemeModeScript } from "flowbite-react";
import ReactDOMServer from "react-dom/server";
export default function render(page: any) {
return createInertiaApp({
page,
render: ReactDOMServer.renderToString,
resolve: (name) => {
const pages = import.meta.glob("../pages/**/*.tsx", { eager: true });
return pages[`../pages/${name}.tsx`];
},
setup: ({ App, props }) => (
<>
<ThemeModeScript />
<App {...props} />
</>
),
});
}
#
Try it outNow that you have successfully installed Flowbite React you can start using the components from the library.
// inertia/pages/home.tsx
import { Button } from "flowbite-react";
export default function Home() {
return <Button>Click me</Button>;
}