File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { html , LitElement } from 'lit'
2+ // copied from solid-ui for now so I can follow same structure as other webcomponets
3+ // i think we need to export this, but want to talk to team
4+ export default abstract class WebComponent extends LitElement {
5+ static states ?: Record < string , Function >
6+
7+ protected internals ?: ElementInternals
8+
9+ protected willUpdate ( changedProperties : Map < string , any > ) {
10+ super . willUpdate ( changedProperties )
11+
12+ const states = this . static ( ) . states
13+
14+ if ( ! states ) {
15+ return
16+ }
17+
18+ const internals = this . getInternals ( )
19+
20+ for ( const [ state , condition ] of Object . entries ( states ) ) {
21+ const matches = condition ( this )
22+
23+ if ( matches && ! internals . states . has ( state ) ) {
24+ internals . states . add ( state )
25+ } else if ( ! matches && internals . states . has ( state ) ) {
26+ internals . states . delete ( state )
27+ }
28+ }
29+ }
30+
31+ protected render ( ) {
32+ return html `< slot > </ slot > `
33+ }
34+
35+ protected getInternals ( ) : ElementInternals {
36+ this . internals ??= this . attachInternals ( )
37+
38+ return this . internals
39+ }
40+
41+ private static ( ) : typeof WebComponent {
42+ return this . constructor as typeof WebComponent
43+ }
44+ }
You can’t perform that action at this time.
0 commit comments