Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Form Components Laravel Package

rawilk/laravel-form-components

A set of reusable Blade form components for Laravel that make building consistent forms quick and clean. Includes inputs, selects, checkboxes, radios, buttons, errors, and styling-friendly markup, with flexible config and easy customization.

View on GitHub
Deep Wiki
Context7

title: Customizing CSS sort: 2

If you want to change the look of the form components to match the style of your own app, you have multiple options.

Option 1: Use Your Own Tailwind CSS Configuration

You can import the index.css and run every [@apply](https://github.com/apply) rule through your own tailwind.config.js.

/* app.css */

[@tailwind](https://github.com/tailwind) base;
[@tailwind](https://github.com/tailwind) components;
[@tailwind](https://github.com/tailwind) utilities;

[@import](https://github.com/import) "../../vendor/rawilk/laravel-form-components/resources/css/index.css";

/* override our styles here */

{note} If you choose this option, make sure you have the required variants included in your tailwind.config.js configuration.

You may also import only the stylesheets you need instead of everything in the index.css file. Most components have their own stylesheets (i.e. input.css for input elements).

Option 2: Copy the CSS To Your Own Project

If you want full-control, you can always copy each of the stylesheets from resources/css to your own project and go wild. In this example, we renamed the file to custom/laravel-form-components.css. Beware: you will have to manually keep this CSS in sync with changes in future package updates:

/* app.css */

... [@import](https://github.com/import) "custom/laravel-form-components.css";

Let's say you wanted to change the spacing in stacked checkbox groups. You could do so like this in the file you just created with the pasted in styles from the package:

/* custom/laravel-form-components.css */

.form-checkbox-group--stacked {
    [@apply](https://github.com/apply) space-y-2;

    /* styles from the package */
    /*[@apply](https://github.com/apply) space-y-4;*/
}

...

Tailwind Configuration

Some custom configuration is necessary to ensure our package's CSS compiles correctly, and that the components are styled correctly.

Required Variants

If you choose Option 1, you will need the following color variants added inside your tailwind.config.js file:

// tailwind.config.js

const colors = require("tailwindcss/colors");

module.exports = {
    // ...
    theme: {
        extend: {
            colors: {
                slate: colors.slate,
            },
        },
    },
};

This will extend the default tailwind color palette to include the slate color variant. There are a few other colors you'll want to make sure you have in your color palette, such as blue and red, so if you're using a custom color palette, make sure those colors are included in it. For a comprehensive overview of what colors and utility classes you'll need in your Tailwind configuration for the package's styles to compile, you can refer to the variables.css file.

Plugins

The [@tailwindcss](https://github.com/tailwindcss)/forms plugin is necessary to for some base styles to be applied to the form components. If you are using the switch-toggle component, you will want to include our custom switch-toggle plugin if you plan on rendering it with custom colors.

// tailwind.config.js

module.exports = {
    // ...
    plugins: [
        require("[@tailwindcss](https://github.com/tailwindcss)/forms"),

        // Only necessary if you're going to use the switch-toggle component with different colors
        require("./vendor/rawilk/laravel-form-components/resources/js/tailwind-plugins/switch-toggle"),

        // Only necessary if you're going to support dark mode
        require("./vendor/rawilk/laravel-form-components/resources/js/tailwind-plugins/dark-mode"),
    ],
};

Purge CSS/Tailwind JIT

Purge CSS is useful for trimming out unused styles from your stylesheets to reduce your overall build size. To ensure the class styles from this package don't get purged from your production build, you should add the following to your purge css content configuration:

{note} The following code snippet is for a TailwindCSS build configuration using a tailwind.config.js file in the build.

module.exports = {
    // ...
    content: [
        // Typical laravel app purge css content
        "./app/**/*.php",
        "./resources/**/*.php",
        "./resources/**/*.js",

        // Make sure you add these lines
        "./vendor/rawilk/laravel-form-components/src/**/*.php",
        "./vendor/rawilk/laravel-form-components/resources/**/*.php",
        "./vendor/rawilk/laravel-form-components/resources/js/*.js",
    ],
};

Due to the dynamic nature of how some classes are rendered onto the markup, you may still find some of them being purged by Tailwind. Here's a few you may want to add to your safelist to prevent from being purged:

module.exports = {
    // ...
    safelist: [
        {
            pattern: /file-upload__input--*/,
        },
        {
            pattern: /switch-toggle--*/,
        },
        {
            pattern: /custom-select__button--*/,
        },
        {
            // For sizing, e.g. form-input--sm
            pattern: /form-input--*/,
        },
        {
            // For checkbox/radio sizing
            pattern: /form-choice--*/,
        },

        // For dark mode...
        {
            // quill editor classes
            pattern: /ql--*/,
        },
        "filepond--panel-root",
        "filepond--root",
    ],
};

You can of course be more selective in what you safelist. For example, instead of using a pattern for the .form-input-- sizing classes, you could just explicitly add form-input--lg to the safelist array instead of using a regex pattern.

Variables

Some styling for components, such as text color and border colors, can be overridden with CSS variables. For example, if you wanted to override the border color for inputs, you could add the following to your app's CSS file:

... :root {
    --input-border-color: theme("colors.green.300");
    --input-dark-border-color: theme("colors.green.500");
}

{note} Make sure to override any variables after you've imported the package's CSS.

For a full reference of the variables you can set in your CSS, please refer to the variables.css file.

Dark Mode

The package's components have also been styled for dark mode and will work with both the class based and OS based strategies. A custom dark mode selector is also supported too.

To opt in to dark mode, you will need to add the dark-mode plugin to your Tailwind configuration file. See Plugins for more information. By default, all components are styled for dark mode in this plugin. You may opt out of certain components being styled here if you're not using them. Here is an example of all the options you can pass to the plugin:

// tailwind.config.js

module.exports = {
    plugins: [
        // ...
        require("./vendor/rawilk/laravel-form-components/resources/js/tailwind-plugins/dark-mode")(
            {
                quill: false,
                filepond: false,
            },
        ),
    ],
};

For more information, please refer to Tailwind's Dark Mode Documentation.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky