Skip to content

Commit 93b9ccb

Browse files
authored
fix: Fix line numbers misalignment with single-line content when actions are provided (#43)
1 parent d4475dc commit 93b9ccb

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

pages/code-view/with-line-numbers.page.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
import { SpaceBetween } from "@cloudscape-design/components";
4+
import { Button, SpaceBetween } from "@cloudscape-design/components";
55

66
import { CodeView } from "../../lib/components";
77
import { ScreenshotArea } from "../screenshot-area";
@@ -12,6 +12,11 @@ export default function CodeViewPage() {
1212
<SpaceBetween direction="vertical" size="l">
1313
<CodeView lineNumbers={true} content={`# Hello World`} />
1414
<CodeView lineNumbers={true} content={`# Hello World\n\nThis is Cloudscape.`} />
15+
<CodeView
16+
lineNumbers={true}
17+
content={`# Hello World`}
18+
actions={<Button ariaLabel="Copy code" iconName="copy"></Button>}
19+
/>
1520
</SpaceBetween>
1621
</ScreenshotArea>
1722
);

src/code-view/internal.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ export function InternalCodeView({
4949
<div className={clsx(lineNumbers && styles["root-with-numbers"], actions && styles["root-with-actions"])}>
5050
<Box color="text-status-inactive" fontSize="body-m">
5151
{lineNumbers && (
52-
<div className={styles["line-numbers"]} aria-hidden={true}>
52+
<div
53+
className={clsx(styles["line-numbers"], actions && styles["line-numbers-with-actions"])}
54+
aria-hidden={true}
55+
>
5356
{getLineNumbers(content).map((number) => (
5457
<span key={number}>{number}</span>
5558
))}

src/code-view/styles.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ $color-background-code-view-dark: #282c34;
4949
:global(.awsui-polaris-dark-mode) & {
5050
background-color: $color-background-code-view-dark;
5151
}
52+
&-with-actions {
53+
min-block-size: cs.$space-scaled-xxl;
54+
}
5255
border-start-start-radius: cs.$border-radius-tiles;
5356
border-end-start-radius: cs.$border-radius-tiles;
5457
background-color: $color-background-code-view-light;

0 commit comments

Comments
 (0)