Skip to content

Commit 2232736

Browse files
authored
Enhance DiscourseContextOverlay and DiscourseNodeUtil components (#495)
* Introduced opacity and color props to DiscourseContextOverlay for better customization. * Added an "Open in Sidebar" button in DiscourseNodeUtil to improve user interaction. * Updated styles to reflect new props and ensure consistent UI behavior.
1 parent 9204ce9 commit 2232736

File tree

2 files changed

+87
-9
lines changed

2 files changed

+87
-9
lines changed

apps/roam/src/components/DiscourseContextOverlay.tsx

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,49 @@ const getOverlayInfo = async (tag: string): Promise<DiscourseData> => {
5858
}
5959
};
6060

61-
type DiscourseContextOverlayProps =
62-
| { id: string; tag: string; uid?: never }
63-
| { id: string; uid: string; tag?: never }
64-
| { id: string; tag: string; uid: string };
61+
const OPACITY_VALUES = [
62+
"5",
63+
"10",
64+
"15",
65+
"20",
66+
"25",
67+
"30",
68+
"35",
69+
"40",
70+
"45",
71+
"50",
72+
"55",
73+
"60",
74+
"65",
75+
"70",
76+
"75",
77+
"80",
78+
"85",
79+
"90",
80+
"95",
81+
"100",
82+
] as const;
83+
84+
type OpacityValue = (typeof OPACITY_VALUES)[number];
85+
86+
type DiscourseContextOverlayBaseProps = {
87+
id: string;
88+
iconColor?: string;
89+
textColor?: string;
90+
opacity?: OpacityValue;
91+
};
92+
93+
// need tag or uid
94+
type DiscourseContextOverlayProps = DiscourseContextOverlayBaseProps &
95+
({ tag: string; uid?: never } | { tag?: never; uid: string });
96+
6597
const DiscourseContextOverlay = ({
6698
tag,
6799
id,
68100
uid,
101+
iconColor,
102+
textColor,
103+
opacity = "100",
69104
}: DiscourseContextOverlayProps) => {
70105
const tagUid = useMemo(() => uid ?? getPageUidByPageTitle(tag), [uid, tag]);
71106
const [loading, setLoading] = useState(true);
@@ -131,10 +166,28 @@ const DiscourseContextOverlay = ({
131166
disabled={loading}
132167
>
133168
<div className="flex items-center gap-1.5">
134-
<Icon icon={"diagram-tree"} />
135-
<span className="mr-1 leading-none">{loading ? "-" : score}</span>
136-
<Icon icon={"link"} />
137-
<span className="leading-none">{loading ? "-" : refs}</span>
169+
<Icon
170+
icon={"diagram-tree"}
171+
color={iconColor}
172+
style={{ opacity: `${Number(opacity) / 100}` }}
173+
/>
174+
<span
175+
className={`mr-1 leading-none opacity-${opacity}`}
176+
style={{ color: textColor }}
177+
>
178+
{loading ? "-" : score}
179+
</span>
180+
<Icon
181+
icon={"link"}
182+
color={iconColor}
183+
style={{ opacity: `${Number(opacity) / 100}` }}
184+
/>
185+
<span
186+
className={`leading-none opacity-${opacity}`}
187+
style={{ color: textColor }}
188+
>
189+
{loading ? "-" : refs}
190+
</span>
138191
</div>
139192
</Button>
140193
}

apps/roam/src/components/canvas/DiscourseNodeUtil.tsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import { useExtensionAPI } from "roamjs-components/components/ExtensionApiContex
2727
import getPageUidByPageTitle from "roamjs-components/queries/getPageUidByPageTitle";
2828
import isLiveBlock from "roamjs-components/queries/isLiveBlock";
2929
import updateBlock from "roamjs-components/writes/updateBlock";
30+
import openBlockInSidebar from "roamjs-components/writes/openBlockInSidebar";
31+
import { Button, Icon } from "@blueprintjs/core";
3032
import createDiscourseNode from "~/utils/createDiscourseNode";
3133
import { DiscourseNode } from "~/utils/getDiscourseNodes";
3234
import { isPageUid } from "./Tldraw";
@@ -517,6 +519,26 @@ export class BaseDiscourseNodeUtil extends ShapeUtil<DiscourseNodeShape> {
517519
onPointerEnter={() => setOverlayMounted(true)}
518520
>
519521
<div style={{ pointerEvents: "all" }}>
522+
{/* Open in Sidebar Button */}
523+
<Button
524+
className="absolute left-1 top-1 z-10"
525+
minimal
526+
small
527+
icon={
528+
<Icon
529+
icon="panel-stats"
530+
color={textColor}
531+
className="opacity-50"
532+
/>
533+
}
534+
onClick={(e) => {
535+
e.stopPropagation();
536+
void openBlockInSidebar(shape.props.uid);
537+
}}
538+
onPointerDown={(e) => e.stopPropagation()}
539+
title="Open in sidebar (Shift+Click)"
540+
/>
541+
520542
{shape.props.imageUrl && isKeyImage ? (
521543
<img
522544
src={shape.props.imageUrl}
@@ -537,12 +559,15 @@ export class BaseDiscourseNodeUtil extends ShapeUtil<DiscourseNodeShape> {
537559
>
538560
{overlayMounted && isOverlayEnabled && (
539561
<div
540-
className="roamjs-discourse-context-overlay-container absolute right-0 top-0"
562+
className="roamjs-discourse-context-overlay-container absolute right-1 top-1"
541563
onPointerDown={(e) => e.stopPropagation()}
542564
>
543565
<DiscourseContextOverlay
544566
uid={shape.props.uid}
545567
id={`${shape.id}-overlay`}
568+
opacity="50"
569+
textColor={textColor}
570+
iconColor={textColor}
546571
/>
547572
</div>
548573
)}

0 commit comments

Comments
 (0)