1- ember-element-helper
2- ==============================================================================
1+ # ember-element-helper
32
43[ ![ Build Status] ( https://github.com/tildeio/ember-element-helper/actions/workflows/ci.yml/badge.svg )] ( https://github.com/tildeio/ember-element-helper/actions/workflows/ci.yml )
54
@@ -18,15 +17,13 @@ this addon as a true polyfill for the feature, allowing the feature to be used
1817on older Ember.js versions and be completely inert on newer versions where the
1918official implementation is available.
2019
21- Compatibility
22- ------------------------------------------------------------------------------
20+ ## Compatibility
2321
2422* Ember.js v3.24 or above
2523* Ember CLI v3.24 or above
2624* Node.js v12 or above
2725
28- Limitations
29- ------------------------------------------------------------------------------
26+ ## Limitations
3027
3128This implementation has the following known limitations:
3229
@@ -52,15 +49,13 @@ This implementation has the following known limitations:
5249 which is first available on Ember 3.11. This is an Ember.js limitation,
5350 unrelated to this addon.
5451
55- Installation
56- ------------------------------------------------------------------------------
52+ ## Installation
5753
5854```
5955ember install ember-element-helper
6056```
6157
62- Usage
63- ------------------------------------------------------------------------------
58+ ## Usage
6459
6560``` hbs
6661{{#let (element this.tagName) as |Tag|}}
@@ -85,12 +80,93 @@ that accepts "contextual components" as arguments:
8580<@tag class="my-tag">hello world!</@tag>
8681```
8782
88- Contributing
89- ------------------------------------------------------------------------------
83+ ### Single File Components
84+
85+ Using the ` (element) ` helper with [ first class component
86+ templates] ( http://emberjs.github.io/rfcs/0779-first-class-component-templates.html ) :
87+
88+ ``` gjs
89+ import { element } from 'ember-element-helper';
90+
91+ <template>
92+ {{#let (element @tagName) as |Tag|}}
93+ <Tag class="my-tag">hello world!</Tag>
94+ {{/let}}
95+ </template>
96+ ```
97+
98+ ### Glint Usage in Classic Mode
99+
100+ In order to use a typed ` (element) ` helper in classic mode, you need to import
101+ the addon's glint template registry and extend your app's registry declaration
102+ as described in the [ Using
103+ Addons] ( https://typed-ember.gitbook.io/glint/using-glint/ember/using-addons#using-glint-enabled-addons )
104+ documentation:
105+
106+ ``` ts
107+ import ' @glint/environment-ember-loose' ;
108+ import type EmberElementHelperRegistry from ' ember-element-helper/template-registry' ;
109+
110+ declare module ' @glint/environment-ember-loose/registry' {
111+ export default interface Registry extends EmberElementHelperRegistry , /* other addon registries */ {
112+ // local entries
113+ }
114+ }
115+ ```
116+
117+ > ** Note:** Glint itself is still under active development, and as such breaking changes might occur.
118+ > Therefore, Glint support by this addon is also considered experimental, and not covered by our SemVer contract!
119+
120+ ### Typing your Components
121+
122+ When your component accepts an element with the ` (element) ` helper, you want to
123+ give this argument a proper type. Here is how:
124+
125+ ``` ts
126+ import type { ElementSignature } from ' ember-element-helper' ;
127+
128+ interface YourComponentSignature <T extends string > {
129+ Element: HTMLSectionElement ;
130+ Args: {
131+ element? : ElementSignature [' Return' ];
132+ };
133+ }
134+ ```
135+
136+ When the ` @element ` argument influences the ` Element ` of your component:
137+
138+ ``` ts
139+ import type { ElementSignature , ElementFromTagName } from ' ember-element-helper' ;
140+
141+ interface YourComponentSignature <T extends string > {
142+ Element: ElementFromTagName <T >;
143+ Args: {
144+ element? : ElementSignature <T >[' Return' ];
145+ };
146+ }
147+ ```
148+
149+ When your component already uses an element for a given condition. When
150+ the condition isn't met, a fallback element is used. The fallback can even be
151+ provided from the outside. Here is the type:
152+
153+ ``` ts
154+ import type { ElementSignature , ElementFromTagName } from ' ember-element-helper' ;
155+
156+ interface YourComponentSignature <
157+ T extends string = ' section'
158+ > {
159+ Element: HTMLButtonElement | HTMLAnchorElement | ElementFromTagName <T >;
160+ Args: {
161+ element? : ElementSignature <T >[' Return' ];
162+ };
163+ }
164+ ```
165+
166+ ## Contributing
90167
91168See the [ Contributing] ( CONTRIBUTING.md ) guide for details.
92169
93- License
94- ------------------------------------------------------------------------------
170+ ## License
95171
96172This project is licensed under the [ MIT License] ( LICENSE.md ) .
0 commit comments