Skip to content

Commit a24fd75

Browse files
committed
add angular guidance from architecture review
1 parent 11b9f97 commit a24fd75

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

docs/contributing/code-style/angular.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,52 @@ import { LogService } from "@bitwarden/common/platform/abstractions/log.service"
194194

195195
export 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+
```

0 commit comments

Comments
 (0)