Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Dark mode #5327

Open
lonix1 opened this issue Apr 24, 2019 · 28 comments
Open

[Feature Request] Dark mode #5327

lonix1 opened this issue Apr 24, 2019 · 28 comments

Comments

@lonix1
Copy link

lonix1 commented Apr 24, 2019

Would be nice to have a dark mode version of the UI.

@mrahhal mrahhal mentioned this issue Apr 12, 2020
17 tasks
@luca0898
Copy link

I was going to open a issue right now on this subject hahaha

@silverwind
Copy link
Contributor

silverwind commented Dec 10, 2020

Poor man's dark mode:

@media (prefers-color-scheme: dark) {
  .swagger-ui {
      filter: invert(88%) hue-rotate(180deg);
  }
  .swagger-ui .microlight {
      filter: invert(100%) hue-rotate(180deg);
  }
}

Edit (2023): Updated to new code box class

@KaKi87
Copy link

KaKi87 commented Dec 10, 2020

Yes, but this is a feature request.

@clementCharasson
Copy link

For those who looking for dark mode in swagger, you can use custom CSS with a stylus plugin.
https://33kk.github.io/uso-archive/?search=swagger

@KaKi87
Copy link

KaKi87 commented Feb 8, 2021

There's also Dark Reader, but this shouldn't prevent Swagger from having a native dark theme ^^

@jeffersoneagley
Copy link

Yea in my case I could build out an alternative, but swagger-ui-react sets sooooooo many default colors, I'm sure it will be brittle.

@lonix1
Copy link
Author

lonix1 commented Feb 17, 2021

Agreed, it must be built-in.

But to get this going, maybe someone has dark mode styles to contribute? I see other apps simply use one of the popular themes floating around: "dracula", "nord dark", etc.

I assume if we make it easy for the devs to adopt, then we'll get this feature.

@daniloab
Copy link

daniloab commented Mar 1, 2021

Now that have the dark mode, can I disable it?

@gleb-svechnikov
Copy link

There was an attempt to solve it #5964 but for unknown reason PR was closed.

@ghandic
Copy link

ghandic commented Oct 12, 2021

Any news on this ?

@Atulin
Copy link

Atulin commented Mar 21, 2022

PR still closed, no other word about it. Dark mode must've killed one of the maintainers' hamster or something.

@jeffersoneagley
Copy link

Still a problem too.

@Atulin
Copy link

Atulin commented Apr 27, 2022

And most probably will continue being one: #5964 (comment)

@mrmelon54
Copy link

at this point I might as well just make my own openapi compliant spec ui with dark mode supported by default
I don't understand how a developer can make a light mode UI it's literally torture

@dretax
Copy link

dretax commented Apr 15, 2023

https://github.com/Amoenus/SwaggerDark/

@OzBob
Copy link

OzBob commented Jul 5, 2023

So reading the PR#5964 comments, the summary is:

[If you want DarkMode, use a custom plugin.]

Which I believe means use static .css file like this one: https://github.com/Amoenus/SwaggerDark/

Not sure why @tim-lai has left this feature request issue open when it is not going to be worked on.

@gdibble
Copy link

gdibble commented Aug 29, 2023

🙏 Should this ever get traction: How about it just respects the OS setting? Thanks! :)

@landsman
Copy link

This would be awesome. I have to see bright colors at night.

I think that by rewriting CSS to using CSS variables + this media query would make the effect:

:root {
  --background-body: white;
}

body {
  background: var(--background-body);
}

/* override variables for dark mode */
@media (prefers-color-scheme: dark) {
  --background-body: black;
}

@landsman
Copy link

cc @Amoenus
I saw you been doing a similar job there: https://github.com/Amoenus/SwaggerDark/

@BenRacicot
Copy link

Any updates here? I'd be willing to lend my development time if a maintainer confirms it will not be ignored.

@landsman
Copy link

Guys, let's add this

@sergei-zachesov
Copy link

Here is another example of a dark theme: https://bf5vj.csb.app/

@fulldecent
Copy link

I'm using poor dark mode with poor CSS hosting with default HTML template. This should be the starting point for anyone using Swagger.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>tbone API</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swagger-ui@5.10.0/dist/swagger-ui.css" integrity="sha256-IgNmYaATqY6z6AuD6hvz9XN0OyeAc94gsTa+lK8ka1Y=" crossorigin="anonymous">
    <style>
        /* Fast dark mode https://github.com/swagger-api/swagger-ui/issues/5327 */
@media (prefers-color-scheme: dark) {
    body {
        background: black;
    }
    .swagger-ui {
        filter: invert(88%) hue-rotate(180deg);
    }
    .swagger-ui .microlight {
        filter: invert(100%) hue-rotate(180deg);
    }
}
    </style>
</head>
<body>
    <div id="swagger-ui"></div>
    <script src="https://cdn.jsdelivr.net/npm/swagger-ui@5.10.0/dist/swagger-ui-bundle.js" integrity="sha256-i050FsZ0MSwm3mVMv7IhpfCdK90RKaXPS/EmiWxv8vc=" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/swagger-ui@5.10.0/dist/swagger-ui-standalone-preset.js" integrity="sha256-IGoJVXW7MRyeZOsKceWVePAShfVpJhnYhDhOQp+Yi38=" crossorigin="anonymous"></script>    
    <script>
        // Initialize Swagger UI
        window.onload = function() {
            const ui = SwaggerUIBundle({
                url: "openapi.yaml",  // Provide the URL to your OpenAPI spec file
                dom_id: '#swagger-ui',
/*
                deepLinking: true,
                presets: [
                    SwaggerUIBundle.presets.apis,
                    SwaggerUIStandalonePreset
                ],
                layout: "BaseLayout"
*/                
            });
            window.ui = ui;
        };
    </script>
