Installation
Setting up Preline UI in a Adonis project using Tailwind CSS.
Please note that the plugin has been tested with the 6.17.2
version of the framework. The framework was installed using the standard npm init adonisjs@latest <project-name>
command. This setup used Inertia
and Vue 3
for the frontend.
If you are using your own project structure or a different version, pay attention to the file paths and features of your version!
The Progressive JavaScript Framework. If you haven't set up Tailwind CSS yet, check out Adonis Tailwind CSS installation guides.
Some components require third-party libraries. The settings below assume full use of Preline UI
, including preloaded dependencies. If you do not intend to use those components that rely on third-party libraries, you may exclude them from your configuration.
Install Preline
using your preferred package manager.
npm install preline
Please note, Preline UI uses Tailwind CSS Forms plugin in all form components. Don't forget to install it, if you haven't done so already: npm install -D @tailwindcss/forms
Include Preline in your projects_root_directory/inertia/css/app.css
file.
@import "tailwindcss";
@import "preline/variants.css";
@source "../../node_modules/preline/dist/*.js";
/* Optional Preline UI Datepicker Plugin */
/* @import "preline/src/plugins/datepicker/styles.css"; */
/* Third-party plugins */
/* @plugin "@tailwindcss/forms"; */
Create the global.d.ts
file in the project root directory, e.g.
projects_root_directory/inertia/types/global.d.ts
import { JQueryStatic } from 'jquery'
import type { DataTable } from 'datatables.net'
import type { Dropzone } from 'dropzone'
import noUiSlider from 'nouislider'
import * as VanillaCalendarPro from 'vanilla-calendar-pro'
import type { IStaticMethods } from 'preline/dist'
declare global {
interface Window {
// Optional third-party libraries
_: typeof import('lodash')
$: JQueryStatic
jQuery: JQueryStatic
DataTable: typeof DataTable
Dropzone: typeof Dropzone
noUiSlider: typeof noUiSlider
VanillaCalendarPro: typeof VanillaCalendarPro
// Preline UI
HSStaticMethods: IStaticMethods
}
}
export {}
Add code that reinitializes the components every time the page is refreshed to projects_root_directory/inertia/plugins/preline.ts
import type { App } from 'vue'
export default {
install: (app: App) => {
app.mixin({
async mounted() {
await import('preline/dist')
window.HSStaticMethods.autoInit()
}
})
}
}
Add the Preline UI JavaScript in your app entry point projects_root_directory/inertia/app/app.ts
...
import $ from 'jquery'
import _ from 'lodash'
import noUiSlider from 'nouislider'
import 'datatables.net'
import 'dropzone/dist/dropzone-min.js'
import * as VanillaCalendarPro from 'vanilla-calendar-pro'
window._ = _
window.$ = $
window.jQuery = $
window.DataTable = $.fn.dataTable
window.noUiSlider = noUiSlider
window.VanillaCalendarPro = VanillaCalendarPro
window.Dropzone = window.Dropzone || {}
import PrelinePlugin from '../plugins/preline'
...
createInertiaApp({
....
setup({ el, App, props, plugin }) {
createSSRApp({ render: () => h(App, props) })
.use(plugin)
.use(PrelinePlugin)
.mount(el)
}
})
Please note, Preline UI comes with some opinionated styles that are applied to components by default. If you want these styles in your project, you may include them into your CSS file. These styles used to come by default in Tailwind v3, so we decided to keep them in Preline UI.
/* Adds pointer cursor to buttons */
@layer base {
button:not(:disabled),
[role="button"]:not(:disabled) {
cursor: pointer;
}
}
/* Defaults hover styles on all devices */
@custom-variant hover (&:hover);