Skip to content

Commit fdebd0b

Browse files
authored
fix: Fixes borders, dark mode highlight, and actions padding style issues (#57)
* fix: Fixes borders, dark mode highlight, and actions padding style issues * removes debugging code * re-add background color to line numbers
1 parent f3e1063 commit fdebd0b

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

pages/code-view/simple.page.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
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";
5+
46
import { CodeView } from "../../lib/components";
57
import { ScreenshotArea } from "../screenshot-area";
8+
69
export default function CodeViewPage() {
710
return (
811
<ScreenshotArea>
912
<h1>Code View</h1>
10-
<CodeView content={"Hello World"} />
11-
<CodeView
12-
content={`public class HelloWorld {\n public static void main(String[] args) {\n System.out.println("Hello, World!");\n }\n}`}
13-
/>
13+
<SpaceBetween size="s">
14+
<CodeView content={"Hello World"} />
15+
<CodeView
16+
content={`public class HelloWorld {\n public static void main(String[] args) {\n System.out.println("Hello, World!");\n }\n}`}
17+
/>
18+
</SpaceBetween>
1419
</ScreenshotArea>
1520
);
1621
}

src/code-view/internal.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ export function InternalCodeView({
4343
...props
4444
}: InternalCodeViewProps) {
4545
const baseProps = getBaseProps(props);
46-
const preRef = useRef<HTMLPreElement>(null);
47-
const darkMode = useCurrentMode(preRef) === "dark";
46+
const containerRef = useRef<HTMLDivElement>(null);
47+
const darkMode = useCurrentMode(containerRef) === "dark";
4848

4949
const regionProps = ariaLabel || ariaLabelledby ? { role: "region" } : {};
5050

@@ -64,7 +64,7 @@ export function InternalCodeView({
6464
dir="ltr"
6565
ref={__internalRootRef}
6666
>
67-
<div className={styles["scroll-container"]}>
67+
<div className={styles["scroll-container"]} ref={containerRef}>
6868
<table
6969
role="presentation"
7070
className={clsx(

src/code-view/styles.scss

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ $color-background-code-view-dark: #282c34;
1010

1111
.root {
1212
position: relative;
13+
border-start-start-radius: cs.$border-radius-tiles;
14+
border-start-end-radius: cs.$border-radius-tiles;
15+
border-end-start-radius: cs.$border-radius-tiles;
16+
border-end-end-radius: cs.$border-radius-tiles;
17+
1318
background-color: $color-background-code-view-light;
1419
:global(.awsui-dark-mode) &,
1520
:global(.awsui-polaris-dark-mode) & {
@@ -22,18 +27,15 @@ $color-background-code-view-dark: #282c34;
2227
}
2328

2429
.code-table {
25-
border-start-start-radius: cs.$border-radius-tiles;
26-
border-start-end-radius: cs.$border-radius-tiles;
27-
border-end-start-radius: cs.$border-radius-tiles;
28-
border-end-end-radius: cs.$border-radius-tiles;
2930
padding-block-start: cs.$space-static-xs;
3031
padding-block-end: cs.$space-static-xs;
3132
table-layout: auto;
32-
width: 100%;
33+
inline-size: 100%;
3334
border-spacing: 0;
3435

3536
&-with-actions {
36-
min-height: calc(2 * cs.$space-scaled-xs + cs.$space-scaled-xxl);
37+
min-block-size: calc(2 * cs.$space-scaled-xs + cs.$space-scaled-xxl);
38+
padding-inline-end: calc(2 * var(--space-static-xxxl-qj5g91, 40px));
3739
}
3840
}
3941

@@ -42,15 +44,16 @@ $color-background-code-view-dark: #282c34;
4244
}
4345

4446
.line-number {
45-
border-right-color: cs.$color-border-divider-default;
46-
background-color: $color-background-code-view-light;
47+
border-inline-end-color: cs.$color-border-divider-default;
4748
vertical-align: text-top;
4849
position: sticky;
49-
left: 0;
50-
border-right-width: 1px;
51-
border-right-style: solid;
52-
padding-left: cs.$space-static-xs;
53-
padding-right: cs.$space-static-xs;
50+
inset-inline-start: 0;
51+
border-inline-end-width: 1px;
52+
border-inline-end-style: solid;
53+
padding-inline-start: cs.$space-static-xs;
54+
padding-inline-end: cs.$space-static-xs;
55+
56+
background-color: $color-background-code-view-light;
5457
:global(.awsui-dark-mode) &,
5558
:global(.awsui-polaris-dark-mode) & {
5659
background-color: $color-background-code-view-dark;
@@ -63,8 +66,8 @@ $color-background-code-view-dark: #282c34;
6366
}
6467

6568
.code-line {
66-
padding-left: cs.$space-static-xs;
67-
padding-right: cs.$space-static-xs;
69+
padding-inline-start: cs.$space-static-xs;
70+
padding-inline-end: cs.$space-static-xs;
6871
&-wrap {
6972
white-space: pre-wrap;
7073
word-break: break-word;

0 commit comments

Comments
 (0)