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

Implement live colour palette previews #50

Open
joeroe opened this issue May 3, 2023 · 2 comments
Open

Implement live colour palette previews #50

joeroe opened this issue May 3, 2023 · 2 comments

Comments

@joeroe
Copy link
Owner

joeroe commented May 3, 2023

They're just CSS files, so should be possible to switch them without rebuilding the site. Maybe just on the example site, to avoid any JS dependencies.

@joeroe joeroe changed the title Find a way of previewing themes Implement live colour palette previews May 3, 2023
@BachoSeven
Copy link

BachoSeven commented Jul 7, 2024

On a related note, how hard would it be to implement a theme-switching button for this template (aka light/dark mode)?

@aziis98
Copy link

aziis98 commented Jul 7, 2024

A very bare bones solution for the example site could be to add the following HTML and JS

<select id="theme-selector">
  <option value="base16-light">Base16 Light</option>
  <option value="base16-dark">Base16 Dark</option>
  <option value="gruvbox-dark">Gruvbox Dark</option>
  <option value="gruvbox-light">Gruvbox Light</option>
  ...
</select>
const themeLinkEl = document.querySelector(`link[href^='https://risotto.joeroe.io/css/palettes']`)

document.getElementById('theme-selector').addEventListener('change', e =>
  themeLinkEl.href = `https://risotto.joeroe.io/css/palettes/${e.target.value}.css`
)

I tried doing this in the devtools and we just need to change the href of the <link> tag pointing to the right theme.

For a light/dark theme switch just change the <select> to only have two themes and add a default theme as follows

<link rel="stylesheet" href="default.css">
<link rel="stylesheet" href="light.css" media="(prefers-color-scheme: light)">
<link rel="stylesheet" href="dark.css" media="(prefers-color-scheme: dark)">

(the link tag with the media query prevents the initial flickering and should even work with JS disabled)

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

No branches or pull requests

3 participants