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

Allow users to bring their own styles #78

Closed
NickyMeuleman opened this issue Jan 28, 2022 · 7 comments
Closed

Allow users to bring their own styles #78

NickyMeuleman opened this issue Jan 28, 2022 · 7 comments

Comments

@NickyMeuleman
Copy link
Collaborator

Allow users to provide their own CSS.
That way they can either tweak a theme to their liking, or even use it to bring their own custom theme. (maybe this can be used to build custom themes on a base of #44)

This raises a few security questions.
It would mean executing CSS on the user's device.
While CSS is probably fine, executing any code that can be user-supplied warrants a closer look at how that is handled.

@BenDMyers
Copy link
Owner

Hey, @NickyMeuleman! Can you let me know what you're imagining this experience to be like?

@NickyMeuleman
Copy link
Collaborator Author

NickyMeuleman commented Jan 28, 2022

I was thinking about an optional way to load a (local) .css file.
That way you could use showmy.chat without having to stick strictly to the pre-defined themes.

This wouldn't replace the pre-defined themes, but be an optional way to provide CSS rules and supply additions/overrides.

Not sure how that would work yet. But some possible implementation:
We may be able to provide another queryparam that does this.
Like how the correct theme .css file is chosen now, also add a (local) one if it is supplied.

The filereader API is pretty neat, I use it on https://nickymeuleman.netlify.app/aoc2021-solver/ to let someone "upload" their own input.
Upload is in quotes there, because the file never leaves the user's computer and all work is done on their machine.

#73 Would be the guide for users to provide their own style rules, how they know what to target.

@BenDMyers
Copy link
Owner

Gotcha — I thiiiiink this is already supported, through other routes.

If you want to start with a theme and just tweak styles, OBS (and maybe OBS's descendants?) let you inject custom styles into your browser source.

If you'd like to inject a whole dang stylesheet, the theme attribute does support a valid URI. I haven't really tested it with local files, but I have confirmed that it supports any stylesheets hosted publicly and served with the text/css MIME type? (Unfortunately, GitHub's raw viewer serves even stylesheets as text/plain). It'd be worth validating whether this already supports local filepaths out of the box.

@NickyMeuleman
Copy link
Collaborator Author

Nice! Didn't know that.
Just tried to load a local file really quick (with some minor changes to the sourcode) and it seems browsers block this for security reasons.
The method I tried was using a file:// URI.
I tested http://localhost:8080/c/test?DEMO=true&theme=file://home/nicky/projects/showmy.chat/src/test.css and the browser blocked it.

Since using local CSS is possible via the tools you're likely to use showmy.chat with like OBS this is fine.
(OBS worked perfectly, really nice)

Didn't test the web-hosted files yet.
If that works, feel free to close this issue!

@BenDMyers
Copy link
Owner

Here's an example of using Pico.css as an external, CDN-hosted stylesheet:

https://showmy.chat/c/NMeuleman?DEMO=true&theme=https://unpkg.com/@picocss/pico@latest/css/pico.min.css

@BenDMyers
Copy link
Owner

There's a brief comment about this feature in the config docs — https://showmy.chat/docs/configuration/#theme — but it's easy to miss. I think this feature is very cool because not only does it mean folks can build their own themes without having to go through the contributor workflow, it also allows us to provide private themes for folks (and have them be responsible for hosting).

@NickyMeuleman
Copy link
Collaborator Author

It's awesome and was exactly what I was thinking of when I created this issue!

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

2 participants