Skip to content

Conversation

@AllanOcelot
Copy link
Contributor

@AllanOcelot AllanOcelot commented Nov 15, 2024

Please note, I am NOT a react developer, if you can improve this PR, please do so. I am happy to implement feedback!

I have provided a "dark mode" for swagger. Previously users have relied on third party provided stylesheets, or third party styling tools to achieve this. I believe it's a simple improvement that many users will actually find useful.

Description

  • Added two SVG icons, provided via MDI open source icons.
  • Created a new component "DarkMode", this is imported into "TopBar", when clicked, it toggle's the class "dark" onto the HTML root element ( this is due to the HTML being styled with a white background, and needing to overwrite this default style )
  • Created a new SCSS file "DarkTheme" this is imported in main.scss, yet lives outside the main import, to allow us to target the root HTML element.

Motivation and Context

  • Darkmode has been requested numerous times in issues, it's also something I'd personally like to see
  • I wanted to contribute something back to swagger, since it's a tool I use often
  • It was easy to implement, and I do not believe it causes issues with any existing feature
  • It removes the need for users to fork/edit/ rely on third party tools to have dark mode

How Has This Been Tested?

  • I have visually tested this myself
  • I have run EXISTING tests and they pass

Screenshots (if appropriate):

image
( Screenshot shows the addition of the dark mode icon, in the Topbar )

image
( Screenshot showing darkmode theme active )

image

image

image

image

image

Checklist

My PR contains...

  • No code changes (src/ is unmodified: changes to documentation, CI, metadata, etc.)
  • Dependency changes (any modification to dependencies in package.json)
  • Bug fixes (non-breaking change which fixes an issue)
  • Improvements (misc. changes to existing features)
  • Features (non-breaking change which adds functionality)

My changes...

  • are breaking changes to a public API (config options, System API, major UI change, etc).
  • are breaking changes to a private API (Redux, component props, utility functions, etc.).
  • are breaking changes to a developer API (npm script behavior changes, new dev system dependencies, etc).
  • are not breaking changes.

Documentation

  • My changes do not require a change to the project documentation.
  • My changes require a change to the project documentation.
  • If yes to above: I have updated the documentation accordingly.

Automated tests

  • My changes can not or do not need to be tested.
  • My changes can and should be tested by unit and/or integration tests.
  • If yes to above: I have added tests to cover my changes.
  • If yes to above: I have taken care to cover edge cases in my tests.
  • All new and existing tests passed.

@AllanOcelot AllanOcelot changed the title Ft darkmode Feature - New - Dark Mode Toggle Nov 15, 2024
@AllanOcelot
Copy link
Contributor Author

@Praskand
Copy link

Praskand commented Nov 24, 2024

How did you do it?

@AllanOcelot
Copy link
Contributor Author

How did you do it?

From memory :

It's a new component added to the top bar, when clicked, adds a new class "theme-dark" to the page. We have a new style sheet that styles all descendants of "dark-theme" appropriately.

@pgridharan
Copy link

Hey,

this is something I would love to see merged. One suggestion from my side would be to include support for prefers-color-scheme.

@AllanOcelot
Copy link
Contributor Author

@pgridharan I'd happily implement that, but I've heard no feedback from maintainers, so assumed PR was dead in the water :)

Great suggestion , thanks

@AllanOcelot
Copy link
Contributor Author

Great suggestion @ebrannin-bw - but I doubt this work will ever see the light of day sadly !

wmfgerrit pushed a commit to wikimedia/mediawiki that referenced this pull request Mar 10, 2025
Swagger UI does not directly support dark mode. See:
- swagger-api/swagger-ui#5327
- swagger-api/swagger-ui#10216
Adding skin-invert fixes the appearance, and is straightforward
to remove if direct support meeting our needs is ever added.

Bug: T383483
Change-Id: I30c5030522e376c7114b000b2158637c3829c425
@mateusememe
Copy link

mateusememe commented Mar 23, 2025

This is an amazing feature @AllanOcelot, congrats, please @ebrannin-bw approve this, my eyes thank you 🙏🏻

@taquinoc
Copy link

Nice PR, it was about time for swagger to have a dark mode!!

@williamwinkler
Copy link

Great job @AllanOcelot, I hope this well get merged at some point!

@joesdu
Copy link

joesdu commented Oct 24, 2025

+1

1 similar comment
@XhstormR
Copy link

XhstormR commented Dec 2, 2025

+1

@glowcloud glowcloud mentioned this pull request Dec 9, 2025
@glowcloud
Copy link
Contributor

Hi @AllanOcelot and everyone,

Thank you all for your interest in this! I’ve created a superseding PR with an updated colour palette and handling of additional elements, with full credit to @AllanOcelot for the initial work. As such, I will be closing this PR. Please see #10653 for further progress.

@glowcloud glowcloud closed this Dec 9, 2025
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.

10 participants