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

Add <BaselineStatus> component #156

Merged
merged 43 commits into from
Oct 27, 2024
Merged

Add <BaselineStatus> component #156

merged 43 commits into from
Oct 27, 2024

Conversation

delucis
Copy link
Owner

@delucis delucis commented Oct 24, 2024

Adds a JS-free <BaselineStatus> component for rendering web feature status. Based on https://github.com/web-platform-dx/baseline-status but without the client-side dependencies.

Copy link

changeset-bot bot commented Oct 24, 2024

🦋 Changeset detected

Latest commit: ea56cdd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@astro-community/astro-embed-baseline-status Minor
astro-embed Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

netlify bot commented Oct 24, 2024

Deploy Preview for astro-embed ready!

Name Link
🔨 Latest commit ea56cdd
🔍 Latest deploy log https://app.netlify.com/sites/astro-embed/deploys/671e197b49f71a0009f04127
😎 Deploy Preview https://deploy-preview-156--astro-embed.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

@mayank99 mayank99 left a comment

Choose a reason for hiding this comment

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

I tried it out, and it looks quite broken (as you're probably aware).

Screenshot

I've left some suggestions below (unrelated to the broken styling). I'm aware that a lot of these issues stem from the original <baseline-status> widget; their implementation is extremely disappointing. I think it's possible to build something much better. But also, please feel free to ignore these comments; I don't want to overwhelm you 😅

Excited to see where this goes!

packages/astro-embed-baseline-status/BaselineStatus.astro Outdated Show resolved Hide resolved
packages/astro-embed-baseline-status/BaselineStatus.astro Outdated Show resolved Hide resolved
<baseline-status>
<h1>{feature.name}</h1>
<details>
<summary
Copy link
Contributor

Choose a reason for hiding this comment

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

There's definitely some subjectivity here, but I think the <summary> should not have so much content inside it. Most of the content should be outside the <summary>.

I think of it like a <button>, where the general advice is to keep the labels concise.

packages/astro-embed-baseline-status/BaselineStatus.astro Outdated Show resolved Hide resolved
packages/astro-embed-baseline-status/BaselineStatus.astro Outdated Show resolved Hide resolved
packages/astro-embed-baseline-status/BaselineStatus.astro Outdated Show resolved Hide resolved
packages/astro-embed-baseline-status/BaselineStatus.astro Outdated Show resolved Hide resolved
packages/astro-embed-baseline-status/BrowserIcon.astro Outdated Show resolved Hide resolved
packages/astro-embed-baseline-status/BaselineStatus.astro Outdated Show resolved Hide resolved
packages/astro-embed-baseline-status/BaselineStatus.astro Outdated Show resolved Hide resolved
@delucis
Copy link
Owner Author

delucis commented Oct 25, 2024

Haha, thanks for the review @mayank99! +1 to all of this. So far I had just literally ripped apart the official component translating it to Astro. (I'm also always a bit unsure of how much people want things that are 1:1 with the official implementation vs diverging but better 😁)

Re: styling — last night I was playing around with DSD for isolation, basically:

<baseline-status>
  <template shadowrootmode="open">
    <link rel="stylesheet" href="...">
    <!-- component markup -->
  </template>
</baseline-status>

That's a bit naive I suspect — my first time using DSD — but noted a couple things:

  • Works well for isolating from page styles (although that's not always a goal in this library because for the simpler Twitter and Mastodon embeds it's kind of nice they mostly inherit site styles)
  • Using a <link> for styles feels like the right thing to do (vs an inline <style> which would get duplicated for every instance. However it looks like DSD links are only discovered/downloaded on template adoption? Not a huge deal but does mean styles load slightly slower in this case than CSS which is linked in <head>.
  • Haven't yet looked at custom styles. Would be happy to have something like your parts approach if you wanted to PR it.

Dark theme support in particular is something I'm thinking about. I was also a bit surprised that they considered light-dark stable enough. Other components in this package I've designed to just inherit local colours so this is not an issue.

@mayank99
Copy link
Contributor

However it looks like DSD links are only discovered/downloaded on template adoption? Not a huge deal but does mean styles load slightly slower in this case than CSS which is linked in <head>.

Good point. It might be worth documenting that the stylesheet should be preloaded if this component is in the critical rendering path. That does mean you'll have to expose the CSS file in the package "exports" field.

@delucis
Copy link
Owner Author

delucis commented Oct 25, 2024

Good point. It might be worth documenting that the stylesheet should be preloaded if this component is in the critical rendering path. That does mean you'll have to expose the CSS file in the package "exports" field.

I’m working on an alternative. Remains to be seen if you think it’s a terrible idea. This is my first time really working with Shadow DOM full-stop (let alone DSD), so I could be doing things terribly 😁

Basic idea:

  1. Markup uses DSD something like this:

    <div class="baseline-status">
    	<template shadowrootmode="open">
    		<div part="root"><!-- component --></div>
    	</template>
    </div>
  2. Styles are authored in a regular way with Astro targeting things with ::part().

::part() is a bit annoying of course, but this approach means that the styles can be bundled and hoisted to <head>, the component is still isolated from its context, and the component styles are also scoped to the component (kind of a given with Astro but still).

Seems to be working so far. I’m just going through updating the CSS to match this new approach. (So feel free to tell me now why I shouldn’t do this 😅)

Edit: one reason is it’s making some stuff difficult, e.g. expressing details[open] svg relationships seems to be impossible?

@mayank99
Copy link
Contributor

one reason is it’s making some stuff difficult, e.g. expressing details[open] svg relationships seems to be impossible?

Yeah that's basically the reason. If you can achieve everything you need using ::part, that's great! But it does limit the selectors you can use.

You could always inline some of the CSS in <style> tags inside shadow-roots. If it's a small amount of CSS, it should be totally fine. It increases the document size, but it compresses well, so shouldn't impact size over the network. At runtime, browsers have optimizations to dedupe <style>s repeated across shadow-roots.

@delucis
Copy link
Owner Author

delucis commented Oct 25, 2024

Yeah, that’s basically what I did — only needed to inline two tiny things. Massive commit coming up shortly!

@delucis
Copy link
Owner Author

delucis commented Oct 25, 2024

OK, pushed up that big refactor. I’ve also written some docs outlining the hooks for styling: https://deploy-preview-156--astro-embed.netlify.app/components/baseline-status/

Happy to incorporate feedback here as to how this feels and what other custom properties or parts could be useful.

Re: light-dark() being a little early — I think I’ve found a happy middle ground where it’s still used but the fallback behaviour when it doesn’t work (older browser, site without color-scheme) is OK. Text color inherits the current body color, so should remain legible, and the switcher falls back to prefers-color-scheme for light/dark. If you hit the combo of older browser/no color-scheme AND the site uses a theme contrary to the user’s system preference, the worst thing that happens is that the iconography shades will be using the wrong variant and may have slightly worse contrast, but I think it’s acceptable fallback behaviour (especially considering the crowd likely to be using these components).

Re: custom element namespacing — these have now been removed. There’s a top-level .baseline-status class name that scopes stuff (plus Astro’s scoping on top of that for the built-in styles).

Some outstanding thoughts from your earlier review:

  • The <summary> content is a lot still, but I can’t quite decide what if anything to do about that.
  • I made the feature name <h1> a <p>. There’s part of me that would like some kind of semantic link between that and labelling the card as a whole, but not sure if there’s a good way to do that that is flexible for different usage contexts.

Copy link
Contributor

@mayank99 mayank99 left a comment

Choose a reason for hiding this comment

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

It's late here, I'll take a look tomorrow if you can wait. I appreciate the docs, I'll use it to try theming (I want the baseline widget on my blog to be all monochrome).

For some reason the compiler was generating three `<a>` tags for the link — one additional link after the closing `</template>` and then one more after the final closing `</div>`. These are empty — the text content presumably consumed when outputting the first, correct `<a>`, but can still cause layout issues as well as unnecessary HTML.
The original code used shades that were extremely close to each other for the different Baseline statuses: one for the Baseline checkmark logo, another for the status icons shown next to browsers. The difference seemed more like a mistake than anything and made the color API surface bigger than necessary, so this commit merges those to use the same shades for both.
@mayank99
Copy link
Contributor

Hmm, what would be the best way for me to test this out locally?

@delucis
Copy link
Owner Author

delucis commented Oct 27, 2024

Hmm, what would be the best way for me to test this out locally?

Ah, good point. I may just publish an early version. That would be easiest for you probably.

Otherwise a tool like https://gitpkg.now.sh/ could help to install directly from this branch:

npm install 'https://gitpkg.now.sh/delucis/astro-embed/packages/astro-embed-baseline-status?chris/baseline-status'

And then:

import { BaselineStatus } from '@astro-community/astro-embed-baseline-status';

<BaselineStatus id="has" />

@delucis
Copy link
Owner Author

delucis commented Oct 27, 2024

Going to merge this to release an initial version for testing. We can keep using this PR to discuss if you like or feel free to open a follow-up issue or PR if you prefer.

One thing I haven’t done for now is to put these styles in @layer — style overrides in my docs examples seemed OK, but if it turns out to be a pain in practice, we can do that.

@delucis delucis merged commit bdaa3db into main Oct 27, 2024
5 checks passed
@delucis delucis deleted the chris/baseline-status branch October 27, 2024 10:50
@github-actions github-actions bot mentioned this pull request Oct 27, 2024
@mayank99
Copy link
Contributor

mayank99 commented Nov 2, 2024

I got the chance to try it out. Unfortunately it was too limiting to fit my needs.

  • The styles are all global and unlayered, so they take priority over my layered styles. Even without layers, the styles have non-zero specificity, which means they could override consumer's styles.
  • There is no slotting capability. I would like to be able to switch out the browser icons with monochrome versions, as well as change some of the text and the WebStatus link.

At this point, I think I'll go with my own implementation so you don't have to worry about any of this. The component works great, and most consumers probably would not run into these issues if they use the component as-is.

I also noticed a bug with the layout, which I've opened a PR for. #163

@delucis
Copy link
Owner Author

delucis commented Nov 2, 2024

Thanks for the PR! As mentioned above, happy to move styles to @layer, I just wanted to get an initial version published and while doing that realised I hadn’t used @layer.

Also totally open to other changes — please don’t feel like it’s a bother! If it’s too limiting for you, it’s potentially too limiting for others and I’d love to improve it. (Also, no evidence yet of anyone else using this, so no reason not to tailor it to your needs 😂)

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

Successfully merging this pull request may close these issues.

2 participants