Installation
Setting up Preline UI in a Ruby on Rails project using Tailwind CSS and Importmap.
A web application framework written in Ruby. If you haven't set up Tailwind CSS yet, check out Rails Tailwind CSS installation guides.
Install preline via npm or yarn.
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
Update tailwind.config.js files with Preline UI configuration.
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
'./app/helpers/**/*.rb',
'./app/javascript/**/*.js',
'./app/views/**/*',
'./app/views/**/*.erb',
'./app/views/**/*.html',
'./node_modules/preline/**/*.js'
],
theme: {
extend: {},
},
plugins: [
require('preline/plugin'),
],
}
Update your CSS and JavaScript files to include Preline UI with Turbo integration.
@import 'tailwindcss';
@import 'preline/variants.css';
/* Preline Themes */
@import "./themes/theme.css";
Check out the Theme docs to learn more about Preline Themes.
// ... other imports
import "preline"
// Initialize Preline components after Turbo page loads
document.addEventListener('turbo:load', () => {
if (window.HSStaticMethods) {
window.HSStaticMethods.autoInit();
}
});
Configure Rails Importmap to serve Preline JavaScript and copy the file to the vendor directory.
pin "preline", to: "preline.js", preload: true
mkdir -p vendor/javascript
cp node_modules/preline/dist/preline.js vendor/javascript/
Please note, Rails Importmap cannot serve files directly from node_modules/ directory due to security and architectural constraints. Copying to vendor/javascript/ ensures proper integration with Rails' asset pipeline.
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);