Skip to content

Commit 19cf57d

Browse files
authored
chore: Reusing arrow styles between popover and annotation context (#4042)
1 parent 0c4c33e commit 19cf57d

File tree

5 files changed

+22
-131
lines changed

5 files changed

+22
-131
lines changed

src/annotation-context/annotation/annotation-popover.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33
import React, { useEffect } from 'react';
4-
import clsx from 'clsx';
54

65
import { useUniqueId } from '@cloudscape-design/component-toolkit/internal';
76

@@ -11,9 +10,9 @@ import { InternalButton } from '../../button/internal';
1110
import { HotspotProps } from '../../hotspot/interfaces';
1211
import { scrollElementIntoView } from '../../internal/utils/scrollable-containers';
1312
import { joinStrings } from '../../internal/utils/strings/join-strings.js';
13+
import Arrow from '../../popover/arrow';
1414
import PopoverBody from '../../popover/body';
1515
import PopoverContainer from '../../popover/container';
16-
import { InternalPosition } from '../../popover/interfaces';
1716
import InternalSpaceBetween from '../../space-between/internal';
1817
import { AnnotationContextProps } from '../interfaces';
1918

@@ -48,13 +47,6 @@ interface AnnotationPopoverProps {
4847
i18nStrings: AnnotationContextProps['i18nStrings'];
4948
}
5049

51-
const arrow = (position: InternalPosition | null) => (
52-
<div className={clsx(styles.arrow, styles[`arrow-position-${position}`])}>
53-
<div className={styles['arrow-outer']} />
54-
<div className={styles['arrow-inner']} />
55-
</div>
56-
);
57-
5850
export function AnnotationPopover({
5951
title,
6052
content,
@@ -97,7 +89,7 @@ export function AnnotationPopover({
9789
trackRef={trackRef}
9890
trackKey={taskLocalStepIndex}
9991
variant="annotation"
100-
arrow={arrow}
92+
arrow={position => <Arrow position={position} variant="info" />}
10193
zIndex={7000}
10294
renderWithPortal={true}
10395
>

src/annotation-context/annotation/arrow.scss

Lines changed: 0 additions & 113 deletions
This file was deleted.

src/annotation-context/annotation/styles.scss

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
@use '@cloudscape-design/component-toolkit/internal/focus-visible' as focus-visible;
99
@use '../../internal/generated/custom-css-properties/index.scss' as custom-props;
1010

11-
@use './arrow';
12-
1311
.annotation,
1412
.next-button,
1513
.previous-button,

src/popover/arrow.scss

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// - A foreground triangle with popover background color overlapping
1414
// the outer triangle 1 pixel in
1515
//
16-
// For the sake of accurate positioning, the arrow box has to be an even integer in px
16+
// For the sake of accurate positioning, the arrow box has to be an even integer (in px, not rem).
1717
// The box-shadow rotates with the arrow, so we need different shadows for each direction
1818

1919
// Based on $awsui-box-shadow-inner shadow, but rotated based on x and y multipliers.
@@ -22,8 +22,8 @@
2222
box-shadow: ($box-shadow-size * $x) ($box-shadow-size * $y) 4px -2px awsui.$color-shadow-default;
2323
}
2424

25-
$arrow-edge-length: 14px;
26-
$arrow-width: 20px;
25+
$arrow-edge-length: 1.4 * styles.$base-size;
26+
$arrow-width: 2 * styles.$base-size;
2727
$arrow-height: $arrow-width * 0.5;
2828

2929
inline-size: $arrow-width;
@@ -114,3 +114,17 @@
114114
}
115115
}
116116
}
117+
118+
.arrow-variant-info {
119+
> .arrow-outer {
120+
&::after {
121+
background-color: awsui.$color-border-status-info;
122+
}
123+
}
124+
125+
> .arrow-inner {
126+
&::after {
127+
background-color: awsui.$color-background-status-info;
128+
}
129+
}
130+
}

src/popover/arrow.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import styles from './styles.css.js';
1010

1111
interface ArrowProps {
1212
position: InternalPosition | null;
13+
variant?: 'default' | 'info';
1314
}
1415

15-
const Arrow = (props: ArrowProps) => {
16+
const Arrow = ({ position, variant }: ArrowProps) => {
1617
const isVisualRefresh = useVisualRefresh();
17-
1818
return (
19-
<div className={clsx(styles.arrow, props.position && styles[`arrow-position-${props.position}`])}>
19+
<div className={clsx(styles.arrow, styles[`arrow-position-${position}`], styles[`arrow-variant-${variant}`])}>
2020
<div className={styles['arrow-outer']} />
2121
<div className={clsx(styles['arrow-inner'], isVisualRefresh && styles.refresh)} />
2222
</div>

0 commit comments

Comments
 (0)