lukeboy_2002's avatar

dark mode for filepond

Hi,

Is there a way to add dark: to filepond?

in my tailwind.config I added darkMode: 'class',

in my blade file I have:

@push('styles')
<link href="https://unpkg.com/filepond@^4/dist/filepond.css" rel="stylesheet" />
<link href="{{ asset('css/filepond.css') }}" rel="stylesheet" />
<link href="https://unpkg.com/filepond-plugin-image-preview/dist/filepond-plugin-image-preview.css" rel="stylesheet" />
@endpush

<x-forms.label for="title" value="Title" />
<x-forms.input type="text" name="title" id="title" :value="old('title')" required autofocus />
<x-forms.input-error for="name" class="mt-2" />

@push('scripts')
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/select2.min.js"></script>
<script src="https://unpkg.com/filepond-plugin-file-validate-type/dist/filepond-plugin-file-validate-type.js"></script>
<script src="https://unpkg.com/filepond-plugin-image-preview/dist/filepond-plugin-image-preview.js"></script>
<script src="https://unpkg.com/filepond-plugin-file-validate-size/dist/filepond-plugin-file-validate-size.js"></script>
<script src="https://unpkg.com/filepond@^4/dist/filepond.js"></script>
        <script>
            FilePond.registerPlugin(FilePondPluginImagePreview);
            FilePond.registerPlugin(FilePondPluginFileValidateType);
            FilePond.registerPlugin(FilePondPluginFileValidateSize);


            // Get a reference to the file input element
            const inputElement = document.querySelector('#image');

            // Create a FilePond instance
            const pond = FilePond.create(inputElement, {
                acceptedFileTypes: ['image/*'],
                server: {
                    process: '{{ route('admin.filepond.upload') }}',
                    revert: '{{ route('admin.filepond.revert') }}',
                    headers: {
                        'X-CSRF-TOKEN': '{{ csrf_token() }}'
                    }
                }
            });
        </script>
    @endpush

I have this css file:

/* use a hand cursor intead of arrow for the action buttons */
.filepond--file-action-button {
    cursor: pointer;
}

/* the text color of the drop label*/
.filepond--drop-label {
    color: #555;
}

/* underline color for "Browse" button */
.filepond--label-action {
    text-decoration-color: #aaa;
}

/* the background color of the filepond drop area */
.filepond--panel-root {
    background-color: #eee;
}

/* the border radius of the drop area */
.filepond--panel-root {
    border-radius: 0.5em;
}

/* the border radius of the file item */
.filepond--item-panel {
    border-radius: 0.5em;
}

/* the background color of the file and file panel (used when dropping an image) */
.filepond--item-panel {
    background-color: #555;
}

/* the background color of the drop circle */
.filepond--drip-blob {
    background-color: #000;
}

/* the background color of the black action buttons */
.filepond--file-action-button {
    background-color: rgba(0, 0, 0, 0.5);
}

/* the icon color of the black action buttons */
.filepond--file-action-button {
    color: white;
}

/* the color of the focus ring */
.filepond--file-action-button:hover,
.filepond--file-action-button:focus {
    box-shadow: 0 0 0 0.125em rgba(255, 255, 255, 0.9);
}

/* the text color of the file status and info labels */
.filepond--file {
    color: white;
}

/* error state color */
[data-filepond-item-state*='error'] .filepond--item-panel,
[data-filepond-item-state*='invalid'] .filepond--item-panel {
    background-color: red;
}

[data-filepond-item-state='processing-complete'] .filepond--item-panel {
    background-color: green;
}

/* bordered drop area */
.filepond--panel-root {
    background-color: transparent;
    border: 1px solid rgb(107 114 128);
}

and I have a switcher.js

//DARKMODE
//icons
const sunIcon = document.querySelector(".sun");
const moonIcon = document.querySelector(".moon");

//theme Vars
const userTheme = localStorage.getItem("theme");
const systemTheme = window.matchMedia("(prefers-color-scheme:dark)").matches;

//icons toggling
const iconToggle = () => {
    moonIcon.classList.toggle("display-none");
    sunIcon.classList.toggle("display-none");
};

//initial theme check
const themeCheck = () => {
    if (userTheme === "dark" || (!userTheme && systemTheme)) {
        document.documentElement.classList.add("dark");
        moonIcon.classList.add("display-none");
        return;
    }
    sunIcon.classList.add("display-none");
};

//manual theme switch
const themeSwitch = () => {
    if (document.documentElement.classList.contains("dark")) {
        document.documentElement.classList.remove("dark");
        localStorage.setItem("theme", "light");
        iconToggle();
        return;
    }
    document.documentElement.classList.add("dark");
    localStorage.setItem("theme", "dark");
    iconToggle();
};

//call theme switch on clicking buttons
sunIcon.addEventListener("click", () => {
    themeSwitch();
});

moonIcon.addEventListener("click", () => {
    themeSwitch();
});

//invoke theme check on initial load
themeCheck();

I tried a lot of given solutions on the internet but nothing works.

Can someone help me

0 likes
1 reply
LaryAI's avatar
LaryAI
AI
Best Answer
Level 58

To implement a dark mode for FilePond when using Tailwind CSS with the darkMode: 'class' configuration, you can define dark mode styles within your custom CSS file. You'll need to prefix your dark mode styles with .dark to ensure they are applied when the dark class is added to your document's html or body element.

Here's how you can modify your existing CSS to support dark mode for FilePond:

/* Default light theme styles */
.filepond--panel-root {
    background-color: #eee;
    /* ... other styles ... */
}

/* ... other default light theme styles ... */

/* Dark theme styles */
.dark .filepond--panel-root {
    background-color: #333; /* Dark background for the panel */
    /* ... other dark styles ... */
}

.dark .filepond--drop-label {
    color: #ddd; /* Lighter text color for dark mode */
}

.dark .filepond--label-action {
    text-decoration-color: #ccc; /* Lighter underline color for "Browse" button */
}

.dark .filepond--item-panel {
    background-color: #444; /* Dark background for file items */
}

.dark .filepond--drip-blob {
    background-color: #555; /* Dark background for the drop circle */
}

.dark .filepond--file-action-button {
    background-color: rgba(255, 255, 255, 0.5); /* Lighter background for action buttons */
    color: black; /* Dark text/icon color for action buttons */
}

/* ... other dark theme styles ... */

/* You can also customize the colors for error and success states in dark mode */
.dark [data-filepond-item-state*='error'] .filepond--item-panel {
    background-color: #ff5555; /* Darker red for errors */
}

.dark [data-filepond-item-state='processing-complete'] .filepond--item-panel {
    background-color: #55ff55; /* Darker green for success */
}

Make sure that your switcher.js script correctly toggles the dark class on the html or body element when the theme is switched. The CSS styles prefixed with .dark will then be applied automatically.

Additionally, ensure that your @push('styles') section in the Blade file includes the custom CSS file that contains these dark mode styles. If you have separate CSS files for light and dark themes, you may need to dynamically load the appropriate file based on the current theme.

Lastly, verify that the FilePond instance is initialized after the theme has been determined and applied, so that FilePond can pick up the correct initial styles. If necessary, you can refresh FilePond's styles after a theme change by calling pond.redraw() or reinitializing the FilePond instance.

Please or to participate in this conversation.