Skip to content

Commit 93e4d9a

Browse files
authored
DT-2971-change-codeblock-expand-to-maximize (#2771)
* add maximizable component * add maximizable to code-block component * add formatJSON utility * convert code-block to svelte5 and refactor * tweak code-block stories * escape to close * code tweaks from PR * match existing types for copyable prop * fix accessibility error: scroller must be focusable * handle tabbing away from maximized code block * increase z-index of maximized element * update codeblock to use onChange callback instead of raising change event * update payload-input to use codeblock onChange callback * export prop types for storybook * rename onChange to onchange and pass string instead of event * make maximized bindable * use svelte:window instead of addEventListener * remove or extract ternaries * clean up maximize button * tune types for CodeBlock * improve formatJson, fix bug rerturning undefined * make reactive, allow controlled use * apply to stories * tidy
1 parent 91f471f commit 93e4d9a

10 files changed

Lines changed: 459 additions & 262 deletions

File tree

src/lib/components/payload-input.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
}
2929
};
3030
31-
const handleInputChange = (event: CustomEvent<string>): void => {
32-
input = event.detail;
31+
const handleInputChange = (text: string): void => {
32+
input = text;
3333
};
3434
3535
const clearValues = () => {
@@ -52,7 +52,7 @@
5252
{id}
5353
maxHeight={320}
5454
content={input}
55-
on:change={handleInputChange}
55+
onchange={handleInputChange}
5656
editable={editing}
5757
copyable={false}
5858
/>

src/lib/holocene/code-block.stories.svelte

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script lang="ts" context="module">
22
import type { Meta } from '@storybook/svelte';
33
4+
import type { Props } from '$lib/holocene/code-block.svelte';
45
import CodeBlock from '$lib/holocene/code-block.svelte';
56
67
export const meta = {
@@ -51,30 +52,35 @@
5152
table: { category: 'Copy Icon' },
5253
},
5354
},
54-
} satisfies Meta<CodeBlock>;
55+
} satisfies Meta<Props>;
5556
</script>
5657

5758
<script lang="ts">
5859
import { action } from '@storybook/addon-actions';
5960
import { Story, Template } from '@storybook/addon-svelte-csf';
6061
6162
import { stringifyWithBigInt } from '$lib/utilities/parse-with-big-int';
62-
</script>
6363
64-
<Template id="json" let:args>
65-
<CodeBlock language="json" {...args} on:change={action('change')} />
66-
</Template>
64+
let editableContent = $state(
65+
stringifyWithBigInt({ hello: 'world' }, null, 2),
66+
);
6767
68-
<Template id="shell" let:args>
69-
<CodeBlock language="shell" {...args} on:change={action('change')} />
70-
</Template>
68+
const handleEditableChange = (text: string) => {
69+
editableContent = text;
70+
action('change')(text);
71+
};
72+
</script>
7173

72-
<Template id="text" let:args>
73-
<CodeBlock language="text" {...args} on:change={action('change')} />
74+
<Template let:args>
75+
<CodeBlock {...args} onchange={action('change')} />
7476
</Template>
7577

76-
<Template let:args>
77-
<CodeBlock {...args} />
78+
<Template id="editable" let:args>
79+
<CodeBlock
80+
{...args}
81+
content={editableContent}
82+
onchange={handleEditableChange}
83+
/>
7884
</Template>
7985

8086
<Story
@@ -86,9 +92,9 @@
8692

8793
<Story
8894
name="Editable"
95+
template="editable"
8996
args={{
9097
editable: true,
91-
content: stringifyWithBigInt({ hello: 'world' }, null, 2),
9298
}}
9399
/>
94100

@@ -131,18 +137,25 @@
131137
/>
132138

133139
<Story
134-
name="Shell"
140+
name="Copyable (Maximum Height)"
135141
args={{
136-
language: 'shell',
137-
content: 'echo "Hello, World!"',
142+
maxHeight: 100,
143+
content: stringifyWithBigInt(
144+
Object.getOwnPropertyDescriptors(Array.prototype),
145+
null,
146+
2,
147+
),
148+
copyable: true,
149+
copyIconTitle: 'Click to copy content',
150+
copySuccessIconTitle: 'Content copied to clipboard',
138151
}}
139152
/>
140153

141154
<Story
142-
name="Text"
155+
name="Shell"
143156
args={{
144-
language: 'text',
145-
content: 'Hello, World!',
157+
language: 'shell',
158+
content: 'echo "Hello, World!"',
146159
}}
147160
/>
148161

@@ -157,6 +170,14 @@
157170
}}
158171
/>
159172

173+
<Story
174+
name="Text"
175+
args={{
176+
language: 'text',
177+
content: 'Hello, World!',
178+
}}
179+
/>
180+
160181
<Story
161182
name="Copyable (Text)"
162183
args={{

0 commit comments

Comments
 (0)