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

Update Media Object to support new color theme variables #5187

Merged

Conversation

pastelcyborg
Copy link
Contributor

@pastelcyborg pastelcyborg commented Jun 24, 2024

Done

  • Updated Media Object component to support new color theme variable

Please note the code comment at the top of the file: we can no longer use the vf-url-friendly-color function for theming the icons, as it cannot interpolate CSS variables during compilation (since they only exist at runtime). Instead, I hard-coded different inline icons with specific colors for light/dark themes (paper will use the light theme colors). I think this works, particularly given this element is intended to be deprecated anyway.

Fixes WD-11867

QA

  • Open default, large, and circle demos
  • Ensure component looks as expected across all themes

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 release (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.

@webteam-app
Copy link

Copy link
Member

@jmuzina jmuzina left a comment

Choose a reason for hiding this comment

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

Nice approach! I think this is fine since this component is deprecated as you said.

}

&--venue {
@extend %vf-iconed-list-item;
// prettier-ignore
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="90" height="90" viewBox="0 0 90 90.000001"><g transform="translate(-111.967 -929.337)" color="%23000"><path fill="none" stroke-width="4" overflow="visible" enable-background="accumulate" d="M111.967 929.336h90v90h-90z"/><circle r="6.5" cy="24.5" cx="23.5" transform="matrix(1.846 0 0 1.846 113.583 929.105)" fill="' + vf-url-friendly-color($color-mid-dark) + '" stroke-width="2" overflow="visible" enable-background="accumulate"/><circle r="21" cy="45" cx="45" transform="matrix(1.429 0 0 1.429 92.682 910.05)" fill="none" stroke="' + vf-url-friendly-color($color-mid-dark) + '" stroke-width="4.2" stroke-linejoin="round" overflow="visible" enable-background="accumulate"/><path d="M152.967 931.736l8-2.4v15h-8zM160.967 1016.336h-8v-12h8zM198.967 970.336v8h-12v-8zM114.967 978.336v-8h12v8z" overflow="visible" fill="' + vf-url-friendly-color($color-mid-dark) + '" stroke-width="6" enable-background="accumulate"/></g></svg>');

.is-dark & {
Copy link
Member

Choose a reason for hiding this comment

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

Yes, that's the easiest way to deal with legacy components not supporting the CSS variables.

I'd just add support for having is-dark/is-light class name on itself as well:

.is-dark &,
&.is-dark

And similar with is-light to make sure we can override it to light if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I totally follow, @bartaz - you're saying to add the is-dark theme class onto the p-media-object__meta-list-item itself? What would be the scenario in which someone would need to add the theme class directly onto this element?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, the theme class names can be put on any level. So as a simplification for such legacy components I think it's good to at least support 2 "extremes" (setting class on body - which should be the new most common way to do it, or setting it on component itself - which was the old way to do it).

We do it in similar way in icons:

body.is-dark &,
&.is-light, // DEPRECATED: use is-dark instead
&.is-dark {
@include vf-icon-applications($colors--dark-theme--icon);
}

This way, we should be always able to override the parent theme, by setting theme on the component.
For example if there is a mix of is-dark and is-light on parent elements (because page is dark, but then there is a light strip, and in this light strip there is media object), if the media object thinks it should be "dark" (because of dark class on body), but is actually on light background, we can set is-light on it directly, to override it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I guess I'm still misunderstanding.

The way I have it written, a descendent selector is used to implement themed icons:

.is-dark .p-media-object__meta-list-item--date

If I add an additional selector in the way I'm interpreting your comment, this wouldn't really add any useful functionality:

.p-media-object__meta-list-item---date.is-dark

Because there's no reason to add the theme class at this child level. My descendent selector would already handle both the cases of the theme class existing at the body level or at the component (.p-media-object or similar) level.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, sorry, my bad. They way I mentioned is supposed to be on component root element level.

You know what, it's a legacy component anyway, likely not used in any dark theme situations. So your approach should be fine. In case we spot a bug with that we will address it properly (likely by updating those icons, or redesigning that).

Copy link
Member

@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.

LGTM, sorry for the confusion.

@jmuzina jmuzina added Review: Percy needed This PR needs a review of Percy for visual regressions and removed Review: Percy needed This PR needs a review of Percy for visual regressions labels Jun 26, 2024
@pastelcyborg pastelcyborg added Review: Code +1 Review: Percy +1 and removed Review: Code +1 (with changes) Review: Percy needed This PR needs a review of Percy for visual regressions labels Jun 26, 2024
@pastelcyborg pastelcyborg merged commit c1eda3d into canonical:main Jun 26, 2024
18 checks passed
@pastelcyborg pastelcyborg deleted the update-media-object-theming branch June 26, 2024 14:36
jmuzina pushed a commit to jmuzina/vanilla-framework that referenced this pull request Jun 26, 2024
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.

4 participants