Skip to content

Add dark mode#780

Open
Alwinator wants to merge 1 commit into
jowilf:mainfrom
Alwinator:dark-mode
Open

Add dark mode#780
Alwinator wants to merge 1 commit into
jowilf:mainfrom
Alwinator:dark-mode

Conversation

@Alwinator

Copy link
Copy Markdown
Contributor

Related

Summary

This PR adds automatic dark mode support to the starlette-admin interface. The admin now follows the user's operating system / browser color-scheme preference and switches between light and dark themes accordingly — with no configuration required.

Tabler (the underlying UI framework) already ships a dark theme that is enabled via the data-bs-theme="dark" attribute on <body>. This PR wires that up automatically and patches the bundled third-party widgets that don't ship their own dark variants.

What's included

  • starlette_admin/statics/js/dark-mode.js — Detects the prefers-color-scheme: dark media query and toggles data-bs-theme="dark" on <body>. It applies the theme on page load and keeps it in sync if the user changes their system preference at runtime.
  • starlette_admin/statics/css/dark-mode.css — Dark-mode styling fixes for the bundled widgets that don't provide dark variants out of the box:
    • Select2 dropdowns, single/multiple selections and search fields
    • DataTables button collections and popovers
    • Flatpickr date/time picker (calendar, month/weekday headers, day cells, time inputs and navigation arrows)
  • starlette_admin/templates/base.html — Includes the new stylesheet and script in the base template.

Behavior

  • Automatic: follows the OS/browser theme preference; no toggle or setting needed.
  • Reactive: responds to live changes in the system color scheme.
  • Consistent: bundled widgets (Select2, DataTables, Flatpickr) are restyled to match the dark theme.
  • Non-breaking: light mode remains the default when the system preference is light; no public API changes.

Files changed

File Change
starlette_admin/statics/css/dark-mode.css New file (126 lines)
starlette_admin/statics/js/dark-mode.js New file (22 lines)
starlette_admin/templates/base.html +2 lines (include CSS & JS)

How to test

  1. Run any of the bundled examples (e.g. examples/sqla).
  2. Set your operating system or browser to dark appearance.
  3. Open the admin — the UI should render in dark mode.
  4. Toggle your system theme back to light and confirm the admin switches without a page reload.
  5. Verify the Select2 dropdowns, DataTables column-visibility buttons and Flatpickr date pickers are legible in dark mode.

@vahidzhe

Copy link
Copy Markdown

Could you please share screenshots of the UI after the recent changes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants