国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home Web Front-end CSS Tutorial A Bit on Web Component Libraries

A Bit on Web Component Libraries

Apr 03, 2025 am 09:42 AM

A Bit on Web Component Libraries

There have been a lot of news about Web Components recently, and I will sort them out here.

I think one of the best application scenarios for Web Components is the pattern library. Instead of using it like Bootstrap<div> , or use it like Bulma<code><div> , it is better to use custom elements, e.g.<code><designsystem-tabs></designsystem-tabs> . The new Shoelace library uses the sl namespace to define its components. It is a schema library that is entirely based on Web Components, where the tags are<sl-tab-group></sl-tab-group> element.

What are the benefits of doing this? First, it introduces the component model. This means that if you are working on a component it will have a template and a stylesheet related to its location. Looking at the internal implementation of Shoelace, you can see that it's all based on Stencil.

Another benefit is that the component can use (and does use) a Shadow DOM. This provides an isolation mechanism directly from the web platform. For us CSS developers, this means that the style of the tags in the tag component is done using the .tab class (wow, it's so cool!), but it's isolated in that component. Even with such a generic name, I would not accidentally affect other components of the common class on the page, nor would there be some external CSS to interfere with the internal structure here. Shadow DOM is like a security wall that prevents styles from leaking or infiltration.

I also see the FAST framework1 which is also a set of components. Its tag is defined as<fast-tabs></fast-tabs> . This reminds me of another advantage of Web Components as a schema library method: it feels like it's API-driven, even starting with the name of the component itself, which is actually what you use in HTML. The properties on this element can be completely customized. The emerging standard seems to be that you don't even have to add data- prefix to custom properties. So if I want to make a tag component, it might be<chris-tabs active-tab="lunch" variation="rounded"></chris-tabs> .

Perhaps the biggest player using Web Components as the schema library is Ionic. Their labels are<ion-tabs></ion-tabs> , you can use them without involving any other frameworks (although they support Angular, React, and Vue in addition to their own Stencil). Ionic has made great progress in Web Components and has recently supported Shadow Parts. Here is the explanation of Brandy Carney again explaining the packaging:

Shadow DOM helps prevent styles from leaking from components and being accidentally applied to other elements. For example, we assign .buttonclass to our<ion-button></ion-button> Components. If the Ionic Framework user sets the .button class on one of its own elements, in earlier versions of the framework it inherits the Ionic button style. because<ion-button></ion-button> It's now a Shadow Web Component, so this problem no longer exists.

However, due to this encapsulation, the style cannot penetrate into the internal elements of the Shadow component. This means that if the Shadow component renders elements in its shadow tree, the user cannot use their CSS to locate internal elements.

Encapsulation is a good thing, but it does make the styling "harder" (deliberately). There is an important CSS concept to understand: CSS custom properties can penetrate Shadow DOM . But it is not wise for people to decide—I think that’s right—to “variably” everything in a design system. Instead, they give each HTML fragment within the Shadow DOM a part, e.g.<div part="icon"> , which allows us to "access from outside" using CSS, e.g. <code>custom-component::part(icon) { } . I think part-based style hooks are mostly good and a sensible solution for a pattern library like this, but I admit that part of it bothers me. The selector works differently than you expected. For example, you cannot select content conditionally. You can also not select child elements or use cascades. In other words, it's just a one-off, or like you're going straight through the film with your hands. You can reach forward and grab something or not, but you can do nothing.

Speaking of things that make people angry, Andrea Giammarchi has a good point of view on the current situation of Web Components:

Every library that started with, including mine, suggests that we should import the library to define what is called a " portable custom element ".

Google always recommends using LitElement. Microsoft wants you to use FASTElement. Stencil has its own components. hyperHTML has its own components. No one uses only "raw" Web Components. This is very strange! The worst part I think is that Web Components should be a "native platform" thing, which means we shouldn't need to rely on a particular technology to use them. When we do this, we are locked onto it like using React or anything else.

Andrea puts forward some ideas in the article, including using some new and smaller libraries. I think what I want to see is a schema library that doesn't use any library at all.

  1. FAST calls itself a "interface system" in a continuous sentence on the homepage, followed by a "UI framework". Shoelaces calls itself a "library", but I call it a "mode library". I think "design system" is the most commonly used term to describe this concept, but is often more extensive than a particular technology. FAST uses this term in the code itself to denote the wrapper element that controls the subject. I don't think the terminology surrounding all of this stuff is far from certain.

The above is the detailed content of A Bit on Web Component Libraries. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How can I include CSS only on some pages? How can I include CSS only on some pages? Jun 11, 2025 am 12:01 AM

There are three ways to selectively include CSS on a specific page: 1. Inline CSS, suitable for pages that are not frequently accessed or require unique styles; 2. Load external CSS files using JavaScript conditions, suitable for situations where flexibility is required; 3. Containment on the server side, suitable for scenarios using server-side languages. This approach can optimize website performance and maintainability, but requires balance of modularity and performance.

Flexbox vs Grid: Understanding the Key Differences in CSS Layout Flexbox vs Grid: Understanding the Key Differences in CSS Layout Jun 10, 2025 am 12:03 AM

Flexboxisidealforone-dimensionallayouts,whileGridsuitstwo-dimensional,complexlayouts.UseFlexboxforaligningitemsinasingleaxisandGridforprecisecontroloverrowsandcolumnsinintricatedesigns.

Creating an Auto-Closing Notification With an HTML Popover Creating an Auto-Closing Notification With an HTML Popover Jun 10, 2025 am 09:45 AM

The HTML popover attribute transforms elements into top-layer elements that can be opened and closed with a button or JavaScript. Popovers can be dismissed a number of ways, but there is no option to auto-close them. Preethi has a technique you can u

What is 'render-blocking CSS'? What is 'render-blocking CSS'? Jun 24, 2025 am 12:42 AM

CSS blocks page rendering because browsers view inline and external CSS as key resources by default, especially with imported stylesheets, header large amounts of inline CSS, and unoptimized media query styles. 1. Extract critical CSS and embed it into HTML; 2. Delay loading non-critical CSS through JavaScript; 3. Use media attributes to optimize loading such as print styles; 4. Compress and merge CSS to reduce requests. It is recommended to use tools to extract key CSS, combine rel="preload" asynchronous loading, and use media delayed loading reasonably to avoid excessive splitting and complex script control.

How to use Lotties in Figma How to use Lotties in Figma Jun 14, 2025 am 10:17 AM

In the following tutorial, I will show you how to create Lottie animations in Figma. We'll use two colorful designs to exmplify how you can animate in Figma, and then I'll show you how to go from Figma to Lottie animations. All you need is a free Fig

Breaking Boundaries: Building a Tangram Puzzle With (S)CSS Breaking Boundaries: Building a Tangram Puzzle With (S)CSS Jun 13, 2025 am 11:33 AM

We put it to the test and it turns out Sass can replace JavaScript, at least when it comes to low-level logic and puzzle behavior. With nothing but maps, mixins, functions, and a whole lot of math, we managed to bring our Tangram puzzle to life, no J

External vs. Internal CSS: What's the Best Approach? External vs. Internal CSS: What's the Best Approach? Jun 20, 2025 am 12:45 AM

ThebestapproachforCSSdependsontheproject'sspecificneeds.Forlargerprojects,externalCSSisbetterduetomaintainabilityandreusability;forsmallerprojectsorsingle-pageapplications,internalCSSmightbemoresuitable.It'scrucialtobalanceprojectsize,performanceneed

Does my CSS must be on lower case? Does my CSS must be on lower case? Jun 19, 2025 am 12:29 AM

No,CSSdoesnothavetobeinlowercase.However,usinglowercaseisrecommendedfor:1)Consistencyandreadability,2)Avoidingerrorsinrelatedtechnologies,3)Potentialperformancebenefits,and4)Improvedcollaborationwithinteams.

See all articles