</body>
</html>

@jcphlux
Copy link

jcphlux commented Nov 18, 2023

I just started a Swagger UI Themes project. It uses webkits and builds the theme css file the same way Swagger UI builds there default css. I only have a dark-modern theme so far but I just started the project last night. swagger-ui-themes
you can check out a demo page at Dark Modern Demo

I am looking into some way to host the css files on a cdn and will work on adding distribution downloads but for now you can grab the css from the dist folder

@tteze
Copy link

tteze commented Jan 11, 2024

For whose who searching for a nelmio api doc dark mode i use this, it works well.

In templates/bundles/NelmioApiDocBundle/SwaggerUi/index.html.twig put :

{% extends '@!NelmioApiDoc/SwaggerUi/index.html.twig' %}

{% block stylesheets %}
    {{ parent() }}

    <style>
        @media (prefers-color-scheme: dark) {
            body {
                background: #000000;
            }
            .swagger-ui * {
                filter: invert(100%);
            }
        }
    </style>
{% endblock %}

@landsman
Copy link

CSS variables would fix the whole issue without hacking by inverting colors.

@JesseSinivuori
Copy link

Just got started with swagger-ui ( and hono: @hono/swagger-ui) and couldn't find dark mode so i made a quick one... looks like this:
Screenshot 2024-06-28 at 00-58-09 Custom Swagger i used tailwind colors

here's the code:

app.get("/ui", (c) => {
  return c.html(`
    <html lang="en">
      <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <meta name="description" content="Custom Swagger" />
        <title>Custom Swagger</title>
        <script>
        </script>
        <style>
            :root {
      --bg-color: #020617;
      --primary-color: #e2e8f0;
      --secondary-color: #94a3b8;
      --highlight-bg-color: transparent;
      --highlight-border-color: #1e293b;
      --button-bg-color: #0f172a;
      --button-text-color: #e2e8f0;
      --method-bg-color: transparent;
      --cancel-border-color: #b91c1c;
      --success-color: #4ade80;
      --select-bg-color: transparent
      --copy-button-bg-color: transparent
      --servers-bg-color: transparent
      --execute-button-bg-color: transparent
    }

    body {
      background-color: var(--bg-color);
      color-scheme: dark;
    }

    * {
      color: var(--primary-color);
    }

     .execute {
      color: var(--bg-color) !important;
      background-color: var(--primary-color) !important;
      border: transparent 1px solid !important;
    }

    .btn-clear, .btn-clear:hover {
      color: var(--primary-color) !important;
      border: transparent 1px solid !important;
    }

    .btn-clear:hover {
      border: transparent 1px solid !important;
    }
    
    .opblock-summary-method {
      background-color: var(--method-bg-color) !important;
      font-weight: 800 !important
    }

    .opblock-section-header {
      background-color: var(--highlight-bg-color) !important;
    }

    p, td, .tabitem {
      color: var(--secondary-color) !important;
    }

    h1, h2, h3, h4, h5, h6, h7 .active {
      color: var(--primary-color) !important;
    }

    pre .highlight-code, .microlight {
      background-color: var(--highlight-bg-color) !important;
      border: var(--highlight-border-color) solid 1px;
    }

    .try-out__btn {
      color: var(--button-bg-color) !important;
      background-color: var(--primary-color) !important;
      border: transparent 1px solid !important;
    }

    .cancel {
      color: var(--primary-color) !important;
      background-color: var(--highlight-bg-color) !important;
      border-color: var(--secondary-color) !important;
    }

    .download-contents {
      background-color: var(--button-bg-color) !important;
      color: var(--primary-color);
    }

    .copy-to-clipboard {
      background-color: var(--copy-button-bg-color) !important;
      color: var(--button-text-color);
    }

    .highlight-code .copy-to-clipboard {
      background-color: var(--button-bg-color) !important;
      color: var(--button-text-color);
    }

    .servers {
      background-color: var(--servers-bg-color) !important;
    }

    .response-control-media-type__accept-message {
      color: var(--success-color) !important;
    }

    .title small {
      background-color: var(--bg-color) !important;
    }

    .arrow {
      fill: var(--primary-color) !important;
    }

    select {
      background-color: var(--select-bg-color) !important;
      color: var(--primary-color) !important;
      border-color: var(--highlight-border-color) !important;
    }

    .opblock-summary-control {
      outline: none !important;
    }

    .model-box .json-schema-2020-12__title, .json-schema-2020-12-expand-deep-button {
      color: var(--secondary-color) !important;
    }
    .json-schema-2020-12__attribute--primary {
      color: var(--primary-color) !important;
    }
        </style>
      </head>
      ${SwaggerUI({ url: "/api/v1/doc" })}
    </html>
  `);
});

its not perfect but its something for a starting point i guess 🙂

@matiasvallejosdev
Copy link

matiasvallejosdev commented Oct 8, 2024

I used this https://github.com/Amoenus/SwaggerDark but please must we add a new feature for dark mode.

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

Successfully merging a pull request may close this issue.