11"use client" ;
22
33import { html } from "lit" ;
4- import { customElement , state } from "lit/decorators.js" ;
4+ import { customElement , property , state } from "lit/decorators.js" ;
55
66import type { LitProps } from "../../../types/components.ts" ;
77import { eventHandler } from "../../../util/decorators.ts" ;
@@ -20,20 +20,120 @@ export type ExpandablePropertyProps = LitProps<ExpandableProperty>;
2020export class ExpandableProperty extends SpeakeasyComponent {
2121 static override styles = litStyles ;
2222
23+ /**
24+ * The identifier for the row. This id is unique within the tree, but is _not_
25+ * unique in the DOM, and is not used to set the `id` attribute on the DOM
26+ * element.
27+ */
28+ @property ( { type : String } )
29+ public entryId ! : string ;
30+
31+ /**
32+ * The parent entryId for the row (not the parent's DOM ID)
33+ */
34+ @property ( { type : String } )
35+ public parentId ?: string ;
36+
37+ /**
38+ * Whether the row has expandable content or not. This is used to know whether
39+ * or not to render an expandable header cell in the event when there are no
40+ * children. In the case of no children, we do render an expandable header
41+ * cell if the row has expandable content, otherwise we do not.
42+ */
43+ @property ( { type : Boolean } )
44+ public hasExpandableContent ! : boolean ;
45+
46+ /**
47+ * Whether the row should be expanded by default or not on page load, if it
48+ * has children and/or front matter.
49+ */
50+ @property ( { type : Boolean } )
51+ public expandByDefault ! : boolean ;
52+
2353 @state ( )
2454 private isOpen = false ;
2555 #setIsOpen = eventHandler ( "spk-toggle" , ( ) => ( this . isOpen = ! this . isOpen ) ) ;
2656
2757 override connectedCallback ( ) {
2858 super . connectedCallback ( ) ;
59+ this . isOpen = ! ! this . expandByDefault ;
2960 hashManager ( this . id , ( open : boolean ) => {
3061 this . isOpen = open ;
3162 } ) ;
3263 }
3364
3465 public override render ( ) {
35- return html `< div class ="property ">
36- < div class ="propertyDot "> </ div >
66+ // TODO:
67+ const measureContainer = null ;
68+
69+ const frontmatterConnection = this . hasSlot ( "properties" )
70+ ? "connected"
71+ : "none" ;
72+ const frontmatter = html `
73+ ${ this . hasSlot ( "description" )
74+ ? html `
75+ < spk-connecting-cell
76+ bottom ="${ frontmatterConnection } "
77+ top ="${ frontmatterConnection } "
78+ right ="none "
79+ >
80+ < slot name ="description "> </ slot >
81+ </ spk-connecting-cell >
82+ `
83+ : null }
84+ ${ this . hasSlot ( "examples" )
85+ ? html `
86+ < spk-connecting-cell
87+ bottom ="${ frontmatterConnection } "
88+ top ="${ frontmatterConnection } "
89+ right ="none "
90+ >
91+ < slot name ="examples "> </ slot >
92+ </ spk-connecting-cell >
93+ `
94+ : null }
95+ ${ this . hasSlot ( "default-value" )
96+ ? html `
97+ < spk-connecting-cell
98+ bottom ="${ frontmatterConnection } "
99+ top ="${ frontmatterConnection } "
100+ right ="none "
101+ >
102+ < slot name ="default-value "> </ slot >
103+ </ spk-connecting-cell >
104+ `
105+ : null }
106+ ${ this . hasSlot ( "embed" )
107+ ? html `
108+ < spk-connecting-cell
109+ bottom ="${ frontmatterConnection } "
110+ top ="${ frontmatterConnection } "
111+ right ="connected "
112+ >
113+ < slot name ="embed "> </ slot >
114+ </ spk-connecting-cell >
115+ `
116+ : null }
117+ ${ this . hasSlot ( "breakouts" )
118+ ? html ` < slot name ="breakouts "> </ slot > `
119+ : null }
120+ ` ;
121+
122+ // TODO:
123+ const propertyCell = frontmatter ;
124+
125+ return html `< div data-testid =${ this . id } class ="entryContainer">
126+ < div class ="entryHeaderContainer ">
127+ ${ this . hasExpandableContent
128+ ? html `< spk-expandable-cell
129+ .isOpen ="${ this . isOpen } "
130+ @spk-toggle ="${ this . #setIsOpen} "
131+ variant ="property "
132+ > </ spk-expandable-cell > `
133+ : html `< spk-non-expandable-cell > </ spk-non-expandable-cell > ` }
134+ < slot name ="title "> </ slot >
135+ </ div >
136+ ${ this . isOpen ? propertyCell : null } ${ measureContainer }
37137 </ div > ` ;
38138 }
39139}
0 commit comments