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

Theme switch in examples #5022

Merged
merged 22 commits into from Mar 13, 2024
Merged

Conversation

codeEmpress1
Copy link
Contributor

Done

  • Add toggle button to switch themes in examples
  • Update dark examples to have dark theme on body
    [List of work items including drive-bys]

Fixes [list issues/bugs if needed]

QA

  • Go to docs/examples, click on any example and ensure that there are buttons at the bottom to change between themes

  • Click the themes and ensure it changes accordingly

  • Click on dark examples and ensure it's dark by default, then click on light or paper theme and ensure it changes accordingly.

  • Open demo

  • [Add QA steps]

  • Review updated documentation:

    • [List any updated documentation for review]

Check if PR is ready for release

If this PR contains Vanilla SCSS code changes, it should contain the following changes to make sure it's ready for the release:

  • PR should have one of the following labels to automatically categorise it in release notes:
    • Feature 🎁, Breaking Change 💣, Bug 🐛, Documentation 📝, Maintenance 🔨.
  • Vanilla version in package.json should be updated relative to the most recent release, following semver convention:
    • if CSS class names are not changed it can be bugfix relesase (x.x.X)
    • if CSS class names are changed/added/removed it should be minor version (x.X.0)
    • see the wiki for more details
  • Any changes to component class names (new patterns, variants, removed or added features) should be listed on the what's new page.

Screenshots

image

[if relevant, include a screenshot or screen capture]

@webteam-app
Copy link

Demo starting at https://vanilla-framework-5022.demos.haus

@codeEmpress1
Copy link
Contributor Author

@bartaz I added the toggles as button rather than radio buttons, let me know what you think. Also I'm not so sure how to handle some dark examples like the ones in navigation, the is-dark class was added on heading element and taking it out to body doesn't seems to work. Another one is the dark example for logo, links to logos for dark and light themes are different, I'm thinking we can have the logo links as variables and add it conditionally to the img src

@codeEmpress1 codeEmpress1 marked this pull request as draft March 6, 2024 05:54
&.is-accent {
@include vf-highlight-bar($color-accent);
}
@include vf-highlight-bar($colors--theme--text-default);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You didn't have to do this, thanks :)

I think by mistake you removed the .is-accent version. I don't think we have separate themed accent colour, so for now just keep it as is, regardless of the theme.

<button class="p-button--negative is-dark">Negative button</button>
<button class="p-button--brand is-dark">Brand button</button>
<div class="p-strip is-shallow">
<button class="p-button">Default button</button>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if that works, because buttons have not been migrated to new theming yet, so they need to have is-dark class on them (they don't inherit the theme).

You can keep the is_dark = True part to have class on body, but the is-dark class on buttons needs to stay for now. I know that your toggle will not work properly here, but it's fine.
(I commented in MM about the conditional, so that's another option as well).

Overall, the is-dark classes on buttons need to stay until buttons are properly themed.

@@ -5,7 +5,7 @@

{% set is_paper = true %}
{% block content %}
<div class="p-strip is-dark">
<div class="p-strip">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example is used in the docs to show how to make strip dark, so in this case we want the is-dark class on strip, not on body (to show how to change single strip to dark).

So for now it's ok that theme switch will not work (or will not be available) on this example.

<div class="u-fixed-width p-section--shallow">
<hr class="p-rule--highlight is-dark">
<hr class="p-rule--highlight">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will also not work, the rule component does not support new theming yet, so it will not inherit the theme. It needs to have is-dark class on itself.

So the switch will not work here yet, please revert this example.

</style>
{% endblock %}

{%set is_dark = True%}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a bit of missing whitespace for consistency

Suggested change
{%set is_dark = True%}
{% set is_dark = True %}

</style>
{% endblock %}

{%set is_dark = True%}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you mentioned in the comment, this is tricky one because if images. We can't change images based on the theme, we don't have a solution for it (outside of built in icons). We can't change src based on theme or anything, at least not easily.

So I guess it's ok to just keep this one dark, with switch not working.

{% block content %}
<div class="p-strip is-dark">
<div class="p-strip">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove the strip completely, it was only there to make backround dark.

@codeEmpress1 codeEmpress1 marked this pull request as ready for review March 6, 2024 15:57
@codeEmpress1 codeEmpress1 changed the title WIP: Theme switch in examples Theme switch in examples Mar 6, 2024
@@ -4,6 +4,7 @@
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta id="is-not-themed" data-is_not_themed="{{is_not_themed}}">
Copy link
Contributor

@bartaz bartaz Mar 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an interesting approach to inject the value into the template, but because we only need to read it in JS, maybe it would be simpler (and more reliable) to pass a JS variable instead?

Something like:

<script>
const SHOW_THEME_SWITCH = {% if is_not_themed %}False{% else %}True{% endif %};
</script>

And then you can just check the value of this global var?

codeEmpress1 and others added 2 commits March 8, 2024 10:56
Co-authored-by: Bartek Szopka <83575+bartaz@users.noreply.github.com>
Copy link
Contributor

@bartaz bartaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple small comments, but we are getting there!

templates/_layouts/examples.html Show resolved Hide resolved
templates/_layouts/examples.html Outdated Show resolved Hide resolved
templates/_layouts/examples.html Outdated Show resolved Hide resolved
templates/static/js/example-tools.js Outdated Show resolved Hide resolved
templates/static/js/example-tools.js Outdated Show resolved Hide resolved
Copy link
Contributor

@bartaz bartaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some small updates/fixes in last commits if you are interested.

But looks great, thanks for help with that!

@bartaz bartaz merged commit 4e3b67e into canonical:main Mar 13, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants