Skip to content

Commit 72c479b

Browse files
committed
fix(Snippet): indentation not working (#5534)
1 parent a016245 commit 72c479b

File tree

5 files changed

+53
-1
lines changed

5 files changed

+53
-1
lines changed

.changeset/sour-ways-scream.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@ultraviolet/ui": patch
3+
---
4+
5+
Fix `<Snippet />` to preserve indentation
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Template } from './Template.stories'
2+
3+
export const Indented = Template.bind({})
4+
5+
Indented.args = {
6+
children: `{
7+
"name": "John Doe",
8+
"age": 30,
9+
"email": "[email protected]",
10+
"isActive": true,
11+
"roles": ["admin", "user"],
12+
"address": {
13+
"street": "123 Main St",
14+
"city": "Metropolis",
15+
"zip": "12345"
16+
}
17+
}`,
18+
}
19+
20+
Indented.parameters = {
21+
docs: {
22+
description: {
23+
story:
24+
'If you add indentation to the code snippet, it will be preserved.',
25+
},
26+
},
27+
}

packages/ui/src/components/Snippet/__stories__/index.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ export { LongMultilineExpanded } from './LongMultilineExpanded.stories'
2323
export { Prefixes } from './Prefixes.stories'
2424
export { Rows } from './Rows.stories'
2525
export { NoExpandable } from './NoExpandable.stories'
26+
export { Indented } from './Indented.stories'

packages/ui/src/components/Snippet/__tests__/__snapshots__/index.test.tsx.snap

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ exports[`snippet > renders correctly 1`] = `
3333
3434
.emotion-6 {
3535
display: block;
36+
white-space: pre;
3637
}
3738
3839
.emotion-6:not([data-multiline]):after {
@@ -156,6 +157,7 @@ exports[`snippet > renders correctly in multiline 1`] = `
156157
157158
.emotion-8 {
158159
display: block;
160+
white-space: pre;
159161
}
160162
161163
.emotion-8:not([data-multiline]):after {
@@ -382,6 +384,7 @@ exports[`snippet > renders correctly in multiline with prefix command 1`] = `
382384
383385
.emotion-8 {
384386
display: block;
387+
white-space: pre;
385388
}
386389
387390
.emotion-8:not([data-multiline]):after {
@@ -623,6 +626,7 @@ exports[`snippet > renders correctly in multiline with prefix lines number 1`] =
623626
624627
.emotion-8 {
625628
display: block;
629+
white-space: pre;
626630
}
627631
628632
.emotion-8:not([data-multiline]):after {
@@ -855,6 +859,7 @@ exports[`snippet > renders correctly with copiedText 1`] = `
855859
856860
.emotion-6 {
857861
display: block;
862+
white-space: pre;
858863
}
859864
860865
.emotion-6:not([data-multiline]):after {
@@ -968,6 +973,7 @@ exports[`snippet > renders correctly with copyText 1`] = `
968973
969974
.emotion-6 {
970975
display: block;
976+
white-space: pre;
971977
}
972978
973979
.emotion-6:not([data-multiline]):after {
@@ -1112,6 +1118,7 @@ exports[`snippet > renders correctly with custom number of rows 1`] = `
11121118
11131119
.emotion-6 {
11141120
display: block;
1121+
white-space: pre;
11151122
}
11161123
11171124
.emotion-6:not([data-multiline]):after {
@@ -1126,6 +1133,7 @@ exports[`snippet > renders correctly with custom number of rows 1`] = `
11261133
11271134
.emotion-6 {
11281135
display: block;
1136+
white-space: pre;
11291137
}
11301138
11311139
.emotion-6:not([data-multiline]):after {
@@ -1292,6 +1300,7 @@ exports[`snippet > renders correctly with hideText 1`] = `
12921300
12931301
.emotion-8 {
12941302
display: block;
1303+
white-space: pre;
12951304
}
12961305
12971306
.emotion-8:not([data-multiline]):after {
@@ -1557,6 +1566,7 @@ exports[`snippet > renders correctly with initiallyExpanded 1`] = `
15571566
15581567
.emotion-8 {
15591568
display: block;
1569+
white-space: pre;
15601570
}
15611571
15621572
.emotion-8:not([data-multiline]):after {
@@ -1571,6 +1581,7 @@ exports[`snippet > renders correctly with initiallyExpanded 1`] = `
15711581
15721582
.emotion-8 {
15731583
display: block;
1584+
white-space: pre;
15741585
}
15751586
15761587
.emotion-8:not([data-multiline]):after {
@@ -1842,6 +1853,7 @@ exports[`snippet > renders correctly with noExpandable 1`] = `
18421853
18431854
.emotion-6 {
18441855
display: block;
1856+
white-space: pre;
18451857
}
18461858
18471859
.emotion-6:not([data-multiline]):after {
@@ -1856,6 +1868,7 @@ exports[`snippet > renders correctly with noExpandable 1`] = `
18561868
18571869
.emotion-6 {
18581870
display: block;
1871+
white-space: pre;
18591872
}
18601873
18611874
.emotion-6:not([data-multiline]):after {
@@ -2061,6 +2074,7 @@ exports[`snippet > renders correctly with showText 1`] = `
20612074
20622075
.emotion-8 {
20632076
display: block;
2077+
white-space: pre;
20642078
}
20652079
20662080
.emotion-8:not([data-multiline]):after {
@@ -2075,6 +2089,7 @@ exports[`snippet > renders correctly with showText 1`] = `
20752089
20762090
.emotion-8 {
20772091
display: block;
2092+
white-space: pre;
20782093
}
20792094
20802095
.emotion-8:not([data-multiline]):after {
@@ -2340,6 +2355,7 @@ exports[`snippet > renders correctly with single line with prefix command 1`] =
23402355
23412356
.emotion-6 {
23422357
display: block;
2358+
white-space: pre;
23432359
}
23442360
23452361
.emotion-6:not([data-multiline]):after {
@@ -2468,6 +2484,7 @@ exports[`snippet > renders correctly with single line with prefix lines number 1
24682484
24692485
.emotion-6 {
24702486
display: block;
2487+
white-space: pre;
24712488
}
24722489
24732490
.emotion-6:not([data-multiline]):after {
@@ -2646,6 +2663,7 @@ exports[`snippet > should click on extend button to display full content on 1`]
26462663
26472664
.emotion-8 {
26482665
display: block;
2666+
white-space: pre;
26492667
}
26502668
26512669
.emotion-8:not([data-multiline]):after {
@@ -2660,6 +2678,7 @@ exports[`snippet > should click on extend button to display full content on 1`]
26602678
26612679
.emotion-8 {
26622680
display: block;
2681+
white-space: pre;
26632682
}
26642683
26652684
.emotion-8:not([data-multiline]):after {

packages/ui/src/components/Snippet/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const StyledSpan = styled('span', {
4646
!['linePrefix', 'multiline', 'prefix'].includes(prop),
4747
})<{ linePrefix?: string; multiline?: boolean; prefix?: Prefixes }>`
4848
display: block;
49-
49+
white-space: pre;
5050
5151
&:not([data-multiline]):after {
5252
content: "";

0 commit comments

Comments
 (0)