惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
News and Events Feed by Topic
GbyAI
GbyAI
博客园 - Franky
宝玉的分享
宝玉的分享
Blog — PlanetScale
Blog — PlanetScale
Google DeepMind News
Google DeepMind News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
人人都是产品经理
人人都是产品经理
Microsoft Azure Blog
Microsoft Azure Blog
The Register - Security
The Register - Security
腾讯CDC
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
I
InfoQ
The Cloudflare Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Engineering at Meta
Engineering at Meta
MongoDB | Blog
MongoDB | Blog
有赞技术团队
有赞技术团队
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
F
Full Disclosure
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Vercel News
Vercel News
博客园 - 【当耐特】
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Schneier on Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Project Zero
Project Zero
量子位
M
MIT News - Artificial intelligence
Stack Overflow Blog
Stack Overflow Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
美团技术团队
Attack and Defense Labs
Attack and Defense Labs
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Blog of Author Tim Ferriss
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Troy Hunt's Blog
Google Online Security Blog
Google Online Security Blog
罗磊的独立博客
P
Proofpoint News Feed
Schneier on Security
Schneier on Security
Spread Privacy
Spread Privacy
S
SegmentFault 最新的问题
L
LINUX DO - 最新话题
Simon Willison's Weblog
Simon Willison's Weblog
爱范儿
爱范儿
博客园 - 聂微东
A
About on SuperTechFans
PCI Perspectives
PCI Perspectives
D
Docker

Ben Frain

So, you want a React modal that uses the <dialog> element and transitions in AND out? Scroll indicators on tables with background colours using animation-timeline Review: SoundPEATS Clip1 Open ear clip-on headphones VS Code – highlight just the active indent guide Review: MoErgo Go60, a split ergonomic and fully programmable keyboard Review: Kinesis mWave mechanical ergonomic and programmable keyboard iOS26 Safari theme-color/tab-tinting with fixed position elements is a mess New Book: Responsive Web Design with HTML5 and CSS, 5th Edition Use @supports with a proxy feature/value for features you can’t test for (@starting-style) First adventures in View Transitions Review: Benq Screenbar Pro and Halo lightbars. The kit you never knew you needed! Center items in a container, and make then left aligned when they overflow A single element CSS donut timer/countdown timer, that can sit on any background Review: Open Ear Headphones – Bose Open Ultra v Huawei FreeClip In search of the perfect autocomplete for CSS Managing multiple versions of node, without NVM or additional tools Review: Keychron Q14 Max Alice 96 Key mechanical keyboard NEW VIDEO COURSE: Responsive Web Design with HTML5 and CSS Is CSS Grid really slower than Flexbox? Review: Advantage360 Pro Signature Edition 2024 mechanical ergonomic keyboard More Keys or Fewer Keys for mechanical keyboards Yes! You can use position: sticky and overflow together Neovim – how to do project-wide find and replace? Review: Keyboardio Model 100, split, wooden, mechanical keyboard Struggling to learn SwiftUI How to create rounded gradient borders with any background in CSS How to get equal size icons in the cmp completion menu of Neovim with Kitty terminal Review: Dygma Defy, split, mechanical, programmable ergonomic keyboard What’s the best way to reset WAAPI chained animations? Dynamically create a ref for items when iterating over them in lit.dev templates Selecting and pausing running animations in Lit Web Components New Web APIs — a popover on top of a dialog element can’t be interacted with? Review: ZSA Voyager, split, mechanical keyboard Russel Brand, narcissism, and a sadly common pattern… When it comes to text editors, I feel like Goldilocks Simple settings for writing and converting markdown with Sublime Text Review: The ZSA Platform tenting kit for the Moonlander keyboard Logitech MX Master 3/3s scroll wheel fix Building a line graph with CSS clip-mask Review: Dell 6K 32″ Monitor U3224KBA I broke my keyboard! Swapping the key switches in the Kinesis Advantage360 Pro HUGE macOS Productivity boost: Set-up simple, keyboard only, instant App switching and arrangement Adding to $PATH for a central location for Neovim/NPM tools Neovim Power Tips: Volume 2 Review: MoErgo Glove80, split, wireless, columnar ergonomic keyboard with RGB Review: Kinesis Advantage 360 Pro — split ergo mechanical keyboard Review: Dactyl Manuform – an ergonomic, custom built mechanical keyboard How to animate along an SVG path at the same time the path animates? Getting the context of Web Components (lit)
Using CSS @property inside shadowRoot (web components) workaround
Ben Frain · 2023-12-13 · via Ben Frain

Another adventure using lit and another little ‘Gotcha’ I picked up from the good folks on the lit Discord.

This one was niche enough I felt it was worth documenting.

I was trying to use the new CSS @property inside a lit/web component and couldn’t figure out what I was doing wrong. In this case I was making a single element loader, using a conical-gradient. The idea was that I would run an animation that made use of a registered custom property to animate the conical gradient. Here is an example outside of a web component.

See the Pen Super Easy Pie chart loader by Ben Frain (@benfrain) on CodePen.

And for copy and paste goodness, here is the CSS:

@property --countdown {
  syntax: "<percentage>";
  initial-value: 100%;
  inherits: false;
}

@keyframes deplete {
  100% {
    --countdown: 0%;
  }
}

.thing {
  height: 100px;
  width: 100px;
  border-radius: 50%;
  animation: deplete 10s linear;
  background-image: conic-gradient(
    hotpink 0,
    pink var(--countdown),
    transparent var(--countdown)
  );
}

I have set the @property name to --countdown, set it to use percentage as the syntax, given an initial value, then created a set of @keyframes to take the value from the default 100%, to 0%.

Then I set my conical-gradient to have a hard lined edge that is at the same value as the countdown, so that when the animation runs, my conical-gradient gets animated giving me the Pie Timer effect.

However, sticking this in a web component does not work. The reason is, that @property does not work inside the CSS of a shadowRoot.

To get things working in Web Component land, this requires installing the @property in the document, and here is the way you can do that:

import { html, css, LitElement } from "lit";
import { customElement, property } from "lit/decorators.js";

@customElement("simple-greeting")
export class SimpleGreeting extends LitElement {
  static {
    console.log("install document styles");
    const documentStyles = css`
      @property --panelCountdown {
        syntax: "<percentage>";
        initial-value: 100%;
        inherits: false;
      }
    `;
    document.adoptedStyleSheets.push(documentStyles.styleSheet);
  }

  static styles = css`
    @keyframes deplete {
      100% {
        --panelCountdown: 0%;
      }
    }

    .thing {
      height: 100px;
      width: 100px;
      border-radius: 50%;
      animation: deplete 10s linear;
      background-image: conic-gradient(
        hotpink 0,
        pink var(--panelCountdown),
        transparent var(--panelCountdown)
      );
    }
  `;

  render() {
    return html`<div class="thing"></div>`;
  }
}

With that installed via document.adoptedStyleSheets the @property is registered and ready to use. You can see this over on the lit.dev playground: https://lit.dev/playground/#gist=f4251bf213f8cbdb9d68a406ff50cd13