Skip to content

Commit bd34bc3

Browse files
feat(debug): Add collapse on load & hide toggle button options (#1040)
Co-authored-by: Chris Swithinbank <[email protected]>
1 parent ee230c1 commit bd34bc3

4 files changed

Lines changed: 42 additions & 1 deletion

File tree

docs/documentation/debugging.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ const client = Client({
1919
});
2020
```
2121

22+
### Debug Panel options
23+
24+
You can use the `collapseOnLoad` option to hide the panel by default when the client loads. The `hideToggleButton` option removes the toggle button on the side of the panel which means you can only use the keyboard shortcut to toggle its visibility.
25+
26+
```js
27+
const client = Client({
28+
// ...
29+
debug: {
30+
// ...
31+
collapseOnLoad: true/false,
32+
hideToggleButton: true/false
33+
},
34+
});
35+
```
36+
2237
### Custom metadata in game logs
2338

2439
It can sometimes be helpful to surface some metadata during a move.

src/client/client.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ type Action =
5252
export interface DebugOpt {
5353
target?: HTMLElement;
5454
impl?: typeof Debug;
55+
collapseOnLoad?: boolean;
56+
hideToggleButton?: boolean;
5557
}
5658

5759
/**

src/client/debug/Debug.svelte

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@
3838
visible = !visible;
3939
}
4040
41-
let visible = true;
41+
const debugOpt = $clientManager.client.debugOpt
42+
let visible = !debugOpt || !debugOpt.collapseOnLoad;
43+
const showToggleButton = !debugOpt || !debugOpt.hideToggleButton
44+
4245
function Keypress(e) {
4346
if (e.key == '.') {
4447
ToggleVisibility();
@@ -180,6 +183,7 @@
180183

181184
<section aria-label="boardgame.io Debug Panel" class="debug-panel">
182185
{#if !visible}
186+
{#if showToggleButton}
183187
<button
184188
on:click={ToggleVisibility}
185189
class="visibility-toggle opener"
@@ -191,8 +195,10 @@
191195
<Chevron />
192196
</span>
193197
</button>
198+
{/if}
194199
{:else}
195200
<div transition:fly={{ x: 400, ...transitionOpts }} class="panel">
201+
{#if showToggleButton}
196202
<button
197203
on:click={ToggleVisibility}
198204
class="visibility-toggle closer"
@@ -204,6 +210,7 @@
204210
<Chevron />
205211
</span>
206212
</button>
213+
{/if}
207214
<Menu on:change={MenuChange} {panes} {pane} />
208215
<div
209216
bind:this={paneDiv}

src/client/debug/tests/debug.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,23 @@ test('visibility toggle', async () => {
7070
client.stop();
7171
});
7272

73+
test('panel options', async () => {
74+
const client = Client({
75+
game: {},
76+
debug: { hideToggleButton: true, collapseOnLoad: true },
77+
});
78+
client.start();
79+
80+
const hideButton = screen.queryByTitle('Hide Debug Panel');
81+
expect(hideButton).not.toBeInTheDocument();
82+
83+
expect(
84+
screen.queryByRole('heading', { name: 'Controls' })
85+
).not.toBeInTheDocument();
86+
87+
client.stop();
88+
});
89+
7390
describe('multiple clients', () => {
7491
const client0 = Client({
7592
game: { name: 'game1' },

0 commit comments

Comments
 (0)