Skip to content

Commit ea63d13

Browse files
committed
added support for @tag argument to support dynamic tag generation
1 parent 944ee95 commit ea63d13

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

packages/components/src/components/hds/layout/flex/index.hbs

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
Copyright (c) HashiCorp, Inc.
33
SPDX-License-Identifier: MPL-2.0
44
}}
5-
{{! ADD YOUR TEMPLATE CONTENT HERE }}
6-
<div class={{this.classNames}} ...attributes>
7-
{{yield}}
8-
</div>
5+
{{#if (eq this.componentTag "div")}}
6+
<div class={{this.classNames}} ...attributes>{{yield}}</div>
7+
{{else}}
8+
{{#let (element this.componentTag) as |Tag|}}<Tag class={{this.classNames}} ...attributes>{{yield}}</Tag>{{/let}}
9+
{{/if}}

packages/components/src/components/hds/layout/flex/index.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,14 @@ export const DIRECTIONS: string[] = Object.values(HdsLayoutFlexDirectionValues);
2222
export const JUSTIFYS: string[] = Object.values(HdsLayoutFlexJustifyValues);
2323
export const ALIGNS: string[] = Object.values(HdsLayoutFlexAlignValues);
2424

25+
// A list of all existing tag names in the HTMLElementTagNameMap interface
26+
type AvailableTagNames = keyof HTMLElementTagNameMap;
27+
// A union of all types in the HTMLElementTagNameMap interface
28+
type AvailableElements = HTMLElementTagNameMap[keyof HTMLElementTagNameMap];
29+
2530
export interface HdsLayoutFlexSignature {
2631
Args: {
32+
tag?: AvailableTagNames;
2733
direction?: HdsLayoutFlexDirections;
2834
justify?: HdsLayoutFlexJustifys;
2935
align?: HdsLayoutFlexAligns;
@@ -33,10 +39,14 @@ export interface HdsLayoutFlexSignature {
3339
Blocks: {
3440
default: [];
3541
};
36-
Element: HTMLDivElement;
42+
Element: AvailableElements;
3743
}
3844

3945
export default class HdsLayoutFlex extends Component<HdsLayoutFlexSignature> {
46+
get componentTag(): AvailableTagNames {
47+
return this.args.tag ?? 'div';
48+
}
49+
4050
get direction(): HdsLayoutFlexDirections {
4151
return this.args.direction ?? DEFAULT_DIRECTION;
4252
}

0 commit comments

Comments
 (0)