Permettre aux utilisateurs de sélectionner de nouvelles palettes de couleurs

:bookmark: Ceci est un guide pour rendre une nouvelle palette de couleurs disponible pour que tous les utilisateurs puissent la choisir dans les préférences de leur profil.

:person_raising_hand: Niveau d’utilisateur requis : Administrateur

Inclure une nouvelle palette de couleurs

  1. Allez dans AdminApparencePalettes de couleurs
  2. Créez une nouvelle palette de couleurs en cliquant sur le bouton + Nouvelle
  3. Sélectionnez la palette de couleurs de base préférée dans la liste
  4. Cochez l’option La palette de couleurs peut être sélectionnée par les utilisateurs
  5. Effectuez les ajustements de palette appropriés, si nécessaire
  6. Enregistrez la palette de couleurs

Sélection de la palette de couleurs

Désormais, les utilisateurs peuvent sélectionner la nouvelle palette de couleurs sur leur page de préférences respective : https://votre-site.com/my/preferences/interface :

  1. Accès aux préférences utilisateur : Les utilisateurs peuvent accéder à leurs préférences en cliquant sur leur icône de profil dans le coin supérieur droit du forum et en sélectionnant « Préférences » dans le menu déroulant.
  2. Onglet Interface : Dans les préférences, l’onglet « Interface » contient le paramètre permettant de choisir une palette de couleurs pour les modes Clair et Sombre.
  3. Sélection de la palette de couleurs : Les utilisateurs peuvent choisir leur palette de couleurs préférée dans le menu déroulant fourni.
  4. Mode couleur de l’interface : Les utilisateurs peuvent également sélectionner leur mode couleur d’interface préféré — Auto (suit la préférence du système), Clair ou Sombre.
  5. Enregistrement des modifications : Une fois leur palette de couleurs désirée sélectionnée, les utilisateurs doivent cliquer sur le bouton « Enregistrer les modifications » en bas de la page pour appliquer les changements.

Mode sombre

Par défaut, Sombre, Clair WCAG, Sombre WCAG, Dracula, Solaire Clair et Solaire Sombre sont déjà des palettes de couleurs définies dans Discourse.

Ressources supplémentaires

37 « J'aime »

Great work! Simple to understand how to compose themes together quite nicely – I’m going to play around with themes soon, for sure!

Bit o’ feedback on this:

I’m seeing that there’s an option to import themes directly - What’s the structure that import-able themes should take? A repository with the .dcstyle.json file(s) at the root? It’s not clear, and the placeholder value – https://github.com/discourse/discourse/sample_theme - doesn’t lend any clues.

It also seems that exporting themes got a little more difficult as you can’t just export a theme with a single click if that theme is dependent on child themes. I understand why this might need to be this way, but I’m concerned about portability of themes with the added inheritance - will there be a way to export the theme as a bundle with all child themes attached as well?

2 « J'aime »

You can read about that here:

5 « J'aime »

We are going to ship both dark and light themes by default out of the box, yes? That’s my goal here. We also need:

  • small font
  • large font

themes to ship natively as well.

8 « J'aime »

This is fabulous. :rocket: Thanks for adding this feature and for writing up this howto. Can you add instructions for specifying a different logo for the dark theme? That will be a common request I am sure.

11 « J'aime »

Yup, this is the primary (only?) blocker for this. I see that Meta is switching logos, or applying some kind of shadow.

This is actually pretty simple:

old method
.logo-big {
    display: block;
    -moz-box-sizing: border-box;
     box-sizing: border-box;
     background: url(awesome-dark-logo.png) no-repeat;
     width: 150px; 
     height: 40px; 
     padding-left: 150px; 
     background-size: 150px 40px;
}

You basically evict the existing image out of the IMG tag

13 « J'aime »

Setting up a dark theme made me inquire into where this grey background colour comes from:

I do not have any black in my colour scheme so I suppose that the grey is calculated as a lighter version of the complementary colour of the primary colour (white, in my case).

While I can see the reasoning behind it, it doesn’t really work if your black theme is using anything outside the black/grey spectrum as secondary colour. Perhaps it’s a matter of taste, but I’d probably prefer that navigation button background colour (or whatever it’s called) to be based on the secondary colour.

I am not saying that every colour should be chosen manually (discourse is generally doing a great job in calculating colours - mainly shades and tints, I believe - based on the few customizable ones) but this particular formula seems a bit too constraining.

Perhaps it can be solved with a single switch that allows the user to switch the color base between primary and secondary colour?

Use secondary colour as base for button backgrounds

2 « J'aime »

@tophee, I think the derivative colors make it really easy to use. For advanced color schemes you have to use advanced features—specifically custom CSS in this case. That seems like a logical ask to me.

Awesome. This makes browsing the discourse at night so much easier on the eyes, even with the new Windows 10 “night mode” the light theme is pretty bright.

Now the ability to switch the theme easily through a keyboard shortcut, menu item or other button, and we’re set! :sunglasses: :heart_eyes:

1 « J'aime »

I am not calling derivative colours into question, merely pointing out that the way one of them is derived could be improved.

So using a colour outside the black-white continuum is advanced? I wouldn’t think so.

In my testing I am noticing some peculiarities, and I even had another user on my site test this because this seemed to simple that I thought I was missing something, but here are my steps to reproduce:

  1. Have no user selectable themes enabled.
  2. Change your default theme.

Observed Result: The theme doesn’t change for the user until they go in to their Preferences > Interface and click Save Changes, even though that is the only theme available to them in the dropdown. Is anybody else seeing this?

I think this is an admin thing, also make sure you are on latest.

If you ever set the theme via the selector in prefs we set a cookie (this cookie is validated server side with an admin bypass)

So, I would re-test this theory of yours on Chrome incognito … what happens? Then as a non admin … what happens?

Yeah, must just be a cookie refresh issue. I was doing a hard refresh clearing the cache, but I had two logged in tabs open so I think that may have played a part. I can reproduce in incognito, but not after a hard refresh, so this appears to be a non-issue. I will be more careful about testing in incognito mode before reporting again. Thanks for the quick reply.

2 « J'aime »

Hello
I have try it but i am not able to change theme from menu (like on meta) i use discourse app and safari and still not show . I run the latest version of discourse .

You need the Hamburger Theme Selector to display themes inside the hamburger menu.

4 « J'aime »

Oh y understand now …Thanks .

What would be the right code for .logo-small? Seems to be a large gap on right when using:

.logo-small { display: block; -moz-box-sizing: border-box; box-sizing: border-box; background: url(awesome-dark-icon.png) no-repeat; width: 40px; height: 40px; padding-left: 150px; background-size: 40px 40px; }

Not totally sure, can you add a screenshot of what you have now? Perhaps @awesomerobot can help.

My guess from looking at your CSS is that the padding-left: 150px; is the cause; your .logo-small is 40px wide, so you’d have 110px of space to the right of it because of that padding-left.

5 « J'aime »