Articoli correlati a Web Components with Lit: A hands-on guide to building...

Web Components with Lit: A hands-on guide to building web components and design systems - Brossura

Patel, Sandeep

 
9798173988058: Web Components with Lit: A hands-on guide to building web components and design systems

Sinossi

Frameworks come and go. The components you build on the browser's own element model don't have to.

Web Components with Lit teaches the platform first: custom elements, shadow DOM, slots, the upgrade problem, retargeted events, with no framework in sight, because Lit is a thin layer over those primitives and the layer makes more sense once you've felt the bare platform. Then it builds up Lit itself: reactive properties, the update lifecycle, templates and directives, reactive controllers, context, state management, and forms that work inside a native form element.

One project runs through the whole book. Cinder is a small design system, published as cinder-ui. It starts in Chapter 6 as a button that does almost nothing and ends as a versioned, documented, server-renderable npm package with a React wrapper and written guidance for every other framework. Along the way you build an icon, a text field and checkbox that participate in form validation, an accessible dialog, a toast system, and a theming layer driven by design tokens.

The book is written to be read four ways. If you're new to web components, Part I teaches the platform from zero. If you're coming from React, Vue, or Angular, it shows you the parts of the browser your framework hides and where Lit's reactivity diverges from what you know. If you already ship Lit, it starts you at the patterns most Lit codebases get wrong: controllers, context, state, forms, and the delivery material that's hardest to find written down: accessibility, testing, visual regression, localization, server-side rendering, and publishing.

Every example is plain JavaScript. Lit needs no compiler and no build step to start, and the standards-only syntax, static properties, no decorators, is the version that will still run unchanged years from now. Where TypeScript changes the picture, a short callout shows the decorator equivalent, and an appendix collects all of it.

Every runnable listing in the book was actually run, in a real browser or a real terminal, before the text described what it does, including the listings that are meant to fail. Every cross-reference was checked. Every version number was verified against the live source. Where checking the code caught the first draft being wrong, the correction was left in the text.

You'll learn how to:

  • Define custom elements and manage their lifecycle without a framework
  • Use shadow DOM, slots, and CSS encapsulation deliberately
  • Model reactive state with Lit's properties and update lifecycle
  • Write templates, use built-in directives, and build your own
  • Style and theme components with custom properties, parts, and design tokens
  • Extract behavior into reactive controllers and share state with context and stores
  • Build form-associated components that validate inside a native form element
  • Make components accessible: focus management, overlays, ARIA across the shadow boundary
  • Test components, add visual-regression and end-to-end coverage, and wire up CI
  • Localize, server-render and hydrate, and publish a component library to npm
  • Consume the library from React and other frameworks

Who it's for: developers who can write modern JavaScript and have touched the DOM directly at least once. No TypeScript, no build tool, and no prior component-library experience required.

Le informazioni nella sezione "Riassunto" possono far riferimento a edizioni diverse di questo titolo.