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

giscus dark mode #383

Open
tomalaforge opened this issue Dec 1, 2023 · 7 comments
Open

giscus dark mode #383

tomalaforge opened this issue Dec 1, 2023 · 7 comments
Labels

Comments

@tomalaforge
Copy link
Owner

tomalaforge commented Dec 1, 2023

I'm starting a new issue, this will be easier to follow.

From @jdegand
I think the dark mode problems may stem from the binding of the theme. See this giscus issue. On my computer the comment section is still white on the dark mode as well. You are binding in the comment section.astro file with data-theme="preferred_color_scheme". I noticed inspecting source code both light and dark in some classes.

Giscus doesn't really seem to support / advertise Angular support (Giscus component has no version for Angular) and I think the binding issue is probably why.

It is just a minor issue.

Originally posted by @jdegand in #377 (comment)

@jdegand
Copy link
Contributor

jdegand commented Dec 2, 2023

export class L extends HTMLElement {
    #e = "starlight-theme";
    constructor() {
        super(), this.#n(this.#o());
        const e = this.querySelector("select");
        e && e.addEventListener("change", n => {
            n.currentTarget instanceof HTMLSelectElement && this.#n(this.#t(n.currentTarget.value))
        })
    }
    #t(e) {
        return e === "auto" || e === "dark" || e === "light" ? e : "auto"
    }
    #s() {
        return matchMedia("(prefers-color-scheme: light)").matches ? "light" : "dark"
    }
    #n(e) {
        StarlightThemeProvider.updatePickers(e), document.documentElement.dataset.theme = e === "auto" ? this.#s() : e, this.#r(e)
    }
    #r(e) {
        typeof localStorage < "u" && (e === "light" || e === "dark" ? localStorage.setItem(this.#e, e) : localStorage.removeItem(this.#e))
    }
    #o() {
        const e = typeof localStorage < "u" && localStorage.getItem(this.#e);
        return this.#t(e)
    }
}

I used the web components extension and this nested ternary is used for the select.

document.documentElement.dataset.theme = e === "auto" ? this.#s() : e, this.#r(e)

Does this look right to you?

@tomalaforge
Copy link
Owner Author

I've never used web component, but if it does the job, it's right for me.

@jdegand
Copy link
Contributor

jdegand commented Dec 6, 2023

I'm thinking now that there maybe a conditional logic error. The issue mentioned attribute binding but the error still occurs when both attributes are correct.

This issue is worth looking at as well.

@tomalaforge
Copy link
Owner Author

yes indeed, the change is not done automatically. I need to look at it more closely when I have more time. Or if you want to do it, don't hesitate 😅

Copy link

This issue is stale because it has been open for 20 days with no activity.

@github-actions github-actions bot added the stale label Dec 28, 2023
@jdegand
Copy link
Contributor

jdegand commented Dec 31, 2023

Giscus has a bug and is down for next few days.

@github-actions github-actions bot removed the stale label Jan 1, 2024
Copy link

This issue is stale because it has been open for 20 days with no activity.

@github-actions github-actions bot added the stale label Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants