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

推荐订阅源

K
Kaspersky official blog
小众软件
小众软件
Engineering at Meta
Engineering at Meta
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
G
Google Developers Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
V
V2EX
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Google DeepMind News
Google DeepMind News
Security Archives - TechRepublic
Security Archives - TechRepublic
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
C
Check Point Blog
aimingoo的专栏
aimingoo的专栏
罗磊的独立博客
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
MongoDB | Blog
MongoDB | Blog
L
LINUX DO - 热门话题
酷 壳 – CoolShell
酷 壳 – CoolShell
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
H
Help Net Security
Martin Fowler
Martin Fowler
G
GRAHAM CLULEY
Simon Willison's Weblog
Simon Willison's Weblog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - Franky
V
Vulnerabilities – Threatpost
云风的 BLOG
云风的 BLOG
博客园_首页
C
Cybersecurity and Infrastructure Security Agency CISA
量子位
Stack Overflow Blog
Stack Overflow Blog
Recent Announcements
Recent Announcements
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
I
Intezer
Scott Helme
Scott Helme
A
About on SuperTechFans
博客园 - 司徒正美
Hacker News: Ask HN
Hacker News: Ask HN
The GitHub Blog
The GitHub Blog
Forbes - Security
Forbes - Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园 - 聂微东
人人都是产品经理
人人都是产品经理
The Cloudflare Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Spread Privacy
Spread Privacy
T
Tailwind CSS Blog
S
Security Affairs
宝玉的分享
宝玉的分享

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