You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit daffa2c
Browse filesBrowse the repository at this point in the historyBrowse files
@@ -64,6 +64,8 @@ Elements should provide reasonable defaults for better developer experience for
64
64
65
65
The alert can internally provide the default icon style for the status in the system. But as above with the button, the alert element runs the risk of absorbing parts of the icon API. To mitigate this, use a documented named slot as the customization hook.
Slots can provide default content if the consumer supplies no content. Here the template sets an internal icon with a status icon that matches the status of the alert. If the consumer wants to customize the icon, they can project their own icon into the `icon` slot and override the default. This makes `icon` an explicit public slot API, while avoiding a series of icon-specific inherited attributes or properties on the alert.
84
88
85
89
## Semantic Obfuscation - anti-pattern
86
90
87
91
When building composition based APIs the developer should push the semantics of the HTML up into the light DOM or the control of the consumer. In this example the card element embeds the h1 heading. This creates an incorrect DOM structure as only one given h1 can exist within the page. This also applies as the page structure should work down from h1-h6.
While composition based APIs may be more verbose at times, they lower the API surface area to learn in the system and help ensure there is a singular way to use the element. Once a consumer learns an element API, that API usage remains predictable and reliable throughout the system.
128
136
129
137
Consumer apps/plugins can add opinionated abstractions. This can provide a more opinionated terse API in which consumers can always “escape” or access the elements of the base library as needed. It's easier to add abstraction layers, it's much more difficult to pull apart the wrong base abstraction.
Copy file name to clipboardExpand all lines: projects/site/src/docs/api-design/packaging.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -45,7 +45,7 @@ Build outputs should target the latest ES2020+. Build outputs should not compile
45
45
46
46
<nve-alertstatus="warning">Warning: avoid alternate build targets as it increases complexity and is unnecessary with modern build tools and browsers.</nve-alert>
47
47
48
-
<nve-alert><nve-iconslot="icon">🎓</nve-icon> Learn: <ahref="https://justinfagnani.com/2019/11/01/how-to-publish-web-components-to-npm/">publishing Web Components</a></nve-alert>
48
+
<nve-alert><nve-iconslot="icon"name="academic-cap"></nve-icon> Learn: <ahref="https://justinfagnani.com/2019/11/01/how-to-publish-web-components-to-npm/">publishing Web Components</a></nve-alert>
49
49
50
50
## Entrypoints
51
51
@@ -95,8 +95,8 @@ The `package.json` should use a `sideEffects` array that lists registration and
95
95
96
96
This enables tools like Webpack and Rollup to preserve explicit registration entrypoints while still tree-shaking side-effect-free component modules.
97
97
98
-
<nve-alert><nve-iconslot="icon">🎓</nve-icon> Learn about <ahref="/docs/integrations/lit-library/">Lit Library integration</a></nve-alert>
98
+
<nve-alert><nve-iconslot="icon"name="academic-cap"></nve-icon> Learn about <ahref="/docs/integrations/lit-library/">Lit Library integration</a></nve-alert>
99
99
100
-
<nve-alert><nve-iconslot="icon">🎓</nve-icon> Learn: <ahref="https://github.com/webcomponents/polyfills/tree/master/packages/scoped-custom-element-registry">scoped element registry</a></nve-alert>
100
+
<nve-alert><nve-iconslot="icon"name="academic-cap"></nve-icon> Learn: <ahref="https://github.com/webcomponents/polyfills/tree/master/packages/scoped-custom-element-registry">scoped element registry</a></nve-alert>
<pnve-text="body">Learn: by default when you set a property, Lit does not update the corresponding attribute in the DOM for performance. If the attribute serves as a style hook example, <codenve-text="code">:host([disabled])</code> then you can add the <codenve-text="code">reflect</code> option to the property decorator.</p>
<nve-alert><nve-iconslot="icon">🎓</nve-icon> Learn: <ahref="https://kentcdodds.com/blog/make-impossible-states-impossible"nve-text="link">make impossible states impossible</a></nve-alert>
59
+
<nve-alert><nve-iconslot="icon"name="academic-cap"></nve-icon> Learn: <ahref="https://kentcdodds.com/blog/make-impossible-states-impossible"nve-text="link">make impossible states impossible</a></nve-alert>
60
60
61
61
## Boolean Types
62
62
@@ -81,20 +81,20 @@ Boolean property/attribute type behave the same as native HTML element boolean t
81
81
While Lit keeps both properties and attributes in sync, do not use complex types like `object` and `array` on the API. Since HTML cannot represent JavaScript objects, Lit must JSON parse attributes and reflect them anytime there is a change to ensure the JavaScript property and HTML attribute are in sync. This can be expensive to parse when using an object or array and cause unexpected behaviors such as lost object references for the user.
82
82
83
83
<nve-alertstatus="success">
84
-
Use <code>string | number | boolean</code>
84
+
Use <codenve-text="code">string | number | boolean</code>
85
85
</nve-alert>
86
86
87
87
<nve-alertstatus="danger">
88
-
Avoid <code>object | array</code>
88
+
Avoid <codenve-text="code">object | array</code>
89
89
</nve-alert>
90
90
91
91
Complex types cause compatibility and usability issues as it can require the developer to use JavaScript to render content. This can make it difficult for user-generated content like CMS systems or SSR (Server Side Rendering) to easily render static HTML.
92
92
93
93
<nve-alertstatus="warning">
94
-
Warning: avoid using <code>@property</code> on built in properties/attributes on the <code>HTMLElement</code> as the decorator overrides the getter/setter and can cause unexpected behavior. <ahref="https://github.com/vmware-clarity/core/blob/main/projects/core/build/eslint-rules/reserved-property-names.js"nve-text="link">read more</a>
94
+
Warning: avoid using <codenve-text="code">@property</code> on built in properties/attributes on the <codenve-text="code">HTMLElement</code> as the decorator overrides the getter/setter and can cause unexpected behavior. <ahref="https://github.com/vmware-clarity/core/blob/main/projects/core/build/eslint-rules/reserved-property-names.js"nve-text="link">read more</a>
Learn about <ahref="https://developers.google.com/web/fundamentals/web-components/best-practices#attributes-properties"nve-text="link">Web Fundamentals Attributes vs Properties</a>.
Warning: only use <code>DataElement</code> for data structures that have no reasonable declarative HTML representation. If primitive attributes, slots, or child elements can represent the content, prefer those approaches.
150
+
Warning: only use <code nve-text="code">DataElement</code> for data structures that have no reasonable declarative HTML representation. If primitive attributes, slots, or child elements can represent the content, prefer those approaches.
Copy file name to clipboardExpand all lines: projects/site/src/docs/api-design/registration.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,6 +31,6 @@ Tag names should avoid using verbs or actions within the name. The properties an
31
31
32
32
{% enddodont %}
33
33
34
-
<nve-alert><nve-iconslot="icon">🎓</nve-icon> Learn: elements should follow common and established names for existing UI patterns. See <ahref="https://open-ui.org"nve-text="link">openui.org</a> for more details on upcoming specs.</nve-alert>
34
+
<nve-alert><nve-iconslot="icon"name="academic-cap"></nve-icon> Learn: elements should follow common and established names for existing UI patterns. See <ahref="https://open-ui.org"nve-text="link">openui.org</a> for more details on upcoming specs.</nve-alert>
35
35
36
-
<nve-alert><nve-iconslot="icon">🎓</nve-icon> Learn: learn common component names from the Open UI <ahref="https://open-ui.org/research/component-matrix"nve-text="link">component name matrix</a>.</nve-alert>
36
+
<nve-alert><nve-iconslot="icon"name="academic-cap"></nve-icon> Learn: learn common component names from the Open UI <ahref="https://open-ui.org/research/component-matrix"nve-text="link">component name matrix</a>.</nve-alert>
0 commit comments