Skip to content

Commit 922de45

Browse files
committed
More scaffolding
1 parent 54c4f64 commit 922de45

File tree

3 files changed

+119
-13
lines changed

3 files changed

+119
-13
lines changed

packages/react/src/components/ExpandableSection/ExpandableProperty.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { Children, isValidElement } from "react";
44

55
import { InternalError } from "../../util/internalError.ts";
66
import { ConnectingCell } from "../ConnectingCell.tsx";
7-
import { PropertyContents } from "./components/PropertyContents.tsx";
87
import styles from "./styles.module.css";
98
import type {
109
ExpandablePropertyBreakoutsProps,
@@ -21,7 +20,13 @@ import type {
2120
* and front-matter, children, etc. in the body.
2221
*/
2322
export function ExpandableProperty(props: ExpandablePropertyProps) {
24-
return <PropertyContents {...props} />;
23+
return (
24+
<spk-expandable-property
25+
{...props}
26+
entryId={props.id}
27+
id={props.headingId}
28+
></spk-expandable-property>
29+
);
2530
}
2631

2732
/**

packages/web-components/src/components/expandable/expandableBreakout/component.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,37 +65,38 @@ export class ExpandableBreakout extends SpeakeasyComponent {
6565
public override render() {
6666
let details = html``;
6767
if (this.isOpen) {
68+
const connection = this.hasSlot("properties") ? "connected" : "none";
6869
details = html`${this.hasSlot("description")
6970
? html`<spk-connecting-cell
70-
bottom="${this.hasSlot("properties")}"
71-
top="${this.hasSlot("properties")}"
71+
bottom="${connection}"
72+
top="${connection}"
7273
right="none"
7374
>
7475
<slot name="description"></slot>
7576
</spk-connecting-cell>`
7677
: null}
7778
${this.hasSlot("examples")
7879
? html`<spk-connecting-cell
79-
bottom="${this.hasSlot("properties")}"
80-
top="${this.hasSlot("properties")}"
80+
bottom="${connection}"
81+
top="${connection}"
8182
right="none"
8283
>
8384
<slot name="examples"></slot>
8485
</spk-connecting-cell>`
8586
: null}
8687
${this.hasSlot("defaultValue")
8788
? html`<spk-connecting-cell
88-
bottom="${this.hasSlot("properties")}"
89-
top="${this.hasSlot("properties")}"
89+
bottom="${connection}"
90+
top="${connection}"
9091
right="none"
9192
>
9293
<slot name="defaultValue"></slot>
9394
</spk-connecting-cell>`
9495
: null}
9596
${this.hasSlot("embed")
9697
? html`<spk-connecting-cell
97-
bottom="${this.hasSlot("properties")}"
98-
top="${this.hasSlot("properties")}"
98+
bottom="${connection}"
99+
top="${connection}"
99100
right="connected"
100101
>
101102
<slot name="embed"></slot>

packages/web-components/src/components/expandable/expandableProperty/component.ts

Lines changed: 103 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client";
22

33
import { html } from "lit";
4-
import { customElement, state } from "lit/decorators.js";
4+
import { customElement, property, state } from "lit/decorators.js";
55

66
import type { LitProps } from "../../../types/components.ts";
77
import { eventHandler } from "../../../util/decorators.ts";
@@ -20,20 +20,120 @@ export type ExpandablePropertyProps = LitProps<ExpandableProperty>;
2020
export 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

Comments
 (0)