Skip to content

Commit 6741164

Browse files
Ruben Carvalhogethinwebster
authored andcommitted
chore: Fix minimum-height and actions absolute positioning
1 parent 529aeb4 commit 6741164

File tree

3 files changed

+58
-33
lines changed

3 files changed

+58
-33
lines changed

pages/code-view/with-actions-button.page.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ export default function CodeViewPage() {
1414
actions={<Button ariaLabel="Copy code" iconName="copy"></Button>}
1515
content={`Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.`}
1616
/>
17+
<CodeView
18+
lineNumbers={true}
19+
lineWrapping={true}
20+
actions={<Button ariaLabel="Copy code" iconName="copy"></Button>}
21+
content={`Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.`}
22+
/>
1723
</SpaceBetween>
1824
</ScreenshotArea>
1925
);

src/code-view/internal.tsx

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -58,39 +58,47 @@ export function InternalCodeView({
5858
aria-labelledby={ariaLabelledby}
5959
ref={__internalRootRef}
6060
>
61-
<table className={clsx(styles["code-table"])}>
62-
<colgroup>
63-
<col style={{ width: 1 } /* shrink to fit content */} />
64-
<col style={{ width: "auto" }} />
65-
</colgroup>
66-
<tbody>
67-
{Children.map(code.props.children, (child, index) => {
68-
return (
69-
<tr key={index}>
70-
{lineNumbers && (
71-
<td className={clsx(styles["line-number"], styles.unselectable)} aria-hidden={true}>
72-
<Box color="text-status-inactive" fontSize="body-m">
73-
{index + 1}
61+
<div className={styles["scroll-container"]}>
62+
<table
63+
className={clsx(
64+
styles["code-table"],
65+
actions && styles["code-table-with-actions"],
66+
lineWrapping && styles["code-table-with-line-wrapping"]
67+
)}
68+
>
69+
<colgroup>
70+
<col style={{ width: 1 } /* shrink to fit content */} />
71+
<col style={{ width: "auto" }} />
72+
</colgroup>
73+
<tbody>
74+
{Children.map(code.props.children, (child, index) => {
75+
return (
76+
<tr key={index}>
77+
{lineNumbers && (
78+
<td className={clsx(styles["line-number"], styles.unselectable)} aria-hidden={true}>
79+
<Box color="text-status-inactive" fontSize="body-m">
80+
{index + 1}
81+
</Box>
82+
</td>
83+
)}
84+
<td className={styles["code-line"]}>
85+
<Box color="text-status-inactive" variant="code" fontSize="body-m">
86+
<span
87+
className={clsx(
88+
code.props.className,
89+
lineWrapping ? styles["code-line-wrap"] : styles["code-line-nowrap"]
90+
)}
91+
>
92+
{child}
93+
</span>
7494
</Box>
7595
</td>
76-
)}
77-
<td className={styles["code-line"]}>
78-
<Box color="text-status-inactive" variant="code" fontSize="body-m">
79-
<span
80-
className={clsx(
81-
code.props.className,
82-
lineWrapping ? styles["code-line-wrap"] : styles["code-line-nowrap"]
83-
)}
84-
>
85-
{child}
86-
</span>
87-
</Box>
88-
</td>
89-
</tr>
90-
);
91-
})}
92-
</tbody>
93-
</table>
96+
</tr>
97+
);
98+
})}
99+
</tbody>
100+
</table>
101+
</div>
94102
{actions && <div className={styles.actions}>{actions}</div>}
95103
</div>
96104
);

src/code-view/styles.scss

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ $color-background-code-view-dark: #282c34;
1010
background-color: $color-background-code-view-dark;
1111
}
1212
background-color: $color-background-code-view-light;
13+
}
14+
15+
.scroll-container {
1316
overflow-x: auto;
1417
}
1518

@@ -23,6 +26,14 @@ $color-background-code-view-dark: #282c34;
2326
table-layout: auto;
2427
width: 100%;
2528
border-spacing: 0;
29+
30+
&-with-actions {
31+
min-height: calc(2 * cs.$space-scaled-xs + cs.$space-scaled-xxl);
32+
}
33+
}
34+
35+
.code-table-with-actions.code-table-with-line-wrapping {
36+
padding-inline-end: cs.$space-static-xxl;
2637
}
2738

2839
.line-number {
@@ -59,7 +70,7 @@ $color-background-code-view-dark: #282c34;
5970

6071
.actions {
6172
position: absolute;
62-
inset-block-start: cs.$space-static-xs;
63-
inset-inline-end: cs.$space-static-xs;
73+
inset-block-start: cs.$space-scaled-xs;
74+
inset-inline-end: cs.$space-scaled-xs;
6475
padding-inline-start: cs.$space-container-horizontal;
6576
}

0 commit comments

Comments
 (0)