File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed
docs/contributing/code-style Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -194,3 +194,52 @@ import { LogService } from "@bitwarden/common/platform/abstractions/log.service"
194194
195195export class DifferentPackageService {}
196196```
197+
198+ ### String-backed Enum-likes ([ ADR-0025] ( ../../architecture/adr/0025-ts-deprecate-enums.md ) )
199+
200+ String-typed enum likes can be used as inputs of a component directly. Simply expose the enum-like
201+ property from your component:
202+
203+ ``` ts
204+ // given:
205+ const EnumLike = { Some = " some" , Value: " value" };
206+ type EnumLike = EnumLike [keyof typeof EnumLike ];
207+
208+ // add the input:
209+ @Component ({ ... })
210+ class YourComponent {
211+ @Input () input: EnumLike = EnumLike .Some ;
212+
213+ // ...
214+ }
215+ ```
216+
217+ Composers can use the enum's string values directly:
218+
219+ ``` html
220+ <my-component input =" value" />
221+ ```
222+
223+ ### Numeric Enum-likes ([ ADR-0025] ( ../../architecture/adr/0025-ts-deprecate-enums.md ) )
224+
225+ Using numeric enum-likes in components should be avoided. If it is necessary, follow the same
226+ pattern as a string-backed enum.
227+
228+ Composers that need hard-coded enum-likes in their template should expose the data from their
229+ component:
230+
231+ ``` ts
232+ import { EnumLike } from " ..." ;
233+
234+ // add the input to your component:
235+ @Component ({ ... })
236+ class TheirComponent {
237+ protected readonly EnumLike = EnumLike ;
238+ }
239+ ```
240+
241+ And then bind the input in the template:
242+
243+ ``` ts
244+ < my - component [input ]= ' EnumLike.Value' / >
245+ ```
You can’t perform that action at this time.
0 commit comments